From 0bb617ff93d242d20e9e63f44664f38a653898d4 Mon Sep 17 00:00:00 2001 From: Gregor Kleen Date: Sun, 10 Jan 2016 00:30:18 +0000 Subject: reworked test harness for (partial) auto-detection --- spec/Spec.hs | 8 -------- spec/src/Thermoprint/Printout.hs | 7 ++++--- spec/test/Spec.hs | 1 + spec/test/Thermoprint/PrintoutSpec.hs | 9 +++++++++ spec/thermoprint-spec.cabal | 5 ++++- 5 files changed, 18 insertions(+), 12 deletions(-) delete mode 100644 spec/Spec.hs create mode 100644 spec/test/Spec.hs create mode 100644 spec/test/Thermoprint/PrintoutSpec.hs (limited to 'spec') 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 @@ -import Test.Hspec -import Test.Hspec.QuickCheck - -import qualified Thermoprint.Printout - -main :: IO () -main = hspec $ do - 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 cotext' (HSpace n) = TL.pack . genericReplicate n $ ' ' cotext' (SpaceSep xs) = TL.intercalate " " . map cotext' . toList $ xs -prop_text :: Property --- ^ prop> cotext . either id Line . `text` $ x = x +prop_text :: Text -> Bool +-- ^ prop> (`cotext` . either id Line . `text` $ x) == x -- -- Where 'x' is restricted to those `TL.Text` which do not contain whitespace besides ' ' and '\n'. -prop_text = forAll (TL.map normSpace <$> arbitrary) $ \x -> (cotext . either id Line . text $ x) == x +prop_text x = (cotext . either id Line . text $ x') == x' where + x' = TL.map normSpace x normSpace c | isSpace c , 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 @@ +module Thermoprint.PrintoutSpec (spec) where + +import Test.Hspec +import Test.Hspec.QuickCheck (prop) +import Thermoprint.Printout + +spec :: Spec +spec = do + 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 Test-Suite tests type: exitcode-stdio-1.0 + hs-source-dirs: test main-is: Spec.hs build-depends: base >=4.8.1 && <5 , thermoprint-spec -any - , hspec >=2.2.1 && <3 \ No newline at end of file + , hspec >=2.2.1 && <3 + , QuickCheck >=2.8.1 && <3 + , quickcheck-instances >=0.3.11 && <4 \ No newline at end of file -- cgit v1.2.3