From: Stephen Gildea Date: Mon, 18 Jan 2021 21:27:22 +0000 (-0800) Subject: time-stamp-tests now pass in more locales X-Git-Tag: emacs-28.0.90~4229 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=35119b2bc0fd602a19fa0b07d305592d139be6a8;p=emacs.git time-stamp-tests now pass in more locales Update time-stamp-tests to use format-time-string to generate the date words (month, day of week, AM/PM) instead of hard-coding English. Now the tests pass in locales other than "C" and US English. Expand the test coverage of modifier characters. --- diff --git a/test/lisp/time-stamp-tests.el b/test/lisp/time-stamp-tests.el index 81488c3df19..4ae3c1917dd 100644 --- a/test/lisp/time-stamp-tests.el +++ b/test/lisp/time-stamp-tests.el @@ -262,40 +262,48 @@ (ert-deftest time-stamp-format-day-of-week () "Test time-stamp formats for named day of week." (with-time-stamp-test-env - ;; implemented and documented since 1997 - (should (equal (time-stamp-string "%3a" ref-time1) "Mon")) - (should (equal (time-stamp-string "%#A" ref-time1) "MONDAY")) - ;; documented 1997-2019 - (should (equal (time-stamp-string "%3A" ref-time1) "MON")) - (should (equal (time-stamp-string "%:a" ref-time1) "Monday")) - ;; implemented since 2001, documented since 2019 - (should (equal (time-stamp-string "%#a" ref-time1) "MON")) - (should (equal (time-stamp-string "%:A" ref-time1) "Monday")) - ;; allowed but undocumented since 2019 (warned 1997-2019) - (should (equal (time-stamp-string "%^A" ref-time1) "MONDAY")) - ;; warned 1997-2019, changed in 2019 - (should (equal (time-stamp-string "%a" ref-time1) "Mon")) - (should (equal (time-stamp-string "%^a" ref-time1) "MON")) - (should (equal (time-stamp-string "%A" ref-time1) "Monday")))) + (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)) + (MONDAY (format-time-string "%^A" ref-time1 t))) + ;; implemented and documented since 1997 + (should (equal (time-stamp-string "%3a" ref-time1) Mon)) + (should (equal (time-stamp-string "%#A" ref-time1) MONDAY)) + ;; documented 1997-2019 + (should (equal (time-stamp-string "%3A" ref-time1) MON)) + (should (equal (time-stamp-string "%:a" ref-time1) Monday)) + ;; implemented since 2001, documented since 2019 + (should (equal (time-stamp-string "%#a" ref-time1) MON)) + (should (equal (time-stamp-string "%:A" ref-time1) Monday)) + ;; allowed but undocumented since 2019 (warned 1997-2019) + (should (equal (time-stamp-string "%^A" ref-time1) MONDAY)) + ;; warned 1997-2019, changed in 2019 + (should (equal (time-stamp-string "%a" ref-time1) Mon)) + (should (equal (time-stamp-string "%^a" ref-time1) MON)) + (should (equal (time-stamp-string "%A" ref-time1) Monday))))) (ert-deftest time-stamp-format-month-name () "Test time-stamp formats for month name." (with-time-stamp-test-env - ;; implemented and documented since 1997 - (should (equal (time-stamp-string "%3b" ref-time1) "Jan")) - (should (equal (time-stamp-string "%#B" ref-time1) "JANUARY")) - ;; documented 1997-2019 - (should (equal (time-stamp-string "%3B" ref-time1) "JAN")) - (should (equal (time-stamp-string "%:b" ref-time1) "January")) - ;; implemented since 2001, documented since 2019 - (should (equal (time-stamp-string "%#b" ref-time1) "JAN")) - (should (equal (time-stamp-string "%:B" ref-time1) "January")) - ;; allowed but undocumented since 2019 (warned 1997-2019) - (should (equal (time-stamp-string "%^B" ref-time1) "JANUARY")) - ;; warned 1997-2019, changed in 2019 - (should (equal (time-stamp-string "%b" ref-time1) "Jan")) - (should (equal (time-stamp-string "%^b" ref-time1) "JAN")) - (should (equal (time-stamp-string "%B" ref-time1) "January")))) + (let ((Jan (format-time-string "%b" ref-time1 t)) + (JAN (format-time-string "%^b" ref-time1 t)) + (January (format-time-string "%B" ref-time1 t)) + (JANUARY (format-time-string "%^B" ref-time1 t))) + ;; implemented and documented since 1997 + (should (equal (time-stamp-string "%3b" ref-time1) Jan)) + (should (equal (time-stamp-string "%#B" ref-time1) JANUARY)) + ;; documented 1997-2019 + (should (equal (time-stamp-string "%3B" ref-time1) JAN)) + (should (equal (time-stamp-string "%:b" ref-time1) January)) + ;; implemented since 2001, documented since 2019 + (should (equal (time-stamp-string "%#b" ref-time1) JAN)) + (should (equal (time-stamp-string "%:B" ref-time1) January)) + ;; allowed but undocumented since 2019 (warned 1997-2019) + (should (equal (time-stamp-string "%^B" ref-time1) JANUARY)) + ;; warned 1997-2019, changed in 2019 + (should (equal (time-stamp-string "%b" ref-time1) Jan)) + (should (equal (time-stamp-string "%^b" ref-time1) JAN)) + (should (equal (time-stamp-string "%B" ref-time1) January))))) (ert-deftest time-stamp-format-day-of-month () "Test time-stamp formats for day of month." @@ -483,14 +491,18 @@ (ert-deftest time-stamp-format-am-pm () "Test time-stamp formats for AM and PM strings." (with-time-stamp-test-env - ;; implemented and documented since 1997 - (should (equal (time-stamp-string "%#p" ref-time1) "pm")) - (should (equal (time-stamp-string "%#p" ref-time3) "am")) - (should (equal (time-stamp-string "%P" ref-time1) "PM")) - (should (equal (time-stamp-string "%P" ref-time3) "AM")) - ;; warned 1997-2019, changed in 2019 - (should (equal (time-stamp-string "%p" ref-time1) "PM")) - (should (equal (time-stamp-string "%p" ref-time3) "AM")))) + (let ((pm (format-time-string "%#p" ref-time1 t)) + (am (format-time-string "%#p" ref-time3 t)) + (PM (format-time-string "%p" ref-time1 t)) + (AM (format-time-string "%p" ref-time3 t))) + ;; implemented and documented since 1997 + (should (equal (time-stamp-string "%#p" ref-time1) pm)) + (should (equal (time-stamp-string "%#p" ref-time3) am)) + (should (equal (time-stamp-string "%P" ref-time1) PM)) + (should (equal (time-stamp-string "%P" ref-time3) AM)) + ;; warned 1997-2019, changed in 2019 + (should (equal (time-stamp-string "%p" ref-time1) PM)) + (should (equal (time-stamp-string "%p" ref-time3) AM))))) (ert-deftest time-stamp-format-day-number-in-week () "Test time-stamp formats for day number in week." @@ -567,10 +579,15 @@ (ert-deftest time-stamp-format-ignored-modifiers () "Test additional args allowed (but ignored) to allow for future expansion." (with-time-stamp-test-env - ;; allowed modifiers - (should (equal (time-stamp-string "%.,@-+_ ^(stuff)P" ref-time3) "AM")) - ;; not all punctuation is allowed - (should-not (equal (time-stamp-string "%&P" ref-time3) "AM")))) + (let ((May (format-time-string "%B" ref-time3 t))) + ;; allowed modifiers + (should (equal (time-stamp-string "%.,@+ (stuff)B" ref-time3) May)) + ;; parens nest + (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)) + ;; not all punctuation is allowed + (should-not (equal (time-stamp-string "%&B" ref-time3) May))))) (ert-deftest time-stamp-format-non-conversions () "Test that without a %, the text is copied literally." @@ -580,16 +597,22 @@ (ert-deftest time-stamp-format-string-width () "Test time-stamp string width modifiers." (with-time-stamp-test-env - ;; strings truncate on the right or are blank-padded on the left - (should (equal (time-stamp-string "%0P" ref-time3) "")) - (should (equal (time-stamp-string "%1P" ref-time3) "A")) - (should (equal (time-stamp-string "%2P" ref-time3) "AM")) - (should (equal (time-stamp-string "%3P" ref-time3) " AM")) - (should (equal (time-stamp-string "%0%" ref-time3) "")) - (should (equal (time-stamp-string "%1%" ref-time3) "%")) - (should (equal (time-stamp-string "%2%" ref-time3) " %")) - (should (equal (time-stamp-string "%#3a" ref-time3) "SUN")) - (should (equal (time-stamp-string "%#3b" ref-time2) "NOV")))) + (let ((May (format-time-string "%b" ref-time3 t)) + (SUN (format-time-string "%^a" ref-time3 t)) + (NOV (format-time-string "%^b" ref-time2 t))) + ;; strings truncate on the right or are blank-padded on the left + (should (equal (time-stamp-string "%0b" ref-time3) "")) + (should (equal (time-stamp-string "%1b" ref-time3) (substring May 0 1))) + (should (equal (time-stamp-string "%2b" ref-time3) (substring May 0 2))) + (should (equal (time-stamp-string "%3b" ref-time3) May)) + (should (equal (time-stamp-string "%4b" ref-time3) (concat " " May))) + (should (equal (time-stamp-string "%0%" ref-time3) "")) + (should (equal (time-stamp-string "%1%" ref-time3) "%")) + (should (equal (time-stamp-string "%2%" ref-time3) " %")) + (should (equal (time-stamp-string "%9%" ref-time3) " %")) + (should (equal (time-stamp-string "%10%" ref-time3) " %")) + (should (equal (time-stamp-string "%#3a" ref-time3) SUN)) + (should (equal (time-stamp-string "%#3b" ref-time2) NOV))))) ;;; Tests of helper functions