1- module Tests exposing (suite )
1+ module Tests exposing (parserBinding , testAliases )
22
33import Ansi.Color
44import Diff
@@ -9,8 +9,8 @@ import Generate
99import Test exposing (Test , test )
1010
1111
12- suite : Test
13- suite =
12+ parserBinding : Test
13+ parserBinding =
1414 testBinding " Parser" parserModule parserBindings
1515
1616
@@ -127,3 +127,75 @@ caseOf_ =
127127 Basics.identity
128128 ]
129129 }"""
130+
131+
132+ aliasSource : String
133+ aliasSource =
134+ """ module Foo exposing (a)
135+
136+ import Imported exposing (Foo(..))
137+
138+
139+ type alias Foo a =
140+ Imported.Foo a
141+
142+
143+ a : Foo Int
144+ a =
145+ Debug.todo ""
146+ """
147+
148+
149+ aliasExpected : String
150+ aliasExpected =
151+ """ module Gen.Foo exposing ( moduleName_, a, values_ )
152+
153+ {-|
154+ # Generated bindings for Foo
155+
156+ @docs moduleName_, a, values_
157+ -}
158+
159+
160+ import Elm
161+ import Elm.Annotation as Type
162+
163+
164+ {-| The name of this module. -}
165+ moduleName_ : List String
166+ moduleName_ =
167+ [ "Foo" ]
168+
169+
170+ {-| a: Foo.Foo Int -}
171+ a : Elm.Expression
172+ a =
173+ Elm.value
174+ { importFrom = [ "Foo" ]
175+ , name = "a"
176+ , annotation = Just (Type.namedWith [ "Foo" ] "Foo" [ Type.int ])
177+ }
178+
179+
180+ values_ : { a : Elm.Expression }
181+ values_ =
182+ { a =
183+ Elm.value
184+ { importFrom = [ "Foo" ]
185+ , name = "a"
186+ , annotation = Just (Type.namedWith [ "Foo" ] "Foo" [ Type.int ])
187+ }
188+ }"""
189+
190+
191+ testAliases : Test
192+ testAliases =
193+ test " Aliases are codegenned properly" <|
194+ \ _ ->
195+ case DocsFromSource . fromSource aliasSource of
196+ Err _ ->
197+ Expect . fail " Could not parse source"
198+
199+ Ok file ->
200+ ( Generate . moduleToFile file) . contents
201+ |> expectEqualMultiline aliasExpected
0 commit comments