From 4cb816d5a7dd6338004982ae14efd755abc741bd Mon Sep 17 00:00:00 2001 From: Miles Frain Date: Wed, 12 May 2021 11:28:59 -0700 Subject: [PATCH 1/2] Move slow tests to end and print status updates --- test/CodePoints.purs | 23 +++++++++++++++-------- test/CodeUnits.purs | 23 +++++++++++++++-------- 2 files changed, 30 insertions(+), 16 deletions(-) diff --git a/test/CodePoints.purs b/test/CodePoints.purs index 76c52d6..3152942 100644 --- a/test/CodePoints.purs +++ b/test/CodePoints.purs @@ -13,11 +13,12 @@ import Data.String.CodeUnits (singleton) import Data.String.Common as SC import Data.Unfoldable (replicate) import Effect (Effect) +import Effect.Class.Console (log) import Test.Assert (assert', assert) import Text.Parsing.StringParser (Parser, runParser, try) +import Text.Parsing.StringParser.CodePoints (anyDigit, char, eof, string, anyChar, regex) import Text.Parsing.StringParser.Combinators (many1, endBy1, sepBy1, optionMaybe, many, manyTill, many1Till, chainl, fix, between) import Text.Parsing.StringParser.Expr (Assoc(..), Operator(..), buildExprParser) -import Text.Parsing.StringParser.CodePoints (anyDigit, char, eof, string, anyChar, regex) parens :: forall a. Parser a -> Parser a parens = between (string "(") (string ")") @@ -66,11 +67,8 @@ expectResult res p input = runParser p input == Right res testCodePoints :: Effect Unit testCodePoints = do - assert' "many should not blow the stack" $ canParse (many (string "a")) (SC.joinWith "" $ replicate 100000 "a") - assert' "many failing after" $ parseFail (do - as <- many (string "a") - eof - pure as) (SC.joinWith "" (replicate 100000 "a") <> "b" ) + + log "Running basic tests" assert $ expectResult 3 nested "(((a)))" assert $ expectResult ("a":"a":"a":Nil) (many (string "a")) "aaa" @@ -93,10 +91,19 @@ testCodePoints = do assert $ expectResult Nil (manyTill (string "a") (string "b")) "b" assert $ expectResult (NonEmptyList ("a" :| "a":"a":Nil)) (many1Till (string "a") (string "b")) "aaab" assert $ parseFail (many1Till (string "a") (string "b")) "b" - -- check against overflow - assert $ canParse (many1Till (string "a") (string "and")) $ (fold <<< take 10000 $ repeat "a") <> "and" -- check correct order assert $ expectResult (NonEmptyList ('a' :| 'b':'c':Nil)) (many1Till anyChar (string "d")) "abcd" assert $ expectResult "\x458CA" (string "\x458CA" <* char ']' <* eof ) "\x458CA]" assert $ expectResult "\x458CA" (string "\x458CA" <* string ")" <* eof ) "\x458CA)" assert $ expectResult '\xEEE2' (char '\xEEE2' <* eof ) "\xEEE2" + + log "Running overflow tests (may take a while)" + + -- check against overflow + assert $ canParse (many1Till (string "a") (string "and")) $ (fold <<< take 10000 $ repeat "a") <> "and" + + assert' "many should not blow the stack" $ canParse (many (string "a")) (SC.joinWith "" $ replicate 100000 "a") + assert' "many failing after" $ parseFail (do + as <- many (string "a") + eof + pure as) (SC.joinWith "" (replicate 100000 "a") <> "b" ) diff --git a/test/CodeUnits.purs b/test/CodeUnits.purs index ff81cec..fbdf19b 100644 --- a/test/CodeUnits.purs +++ b/test/CodeUnits.purs @@ -13,11 +13,12 @@ import Data.String.CodeUnits (singleton) import Data.String.Common as SC import Data.Unfoldable (replicate) import Effect (Effect) +import Effect.Class.Console (log) import Test.Assert (assert', assert) import Text.Parsing.StringParser (Parser, runParser, try) +import Text.Parsing.StringParser.CodeUnits (anyDigit, eof, string, anyChar, regex) import Text.Parsing.StringParser.Combinators (many1, endBy1, sepBy1, optionMaybe, many, manyTill, many1Till, chainl, fix, between) import Text.Parsing.StringParser.Expr (Assoc(..), Operator(..), buildExprParser) -import Text.Parsing.StringParser.CodeUnits (anyDigit, eof, string, anyChar, regex) parens :: forall a. Parser a -> Parser a parens = between (string "(") (string ")") @@ -66,11 +67,8 @@ expectResult res p input = runParser p input == Right res testCodeUnits :: Effect Unit testCodeUnits = do - assert' "many should not blow the stack" $ canParse (many (string "a")) (SC.joinWith "" $ replicate 100000 "a") - assert' "many failing after" $ parseFail (do - as <- many (string "a") - eof - pure as) (SC.joinWith "" (replicate 100000 "a") <> "b" ) + + log "Running basic tests" assert $ expectResult 3 nested "(((a)))" assert $ expectResult ("a":"a":"a":Nil) (many (string "a")) "aaa" @@ -93,7 +91,16 @@ testCodeUnits = do assert $ expectResult Nil (manyTill (string "a") (string "b")) "b" assert $ expectResult (NonEmptyList ("a" :| "a":"a":Nil)) (many1Till (string "a") (string "b")) "aaab" assert $ parseFail (many1Till (string "a") (string "b")) "b" - -- check against overflow - assert $ canParse (many1Till (string "a") (string "and")) $ (fold <<< take 10000 $ repeat "a") <> "and" -- check correct order assert $ expectResult (NonEmptyList ('a' :| 'b':'c':Nil)) (many1Till anyChar (string "d")) "abcd" + + log "Running overflow tests (may take a while)" + + -- check against overflow + assert $ canParse (many1Till (string "a") (string "and")) $ (fold <<< take 10000 $ repeat "a") <> "and" + + assert' "many should not blow the stack" $ canParse (many (string "a")) (SC.joinWith "" $ replicate 100000 "a") + assert' "many failing after" $ parseFail (do + as <- many (string "a") + eof + pure as) (SC.joinWith "" (replicate 100000 "a") <> "b" ) \ No newline at end of file From 362ef4714233fcd2041546bb06a4de61e4691c3c Mon Sep 17 00:00:00 2001 From: Miles Frain Date: Wed, 12 May 2021 11:45:08 -0700 Subject: [PATCH 2/2] Update changelog --- CHANGELOG.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index fb4d68f..00c2177 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,10 +12,12 @@ Bugfixes: Other improvements: +- Run slowest tests last and print status updates (#72) + ## [v6.0.1](https://github.com/purescript-contrib/purescript-string-parsers/releases/tag/v6.0.1) - 2021-05-11 Other improvements: -- Fix transitive dependencies errors found by Spago 0.20 (#71 by @milesfrain) +- Fix transitive dependencies errors found by Spago 0.20 (#71) ## [v6.0.0](https://github.com/purescript-contrib/purescript-string-parsers/releases/tag/v6.0.0) - 2021-02-26