@@ -13,11 +13,12 @@ import Data.String.CodeUnits (singleton)
13
13
import Data.String.Common as SC
14
14
import Data.Unfoldable (replicate )
15
15
import Effect (Effect )
16
+ import Effect.Class.Console (log )
16
17
import Test.Assert (assert' , assert )
17
18
import Text.Parsing.StringParser (Parser , runParser , try )
19
+ import Text.Parsing.StringParser.CodePoints (anyDigit , char , eof , string , anyChar , regex )
18
20
import Text.Parsing.StringParser.Combinators (many1 , endBy1 , sepBy1 , optionMaybe , many , manyTill , many1Till , chainl , fix , between )
19
21
import Text.Parsing.StringParser.Expr (Assoc (..), Operator (..), buildExprParser )
20
- import Text.Parsing.StringParser.CodePoints (anyDigit , char , eof , string , anyChar , regex )
21
22
22
23
parens :: forall a . Parser a -> Parser a
23
24
parens = between (string " (" ) (string " )" )
@@ -66,11 +67,8 @@ expectResult res p input = runParser p input == Right res
66
67
67
68
testCodePoints :: Effect Unit
68
69
testCodePoints = 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"
74
72
75
73
assert $ expectResult 3 nested " (((a)))"
76
74
assert $ expectResult (" a" :" a" :" a" :Nil ) (many (string " a" )) " aaa"
@@ -93,10 +91,19 @@ testCodePoints = do
93
91
assert $ expectResult Nil (manyTill (string " a" ) (string " b" )) " b"
94
92
assert $ expectResult (NonEmptyList (" a" :| " a" :" a" :Nil )) (many1Till (string " a" ) (string " b" )) " aaab"
95
93
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"
98
94
-- check correct order
99
95
assert $ expectResult (NonEmptyList (' a' :| ' b' :' c' :Nil )) (many1Till anyChar (string " d" )) " abcd"
100
96
assert $ expectResult " \x458CA " (string " \x458CA " <* char ' ]' <* eof ) " \x458CA ]"
101
97
assert $ expectResult " \x458CA " (string " \x458CA " <* string " )" <* eof ) " \x458CA )"
102
98
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