]> git.eshelyaron.com Git - emacs.git/commitdiff
Test format-time-string padding
authorPaul Eggert <eggert@cs.ucla.edu>
Fri, 6 Dec 2019 23:36:48 +0000 (15:36 -0800)
committerPaul Eggert <eggert@cs.ucla.edu>
Fri, 6 Dec 2019 23:37:32 +0000 (15:37 -0800)
Adapted from tests written by Stephen Gildea.
* test/src/timefns-tests.el:
(format-time-string-padding-minimal-deletes-unneeded-zeros)
(format-time-string-padding-minimal-retains-needed-zeros)
(format-time-string-padding-spaces)
(format-time-string-padding-zeros-adds-on-insignificant-side):
New tests.

test/src/timefns-tests.el

index 3a18a4a24dd8d5906a31940e8efd91feb201f0b5..827efd38e889b3d6e6b9137e4289891e667aeaf0 100644 (file)
                "2038-01-19 02:14:08")
               (timefns-tests--have-leap-seconds))))
 
+;;; Tests of format-time-string padding
+
+(ert-deftest format-time-string-padding-minimal-deletes-unneeded-zeros ()
+  (let ((ref-time (append (encode-time 0 0 0 15 2 2000) '(123450))))
+    (should (equal (format-time-string "%-:::z" ref-time "FJT-12") "+12"))
+    (should (equal (format-time-string "%-N" ref-time) "12345"))
+    (should (equal (format-time-string "%-6N" ref-time) "12345"))
+    (should (equal (format-time-string "%-m" ref-time) "2")))) ;not "02"
+
+(ert-deftest format-time-string-padding-minimal-retains-needed-zeros ()
+  (let ((ref-time (append (encode-time 0 0 0 20 10 2000) '(3450))))
+    (should (equal (format-time-string "%-z" ref-time "IST-5:30") "+530"))
+    (should (equal (format-time-string "%-4z" ref-time "IST-5:30") "+530"))
+    (should (equal (format-time-string "%4z" ref-time "IST-5:30") "+530"))
+    (should (equal (format-time-string "%-N" ref-time) "00345"))
+    (should (equal (format-time-string "%-3N" ref-time) "003"))
+    (should (equal (format-time-string "%3N" ref-time) "003"))
+    (should (equal (format-time-string "%-m" ref-time) "10")) ;not "1"
+    (should (equal (format-time-string "%-1m" ref-time) "10")) ;not "1"
+    (should (equal (format-time-string "%1m" ref-time) "10")))) ;not "1"
+
+(ert-deftest format-time-string-padding-spaces ()
+  (let ((ref-time (append (encode-time 0 0 0 10 12 2000) '(123000))))
+    (should (equal (format-time-string "%_7z" ref-time "CHA-12:45") "  +1245"))
+    (should (equal (format-time-string "%_6N" ref-time) "123   "))
+    (should (equal (format-time-string "%_9N" ref-time) "123      "))
+    (should (equal (format-time-string "%_12N" ref-time) "123         "))
+    (should (equal (format-time-string "%_m" ref-time) "12"))
+    (should (equal (format-time-string "%_2m" ref-time) "12"))
+    (should (equal (format-time-string "%_3m" ref-time) " 12"))))
+
+(ert-deftest format-time-string-padding-zeros-adds-on-insignificant-side ()
+  "Fractional seconds have a fixed place on the left,
+and any padding must happen on the right.  All other numbers have
+a fixed place on the right and are padded on the left."
+  (let ((ref-time (append (encode-time 0 0 0 10 12 2000) '(123000))))
+    (should (equal (format-time-string "%3m" ref-time) "012"))
+    (should (equal (format-time-string "%7z" ref-time "CHA-12:45") "+001245"))
+    (should (equal (format-time-string "%12N" ref-time) "123000000000"))
+    (should (equal (format-time-string "%9N" ref-time) "123000000"))
+    (should (equal (format-time-string "%6N" ref-time) "123000"))))
+
+
 (ert-deftest time-equal-p-nil-nil ()
   (should (time-equal-p nil nil)))