aboutsummaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
authorGregor Kleen <gkleen@yggdrasil.li>2016-01-10 00:30:18 +0000
committerGregor Kleen <gkleen@yggdrasil.li>2016-01-10 00:30:18 +0000
commit0bb617ff93d242d20e9e63f44664f38a653898d4 (patch)
treee007e973bd670dec4169b2f070c4bccd5efb5886 /spec
parent11a3a881157494508593bc2323fbc62b6ee04b5f (diff)
downloadthermoprint-0bb617ff93d242d20e9e63f44664f38a653898d4.tar
thermoprint-0bb617ff93d242d20e9e63f44664f38a653898d4.tar.gz
thermoprint-0bb617ff93d242d20e9e63f44664f38a653898d4.tar.bz2
thermoprint-0bb617ff93d242d20e9e63f44664f38a653898d4.tar.xz
thermoprint-0bb617ff93d242d20e9e63f44664f38a653898d4.zip
reworked test harness for (partial) auto-detection
Diffstat (limited to 'spec')
-rw-r--r--spec/Spec.hs8
-rw-r--r--spec/src/Thermoprint/Printout.hs7
-rw-r--r--spec/test/Spec.hs1
-rw-r--r--spec/test/Thermoprint/PrintoutSpec.hs9
-rw-r--r--spec/thermoprint-spec.cabal5
5 files changed, 18 insertions, 12 deletions
diff --git a/spec/Spec.hs b/spec/Spec.hs
deleted file mode 100644
index 79f2983..0000000
--- a/spec/Spec.hs
+++ /dev/null
@@ -1,8 +0,0 @@
1import Test.Hspec
2import Test.Hspec.QuickCheck
3
4import qualified Thermoprint.Printout
5
6main :: IO ()
7main = hspec $ do
8 prop "Thermoprint.Printout.prop_text" Thermoprint.Printout.prop_text
diff --git a/spec/src/Thermoprint/Printout.hs b/spec/src/Thermoprint/Printout.hs
index 7c6d5c0..32c403c 100644
--- a/spec/src/Thermoprint/Printout.hs
+++ b/spec/src/Thermoprint/Printout.hs
@@ -149,12 +149,13 @@ cotext (Line x) = cotext' x
149 cotext' (HSpace n) = TL.pack . genericReplicate n $ ' ' 149 cotext' (HSpace n) = TL.pack . genericReplicate n $ ' '
150 cotext' (SpaceSep xs) = TL.intercalate " " . map cotext' . toList $ xs 150 cotext' (SpaceSep xs) = TL.intercalate " " . map cotext' . toList $ xs
151 151
152prop_text :: Property 152prop_text :: Text -> Bool
153-- ^ prop> cotext . either id Line . `text` $ x = x 153-- ^ prop> (`cotext` . either id Line . `text` $ x) == x
154-- 154--
155-- Where 'x' is restricted to those `TL.Text` which do not contain whitespace besides ' ' and '\n'. 155-- Where 'x' is restricted to those `TL.Text` which do not contain whitespace besides ' ' and '\n'.
156prop_text = forAll (TL.map normSpace <$> arbitrary) $ \x -> (cotext . either id Line . text $ x) == x 156prop_text x = (cotext . either id Line . text $ x') == x'
157 where 157 where
158 x' = TL.map normSpace x
158 normSpace c 159 normSpace c
159 | isSpace c 160 | isSpace c
160 , c `elem` keep = c 161 , c `elem` keep = c
diff --git a/spec/test/Spec.hs b/spec/test/Spec.hs
new file mode 100644
index 0000000..a824f8c
--- /dev/null
+++ b/spec/test/Spec.hs
@@ -0,0 +1 @@
{-# OPTIONS_GHC -F -pgmF hspec-discover #-}
diff --git a/spec/test/Thermoprint/PrintoutSpec.hs b/spec/test/Thermoprint/PrintoutSpec.hs
new file mode 100644
index 0000000..5a48496
--- /dev/null
+++ b/spec/test/Thermoprint/PrintoutSpec.hs
@@ -0,0 +1,9 @@
1module Thermoprint.PrintoutSpec (spec) where
2
3import Test.Hspec
4import Test.Hspec.QuickCheck (prop)
5import Thermoprint.Printout
6
7spec :: Spec
8spec = do
9 prop "prop_text" prop_text
diff --git a/spec/thermoprint-spec.cabal b/spec/thermoprint-spec.cabal
index ba97420..c4599c8 100644
--- a/spec/thermoprint-spec.cabal
+++ b/spec/thermoprint-spec.cabal
@@ -38,7 +38,10 @@ library
38 38
39Test-Suite tests 39Test-Suite tests
40 type: exitcode-stdio-1.0 40 type: exitcode-stdio-1.0
41 hs-source-dirs: test
41 main-is: Spec.hs 42 main-is: Spec.hs
42 build-depends: base >=4.8.1 && <5 43 build-depends: base >=4.8.1 && <5
43 , thermoprint-spec -any 44 , thermoprint-spec -any
44 , hspec >=2.2.1 && <3 \ No newline at end of file 45 , hspec >=2.2.1 && <3
46 , QuickCheck >=2.8.1 && <3
47 , quickcheck-instances >=0.3.11 && <4 \ No newline at end of file