Skip to content

Commit 125beba

Browse files
committed
Remove task :done attribute
1 parent f8a97e5 commit 125beba

10 files changed

Lines changed: 33 additions & 35 deletions

File tree

src/plan.janet

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,10 +114,10 @@
114114
(tasks-from-days (days-between plan start-date end-date)))
115115

116116
(defn completed-tasks [plan]
117-
(filter (fn [t] (t :done)) (all-tasks plan)))
117+
(filter (fn [t] (= (t :state) :checked)) (all-tasks plan)))
118118

119119
(defn pending-tasks [plan]
120-
(filter (fn [t] (not (t :done))) (all-tasks plan)))
120+
(filter (fn [t] (= (t :state) :open)) (all-tasks plan)))
121121

122122
(defn has-task-after?
123123
```

src/plan/parser.janet

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
:tasks
4040
{:main (group (any :task))
4141
:task
42-
{:main (replace (* (constant :done) :task-begin
42+
{:main (replace (* (constant :state) :task-begin
4343
" "
4444
(constant :title) (capture (some (if-not (+ "\n" " (missed on") 1)))
4545
(? :task-missed-on-date)
@@ -51,8 +51,8 @@
5151
{:main (* "- " :checkbox)
5252
:checkbox
5353
{:main (+ :checkbox-done :checkbox-pending)
54-
:checkbox-done (* (+ "[x]" "[X]") (constant true))
55-
:checkbox-pending (* "[ ]" (constant false))}}
54+
:checkbox-done (* (+ "[x]" "[X]") (constant :checked))
55+
:checkbox-pending (* "[ ]" (constant :open))}}
5656
:task-missed-on-date (* " (missed on " (constant :missed-on) :date ")")
5757
:task-body
5858
{:main (group (any :task-body-line))

src/plan/serializer.janet

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
(defn- plan-title [plan]
99
(string "# " (plan :title)))
1010

11-
(defn- checkbox [done]
12-
(if done "[X]" "[ ]"))
11+
(defn- checkbox [task]
12+
(if (= (task :state) :checked) "[X]" "[ ]"))
1313

1414
(defn- serialize-event-title [event]
1515
(string "- " (event :title)))
@@ -34,7 +34,7 @@
3434
""))
3535

3636
(defn- serialize-task-title [task]
37-
(string "- " (checkbox (task :done)) " " (task :title) (task-mark task)))
37+
(string "- " (checkbox task) " " (task :title) (task-mark task)))
3838

3939
(defn- serialize-task-body [task]
4040
(def body (task :body))

src/task.janet

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
### ————————————————————————————————————————————————————————————————————————————————————————————————
22
### This module implements task entity and related functions.
3+
###
4+
### A task can have the following states: :checked, :open.
35

46
(import ./date)
57

68
(defn build-task [title done &opt body]
79
(default body @[])
8-
{:title title :body body :done done :state (if done :checked :open)})
10+
{:title title :body body :state (if done :checked :open)})
911

1012
(defn build-scheduled-task [line title schedule]
1113
(def task (build-task title false))

test/commands/schedule_contacts_test.janet

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
(let [day ((plan :days) 0)
1818
task ((day :tasks) 0)]
1919
(test (task :title) "Contact John Doe")
20-
(test (task :done) false)
20+
(test (task :state) :open)
2121
(test (empty? (task :body)) true)))
2222

2323
(deftest "schedules contacts for future"
@@ -33,7 +33,7 @@
3333
(if (= 1 (length (day-2 :tasks)))
3434
(let [task ((day-2 :tasks) 0)]
3535
(test (task :title) "Contact John Doe")
36-
(test (task :done) false)
36+
(test (task :state) :open)
3737
(test (empty? (task :body)) true))))
3838

3939
(deftest "schedules contacts with birthday"
@@ -46,7 +46,7 @@
4646
(let [day ((plan :days) 0)
4747
task ((day :tasks) 0)]
4848
(test (task :title) "Congratulate birthday to John Doe")
49-
(test (task :done) false)
49+
(test (task :state) :open)
5050
(test (empty? (task :body)) true)))
5151

5252
(deftest "schedules contacts with missed birthday"

test/commands/schedule_tasks_test.janet

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@
170170
(let [day ((plan :days) 1)
171171
task ((day :tasks) 0)]
172172
(test (task :title) "Weekly meeting")
173-
(test (task :done) false)
173+
(test (task :state) :open)
174174
(test (task :schedule) "every Monday")))
175175

176176
(deftest "doesn't insert duplicate tasks"
@@ -194,7 +194,7 @@
194194
(let [task ((day :tasks) 0)]
195195
(test (task :title) "Weekly meeting")
196196
(test (d/equal? (d/date 2022 1 17) (task :missed-on)) true)
197-
(test (task :done) false)
197+
(test (task :state) :open)
198198
(test (task :schedule) "every Monday")))))
199199

200200
(deftest "schedules missed monthly tasks"
@@ -221,7 +221,7 @@
221221
(if (not (empty? (day :tasks)))
222222
(let [task ((day :tasks) 0)]
223223
(test (task :title) "Weekly meeting")
224-
(test (task :done) false)
224+
(test (task :state) :open)
225225
(test (task :schedule) "every Monday")))))
226226

227227
(deftest "doesn't schedule tasks that are not scheduled for future day that is not in the plan"

test/examples/todo.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55
## 2020-08-01, Saturday
66

77
- [ ] Develop photos for the grandmother
8-
- [X] Pay bills
8+
- [ ] Pay bills
99

1010
## 2020-07-31, Friday
1111

12-
- [X] Review open pull requests
13-
- [X] Fix flaky test
12+
- [ ] Review open pull requests
13+
- [ ] Fix flaky test

test/plan/parser_test.janet

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -36,31 +36,31 @@
3636
(test (plan :title) "Main TODO")
3737
(let [task (inbox 0)]
3838
(test (task :title) "#home - Fix the lamp")
39-
(test (not (task :done)) true))
39+
(test (task :state) :open))
4040
(let [task (inbox 1)]
4141
(test (task :title) "Update Rust")
42-
(test (not (task :done)) true))
42+
(test (task :state) :open))
4343
(test (= (d/date 2020 8 1) (day-1 :date)) true)
4444
(let [task ((day-1 :tasks) 0)]
4545
(test (task :title) "Develop photos")
46-
(test (not (task :done)) true))
46+
(test (task :state) :open))
4747
(let [task ((day-1 :tasks) 1)]
4848
(test (task :title) "Pay bills")
49-
(test (task :done) true))
49+
(test (task :state) :checked))
5050
(let [task ((day-1 :tasks) 2)]
5151
(test (task :title) "Fix the lamp")
52-
(test (not (task :done)) true)
52+
(test (task :state) :open)
5353
(test (d/equal? (d/date 2020 7 30) (task :missed-on)) true))
5454
(test (= (d/date 2020 7 31) (day-2 :date)) true)
5555
(let [event ((day-2 :events) 0)]
5656
(test (event :title) "Talked to Mike & Molly")
5757
(test (empty? (event :body)) true))
5858
(let [task ((day-2 :tasks) 0)]
5959
(test (task :title) "#work - Review open pull requests")
60-
(test (task :done) true))
60+
(test (task :state) :checked))
6161
(let [task ((day-2 :tasks) 1)]
6262
(test (task :title) "#work - Fix the flaky test")
63-
(test (task :done) true)))
63+
(test (task :state) :checked)))
6464

6565
(deftest "parses a template plan"
6666
(def plan-string
@@ -90,7 +90,7 @@
9090
task ((day :tasks) 0)]
9191
(test (= (d/date 2020 7 30) (day :date)) true)
9292
(test (task :title) "Pay bills")
93-
(test (not (task :done)) true)))
93+
(test (task :state) :open)))
9494

9595
(deftest "parses a plan with one task that has a body"
9696
(def plan-string
@@ -110,7 +110,7 @@
110110
task-body (task :body)]
111111
(test (= (d/date 2020 7 30) (day :date)) true)
112112
(test (task :title) "Pay bills")
113-
(test (not (task :done)) true)
113+
(test (task :state) :open)
114114
(test (task-body 0) "- Electricity")
115115
(test (task-body 1) "- Water")))
116116

@@ -131,9 +131,9 @@
131131
task-2 ((day :tasks) 1)]
132132
(test (= (d/date 2020 7 30) (day :date)) true)
133133
(test (task-1 :title) "Pay bills")
134-
(test (not (task-1 :done)) true)
134+
(test (task-1 :state) :open)
135135
(test (task-2 :title) "Fix the lamp")
136-
(test (task-2 :done) true)))
136+
(test (task-2 :state) :checked)))
137137

138138
(deftest "parses a plan without inbox"
139139
(def plan-string
@@ -206,7 +206,7 @@
206206
(test (event :title) "Talked to Mike & Molly")
207207
(test ((event :body) 0) "- They moved to a new apartment")
208208
(test (task :title) "Fix the lamp")
209-
(test (task :done) true)))
209+
(test (task :state) :checked)))
210210

211211
(deftest "parses a plan with an event without any tasks"
212212
(def plan-string

test/schedule_parser_test.janet

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
(test (length scheduled-tasks) 9)
2727
(let [task (scheduled-tasks 0)]
2828
(test (task :title) "Weekly Meeting")
29-
(test (task :done) false)
29+
(test (task :state) :open)
3030
(test (task :schedule) "every Tuesday"))
3131
(let [task (scheduled-tasks 1)]
3232
(test (task :title) "Puzzle Storm on Lichess")

test/task_test.janet

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
(deftest "builds a new task"
1111
(def task (task/build-task "Weekly meeting" false "Meeting agenda"))
1212
(test (task :title) "Weekly meeting")
13-
(test (task :done) false)
1413
(test (task :body) "Meeting agenda")
1514
(test (task :state) :open))
1615

@@ -23,7 +22,6 @@
2322
(deftest "builds a new scheduled task"
2423
(def task (task/build-scheduled-task 15 "Weekly meeting" "every Tuesday"))
2524
(test (task :title) "Weekly meeting")
26-
(test (task :done) false)
2725
(test (task :state) :open))
2826

2927
## —————————————————————————————————————————————————————————————————————————————————————————————————
@@ -33,7 +31,6 @@
3331
(test (task :title) "Weekly meeting")
3432
(test (task :body) "Meeting agenda")
3533
(test (d/equal? (task :missed-on) date) true)
36-
(test (task :done) false)
3734
(test (task :state) :open))
3835

3936
## —————————————————————————————————————————————————————————————————————————————————————————————————
@@ -43,7 +40,6 @@
4340
(test (task :title) "Weekly meeting")
4441
(test (task :contact) "John Doe")
4542
(test (task :body) "Meeting agenda")
46-
(test (task :done) false)
4743
(test (task :state) :open))
4844

4945
## —————————————————————————————————————————————————————————————————————————————————————————————————

0 commit comments

Comments
 (0)