aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStephen Gildea2020-04-29 07:36:07 -0700
committerStephen Gildea2020-04-29 08:44:23 -0700
commit0a982c077e7393d865622ff780906a0cb252348d (patch)
treea3a34a4b6c38719d83f85687895823f44a1d8006
parentb56401f3849cf6d00717ab8a64a221f2c01455a6 (diff)
downloademacs-0a982c077e7393d865622ff780906a0cb252348d.tar.gz
emacs-0a982c077e7393d865622ff780906a0cb252348d.zip
Test iso8601-parse-zone vs format-time-string %z
* test/lisp/calendar/iso8601-tests.el (iso8601-format-time-string-zone-round-trip): New unit test that format-time-string %z and iso8601-parse-zone are inverses. (test-iso8601-format-time-string-zone-round-trip): New helper function.
-rw-r--r--test/lisp/calendar/iso8601-tests.el31
1 files changed, 31 insertions, 0 deletions
diff --git a/test/lisp/calendar/iso8601-tests.el b/test/lisp/calendar/iso8601-tests.el
index e8b155a7aa7..c835f5792b9 100644
--- a/test/lisp/calendar/iso8601-tests.el
+++ b/test/lisp/calendar/iso8601-tests.el
@@ -232,6 +232,37 @@
232 (should (equal (iso8601-parse-time "15:27:46-05") 232 (should (equal (iso8601-parse-time "15:27:46-05")
233 '(46 27 15 nil nil nil nil nil -18000)))) 233 '(46 27 15 nil nil nil nil nil -18000))))
234 234
235
236(defun test-iso8601-format-time-string-zone-round-trip (offset-minutes z-format)
237 "Pass OFFSET-MINUTES to format-time-string with Z-FORMAT, a %z variation,
238and then to iso8601-parse-zone. The result should be the original offset."
239 (let* ((offset-seconds (* 60 offset-minutes))
240 (zone-string (format-time-string z-format 0 offset-seconds))
241 (offset-rt
242 (condition-case nil
243 (iso8601-parse-zone zone-string)
244 (wrong-type-argument (format "(failed to parse %S)" zone-string))))
245 ;; compare strings that contain enough info to debug failures
246 (success (format "%s(%s) -> %S -> %s"
247 z-format offset-minutes zone-string offset-minutes))
248 (actual (format "%s(%s) -> %S -> %s"
249 z-format offset-minutes zone-string offset-rt)))
250 (should (equal success actual))))
251
252(ert-deftest iso8601-format-time-string-zone-round-trip ()
253 "Round trip zone offsets through format-time-string and iso8601-parse-zone.
254Passing a time zone created by format-time-string %z to
255iso8601-parse-zone should yield the original offset."
256 (dolist (offset-minutes
257 (list
258 ;; compare hours (1- and 2-digit), minutes, both, neither
259 (* 5 60) (* 11 60) 5 11 (+ (* 5 60) 30) (+ (* 11 60) 30) 0
260 ;; do negative values, too
261 (* -5 60) (* -11 60) -5 -11 (- (* -5 60) 30) (- (* -11 60) 30)))
262 (dolist (z-format '("%z" "%:z" "%:::z"))
263 (test-iso8601-format-time-string-zone-round-trip
264 offset-minutes z-format))))
265
235(ert-deftest standard-test-date-and-time-of-day () 266(ert-deftest standard-test-date-and-time-of-day ()
236 (should (equal (iso8601-parse "19850412T101530") 267 (should (equal (iso8601-parse "19850412T101530")
237 '(30 15 10 12 4 1985 nil -1 nil))) 268 '(30 15 10 12 4 1985 nil -1 nil)))