From: Stefan Kangas Date: Thu, 22 Oct 2020 14:34:11 +0000 (+0200) Subject: Use lexical-binding in time-date.el and expand tests X-Git-Tag: emacs-28.0.90~5483^2 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=997ebf91dd6b1f586af44843c37aaad4708011c3;p=emacs.git 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. --- diff --git a/lisp/calendar/time-date.el b/lisp/calendar/time-date.el index 638d8c1f884..f60c9c2ffd3 100644 --- a/lisp/calendar/time-date.el +++ b/lisp/calendar/time-date.el @@ -1,4 +1,4 @@ -;;; time-date.el --- Date and time handling functions +;;; time-date.el --- Date and time handling functions -*- lexical-binding: t -*- ;; Copyright (C) 1998-2020 Free Software Foundation, Inc. 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)))