From c99f8cd96a6d45a03254700b7714202e80c0938b Mon Sep 17 00:00:00 2001 From: MATSUBARA Nobutada Date: Sun, 4 Aug 2019 02:31:12 +0900 Subject: [PATCH] Add toElmType spec for primitive types --- elm-bridge.cabal | 1 + test/Elm/TyRepSpec.hs | 21 +++++++++++++++++++++ test/Spec.hs | 2 ++ 3 files changed, 24 insertions(+) create mode 100644 test/Elm/TyRepSpec.hs diff --git a/elm-bridge.cabal b/elm-bridge.cabal index 008f855..2092b7d 100644 --- a/elm-bridge.cabal +++ b/elm-bridge.cabal @@ -59,6 +59,7 @@ test-suite derive-elm-tests Elm.TyRenderSpec Elm.JsonSpec Elm.ModuleSpec + Elm.TyRepSpec build-depends: base, hspec >= 2.0, diff --git a/test/Elm/TyRepSpec.hs b/test/Elm/TyRepSpec.hs new file mode 100644 index 0000000..c03464f --- /dev/null +++ b/test/Elm/TyRepSpec.hs @@ -0,0 +1,21 @@ +module Elm.TyRepSpec (spec) where + +import Elm.TyRep + +import Data.Proxy +import Test.Hspec + +spec :: Spec +spec = + describe "toElmType" $ + it "should produce the correct code" $ + do toElmType (Proxy :: Proxy Int) `shouldBe` ETyCon (ETCon "Int") + toElmType (Proxy :: Proxy Float) `shouldBe` ETyCon (ETCon "Float") + toElmType (Proxy :: Proxy String) `shouldBe` ETyCon (ETCon "String") + toElmType (Proxy :: Proxy Bool) `shouldBe` ETyCon (ETCon "Bool") + toElmType (Proxy :: Proxy Char) `shouldBe` ETyCon (ETCon "Char") + toElmType (Proxy :: Proxy [Int]) `shouldBe` ETyApp (ETyCon $ ETCon "List") (ETyCon $ ETCon "Int") + toElmType (Proxy :: Proxy (Maybe Int)) `shouldBe` ETyApp (ETyCon $ ETCon "Maybe") (ETyCon $ ETCon "Int") + toElmType (Proxy :: Proxy ()) `shouldBe` ETyTuple 0 + toElmType (Proxy :: Proxy (Int, Bool)) `shouldBe` ETyApp (ETyApp (ETyTuple 2) (ETyCon $ ETCon "Int")) (ETyCon $ ETCon "Bool") + toElmType (Proxy :: Proxy (Int, Bool, String)) `shouldBe` ETyApp (ETyApp (ETyApp (ETyTuple 3) (ETyCon $ ETCon "Int")) (ETyCon $ ETCon "Bool")) (ETyCon $ ETCon "String") diff --git a/test/Spec.hs b/test/Spec.hs index 1251383..f096292 100644 --- a/test/Spec.hs +++ b/test/Spec.hs @@ -4,6 +4,7 @@ import qualified Elm.DeriveSpec import qualified Elm.TyRenderSpec import qualified Elm.JsonSpec import qualified Elm.ModuleSpec +import qualified Elm.TyRepSpec import Test.Hspec @@ -13,3 +14,4 @@ main = hspec $ do describe "Elm.TyRenderSpec" Elm.TyRenderSpec.spec describe "Elm.JsonSpec" Elm.JsonSpec.spec describe "Elm.ModuleSpec" Elm.ModuleSpec.spec + describe "Elm.TyRepSpec" Elm.TyRepSpec.spec