aboutsummaryrefslogtreecommitdiff
path: root/bbcode/test/Text/BBCodeSpec.hs
diff options
context:
space:
mode:
Diffstat (limited to 'bbcode/test/Text/BBCodeSpec.hs')
-rw-r--r--bbcode/test/Text/BBCodeSpec.hs59
1 files changed, 59 insertions, 0 deletions
diff --git a/bbcode/test/Text/BBCodeSpec.hs b/bbcode/test/Text/BBCodeSpec.hs
new file mode 100644
index 0000000..0d8949a
--- /dev/null
+++ b/bbcode/test/Text/BBCodeSpec.hs
@@ -0,0 +1,59 @@
1{-# LANGUAGE OverloadedStrings, OverloadedLists #-}
2
3module Text.BBCodeSpec (spec) where
4
5import Test.Hspec
6import Test.Hspec.QuickCheck (prop)
7import Test.QuickCheck.Instances
8
9import Text.BBCode
10
11import Data.Text (Text)
12
13import Control.Monad (zipWithM_)
14import Data.Monoid ((<>))
15
16spec :: Spec
17spec = do
18 zipWithM_ example [1..] examples
19 where
20 example n (s, ts) = let str = "Example " <> show n
21 in specify str (bbcode s == Right ts)
22
23examples :: [(Text, [DomTree])]
24examples = [ ("[t]test[/t]"
25 , [Element "t" [] [Content "test"]])
26 , ("[t]te\\st[/t]"
27 , [Element "t" [] [Content "te\\st"]])
28 , ("[t]te\\[st[/t]"
29 , [Element "t" [] [Content "te[st"]])
30 , ("[t]test\\\\[/t]"
31 , [Element "t" [] [Content "test\\"]])
32 , ("[\\t]test[/\\t]"
33 , [Element "\\t" [] [Content "test"]])
34 , ("[t attr]test[/t]"
35 , [Element "t" [("attr", "")] [Content "test"]])
36 , ("[t=attr]test[/t]"
37 , [Element "t" [("", "attr")] [Content "test"]])
38 , ("[t attr=val]test[/t]"
39 , [Element "t" [("attr", "val")] [Content "test"]])
40 , ("[t attr=\"val\"]test[/t]"
41 , [Element "t" [("attr", "val")] [Content "test"]])
42 , ("[t attr=\"va]l\"]test[/t]"
43 , [Element "t" [("attr", "va]l")] [Content "test"]])
44 , ("[t attr=\"va\\\"l\"]test[/t]"
45 , [Element "t" [("attr", "va\"l")] [Content "test"]])
46 , ("[t attr=\"val\" attr2=\"val2\" ]test[/t]"
47 , [Element "t" [("attr", "val"), ("attr2", "val2")] [Content "test"]])
48 , ("[br/]"
49 , [Element "br" [] []])
50 , ("[br attr/]"
51 , [Element "br" [("attr", "")] []])
52 , ("[br=val/]"
53 , [Element "br" [("", "val")] []])
54 , ("[br attr=val/]"
55 , [Element "br" [("attr", "val")] []])
56 , ("[br attr=val val2/]"
57 , [Element "br" [("attr", "val"), ("val2", "")] []])
58 ]
59