diff --git a/Makefile b/Makefile index a12b5b49d89ee3e8383925fb10df5219c191f2e0..a474a2e3181b08b51313e0856289df80a1553231 100644 --- a/Makefile +++ b/Makefile @@ -49,4 +49,4 @@ test: -l olctest.el \ -f olctest-batch-test \ $(TESTS) \ - ) + ) && echo "All tests passed" diff --git a/olc.el b/olc.el index 85e7cdba4444c0b41d382a16d976f948eec06cf6..ea6b36691149936d8295a430bb92ef287f4b8b5f 100644 --- a/olc.el +++ b/olc.el @@ -3,7 +3,7 @@ ;; Copyright (C) 2020 David Byers ;; ;; Author: David Byers <david.byers@liu.se> -;; Version: 1.1.0 +;; Version: 1.2.0 ;; Package-Requires: ((emacs "25.1")) ;; Keywords: extensions, lisp ;; URL: https://gitlab.liu.se/davby02/olc @@ -53,6 +53,13 @@ (declare-function request-response-data "request") +;;; Variables: + + +(defvar olc-nominatim-url "https://nominatim.openstreetmap.org/" + "Base url for the nominatim endpoint.") + + ;;; Custom errors: @@ -209,6 +216,13 @@ raise, and args for the raised error. (setq index (1+ index))) code)))) +(defun olc-nominatim-endpoint (path) + "Build a complete url for nominatim endpoint PATH." + (concat olc-nominatim-url + (if (= ?/ (elt olc-nominatim-url (1- (length olc-nominatim-url)))) + "" "/") + path)) + (defsubst olc-clip-latitude (lat) "Clip LAT to -90,90." (max -90 (min 90 lat))) @@ -606,7 +620,7 @@ faster. (let* ((zoom (floor (+ zoom-lo zoom-hi) 2)) (resp (request-response-data (request - "https://nominatim.openstreetmap.org/reverse" + (olc-nominatim-endpoint "reverse") :params `((lat . ,(olc-area-lat area)) (lon . ,(olc-area-lon area)) (zoom . ,zoom) @@ -720,7 +734,7 @@ full open location code." ;; If the code is full then return it (if (olc-is-full code) (olc-recover code 0 0 :format format) - (let ((resp (request "https://nominatim.openstreetmap.org/search" + (let ((resp (request (olc-nominatim-endpoint "search") :params `((q . ,ref) (format . "json") (limit . 1)) diff --git a/test/olctest.el b/test/olctest.el index 5c7ef5df2b26185fc6dcc7c7c757f24aedf28545..34add359f8b8aa8e984f2821e72ad64affef4bd2 100644 --- a/test/olctest.el +++ b/test/olctest.el @@ -488,14 +488,29 @@ "22+" "Nowhere Special, Pitcairn")) :msg "R1") (olc-recover-compound "22+ Nowhere Special, Pitcairn")) - (olctest-expect-failure "R2" - (let ((olc-nominatim-url "https://invalid.domain/nominatim")) - (olctest-assert-error (:exp ((olc-recover-error-reference-search-failed - "22+" "Sweden")) :msg "R2") - (olc-recover-compound "22+ Sweden")))) + (let ((olc-nominatim-url "https://invalid.domain/nominatim")) + (olctest-assert-error (:exp ((olc-recover-error-reference-search-failed + "22+" "Sweden")) :msg "R2") + (olc-recover-compound "22+ Sweden"))) )) +(defun olctest-issue-5 () + (olctest-testcase "issue-5" + (olctest-string= :exp "https://nominatim.openstreetmap.org/search" + :act (olc-nominatim-endpoint "search") + :msg "1") + + (let ((olc-nominatim-url "https://nominatim.invalid")) + (olctest-string= :exp "https://nominatim.invalid/search" + :act (olc-nominatim-endpoint "search") + :msg "2")) + + (let ((olc-nominatim-url "https://nominatim.invalid/")) + (olctest-string= :exp "https://nominatim.invalid/reverse" + :act (olc-nominatim-endpoint "reverse") + :msg "3")))) + (defvar olctest-selected-tests) @@ -515,6 +530,7 @@ (run-test validity) (run-test localtests) (run-test errors) + (run-test issue-5) (run-test issue-3) (run-test issue-2) (run-test issue-1)