From a8c5fce4b61707ee74e37f47d2110b348aa8c2e0 Mon Sep 17 00:00:00 2001 From: Taylor Fausak Date: Mon, 10 May 2021 21:34:04 -0400 Subject: [PATCH] Add tests for `tryVia` --- src/test/Main.hs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/test/Main.hs b/src/test/Main.hs index c9b4abd..f8a9b01 100644 --- a/src/test/Main.hs +++ b/src/test/Main.hs @@ -62,6 +62,12 @@ main = Hspec.hspec . Hspec.describe "Witch" $ do Hspec.describe "tryInto" $ do test $ hush (Witch.tryInto @Int.Int8 (1 :: Int.Int16)) `Hspec.shouldBe` Just 1 + Hspec.describe "tryVia" $ do + let f = Witch.tryVia @Int.Int16 @Int.Int32 @Int.Int8 + test $ hush (f 1) `Hspec.shouldBe` Just 1 + test $ hush (f 128) `Hspec.shouldBe` Nothing + test $ hush (f 32768) `Hspec.shouldBe` Nothing + Hspec.describe "unsafeFrom" $ do test $ Witch.unsafeFrom (1 :: Int.Int16) `Hspec.shouldBe` (1 :: Int.Int8) test $ Exception.evaluate (Witch.unsafeFrom @Int.Int16 @Int.Int8 128) `Hspec.shouldThrow` Hspec.anyException