diff --git a/src/Graphqelm/Generator/Normalize.elm b/src/Graphqelm/Generator/Normalize.elm index f9a20a6d8..f8962666e 100644 --- a/src/Graphqelm/Generator/Normalize.elm +++ b/src/Graphqelm/Generator/Normalize.elm @@ -1,14 +1,46 @@ -module Graphqelm.Generator.Normalize exposing (capitalized, decapitalized) +module Graphqelm.Generator.Normalize exposing (capitalized, decapitalized, elmKeywords) import Char import Regex import String.Extra +{-| Taken from +-} +elmKeywords : List String +elmKeywords = + [ "type" + , "alias" + , "port" + , "if" + , "then" + , "else" + , "case" + , "of" + , "let" + , "in" + , "infix" + , "left" + , "right" + , "non" + , "module" + , "import" + , "exposing" + , "as" + , "where" + , "effect" + , "command" + , "subscription" + , "true" + , "false" + , "null" + ] + + normalizeIfElmReserved : String -> String normalizeIfElmReserved name = - if name == "type" then - "type_" + if List.member name elmKeywords then + name ++ "_" else name diff --git a/tests/Generator/NormalizeTests.elm b/tests/Generator/NormalizeTests.elm index a789b082f..281db5a28 100644 --- a/tests/Generator/NormalizeTests.elm +++ b/tests/Generator/NormalizeTests.elm @@ -7,15 +7,11 @@ import Test exposing (Test, describe, only, test) all : Test all = - describe "normalize" + describe "normalize" <| [ test "leaves valid names untouched" <| \() -> Normalize.decapitalized "validCamelCaseName" |> Expect.equal "validCamelCaseName" - , test "type field name" <| - \() -> - Normalize.decapitalized "type" - |> Expect.equal "type_" , test "leaves valid snake_case names untouched" <| \() -> Normalize.decapitalized "year_budget" @@ -61,3 +57,11 @@ all = Normalize.decapitalized "________x" |> Expect.equal "x________" ] + ++ List.map + (\keyword -> + test (keyword ++ " field name") <| + \() -> + Normalize.decapitalized keyword + |> Expect.equal (keyword ++ "_") + ) + Normalize.elmKeywords