aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/Cana/UtilSpec.hs27
-rw-r--r--test/Spec.hs3
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 #-}