blob: f3f1840a4176dcc48abb24c550bb2f59b0f9c06f (
plain)
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
|
{-# LANGUAGE OverloadedStrings, OverloadedLists #-}
{-# LANGUAGE StandaloneDeriving #-}
module Thermoprint.Printout.BBCodeSpec (spec) where
import Test.Hspec
import Test.Hspec.QuickCheck (prop)
import Test.QuickCheck.Instances
import Thermoprint.Printout.BBCode
import Thermoprint.Printout
import Data.Text (Text)
import Control.Monad (zipWithM_)
import Data.Monoid ((<>))
import Data.Function (on)
import qualified Data.Sequence as Seq (fromList)
instance Eq Block where
(==) = (==) `on` cotext
deriving instance Eq Chunk
spec :: Spec
spec = do
zipWithM_ example [1..] examples
where
example n (s, ts) = let str = "Example " <> show n
in specify str $ bbcode s == (pOut <$> ts)
pOut :: [Block] -> Printout
pOut = pure . Seq.fromList . map Cooked
examples :: [(Text, Either BBCodeError [Block])]
examples = [ ("Hello World!"
, Right [Line (JuxtaPos [word "Hello", HSpace 1, word "World!"])])
, ("Hello [hspace width=2/] World!"
, Right [Line (JuxtaPos [word "Hello", HSpace 4, word "World!"])])
]
where
word = (\(Right l) -> l) . text
|