diff options
| author | Stephen Gildea | 2019-11-19 21:26:09 -0800 |
|---|---|---|
| committer | Stephen Gildea | 2019-11-19 21:27:13 -0800 |
| commit | 123c775aa7a92fc323f88c2e4b6e8185d4c369b4 (patch) | |
| tree | 9d7dac67507759859124fcc6fca6f5cb19ab6b90 /test | |
| parent | 0fce8e9391fd107f9267188a36b85aea778b8440 (diff) | |
| download | emacs-123c775aa7a92fc323f88c2e4b6e8185d4c369b4.tar.gz emacs-123c775aa7a92fc323f88c2e4b6e8185d4c369b4.zip | |
Expand coverage of unit tests for time-stamp
* test/lisp/time-stamp-tests.el: Remove redundant word "test"
from the names of all the tests.
(time-stamp-custom-time-zone, time-stamp-custom-pattern,
time-stamp-custom-inserts-lines, time-stamp-custom-count,
time-stamp-helper-safe-locals): New tests
Diffstat (limited to 'test')
| -rw-r--r-- | test/lisp/time-stamp-tests.el | 219 |
1 files changed, 196 insertions, 23 deletions
diff --git a/test/lisp/time-stamp-tests.el b/test/lisp/time-stamp-tests.el index ae8eaf467d9..fb2780af2de 100644 --- a/test/lisp/time-stamp-tests.el +++ b/test/lisp/time-stamp-tests.el | |||
| @@ -20,13 +20,15 @@ | |||
| 20 | ;;; Code: | 20 | ;;; Code: |
| 21 | 21 | ||
| 22 | (require 'ert) | 22 | (require 'ert) |
| 23 | (require 'generator) | ||
| 23 | (eval-when-compile (require 'cl-lib)) | 24 | (eval-when-compile (require 'cl-lib)) |
| 24 | (require 'time-stamp) | 25 | (require 'time-stamp) |
| 25 | 26 | ||
| 26 | (defmacro with-time-stamp-test-env (&rest body) | 27 | (defmacro with-time-stamp-test-env (&rest body) |
| 27 | "Evaluate BODY with some standard time-stamp test variables bound." | 28 | "Evaluate BODY with some standard time-stamp test variables bound." |
| 29 | (declare (indent defun)) | ||
| 28 | `(let ((user-login-name "test-logname") | 30 | `(let ((user-login-name "test-logname") |
| 29 | (user-full-name "Time Stamp Tester") | 31 | (user-full-name "100%d Tester") ;verify "%" passed unchanged |
| 30 | (buffer-file-name "/emacs/test/time-stamped-file") | 32 | (buffer-file-name "/emacs/test/time-stamped-file") |
| 31 | (mail-host-address "test-mail-host-name") | 33 | (mail-host-address "test-mail-host-name") |
| 32 | (ref-time1 '(17337 16613)) ;Monday, Jan 2, 2006, 3:04:05 PM | 34 | (ref-time1 '(17337 16613)) ;Monday, Jan 2, 2006, 3:04:05 PM |
| @@ -43,7 +45,16 @@ | |||
| 43 | ;; suppress the byte compiler's "unused" warning. | 45 | ;; suppress the byte compiler's "unused" warning. |
| 44 | (list ref-time1 ref-time2 ref-time3) | 46 | (list ref-time1 ref-time2 ref-time3) |
| 45 | ,@body))) | 47 | ,@body))) |
| 46 | (put 'with-time-stamp-test-env 'lisp-indent-hook 'defun) | 48 | |
| 49 | (defmacro with-time-stamp-test-time (reference-time &rest body) | ||
| 50 | "Force any contained time-stamp call to use time REFERENCE-TIME." | ||
| 51 | (declare (indent defun)) | ||
| 52 | `(cl-letf* | ||
| 53 | ((orig-time-stamp-string-fn (symbol-function 'time-stamp-string)) | ||
| 54 | ((symbol-function 'time-stamp-string) | ||
| 55 | (lambda (ts-format) | ||
| 56 | (apply orig-time-stamp-string-fn ts-format ,reference-time nil)))) | ||
| 57 | ,@body)) | ||
| 47 | 58 | ||
| 48 | (defmacro time-stamp-should-warn (form) | 59 | (defmacro time-stamp-should-warn (form) |
| 49 | "Similar to `should' but verifies that a format warning is generated." | 60 | "Similar to `should' but verifies that a format warning is generated." |
| @@ -57,9 +68,152 @@ | |||
| 57 | 68 | ||
| 58 | ;;; Tests: | 69 | ;;; Tests: |
| 59 | 70 | ||
| 71 | ;;; Tests of customization variables | ||
| 72 | |||
| 73 | (ert-deftest time-stamp-custom-time-zone () | ||
| 74 | "Test that setting time-stamp-time-zone affects the format." | ||
| 75 | (with-time-stamp-test-env | ||
| 76 | (let ((time-stamp-time-zone "PST8")) | ||
| 77 | (should (equal (time-stamp-string "%H %Z" ref-time1) "07 PST"))) | ||
| 78 | (let ((time-stamp-time-zone "UTC0")) | ||
| 79 | (should (equal (time-stamp-string "%H %Z" ref-time1) "15 UTC"))) | ||
| 80 | (let ((time-stamp-time-zone "GMT0")) | ||
| 81 | (should (equal (time-stamp-string "%H %Z" ref-time1) "15 GMT"))))) | ||
| 82 | |||
| 83 | (iter-defun time-stamp-test-pattern-sequential () | ||
| 84 | "Iterate through each possibility for a part of time-stamp-pattern." | ||
| 85 | (let ((pattern-value-parts | ||
| 86 | '(("4/" "10/" "-4/" "0/" "") ;0: line limit | ||
| 87 | ("stamp<" "") ;1: start | ||
| 88 | ("%-d" "%_H" "%^a" "%#Z" "%:A" "%02H" "%%" "") ;2: format part 1 | ||
| 89 | (" " "x" ":" "\n" "") ;3: format part 2 | ||
| 90 | ("%-d" "%_H" "%^a" "%#Z" "%:A" "%02H" "%%") ;4: format part 3 | ||
| 91 | (">end" "")))) ;5: end | ||
| 92 | (dotimes (cur (length pattern-value-parts)) | ||
| 93 | (dotimes (cur-index (length (nth cur pattern-value-parts))) | ||
| 94 | (cl-flet ((extract-part | ||
| 95 | (lambda (desired-part) | ||
| 96 | (let ((part-list (nth desired-part pattern-value-parts))) | ||
| 97 | (if (= desired-part cur) | ||
| 98 | (nth cur-index part-list) | ||
| 99 | (nth 0 part-list)))))) | ||
| 100 | ;; Don't repeat the default pattern. | ||
| 101 | (if (or (= cur 0) (> cur-index 0)) | ||
| 102 | ;; The whole format must start with %, so not all | ||
| 103 | ;; generated combinations are valid | ||
| 104 | (if (or (not (equal (extract-part 2) "")) | ||
| 105 | (equal (extract-part 3) "")) | ||
| 106 | (iter-yield (list (extract-part 0) | ||
| 107 | (extract-part 1) | ||
| 108 | (apply #'concat | ||
| 109 | (mapcar #'extract-part '(2 3 4))) | ||
| 110 | (extract-part 5)))))))))) | ||
| 111 | |||
| 112 | (iter-defun time-stamp-test-pattern-multiply () | ||
| 113 | "Iterate through every combination of parts of time-stamp-pattern." | ||
| 114 | (let ((line-limit-values '("" "4/")) | ||
| 115 | (start-values '("" "stamp<")) | ||
| 116 | (format-values '("%%" "%m")) | ||
| 117 | (end-values '("" ">end"))) | ||
| 118 | ;; yield all combinations of the above | ||
| 119 | (dolist (line-limit line-limit-values) | ||
| 120 | (dolist (start start-values) | ||
| 121 | (dolist (format format-values) | ||
| 122 | (dolist (end end-values) | ||
| 123 | (iter-yield (list line-limit start format end)))))))) | ||
| 124 | |||
| 125 | (iter-defun time-stamp-test-pattern-all () | ||
| 126 | (iter-yield-from (time-stamp-test-pattern-sequential)) | ||
| 127 | (iter-yield-from (time-stamp-test-pattern-multiply))) | ||
| 128 | |||
| 129 | (ert-deftest time-stamp-custom-pattern () | ||
| 130 | "Test that time-stamp-pattern is parsed correctly." | ||
| 131 | (iter-do (pattern-parts (time-stamp-test-pattern-all)) | ||
| 132 | (cl-destructuring-bind (line-limit1 start1 whole-format end1) pattern-parts | ||
| 133 | (cl-letf | ||
| 134 | (((symbol-function 'time-stamp-once) | ||
| 135 | (lambda (start search-limit ts-start ts-end | ||
| 136 | ts-format _format-lines _end-lines) | ||
| 137 | ;; Verify that time-stamp parsed time-stamp-pattern and | ||
| 138 | ;; called us with the correct pieces. | ||
| 139 | (let ((limit-number (string-to-number line-limit1))) | ||
| 140 | (if (equal line-limit1 "") | ||
| 141 | (setq limit-number time-stamp-line-limit)) | ||
| 142 | (goto-char (point-min)) | ||
| 143 | (if (> limit-number 0) | ||
| 144 | (should (= search-limit (line-beginning-position | ||
| 145 | (1+ limit-number)))) | ||
| 146 | (should (= search-limit (point-max)))) | ||
| 147 | (goto-char (point-max)) | ||
| 148 | (if (< limit-number 0) | ||
| 149 | (should (= start (line-beginning-position | ||
| 150 | (1+ limit-number)))) | ||
| 151 | (should (= start (point-min))))) | ||
| 152 | (if (equal start1 "") | ||
| 153 | (should (equal ts-start time-stamp-start)) | ||
| 154 | (should (equal ts-start start1))) | ||
| 155 | (if (equal whole-format "%%") | ||
| 156 | (should (equal ts-format time-stamp-format)) | ||
| 157 | (should (equal ts-format whole-format))) | ||
| 158 | (if (equal end1 "") | ||
| 159 | (should (equal ts-end time-stamp-end)) | ||
| 160 | (should (equal ts-end end1))) | ||
| 161 | ;; return nil to stop time-stamp from calling us again | ||
| 162 | nil))) | ||
| 163 | (let ((time-stamp-pattern (concat | ||
| 164 | line-limit1 start1 whole-format end1))) | ||
| 165 | (with-temp-buffer | ||
| 166 | ;; prep the buffer with more than the | ||
| 167 | ;; largest line-limit1 number of lines | ||
| 168 | (insert "\n\n\n\n\n\n\n\n\n\n\n\n") | ||
| 169 | ;; Call time-stamp, which will call time-stamp-once, | ||
| 170 | ;; triggering the tests above. | ||
| 171 | (time-stamp))))))) | ||
| 172 | |||
| 173 | (ert-deftest time-stamp-custom-inserts-lines () | ||
| 174 | "Test that time-stamp inserts lines or not, as directed." | ||
| 175 | (with-time-stamp-test-env | ||
| 176 | (let ((time-stamp-start "Updated on:") | ||
| 177 | ;; the newline in the format will insert a line if we let it | ||
| 178 | (time-stamp-format "\n %Y-%m-%d") | ||
| 179 | (time-stamp-end "$") | ||
| 180 | (time-stamp-inserts-lines nil) ;changed later in the test | ||
| 181 | (buffer-expected-1line "Updated on:\n 2006-01-02\n") | ||
| 182 | (buffer-expected-2line "Updated on:\n 2006-01-02\n 2006-01-02\n")) | ||
| 183 | (with-time-stamp-test-time ref-time1 | ||
| 184 | (with-temp-buffer | ||
| 185 | (insert "Updated on:\n\n") | ||
| 186 | (time-stamp) | ||
| 187 | (should (equal (buffer-string) buffer-expected-1line)) | ||
| 188 | ;; second call should not add a line | ||
| 189 | (time-stamp) | ||
| 190 | (should (equal (buffer-string) buffer-expected-1line)) | ||
| 191 | |||
| 192 | (setq time-stamp-inserts-lines t) | ||
| 193 | ;; with time-stamp-inserts-lines set, should add a line | ||
| 194 | (time-stamp) | ||
| 195 | (should (equal (buffer-string) buffer-expected-2line))))))) | ||
| 196 | |||
| 197 | (ert-deftest time-stamp-custom-count () | ||
| 198 | "Test that time-stamp updates no more than time-stamp-count templates." | ||
| 199 | (with-time-stamp-test-env | ||
| 200 | (let ((time-stamp-start "TS: <") | ||
| 201 | (time-stamp-format "%Y-%m-%d") | ||
| 202 | (time-stamp-count 1) ;changed later in the test | ||
| 203 | (buffer-expected-once "TS: <2006-01-02>\nTS: <>") | ||
| 204 | (buffer-expected-twice "TS: <2006-01-02>\nTS: <2006-01-02>")) | ||
| 205 | (with-time-stamp-test-time ref-time1 | ||
| 206 | (with-temp-buffer | ||
| 207 | (insert "TS: <>\nTS: <>") | ||
| 208 | (time-stamp) | ||
| 209 | (should (equal (buffer-string) buffer-expected-once)) | ||
| 210 | (setq time-stamp-count 2) | ||
| 211 | (time-stamp) | ||
| 212 | (should (equal (buffer-string) buffer-expected-twice))))))) | ||
| 213 | |||
| 60 | ;;; Tests of time-stamp-string formatting | 214 | ;;; Tests of time-stamp-string formatting |
| 61 | 215 | ||
| 62 | (ert-deftest time-stamp-test-format-day-of-week () | 216 | (ert-deftest time-stamp-format-day-of-week () |
| 63 | "Test time-stamp formats for named day of week." | 217 | "Test time-stamp formats for named day of week." |
| 64 | (with-time-stamp-test-env | 218 | (with-time-stamp-test-env |
| 65 | ;; implemented and documented since 1997 | 219 | ;; implemented and documented since 1997 |
| @@ -78,7 +232,7 @@ | |||
| 78 | (should (equal (time-stamp-string "%^a" ref-time1) "MON")) | 232 | (should (equal (time-stamp-string "%^a" ref-time1) "MON")) |
| 79 | (should (equal (time-stamp-string "%A" ref-time1) "Monday")))) | 233 | (should (equal (time-stamp-string "%A" ref-time1) "Monday")))) |
| 80 | 234 | ||
| 81 | (ert-deftest time-stamp-test-format-month-name () | 235 | (ert-deftest time-stamp-format-month-name () |
| 82 | "Test time-stamp formats for month name." | 236 | "Test time-stamp formats for month name." |
| 83 | (with-time-stamp-test-env | 237 | (with-time-stamp-test-env |
| 84 | ;; implemented and documented since 1997 | 238 | ;; implemented and documented since 1997 |
| @@ -97,7 +251,7 @@ | |||
| 97 | (should (equal (time-stamp-string "%^b" ref-time1) "JAN")) | 251 | (should (equal (time-stamp-string "%^b" ref-time1) "JAN")) |
| 98 | (should (equal (time-stamp-string "%B" ref-time1) "January")))) | 252 | (should (equal (time-stamp-string "%B" ref-time1) "January")))) |
| 99 | 253 | ||
| 100 | (ert-deftest time-stamp-test-format-day-of-month () | 254 | (ert-deftest time-stamp-format-day-of-month () |
| 101 | "Test time-stamp formats for day of month." | 255 | "Test time-stamp formats for day of month." |
| 102 | (with-time-stamp-test-env | 256 | (with-time-stamp-test-env |
| 103 | ;; implemented and documented since 1995 | 257 | ;; implemented and documented since 1995 |
| @@ -120,7 +274,7 @@ | |||
| 120 | (should (equal (time-stamp-string "%d" ref-time1) "02")) | 274 | (should (equal (time-stamp-string "%d" ref-time1) "02")) |
| 121 | (should (equal (time-stamp-string "%d" ref-time2) "18")))) | 275 | (should (equal (time-stamp-string "%d" ref-time2) "18")))) |
| 122 | 276 | ||
| 123 | (ert-deftest time-stamp-test-format-hours-24 () | 277 | (ert-deftest time-stamp-format-hours-24 () |
| 124 | "Test time-stamp formats for hour on a 24-hour clock." | 278 | "Test time-stamp formats for hour on a 24-hour clock." |
| 125 | (with-time-stamp-test-env | 279 | (with-time-stamp-test-env |
| 126 | ;; implemented and documented since 1995 | 280 | ;; implemented and documented since 1995 |
| @@ -150,7 +304,7 @@ | |||
| 150 | (should (equal (time-stamp-string "%H" ref-time2) "12")) | 304 | (should (equal (time-stamp-string "%H" ref-time2) "12")) |
| 151 | (should (equal (time-stamp-string "%H" ref-time3) "06")))) | 305 | (should (equal (time-stamp-string "%H" ref-time3) "06")))) |
| 152 | 306 | ||
| 153 | (ert-deftest time-stamp-test-format-hours-12 () | 307 | (ert-deftest time-stamp-format-hours-12 () |
| 154 | "Test time-stamp formats for hour on a 12-hour clock." | 308 | "Test time-stamp formats for hour on a 12-hour clock." |
| 155 | (with-time-stamp-test-env | 309 | (with-time-stamp-test-env |
| 156 | ;; implemented and documented since 1995 | 310 | ;; implemented and documented since 1995 |
| @@ -180,7 +334,7 @@ | |||
| 180 | (should (equal (time-stamp-string "%I" ref-time2) "12")) | 334 | (should (equal (time-stamp-string "%I" ref-time2) "12")) |
| 181 | (should (equal (time-stamp-string "%I" ref-time3) "06")))) | 335 | (should (equal (time-stamp-string "%I" ref-time3) "06")))) |
| 182 | 336 | ||
| 183 | (ert-deftest time-stamp-test-format-month-number () | 337 | (ert-deftest time-stamp-format-month-number () |
| 184 | "Test time-stamp formats for month number." | 338 | "Test time-stamp formats for month number." |
| 185 | (with-time-stamp-test-env | 339 | (with-time-stamp-test-env |
| 186 | ;; implemented and documented since 1995 | 340 | ;; implemented and documented since 1995 |
| @@ -203,7 +357,7 @@ | |||
| 203 | (should (equal (time-stamp-string "%m" ref-time1) "01")) | 357 | (should (equal (time-stamp-string "%m" ref-time1) "01")) |
| 204 | (should (equal (time-stamp-string "%m" ref-time2) "11")))) | 358 | (should (equal (time-stamp-string "%m" ref-time2) "11")))) |
| 205 | 359 | ||
| 206 | (ert-deftest time-stamp-test-format-minute () | 360 | (ert-deftest time-stamp-format-minute () |
| 207 | "Test time-stamp formats for minute." | 361 | "Test time-stamp formats for minute." |
| 208 | (with-time-stamp-test-env | 362 | (with-time-stamp-test-env |
| 209 | ;; implemented and documented since 1995 | 363 | ;; implemented and documented since 1995 |
| @@ -226,7 +380,7 @@ | |||
| 226 | (should (equal (time-stamp-string "%M" ref-time1) "04")) | 380 | (should (equal (time-stamp-string "%M" ref-time1) "04")) |
| 227 | (should (equal (time-stamp-string "%M" ref-time2) "14")))) | 381 | (should (equal (time-stamp-string "%M" ref-time2) "14")))) |
| 228 | 382 | ||
| 229 | (ert-deftest time-stamp-test-format-second () | 383 | (ert-deftest time-stamp-format-second () |
| 230 | "Test time-stamp formats for second." | 384 | "Test time-stamp formats for second." |
| 231 | (with-time-stamp-test-env | 385 | (with-time-stamp-test-env |
| 232 | ;; implemented and documented since 1995 | 386 | ;; implemented and documented since 1995 |
| @@ -249,7 +403,7 @@ | |||
| 249 | (should (equal (time-stamp-string "%S" ref-time1) "05")) | 403 | (should (equal (time-stamp-string "%S" ref-time1) "05")) |
| 250 | (should (equal (time-stamp-string "%S" ref-time2) "15")))) | 404 | (should (equal (time-stamp-string "%S" ref-time2) "15")))) |
| 251 | 405 | ||
| 252 | (ert-deftest time-stamp-test-format-year-2digit () | 406 | (ert-deftest time-stamp-format-year-2digit () |
| 253 | "Test time-stamp formats for %y." | 407 | "Test time-stamp formats for %y." |
| 254 | (with-time-stamp-test-env | 408 | (with-time-stamp-test-env |
| 255 | ;; implemented and documented since 1995 | 409 | ;; implemented and documented since 1995 |
| @@ -274,13 +428,13 @@ | |||
| 274 | (time-stamp-should-warn | 428 | (time-stamp-should-warn |
| 275 | (equal (time-stamp-string "%4y" ref-time1) "2006")))) | 429 | (equal (time-stamp-string "%4y" ref-time1) "2006")))) |
| 276 | 430 | ||
| 277 | (ert-deftest time-stamp-test-format-year-4digit () | 431 | (ert-deftest time-stamp-format-year-4digit () |
| 278 | "Test time-stamp format %Y." | 432 | "Test time-stamp format %Y." |
| 279 | (with-time-stamp-test-env | 433 | (with-time-stamp-test-env |
| 280 | ;; implemented since 1997, documented since 2019 | 434 | ;; implemented since 1997, documented since 2019 |
| 281 | (should (equal (time-stamp-string "%Y" ref-time1) "2006")))) | 435 | (should (equal (time-stamp-string "%Y" ref-time1) "2006")))) |
| 282 | 436 | ||
| 283 | (ert-deftest time-stamp-test-format-am-pm () | 437 | (ert-deftest time-stamp-format-am-pm () |
| 284 | "Test time-stamp formats for AM and PM strings." | 438 | "Test time-stamp formats for AM and PM strings." |
| 285 | (with-time-stamp-test-env | 439 | (with-time-stamp-test-env |
| 286 | ;; implemented and documented since 1997 | 440 | ;; implemented and documented since 1997 |
| @@ -292,14 +446,14 @@ | |||
| 292 | (should (equal (time-stamp-string "%p" ref-time1) "PM")) | 446 | (should (equal (time-stamp-string "%p" ref-time1) "PM")) |
| 293 | (should (equal (time-stamp-string "%p" ref-time3) "AM")))) | 447 | (should (equal (time-stamp-string "%p" ref-time3) "AM")))) |
| 294 | 448 | ||
| 295 | (ert-deftest time-stamp-test-format-day-number-in-week () | 449 | (ert-deftest time-stamp-format-day-number-in-week () |
| 296 | "Test time-stamp formats for day number in week." | 450 | "Test time-stamp formats for day number in week." |
| 297 | (with-time-stamp-test-env | 451 | (with-time-stamp-test-env |
| 298 | (should (equal (time-stamp-string "%w" ref-time1) "1")) | 452 | (should (equal (time-stamp-string "%w" ref-time1) "1")) |
| 299 | (should (equal (time-stamp-string "%w" ref-time2) "5")) | 453 | (should (equal (time-stamp-string "%w" ref-time2) "5")) |
| 300 | (should (equal (time-stamp-string "%w" ref-time3) "0")))) | 454 | (should (equal (time-stamp-string "%w" ref-time3) "0")))) |
| 301 | 455 | ||
| 302 | (ert-deftest time-stamp-test-format-time-zone-name () | 456 | (ert-deftest time-stamp-format-time-zone-name () |
| 303 | "Test time-stamp format %Z." | 457 | "Test time-stamp format %Z." |
| 304 | (with-time-stamp-test-env | 458 | (with-time-stamp-test-env |
| 305 | (let ((UTC-abbr (format-time-string "%Z" ref-time1 t)) | 459 | (let ((UTC-abbr (format-time-string "%Z" ref-time1 t)) |
| @@ -309,7 +463,7 @@ | |||
| 309 | ;; implemented since 1997, documented since 2019 | 463 | ;; implemented since 1997, documented since 2019 |
| 310 | (should (equal (time-stamp-string "%#Z" ref-time1) utc-abbr))))) | 464 | (should (equal (time-stamp-string "%#Z" ref-time1) utc-abbr))))) |
| 311 | 465 | ||
| 312 | (ert-deftest time-stamp-test-format-time-zone-offset () | 466 | (ert-deftest time-stamp-format-time-zone-offset () |
| 313 | "Test time-stamp format %z." | 467 | "Test time-stamp format %z." |
| 314 | (with-time-stamp-test-env | 468 | (with-time-stamp-test-env |
| 315 | (let ((utc-abbr (format-time-string "%#Z" ref-time1 t))) | 469 | (let ((utc-abbr (format-time-string "%#Z" ref-time1 t))) |
| @@ -331,7 +485,7 @@ | |||
| 331 | (should (equal (time-stamp-string "%::z" ref-time1) "+00:00:00")) | 485 | (should (equal (time-stamp-string "%::z" ref-time1) "+00:00:00")) |
| 332 | (should (equal (time-stamp-string "%:::z" ref-time1) "+00")))) | 486 | (should (equal (time-stamp-string "%:::z" ref-time1) "+00")))) |
| 333 | 487 | ||
| 334 | (ert-deftest time-stamp-test-format-non-date-conversions () | 488 | (ert-deftest time-stamp-format-non-date-conversions () |
| 335 | "Test time-stamp formats for non-date items." | 489 | "Test time-stamp formats for non-date items." |
| 336 | (with-time-stamp-test-env | 490 | (with-time-stamp-test-env |
| 337 | ;; implemented and documented since 1995 | 491 | ;; implemented and documented since 1995 |
| @@ -344,10 +498,10 @@ | |||
| 344 | ;; documented 1995-2019 | 498 | ;; documented 1995-2019 |
| 345 | (should (equal | 499 | (should (equal |
| 346 | (time-stamp-string "%s" ref-time1) "test-system-name.example.org")) | 500 | (time-stamp-string "%s" ref-time1) "test-system-name.example.org")) |
| 347 | (should (equal (time-stamp-string "%U" ref-time1) "Time Stamp Tester")) | 501 | (should (equal (time-stamp-string "%U" ref-time1) "100%d Tester")) |
| 348 | (should (equal (time-stamp-string "%u" ref-time1) "test-logname")) | 502 | (should (equal (time-stamp-string "%u" ref-time1) "test-logname")) |
| 349 | ;; implemented since 2001, documented since 2019 | 503 | ;; implemented since 2001, documented since 2019 |
| 350 | (should (equal (time-stamp-string "%L" ref-time1) "Time Stamp Tester")) | 504 | (should (equal (time-stamp-string "%L" ref-time1) "100%d Tester")) |
| 351 | (should (equal (time-stamp-string "%l" ref-time1) "test-logname")) | 505 | (should (equal (time-stamp-string "%l" ref-time1) "test-logname")) |
| 352 | ;; implemented since 2007, documented since 2019 | 506 | ;; implemented since 2007, documented since 2019 |
| 353 | (should (equal | 507 | (should (equal |
| @@ -355,7 +509,7 @@ | |||
| 355 | (should (equal | 509 | (should (equal |
| 356 | (time-stamp-string "%q" ref-time1) "test-system-name")))) | 510 | (time-stamp-string "%q" ref-time1) "test-system-name")))) |
| 357 | 511 | ||
| 358 | (ert-deftest time-stamp-test-format-ignored-modifiers () | 512 | (ert-deftest time-stamp-format-ignored-modifiers () |
| 359 | "Test additional args allowed (but ignored) to allow for future expansion." | 513 | "Test additional args allowed (but ignored) to allow for future expansion." |
| 360 | (with-time-stamp-test-env | 514 | (with-time-stamp-test-env |
| 361 | ;; allowed modifiers | 515 | ;; allowed modifiers |
| @@ -363,12 +517,12 @@ | |||
| 363 | ;; not all punctuation is allowed | 517 | ;; not all punctuation is allowed |
| 364 | (should-not (equal (time-stamp-string "%&P" ref-time3) "AM")))) | 518 | (should-not (equal (time-stamp-string "%&P" ref-time3) "AM")))) |
| 365 | 519 | ||
| 366 | (ert-deftest time-stamp-test-format-non-conversions () | 520 | (ert-deftest time-stamp-format-non-conversions () |
| 367 | "Test that without a %, the text is copied literally." | 521 | "Test that without a %, the text is copied literally." |
| 368 | (with-time-stamp-test-env | 522 | (with-time-stamp-test-env |
| 369 | (should (equal (time-stamp-string "No percent" ref-time1) "No percent")))) | 523 | (should (equal (time-stamp-string "No percent" ref-time1) "No percent")))) |
| 370 | 524 | ||
| 371 | (ert-deftest time-stamp-test-format-string-width () | 525 | (ert-deftest time-stamp-format-string-width () |
| 372 | "Test time-stamp string width modifiers." | 526 | "Test time-stamp string width modifiers." |
| 373 | (with-time-stamp-test-env | 527 | (with-time-stamp-test-env |
| 374 | ;; strings truncate on the right or are blank-padded on the left | 528 | ;; strings truncate on the right or are blank-padded on the left |
| @@ -384,7 +538,7 @@ | |||
| 384 | 538 | ||
| 385 | ;;; Tests of helper functions | 539 | ;;; Tests of helper functions |
| 386 | 540 | ||
| 387 | (ert-deftest time-stamp-test-helper-zone-type-p () | 541 | (ert-deftest time-stamp-helper-zone-type-p () |
| 388 | "Test time-stamp-zone-type-p." | 542 | "Test time-stamp-zone-type-p." |
| 389 | (should (time-stamp-zone-type-p t)) | 543 | (should (time-stamp-zone-type-p t)) |
| 390 | (should (time-stamp-zone-type-p nil)) | 544 | (should (time-stamp-zone-type-p nil)) |
| @@ -399,4 +553,23 @@ | |||
| 399 | (should-not (time-stamp-zone-type-p '(0 0))) | 553 | (should-not (time-stamp-zone-type-p '(0 0))) |
| 400 | (should-not (time-stamp-zone-type-p '("A" "A")))) | 554 | (should-not (time-stamp-zone-type-p '("A" "A")))) |
| 401 | 555 | ||
| 556 | (ert-deftest time-stamp-helper-safe-locals () | ||
| 557 | "Test that our variables are known to be safe local variables." | ||
| 558 | (should (safe-local-variable-p 'time-stamp-format "a string")) | ||
| 559 | (should-not (safe-local-variable-p 'time-stamp-format '(a list))) | ||
| 560 | (should (safe-local-variable-p 'time-stamp-time-zone "a string")) | ||
| 561 | (should-not (safe-local-variable-p 'time-stamp-time-zone 0.5)) | ||
| 562 | (should (safe-local-variable-p 'time-stamp-line-limit 8)) | ||
| 563 | (should-not (safe-local-variable-p 'time-stamp-line-limit "a string")) | ||
| 564 | (should (safe-local-variable-p 'time-stamp-start "a string")) | ||
| 565 | (should-not (safe-local-variable-p 'time-stamp-start 17)) | ||
| 566 | (should (safe-local-variable-p 'time-stamp-end "a string")) | ||
| 567 | (should-not (safe-local-variable-p 'time-stamp-end 17)) | ||
| 568 | (should (safe-local-variable-p 'time-stamp-inserts-lines t)) | ||
| 569 | (should-not (safe-local-variable-p 'time-stamp-inserts-lines 17)) | ||
| 570 | (should (safe-local-variable-p 'time-stamp-count 2)) | ||
| 571 | (should-not (safe-local-variable-p 'time-stamp-count t)) | ||
| 572 | (should (safe-local-variable-p 'time-stamp-pattern "a string")) | ||
| 573 | (should-not (safe-local-variable-p 'time-stamp-pattern 17))) | ||
| 574 | |||
| 402 | ;;; time-stamp-tests.el ends here | 575 | ;;; time-stamp-tests.el ends here |