@@ -5,6 +5,7 @@ import Prelude hiding (between, when)
5
5
import Control.Alt ((<|>))
6
6
import Control.Lazy (fix )
7
7
import Data.Array (some )
8
+ import Data.Array as Array
8
9
import Data.Either (Either (..))
9
10
import Data.List (List (..), fromFoldable , many )
10
11
import Data.List.NonEmpty (cons , cons' )
@@ -16,12 +17,12 @@ import Data.Tuple (Tuple(..))
16
17
import Effect (Effect )
17
18
import Effect.Console (logShow )
18
19
import Test.Assert (assert' )
19
- import Text.Parsing.Parser (ParseError (..), Parser , ParserT , parseErrorPosition , region , runParser )
20
+ import Text.Parsing.Parser (ParseError (..), Parser , ParserT , parseErrorMessage , parseErrorPosition , region , runParser )
20
21
import Text.Parsing.Parser.Combinators (between , chainl , endBy1 , optionMaybe , sepBy1 , try )
21
22
import Text.Parsing.Parser.Expr (Assoc (..), Operator (..), buildExprParser )
22
23
import Text.Parsing.Parser.Language (haskellDef , haskellStyle , javaStyle )
23
24
import Text.Parsing.Parser.Pos (Position (..), initialPos )
24
- import Text.Parsing.Parser.String (anyChar , anyCodePoint , char , eof , satisfy , string , whiteSpace )
25
+ import Text.Parsing.Parser.String (anyChar , anyCodePoint , char , eof , noneOfCodePoints , oneOfCodePoints , satisfy , string , whiteSpace )
25
26
import Text.Parsing.Parser.Token (TokenParser , letter , makeTokenParser , match , token , when )
26
27
27
28
parens :: forall m a . Monad m => ParserT String m a -> ParserT String m a
@@ -49,6 +50,14 @@ parseErrorTestPosition p input expected = case runParser input p of
49
50
assert' (" expected: " <> show expected <> " , pos: " <> show pos) (expected == pos)
50
51
logShow expected
51
52
53
+ parseErrorTestMessage :: forall s a . Show a => Parser s a -> s -> String -> Effect Unit
54
+ parseErrorTestMessage p input expected = case runParser input p of
55
+ Right x -> assert' (" ParseError expected '" <> expected <> " ' but parsed " <> show x) false
56
+ Left err -> do
57
+ let msg = parseErrorMessage err
58
+ assert' (" expected: " <> expected <> " , message: " <> msg) (expected == msg)
59
+ logShow expected
60
+
52
61
opTest :: Parser String String
53
62
opTest = chainl (singleton <$> anyChar) (char ' +' $> append) " "
54
63
@@ -465,6 +474,21 @@ main = do
465
474
sixteenth <- string " π
‘" <|> (singleton <$> char ' x' )
466
475
pure $ [ SCP .singleton quarter, eighth, letterx, sixteenth ]
467
476
477
+ parseTest " π€π―β
π€π―" [ " π€π―" , " β
π€π―" ] do
478
+ none <- Array .many $ noneOfCodePoints $ SCP .toCodePointArray " ββ
"
479
+ one <- Array .many $ oneOfCodePoints $ SCP .toCodePointArray " π€π―β
"
480
+ pure $ SCP .fromCodePointArray <$> [ none, one ]
481
+
482
+ parseErrorTestMessage
483
+ (noneOfCodePoints $ SCP .toCodePointArray " ββ
" )
484
+ " β"
485
+ " Expected none of [\" β\" ,\" β
\" ]"
486
+
487
+ parseErrorTestMessage
488
+ (oneOfCodePoints $ SCP .toCodePointArray " ββ
" )
489
+ " abc"
490
+ " Expected one of [\" β\" ,\" β
\" ]"
491
+
468
492
parseTest " aa bb" [ " aa" , " " , " bb" ] do
469
493
aa <- SCU .fromCharArray <$> some letter
470
494
w <- whiteSpace
0 commit comments