123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160 |
- (ert-deftest test-org-duration/to-minutes ()
- "Test `org-duration-to-minutes' specifications."
-
- (should-error (org-duration-to-minutes "1:2"))
-
- (should (= (org-duration-to-minutes "1:01") 61))
- (should (floatp (org-duration-to-minutes "1:01")))
-
- (should (= (org-duration-to-minutes "1:20:30") 80.5))
- (should (= (org-duration-to-minutes "2h 10min") 130))
- (should (= (org-duration-to-minutes "1d 1:02") 1502))
- (should (= (org-duration-to-minutes "2.5h") 150))
-
- (should (= (org-duration-to-minutes "2") 2))
- (should (= (org-duration-to-minutes "2.5") 2.5))
- (should (= (org-duration-to-minutes 1) 1))
-
- (should (= (org-duration-to-minutes "") 0.0))
-
- (should (= 4
- (let ((org-duration-units '(("longmin" . 2)))
- org-duration--unit-re
- org-duration--full-re
- org-duration--mixed-re)
- (org-duration-set-regexps)
- (org-duration-to-minutes "2longmin"))))
- (should (= 61
- (let ((org-duration-units '(("h" . 61)))
- org-duration--unit-re
- org-duration--full-re
- org-duration--mixed-re)
- (org-duration-set-regexps)
- (org-duration-to-minutes "1h"))))
-
-
- (should (= 60
- (let ((org-duration-units '(("h" . 61)))
- org-duration--unit-re
- org-duration--full-re
- org-duration--mixed-re)
- (org-duration-set-regexps)
- (org-duration-to-minutes "1h" t))))
- (should-error (let ((org-duration-units '(("longmin" . 2)))
- org-duration--unit-re
- org-duration--full-re
- org-duration--mixed-re)
- (org-duration-set-regexps)
- (org-duration-to-minutes "2longmin" t))))
- (ert-deftest test-org-duration/from-minutes ()
- "Test `org-duration-from-minutes' specifications."
-
- (should (equal "1:00"
- (let ((org-duration-format 'h:mm))
- (org-duration-from-minutes 60))))
- (should (equal "1:01:30"
- (let ((org-duration-format 'h:mm:ss))
- (org-duration-from-minutes 61.5))))
- (should (equal "1:01"
- (let ((org-duration-format 'h:mm))
- (org-duration-from-minutes 61.5))))
-
- (should (equal "1h"
- (let ((org-duration-format '(("h" . nil) ("min" . nil))))
- (org-duration-from-minutes 60))))
- (should (equal "1h 0min"
- (let ((org-duration-format '(("h" . nil) ("min" . t))))
- (org-duration-from-minutes 60))))
- (should (equal "50min"
- (let ((org-duration-format '(("h" . nil) ("min" . nil))))
- (org-duration-from-minutes 50))))
- (should (equal "0h 50min"
- (let ((org-duration-format '(("h" . t) ("min" . t))))
- (org-duration-from-minutes 50))))
-
- (should (equal "1d 0:10"
- (let ((org-duration-format '(("d" . nil) (special . h:mm))))
- (org-duration-from-minutes (+ (* 24 60) 10)))))
- (should (equal "1d 0:12:30"
- (let ((org-duration-format '(("d" . nil) (special . h:mm:ss))))
- (org-duration-from-minutes (+ (* 24 60) 12.5)))))
-
- (should (equal "1.5h"
- (let ((org-duration-format '(("h" . nil) (special . 1))))
- (org-duration-from-minutes 90))))
- (should (equal "1.50h"
- (let ((org-duration-format '(("h" . nil) (special . 2))))
- (org-duration-from-minutes 90))))
-
-
-
- (should (equal "0.7h"
- (let ((org-duration-format
- '(("h" . t) ("min" . nil) (special . 1))))
- (org-duration-from-minutes 40))))
- (should (equal "40.0min"
- (let ((org-duration-format
- '(("h" . nil) ("min" . nil) (special . 1))))
- (org-duration-from-minutes 40))))
- (should (equal "0.5min"
- (let ((org-duration-format
- '(("h" . nil) ("min" . nil) (special . 1))))
- (org-duration-from-minutes 0.5)))))
- (ert-deftest test-org-duration/p ()
- "Test `org-duration-p' specifications."
-
- (should (org-duration-p "3:12"))
- (should (org-duration-p "123:12"))
- (should (org-duration-p "1:23:45"))
- (should (org-duration-p "3d 3h 4min"))
- (should (org-duration-p "3d 13:35"))
- (should (org-duration-p "2.35h"))
-
- (should-not (org-duration-p "1minute"))
- (should (let ((org-duration-units '(("minute" . 1)))
- org-duration--unit-re
- org-duration--full-re
- org-duration--mixed-re)
- (org-duration-set-regexps)
- (org-duration-p "2minute")))
-
- (should (org-duration-p "2 h"))
-
- (should-not (org-duration-p "3::12"))
- (should-not (org-duration-p "3:2"))
- (should-not (org-duration-p "3:12:4"))
-
- (should-not (org-duration-p "3d 13:35 13h")))
- (ert-deftest test-org-duration/h:mm-only-p ()
- "Test `org-duration-h:mm-only-p' specifications."
- (should (org-duration-h:mm-only-p '("123:31" "1:00")))
- (should-not (org-duration-h:mm-only-p '("123:32" "1h")))
- (should (eq 'h:mm:ss (org-duration-h:mm-only-p '("3:33" "1:23:45")))))
- (provide 'test-org-duration)
|