Skip to content

Commit

Permalink
DateIgnore: add TaskPaperTag tests
Browse files Browse the repository at this point in the history
  • Loading branch information
roovo committed Feb 4, 2023
1 parent d35731b commit 02e2995
Show file tree
Hide file tree
Showing 3 changed files with 88 additions and 8 deletions.
7 changes: 1 addition & 6 deletions TODO.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
- add flag to GlobalSettings
- store the flag in BoardConfig (for both date and tag board), e.g. DateBoardConfig DateBoardConfig Bool
- in Board.columns use this to set the fileDate to Nothing if needed
- then everything else should just work

- @due(none)
- TaskPaperTag.dueTagParser needs to handle the None case:
- Date | None | NotSpecified
- Dated | DateNone | NotPresent
- this needs to be stored on the TaskItem
- taskItem.due and .dueRataDie need to respect this
- and the rest should just work
Expand Down
7 changes: 6 additions & 1 deletion src/TaskPaperTag.elm
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
module TaskPaperTag exposing (autocompleteTagParser, completedTagParser, dueTagParser, parser)
module TaskPaperTag exposing
( autocompleteTagParser
, completedTagParser
, dueTagParser
, parser
)

import Date exposing (Date)
import Parser as P exposing ((|.), (|=), Parser)
Expand Down
82 changes: 81 additions & 1 deletion tests/TaskPaperTagTests.elm
Original file line number Diff line number Diff line change
@@ -1,15 +1,95 @@
module TaskPaperTagTests exposing (suite)

import Date
import Expect
import Parser
import TaskPaperTag
import Test exposing (..)
import Time


suite : Test
suite =
concat
[ parser
[ autocompleteTagParser
, completedTagParser
, dueTagParser
, parser
]


autocompleteTagParser : Test
autocompleteTagParser =
describe "autocompleteTagParser"
[ test "parsers true value" <|
\() ->
"@autocomplete(true)"
|> Parser.run (TaskPaperTag.autocompleteTagParser identity)
|> Expect.equal (Ok True)
, test "parsers false value" <|
\() ->
"@autocomplete(false)"
|> Parser.run (TaskPaperTag.autocompleteTagParser identity)
|> Expect.equal (Ok False)
, test "fails with the value xXx" <|
\() ->
"@autocomplete(xXx)"
|> Parser.run (TaskPaperTag.autocompleteTagParser identity)
|> Result.toMaybe
|> Expect.equal Nothing
]


completedTagParser : Test
completedTagParser =
describe "completedTagParser"
[ test "parsers a valid dateTime" <|
\() ->
"@completed(2023-01-01T09:00:00)"
|> Parser.run (TaskPaperTag.completedTagParser identity)
|> Result.map Time.posixToMillis
|> Expect.equal (Ok 1672563600000)
, test "parses just a date" <|
\() ->
"@completed(2023-01-01)"
|> Parser.run (TaskPaperTag.completedTagParser identity)
|> Result.map Time.posixToMillis
|> Expect.equal (Ok 1672531200000)
, test "parses if it is a dateTime without seconds" <|
\() ->
"@completed(2023-01-01T00:00)"
|> Parser.run (TaskPaperTag.completedTagParser identity)
|> Result.map Time.posixToMillis
|> Expect.equal (Ok 1672531200000)
, test "fails if it is not a valid dateTime" <|
\() ->
"@completed(2023-01-01T00:00:0)"
|> Parser.run (TaskPaperTag.completedTagParser identity)
|> Result.toMaybe
|> Expect.equal Nothing
]


dueTagParser : Test
dueTagParser =
describe "dueTagParser"
[ test "parsers a valid date" <|
\() ->
"@due(2023-01-01)"
|> Parser.run (TaskPaperTag.dueTagParser identity)
|> Expect.equal (Ok <| Date.fromCalendarDate 2023 Time.Jan 1)
, test "fails to parse an invalid date" <|
\() ->
"@due(2023-02-30)"
|> Parser.run (TaskPaperTag.dueTagParser identity)
|> Result.toMaybe
|> Expect.equal Nothing
, test "fails to parse a dateTime" <|
\() ->
"@due(2023-01-01T00:00:00)"
|> Parser.run (TaskPaperTag.dueTagParser identity)
|> Result.toMaybe
|> Expect.equal Nothing
]


Expand Down

0 comments on commit 02e2995

Please sign in to comment.