]> code.delx.au - offlineimap/blob - testsrc/TestParser.hs
Added prop_rfr_basic
[offlineimap] / testsrc / TestParser.hs
1 {-
2 Copyright (C) 2002-2008 John Goerzen <jgoerzen@complete.org>
3
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 -}
18 module TestParser where
19 import qualified Data.Map as Map
20 import Data.List
21 import qualified Test.HUnit as HU
22 import Test.HUnit.Utils
23 import Data.Word
24 import Test.QuickCheck
25 import TestInfrastructure
26
27 import Network.IMAP.Parser
28 import Network.IMAP.Connection
29 import Network.IMAP.Types
30
31 import TestInfrastructure
32 import TestConnection(expectedString, noCR)
33
34 prop_getFullLine_basic :: [String] -> Property
35 prop_getFullLine_basic s =
36 (null s || not ("}" `isSuffixOf` (head s))) && noCR s ==>
37 runLinesConnection s (getFullLine []) @?=
38 if null s
39 then Left "EOF in input in readLine"
40 else Right (head s, (expectedString (tail s), []))
41
42 prop_getFullLine_count :: [String] -> Property
43 prop_getFullLine_count s =
44 length s >= 2 && noCR s && (length s < 3 || not ("}" `isSuffixOf` (s !! 2)))
45 ==>
46 runLinesConnection lenS (getFullLine []) @?=
47 Right (expectedResult, (expectedRemain, []))
48 where lenS = [braceString] ++ [(head . tail $ s)] ++ drop 2 s
49 braceString = head s ++ "{" ++ show (length (s !! 1)) ++ "}"
50 expectedResult = braceString ++ "\r\n" ++ (s !! 1)
51 expectedRemain = expectedString (drop 2 s)
52
53 prop_rfr_basic :: [String] -> Property
54 prop_rfr_basic s =
55 let testlist =
56 case length s of
57 0 -> []
58 1 -> ["TAG " ++ head s]
59 _ -> map ("* " ++) (init s) ++
60 ["TAG " ++ last s]
61 resultstr = expectedString testlist
62 in noCR s && noBrace s ==>
63 runLinesConnection testlist readFullResponse @?=
64 if null s
65 then Left "EOF in input in readLine"
66 else Right (resultstr, ([], []))
67
68 noBrace s = and (map (not . isSuffixOf "}") s)
69
70 allt = [q "getFullLine_basic" prop_getFullLine_basic,
71 q "getFullLine_count" prop_getFullLine_count,
72 q "readFullResponse_basic" prop_rfr_basic
73 ]