import System.Random
import Data.Word
import Test.HUnit.Utils
+import Text.ParserCombinators.Parsec
(@=?) :: (Eq a, Show a) => a -> a -> Result
expected @=? actual =
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
+
import TestInfrastructure
import TestConnection(expectedString, noCR)
+import TestParserPrim(isValidText)
prop_getFullLine_basic :: [String] -> Property
prop_getFullLine_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
]
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
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 =