emacs-diffs
[Top][All Lists]
Advanced

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

master 48f6888: Test format-time-string padding


From: Paul Eggert
Subject: master 48f6888: Test format-time-string padding
Date: Fri, 6 Dec 2019 18:37:37 -0500 (EST)

branch: master
commit 48f688858854d4181a5f92083d4df6d84364a100
Author: Paul Eggert <address@hidden>
Commit: Paul Eggert <address@hidden>

    Test format-time-string padding
    
    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 | 43 +++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 43 insertions(+)

diff --git a/test/src/timefns-tests.el b/test/src/timefns-tests.el
index 3a18a4a..827efd3 100644
--- a/test/src/timefns-tests.el
+++ b/test/src/timefns-tests.el
@@ -121,6 +121,49 @@
                "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)))
 



reply via email to

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