emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

master 9e70520: time-stamp: improve unit-test coverage


From: Stephen Gildea
Subject: master 9e70520: time-stamp: improve unit-test coverage
Date: Sun, 30 May 2021 01:57:27 -0400 (EDT)

branch: master
commit 9e705206aca6f21f5b507af174cb12655dfa6b6b
Author: Stephen Gildea <stepheng+emacs@gildea.com>
Commit: Stephen Gildea <stepheng+emacs@gildea.com>

    time-stamp: improve unit-test coverage
    
    * test/lisp/time-stamp-tests.el (time-stamp-format-year-4digit,
    time-stamp-format-ignored-modifiers): Improve coverage with more cases.
    (time-stamp-format-multiple-conversions): New test.
---
 test/lisp/time-stamp-tests.el | 35 ++++++++++++++++++++++++++++++++++-
 1 file changed, 34 insertions(+), 1 deletion(-)

diff --git a/test/lisp/time-stamp-tests.el b/test/lisp/time-stamp-tests.el
index 4ae3c19..c021353 100644
--- a/test/lisp/time-stamp-tests.el
+++ b/test/lisp/time-stamp-tests.el
@@ -486,7 +486,10 @@
   "Test time-stamp format %Y."
   (with-time-stamp-test-env
     ;; implemented since 1997, documented since 2019
-    (should (equal (time-stamp-string "%Y" ref-time1) "2006"))))
+    (should (equal (time-stamp-string "%Y" ref-time1) "2006"))
+    ;; numbers do not truncate
+    (should (equal (time-stamp-string "%2Y" ref-time1) "2006"))
+    (should (equal (time-stamp-string "%02Y" ref-time1) "2006"))))
 
 (ert-deftest time-stamp-format-am-pm ()
   "Test time-stamp formats for AM and PM strings."
@@ -586,6 +589,9 @@
      (should (equal (time-stamp-string "%(st(u)ff)B" ref-time3) May))
      ;; escaped parens do not change the nesting level
      (should (equal (time-stamp-string "%(st\\)u\\(ff)B" ref-time3) May))
+     ;; incorrectly nested parens do not crash us
+     (should-not (equal (time-stamp-string "%(stuffB" ref-time3) May))
+     (should-not (equal (time-stamp-string "%)B" ref-time3) May))
      ;; not all punctuation is allowed
      (should-not (equal (time-stamp-string "%&B" ref-time3) May)))))
 
@@ -594,6 +600,33 @@
   (with-time-stamp-test-env
     (should (equal (time-stamp-string "No percent" ref-time1) "No percent"))))
 
+(ert-deftest time-stamp-format-multiple-conversions ()
+  "Tests that multiple %-conversions are independent."
+  (with-time-stamp-test-env
+    (let ((Mon (format-time-string "%a" ref-time1 t))
+          (MON (format-time-string "%^a" ref-time1 t))
+          (Monday (format-time-string "%A" ref-time1 t)))
+      ;; change-case flag is independent
+      (should (equal (time-stamp-string "%a.%#a.%a" ref-time1)
+                     (concat Mon "." MON "." Mon)))
+      ;; up-case flag is independent
+      (should (equal (time-stamp-string "%a.%^a.%a" ref-time1)
+                     (concat Mon "." MON "." Mon)))
+      ;; underscore flag is independent
+      (should (equal (time-stamp-string "%_d.%d.%_d" ref-time1) " 2.02. 2"))
+      ;; minus flag is independendent
+      (should (equal (time-stamp-string "%d.%-d.%d" ref-time1) "02.2.02"))
+      ;; 0 flag is independendent
+      (should (equal (time-stamp-string "%2d.%02d.%2d" ref-time1) " 2.02. 2"))
+      ;; field width is independent
+      (should (equal
+               (time-stamp-string "%6Y.%Y.%6Y" ref-time1) "  2006.2006.  
2006"))
+      ;; colon modifier is independent
+      (should (equal (time-stamp-string "%a.%:a.%a" ref-time1)
+                     (concat Mon "." Monday "." Mon)))
+      ;; format letter is independent
+      (should (equal (time-stamp-string "%H:%M" ref-time1) "15:04")))))
+
 (ert-deftest time-stamp-format-string-width ()
   "Test time-stamp string width modifiers."
   (with-time-stamp-test-env



reply via email to

[Prev in Thread] Current Thread [Next in Thread]