Skip to content

Commit 48ff9b3

Browse files
committed
Add test for the JS output
1 parent d07310b commit 48ff9b3

File tree

4 files changed

+138
-0
lines changed

4 files changed

+138
-0
lines changed

test/Test/JsOutput.hs

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,55 @@ suite =
5151
expectTextContains jsOutput "$temp$list = xs"
5252
expectTextDoesNotContain jsOutput "$temp$fn = fn"
5353

54+
Nothing ->
55+
crash "JS output could not be read."
56+
, scope "direct function calls (lamdera/compiler PR #41)" $ do
57+
project <- io $ Lamdera.Relative.requireDir "test/direct-fn-calls"
58+
let
59+
elmHome = project ++ "/elm-home"
60+
elmStuff = project ++ "/elm-stuff"
61+
62+
maybeJsOutput <- io $ do
63+
rmdir elmHome
64+
rmdir elmStuff
65+
66+
Test.Helpers.withElmHome elmHome $
67+
Ext.Common.withProjectRoot project $
68+
Make.run ["src/Main.elm"] $
69+
Make.Flags
70+
{ _debug = False
71+
, _optimize = True
72+
, _output = Just (Make.JS "elm-stuff/tmp.js")
73+
, _report = Nothing
74+
, _docs = Nothing
75+
, _noWire = True
76+
, _optimizeLegible = False
77+
}
78+
79+
fileContents <- readUtf8Text $ elmStuff ++ "/tmp.js"
80+
81+
rmdir elmHome
82+
rmdir elmStuff
83+
84+
pure fileContents
85+
86+
case maybeJsOutput of
87+
Just jsOutput ->
88+
do
89+
expectTextContains jsOutput "$fn2$ = function (x, y) {"
90+
expectTextContains jsOutput "$fn3$ = function (x, y, z) {"
91+
expectTextContains jsOutput "$Ctor2$ = function (a, b) {"
92+
expectTextContains jsOutput "$Ctor3$ = function (a, b, c) {"
93+
expectTextContains jsOutput "$N2$ = function (a, b) {"
94+
expectTextContains jsOutput "x1 = $author$project$Main$fn1(0)"
95+
expectTextContains jsOutput "x2 = $author$project$Main$fn2$(0, 0)"
96+
expectTextContains jsOutput "x3 = $author$project$Main$fn3$(0, 0, 0)"
97+
expectTextContains jsOutput "c1 = $author$project$Main$Ctor1("
98+
expectTextContains jsOutput "c2 = $author$project$Main$Ctor2$("
99+
expectTextContains jsOutput "c3 = $author$project$Main$Ctor3$("
100+
expectTextContains jsOutput "n1 = 0"
101+
expectTextContains jsOutput "n2 = $author$project$Main$N2$(0, 0)"
102+
54103
Nothing ->
55104
crash "JS output could not be read."
56105
]

test/direct-fn-calls/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
elm-stuff
2+
*.js

test/direct-fn-calls/elm.json

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
{
2+
"type": "application",
3+
"source-directories": [
4+
"src"
5+
],
6+
"elm-version": "0.19.1",
7+
"dependencies": {
8+
"direct": {
9+
"elm/browser": "1.0.2",
10+
"elm/core": "1.0.5",
11+
"elm/html": "1.0.0",
12+
"elm/http": "2.0.0",
13+
"elm/json": "1.1.3",
14+
"elm/url": "1.0.0",
15+
"lamdera/codecs": "1.0.0",
16+
"lamdera/core": "1.0.0"
17+
},
18+
"indirect": {
19+
"elm/bytes": "1.0.8",
20+
"elm/file": "1.0.5",
21+
"elm/time": "1.0.0",
22+
"elm/virtual-dom": "1.0.3"
23+
}
24+
},
25+
"test-dependencies": {
26+
"direct": {},
27+
"indirect": {}
28+
}
29+
}

test/direct-fn-calls/src/Main.elm

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
module Main exposing (main)
2+
3+
import Html
4+
5+
6+
fn1 x =
7+
"fn1"
8+
9+
10+
fn2 x y =
11+
"fn2"
12+
13+
14+
fn3 x y z =
15+
"fn3"
16+
17+
18+
type Type
19+
= Ctor1 ()
20+
| Ctor2 () ()
21+
| Ctor3 () () ()
22+
23+
24+
type Newtype a
25+
= N a
26+
27+
28+
type Newtype2 a b
29+
= N2 a b
30+
31+
32+
main =
33+
let
34+
x1 =
35+
fn1 0
36+
37+
x2 =
38+
fn2 0 0
39+
40+
x3 =
41+
fn3 0 0 0
42+
43+
c1 =
44+
Ctor1 ()
45+
46+
c2 =
47+
Ctor2 () ()
48+
49+
c3 =
50+
Ctor3 () () ()
51+
52+
n1 =
53+
N ()
54+
55+
n2 =
56+
N2 () ()
57+
in
58+
Html.text "compiles!"

0 commit comments

Comments
 (0)