Skip to content

Commit

Permalink
apply tests for #258 by @jfmengels
Browse files Browse the repository at this point in the history
  • Loading branch information
lue-bird committed Sep 10, 2024
1 parent 8c5a9d6 commit d604554
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 3 deletions.
70 changes: 69 additions & 1 deletion tests/Elm/Parser/ExpressionTests.elm
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ all =
, Node { start = { row = 1, column = 13 }, end = { row = 1, column = 15 } } <| ListExpr []
]
)
, test "application expression with operator" <|
, test "Binary operation" <|
\() ->
"model + 1"
|> expectAst
Expand All @@ -142,6 +142,74 @@ all =
(Node { start = { row = 1, column = 1 }, end = { row = 1, column = 6 } } <| FunctionOrValue [] "model")
(Node { start = { row = 1, column = 9 }, end = { row = 1, column = 10 } } <| Integer 1)
)
, test "Nested binary operations (+ and ==)" <|
\() ->
"count + 1 == 1"
|> expectAst
(Node { start = { row = 1, column = 1 }, end = { row = 1, column = 15 } }
(OperatorApplication "=="
Non
(Node { start = { row = 1, column = 1 }, end = { row = 1, column = 10 } }
(OperatorApplication "+"
Left
(Node { start = { row = 1, column = 1 }, end = { row = 1, column = 6 } } (FunctionOrValue [] "count"))
(Node { start = { row = 1, column = 9 }, end = { row = 1, column = 10 } } (Integer 1))
)
)
(Node { start = { row = 1, column = 14 }, end = { row = 1, column = 15 } } (Integer 1))
)
)
, test "Nested binary operations (+ and /=)" <|
\() ->
"count + 1 /= 1"
|> expectAst
(Node { start = { row = 1, column = 1 }, end = { row = 1, column = 15 } }
(OperatorApplication "/="
Non
(Node { start = { row = 1, column = 1 }, end = { row = 1, column = 10 } }
(OperatorApplication "+"
Left
(Node { start = { row = 1, column = 1 }, end = { row = 1, column = 6 } } (FunctionOrValue [] "count"))
(Node { start = { row = 1, column = 9 }, end = { row = 1, column = 10 } } (Integer 1))
)
)
(Node { start = { row = 1, column = 14 }, end = { row = 1, column = 15 } } (Integer 1))
)
)
, test "Nested binary operations (+ and //)" <|
\() ->
"count + 1 // 2"
|> expectAst
(Node { start = { row = 1, column = 1 }, end = { row = 1, column = 15 } }
(OperatorApplication "+"
Left
(Node { start = { row = 1, column = 1 }, end = { row = 1, column = 6 } } (FunctionOrValue [] "count"))
(Node { start = { row = 1, column = 9 }, end = { row = 1, column = 15 } }
(OperatorApplication "//"
Left
(Node { start = { row = 1, column = 9 }, end = { row = 1, column = 10 } } (Integer 1))
(Node { start = { row = 1, column = 14 }, end = { row = 1, column = 15 } } (Integer 2))
)
)
)
)
, test "Nested binary operations (&& and <|)" <|
\() ->
"condition && condition <| f"
|> expectAst
(Node { start = { row = 1, column = 1 }, end = { row = 1, column = 28 } }
(OperatorApplication "<|"
Right
(Node { start = { row = 1, column = 1 }, end = { row = 1, column = 23 } }
(OperatorApplication "&&"
Right
(Node { start = { row = 1, column = 1 }, end = { row = 1, column = 10 } } (FunctionOrValue [] "condition"))
(Node { start = { row = 1, column = 14 }, end = { row = 1, column = 23 } } (FunctionOrValue [] "condition"))
)
)
(Node { start = { row = 1, column = 27 }, end = { row = 1, column = 28 } } (FunctionOrValue [] "f"))
)
)
, test "application expression 2" <|
\() ->
"(\"\", always (List.concat [ [ fileName ], [] ]))"
Expand Down
9 changes: 7 additions & 2 deletions tests/Elm/Parser/ParserWithCommentsTestUtil.elm
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ expectAst : ParserFast.Parser (WithComments a) -> a -> String -> Expect.Expectat
expectAst parser =
\expected source ->
case ParserFast.run parser source of
Err error ->
Expect.fail ("Expected the source to be parsed correctly:\n" ++ Debug.toString error)
Err deadEnds ->
Expect.fail ("Expected the source to be parsed correctly:\n[ " ++ (List.map deadEndToString deadEnds |> String.join "\n, ") ++ "\n]")

Ok actual ->
Expect.all
Expand All @@ -75,6 +75,11 @@ expectAst parser =
()


deadEndToString : Parser.DeadEnd -> String
deadEndToString { row, col, problem } =
"{ problem: " ++ Debug.toString problem ++ ", row = " ++ String.fromInt row ++ ", col = " ++ String.fromInt col ++ " }"


expectAstWithComments : ParserFast.Parser (WithComments a) -> { ast : a, comments : List (Node String) } -> String -> Expect.Expectation
expectAstWithComments parser =
\expected source ->
Expand Down

0 comments on commit d604554

Please sign in to comment.