]> code.delx.au - offlineimap/commitdiff
Added first respText test
authorJohn Goerzen <jgoerzen@complete.org>
Tue, 12 Aug 2008 07:29:03 +0000 (02:29 -0500)
committerJohn Goerzen <jgoerzen@complete.org>
Tue, 12 Aug 2008 07:29:03 +0000 (02:29 -0500)
testsrc/TestInfrastructure.hs
testsrc/TestParser.hs
testsrc/TestParserPrim.hs

index 0cd54100010dc7923f8612a9e3cf03309596f270..feb058e186473f2cf4fb34d7a594f48994b9abe6 100644 (file)
@@ -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
+
index 1bda21f3449f77779f51c9dab5fe55da05c1a92e..31290391c0a67925f5782feaa6316e12143debfe 100644 (file)
@@ -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
        ]
index 8737c9318ab8ae78dcecdc4511ae4ed157fb72fd..ff016fb2d9467dca515d594c79d7976f1ff64d2b 100644 (file)
@@ -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 =