diff options
| author | Gregor Kleen <gkleen@yggdrasil.li> | 2016-01-18 11:39:51 +0000 |
|---|---|---|
| committer | Gregor Kleen <gkleen@yggdrasil.li> | 2016-01-18 11:39:51 +0000 |
| commit | 9435083465a487553b21c599c1340aa5e5ed8a1c (patch) | |
| tree | 39a4e8fbfefb48f7da00e2fbfa4268db329d7afc | |
| parent | abb427bdccfe78649f5d75654a8179093201609c (diff) | |
| download | thermoprint-9435083465a487553b21c599c1340aa5e5ed8a1c.tar thermoprint-9435083465a487553b21c599c1340aa5e5ed8a1c.tar.gz thermoprint-9435083465a487553b21c599c1340aa5e5ed8a1c.tar.bz2 thermoprint-9435083465a487553b21c599c1340aa5e5ed8a1c.tar.xz thermoprint-9435083465a487553b21c599c1340aa5e5ed8a1c.zip | |
First tests for Printout.BBCode
| -rw-r--r-- | spec/test/Thermoprint/Printout/BBCodeSpec.hs | 42 |
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 | |||
| 4 | module Thermoprint.Printout.BBCodeSpec (spec) where | ||
| 5 | |||
| 6 | import Test.Hspec | ||
| 7 | import Test.Hspec.QuickCheck (prop) | ||
| 8 | import Test.QuickCheck.Instances | ||
| 9 | |||
| 10 | import Thermoprint.Printout.BBCode | ||
| 11 | import Thermoprint.Printout | ||
| 12 | |||
| 13 | import Data.Text (Text) | ||
| 14 | |||
| 15 | import Control.Monad (zipWithM_) | ||
| 16 | import Data.Monoid ((<>)) | ||
| 17 | import Data.Function (on) | ||
| 18 | |||
| 19 | import qualified Data.Sequence as Seq (fromList) | ||
| 20 | |||
| 21 | instance Eq Block where | ||
| 22 | (==) = (==) `on` cotext | ||
| 23 | deriving instance Eq Chunk | ||
| 24 | |||
| 25 | spec :: Spec | ||
| 26 | spec = 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 | |||
| 32 | pOut :: [Block] -> Printout | ||
| 33 | pOut = pure . Seq.fromList . map Cooked | ||
| 34 | |||
| 35 | examples :: [(Text, Either BBCodeError [Block])] | ||
| 36 | examples = [ ("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 | ||
