From 08e21d9d20d07d84ae1e819d1d81c82daae6b722 Mon Sep 17 00:00:00 2001 From: John Goerzen Date: Tue, 12 Aug 2008 02:29:03 -0500 Subject: [PATCH] Added first respText test --- testsrc/TestInfrastructure.hs | 10 ++++++++++ testsrc/TestParser.hs | 11 ++++++++++- testsrc/TestParserPrim.hs | 14 +++----------- 3 files changed, 23 insertions(+), 12 deletions(-) diff --git a/testsrc/TestInfrastructure.hs b/testsrc/TestInfrastructure.hs index 0cd5410..feb058e 100644 --- a/testsrc/TestInfrastructure.hs +++ b/testsrc/TestInfrastructure.hs @@ -26,6 +26,7 @@ import Text.Printf import System.Random import Data.Word import Test.HUnit.Utils +import Text.ParserCombinators.Parsec (@=?) :: (Eq a, Show a) => a -> a -> Result expected @=? actual = @@ -88,3 +89,12 @@ q = qccheck (defaultConfig {configMaxTest = 250, configMaxFail = 10000, testCount n _ = testCountBase n ++ replicate (length (testCountBase n)) '\b' +{- | Test a parser, forcing it to apply to all input. -} +p parser input = + case parse parseTest "(none)" input of + Left _ -> Nothing + Right y -> Just y + where parseTest = do r <- parser + eof + return r + diff --git a/testsrc/TestParser.hs b/testsrc/TestParser.hs index 1bda21f..3129039 100644 --- a/testsrc/TestParser.hs +++ b/testsrc/TestParser.hs @@ -30,6 +30,7 @@ import Network.IMAP.Types import TestInfrastructure import TestConnection(expectedString, noCR) +import TestParserPrim(isValidText) prop_getFullLine_basic :: [String] -> Property prop_getFullLine_basic s = @@ -67,7 +68,15 @@ prop_rfr_basic s = noBrace s = and (map (not . isSuffixOf "}") s) +prop_respTextSimple :: String -> Result +prop_respTextSimple s = + p respText s @?= + if isValidText s + then Just (RespText Nothing s) + else Nothing + allt = [q "getFullLine_basic" prop_getFullLine_basic, q "getFullLine_count" prop_getFullLine_count, - q "readFullResponse_basic" prop_rfr_basic + q "readFullResponse_basic" prop_rfr_basic, + q "respText simple" prop_respTextSimple ] diff --git a/testsrc/TestParserPrim.hs b/testsrc/TestParserPrim.hs index 8737c93..ff016fb 100644 --- a/testsrc/TestParserPrim.hs +++ b/testsrc/TestParserPrim.hs @@ -30,15 +30,6 @@ import TestInfrastructure import Text.ParserCombinators.Parsec import Text.ParserCombinators.Parsec.Error -{- | Test a parser, forcing it to apply to all input. -} -p parser input = - case parse parseTest "(none)" input of - Left _ -> Nothing - Right y -> Just y - where parseTest = do r <- parser - eof - return r - prop_quoted :: String -> Result prop_quoted s = p quoted (gen_quoted s) @?= Just s @@ -90,10 +81,11 @@ prop_astring s useQuoted = prop_text :: String -> Result prop_text s = - p text s @=? if isValid + p text s @=? if isValidText s then Just s else Nothing - where isValid = not (null s) && all (`notElem` crlf) s + +isValidText s = not (null s) && all (`notElem` crlf) s prop_tag :: String -> Result prop_tag s = -- 2.39.2