mirror of
https://github.com/mrkkrp/megaparsec.git
synced 2024-11-23 19:38:05 +03:00
fixed test for ‘Text.Megaparsec.Char.string'’
Closes #52. Also added one new test for that function. The test is courtesy of Benjamin Kästner (@bkaestner).
This commit is contained in:
parent
17ba4fb4ee
commit
1d0e390593
@ -79,7 +79,8 @@ tests = testGroup "Character parsers"
|
|||||||
, testProperty "noneOf" prop_noneOf
|
, testProperty "noneOf" prop_noneOf
|
||||||
, testProperty "noneOf'" prop_noneOf'
|
, testProperty "noneOf'" prop_noneOf'
|
||||||
, testProperty "string" prop_string
|
, testProperty "string" prop_string
|
||||||
, testProperty "string'" prop_string' ]
|
, testProperty "string'" prop_string'_0
|
||||||
|
, testProperty "string' (case)" prop_string'_1 ]
|
||||||
|
|
||||||
instance Arbitrary GeneralCategory where
|
instance Arbitrary GeneralCategory where
|
||||||
arbitrary = elements
|
arbitrary = elements
|
||||||
@ -238,8 +239,21 @@ prop_noneOf' a = checkChar (noneOf' a) (`notElemi` a) Nothing
|
|||||||
prop_string :: String -> String -> Property
|
prop_string :: String -> String -> Property
|
||||||
prop_string a = checkString (string a) a (==) (showToken a)
|
prop_string a = checkString (string a) a (==) (showToken a)
|
||||||
|
|
||||||
prop_string' :: String -> String -> Property
|
prop_string'_0 :: String -> String -> Property
|
||||||
prop_string' a = checkString (string' a) a casei (showToken a)
|
prop_string'_0 a = checkString (string' a) a casei (showToken a)
|
||||||
|
|
||||||
|
-- | Randomly change the case in the given string.
|
||||||
|
|
||||||
|
fuzzyCase :: String -> Gen String
|
||||||
|
fuzzyCase s = do
|
||||||
|
b <- vector (length s)
|
||||||
|
return $ zipWith f s b
|
||||||
|
where f k True = if isLower k then toUpper k else toLower k
|
||||||
|
f k False = k
|
||||||
|
|
||||||
|
prop_string'_1 :: String -> Property
|
||||||
|
prop_string'_1 a = forAll (fuzzyCase a) $ \s ->
|
||||||
|
checkString (string' a) a casei (showToken a) s
|
||||||
|
|
||||||
-- | Case-insensitive equality test for characters.
|
-- | Case-insensitive equality test for characters.
|
||||||
|
|
||||||
|
@ -101,7 +101,7 @@ checkChar p f l' s = checkParser p r s
|
|||||||
checkString :: Parser String -> String -> (Char -> Char -> Bool)
|
checkString :: Parser String -> String -> (Char -> Char -> Bool)
|
||||||
-> String -> String -> Property
|
-> String -> String -> Property
|
||||||
checkString p a' test l s' = checkParser p (w a' 0 s') s'
|
checkString p a' test l s' = checkParser p (w a' 0 s') s'
|
||||||
where w [] _ [] = Right a'
|
where w [] _ [] = Right s'
|
||||||
w [] i (s:_) = posErr i s' [uneCh s, exEof]
|
w [] i (s:_) = posErr i s' [uneCh s, exEof]
|
||||||
w _ 0 [] = posErr 0 s' [uneEof, exSpec l]
|
w _ 0 [] = posErr 0 s' [uneEof, exSpec l]
|
||||||
w _ i [] = posErr 0 s' [uneStr (take i s'), exSpec l]
|
w _ i [] = posErr 0 s' [uneStr (take i s'), exSpec l]
|
||||||
|
Loading…
Reference in New Issue
Block a user