Skip to content

Commit

Permalink
Add test for comments in patterns
Browse files Browse the repository at this point in the history
  • Loading branch information
jfmengels committed Oct 31, 2024
1 parent 4d5bab1 commit 0288306
Showing 1 changed file with 28 additions and 1 deletion.
29 changes: 28 additions & 1 deletion tests/Elm/Parser/PatternTests.elm
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ all =
"""(
-- comment
)"""
|> expectAstWithComments Parser.pattern
|> expectAstWithComments
{ ast = Node { start = { row = 1, column = 1 }, end = { row = 3, column = 5 } } UnitPattern
, comments = [ Node { start = { row = 2, column = 4 }, end = { row = 2, column = 14 } } "-- comment" ]
}
Expand Down Expand Up @@ -79,6 +79,28 @@ all =
)
(Node { start = { row = 1, column = 10 }, end = { row = 1, column = 12 } } <| VarPattern "xs")
)
, test "Uncons with comments" <|
\() ->
"a {-1-} :: {-2-} b {-3-} :: {-4-} tail"
|> expectAstWithComments
{ ast =
Node { start = { row = 1, column = 1 }, end = { row = 1, column = 39 } }
(UnConsPattern
(Node { start = { row = 1, column = 1 }, end = { row = 1, column = 2 } } (VarPattern "a"))
(Node { start = { row = 1, column = 18 }, end = { row = 1, column = 39 } }
(UnConsPattern
(Node { start = { row = 1, column = 18 }, end = { row = 1, column = 19 } } (VarPattern "b"))
(Node { start = { row = 1, column = 35 }, end = { row = 1, column = 39 } } (VarPattern "tail"))
)
)
)
, comments =
[ Node { start = { row = 1, column = 3 }, end = { row = 1, column = 8 } } "{-1-}"
, Node { start = { row = 1, column = 12 }, end = { row = 1, column = 17 } } "{-2-}"
, Node { start = { row = 1, column = 20 }, end = { row = 1, column = 25 } } "{-3-}"
, Node { start = { row = 1, column = 29 }, end = { row = 1, column = 34 } } "{-4-}"
]
}
, test "Empty list" <|
\() ->
"[]"
Expand Down Expand Up @@ -305,6 +327,11 @@ expectAst =
ParserWithCommentsUtil.expectAst Parser.pattern


expectAstWithComments : { ast : Node Pattern, comments : List (Node String) } -> String -> Expect.Expectation
expectAstWithComments =
ParserWithCommentsUtil.expectAstWithComments Parser.pattern


expectInvalid : String -> Expect.Expectation
expectInvalid =
ParserWithCommentsUtil.expectInvalid Parser.pattern

0 comments on commit 0288306

Please sign in to comment.