aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorStephen Gildea2025-02-07 09:17:26 -0800
committerStephen Gildea2025-02-07 09:18:04 -0800
commit280b25e0096bb97fb473a8da9b4635fb2d6e5385 (patch)
tree5788c654020f7e667cc0ce2c189dbc55246926fe /test
parenta62b58648ac54feb8fb81aefdb0461cb11bf6a81 (diff)
downloademacs-280b25e0096bb97fb473a8da9b4635fb2d6e5385.tar.gz
emacs-280b25e0096bb97fb473a8da9b4635fb2d6e5385.zip
time-stamp: Better handling of some edge cases
* lisp/time-stamp.el (time-stamp-count): Require confirmation if large. (time-stamp-once): Correctly handle a start regexp matching 0 chars. * test/lisp/time-stamp-tests.el (time-stamp-custom-start): New test.
Diffstat (limited to 'test')
-rw-r--r--test/lisp/time-stamp-tests.el36
1 files changed, 31 insertions, 5 deletions
diff --git a/test/lisp/time-stamp-tests.el b/test/lisp/time-stamp-tests.el
index a7aa00dc267..f4fcce3e957 100644
--- a/test/lisp/time-stamp-tests.el
+++ b/test/lisp/time-stamp-tests.el
@@ -138,6 +138,31 @@
138 (iter-yield-from (time-stamp-test-pattern-sequential)) 138 (iter-yield-from (time-stamp-test-pattern-sequential))
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-start ()
142 "Test that `time-stamp' isn't stuck by a start matching 0 characters."
143 (with-time-stamp-test-env
144 (with-time-stamp-test-time ref-time1
145 (let ((time-stamp-pattern "^%Y-%m-%d<-TS")) ;start matches 0 chars
146 (with-temp-buffer
147 (insert "\n<-TS\n")
148 ;; we should advance to line 2 and find the template
149 (time-stamp)
150 (should (equal (buffer-string) "\n2006-01-02<-TS\n"))))
151 (let ((time-stamp-pattern "\\b%Y-%m-%d\\b") ;start and end match 0 chars
152 (time-stamp-count 2))
153 (with-temp-buffer
154 (insert "..")
155 ;; the two time stamps should be in different places
156 (time-stamp)
157 (should (equal (buffer-string) "2006-01-02..2006-01-02"))))
158 (let ((time-stamp-pattern "::%S\\_>") ;end matches 0 chars
159 (time-stamp-count 2))
160 (with-temp-buffer
161 (insert "::0::0")
162 ;; the second template should be found immediately after the first
163 (time-stamp)
164 (should (equal (buffer-string) "::05::05")))))))
165
141(ert-deftest time-stamp-custom-pattern () 166(ert-deftest time-stamp-custom-pattern ()
142 "Test that `time-stamp-pattern' is parsed correctly." 167 "Test that `time-stamp-pattern' is parsed correctly."
143 (iter-do (pattern-parts (time-stamp-test-pattern-all)) 168 (iter-do (pattern-parts (time-stamp-test-pattern-all))
@@ -246,17 +271,17 @@
246 (let ((time-stamp-start "TS: <") 271 (let ((time-stamp-start "TS: <")
247 (time-stamp-format "%Y-%m-%d") 272 (time-stamp-format "%Y-%m-%d")
248 (time-stamp-count 0) ;changed later in the test 273 (time-stamp-count 0) ;changed later in the test
249 (buffer-expected-once "TS: <2006-01-02>\nTS: <>") 274 (buffer-expected-once "TS: <2006-01-02>TS: <>")
250 (buffer-expected-twice "TS: <2006-01-02>\nTS: <2006-01-02>")) 275 (buffer-expected-twice "TS: <2006-01-02>TS: <2006-01-02>"))
251 (with-time-stamp-test-time ref-time1 276 (with-time-stamp-test-time ref-time1
252 (with-temp-buffer 277 (with-temp-buffer
253 (insert "TS: <>\nTS: <>") 278 (insert "TS: <>TS: <>")
254 (time-stamp) 279 (time-stamp)
255 ;; even with count = 0, expect one time stamp 280 ;; even with count = 0, expect one time stamp
256 (should (equal (buffer-string) buffer-expected-once))) 281 (should (equal (buffer-string) buffer-expected-once)))
257 (with-temp-buffer 282 (with-temp-buffer
258 (setq time-stamp-count 1) 283 (setq time-stamp-count 1)
259 (insert "TS: <>\nTS: <>") 284 (insert "TS: <>TS: <>")
260 (time-stamp) 285 (time-stamp)
261 (should (equal (buffer-string) buffer-expected-once)) 286 (should (equal (buffer-string) buffer-expected-once))
262 287
@@ -698,7 +723,7 @@
698 (should (equal (time-stamp-string "%5z" ref-time1) "+0000")) 723 (should (equal (time-stamp-string "%5z" ref-time1) "+0000"))
699 (let ((time-stamp-time-zone "PST8")) 724 (let ((time-stamp-time-zone "PST8"))
700 (should (equal (time-stamp-string "%5z" ref-time1) "-0800"))) 725 (should (equal (time-stamp-string "%5z" ref-time1) "-0800")))
701 (let ((time-stamp-time-zone "HST10")) 726 (let ((time-stamp-time-zone '(-36000 "HST")))
702 (should (equal (time-stamp-string "%5z" ref-time1) "-1000"))) 727 (should (equal (time-stamp-string "%5z" ref-time1) "-1000")))
703 (let ((time-stamp-time-zone "CET-1")) 728 (let ((time-stamp-time-zone "CET-1"))
704 (should (equal (time-stamp-string "%5z" ref-time1) "+0100"))) 729 (should (equal (time-stamp-string "%5z" ref-time1) "+0100")))
@@ -887,6 +912,7 @@
887 (should (safe-local-variable-p 'time-stamp-inserts-lines t)) 912 (should (safe-local-variable-p 'time-stamp-inserts-lines t))
888 (should-not (safe-local-variable-p 'time-stamp-inserts-lines 17)) 913 (should-not (safe-local-variable-p 'time-stamp-inserts-lines 17))
889 (should (safe-local-variable-p 'time-stamp-count 2)) 914 (should (safe-local-variable-p 'time-stamp-count 2))
915 (should-not (safe-local-variable-p 'time-stamp-count 100))
890 (should-not (safe-local-variable-p 'time-stamp-count t)) 916 (should-not (safe-local-variable-p 'time-stamp-count t))
891 (should (safe-local-variable-p 'time-stamp-pattern "a string")) 917 (should (safe-local-variable-p 'time-stamp-pattern "a string"))
892 (should-not (safe-local-variable-p 'time-stamp-pattern 17))) 918 (should-not (safe-local-variable-p 'time-stamp-pattern 17)))