aboutsummaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
authorGregor Kleen <gkleen@yggdrasil.li>2016-01-18 11:39:51 +0000
committerGregor Kleen <gkleen@yggdrasil.li>2016-01-18 11:39:51 +0000
commit9435083465a487553b21c599c1340aa5e5ed8a1c (patch)
tree39a4e8fbfefb48f7da00e2fbfa4268db329d7afc /spec
parentabb427bdccfe78649f5d75654a8179093201609c (diff)
downloadthermoprint-9435083465a487553b21c599c1340aa5e5ed8a1c.tar
thermoprint-9435083465a487553b21c599c1340aa5e5ed8a1c.tar.gz
thermoprint-9435083465a487553b21c599c1340aa5e5ed8a1c.tar.bz2
thermoprint-9435083465a487553b21c599c1340aa5e5ed8a1c.tar.xz
thermoprint-9435083465a487553b21c599c1340aa5e5ed8a1c.zip
First tests for Printout.BBCode
Diffstat (limited to 'spec')
-rw-r--r--spec/test/Thermoprint/Printout/BBCodeSpec.hs42
1 files changed, 42 insertions, 0 deletions
diff --git a/spec/test/Thermoprint/Printout/BBCodeSpec.hs b/spec/test/Thermoprint/Printout/BBCodeSpec.hs
new file mode 100644
index 0000000..f3f1840
--- /dev/null
+++ b/spec/test/Thermoprint/Printout/BBCodeSpec.hs
@@ -0,0 +1,42 @@
1{-# LANGUAGE OverloadedStrings, OverloadedLists #-}
2{-# LANGUAGE StandaloneDeriving #-}
3
4module Thermoprint.Printout.BBCodeSpec (spec) where
5
6import Test.Hspec
7import Test.Hspec.QuickCheck (prop)
8import Test.QuickCheck.Instances
9
10import Thermoprint.Printout.BBCode
11import Thermoprint.Printout
12
13import Data.Text (Text)
14
15import Control.Monad (zipWithM_)
16import Data.Monoid ((<>))
17import Data.Function (on)
18
19import qualified Data.Sequence as Seq (fromList)
20
21instance Eq Block where
22 (==) = (==) `on` cotext
23deriving instance Eq Chunk
24
25spec :: Spec
26spec = do
27 zipWithM_ example [1..] examples
28 where
29 example n (s, ts) = let str = "Example " <> show n
30 in specify str $ bbcode s == (pOut <$> ts)
31
32pOut :: [Block] -> Printout
33pOut = pure . Seq.fromList . map Cooked
34
35examples :: [(Text, Either BBCodeError [Block])]
36examples = [ ("Hello World!"
37 , Right [Line (JuxtaPos [word "Hello", HSpace 1, word "World!"])])
38 , ("Hello [hspace width=2/] World!"
39 , Right [Line (JuxtaPos [word "Hello", HSpace 4, word "World!"])])
40 ]
41 where
42 word = (\(Right l) -> l) . text