File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1- # ## ————————————————————————————————————————————————————————————————————————————
1+ # ## ————————————————————————————————————————————————————————————————————————————————————————————————
22# ## This module implements a PEG parser that parses schedule string into
33# ## task entities.
44
99 :title (* " # " (some (+ :w + :s +)))
1010 :tasks (group (any :task ))
1111 :task (replace (* " - " :task-title :task-schedule (? " \n " )) ,task/build-scheduled-task )
12- :task-title (replace (capture (some (if-not " (" 1 ))) ,string/trim )
12+ :task-title (replace (capture (some (if-not ( + " (" " \n " ) 1 ))) ,string/trim )
1313 :task-schedule (* " (" (replace (capture (some (+ :w + :s + " -" ))) ,string/trim ) " )" )})
1414
15- # # —————————————————————————————————————————————————————————————————————————————
15+ (defn- task-lines-count
16+ ```
17+ Returns the number of lines that start with '-' in the schedule string.
18+ ```
19+ [schedule-string ]
20+ (length (filter (fn [line ] (string/has-prefix? " -" line ))
21+ (string/split " \n " schedule-string ))))
22+
23+ # # —————————————————————————————————————————————————————————————————————————————————————————————————
1624# # Public Interface
1725
1826(defn parse
2836 (let [tasks (first parse-result )]
2937 (if (empty? tasks )
3038 {:errors [" Schedule is empty" ]}
31- {:tasks tasks }))
39+ (do
40+ (if (= (length tasks ) (task-lines-count schedule-string ))
41+ {:tasks tasks }
42+ {:errors [(string " Schedule can not be parsed - last parsed task is \" "
43+ ((last tasks ) :title )
44+ " \" " )]}))))
3245 {:errors [" Schedule can not be parsed" ]})))
Original file line number Diff line number Diff line change 4343 (def result (schedule_parser/parse schedule-string ))
4444 (is (= " Schedule can not be parsed" (first (result :errors )))))
4545
46+ (deftest parse-schedule-when-task-has-multiple-lines
47+ (def schedule-string
48+ ```
49+ # Scheduled Tasks
50+
51+ - Weekly Meeting (every Tuesday)
52+ - Puzzle Storm on Lichess
53+ - Deploy the web app (every weekday)
54+ ``` )
55+ (def result (schedule_parser/parse schedule-string ))
56+ (is (= " Schedule can not be parsed - last parsed task is \" Weekly Meeting\" "
57+ (first (result :errors )))))
58+
4659(deftest parse-schedule-when-schedule-is-empty
4760 (def schedule-string
4861 ```
You can’t perform that action at this time.
0 commit comments