-
Notifications
You must be signed in to change notification settings - Fork 200
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8b6e1bf
commit 2370f24
Showing
6 changed files
with
95 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
{-| | ||
Module: Test.SchemaCompilerSpec | ||
Copyright: (c) digitally induced GmbH, 2020 | ||
-} | ||
module Test.SchemaCompilerSpec where | ||
|
||
import Test.Hspec | ||
import IHP.Prelude | ||
import IHP.SchemaCompiler | ||
import IHP.IDE.SchemaDesigner.Types | ||
import NeatInterpolation | ||
import qualified Data.Text as Text | ||
|
||
tests = do | ||
describe "SchemaCompiler" do | ||
describe "compileEnumDataDefinitions" do | ||
it "should deal with enum values that have spaces" do | ||
let statement = CreateEnumType { name = "mood", values = ["happy", "very happy", "sad", "very sad"] } | ||
let output = compileStatementPreview [statement] statement |> Text.strip | ||
|
||
output `shouldBe` [text| | ||
data Mood = Happy | VeryHappy | Sad | VerySad deriving (Eq, Show, Read, Enum) | ||
instance FromField Mood where | ||
fromField field (Just value) | value == (Data.Text.Encoding.encodeUtf8 "happy") = pure Happy | ||
fromField field (Just value) | value == (Data.Text.Encoding.encodeUtf8 "very happy") = pure VeryHappy | ||
fromField field (Just value) | value == (Data.Text.Encoding.encodeUtf8 "sad") = pure Sad | ||
fromField field (Just value) | value == (Data.Text.Encoding.encodeUtf8 "very sad") = pure VerySad | ||
fromField field (Just value) = returnError ConversionFailed field ("Unexpected value for enum value. Got: " <> Data.String.Conversions.cs value) | ||
fromField field Nothing = returnError UnexpectedNull field "Unexpected null for enum value" | ||
instance Default Mood where def = Happy | ||
instance ToField Mood where | ||
toField Happy = toField ("happy" :: Text) | ||
toField VeryHappy = toField ("very happy" :: Text) | ||
toField Sad = toField ("sad" :: Text) | ||
toField VerySad = toField ("very sad" :: Text) | ||
instance InputValue Mood where | ||
inputValue Happy = "happy" :: Text | ||
inputValue VeryHappy = "very happy" :: Text | ||
inputValue Sad = "sad" :: Text | ||
inputValue VerySad = "very sad" :: Text | ||
|
||
instance IHP.Controller.Param.ParamReader Mood where readParameter = IHP.Controller.Param.enumParamReader | ||
|] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters