Skip to content

Commit c439cba

Browse files
committed
Migrate to judge
1 parent 04db4f6 commit c439cba

24 files changed

Lines changed: 634 additions & 660 deletions

.semaphore/semaphore.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,4 @@ blocks:
2323
- cd
2424
- checkout
2525
- sudo jpm deps
26-
- jpm test
26+
- judge

project.janet

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
(declare-project
22
:name "janet"
33
:description "A command line utility for planing your days"
4-
:dependencies [{:repo "https://github.com/pyrmont/testament"}
5-
{:url "https://github.com/ianthehenry/judge.git" :tag "v2.6.1"}
4+
:dependencies [{:url "https://github.com/ianthehenry/judge.git" :tag "v2.6.1"}
65
{:repo "https://github.com/janet-lang/argparse"}])
76

87
(declare-executable

src/commands/schedule_tasks.janet

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,10 @@
2222
(def formatted-date (date/format date true))
2323
(case (task :schedule)
2424
(string "every " (date :week-day)) true
25-
"every weekday" (index-of (date :week-day) weekdays)
25+
"every weekday" (number? (index-of (date :week-day) weekdays))
2626
"every month" (= (date :day) 1)
2727
"every 3 months" (and (= (date :day) 1)
28-
(index-of (date :month) [1 4 7 10]))
28+
(number? (index-of (date :month) [1 4 7 10])))
2929
(string "every year on " (remove-year formatted-date)) true
3030
(string "on " formatted-date) true
3131
"every last day" (date/last-day-of-month? date)

test/commands/backup_test.janet

Lines changed: 26 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,54 @@
1-
(import testament :prefix "" :exit true)
1+
(use judge)
2+
23
(import ../../src/date)
34
(import ../../src/file_repository)
45
(import ../../src/commands/backup :prefix "")
56

67
## ————————————————————————————————————————————————————————————————————————————————————————————————
78
## Test backup-path
89

9-
(deftest backup-path-when-file-does-not-exist
10-
(is (= "test/examples/plan-2020-08-01.md"
11-
(backup-path "test/examples/plan.md" (date/date 2020 8 1)))))
10+
(deftest "when file doesn't exist"
11+
(test (backup-path "test/examples/plan.md" (date/date 2020 8 1))
12+
"test/examples/plan-2020-08-01.md"))
1213

13-
(deftest backup-path-when-plan-path-begins-with-dot
14-
(is (= "./test/examples/plan-2020-08-01.md"
15-
(backup-path "./test/examples/plan.md" (date/date 2020 8 1))))
16-
(is (= "./test/examples/plan-2020-08-02-1.md"
17-
(backup-path "./test/examples/plan.md" (date/date 2020 8 2)))))
14+
(deftest "when plan path begins with dot"
15+
(test (backup-path "./test/examples/plan.md" (date/date 2020 8 1))
16+
"./test/examples/plan-2020-08-01.md")
17+
(test (backup-path "./test/examples/plan.md" (date/date 2020 8 2))
18+
"./test/examples/plan-2020-08-02-1.md"))
1819

19-
(deftest backup-path-when-plan-path-begins-with-two-dots
20-
(is (= "../alas/test/examples/plan-2020-08-01.md"
21-
(backup-path "../alas/test/examples/plan.md" (date/date 2020 8 1))))
22-
(is (= "../alas/test/examples/plan-2020-08-02-1.md"
23-
(backup-path "../alas/test/examples/plan.md" (date/date 2020 8 2)))))
20+
(deftest "when plan path begins with two dots"
21+
(test (backup-path "../alas/test/examples/plan.md" (date/date 2020 8 1))
22+
"../alas/test/examples/plan-2020-08-01.md")
23+
(test (backup-path "../alas/test/examples/plan.md" (date/date 2020 8 2))
24+
"../alas/test/examples/plan-2020-08-02-1.md"))
2425

25-
(deftest backup-path-when-file-exists
26-
(is (= "test/examples/plan-2020-08-02-1.md"
27-
(backup-path "test/examples/plan.md" (date/date 2020 8 2))))
28-
(is (= "test/examples/plan-2020-08-03-2.md"
29-
(backup-path "test/examples/plan.md" (date/date 2020 8 3)))))
26+
(deftest "when file exists"
27+
(test (backup-path "test/examples/plan.md" (date/date 2020 8 2))
28+
"test/examples/plan-2020-08-02-1.md")
29+
(test (backup-path "test/examples/plan.md" (date/date 2020 8 3))
30+
"test/examples/plan-2020-08-03-2.md"))
3031

3132
## ————————————————————————————————————————————————————————————————————————————————————————————————
3233
## Test backup
3334

34-
(deftest backup-plan
35+
(deftest "backup plan"
3536
(def plan-path "test/examples/todo.md")
3637
(def backup-path "test/examples/todo-2020-08-01.md")
3738
(def plan (file_repository/load plan-path))
3839
(backup plan plan-path (date/date 2020 8 1))
39-
(is (os/stat backup-path))
40+
(test (table? (os/stat backup-path)) true)
4041
(os/rm backup-path))
4142

4243
## ————————————————————————————————————————————————————————————————————————————————————————————————
4344
## Test build-command
4445

45-
(deftest build-command-when-not-skipping-backup
46+
(deftest "when not skipping backup"
4647
(def arguments {"stats" true})
4748
(def result (build-command arguments "test/examples/plan.md"))
48-
(is (tuple? (result :command))))
49+
(test (tuple? (result :command)) true))
4950

50-
(deftest build-command-when-skipping-backup
51+
(deftest "when skipping backup"
5152
(def arguments {"skip-backup" true "stats" true})
5253
(def result (build-command arguments "test/examples/plan.md"))
53-
(is (empty? result)))
54-
55-
(run-tests!)
54+
(test (empty? result) true))
Lines changed: 34 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
(import testament :prefix "" :exit true)
1+
(use judge)
2+
23
(import ../../src/date :as "d")
34
(import ../../src/day)
45
(import ../../src/plan)
@@ -7,69 +8,72 @@
78
## —————————————————————————————————————————————————————————————————————————————————————————————————
89
## Test insert-days
910

10-
(deftest insert-day-at-top
11+
(deftest "insert day at the top"
1112
(def plan (plan/build-plan :days @[(day/build-day (d/date 2020 8 3))
1213
(day/build-day (d/date 2020 8 2))]))
1314
(def new-plan (insert-days plan (d/date 2020 8 4) (d/date 2020 8 4)))
1415
(def day-1 (first (new-plan :days)))
15-
(is (= 3 (length (new-plan :days))))
16-
(is (= (d/date 2020 8 4) (day-1 :date)))
17-
(is (empty? (day-1 :tasks))))
16+
(test (length (new-plan :days)) 3)
17+
(test (day-1 :date)
18+
{:day 4 :month 8 :week-day "Tuesday" :year 2020})
19+
(test (empty? (day-1 :tasks)) true))
1820

19-
(deftest insert-three-days-at-top
20-
(print "insert-three-days-at-top")
21+
(deftest "insert three days at the top"
2122
(def plan (plan/build-plan :days @[(day/build-day (d/date 2020 8 3))
2223
(day/build-day (d/date 2020 8 2))]))
2324
(def new-plan (insert-days plan (d/date 2020 8 7) (d/date 2020 8 5)))
2425
(def day-1 (first (new-plan :days)))
25-
(is (= 5 (length (new-plan :days))))
26-
(is (= (d/date 2020 8 7) (day-1 :date))))
26+
(test (length (new-plan :days)) 5)
27+
(test (day-1 :date)
28+
{:day 7 :month 8 :week-day "Friday" :year 2020}))
2729

28-
(deftest insert-days-in-middle
30+
(deftest "insert days in the middle"
2931
(def plan (plan/build-plan :days @[(day/build-day (d/date 2020 8 6))
3032
(day/build-day (d/date 2020 8 2))]))
3133
(def new-plan (insert-days plan (d/date 2020 8 4) (d/date 2020 8 4)))
3234
(def day-2 ((new-plan :days) 1))
33-
(is (= 3 (length (new-plan :days))))
34-
(is (= (d/date 2020 8 4) (day-2 :date))))
35+
(test (length (new-plan :days)) 3)
36+
(test (day-2 :date)
37+
{:day 4 :month 8 :week-day "Tuesday" :year 2020}))
3538

36-
(deftest insert-days-when-today-already-exists
39+
(deftest "insert days when today already exists"
3740
(def plan (plan/build-plan :days @[(day/build-day (d/date 2020 8 6))
3841
(day/build-day (d/date 2020 8 4))]))
3942
(def new-plan (insert-days plan (d/date 2020 8 6) (d/date 2020 8 4)))
4043
(def day-2 ((new-plan :days) 1))
41-
(is (= 3 (length (new-plan :days))))
42-
(is (= (d/date 2020 8 5) (day-2 :date))))
44+
(test (length (new-plan :days)) 3)
45+
(test (day-2 :date)
46+
{:day 5 :month 8 :week-day "Wednesday" :year 2020}))
4347

44-
(deftest insert-days-with-empty-todo
48+
(deftest "insert days with empty todo"
4549
(def plan (plan/build-plan))
4650
(def new-plan (insert-days plan (d/date 2020 8 4) (d/date 2020 8 4)))
47-
(is (= 1 (length (new-plan :days))))
48-
(is (= (d/date 2020 8 4) ((first (new-plan :days)) :date))))
51+
(test (length (new-plan :days)) 1)
52+
(test ((first (new-plan :days)) :date)
53+
{:day 4 :month 8 :week-day "Tuesday" :year 2020}))
4954

50-
(deftest insert-days-with-one-day-in-future
55+
(deftest "insert days with one day in the future"
5156
(def plan (plan/build-plan :days @[(day/build-day (d/date 2020 8 6))]))
5257
(def new-plan (insert-days plan(d/date 2020 8 5) (d/date 2020 8 4)))
5358
(def day-2 ((new-plan :days) 1))
54-
(is (= 3 (length (new-plan :days))))
55-
(is (= (d/date 2020 8 5) (day-2 :date))))
59+
(test (length (new-plan :days)) 3)
60+
(test (day-2 :date)
61+
{:day 5 :month 8 :week-day "Wednesday" :year 2020}))
5662

5763
## —————————————————————————————————————————————————————————————————————————————————————————————————
5864
## Test build-command
5965

60-
(deftest build-command-without-matching-arguments
66+
(deftest "without matching arguments"
6167
(def arguments {"stats" true})
62-
(is (empty? (build-command arguments))))
68+
(test (empty? (build-command arguments)) true))
6369

64-
(deftest build-command-with-correct-arguments
70+
(deftest "with correct arguments"
6571
(def arguments {"insert-days" "3"})
6672
(def result (build-command arguments))
67-
(is (tuple? (result :command))))
73+
(test (tuple? (result :command)) true))
6874

69-
(deftest build-command-with-incorrect-arguments
75+
(deftest "with incorrect arguments"
7076
(def arguments {"insert-days" "three"})
7177
(def result (build-command arguments))
72-
(is (nil? (result :command)))
73-
(is (= "--insert-days argument is not a number." (first (result :errors)))))
74-
75-
(run-tests!)
78+
(test (nil? (result :command)) true)
79+
(test (first (result :errors)) "--insert-days argument is not a number."))
Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
(import testament :prefix "" :exit true)
1+
(use judge)
22

33
(import ../../src/date :as "d")
44
(import ../../src/day)
@@ -9,39 +9,37 @@
99
## —————————————————————————————————————————————————————————————————————————————————————————————————
1010
## Test insert-task
1111

12-
(deftest insert-task-when-day-exists-and-task-does-not-exist
12+
(deftest "when the day exists and the task doesn't exist"
1313
(def plan (plan/build-plan :days @[(day/build-day (d/date 2020 8 10))]))
1414
(def new-plan (insert-task plan (d/date 2020 8 10) "Upgrade OS"))
1515
(def day (first (new-plan :days)))
16-
(is (= 1 (length (day :tasks))))
17-
(is (= "Upgrade OS" ((first (day :tasks)) :title))))
16+
(test (length (day :tasks)) 1)
17+
(test ((first (day :tasks)) :title) "Upgrade OS"))
1818

19-
(deftest insert-task-when-day-does-not-exist
19+
(deftest "when the day doesn't exist"
2020
(def plan (plan/build-plan :days @[(day/build-day (d/date 2020 8 10))]))
2121
(def new-plan (insert-task plan (d/date 2020 8 11) "Upgrade OS"))
22-
(is (= 1 (length (plan :days))))
23-
(is (empty? ((first (plan :days)) :tasks))))
22+
(test (length (plan :days)) 1)
23+
(test (empty? ((first (plan :days)) :tasks)) true))
2424

25-
(deftest insert-taks-when-task-already-exists
25+
(deftest "when the task already exists"
2626
(def day (day/build-day (d/date 2020 8 10)
2727
@[]
2828
@[(task/build-task "Upgrade OS" false)]))
2929
(def plan (plan/build-plan :days @[day]))
3030
(def new-plan (insert-task plan (d/date 2020 8 10) "Upgrade OS"))
3131
(def new-day (first (new-plan :days)))
32-
(is (= 1 (length (new-day :tasks))))
33-
(is (= "Upgrade OS" ((first (new-day :tasks)) :title))))
32+
(test (length (new-day :tasks)) 1)
33+
(test ((first (new-day :tasks)) :title) "Upgrade OS"))
3434

3535
## —————————————————————————————————————————————————————————————————————————————————————————————————
3636
## Test build-command
3737

38-
(deftest build-command-without-matching-arguments
38+
(deftest "without matching arguments"
3939
(def arguments {"stats" true})
40-
(is (empty? (build-command arguments))))
40+
(test (empty? (build-command arguments)) true))
4141

42-
(deftest build-command-with-correct-arguments
42+
(deftest "with correct arguments"
4343
(def arguments {"insert-task" "Upgrade OS"})
4444
(def result (build-command arguments))
45-
(is (tuple? (result :command))))
46-
47-
(run-tests!)
45+
(test (tuple? (result :command)) true))
Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
(import testament :prefix "" :exit true)
1+
(use judge)
22

33
(import ../../src/commands/list_contacts :prefix "")
44
(import ../../src/date :as d)
@@ -7,32 +7,29 @@
77
## ————————————————————————————————————————————————————————————————————————————————————————————————–
88
## Test list-contacts
99

10-
(deftest list-contacts
10+
(deftest "#list-contacts"
1111
(def contacts @[(contact/build-contact "John Doe" :category :a)
1212
(contact/build-contact "Jane Doe" :birthday "03-21")
1313
(contact/build-contact "Marry Doe" :last-contact (d/date 2022 03 15))])
1414
(def lines (list-contacts contacts))
15-
(is (= 3 (length lines)))
16-
(is (= "John Doe,a,," (lines 0)))
17-
(is (= "Jane Doe,,03-21," (lines 1)))
18-
(is (= "Marry Doe,,,2022-03-15" (lines 2))))
15+
(test (length lines) 3)
16+
(test (lines 0) "John Doe,a,,")
17+
(test (lines 1) "Jane Doe,,03-21,")
18+
(test (lines 2) "Marry Doe,,,2022-03-15"))
1919

2020
## ————————————————————————————————————————————————————————————————————————————————————————————————–
2121
## Test build-command
2222

23-
(deftest build-command-without-matching-argument
23+
(deftest "without matching arguments"
2424
(def arguments {"stats" true})
25-
(is (empty? (build-command arguments))))
25+
(test (empty? (build-command arguments)) true))
2626

27-
(deftest build-command-with-correct-arguments
27+
(deftest "with correct arguments"
2828
(def arguments {"list-contacts" "test/examples/contacts"})
2929
(def result (build-command arguments))
30-
(is (tuple? (result :command))))
30+
(test (tuple? (result :command)) true))
3131

32-
(deftest build-command-when-directory-does-not-exist
32+
(deftest "when the directory doesn't exist"
3333
(def arguments {"list-contacts" "test/missing-directory"})
3434
(def result (build-command arguments))
35-
(is (= "--list-contacts directory does not exist." (first (result :errors)))))
36-
37-
38-
(run-tests!)
35+
(test (first (result :errors)) "--list-contacts directory does not exist."))
Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
(import testament :prefix "" :exit true)
1+
(use judge)
22

33
(import ../../src/date :as "d")
44
(import ../../src/plan)
@@ -9,7 +9,7 @@
99
## ————————————————————————————————————————————————————————————————————————————————————————————————
1010
## Test remove-empty-days
1111

12-
(deftest remove-empty-days-in-past
12+
(deftest "removes empty days in the past"
1313
(def plan
1414
(plan/build-plan
1515
:days @[(day/build-day (d/date 2020 8 7))
@@ -18,20 +18,20 @@
1818
(day/build-day (d/date 2020 8 3) @[]
1919
@[(task/build-task "Buy milk" true)])]))
2020
(def new-plan (remove-empty-days plan (d/date 2020 8 6)))
21-
(is (= 2 (length (new-plan :days))))
22-
(is (= (d/date 2020 8 7) (((new-plan :days) 0) :date)))
23-
(is (= (d/date 2020 8 3) (((new-plan :days) 1) :date))))
21+
(test (length (new-plan :days)) 2)
22+
(test (((new-plan :days) 0) :date)
23+
{:day 7 :month 8 :week-day "Friday" :year 2020})
24+
(test (((new-plan :days) 1) :date)
25+
{:day 3 :month 8 :week-day "Monday" :year 2020}))
2426

2527
## ————————————————————————————————————————————————————————————————————————————————————————————————
2628
## Test build-command
2729

28-
(deftest build-command-without-matching-argument
30+
(deftest "doesn't build the command when arguments are not matching"
2931
(def arguments {"stats" true})
30-
(is (empty? (build-command arguments))))
32+
(test (empty? (build-command arguments)) true))
3133

32-
(deftest build-command-with-correct-arguments
34+
(deftest "builds the command when arguments are matching"
3335
(def arguments {"remove-empty-days" true})
3436
(def result (build-command arguments))
35-
(is (tuple? (result :command))))
36-
37-
(run-tests!)
37+
(test (tuple? (result :command)) true))

0 commit comments

Comments
 (0)