Skip to content

Commit 3113695

Browse files
committed
Raise error when state is not supported
1 parent 9b03b91 commit 3113695

2 files changed

Lines changed: 10 additions & 3 deletions

File tree

src/task.janet

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

64
(import ./date)
75

6+
(def states [:open :checked])
7+
88
(defn build-task [title state &opt body]
99
(default body @[])
10-
{:title title :body body :state state})
10+
(if (index-of state states)
11+
{:title title :body body :state state}
12+
(error (string "task doesn't support the state '" state "'"))))
1113

1214
(defn build-scheduled-task [line title schedule]
1315
(def task (build-task title :open))

test/task_test.janet

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,11 @@
1313
(test (task :body) "Meeting agenda")
1414
(test (task :state) :open))
1515

16+
(deftest "raises an error when the state is not valid"
17+
(test-error
18+
(task/build-task "Weekly meeting" :closed)
19+
"task doesn't support the state 'closed'"))
20+
1621
## —————————————————————————————————————————————————————————————————————————————————————————————————
1722
## Test build-scheduled-task
1823
(deftest "builds a new scheduled task"

0 commit comments

Comments
 (0)