diff options
author | Daniel Schadt <kingdread@gmx.de> | 2021-08-03 17:36:28 +0200 |
---|---|---|
committer | Daniel Schadt <kingdread@gmx.de> | 2021-08-03 17:36:28 +0200 |
commit | ace37a9df956828634c94637d621180002a7920c (patch) | |
tree | 37b69353aefacdedf680df06a52a76a031bf817c /test | |
parent | daba74c8bc066c29eb3488246835f765c111b0c7 (diff) | |
download | Cana-ace37a9df956828634c94637d621180002a7920c.tar.gz Cana-ace37a9df956828634c94637d621180002a7920c.tar.bz2 Cana-ace37a9df956828634c94637d621180002a7920c.zip |
add basic test infrastructure
So far, the tests are still pretty pointless, but the infrastructure to
build better tests is there now.
Diffstat (limited to 'test')
-rw-r--r-- | test/Cana/UtilSpec.hs | 27 | ||||
-rw-r--r-- | test/Spec.hs | 3 |
2 files changed, 28 insertions, 2 deletions
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 #-} |