diff options
Diffstat (limited to 'test')
| -rw-r--r-- | test/src/editfns-tests.el | 59 | ||||
| -rw-r--r-- | test/src/timefns-tests.el | 79 |
2 files changed, 79 insertions, 59 deletions
diff --git a/test/src/editfns-tests.el b/test/src/editfns-tests.el index 4a840c8d7d1..17b2c510734 100644 --- a/test/src/editfns-tests.el +++ b/test/src/editfns-tests.el | |||
| @@ -204,65 +204,6 @@ | |||
| 204 | (should (string-equal (format "%d" 0.9) "0")) | 204 | (should (string-equal (format "%d" 0.9) "0")) |
| 205 | (should (string-equal (format "%d" 1.1) "1"))) | 205 | (should (string-equal (format "%d" 1.1) "1"))) |
| 206 | 206 | ||
| 207 | ;;; Check format-time-string with various TZ settings. | ||
| 208 | ;;; Use only POSIX-compatible TZ values, since the tests should work | ||
| 209 | ;;; even if tzdb is not in use. | ||
| 210 | (ert-deftest format-time-string-with-zone () | ||
| 211 | ;; Don’t use (0 0 0 0) as the test case, as there are too many bugs | ||
| 212 | ;; in MS-Windows (and presumably other) C libraries when formatting | ||
| 213 | ;; time stamps near the Epoch of 1970-01-01 00:00:00 UTC, and this | ||
| 214 | ;; test is for GNU Emacs, not for C runtimes. Instead, look before | ||
| 215 | ;; you leap: "look" is the timestamp just before the first leap | ||
| 216 | ;; second on 1972-06-30 23:59:60 UTC, so it should format to the | ||
| 217 | ;; same string regardless of whether the underlying C library | ||
| 218 | ;; ignores leap seconds, while avoiding circa-1970 glitches. | ||
| 219 | ;; | ||
| 220 | ;; Similarly, stick to the limited set of time zones that are | ||
| 221 | ;; supported by both POSIX and MS-Windows: exactly 3 ASCII letters | ||
| 222 | ;; in the abbreviation, and no DST. | ||
| 223 | (let ((look '(1202 22527 999999 999999)) | ||
| 224 | (format "%Y-%m-%d %H:%M:%S.%3N %z (%Z)")) | ||
| 225 | ;; UTC. | ||
| 226 | (should (string-equal | ||
| 227 | (format-time-string "%Y-%m-%d %H:%M:%S.%3N %z" look t) | ||
| 228 | "1972-06-30 23:59:59.999 +0000")) | ||
| 229 | ;; "UTC0". | ||
| 230 | (should (string-equal | ||
| 231 | (format-time-string format look "UTC0") | ||
| 232 | "1972-06-30 23:59:59.999 +0000 (UTC)")) | ||
| 233 | ;; Negative UTC offset, as a Lisp list. | ||
| 234 | (should (string-equal | ||
| 235 | (format-time-string format look '(-28800 "PST")) | ||
| 236 | "1972-06-30 15:59:59.999 -0800 (PST)")) | ||
| 237 | ;; Negative UTC offset, as a Lisp integer. | ||
| 238 | (should (string-equal | ||
| 239 | (format-time-string format look -28800) | ||
| 240 | ;; MS-Windows build replaces unrecognizable TZ values, | ||
| 241 | ;; such as "-08", with "ZZZ". | ||
| 242 | (if (eq system-type 'windows-nt) | ||
| 243 | "1972-06-30 15:59:59.999 -0800 (ZZZ)" | ||
| 244 | "1972-06-30 15:59:59.999 -0800 (-08)"))) | ||
| 245 | ;; Positive UTC offset that is not an hour multiple, as a string. | ||
| 246 | (should (string-equal | ||
| 247 | (format-time-string format look "IST-5:30") | ||
| 248 | "1972-07-01 05:29:59.999 +0530 (IST)")))) | ||
| 249 | |||
| 250 | ;;; This should not dump core. | ||
| 251 | (ert-deftest format-time-string-with-outlandish-zone () | ||
| 252 | (should (stringp | ||
| 253 | (format-time-string "%Y-%m-%d %H:%M:%S.%3N %z" nil | ||
| 254 | (concat (make-string 2048 ?X) "0"))))) | ||
| 255 | |||
| 256 | (defun editfns-tests--have-leap-seconds () | ||
| 257 | (string-equal (format-time-string "%Y-%m-%d %H:%M:%S" 78796800 t) | ||
| 258 | "1972-06-30 23:59:60")) | ||
| 259 | |||
| 260 | (ert-deftest format-time-string-with-bignum-on-32-bit () | ||
| 261 | (should (or (string-equal | ||
| 262 | (format-time-string "%Y-%m-%d %H:%M:%S" (- (ash 1 31) 3600) t) | ||
| 263 | "2038-01-19 02:14:08") | ||
| 264 | (editfns-tests--have-leap-seconds)))) | ||
| 265 | |||
| 266 | (ert-deftest format-with-field () | 207 | (ert-deftest format-with-field () |
| 267 | (should (equal (format "First argument %2$s, then %3$s, then %1$s" 1 2 3) | 208 | (should (equal (format "First argument %2$s, then %3$s, then %1$s" 1 2 3) |
| 268 | "First argument 2, then 3, then 1")) | 209 | "First argument 2, then 3, then 1")) |
diff --git a/test/src/timefns-tests.el b/test/src/timefns-tests.el new file mode 100644 index 00000000000..8418b509e17 --- /dev/null +++ b/test/src/timefns-tests.el | |||
| @@ -0,0 +1,79 @@ | |||
| 1 | ;;; timefns-tests.el -- tests for timefns.c | ||
| 2 | |||
| 3 | ;; Copyright (C) 2016-2018 Free Software Foundation, Inc. | ||
| 4 | |||
| 5 | ;; This file is part of GNU Emacs. | ||
| 6 | |||
| 7 | ;; This program is free software; you can redistribute it and/or modify | ||
| 8 | ;; it under the terms of the GNU General Public License as published by | ||
| 9 | ;; the Free Software Foundation, either version 3 of the License, or | ||
| 10 | ;; (at your option) any later version. | ||
| 11 | |||
| 12 | ;; This program is distributed in the hope that it will be useful, | ||
| 13 | ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 14 | ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 15 | ;; GNU General Public License for more details. | ||
| 16 | |||
| 17 | ;; You should have received a copy of the GNU General Public License | ||
| 18 | ;; along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
| 19 | |||
| 20 | (require 'ert) | ||
| 21 | |||
| 22 | ;;; Check format-time-string with various TZ settings. | ||
| 23 | ;;; Use only POSIX-compatible TZ values, since the tests should work | ||
| 24 | ;;; even if tzdb is not in use. | ||
| 25 | (ert-deftest format-time-string-with-zone () | ||
| 26 | ;; Don’t use (0 0 0 0) as the test case, as there are too many bugs | ||
| 27 | ;; in MS-Windows (and presumably other) C libraries when formatting | ||
| 28 | ;; time stamps near the Epoch of 1970-01-01 00:00:00 UTC, and this | ||
| 29 | ;; test is for GNU Emacs, not for C runtimes. Instead, look before | ||
| 30 | ;; you leap: "look" is the timestamp just before the first leap | ||
| 31 | ;; second on 1972-06-30 23:59:60 UTC, so it should format to the | ||
| 32 | ;; same string regardless of whether the underlying C library | ||
| 33 | ;; ignores leap seconds, while avoiding circa-1970 glitches. | ||
| 34 | ;; | ||
| 35 | ;; Similarly, stick to the limited set of time zones that are | ||
| 36 | ;; supported by both POSIX and MS-Windows: exactly 3 ASCII letters | ||
| 37 | ;; in the abbreviation, and no DST. | ||
| 38 | (let ((look '(1202 22527 999999 999999)) | ||
| 39 | (format "%Y-%m-%d %H:%M:%S.%3N %z (%Z)")) | ||
| 40 | ;; UTC. | ||
| 41 | (should (string-equal | ||
| 42 | (format-time-string "%Y-%m-%d %H:%M:%S.%3N %z" look t) | ||
| 43 | "1972-06-30 23:59:59.999 +0000")) | ||
| 44 | ;; "UTC0". | ||
| 45 | (should (string-equal | ||
| 46 | (format-time-string format look "UTC0") | ||
| 47 | "1972-06-30 23:59:59.999 +0000 (UTC)")) | ||
| 48 | ;; Negative UTC offset, as a Lisp list. | ||
| 49 | (should (string-equal | ||
| 50 | (format-time-string format look '(-28800 "PST")) | ||
| 51 | "1972-06-30 15:59:59.999 -0800 (PST)")) | ||
| 52 | ;; Negative UTC offset, as a Lisp integer. | ||
| 53 | (should (string-equal | ||
| 54 | (format-time-string format look -28800) | ||
| 55 | ;; MS-Windows build replaces unrecognizable TZ values, | ||
| 56 | ;; such as "-08", with "ZZZ". | ||
| 57 | (if (eq system-type 'windows-nt) | ||
| 58 | "1972-06-30 15:59:59.999 -0800 (ZZZ)" | ||
| 59 | "1972-06-30 15:59:59.999 -0800 (-08)"))) | ||
| 60 | ;; Positive UTC offset that is not an hour multiple, as a string. | ||
| 61 | (should (string-equal | ||
| 62 | (format-time-string format look "IST-5:30") | ||
| 63 | "1972-07-01 05:29:59.999 +0530 (IST)")))) | ||
| 64 | |||
| 65 | ;;; This should not dump core. | ||
| 66 | (ert-deftest format-time-string-with-outlandish-zone () | ||
| 67 | (should (stringp | ||
| 68 | (format-time-string "%Y-%m-%d %H:%M:%S.%3N %z" nil | ||
| 69 | (concat (make-string 2048 ?X) "0"))))) | ||
| 70 | |||
| 71 | (defun timefns-tests--have-leap-seconds () | ||
| 72 | (string-equal (format-time-string "%Y-%m-%d %H:%M:%S" 78796800 t) | ||
| 73 | "1972-06-30 23:59:60")) | ||
| 74 | |||
| 75 | (ert-deftest format-time-string-with-bignum-on-32-bit () | ||
| 76 | (should (or (string-equal | ||
| 77 | (format-time-string "%Y-%m-%d %H:%M:%S" (- (ash 1 31) 3600) t) | ||
| 78 | "2038-01-19 02:14:08") | ||
| 79 | (timefns-tests--have-leap-seconds)))) | ||