]> code.delx.au - offlineimap/blobdiff - testsrc/TestParserPrim.hs
Added test for string3501
[offlineimap] / testsrc / TestParserPrim.hs
index 1bda21f3449f77779f51c9dab5fe55da05c1a92e..ec65c06138c3b220a47bc8ca3123f7591e269c37 100644 (file)
@@ -15,8 +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 TestParser where
-import qualified Data.Map as Map
+module TestParserPrim where
 import Data.List
 import qualified Test.HUnit as HU
 import Test.HUnit.Utils
@@ -24,50 +23,40 @@ import Data.Word
 import Test.QuickCheck
 import TestInfrastructure
 
-import Network.IMAP.Parser
-import Network.IMAP.Connection
+import Network.IMAP.Parser.Prim
 import Network.IMAP.Types
 
 import TestInfrastructure
-import TestConnection(expectedString, noCR)
-
-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_getFullLine_count :: [String] -> Property
-prop_getFullLine_count s =
-    length s >= 2 && noCR s && (length s < 3 || not ("}" `isSuffixOf` (s !! 2)))
-           ==> 
-           runLinesConnection lenS (getFullLine []) @?=
-                              Right (expectedResult, (expectedRemain, []))
-    where lenS = [braceString] ++ [(head . tail $ s)] ++ drop 2 s
-          braceString = head s ++ "{" ++ show (length (s !! 1)) ++ "}"
-          expectedResult = braceString ++ "\r\n" ++ (s !! 1)
-          expectedRemain = expectedString (drop 2 s)
-
-prop_rfr_basic :: [String] -> Property
-prop_rfr_basic s =
-    let testlist = 
-            case length s of
-              0 -> []
-              1 -> ["TAG " ++ head s]
-              _ -> map ("* " ++) (init s) ++
-                   ["TAG " ++ last s]
-        resultstr = expectedString testlist
-    in noCR s && noBrace s ==>
-       runLinesConnection testlist readFullResponse @?=
-             if null s
-                then Left "EOF in input in readLine"
-                else Right (resultstr, ([], []))
-
-noBrace s = and (map (not . isSuffixOf "}") s)
-
-allt = [q "getFullLine_basic" prop_getFullLine_basic,
-        q "getFullLine_count" prop_getFullLine_count,
-        q "readFullResponse_basic" prop_rfr_basic
+import Text.ParserCombinators.Parsec
+
+p parser input = 
+    case parse parser "(none)" input of
+      Left e -> Left (show e)
+      Right y -> Right y
+
+prop_quoted :: String -> Result
+prop_quoted s =
+    p quoted (gen_quoted s) @?= Right s
+
+gen_quoted :: String -> String
+gen_quoted s = '"' : concatMap quoteChar s ++ "\""
+    where quoteChar '\\' = "\\\\"
+          quoteChar '"' = "\\\""
+          quoteChar x = [x]
+
+prop_literal :: String -> Result
+prop_literal s =
+    p literal (gen_literal s) @?= Right s
+
+gen_literal :: String -> String
+gen_literal s =
+    "{" ++ show (length s) ++ "}\r\n" ++ s
+
+prop_string3501 :: String -> Bool -> Result
+prop_string3501 s True = p string3501 (gen_quoted s) @?= Right s
+prop_string3501 s False = p string3501 (gen_literal s) @?= Right s
+    
+allt = [q "quoted" prop_quoted,
+        q "literal" prop_literal,
+        q "string3501" prop_string3501
        ]