Add toElmType spec for primitive types

This commit is contained in:
MATSUBARA Nobutada 2019-08-04 02:31:12 +09:00
parent 38289cc4d0
commit c99f8cd96a
3 changed files with 24 additions and 0 deletions

View File

@ -59,6 +59,7 @@ test-suite derive-elm-tests
Elm.TyRenderSpec
Elm.JsonSpec
Elm.ModuleSpec
Elm.TyRepSpec
build-depends:
base,
hspec >= 2.0,

21
test/Elm/TyRepSpec.hs Normal file
View File

@ -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")

View File

@ -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