File tree Expand file tree Collapse file tree 2 files changed +9
-1
lines changed
src/Text/Parsing/StringParser Expand file tree Collapse file tree 2 files changed +9
-1
lines changed Original file line number Diff line number Diff line change @@ -51,7 +51,7 @@ anyChar :: Parser Char
51
51
anyChar = Parser \{ substr, posFromStart } ->
52
52
case SCP .codePointAt 0 substr of
53
53
Just cp -> case toChar cp of
54
- Just chr -> Right { result: chr, suffix: { substr: SCP .drop 1 substr, posFromStart: posFromStart + 1 } }
54
+ Just chr -> Right { result: chr, suffix: { substr: SCP .drop 1 substr, posFromStart: posFromStart + SCU .length ( SCP .singleton cp) } }
55
55
Nothing -> Left { pos: posFromStart, error: " CodePoint " <> show cp <> " is not a character" }
56
56
Nothing -> Left { pos: posFromStart, error: " Unexpected EOF" }
57
57
where
Original file line number Diff line number Diff line change @@ -72,6 +72,12 @@ parseFail p input = isLeft $ runParser p input
72
72
expectResult :: forall a . Eq a => a -> Parser a -> String -> Boolean
73
73
expectResult res p input = runParser p input == Right res
74
74
75
+ expectPosition :: forall a . Int -> Parser a -> String -> Boolean
76
+ expectPosition pos (Parser p) input =
77
+ case p { substr: input, posFromStart: 0 } of
78
+ Right r -> r.suffix.posFromStart == pos
79
+ Left _ -> false
80
+
75
81
testCodePoints :: Effect Unit
76
82
testCodePoints = do
77
83
@@ -113,6 +119,8 @@ testCodePoints = do
113
119
assert $ expectResult " \x458CA " (string " \x458CA " <* char ' ]' <* eof) " \x458CA ]"
114
120
assert $ expectResult " \x458CA " (string " \x458CA " <* string " )" <* eof) " \x458CA )"
115
121
assert $ expectResult ' \xEEE2 ' (char ' \xEEE2 ' <* eof) " \xEEE2 "
122
+ assert $ expectPosition 1 anyChar " \xEEE2 "
123
+ assert $ expectPosition 2 anyChar " \x458CA "
116
124
117
125
log " Running overflow tests (may take a while)"
118
126
You can’t perform that action at this time.
0 commit comments