From ace37a9df956828634c94637d621180002a7920c Mon Sep 17 00:00:00 2001 From: Daniel Schadt Date: Tue, 3 Aug 2021 17:36:28 +0200 Subject: add basic test infrastructure So far, the tests are still pretty pointless, but the infrastructure to build better tests is there now. --- test/Cana/UtilSpec.hs | 27 +++++++++++++++++++++++++++ test/Spec.hs | 3 +-- 2 files changed, 28 insertions(+), 2 deletions(-) create mode 100644 test/Cana/UtilSpec.hs (limited to 'test') diff --git a/test/Cana/UtilSpec.hs b/test/Cana/UtilSpec.hs new file mode 100644 index 0000000..7a3292a --- /dev/null +++ b/test/Cana/UtilSpec.hs @@ -0,0 +1,27 @@ +module Cana.UtilSpec where + +import Test.Hspec + +import Cana.Util + +spec :: Spec +spec = do + describe "splitList" $ do + it "returns unchanged lists" $ do + splitList (0 :: Int) [1, 2, 3] `shouldBe` [[1, 2, 3]] + it "splits on the given item" $ do + splitList (0 :: Int) [1, 2, 0, 3, 4] `shouldBe` [[1, 2], [3, 4]] + it "may return empty sublists" $ do + splitList (0 :: Int) [1, 0, 0, 2] `shouldBe` [[1], [], [2]] + + describe "mapLeft" $ do + it "maps a function over the Left element" $ do + mapLeft (++" World!") (Left "Hello" :: Either String String) `shouldBe` Left "Hello World!" + it "leaves Right untouched" $ do + mapLeft (++" World!") (Right "Hello") `shouldBe` Right "Hello" + + describe "applyWhen" $ do + it "applies a function when True is given" $ do + applyWhen True (+1) (3 :: Int) `shouldBe` 4 + it "doesn't apply a function when False is given" $ do + applyWhen False (+1) (3 :: Int) `shouldBe` 3 diff --git a/test/Spec.hs b/test/Spec.hs index cd4753f..a824f8c 100644 --- a/test/Spec.hs +++ b/test/Spec.hs @@ -1,2 +1 @@ -main :: IO () -main = putStrLn "Test suite not yet implemented" +{-# OPTIONS_GHC -F -pgmF hspec-discover #-} -- cgit v1.2.3