-
Notifications
You must be signed in to change notification settings - Fork 0
/
MIMEDir_test.hs
77 lines (66 loc) · 3.58 KB
/
MIMEDir_test.hs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
-- Copyright 2010 Leonid Movshovich <[email protected]>
-- This file is part of SPIM.
-- SPIM is free software: you can redistribute it and/or modify
-- it under the terms of the GNU Affero General Public License as published by
-- the Free Software Foundation, either version 3 of the License, or
-- (at your option) any later version.
-- SPIM is distributed in the hope that it will be useful,
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-- GNU Affero General Public License for more details.
-- You should have received a copy of the GNU Affero General Public License
-- along with SPIM. If not, see <http://www.gnu.org/licenses/>.
module Main where
import Test.HUnit
import qualified Data.Map as Map
import MIMEDir
clTests = test
-- positive tests
["happy path" ~: readContentLine "name;param=pval1,pval2:value"
@?= ContentLine "name"
(Map.singleton "param" "pval1,pval2")
"value"
, "empty value" ~: readContentLine "name;param=pval:"
@?= ContentLine "name"
(Map.singleton "param" "pval")
""
, "empty params" ~: readContentLine "name:value"
@?= ContentLine "name"
(Map.empty)
"value"
, "empty param value" ~: readContentLine "name;param=:value"
@?= ContentLine "name"
(Map.singleton "param" "")
"value"
, "empty name" ~: readContentLine ":value" @?= ContentLine "" (Map.empty) "value"
-- negative tests
, "no colon" ~: do res <- catch (readIO "sometext")
(\e -> do return "")
assertEqual "read of wrong string had to rise" "" res]
vcTests = test [
"takeBeforeCRLF" ~: takeBeforeCRLF "text\r\nothertext" @?= "text"
, "readCL" ~: readContentLine "begin:vcard"
@?= ContentLine "begin" Map.empty "vcard"
, "reads" ~: contentLineFromString "begin:vcard\r\ntherest"
@?= (ContentLine "begin" Map.empty "vcard", "therest")
, "readCLs1" ~: readContentLines "begin:vcard\r\n"
@?= [ContentLine "begin" Map.empty "vcard"]
, "readCLs2" ~: readContentLines "begin:vcard\r\nend:vcard\r\n"
@?= [ContentLine "begin" Map.empty "vcard"
, ContentLine "end" Map.empty "vcard"]
, "happy path" ~: mimeDirToString (mimeDirFromString "BEGIN:VCARD\r\nEND:VCARD")
@?= mimeDirToString (MIMEDir "VCARD" Map.empty)
, "reverse happy path" ~: mimeDirToString MIMEDir
{kind = "INDEX",
contents =
(Map.fromList
[("1234321", Left [(Map.empty, "PP")])
, ("FIELD", Left [(Map.empty, "TEL")])])}
@?= "BEGIN:INDEX\r\n1234321:PP\r\nFIELD:TEL\r\nEND:INDEX\r\n"
]
main :: IO ()
main = do putStr "ContentLine tests:\n"
_ <- runTestTT clTests
putStr "MIMEDir tests:\n"
_ <- runTestTT vcTests
return ()