Skip to content

Commit

Permalink
Add tests to the binding generator
Browse files Browse the repository at this point in the history
  • Loading branch information
miniBill committed Dec 2, 2024
1 parent 53525e5 commit 7f94ac0
Show file tree
Hide file tree
Showing 3 changed files with 120 additions and 30 deletions.
66 changes: 37 additions & 29 deletions cli/gen-package/elm.json
Original file line number Diff line number Diff line change
@@ -1,33 +1,41 @@
{
"type": "application",
"source-directories": ["src", "codegen", "../../src"],
"elm-version": "0.19.1",
"dependencies": {
"direct": {
"Chadtech/elm-bool-extra": "2.4.2",
"elm/browser": "1.0.2",
"elm/core": "1.0.5",
"elm/html": "1.0.0",
"elm/json": "1.1.3",
"elm/parser": "1.1.0",
"elm/project-metadata-utils": "1.0.2",
"elm-community/maybe-extra": "5.2.0",
"rtfeldman/elm-hex": "1.0.0",
"stil4m/elm-syntax": "7.2.4",
"the-sett/elm-pretty-printer": "3.0.0"
"type": "application",
"source-directories": [
"src",
"codegen",
"../../src"
],
"elm-version": "0.19.1",
"dependencies": {
"direct": {
"Chadtech/elm-bool-extra": "2.4.2",
"elm/browser": "1.0.2",
"elm/core": "1.0.5",
"elm/html": "1.0.0",
"elm/json": "1.1.3",
"elm/parser": "1.1.0",
"elm/project-metadata-utils": "1.0.2",
"elm-community/maybe-extra": "5.2.0",
"rtfeldman/elm-hex": "1.0.0",
"stil4m/elm-syntax": "7.2.4",
"the-sett/elm-pretty-printer": "3.0.0"
},
"indirect": {
"elm/time": "1.0.0",
"elm/url": "1.0.0",
"elm/virtual-dom": "1.0.2",
"elm-community/basics-extra": "4.1.0",
"elm-community/list-extra": "8.3.0",
"miniBill/elm-unicode": "1.0.2",
"stil4m/structured-writer": "1.0.3"
}
},
"indirect": {
"elm/time": "1.0.0",
"elm/url": "1.0.0",
"elm/virtual-dom": "1.0.2",
"elm-community/basics-extra": "4.1.0",
"elm-community/list-extra": "8.3.0",
"miniBill/elm-unicode": "1.0.2",
"stil4m/structured-writer": "1.0.3"
"test-dependencies": {
"direct": {
"elm-explorations/test": "1.2.2"
},
"indirect": {
"elm/random": "1.0.0"
}
}
},
"test-dependencies": {
"direct": {},
"indirect": {}
}
}
2 changes: 1 addition & 1 deletion cli/gen-package/src/Generate.elm
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module Generate exposing (main)
module Generate exposing (main, moduleToFile, parseSources)

{-| -}

Expand Down
82 changes: 82 additions & 0 deletions cli/gen-package/tests/Tests.elm
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
module Tests exposing (suite)

import DocsFromSource
import Expect
import Generate
import Test exposing (Test, test)


source : String
source =
"""module Foo exposing (a)
import Imported exposing (Foo(..))
type alias Foo a =
Imported.Foo a
a : Foo Int
a =
Debug.todo ""
"""


expected : String
expected =
"""module Gen.Foo exposing ( moduleName_, a, values_ )
{-|
# Generated bindings for Foo
@docs moduleName_, a, values_
-}
import Elm
import Elm.Annotation as Type
{-| The name of this module. -}
moduleName_ : List String
moduleName_ =
[ "Foo" ]
{-| a: Foo.Foo Int -}
a : Elm.Expression
a =
Elm.value
{ importFrom = [ "Foo" ]
, name = "a"
, annotation = Just (Type.namedWith [ "Foo" ] "Foo" [ Type.int ])
}
values_ : { a : Elm.Expression }
values_ =
{ a =
Elm.value
{ importFrom = [ "Foo" ]
, name = "a"
, annotation = Just (Type.namedWith [ "Foo" ] "Foo" [ Type.int ])
}
}"""


suite : Test
suite =
test "Aliases are codegenned properly" <|
\_ ->
case DocsFromSource.fromSource source of
Err _ ->
Expect.fail "Could not parse source"

Ok file ->
Generate.moduleToFile file
|> Expect.equal
{ path = "Gen/Foo.elm"
, contents = expected
, warnings = []
}

0 comments on commit 7f94ac0

Please sign in to comment.