From 57c56564d15cd5c83a4f1d1bab5490e6b75e8656 Mon Sep 17 00:00:00 2001 From: Gregor Kleen Date: Mon, 18 Jan 2016 12:09:36 +0000 Subject: Moved Printout.BBCode to own module --- tp-bbcode/test/Spec.hs | 1 + tp-bbcode/test/Thermoprint/Printout/BBCodeSpec.hs | 42 +++++++++++++++++++++++ 2 files changed, 43 insertions(+) create mode 100644 tp-bbcode/test/Spec.hs create mode 100644 tp-bbcode/test/Thermoprint/Printout/BBCodeSpec.hs (limited to 'tp-bbcode/test') 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 @@ +{-# 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 -- cgit v1.2.3