]> code.delx.au - offlineimap/commitdiff
Added first TestParser, genericized some other Test code
authorJohn Goerzen <jgoerzen@complete.org>
Tue, 12 Aug 2008 13:46:31 +0000 (08:46 -0500)
committerJohn Goerzen <jgoerzen@complete.org>
Tue, 12 Aug 2008 13:46:31 +0000 (08:46 -0500)
testsrc/TestConnection.hs
testsrc/TestInfrastructure.hs
testsrc/TestParser.hs
testsrc/TestSyncable.hs
testsrc/runtests.hs

index 275c259e05c2ae0713a64b7d697052c09966fbde..9ef511550281f797978a5f722fce022197e84a4b 100644 (file)
@@ -45,9 +45,12 @@ expectedString f =
                 [] -> []
                 _ -> (intercalate "\r\n" f) ++ "\r\n"
 
+noCR :: [String] -> Bool
+noCR s = and (map (notElem '\r') s)
+
 prop_readLine :: [String] -> Property
 prop_readLine s =
-    (and (map (notElem '\r') s)) ==> 
+    noCR s ==> 
         runLinesConnection s readLine @?=
             if null s
                then Left "EOF in input in readLine"
@@ -63,9 +66,6 @@ prop_readBytes s l =
                     LT -> Right (take l s, (drop l s, []))
                     GT -> Left "EOF in input in readBytes"
 
-q :: Testable a => String -> a -> HU.Test
-q = qccheck (defaultConfig {configMaxTest = 250, configMaxFail = 5000})
-
 allt = [q "Identity" prop_identity,
         q "Lines identity" prop_linesidentity,
         q "Lines list identity" prop_lineslistidentity,
index 0b05e0fcd3fcc3c5855fdfe1eb3d972aa0b5beb9..f5ae0044323b2f64a1fb8684599d8bfc6ef32aa6 100644 (file)
@@ -25,6 +25,7 @@ import System.IO
 import Text.Printf
 import System.Random
 import Data.Word
+import Test.HUnit.Utils
 
 (@=?) :: (Eq a, Show a) => a -> a -> Result
 expected @=? actual = 
@@ -78,3 +79,6 @@ runVerbTestText (HU.PutText put us) t = do
          kind  = if null path' then p0 else p1
          path' = HU.showPath (HU.path ss)
 
+q :: Testable a => String -> a -> HU.Test
+q = qccheck (defaultConfig {configMaxTest = 250, configMaxFail = 5000})
+
index 275c259e05c2ae0713a64b7d697052c09966fbde..124751cb55edb43a2819e2b6be62a095eaad5673 100644 (file)
@@ -15,7 +15,7 @@ You should have received a copy of the GNU General Public License
 along with this program; if not, write to the Free Software
 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 -}
-module TestConnection where
+module TestParser where
 import qualified Data.Map as Map
 import Data.List
 import qualified Test.HUnit as HU
@@ -24,51 +24,20 @@ import Data.Word
 import Test.QuickCheck
 import TestInfrastructure
 
+import Network.IMAP.Parser
 import Network.IMAP.Connection
 import Network.IMAP.Types
 
-prop_identity :: String -> Bool
-prop_identity f = runStringConnection f (\_ -> return ()) == Right ((), (f, []))
-
-prop_linesidentity :: String -> Bool
-prop_linesidentity f =
-    runLinesConnection [f] (\_ -> return ()) == Right ((), (f ++ "\r\n", []))
-
-prop_lineslistidentity :: [String] -> Property
-prop_lineslistidentity f =
-    and (map (notElem '\r') f)  ==> 
-        runLinesConnection f (\_ -> return ()) @?= Right ((), (expected, []))
-    where expected = expectedString f
-
-expectedString f =
-              case f of
-                [] -> []
-                _ -> (intercalate "\r\n" f) ++ "\r\n"
+import TestInfrastructure
+import TestConnection(expectedString, noCR)
 
-prop_readLine :: [String] -> Property
-prop_readLine s =
-    (and (map (notElem '\r') s)) ==> 
-        runLinesConnection s readLine @?=
+prop_getFullLine_basic :: [String] -> Property
+prop_getFullLine_basic s =
+    (null s || not ("}" `isSuffixOf` (head s))) && noCR s ==>
+        runLinesConnection s (getFullLine []) @?= 
             if null s
                then Left "EOF in input in readLine"
                else Right (head s, (expectedString (tail s), []))
 
-prop_readBytes :: String -> Int -> Result
-prop_readBytes s l =
-      runStringConnection s (\c -> readBytes c (fromIntegral l)) @?=
-          if l < 0
-             then Left "readBytes: negative count"
-             else case compare l (length s) of
-                    EQ -> Right (take l s, (drop l s, []))
-                    LT -> Right (take l s, (drop l s, []))
-                    GT -> Left "EOF in input in readBytes"
-
-q :: Testable a => String -> a -> HU.Test
-q = qccheck (defaultConfig {configMaxTest = 250, configMaxFail = 5000})
-
-allt = [q "Identity" prop_identity,
-        q "Lines identity" prop_linesidentity,
-        q "Lines list identity" prop_lineslistidentity,
-        q "readline" prop_readLine,
-        q "readBytes" prop_readBytes
+allt = [q "getFullLine_basic" prop_getFullLine_basic
        ]
index 131702b7b669e9afceb8b76752084bfe0838202b..7e7dafadf6c67c4ba7f3d82700bc87c0e9cb1168 100644 (file)
@@ -181,9 +181,6 @@ prop_diffCollection coll1 coll2 =
         newcoll2 = unaryApplyChanges coll1 commands
         in coll2 @=? newcoll2
 
-q :: Testable a => String -> a -> HU.Test
-q = qccheck (defaultConfig {configMaxTest = 250})
-
 allt = [q "Empty" prop_empty,
         q "Del all from child" prop_delAllFromChild,
         q "Del all from master" prop_delAllFromMaster,
index 74b38d96033124d6262271201e374170d5ae39d1..41726eeff4a65c7e0c83b6f9c571cc3f5c2ef533 100644 (file)
@@ -29,6 +29,7 @@ import TestInfrastructure
 
 import qualified TestSyncable
 import qualified TestConnection
+import qualified TestParser
 
 q :: Testable a => String -> a -> HU.Test
 q = qccheck (defaultConfig {configMaxTest = 250})
@@ -36,7 +37,8 @@ q = qccheck (defaultConfig {configMaxTest = 250})
 tl msg t = HU.TestLabel msg $ HU.TestList t
 
 allt = [tl "TestSyncable" TestSyncable.allt,
-        tl "TestConnection" TestConnection.allt]
+        tl "TestConnection" TestConnection.allt,
+        tl "TestParser" TestParser.allt]
 
 testh = HU.runTestTT $ HU.TestList allt
 testv = runVerbTestText (HU.putTextToHandle stderr True) $ HU.TestList allt