@@ -13,11 +13,12 @@ import Data.String.CodeUnits (singleton)
1313import Data.String.Common as SC
1414import Data.Unfoldable (replicate )
1515import Effect (Effect )
16+ import Effect.Class.Console (log )
1617import Test.Assert (assert' , assert )
1718import Text.Parsing.StringParser (Parser , runParser , try )
19+ import Text.Parsing.StringParser.CodePoints (anyDigit , char , eof , string , anyChar , regex )
1820import Text.Parsing.StringParser.Combinators (many1 , endBy1 , sepBy1 , optionMaybe , many , manyTill , many1Till , chainl , fix , between )
1921import Text.Parsing.StringParser.Expr (Assoc (..), Operator (..), buildExprParser )
20- import Text.Parsing.StringParser.CodePoints (anyDigit , char , eof , string , anyChar , regex )
2122
2223parens :: forall a . Parser a -> Parser a
2324parens = between (string " (" ) (string " )" )
@@ -66,11 +67,8 @@ expectResult res p input = runParser p input == Right res
6667
6768testCodePoints :: Effect Unit
6869testCodePoints = do
69- assert' " many should not blow the stack" $ canParse (many (string " a" )) (SC .joinWith " " $ replicate 100000 " a" )
70- assert' " many failing after" $ parseFail (do
71- as <- many (string " a" )
72- eof
73- pure as) (SC .joinWith " " (replicate 100000 " a" ) <> " b" )
70+
71+ log " Running basic tests"
7472
7573 assert $ expectResult 3 nested " (((a)))"
7674 assert $ expectResult (" a" :" a" :" a" :Nil ) (many (string " a" )) " aaa"
@@ -93,10 +91,19 @@ testCodePoints = do
9391 assert $ expectResult Nil (manyTill (string " a" ) (string " b" )) " b"
9492 assert $ expectResult (NonEmptyList (" a" :| " a" :" a" :Nil )) (many1Till (string " a" ) (string " b" )) " aaab"
9593 assert $ parseFail (many1Till (string " a" ) (string " b" )) " b"
96- -- check against overflow
97- assert $ canParse (many1Till (string " a" ) (string " and" )) $ (fold <<< take 10000 $ repeat " a" ) <> " and"
9894 -- check correct order
9995 assert $ expectResult (NonEmptyList (' a' :| ' b' :' c' :Nil )) (many1Till anyChar (string " d" )) " abcd"
10096 assert $ expectResult " \x458CA " (string " \x458CA " <* char ' ]' <* eof ) " \x458CA ]"
10197 assert $ expectResult " \x458CA " (string " \x458CA " <* string " )" <* eof ) " \x458CA )"
10298 assert $ expectResult ' \xEEE2 ' (char ' \xEEE2 ' <* eof ) " \xEEE2 "
99+
100+ log " Running overflow tests (may take a while)"
101+
102+ -- check against overflow
103+ assert $ canParse (many1Till (string " a" ) (string " and" )) $ (fold <<< take 10000 $ repeat " a" ) <> " and"
104+
105+ assert' " many should not blow the stack" $ canParse (many (string " a" )) (SC .joinWith " " $ replicate 100000 " a" )
106+ assert' " many failing after" $ parseFail (do
107+ as <- many (string " a" )
108+ eof
109+ pure as) (SC .joinWith " " (replicate 100000 " a" ) <> " b" )
0 commit comments