-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathelcron-test.el
63 lines (57 loc) · 2.55 KB
/
elcron-test.el
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
;;; elcron-test.el --- Unit-tests for elcron.el -*- lexical-binding:t -*-
;;
;; Author: Al Haji-Ali <abdo.haji.ali@gmail.com>
;; URL: https://github.com/haji-ali/elcron.git
;; Version: 0.1.0
;; Package-Requires: ((emacs "26.1"))
;; Keywords: convenience
;;
;; This file is not part of GNU Emacs.
;;
;; This program is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.
;;
;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;;
;; You should have received a copy of the GNU General Public License
;; along with this program. If not, see <http://www.gnu.org/licenses/>.
;;
;;; Code:
(require 'ert)
(require 'elcron)
(ert-deftest elcron-test-parser ()
(should (equal
(elcron--normalize "0 0/5 14,18,3-39,52 * JAN,MAR,SEP MON-FRI 2002-2011 LW")
'[0 (/ 0 5) (14 18 (- 3 39) 52) * (jan mar sep)
(- mon fri) (- 2002 2011) (W L)]))
(should (equal
(elcron--normalize "L 3L 3W */3 2#2 ? W LW")
'[L (L 3) (W 3) (/ nil 3) (\# 2 2) \? ERROR (W L)])))
(ert-deftest elcron-test-next ()
(cl-flet* ((check (x y &optional time)
(let* ((time (or time '(9 12 18 11 1 2023 3 nil 0)))
(res (elcron-same-or-next time x)))
(and (equal (butlast res 3) y)
(equal (butlast (elcron-same-or-next res x) 3) y)))))
(should (check '[0] '(0 13 18 11 1 2023)))
(should (check '[0 0] '(0 0 19 11 1 2023)))
(should (check '[3 0 3] '(3 0 3 12 1 2023)))
(should (check '[* * * * 3 tue] '(0 0 0 7 3 2023)))
(should (check '[* * * L * *] '(0 0 0 31 1 2023)))
(should (check '[* * * * * (L fri)] '(0 0 0 27 1 2023)))
(should (check '[* * * * * (\# fri 1)] '(0 0 0 3 2 2023)))
(should (check '[* * * * * (\# fri 2)] '(0 0 0 13 1 2023)))
(should (check '[* * * (W 14) * *] '(0 0 0 13 1 2023)))
(should (check '[* * * (W L) * *] '(0 0 0 31 1 2023)))
(should (check '[* * * (W L) * *] '(0 0 0 28 4 2023)
'(9 12 18 11 4 2023 3 nil 0)))
(should (check '[* * * (W 15) * *] '(0 0 0 16 1 2023)))
(should (check
"0/5 14,18,20-39,52 * * JAN,MAR,SEP MON-FRI 2002-2050"
'(0 14 18 11 1 2023)))))
;;; elcron-test.el ends here