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. --- Cana.cabal | 2 ++ package.yaml | 1 + test/Cana/UtilSpec.hs | 27 +++++++++++++++++++++++++++ test/Spec.hs | 3 +-- 4 files changed, 31 insertions(+), 2 deletions(-) create mode 100644 test/Cana/UtilSpec.hs diff --git a/Cana.cabal b/Cana.cabal index e81c75a..92ae4d6 100644 --- a/Cana.cabal +++ b/Cana.cabal @@ -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 #-} -- cgit v1.2.3