From 1d0e39059360de832ff4aaf33e047aaebba1c720 Mon Sep 17 00:00:00 2001 From: mrkkrp Date: Mon, 5 Oct 2015 00:10:59 +0600 Subject: [PATCH] =?UTF-8?q?fixed=20test=20for=20=E2=80=98Text.Megaparsec.C?= =?UTF-8?q?har.string'=E2=80=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Closes #52. Also added one new test for that function. The test is courtesy of Benjamin Kästner (@bkaestner). --- tests/Char.hs | 20 +++++++++++++++++--- tests/Util.hs | 2 +- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/tests/Char.hs b/tests/Char.hs index 72ccefb..92baa32 100644 --- a/tests/Char.hs +++ b/tests/Char.hs @@ -79,7 +79,8 @@ tests = testGroup "Character parsers" , testProperty "noneOf" prop_noneOf , testProperty "noneOf'" prop_noneOf' , testProperty "string" prop_string - , testProperty "string'" prop_string' ] + , testProperty "string'" prop_string'_0 + , testProperty "string' (case)" prop_string'_1 ] instance Arbitrary GeneralCategory where arbitrary = elements @@ -238,8 +239,21 @@ prop_noneOf' a = checkChar (noneOf' a) (`notElemi` a) Nothing prop_string :: String -> String -> Property prop_string a = checkString (string a) a (==) (showToken a) -prop_string' :: String -> String -> Property -prop_string' a = checkString (string' a) a casei (showToken a) +prop_string'_0 :: String -> String -> Property +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. diff --git a/tests/Util.hs b/tests/Util.hs index e6cc461..1cb6f87 100644 --- a/tests/Util.hs +++ b/tests/Util.hs @@ -101,7 +101,7 @@ checkChar p f l' s = checkParser p r s checkString :: Parser String -> String -> (Char -> Char -> Bool) -> String -> String -> Property 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 _ 0 [] = posErr 0 s' [uneEof, exSpec l] w _ i [] = posErr 0 s' [uneStr (take i s'), exSpec l]