diff options
author | Stefan Kangas <stefan@marxist.se> | 2020-10-22 16:34:11 +0200 |
---|---|---|
committer | Stefan Kangas <stefan@marxist.se> | 2020-10-22 17:33:29 +0200 |
commit | 997ebf91dd6b1f586af44843c37aaad4708011c3 (patch) | |
tree | 103d62cd37ca0de09af45b9b4a4f25d5f02c55f8 /test/lisp/calendar/time-date-tests.el | |
parent | 8dffe61a9c461506311027c99374246440bd97fe (diff) | |
download | emacs-997ebf91dd6b1f586af44843c37aaad4708011c3.tar.gz emacs-997ebf91dd6b1f586af44843c37aaad4708011c3.tar.bz2 emacs-997ebf91dd6b1f586af44843c37aaad4708011c3.zip |
Use lexical-binding in time-date.el and expand tests
* lisp/calendar/time-date.el: Use lexical-binding.
* test/lisp/calendar/time-date-tests.el
(test-obsolete-with-decoded-time-value)
(test-obsolete-encode-time-value, test-format-seconds)
(test-days-to-time, test-seconds-to-string): New tests.
(test-days-in-month, test-time-since, test-time-decoded-period):
Expand test with a few more values.
Diffstat (limited to 'test/lisp/calendar/time-date-tests.el')
-rw-r--r-- | test/lisp/calendar/time-date-tests.el | 52 |
1 files changed, 51 insertions, 1 deletions
diff --git a/test/lisp/calendar/time-date-tests.el b/test/lisp/calendar/time-date-tests.el index 233d43cd01a..3f8954a8ff9 100644 --- a/test/lisp/calendar/time-date-tests.el +++ b/test/lisp/calendar/time-date-tests.el @@ -22,19 +22,67 @@ (require 'ert) (require 'time-date) +(ert-deftest test-obsolete-with-decoded-time-value () + (with-suppressed-warnings ((obsolete with-decoded-time-value)) + (with-decoded-time-value ((high low micro pico type '(1 2 3 4 5 6 8 8))) + (should (equal (list high low micro pico type) '(1 2 3 4 3)))))) + +(ert-deftest test-obsolete-encode-time-value () + (should (equal (with-suppressed-warnings ((obsolete encode-time-value)) + (encode-time-value 1 2 3 4 0)) + '(1 . 2))) + (should (equal (with-suppressed-warnings ((obsolete encode-time-value)) + (encode-time-value 1 2 3 4 1)) + '(1 2))) + (should (equal (with-suppressed-warnings ((obsolete encode-time-value)) + (encode-time-value 1 2 3 4 2)) + '(1 2 3))) + (should (equal (with-suppressed-warnings ((obsolete encode-time-value)) + (encode-time-value 1 2 3 4 3)) + '(1 2 3 4)))) + (ert-deftest test-leap-year () (should-not (date-leap-year-p 1999)) (should-not (date-leap-year-p 1900)) (should (date-leap-year-p 2000)) (should (date-leap-year-p 2004))) +(ert-deftest test-days-to-time () + (should (equal (days-to-time 0) '(0 0))) + (should (equal (days-to-time 1) '(1 20864))) + (should (equal (days-to-time 999) '(1317 2688))) + (should (equal (days-to-time 0.0) '(0 0 0 0))) + (should (equal (days-to-time 0.5) '(0 43200 0 0))) + (should (equal (days-to-time 1.0) '(1 20864 0 0))) + (should (equal (days-to-time 999.0) '(1317 2688 0 0)))) + +(ert-deftest test-seconds-to-string () + (should (equal (seconds-to-string 0) "0s")) + (should (equal (seconds-to-string 9) "9.00s")) + (should (equal (seconds-to-string 99) "99.00s")) + (should (equal (seconds-to-string 999) "16.65m")) + (should (equal (seconds-to-string 9999) "2.78h")) + (should (equal (seconds-to-string 99999) "27.78h")) + (should (equal (seconds-to-string 999999) "11.57d")) + (should (equal (seconds-to-string 9999999) "115.74d")) + (should (equal (seconds-to-string 99999999) "3.17y")) + (should (equal (seconds-to-string 999999999) "31.69y"))) + (ert-deftest test-days-in-month () (should (= (date-days-in-month 2004 2) 29)) (should (= (date-days-in-month 2004 3) 31)) + (should (= (date-days-in-month 2019 2) 28)) + (should (= (date-days-in-month 2020 12) 31)) (should-not (= (date-days-in-month 1900 3) 28)) + (should-error (date-days-in-month 2020 0)) (should-error (date-days-in-month 2020 15)) (should-error (date-days-in-month 2020 'foo))) +(ert-deftest test-format-seconds () + (should (equal (format-seconds "%y %d %h %m %s %%" 0) "0 0 0 0 0 %")) + (should (equal (format-seconds "%y %d %h %m %s %%" 9999999) "0 115 17 46 39 %")) + (should (equal (format-seconds "%y %d %h %m %z %s %%" 1) " 1 %"))) + (ert-deftest test-ordinal () (should (equal (date-ordinal-to-time 2008 271) '(nil nil nil 27 9 2008 nil nil nil))) @@ -107,7 +155,8 @@ '(12 15 14 8 7 2019 1 t 7200))))) (ert-deftest test-time-since () - (should (time-equal-p 0 (time-since nil)))) + (should (time-equal-p 0 (time-since nil))) + (should (= (cadr (time-since (time-subtract (current-time) 1))) 1))) (ert-deftest test-time-decoded-period () (should (equal (decoded-time-period '(nil nil 1 nil nil nil nil nil nil)) @@ -119,6 +168,7 @@ (should (equal (decoded-time-period '(0 0 0 1 0 0 nil nil nil)) 86400)) (should (equal (decoded-time-period '(0 0 0 0 1 0 nil nil nil)) 2592000)) (should (equal (decoded-time-period '(0 0 0 0 0 1 nil nil nil)) 31536000)) + (should (equal (decoded-time-period '(1 2 3 4 5 6 nil nil nil)) 202532521)) (should (equal (decoded-time-period '((135 . 10) 0 0 0 0 0 nil nil nil)) 13.5))) |