Skip to content
Snippets Groups Projects
Commit a84a9b7e authored by David Byers's avatar David Byers
Browse files

Complete the fix for #1

parent 4eedef44
No related branches found
No related tags found
1 merge request!3Complete the fix for #1
2020-07-23 David Byers <david.byers@liu.se> 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): Fix issue #1 (olc-recover-compound fails on full codes):
* test/olctest.el: Improved test macros. Tests for issue 1. * test/olctest.el: Improved test macros. Tests for issue 1.
......
...@@ -519,7 +519,11 @@ If FORMAT is `area' (or any other value), the returned value is an ...@@ -519,7 +519,11 @@ If FORMAT is `area' (or any other value), the returned value is an
full open location code." full open location code."
(let ((parse (olc-parse-code code))) (let ((parse (olc-parse-code code)))
(if (olc-is-full parse) (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) (setq lat (olc-clip-latitude lat)
lon (olc-normalize-longitude lon)) lon (olc-normalize-longitude lon))
(let* ((padlen (- (olc-parse-precision parse) (let* ((padlen (- (olc-parse-precision parse)
...@@ -559,19 +563,21 @@ full open location code." ...@@ -559,19 +563,21 @@ full open location code."
;; Make sure we can do requests ;; Make sure we can do requests
(unless (fboundp 'request) (signal 'void-function 'request)) (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 code stringp)
(cl-check-type format (member latlon area nil)) (cl-check-type format (member latlon area nil))
(if (string-match "^\\(\\S-+\\)\\s-+\\(.*\\)$" code) ;; Process code and check ref
(progn (cl-check-type ref null) (cond ((string-match "^\\(\\S-+\\)\\s-+\\(.*\\)$" code)
(setq ref (match-string 2 code) (progn (cl-check-type ref null)
code (match-string 1 code))) (setq ref (match-string 2 code)
(cl-check-type ref stringp)) code (match-string 1 code))))
((olc-is-full code))
(t (cl-check-type ref stringp)))
;; If the code is full then return it ;; If the code is full then return it
(if (olc-is-full code) (if (olc-is-full code)
code (olc-recover code 0 0 :format format)
(let ((resp (request "https://nominatim.openstreetmap.org/search" (let ((resp (request "https://nominatim.openstreetmap.org/search"
:params `((q . ,ref) :params `((q . ,ref)
(format . "json") (format . "json")
......
...@@ -240,10 +240,34 @@ ...@@ -240,10 +240,34 @@
(defun olctest-issue-1 () (defun olctest-issue-1 ()
(olctest-testcase "local: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" (olctest-string= :exp "9FFV9VH8+9C"
:act (olc-recover-compound "9FFV9VH8+9C" :ref "Antarctica") :act (olc-recover-compound "9FFV9VH8+9C" :ref "Antarctica")
:msg "O1") :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" (olctest-string= :exp "9FFPMGGC+9C"
:act (olc-recover-compound "+9C Sweden") :act (olc-recover-compound "+9C Sweden")
:msg "O2") :msg "O2")
...@@ -252,17 +276,7 @@ ...@@ -252,17 +276,7 @@
:act (olc-recover-compound "+9C" :ref "Sweden") :act (olc-recover-compound "+9C" :ref "Sweden")
:msg "O3") :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 () (defun olctest-run-all ()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment