diff options
| author | Stephen Gildea | 2024-12-14 10:46:15 -0800 |
|---|---|---|
| committer | Stephen Gildea | 2024-12-14 10:46:15 -0800 |
| commit | 7dcc05987160cabc0c063bc285d34cdb2c3c600f (patch) | |
| tree | 44625a7f740c5ad9ec055c288f380e942f23e096 | |
| parent | 33532c58992fc44afa5369678cb53252ec7dc3ac (diff) | |
| download | emacs-7dcc05987160cabc0c063bc285d34cdb2c3c600f.tar.gz emacs-7dcc05987160cabc0c063bc285d34cdb2c3c600f.zip | |
; * test/lisp/time-stamp-tests.el: make checkdoc happier
| -rw-r--r-- | test/lisp/time-stamp-tests.el | 267 |
1 files changed, 134 insertions, 133 deletions
diff --git a/test/lisp/time-stamp-tests.el b/test/lisp/time-stamp-tests.el index 69b14839aec..4492bd12f1a 100644 --- a/test/lisp/time-stamp-tests.el +++ b/test/lisp/time-stamp-tests.el | |||
| @@ -25,7 +25,7 @@ | |||
| 25 | (require 'time-stamp) | 25 | (require 'time-stamp) |
| 26 | 26 | ||
| 27 | (defmacro with-time-stamp-test-env (&rest body) | 27 | (defmacro with-time-stamp-test-env (&rest body) |
| 28 | "Evaluate BODY with some standard time-stamp test variables bound." | 28 | "Evaluate BODY with some standard `time-stamp' test variables bound." |
| 29 | (declare (indent 0) (debug t)) | 29 | (declare (indent 0) (debug t)) |
| 30 | `(let ((user-login-name "test-logname") | 30 | `(let ((user-login-name "test-logname") |
| 31 | (user-full-name "100%d Tester") ;verify "%" passed unchanged | 31 | (user-full-name "100%d Tester") ;verify "%" passed unchanged |
| @@ -55,7 +55,7 @@ | |||
| 55 | ,@body)) | 55 | ,@body)) |
| 56 | 56 | ||
| 57 | (defmacro with-time-stamp-system-name (name &rest body) | 57 | (defmacro with-time-stamp-system-name (name &rest body) |
| 58 | "Force `system-name' to return NAME while evaluating BODY." | 58 | "Force function `system-name' to return NAME while evaluating BODY." |
| 59 | (declare (indent 1) (debug t)) | 59 | (declare (indent 1) (debug t)) |
| 60 | `(cl-letf (((symbol-function 'system-name) | 60 | `(cl-letf (((symbol-function 'system-name) |
| 61 | (lambda () ,name))) | 61 | (lambda () ,name))) |
| @@ -77,7 +77,7 @@ | |||
| 77 | ;;; Tests of customization variables | 77 | ;;; Tests of customization variables |
| 78 | 78 | ||
| 79 | (ert-deftest time-stamp-custom-time-zone () | 79 | (ert-deftest time-stamp-custom-time-zone () |
| 80 | "Test that setting time-stamp-time-zone affects the format." | 80 | "Test that setting `time-stamp-time-zone' affects the format." |
| 81 | (with-time-stamp-test-env | 81 | (with-time-stamp-test-env |
| 82 | (let ((time-stamp-time-zone "PST8")) | 82 | (let ((time-stamp-time-zone "PST8")) |
| 83 | (should (equal (time-stamp-string "%H %Z" ref-time1) "07 PST"))) | 83 | (should (equal (time-stamp-string "%H %Z" ref-time1) "07 PST"))) |
| @@ -139,7 +139,7 @@ | |||
| 139 | (iter-yield-from (time-stamp-test-pattern-multiply))) | 139 | (iter-yield-from (time-stamp-test-pattern-multiply))) |
| 140 | 140 | ||
| 141 | (ert-deftest time-stamp-custom-pattern () | 141 | (ert-deftest time-stamp-custom-pattern () |
| 142 | "Test that time-stamp-pattern is parsed correctly." | 142 | "Test that `time-stamp-pattern' is parsed correctly." |
| 143 | (iter-do (pattern-parts (time-stamp-test-pattern-all)) | 143 | (iter-do (pattern-parts (time-stamp-test-pattern-all)) |
| 144 | (cl-destructuring-bind (line-limit1 start1 whole-format end1) pattern-parts | 144 | (cl-destructuring-bind (line-limit1 start1 whole-format end1) pattern-parts |
| 145 | (cl-letf | 145 | (cl-letf |
| @@ -197,7 +197,7 @@ | |||
| 197 | "Updated in: <\t 2006 \t>"))))))) | 197 | "Updated in: <\t 2006 \t>"))))))) |
| 198 | 198 | ||
| 199 | (ert-deftest time-stamp-custom-inserts-lines () | 199 | (ert-deftest time-stamp-custom-inserts-lines () |
| 200 | "Test that time-stamp inserts lines or not, as directed." | 200 | "Test that `time-stamp' inserts lines or not, as directed." |
| 201 | (with-time-stamp-test-env | 201 | (with-time-stamp-test-env |
| 202 | (let ((time-stamp-start "Updated on:") | 202 | (let ((time-stamp-start "Updated on:") |
| 203 | ;; the newline in the format will insert a line if we let it | 203 | ;; the newline in the format will insert a line if we let it |
| @@ -221,7 +221,7 @@ | |||
| 221 | (should (equal (buffer-string) buffer-expected-2line))))))) | 221 | (should (equal (buffer-string) buffer-expected-2line))))))) |
| 222 | 222 | ||
| 223 | (ert-deftest time-stamp-custom-end () | 223 | (ert-deftest time-stamp-custom-end () |
| 224 | "Test that time-stamp finds the end pattern on the correct line." | 224 | "Test that `time-stamp' finds the end pattern on the correct line." |
| 225 | (with-time-stamp-test-env | 225 | (with-time-stamp-test-env |
| 226 | (let ((time-stamp-start "Updated on: <") | 226 | (let ((time-stamp-start "Updated on: <") |
| 227 | (time-stamp-format "%Y-%m-%d") | 227 | (time-stamp-format "%Y-%m-%d") |
| @@ -241,7 +241,7 @@ | |||
| 241 | (should (equal (buffer-string) buffer-expected-time-stamped))))))) | 241 | (should (equal (buffer-string) buffer-expected-time-stamped))))))) |
| 242 | 242 | ||
| 243 | (ert-deftest time-stamp-custom-count () | 243 | (ert-deftest time-stamp-custom-count () |
| 244 | "Test that time-stamp updates no more than time-stamp-count templates." | 244 | "Test that `time-stamp' updates no more than `time-stamp-count' templates." |
| 245 | (with-time-stamp-test-env | 245 | (with-time-stamp-test-env |
| 246 | (let ((time-stamp-start "TS: <") | 246 | (let ((time-stamp-start "TS: <") |
| 247 | (time-stamp-format "%Y-%m-%d") | 247 | (time-stamp-format "%Y-%m-%d") |
| @@ -289,97 +289,97 @@ | |||
| 289 | ;;; Tests of time-stamp-string formatting | 289 | ;;; Tests of time-stamp-string formatting |
| 290 | 290 | ||
| 291 | (ert-deftest time-stamp-format-day-of-week () | 291 | (ert-deftest time-stamp-format-day-of-week () |
| 292 | "Test time-stamp formats for named day of week." | 292 | "Test `time-stamp' formats for named day of week." |
| 293 | (with-time-stamp-test-env | 293 | (with-time-stamp-test-env |
| 294 | (let* ((Mon (format-time-string "%a" ref-time1 t)) | 294 | (let* ((Mon (format-time-string "%a" ref-time1 t)) |
| 295 | (MON (format-time-string "%^a" ref-time1 t)) | 295 | (MON (format-time-string "%^a" ref-time1 t)) |
| 296 | (Monday (format-time-string "%A" ref-time1 t)) | 296 | (Monday (format-time-string "%A" ref-time1 t)) |
| 297 | (MONDAY (format-time-string "%^A" ref-time1 t)) | 297 | (MONDAY (format-time-string "%^A" ref-time1 t)) |
| 298 | (p4-Mon (string-pad Mon 4 ?\s t)) | 298 | (p4-Mon (string-pad Mon 4 ?\s t)) |
| 299 | (p4-MON (string-pad MON 4 ?\s t)) | 299 | (p4-MON (string-pad MON 4 ?\s t)) |
| 300 | (p10-Monday (string-pad Monday 10 ?\s t)) | 300 | (p10-Monday (string-pad Monday 10 ?\s t)) |
| 301 | (p10-MONDAY (string-pad MONDAY 10 ?\s t))) | 301 | (p10-MONDAY (string-pad MONDAY 10 ?\s t))) |
| 302 | ;; implemented and recommended since 1997 | 302 | ;; implemented and recommended since 1997 |
| 303 | (should (equal (time-stamp-string "%#A" ref-time1) MONDAY)) | 303 | (should (equal (time-stamp-string "%#A" ref-time1) MONDAY)) |
| 304 | (should (equal (time-stamp-string "%#10A" ref-time1) p10-MONDAY)) | 304 | (should (equal (time-stamp-string "%#10A" ref-time1) p10-MONDAY)) |
| 305 | ;; implemented since 1997, recommended 1997-2024 | 305 | ;; implemented since 1997, recommended 1997-2024 |
| 306 | (should (equal (time-stamp-string "%3a" ref-time1) Mon)) | 306 | (should (equal (time-stamp-string "%3a" ref-time1) Mon)) |
| 307 | ;; recommended 1997-2019 | 307 | ;; recommended 1997-2019 |
| 308 | (should (equal (time-stamp-string "%:a" ref-time1) Monday)) | 308 | (should (equal (time-stamp-string "%:a" ref-time1) Monday)) |
| 309 | ;; recommended 1997-2019, warned since 2024, will change | 309 | ;; recommended 1997-2019, warned since 2024, will change |
| 310 | (time-stamp-should-warn | 310 | (time-stamp-should-warn |
| 311 | (should (equal (time-stamp-string "%3A" ref-time1) MON))) | 311 | (should (equal (time-stamp-string "%3A" ref-time1) MON))) |
| 312 | (time-stamp-should-warn | 312 | (time-stamp-should-warn |
| 313 | (should (equal (time-stamp-string "%10A" ref-time1) p10-MONDAY))) | 313 | (should (equal (time-stamp-string "%10A" ref-time1) p10-MONDAY))) |
| 314 | ;; implemented since 2001, recommended since 2019 | 314 | ;; implemented since 2001, recommended since 2019 |
| 315 | (should (equal (time-stamp-string "%#a" ref-time1) MON)) | 315 | (should (equal (time-stamp-string "%#a" ref-time1) MON)) |
| 316 | (should (equal (time-stamp-string "%#3a" ref-time1) MON)) | 316 | (should (equal (time-stamp-string "%#3a" ref-time1) MON)) |
| 317 | (should (equal (time-stamp-string "%#4a" ref-time1) p4-MON)) | 317 | (should (equal (time-stamp-string "%#4a" ref-time1) p4-MON)) |
| 318 | ;; implemented since 2001, recommended 2019-2024 | 318 | ;; implemented since 2001, recommended 2019-2024 |
| 319 | (should (equal (time-stamp-string "%:A" ref-time1) Monday)) | 319 | (should (equal (time-stamp-string "%:A" ref-time1) Monday)) |
| 320 | ;; broken 2019-2024 | 320 | ;; broken 2019-2024 |
| 321 | (should (equal (time-stamp-string "%:10A" ref-time1) p10-Monday)) | 321 | (should (equal (time-stamp-string "%:10A" ref-time1) p10-Monday)) |
| 322 | ;; broken in 2019, changed in 2024 | 322 | ;; broken in 2019, changed in 2024 |
| 323 | (should (equal (time-stamp-string "%-A" ref-time1) Monday)) | 323 | (should (equal (time-stamp-string "%-A" ref-time1) Monday)) |
| 324 | (should (equal (time-stamp-string "%_A" ref-time1) Monday)) | 324 | (should (equal (time-stamp-string "%_A" ref-time1) Monday)) |
| 325 | ;; allowed but not recommended since 2019 (warned 1997-2019) | 325 | ;; allowed but not recommended since 2019 (warned 1997-2019) |
| 326 | (should (equal (time-stamp-string "%^A" ref-time1) MONDAY)) | 326 | (should (equal (time-stamp-string "%^A" ref-time1) MONDAY)) |
| 327 | ;; warned 1997-2019, changed in 2019, recommended (with caveat) since 2024 | 327 | ;; warned 1997-2019, changed in 2019, recommended (with caveat) since 2024 |
| 328 | (should (equal (time-stamp-string "%a" ref-time1) Mon)) | 328 | (should (equal (time-stamp-string "%a" ref-time1) Mon)) |
| 329 | (should (equal (time-stamp-string "%4a" ref-time1) p4-Mon)) | 329 | (should (equal (time-stamp-string "%4a" ref-time1) p4-Mon)) |
| 330 | (should (equal (time-stamp-string "%04a" ref-time1) p4-Mon)) | 330 | (should (equal (time-stamp-string "%04a" ref-time1) p4-Mon)) |
| 331 | (should (equal (time-stamp-string "%A" ref-time1) Monday)) | 331 | (should (equal (time-stamp-string "%A" ref-time1) Monday)) |
| 332 | ;; warned 1997-2019, changed in 2019 | 332 | ;; warned 1997-2019, changed in 2019 |
| 333 | (should (equal (time-stamp-string "%^a" ref-time1) MON)) | 333 | (should (equal (time-stamp-string "%^a" ref-time1) MON)) |
| 334 | (should (equal (time-stamp-string "%^4a" ref-time1) p4-MON))))) | 334 | (should (equal (time-stamp-string "%^4a" ref-time1) p4-MON))))) |
| 335 | 335 | ||
| 336 | (ert-deftest time-stamp-format-month-name () | 336 | (ert-deftest time-stamp-format-month-name () |
| 337 | "Test time-stamp formats for month name." | 337 | "Test `time-stamp' formats for month name." |
| 338 | (with-time-stamp-test-env | 338 | (with-time-stamp-test-env |
| 339 | (let* ((Jan (format-time-string "%b" ref-time1 t)) | 339 | (let* ((Jan (format-time-string "%b" ref-time1 t)) |
| 340 | (JAN (format-time-string "%^b" ref-time1 t)) | 340 | (JAN (format-time-string "%^b" ref-time1 t)) |
| 341 | (January (format-time-string "%B" ref-time1 t)) | 341 | (January (format-time-string "%B" ref-time1 t)) |
| 342 | (JANUARY (format-time-string "%^B" ref-time1 t)) | 342 | (JANUARY (format-time-string "%^B" ref-time1 t)) |
| 343 | (p4-Jan (string-pad Jan 4 ?\s t)) | 343 | (p4-Jan (string-pad Jan 4 ?\s t)) |
| 344 | (p4-JAN (string-pad JAN 4 ?\s t)) | 344 | (p4-JAN (string-pad JAN 4 ?\s t)) |
| 345 | (p10-January (string-pad January 10 ?\s t)) | 345 | (p10-January (string-pad January 10 ?\s t)) |
| 346 | (p10-JANUARY (string-pad JANUARY 10 ?\s t))) | 346 | (p10-JANUARY (string-pad JANUARY 10 ?\s t))) |
| 347 | ;; implemented and recommended since 1997 | 347 | ;; implemented and recommended since 1997 |
| 348 | (should (equal (time-stamp-string "%#B" ref-time1) JANUARY)) | 348 | (should (equal (time-stamp-string "%#B" ref-time1) JANUARY)) |
| 349 | (should (equal (time-stamp-string "%#10B" ref-time1) p10-JANUARY)) | 349 | (should (equal (time-stamp-string "%#10B" ref-time1) p10-JANUARY)) |
| 350 | ;; implemented since 1997, recommended 1997-2024 | 350 | ;; implemented since 1997, recommended 1997-2024 |
| 351 | (should (equal (time-stamp-string "%3b" ref-time1) Jan)) | 351 | (should (equal (time-stamp-string "%3b" ref-time1) Jan)) |
| 352 | ;; recommended 1997-2019 | 352 | ;; recommended 1997-2019 |
| 353 | (should (equal (time-stamp-string "%:b" ref-time1) January)) | 353 | (should (equal (time-stamp-string "%:b" ref-time1) January)) |
| 354 | ;; recommended 1997-2019, warned since 2024, will change | 354 | ;; recommended 1997-2019, warned since 2024, will change |
| 355 | (time-stamp-should-warn | 355 | (time-stamp-should-warn |
| 356 | (should (equal (time-stamp-string "%3B" ref-time1) JAN))) | 356 | (should (equal (time-stamp-string "%3B" ref-time1) JAN))) |
| 357 | (time-stamp-should-warn | 357 | (time-stamp-should-warn |
| 358 | (should (equal (time-stamp-string "%10B" ref-time1) p10-JANUARY))) | 358 | (should (equal (time-stamp-string "%10B" ref-time1) p10-JANUARY))) |
| 359 | ;; implemented since 2001, recommended since 2019 | 359 | ;; implemented since 2001, recommended since 2019 |
| 360 | (should (equal (time-stamp-string "%#b" ref-time1) JAN)) | 360 | (should (equal (time-stamp-string "%#b" ref-time1) JAN)) |
| 361 | (should (equal (time-stamp-string "%#3b" ref-time1) JAN)) | 361 | (should (equal (time-stamp-string "%#3b" ref-time1) JAN)) |
| 362 | (should (equal (time-stamp-string "%#4b" ref-time1) p4-JAN)) | 362 | (should (equal (time-stamp-string "%#4b" ref-time1) p4-JAN)) |
| 363 | ;; implemented since 2001, recommended 2019-2024 | 363 | ;; implemented since 2001, recommended 2019-2024 |
| 364 | (should (equal (time-stamp-string "%:B" ref-time1) January)) | 364 | (should (equal (time-stamp-string "%:B" ref-time1) January)) |
| 365 | ;; broken 2019-2024 | 365 | ;; broken 2019-2024 |
| 366 | (should (equal (time-stamp-string "%:10B" ref-time1) p10-January)) | 366 | (should (equal (time-stamp-string "%:10B" ref-time1) p10-January)) |
| 367 | ;; broken in 2019, changed in 2024 | 367 | ;; broken in 2019, changed in 2024 |
| 368 | (should (equal (time-stamp-string "%-B" ref-time1) January)) | 368 | (should (equal (time-stamp-string "%-B" ref-time1) January)) |
| 369 | (should (equal (time-stamp-string "%_B" ref-time1) January)) | 369 | (should (equal (time-stamp-string "%_B" ref-time1) January)) |
| 370 | ;; allowed but not recommended since 2019 (warned 1997-2019) | 370 | ;; allowed but not recommended since 2019 (warned 1997-2019) |
| 371 | (should (equal (time-stamp-string "%^B" ref-time1) JANUARY)) | 371 | (should (equal (time-stamp-string "%^B" ref-time1) JANUARY)) |
| 372 | ;; warned 1997-2019, changed in 2019, recommended (with caveat) since 2024 | 372 | ;; warned 1997-2019, changed in 2019, recommended (with caveat) since 2024 |
| 373 | (should (equal (time-stamp-string "%b" ref-time1) Jan)) | 373 | (should (equal (time-stamp-string "%b" ref-time1) Jan)) |
| 374 | (should (equal (time-stamp-string "%4b" ref-time1) p4-Jan)) | 374 | (should (equal (time-stamp-string "%4b" ref-time1) p4-Jan)) |
| 375 | (should (equal (time-stamp-string "%04b" ref-time1) p4-Jan)) | 375 | (should (equal (time-stamp-string "%04b" ref-time1) p4-Jan)) |
| 376 | (should (equal (time-stamp-string "%B" ref-time1) January)) | 376 | (should (equal (time-stamp-string "%B" ref-time1) January)) |
| 377 | ;; warned 1997-2019, changed in 2019 | 377 | ;; warned 1997-2019, changed in 2019 |
| 378 | (should (equal (time-stamp-string "%^b" ref-time1) JAN)) | 378 | (should (equal (time-stamp-string "%^b" ref-time1) JAN)) |
| 379 | (should (equal (time-stamp-string "%^4b" ref-time1) p4-JAN))))) | 379 | (should (equal (time-stamp-string "%^4b" ref-time1) p4-JAN))))) |
| 380 | 380 | ||
| 381 | (ert-deftest time-stamp-format-day-of-month () | 381 | (ert-deftest time-stamp-format-day-of-month () |
| 382 | "Test time-stamp formats for day of month." | 382 | "Test `time-stamp' formats for day of month." |
| 383 | (with-time-stamp-test-env | 383 | (with-time-stamp-test-env |
| 384 | ;; implemented since 1995, recommended until 2024 | 384 | ;; implemented since 1995, recommended until 2024 |
| 385 | (should (equal (time-stamp-string "%2d" ref-time1) " 2")) | 385 | (should (equal (time-stamp-string "%2d" ref-time1) " 2")) |
| @@ -402,7 +402,7 @@ | |||
| 402 | (should (equal (time-stamp-string "%d" ref-time2) "18")))) | 402 | (should (equal (time-stamp-string "%d" ref-time2) "18")))) |
| 403 | 403 | ||
| 404 | (ert-deftest time-stamp-format-hours-24 () | 404 | (ert-deftest time-stamp-format-hours-24 () |
| 405 | "Test time-stamp formats for hour on a 24-hour clock." | 405 | "Test `time-stamp' formats for hour on a 24-hour clock." |
| 406 | (with-time-stamp-test-env | 406 | (with-time-stamp-test-env |
| 407 | ;; implemented since 1995, recommended until 2024 | 407 | ;; implemented since 1995, recommended until 2024 |
| 408 | (should (equal (time-stamp-string "%2H" ref-time1) "15")) | 408 | (should (equal (time-stamp-string "%2H" ref-time1) "15")) |
| @@ -432,7 +432,7 @@ | |||
| 432 | (should (equal (time-stamp-string "%H" ref-time3) "06")))) | 432 | (should (equal (time-stamp-string "%H" ref-time3) "06")))) |
| 433 | 433 | ||
| 434 | (ert-deftest time-stamp-format-hours-12 () | 434 | (ert-deftest time-stamp-format-hours-12 () |
| 435 | "Test time-stamp formats for hour on a 12-hour clock." | 435 | "Test `time-stamp' formats for hour on a 12-hour clock." |
| 436 | (with-time-stamp-test-env | 436 | (with-time-stamp-test-env |
| 437 | ;; implemented since 1995, recommended until 2024 | 437 | ;; implemented since 1995, recommended until 2024 |
| 438 | (should (equal (time-stamp-string "%2I" ref-time1) " 3")) | 438 | (should (equal (time-stamp-string "%2I" ref-time1) " 3")) |
| @@ -462,7 +462,7 @@ | |||
| 462 | (should (equal (time-stamp-string "%I" ref-time3) "06")))) | 462 | (should (equal (time-stamp-string "%I" ref-time3) "06")))) |
| 463 | 463 | ||
| 464 | (ert-deftest time-stamp-format-month-number () | 464 | (ert-deftest time-stamp-format-month-number () |
| 465 | "Test time-stamp formats for month number." | 465 | "Test `time-stamp' formats for month number." |
| 466 | (with-time-stamp-test-env | 466 | (with-time-stamp-test-env |
| 467 | ;; implemented since 1995, recommended until 2024 | 467 | ;; implemented since 1995, recommended until 2024 |
| 468 | (should (equal (time-stamp-string "%2m" ref-time1) " 1")) | 468 | (should (equal (time-stamp-string "%2m" ref-time1) " 1")) |
| @@ -485,7 +485,7 @@ | |||
| 485 | (should (equal (time-stamp-string "%m" ref-time2) "11")))) | 485 | (should (equal (time-stamp-string "%m" ref-time2) "11")))) |
| 486 | 486 | ||
| 487 | (ert-deftest time-stamp-format-minute () | 487 | (ert-deftest time-stamp-format-minute () |
| 488 | "Test time-stamp formats for minute." | 488 | "Test `time-stamp' formats for minute." |
| 489 | (with-time-stamp-test-env | 489 | (with-time-stamp-test-env |
| 490 | ;; implemented since 1995, recommended until 2024 | 490 | ;; implemented since 1995, recommended until 2024 |
| 491 | (should (equal (time-stamp-string "%2M" ref-time1) " 4")) | 491 | (should (equal (time-stamp-string "%2M" ref-time1) " 4")) |
| @@ -508,7 +508,7 @@ | |||
| 508 | (should (equal (time-stamp-string "%M" ref-time2) "14")))) | 508 | (should (equal (time-stamp-string "%M" ref-time2) "14")))) |
| 509 | 509 | ||
| 510 | (ert-deftest time-stamp-format-second () | 510 | (ert-deftest time-stamp-format-second () |
| 511 | "Test time-stamp formats for second." | 511 | "Test `time-stamp' formats for second." |
| 512 | (with-time-stamp-test-env | 512 | (with-time-stamp-test-env |
| 513 | ;; implemented since 1995, recommended until 2024 | 513 | ;; implemented since 1995, recommended until 2024 |
| 514 | (should (equal (time-stamp-string "%2S" ref-time1) " 5")) | 514 | (should (equal (time-stamp-string "%2S" ref-time1) " 5")) |
| @@ -531,7 +531,7 @@ | |||
| 531 | (should (equal (time-stamp-string "%S" ref-time2) "15")))) | 531 | (should (equal (time-stamp-string "%S" ref-time2) "15")))) |
| 532 | 532 | ||
| 533 | (ert-deftest time-stamp-format-year-2digit () | 533 | (ert-deftest time-stamp-format-year-2digit () |
| 534 | "Test time-stamp formats for %y." | 534 | "Test `time-stamp' formats for %y." |
| 535 | (with-time-stamp-test-env | 535 | (with-time-stamp-test-env |
| 536 | ;; implemented since 1995, recommended 1995-2024 | 536 | ;; implemented since 1995, recommended 1995-2024 |
| 537 | (should (equal (time-stamp-string "%02y" ref-time1) "06")) | 537 | (should (equal (time-stamp-string "%02y" ref-time1) "06")) |
| @@ -559,7 +559,7 @@ | |||
| 559 | (equal (time-stamp-string "%4y" ref-time1) "2006")))) | 559 | (equal (time-stamp-string "%4y" ref-time1) "2006")))) |
| 560 | 560 | ||
| 561 | (ert-deftest time-stamp-format-year-4digit () | 561 | (ert-deftest time-stamp-format-year-4digit () |
| 562 | "Test time-stamp format %Y." | 562 | "Test `time-stamp' format %Y." |
| 563 | (with-time-stamp-test-env | 563 | (with-time-stamp-test-env |
| 564 | ;; implemented since 1997, recommended since 2019 | 564 | ;; implemented since 1997, recommended since 2019 |
| 565 | (should (equal (time-stamp-string "%Y" ref-time1) "2006")) | 565 | (should (equal (time-stamp-string "%Y" ref-time1) "2006")) |
| @@ -568,7 +568,7 @@ | |||
| 568 | (should (equal (time-stamp-string "%02Y" ref-time1) "2006")))) | 568 | (should (equal (time-stamp-string "%02Y" ref-time1) "2006")))) |
| 569 | 569 | ||
| 570 | (ert-deftest time-stamp-format-am-pm () | 570 | (ert-deftest time-stamp-format-am-pm () |
| 571 | "Test time-stamp formats for AM and PM strings." | 571 | "Test `time-stamp' formats for AM and PM strings." |
| 572 | (with-time-stamp-test-env | 572 | (with-time-stamp-test-env |
| 573 | (let ((pm (format-time-string "%P" ref-time1 t)) | 573 | (let ((pm (format-time-string "%P" ref-time1 t)) |
| 574 | (am (format-time-string "%P" ref-time3 t)) | 574 | (am (format-time-string "%P" ref-time3 t)) |
| @@ -599,14 +599,14 @@ | |||
| 599 | (should (equal (time-stamp-string "%^P" ref-time3) ""))))) | 599 | (should (equal (time-stamp-string "%^P" ref-time3) ""))))) |
| 600 | 600 | ||
| 601 | (ert-deftest time-stamp-format-day-number-in-week () | 601 | (ert-deftest time-stamp-format-day-number-in-week () |
| 602 | "Test time-stamp formats for day number in week." | 602 | "Test `time-stamp' formats for day number in week." |
| 603 | (with-time-stamp-test-env | 603 | (with-time-stamp-test-env |
| 604 | (should (equal (time-stamp-string "%w" ref-time1) "1")) | 604 | (should (equal (time-stamp-string "%w" ref-time1) "1")) |
| 605 | (should (equal (time-stamp-string "%w" ref-time2) "5")) | 605 | (should (equal (time-stamp-string "%w" ref-time2) "5")) |
| 606 | (should (equal (time-stamp-string "%w" ref-time3) "0")))) | 606 | (should (equal (time-stamp-string "%w" ref-time3) "0")))) |
| 607 | 607 | ||
| 608 | (ert-deftest time-stamp-format-time-zone-name () | 608 | (ert-deftest time-stamp-format-time-zone-name () |
| 609 | "Test time-stamp format %Z." | 609 | "Test `time-stamp' format %Z." |
| 610 | (with-time-stamp-test-env | 610 | (with-time-stamp-test-env |
| 611 | (let ((UTC-abbr (format-time-string "%Z" ref-time1 t)) | 611 | (let ((UTC-abbr (format-time-string "%Z" ref-time1 t)) |
| 612 | (utc-abbr (format-time-string "%#Z" ref-time1 t))) | 612 | (utc-abbr (format-time-string "%#Z" ref-time1 t))) |
| @@ -619,7 +619,7 @@ | |||
| 619 | (should (equal (time-stamp-string "%^#Z" ref-time1) utc-abbr))))) | 619 | (should (equal (time-stamp-string "%^#Z" ref-time1) utc-abbr))))) |
| 620 | 620 | ||
| 621 | (ert-deftest time-stamp-format-time-zone-offset () | 621 | (ert-deftest time-stamp-format-time-zone-offset () |
| 622 | "Test time-stamp legacy format %z and spot-test new offset format %5z." | 622 | "Test `time-stamp' legacy format %z and spot-test new offset format %5z." |
| 623 | (with-time-stamp-test-env | 623 | (with-time-stamp-test-env |
| 624 | (let ((utc-abbr (format-time-string "%#Z" ref-time1 t))) | 624 | (let ((utc-abbr (format-time-string "%#Z" ref-time1 t))) |
| 625 | ;; recommended 1995-2019, warned since 2019, will change | 625 | ;; recommended 1995-2019, warned since 2019, will change |
| @@ -644,7 +644,7 @@ | |||
| 644 | (should (equal (time-stamp-string "%9::z" ref-time1) "+00:00:00")))) | 644 | (should (equal (time-stamp-string "%9::z" ref-time1) "+00:00:00")))) |
| 645 | 645 | ||
| 646 | (ert-deftest time-stamp-format-non-date-conversions () | 646 | (ert-deftest time-stamp-format-non-date-conversions () |
| 647 | "Test time-stamp formats for non-date items." | 647 | "Test `time-stamp' formats for non-date items." |
| 648 | (with-time-stamp-test-env | 648 | (with-time-stamp-test-env |
| 649 | (with-time-stamp-system-name "test-system-name.example.org" | 649 | (with-time-stamp-system-name "test-system-name.example.org" |
| 650 | ;; implemented and recommended since 1995 | 650 | ;; implemented and recommended since 1995 |
| @@ -682,22 +682,22 @@ | |||
| 682 | (ert-deftest time-stamp-format-ignored-modifiers () | 682 | (ert-deftest time-stamp-format-ignored-modifiers () |
| 683 | "Test additional args allowed (but ignored) to allow for future expansion." | 683 | "Test additional args allowed (but ignored) to allow for future expansion." |
| 684 | (with-time-stamp-test-env | 684 | (with-time-stamp-test-env |
| 685 | (let ((May (format-time-string "%B" ref-time3 t))) | 685 | (let ((May (format-time-string "%B" ref-time3 t))) |
| 686 | ;; allowed modifiers | 686 | ;; allowed modifiers |
| 687 | (should (equal (time-stamp-string "%.,@+*EO (stuff)B" ref-time3) May)) | 687 | (should (equal (time-stamp-string "%.,@+*EO (stuff)B" ref-time3) May)) |
| 688 | ;; parens nest | 688 | ;; parens nest |
| 689 | (should (equal (time-stamp-string "%(st(u)ff)B" ref-time3) May)) | 689 | (should (equal (time-stamp-string "%(st(u)ff)B" ref-time3) May)) |
| 690 | ;; escaped parens do not change the nesting level | 690 | ;; escaped parens do not change the nesting level |
| 691 | (should (equal (time-stamp-string "%(st\\)u\\(ff)B" ref-time3) May)) | 691 | (should (equal (time-stamp-string "%(st\\)u\\(ff)B" ref-time3) May)) |
| 692 | ;; incorrectly nested parens do not crash us | 692 | ;; incorrectly nested parens do not crash us |
| 693 | (should-not (equal (time-stamp-string "%(stuffB" ref-time3) May)) | 693 | (should-not (equal (time-stamp-string "%(stuffB" ref-time3) May)) |
| 694 | (should-not (equal (time-stamp-string "%)B" ref-time3) May)) | 694 | (should-not (equal (time-stamp-string "%)B" ref-time3) May)) |
| 695 | ;; unterminated format does not crash us | 695 | ;; unterminated format does not crash us |
| 696 | (should-not (equal (time-stamp-string "%" ref-time3) May)) | 696 | (should-not (equal (time-stamp-string "%" ref-time3) May)) |
| 697 | ;; not all punctuation is allowed | 697 | ;; not all punctuation is allowed |
| 698 | (should-not (equal (time-stamp-string "%&B" ref-time3) May)) | 698 | (should-not (equal (time-stamp-string "%&B" ref-time3) May)) |
| 699 | (should-not (equal (time-stamp-string "%/B" ref-time3) May)) | 699 | (should-not (equal (time-stamp-string "%/B" ref-time3) May)) |
| 700 | (should-not (equal (time-stamp-string "%;B" ref-time3) May))))) | 700 | (should-not (equal (time-stamp-string "%;B" ref-time3) May))))) |
| 701 | 701 | ||
| 702 | (ert-deftest time-stamp-format-non-conversions () | 702 | (ert-deftest time-stamp-format-non-conversions () |
| 703 | "Test that without a %, the text is copied literally." | 703 | "Test that without a %, the text is copied literally." |
| @@ -740,7 +740,7 @@ | |||
| 740 | (should (equal (time-stamp-string "%H:%M%%%S" ref-time1) "15:04%05"))))) | 740 | (should (equal (time-stamp-string "%H:%M%%%S" ref-time1) "15:04%05"))))) |
| 741 | 741 | ||
| 742 | (ert-deftest time-stamp-format-string-width () | 742 | (ert-deftest time-stamp-format-string-width () |
| 743 | "Test time-stamp string width modifiers." | 743 | "Test `time-stamp' string width modifiers." |
| 744 | (with-time-stamp-test-env | 744 | (with-time-stamp-test-env |
| 745 | (let ((UTC-abbr (format-time-string "%Z" ref-time1 t))) | 745 | (let ((UTC-abbr (format-time-string "%Z" ref-time1 t))) |
| 746 | (should (equal (time-stamp-string "%1%" ref-time3) "%")) | 746 | (should (equal (time-stamp-string "%1%" ref-time3) "%")) |
| @@ -764,14 +764,14 @@ | |||
| 764 | ;;; Tests of helper functions | 764 | ;;; Tests of helper functions |
| 765 | 765 | ||
| 766 | (ert-deftest time-stamp-helper-string-defaults () | 766 | (ert-deftest time-stamp-helper-string-defaults () |
| 767 | "Test that time-stamp-string defaults its format to time-stamp-format." | 767 | "Test that `time-stamp-string' defaults its format to `time-stamp-format'." |
| 768 | (with-time-stamp-test-env | 768 | (with-time-stamp-test-env |
| 769 | (should (equal (time-stamp-string nil ref-time1) | 769 | (should (equal (time-stamp-string nil ref-time1) |
| 770 | (time-stamp-string time-stamp-format ref-time1))) | 770 | (time-stamp-string time-stamp-format ref-time1))) |
| 771 | (should (equal (time-stamp-string 'not-a-string ref-time1) nil)))) | 771 | (should (equal (time-stamp-string 'not-a-string ref-time1) nil)))) |
| 772 | 772 | ||
| 773 | (ert-deftest time-stamp-helper-zone-type-p () | 773 | (ert-deftest time-stamp-helper-zone-type-p () |
| 774 | "Test time-stamp-zone-type-p." | 774 | "Test `time-stamp-zone-type-p'." |
| 775 | (should (time-stamp-zone-type-p t)) | 775 | (should (time-stamp-zone-type-p t)) |
| 776 | (should (time-stamp-zone-type-p nil)) | 776 | (should (time-stamp-zone-type-p nil)) |
| 777 | (should (time-stamp-zone-type-p 'wall)) | 777 | (should (time-stamp-zone-type-p 'wall)) |
| @@ -812,13 +812,13 @@ FORMAT must be time format \"%z\" or some variation thereof. | |||
| 812 | ZONE is as the ZONE argument of the `format-time-string' function. | 812 | ZONE is as the ZONE argument of the `format-time-string' function. |
| 813 | This function is called by 99% of the `time-stamp' \"%z\" unit tests." | 813 | This function is called by 99% of the `time-stamp' \"%z\" unit tests." |
| 814 | (with-time-stamp-test-env | 814 | (with-time-stamp-test-env |
| 815 | (let ((time-stamp-time-zone zone)) | 815 | (let ((time-stamp-time-zone zone)) |
| 816 | ;; Call your favorite time formatter here. | 816 | ;; Call your favorite time formatter here. |
| 817 | ;; For narrower-scope unit testing, | 817 | ;; For narrower-scope unit testing, |
| 818 | ;; instead of calling time-stamp-string here, | 818 | ;; instead of calling time-stamp-string here, |
| 819 | ;; we could directly call (format-time-offset format zone) | 819 | ;; we could directly call (format-time-offset format zone) |
| 820 | (time-stamp-string format) | 820 | (time-stamp-string format) |
| 821 | ))) | 821 | ))) |
| 822 | 822 | ||
| 823 | (defun format-time-offset (format offset-secs) | 823 | (defun format-time-offset (format offset-secs) |
| 824 | "Use FORMAT to format the time zone represented by OFFSET-SECS. | 824 | "Use FORMAT to format the time zone represented by OFFSET-SECS. |
| @@ -853,14 +853,15 @@ and is called by some low-level `time-stamp' \"%z\" unit tests." | |||
| 853 | trailing-string))) | 853 | trailing-string))) |
| 854 | 854 | ||
| 855 | (defun fz-make+zone (h &optional m s) | 855 | (defun fz-make+zone (h &optional m s) |
| 856 | "Create a non-negative offset." | 856 | "Create a non-negative offset from interval H M S." |
| 857 | (declare (pure t)) | 857 | (declare (pure t)) |
| 858 | (let ((m (or m 0)) | 858 | (let ((m (or m 0)) |
| 859 | (s (or s 0))) | 859 | (s (or s 0))) |
| 860 | (+ (* 3600 h) (* 60 m) s))) | 860 | (+ (* 3600 h) (* 60 m) s))) |
| 861 | 861 | ||
| 862 | (defun fz-make-zone (h &optional m s) | 862 | (defun fz-make-zone (h &optional m s) |
| 863 | "Create a negative offset. The arguments are all non-negative." | 863 | "Create a negative offset. |
| 864 | The interval arguments H M and S are all non-negative." | ||
| 864 | (declare (pure t)) | 865 | (declare (pure t)) |
| 865 | (- (fz-make+zone h m s))) | 866 | (- (fz-make+zone h m s))) |
| 866 | 867 | ||
| @@ -1071,7 +1072,7 @@ the other expected results for hours greater than 99 with non-zero seconds." | |||
| 1071 | ;; The legacy exception for %z in time-stamp will need to remain | 1072 | ;; The legacy exception for %z in time-stamp will need to remain |
| 1072 | ;; through at least 2024 and Emacs 28. | 1073 | ;; through at least 2024 and Emacs 28. |
| 1073 | (ert-deftest formatz-%z-spotcheck () | 1074 | (ert-deftest formatz-%z-spotcheck () |
| 1074 | "Spot-check internal implementation of time-stamp format %z." | 1075 | "Spot-check internal implementation of `time-stamp' format %z." |
| 1075 | (should (equal (format-time-offset "%z" (fz-make+zone 0)) "+0000")) | 1076 | (should (equal (format-time-offset "%z" (fz-make+zone 0)) "+0000")) |
| 1076 | (should (equal (format-time-offset "%z" (fz-make+zone 0 30)) "+0030")) | 1077 | (should (equal (format-time-offset "%z" (fz-make+zone 0 30)) "+0030")) |
| 1077 | (should (equal (format-time-offset "%z" (fz-make+zone 0 0 30)) "+000030")) | 1078 | (should (equal (format-time-offset "%z" (fz-make+zone 0 0 30)) "+000030")) |