Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,17 @@ schedule tasks and help you stay in touch with your contacts.

For more information, visit the the main [Alas
website](https://www.hackberry.dev/alas/).

## Development

Install dependencies with:

```sh
jpm deps
```

Run tests with:

```sh
jpm test
```
1 change: 0 additions & 1 deletion TODO.md

This file was deleted.

18 changes: 10 additions & 8 deletions src/commands/schedule_tasks.janet
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
(import ../file_repository)
(import ../schedule_parser)

(def command "--schedule-tasks")
(def weekdays ["Monday" "Tuesday" "Wednesday" "Thursday" "Friday"])

(defn- remove-year [formatted-date]
Expand Down Expand Up @@ -48,6 +49,9 @@
(task/mark-as-missed task (day :date))))
tasks))

(defn- format-parse-errors [errors]
(map (fn [error] (string command " " (string/ascii-lower error) ".")) errors))

## —————————————————————————————————————————————————————————————————————————————————————————————————
## Public Interface

Expand All @@ -70,12 +74,10 @@
(let [load-file-result (file_repository/load argument)
error (load-file-result :error)]
(if error
{:errors [(string "--schedule-tasks " (string/ascii-lower error))]}
(let [parse-result (schedule_parser/parse (load-file-result :text))]
(if parse-result
(let [schedule (first parse-result)]
(if (empty? schedule)
{:errors ["--schedule-tasks schedule is empty."]}
{:command [schedule-tasks (first parse-result) (date/today)]}))
{:errors ["--schedule-tasks schedule could not be parsed."]}))))
{:errors [(string command " " (string/ascii-lower error))]}
(let [parse-result (schedule_parser/parse (load-file-result :text))
errors (parse-result :errors)]
(if errors
{:errors (format-parse-errors errors)}
{:command [schedule-tasks (parse-result :tasks) (date/today)]}))))
{}))
13 changes: 11 additions & 2 deletions src/schedule_parser.janet
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,16 @@

(defn parse
```
Parses schedule string and returns an array of task entities.
Parses schedule-string and returns a tuple:

- {:tasks tasks} Where tasks is an array of task entities, when parsing was successfull.
- {:errors errors} Where errors is an array of strings.
```
[schedule-string]
(peg/match schedule-grammar schedule-string))
(let [parse-result (peg/match schedule-grammar schedule-string)]
(if parse-result
(let [tasks (first parse-result)]
(if (empty? tasks)
{:errors ["Schedule is empty"]}
{:tasks tasks}))
{:errors ["Schedule can not be parsed"]})))
2 changes: 1 addition & 1 deletion test/commands/schedule_tasks_test.janet
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@
(def arguments {"schedule-tasks" "test/examples/unparsable-schedule.md"})
(def result (build-command arguments))
(is (nil? (result :command)))
(is (= "--schedule-tasks schedule could not be parsed." (first (result :errors)))))
(is (= "--schedule-tasks schedule can not be parsed." (first (result :errors)))))

(deftest build-command-when-schedule-is-empty
(def arguments {"schedule-tasks" "test/examples/empty-schedule.md"})
Expand Down
7 changes: 7 additions & 0 deletions test/examples/schedule-without-date.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Scheduled Tasks

- Weekly Meeting (every Tuesday)
- Deploy the web app (every weekday)
- Pay football practice
- Martha's birthsday (every 05-24)
- Meeting with Jack (on 2022-05-03)
26 changes: 24 additions & 2 deletions test/schedule_parser_test.janet
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
(import ../src/date :as d)
(import ../src/schedule_parser)

## —————————————————————————————————————————————————————————————————————————————————————————————————
## Test parse-schedule

(deftest parse-schedule
(def schedule-string
```
Expand All @@ -11,10 +14,11 @@
- Puzzle Storm on Lichess (every day)
- Deploy the web app (every weekday)
- Pay football practice (every month)
- Martha's birthsday (every 05-24)
- Martha's birthday (every 05-24)
- Meeting with Jack (on 2022-05-03)
```)
(def scheduled-tasks (first (schedule_parser/parse schedule-string)))
(def result (schedule_parser/parse schedule-string))
(def scheduled-tasks (result :tasks))
(is (= 6 (length scheduled-tasks)))
(let [task (scheduled-tasks 0)]
(is (= "Weekly Meeting" (task :title)))
Expand All @@ -29,4 +33,22 @@
(is (= false (task :done)))
(is (= "on 2022-05-03" (task :schedule)))))

(deftest parse-schedule-when-schedule-can-not-be-parsed
(def schedule-string
```
## Schedule

* One (always)
```)
(def result (schedule_parser/parse schedule-string))
(is (= "Schedule can not be parsed" (first (result :errors)))))

(deftest parse-schedule-when-schedule-is-empty
(def schedule-string
```
# Scheduled Tasks
```)
(def result (schedule_parser/parse schedule-string))
(is (= "Schedule is empty" (first (result :errors)))))

(run-tests!)