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
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)
+import Text.ParserCombinators.Parsec
-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), []))
+p parser input =
+ case parse parser "(none)" input of
+ Left e -> Left (show e)
+ Right y -> Right y
-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_quoted :: String -> Result
+prop_quoted s =
+ p quoted (gen_quoted s) @?= Right 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, ([], []))
+gen_quoted :: String -> String
+gen_quoted s = '"' : concatMap quoteChar s ++ "\""
+ where quoteChar '\\' = "\\\\"
+ quoteChar '"' = "\\\""
+ quoteChar x = [x]
-noBrace s = and (map (not . isSuffixOf "}") s)
+prop_literal :: String -> Result
+prop_literal s =
+ p literal (gen_literal s) @?= Right s
-allt = [q "getFullLine_basic" prop_getFullLine_basic,
- q "getFullLine_count" prop_getFullLine_count,
- q "readFullResponse_basic" prop_rfr_basic
+gen_literal :: String -> String
+gen_literal s =
+ "{" ++ show (length s) ++ "}\r\n" ++ s
+
+allt = [q "quoted" prop_quoted,
+ q "literal" prop_literal
]