diff options
| author | Paul Eggert | 2018-10-03 09:10:01 -0700 |
|---|---|---|
| committer | Paul Eggert | 2018-10-06 23:31:04 -0700 |
| commit | 3cc452327eff056f17637566aaf05a877e61d69a (patch) | |
| tree | e702e883dab66b2a63cf1b728c3bd7ca0faabd70 /test | |
| parent | 93fe420942c08111a6048af7c4d7807c61d80a09 (diff) | |
| download | emacs-3cc452327eff056f17637566aaf05a877e61d69a.tar.gz emacs-3cc452327eff056f17637566aaf05a877e61d69a.zip | |
Improvements on (TICKS . HZ)
This patch is in response to Eli's review (Bug#32902#10).
* src/systime.c: Doc strings of affected functions now refer
to format-time-string instead of to Lisp manual, and
format-time-string's doc string covers time values.
* test/src/systime-tests.el (format-time-string-with-zone):
Check decode-time too.
(decode-then-encode-time, time-arith-tests): New tests.
Diffstat (limited to 'test')
| -rw-r--r-- | test/src/timefns-tests.el | 116 |
1 files changed, 89 insertions, 27 deletions
diff --git a/test/src/timefns-tests.el b/test/src/timefns-tests.el index 435dcf7db70..ebeb43de163 100644 --- a/test/src/timefns-tests.el +++ b/test/src/timefns-tests.el | |||
| @@ -19,7 +19,7 @@ | |||
| 19 | 19 | ||
| 20 | (require 'ert) | 20 | (require 'ert) |
| 21 | 21 | ||
| 22 | ;;; Check format-time-string with various TZ settings. | 22 | ;;; Check format-time-string and decode-time with various TZ settings. |
| 23 | ;;; Use only POSIX-compatible TZ values, since the tests should work | 23 | ;;; Use only POSIX-compatible TZ values, since the tests should work |
| 24 | ;;; even if tzdb is not in use. | 24 | ;;; even if tzdb is not in use. |
| 25 | (ert-deftest format-time-string-with-zone () | 25 | (ert-deftest format-time-string-with-zone () |
| @@ -35,32 +35,61 @@ | |||
| 35 | ;; Similarly, stick to the limited set of time zones that are | 35 | ;; Similarly, stick to the limited set of time zones that are |
| 36 | ;; supported by both POSIX and MS-Windows: exactly 3 ASCII letters | 36 | ;; supported by both POSIX and MS-Windows: exactly 3 ASCII letters |
| 37 | ;; in the abbreviation, and no DST. | 37 | ;; in the abbreviation, and no DST. |
| 38 | (let ((look '(1202 22527 999999 999999)) | 38 | (let ((format "%Y-%m-%d %H:%M:%S.%3N %z (%Z)")) |
| 39 | (format "%Y-%m-%d %H:%M:%S.%3N %z (%Z)")) | 39 | (dolist (look '((1202 22527 999999 999999) |
| 40 | ;; UTC. | 40 | (7879679999900 . 100000) |
| 41 | (should (string-equal | 41 | (78796799999999999999 . 1000000000000))) |
| 42 | (format-time-string "%Y-%m-%d %H:%M:%S.%3N %z" look t) | 42 | ;; UTC. |
| 43 | "1972-06-30 23:59:59.999 +0000")) | 43 | (should (string-equal |
| 44 | ;; "UTC0". | 44 | (format-time-string "%Y-%m-%d %H:%M:%S.%3N %z" look t) |
| 45 | (should (string-equal | 45 | "1972-06-30 23:59:59.999 +0000")) |
| 46 | (format-time-string format look "UTC0") | 46 | (should (equal (decode-time look t) |
| 47 | "1972-06-30 23:59:59.999 +0000 (UTC)")) | 47 | '(59 59 23 30 6 1972 5 nil 0))) |
| 48 | ;; Negative UTC offset, as a Lisp list. | 48 | ;; "UTC0". |
| 49 | (should (string-equal | 49 | (should (string-equal |
| 50 | (format-time-string format look '(-28800 "PST")) | 50 | (format-time-string format look "UTC0") |
| 51 | "1972-06-30 15:59:59.999 -0800 (PST)")) | 51 | "1972-06-30 23:59:59.999 +0000 (UTC)")) |
| 52 | ;; Negative UTC offset, as a Lisp integer. | 52 | (should (equal (decode-time look "UTC0") |
| 53 | (should (string-equal | 53 | '(59 59 23 30 6 1972 5 nil 0))) |
| 54 | (format-time-string format look -28800) | 54 | ;; Negative UTC offset, as a Lisp list. |
| 55 | ;; MS-Windows build replaces unrecognizable TZ values, | 55 | (should (string-equal |
| 56 | ;; such as "-08", with "ZZZ". | 56 | (format-time-string format look '(-28800 "PST")) |
| 57 | (if (eq system-type 'windows-nt) | 57 | "1972-06-30 15:59:59.999 -0800 (PST)")) |
| 58 | "1972-06-30 15:59:59.999 -0800 (ZZZ)" | 58 | (should (equal (decode-time look '(-28800 "PST")) |
| 59 | "1972-06-30 15:59:59.999 -0800 (-08)"))) | 59 | '(59 59 15 30 6 1972 5 nil -28800))) |
| 60 | ;; Positive UTC offset that is not an hour multiple, as a string. | 60 | ;; Negative UTC offset, as a Lisp integer. |
| 61 | (should (string-equal | 61 | (should (string-equal |
| 62 | (format-time-string format look "IST-5:30") | 62 | (format-time-string format look -28800) |
| 63 | "1972-07-01 05:29:59.999 +0530 (IST)")))) | 63 | ;; MS-Windows build replaces unrecognizable TZ values, |
| 64 | ;; such as "-08", with "ZZZ". | ||
| 65 | (if (eq system-type 'windows-nt) | ||
| 66 | "1972-06-30 15:59:59.999 -0800 (ZZZ)" | ||
| 67 | "1972-06-30 15:59:59.999 -0800 (-08)"))) | ||
| 68 | (should (equal (decode-time look -28800) | ||
| 69 | '(59 59 15 30 6 1972 5 nil -28800))) | ||
| 70 | ;; Positive UTC offset that is not an hour multiple, as a string. | ||
| 71 | (should (string-equal | ||
| 72 | (format-time-string format look "IST-5:30") | ||
| 73 | "1972-07-01 05:29:59.999 +0530 (IST)")) | ||
| 74 | (should (equal (decode-time look "IST-5:30") | ||
| 75 | '(59 29 5 1 7 1972 6 nil 19800)))))) | ||
| 76 | |||
| 77 | (ert-deftest decode-then-encode-time () | ||
| 78 | (let ((time-values (list 0 -2 1 0.0 -0.0 -2.0 1.0 | ||
| 79 | most-negative-fixnum most-positive-fixnum | ||
| 80 | (1- most-negative-fixnum) | ||
| 81 | (1+ most-positive-fixnum) | ||
| 82 | 1e+INF -1e+INF 1e+NaN -1e+NaN | ||
| 83 | '(0 1 0 0) '(1 0 0 0) '(-1 0 0 0) | ||
| 84 | '(123456789000000 . 1000000) | ||
| 85 | (cons (1+ most-positive-fixnum) 1000000000000) | ||
| 86 | (cons 1000000000000 (1+ most-positive-fixnum))))) | ||
| 87 | (dolist (a time-values) | ||
| 88 | (let* ((d (ignore-errors (decode-time a t))) | ||
| 89 | (e (encode-time d)) | ||
| 90 | (diff (float-time (time-subtract a e)))) | ||
| 91 | (should (or (not d) | ||
| 92 | (and (<= 0 diff) (< diff 1)))))))) | ||
| 64 | 93 | ||
| 65 | ;;; This should not dump core. | 94 | ;;; This should not dump core. |
| 66 | (ert-deftest format-time-string-with-outlandish-zone () | 95 | (ert-deftest format-time-string-with-outlandish-zone () |
| @@ -80,3 +109,36 @@ | |||
| 80 | 109 | ||
| 81 | (ert-deftest time-equal-p-nil-nil () | 110 | (ert-deftest time-equal-p-nil-nil () |
| 82 | (should (time-equal-p nil nil))) | 111 | (should (time-equal-p nil nil))) |
| 112 | |||
| 113 | (ert-deftest time-arith-tests () | ||
| 114 | (let ((time-values (list 0 -1 1 0.0 -0.0 -1.0 1.0 | ||
| 115 | most-negative-fixnum most-positive-fixnum | ||
| 116 | (1- most-negative-fixnum) | ||
| 117 | (1+ most-positive-fixnum) | ||
| 118 | 1e+INF -1e+INF 1e+NaN -1e+NaN | ||
| 119 | '(0 0 0 1) '(0 0 1 0) '(0 1 0 0) '(1 0 0 0) | ||
| 120 | '(-1 0 0 0) '(1 2 3 4) '(-1 2 3 4) | ||
| 121 | '(-123456789 . 100000) '(123456789 . 1000000) | ||
| 122 | (cons (1+ most-positive-fixnum) 1000000000000) | ||
| 123 | (cons 1000000000000 (1+ most-positive-fixnum))))) | ||
| 124 | (dolist (a time-values) | ||
| 125 | (dolist (b time-values) | ||
| 126 | (let ((aa (time-subtract (time-add a b) b))) | ||
| 127 | (should (or (time-equal-p a aa) (and (floatp aa) (isnan aa))))) | ||
| 128 | (should (= 1 (+ (if (time-less-p a b) 1 0) | ||
| 129 | (if (time-equal-p a b) 1 0) | ||
| 130 | (if (time-less-p b a) 1 0) | ||
| 131 | (if (or (and (floatp a) (isnan a)) | ||
| 132 | (and (floatp b) (isnan b))) | ||
| 133 | 1 0)))) | ||
| 134 | (should (or (not (time-less-p 0 b)) | ||
| 135 | (time-less-p a (time-add a b)) | ||
| 136 | (time-equal-p a (time-add a b)) | ||
| 137 | (and (floatp (time-add a b)) (isnan (time-add a b))))) | ||
| 138 | (let ((x (float-time (time-add a b))) | ||
| 139 | (y (+ (float-time a) (float-time b)))) | ||
| 140 | (should (or (and (isnan x) (isnan y)) | ||
| 141 | (= x y) | ||
| 142 | (< 0.99 (/ x y) 1.01) | ||
| 143 | (< 0.99 (/ (- (float-time a)) (float-time b)) | ||
| 144 | 1.01)))))))) | ||