diff options
author | Gregor Kleen <gkleen@yggdrasil.li> | 2016-01-18 12:09:36 +0000 |
---|---|---|
committer | Gregor Kleen <gkleen@yggdrasil.li> | 2016-01-18 12:09:36 +0000 |
commit | 57c56564d15cd5c83a4f1d1bab5490e6b75e8656 (patch) | |
tree | 55ea741665155b46b9e599b149dee3323fe479c0 /tp-bbcode/test | |
parent | 9435083465a487553b21c599c1340aa5e5ed8a1c (diff) | |
download | thermoprint-57c56564d15cd5c83a4f1d1bab5490e6b75e8656.tar thermoprint-57c56564d15cd5c83a4f1d1bab5490e6b75e8656.tar.gz thermoprint-57c56564d15cd5c83a4f1d1bab5490e6b75e8656.tar.bz2 thermoprint-57c56564d15cd5c83a4f1d1bab5490e6b75e8656.tar.xz thermoprint-57c56564d15cd5c83a4f1d1bab5490e6b75e8656.zip |
Moved Printout.BBCode to own module
Diffstat (limited to 'tp-bbcode/test')
-rw-r--r-- | tp-bbcode/test/Spec.hs | 1 | ||||
-rw-r--r-- | tp-bbcode/test/Thermoprint/Printout/BBCodeSpec.hs | 42 |
2 files changed, 43 insertions, 0 deletions
diff --git a/tp-bbcode/test/Spec.hs b/tp-bbcode/test/Spec.hs new file mode 100644 index 0000000..a824f8c --- /dev/null +++ b/tp-bbcode/test/Spec.hs | |||
@@ -0,0 +1 @@ | |||
{-# OPTIONS_GHC -F -pgmF hspec-discover #-} | |||
diff --git a/tp-bbcode/test/Thermoprint/Printout/BBCodeSpec.hs b/tp-bbcode/test/Thermoprint/Printout/BBCodeSpec.hs new file mode 100644 index 0000000..f3f1840 --- /dev/null +++ b/tp-bbcode/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 | ||