@@ -9,15 +9,16 @@ import Data.List (List(Nil), (:))
9
9
import Data.List.Lazy (take , repeat )
10
10
import Data.List.NonEmpty (NonEmptyList (..))
11
11
import Data.NonEmpty ((:|))
12
+ import Data.String.CodePoints as SCP
12
13
import Data.String.CodeUnits (singleton )
13
14
import Data.String.Common as SC
14
15
import Data.Unfoldable (replicate )
15
16
import Effect (Effect )
16
17
import Test.Assert (assert' , assert )
17
18
import Text.Parsing.StringParser (Parser , runParser , try )
19
+ import Text.Parsing.StringParser.CodeUnits (anyChar , anyCodePoint , anyDigit , eof , regex , string )
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.CodeUnits (anyDigit , eof , string , anyChar , regex )
21
22
22
23
parens :: forall a . Parser a -> Parser a
23
24
parens = between (string " (" ) (string " )" )
@@ -97,3 +98,22 @@ testCodeUnits = do
97
98
assert $ canParse (many1Till (string " a" ) (string " and" )) $ (fold <<< take 10000 $ repeat " a" ) <> " and"
98
99
-- check correct order
99
100
assert $ expectResult (NonEmptyList (' a' :| ' b' :' c' :Nil )) (many1Till anyChar (string " d" )) " abcd"
101
+ -- check anyCodePoint
102
+ let anyCodePointStr = map SCP .singleton anyCodePoint
103
+ let anyCharStr = map singleton anyChar
104
+ assert $ expectResult (NonEmptyList (" 🍔" :| " 🍺" :Nil )) (many1 $ anyCodePointStr) " 🍔🍺"
105
+ assert $ expectResult " 🍔" (anyChar *> anyCodePointStr <* anyChar) " a🍔a"
106
+ assert $ expectResult ({a: " 🍔" , b: " 🍺" }) ({a:_, b:_} <$> (anyCodePointStr <* void anyChar) <*> anyCodePointStr) " 🍔a🍺"
107
+ assert $ expectResult ({a: " a" , b: " b" , c:" c" }) ({a:_, b:_, c:_} <$> anyCodePointStr <*> anyCodePointStr <*> anyCodePointStr) " abc"
108
+ -- check string
109
+ assert $ expectResult " 🍔🍺" (string " 🍔🍺" ) " 🍔🍺"
110
+ assert $ expectResult (NonEmptyList (" 🍔🍺" :| " 🍔🍺" :" 🍔🍺" :Nil )) (many1 $ string " 🍔🍺" ) " 🍔🍺🍔🍺🍔🍺"
111
+ assert $ expectResult (NonEmptyList (" a🍔🍺" :|" a🍔🍺" :" a🍔🍺" :Nil )) (many1 $ string " a🍔🍺" ) " a🍔🍺a🍔🍺a🍔🍺"
112
+ assert $ expectResult (NonEmptyList (" 🍔a🍺" :|" 🍔a🍺" :" 🍔a🍺" :Nil )) (many1 $ string " 🍔a🍺" ) " 🍔a🍺🍔a🍺🍔a🍺"
113
+ assert $ expectResult (NonEmptyList (" 🍔🍺a" :| " 🍔🍺a" :" 🍔🍺a" :Nil )) (many1 $ string " 🍔🍺a" ) " 🍔🍺a🍔🍺a🍔🍺a"
114
+ assert $ expectResult (NonEmptyList (" a" :| " a" :" a" :Nil )) (many1 $ string " a" ) " aaa"
115
+ assert $ expectResult (NonEmptyList (" abc" :| " abc" :" abc" :Nil )) (many1 $ string " abc" ) " abcabcabc"
116
+ assert $ expectResult (NonEmptyList (" abc" :| " abc" :" abc" :Nil )) (many1 $ string " abc" ) " abcabcabc"
117
+ assert $ expectResult (NonEmptyList (" abc�def" :| Nil )) (many1 $ string " abc�def" ) " abc�def"
118
+
119
+ assert $ expectResult " 🍔\xd83c " (string " 🍔\xd83c " ) " 🍔🍺"
0 commit comments