]> gitweb @ CieloNegro.org - Rakka.git/blob - test/WikiParserTest.hs
wrote more...
[Rakka.git] / test / WikiParserTest.hs
1 module WikiParserTest
2     ( testData
3     )
4     where
5
6 import           Rakka.Wiki
7 import           Rakka.Wiki.Parser
8 import           Test.HUnit
9 import           Text.ParserCombinators.Parsec
10
11
12 parseWiki :: String -> Either String WikiPage
13 parseWiki src = case parse wikiPage "" src of
14                   Left  err  -> Left (show err)
15                   Right page -> Right page
16
17
18 testData :: [Test]
19 testData = [ (parseWiki ""
20               ~?=
21               (Right []))
22
23            , (parseWiki "=heading="
24               ~?=
25               (Right [Block (Heading 1 "heading")]))
26
27            , (parseWiki "==      heading  ==  \n"
28               ~?=
29               (Right [Block (Heading 2 "heading")]))
30
31            , (parseWiki "===== hello world =====\n"
32               ~?=
33               (Right [Block (Heading 5 "hello world")]))
34
35            , (parseWiki "a =not a heading="
36               ~?=
37               (Right [Inline (Text "a =not a heading=")]))
38
39            , (parseWiki "=h=\n\n=h="
40               ~?=
41               (Right [ Block (Heading 1 "h")
42                      , Block (Heading 1 "h")
43                      ]))
44
45            , (parseWiki "foo\nbar\n\nbaz\n"
46               ~?=
47               (Right [ Inline (Text "foo")
48                      , Inline (Text "\n")
49                      , Inline (Text "bar")
50                      , Block EmptyLine
51                      , Inline (Text "baz")
52                      , Inline (Text "\n")
53                      ]))
54
55            , (parseWiki "foo\n\n\nbar"
56               ~?=
57               (Right [ Inline (Text "foo")
58                      , Block EmptyLine
59                      , Inline (Text "bar")
60                      ]))
61
62            , (parseWiki "foo\n=h="
63               ~?=
64               (Right [ Inline (Text "foo")
65                      , Inline (Text "\n")
66                      , Block (Heading 1 "h")
67                      ]))
68
69            , (parseWiki "<!-- comment -->"
70               ~?=
71               (Right []))
72
73            , (parseWiki "<!-- comment -->foo"
74               ~?=
75               (Right [Inline (Text "foo")]))
76
77            , (parseWiki "foo<!-- comment -->"
78               ~?=
79               (Right [Inline (Text "foo")]))
80
81            , (parseWiki "foo<!-- comment -->bar"
82               ~?=
83               (Right [ Inline (Text "foo")
84                      , Inline (Text "bar")
85                      ]))
86
87            , (parseWiki "<!-- comment -->=h="
88               ~?=
89               (Right [Block (Heading 1 "h")]))
90
91            , (parseWiki "=h= <!---->"
92               ~?=
93               (Right [Block (Heading 1 "h")]))
94
95            , (parseWiki "<!-- <!-- nested --> comment -->"
96               ~?=
97               (Right []))
98
99            , (parseWiki "[[Page]]"
100               ~?= 
101               (Right [Inline (PageLink (Just "Page") Nothing Nothing)]))
102
103            , (parseWiki "[[Page|Link to \"Page\"]]"
104               ~?=
105               (Right [Inline (PageLink (Just "Page") Nothing (Just "Link to \"Page\""))]))
106
107            , (parseWiki "[[Page#foo]]"
108               ~?= 
109               (Right [Inline (PageLink (Just "Page") (Just "foo") Nothing)]))
110
111            , (parseWiki "[[#foo]]"
112               ~?= 
113               (Right [Inline (PageLink Nothing (Just "foo") Nothing)]))
114
115            , (parseWiki "[[Page#foo|Link to \"Page#foo\"]]"
116               ~?=
117               (Right [Inline (PageLink (Just "Page") (Just "foo") (Just "Link to \"Page#foo\""))]))
118
119            , (parseWiki "foo [[Bar]] baz"
120               ~?=
121               (Right [ Inline (Text "foo ")
122                      , Inline (PageLink (Just "Bar") Nothing Nothing)
123                      , Inline (Text " baz")
124                      ]))
125
126            , (parseWiki "[[Foo]]\n[[Bar]]"
127               ~?= 
128               (Right [ Inline (PageLink (Just "Foo") Nothing Nothing)
129                      , Inline (Text "\n")
130                      , Inline (PageLink (Just "Bar") Nothing Nothing)
131                      ]))
132            ]