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 | |
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.
-rw-r--r-- | Cana.cabal | 2 | ||||
-rw-r--r-- | package.yaml | 1 | ||||
-rw-r--r-- | test/Cana/UtilSpec.hs | 27 | ||||
-rw-r--r-- | test/Spec.hs | 3 |
4 files changed, 31 insertions, 2 deletions
@@ -99,6 +99,7 @@ test-suite Cana-test type: exitcode-stdio-1.0 main-is: Spec.hs other-modules: + Cana.UtilSpec Paths_Cana hs-source-dirs: test @@ -110,6 +111,7 @@ test-suite Cana-test , data-default , directory , filepath + , hspec , mime-types , network , network-uri diff --git a/package.yaml b/package.yaml index 091eadb..f325091 100644 --- a/package.yaml +++ b/package.yaml @@ -84,3 +84,4 @@ tests: - -with-rtsopts=-N dependencies: - Cana + - hspec 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 #-} |