Skip to content

Commit 55de216

Browse files
committed
Update tests; Use try
Tests will succeed now and hopefully demonstrate the use of `try` inside a `many` parser.
1 parent ecb46cd commit 55de216

File tree

1 file changed

+10
-13
lines changed

1 file changed

+10
-13
lines changed

test/Main.purs

+10-13
Original file line numberDiff line numberDiff line change
@@ -39,15 +39,11 @@ nested = fix \p -> (do
3939
parseTest :: forall s a eff. (Show a, Eq a) => s -> a -> Parser s a -> Eff (console :: CONSOLE, assert :: ASSERT | eff) Unit
4040
parseTest input expected p = case runParser input p of
4141
Right actual -> assert (expected == actual)
42-
Left err -> do
43-
print $ "error: " ++ show err
44-
assert false
42+
Left err -> assert' ("error: " ++ show err) false
4543

4644
parseErrorTestPosition :: forall s a eff. (Show a) => Parser s a -> s -> Position -> Eff (console :: CONSOLE, assert :: ASSERT | eff) Unit
4745
parseErrorTestPosition p input expected = case runParser input p of
48-
Right _ -> do
49-
print "error: ParseError expected!"
50-
assert false
46+
Right _ -> assert' "error: ParseError expected!" false
5147
Left (ParseError { position: pos }) -> assert (expected == pos)
5248

5349
opTest :: Parser String String
@@ -95,14 +91,15 @@ isA _ = false
9591

9692
main = do
9793

98-
parseTest "" Nil $ many $ char '\n' *> char '\n'
99-
parseTest "" Nil $ many $ string "\n\n"
94+
parseErrorTestPosition
95+
(many $ char 'f' *> char '?')
96+
"foo"
97+
(Position { column: 3, line: 1 })
10098

101-
parseTest "\n" (Cons '\n' Nil) $ many $ char '\n'
102-
parseTest "\n" (Cons "\n" Nil) $ many $ string "\n"
103-
104-
parseTest "\n" Nil $ many $ string "\n\n"
105-
parseTest "\n" Nil $ many $ char '\n' *> char '\n'
99+
parseTest
100+
"foo"
101+
Nil
102+
(many $ try $ char 'f' *> char '?')
106103

107104
parseTest "(((a)))" 3 nested
108105
parseTest "aaa" (Cons "a" (Cons "a" (Cons "a" Nil))) $ many (string "a")

0 commit comments

Comments
 (0)