diff --git a/CHANGELOG b/CHANGELOG index 0261a616cc4d2063c2d55ffdc9a39029e8afec3f..66e1eea1bc0fc932a82db6c103c5fabcf0d73f51 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,5 +1,11 @@ 2020-07-23 David Byers <david.byers@liu.se> + Fix issue #1 more properly: + * olc.el (olc-recover): Honor format arg when dealing with full + codes. + (olc-recover-compound): Defer to olc-recover when dealing with + full codes. + Fix issue #1 (olc-recover-compound fails on full codes): * test/olctest.el: Improved test macros. Tests for issue 1. diff --git a/olc.el b/olc.el index 0d59bad7638ec66f7d3abf424a88b4d4a2ac7ac5..3ebb070644ab0ec5e5b316175e70c6aafb9d19cf 100644 --- a/olc.el +++ b/olc.el @@ -519,7 +519,11 @@ If FORMAT is `area' (or any other value), the returned value is an full open location code." (let ((parse (olc-parse-code code))) (if (olc-is-full parse) - (upcase code) + (if (eq format 'latlon) + (let ((area (olc-decode parse))) + (cons (olc-area-lat area) + (olc-area-lon area))) + (upcase code)) (setq lat (olc-clip-latitude lat) lon (olc-normalize-longitude lon)) (let* ((padlen (- (olc-parse-precision parse) @@ -559,19 +563,21 @@ full open location code." ;; Make sure we can do requests (unless (fboundp 'request) (signal 'void-function 'request)) - ;; Check types (defer check of ref + ;; Check types (defer check of ref) (cl-check-type code stringp) (cl-check-type format (member latlon area nil)) - (if (string-match "^\\(\\S-+\\)\\s-+\\(.*\\)$" code) - (progn (cl-check-type ref null) - (setq ref (match-string 2 code) - code (match-string 1 code))) - (cl-check-type ref stringp)) + ;; Process code and check ref + (cond ((string-match "^\\(\\S-+\\)\\s-+\\(.*\\)$" code) + (progn (cl-check-type ref null) + (setq ref (match-string 2 code) + code (match-string 1 code)))) + ((olc-is-full code)) + (t (cl-check-type ref stringp))) ;; If the code is full then return it (if (olc-is-full code) - code + (olc-recover code 0 0 :format format) (let ((resp (request "https://nominatim.openstreetmap.org/search" :params `((q . ,ref) (format . "json") diff --git a/test/olctest.el b/test/olctest.el index a1c02c16887d322fdc27d7ed8cba7e3007f87fbe..062963e48b1912cf7b4852270db88adec470cb83 100644 --- a/test/olctest.el +++ b/test/olctest.el @@ -240,10 +240,34 @@ (defun olctest-issue-1 () (olctest-testcase "local:issue-1" + (olctest-assert-error (:exp (wrong-type-argument) :msg "F1") + (olc-recover-compound nil)) + + (olctest-assert-error (:exp (wrong-type-argument) :msg "F2") + (olc-recover-compound "+9C Sweden" :ref "Norway")) + + (olctest-assert-error (:exp (wrong-type-argument) :msg "F3") + (olc-recover-compound "+9C" :ref nil)) + + (olctest-assert-error (:exp (wrong-type-argument) :msg "F4") + (olc-recover-compound "+9C Sweden" :format 'undefined)) + + (olctest-string= :exp "9FFV9VH8+9C" + :act (olc-recover-compound "9FFV9VH8+9C") + :msg "O1") + (olctest-string= :exp "9FFV9VH8+9C" :act (olc-recover-compound "9FFV9VH8+9C" :ref "Antarctica") :msg "O1") + (olctest-equal :exp '(-89.99875 . -179.99875) + :act (olc-recover "22222222+" 0 0 :format 'latlon) + :msg "O4") + + (olctest-equal :exp '(-89.99875 . -179.99875) + :act (olc-recover-compound "22222222+" :format 'latlon) + :msg "O4") + (olctest-string= :exp "9FFPMGGC+9C" :act (olc-recover-compound "+9C Sweden") :msg "O2") @@ -252,17 +276,7 @@ :act (olc-recover-compound "+9C" :ref "Sweden") :msg "O3") - (olctest-assert-error (:exp (wrong-type-argument) :msg "F1") - (olc-recover-compound nil)) - - (olctest-assert-error (:exp (wrong-type-argument) :msg "F2") - (olc-recover-compound "+9C Sweden" :ref "Norway")) - - (olctest-assert-error (:exp (wrong-type-argument) :msg "F3") - (olc-recover-compound "+9C" :ref nil)) - - (olctest-assert-error (:exp (wrong-type-argument) :msg "F4") - (olc-recover-compound "+9C Sweden" :format 'undefined)))) + )) (defun olctest-run-all ()