on master help sign in
Merge pull request #1134 from elm-lang/pr/1126

Expected output tests for Debug.crash.

commit020604921911d5a8bcb599f82569258e64c38dfe authorEvan Czaplicki <info@elm-lang.org> dateTue 27 Oct 2015, 21:08 (11 years ago) parentb74854983317c8
9 files changed+128−4
tests/Test/Compiler.hs+35−4 tests/test-files/good-expected-js/CodeGenBugs/CommentInterpretedAsInfix.elm.js+14 tests/test-files/good-expected-js/CodeGenBugs/NestedPatternMatch.elm.js+10 tests/test-files/good-expected-js/Crash/CrashCase.elm.js+20 tests/test-files/good-expected-js/Crash/CrashIf.elm.js+15 tests/test-files/good/CodeGenBugs/CommentInterpretedAsInfix.elm+12 tests/test-files/good/CodeGenBugs/NestedPatternMatch.elm+5 tests/test-files/good/Crash/CrashCase.elm+9 tests/test-files/good/Crash/CrashIf.elm+8
tests/Test/Compiler.hs+35−4
@@ -18,7 +18,10 @@ import Test.HUnit (Assertion, assertFailure, assertBool, assertEqual)
1818
1919import qualified Elm.Compiler as Compiler
2020import qualified Elm.Package as Package
21−
21+import qualified AST.Module as Module
22+import qualified AST.Module.Name as ModuleName
23+import qualified AST.Variable as Variable
24+import qualified AST.Type as Type
2225
2326
2427writeExpectedJsEnvVarName :: String
@@ -68,12 +71,40 @@ convertToExpectedJsFilePath expectedJsDir filePath =
6871-- TEST HELPERS
6972
7073
74+essentialInterfaces :: Module.Interfaces
75+essentialInterfaces =
76+ Map.fromList
77+ [
78+ (ModuleName.inCore ["Debug"],
79+ buildCoreInterface
80+ [
81+ ("crash", Type.Lambda (Type.Var "String") (Type.Var "a"))
82+ ]
83+ )
84+ ]
85+
86+
87+buildCoreInterface :: [(String, Type.Canonical)] -> Module.Interface
88+buildCoreInterface members =
89+ let exports = map (Variable.Value . fst) members
90+ imports = []
91+ types = Map.fromList members
92+ adts = Map.empty
93+ aliases = Map.empty
94+ fixities = []
95+ ports = []
96+ in
97+ Module.Interface Compiler.version Package.coreName exports types imports adts aliases fixities ports
98+
99+
71100compileString :: FilePath -> String -> Either String Compiler.Result
72101compileString filePath source =
73− let context =
74− Compiler.Context Package.coreName True False []
102+ let dependentModuleNames =
103+ Map.keys essentialInterfaces
104+ context =
105+ Compiler.Context Package.coreName True False dependentModuleNames
75106 (dealiaser, _warnings, result) =
76− Compiler.compile context source Map.empty
107+ Compiler.compile context source essentialInterfaces
77108 formatErrors errors =
78109 concatMap (Compiler.errorToString dealiaser filePath source) errors
79110 in
tests/test-files/good-expected-js/CodeGenBugs/CommentInterpretedAsInfix.elm.jsnew file+14
@@ -0,0 +1,14 @@
1+Elm.Main = Elm.Main || {};
2+Elm.Main.make = function (_elm) {
3+ "use strict";
4+ _elm.Main = _elm.Main || {};
5+ if (_elm.Main.values) return _elm.Main.values;
6+ var _U = Elm.Native.Utils.make(_elm);
7+ var _op = {};
8+ var always = F2(function (x,s) { return x;});
9+ _op["|>"] = F2(function (a,f) { return f(a);});
10+ var value = A2(_op["|>"],"Hi",always("Hello"));
11+ return _elm.Main.values = {_op: _op
12+ ,always: always
13+ ,value: value};
14+};
tests/test-files/good-expected-js/CodeGenBugs/NestedPatternMatch.elm.jsnew file+10
@@ -0,0 +1,10 @@
1+Elm.Main = Elm.Main || {};
2+Elm.Main.make = function (_elm) {
3+ "use strict";
4+ _elm.Main = _elm.Main || {};
5+ if (_elm.Main.values) return _elm.Main.values;
6+ var _U = Elm.Native.Utils.make(_elm);
7+ var _op = {};
8+ var foo = function (_p0) { var _p1 = _p0;return _p1;};
9+ return _elm.Main.values = {_op: _op,foo: foo};
10+};
tests/test-files/good-expected-js/Crash/CrashCase.elm.jsnew file+20
@@ -0,0 +1,20 @@
1+Elm.Main = Elm.Main || {};
2+Elm.Main.make = function (_elm) {
3+ "use strict";
4+ _elm.Main = _elm.Main || {};
5+ if (_elm.Main.values) return _elm.Main.values;
6+ var _U = Elm.Native.Utils.make(_elm),
7+ $Debug = Elm.Debug.make(_elm);
8+ var _op = {};
9+ var test = function (x) {
10+ var _p0 = x;
11+ if (_p0 === 1) {
12+ return 2;
13+ } else {
14+ return _U.crashCase("Main",
15+ {start: {line: 5,column: 5},end: {line: 9,column: 43}},
16+ _p0)("unexpected value");
17+ }
18+ };
19+ return _elm.Main.values = {_op: _op,test: test};
20+};
tests/test-files/good-expected-js/Crash/CrashIf.elm.jsnew file+15
@@ -0,0 +1,15 @@
1+Elm.Main = Elm.Main || {};
2+Elm.Main.make = function (_elm) {
3+ "use strict";
4+ _elm.Main = _elm.Main || {};
5+ if (_elm.Main.values) return _elm.Main.values;
6+ var _U = Elm.Native.Utils.make(_elm),
7+ $Debug = Elm.Debug.make(_elm);
8+ var _op = {};
9+ var test = function (x) {
10+ return x ? 2 : _U.crash("Main",
11+ {start: {line: 8,column: 9}
12+ ,end: {line: 8,column: 20}})("unexpected value");
13+ };
14+ return _elm.Main.values = {_op: _op,test: test};
15+};
tests/test-files/good/CodeGenBugs/CommentInterpretedAsInfix.elmnew file+12
@@ -0,0 +1,12 @@
1+
2+-- Issue: https://github.com/elm-lang/elm-compiler/issues/894
3+-- Two dashes immediately follow by other symbols are incorrectly
4+-- interpreted as an infix operator, instead of a comment.
5+
6+(|>) a f = f a
7+
8+always x s = x
9+
10+value = "Hi"
11+ |> always "Hello"
12+ --|> always "Bye"
tests/test-files/good/CodeGenBugs/NestedPatternMatch.elmnew file+5
@@ -0,0 +1,5 @@
1+
2+-- Issue: https://github.com/elm-lang/elm-compiler/issues/1115
3+-- Nested patterns are not correctly handled and fail with unreachable assertion error.
4+
5+foo (({f1} as r1) as r2) = r1
tests/test-files/good/Crash/CrashCase.elmnew file+9
@@ -0,0 +1,9 @@
1+
2+import Debug
3+
4+test x =
5+ case x of
6+ 1 ->
7+ 2
8+ _ ->
9+ Debug.crash "unexpected value"
tests/test-files/good/Crash/CrashIf.elmnew file+8
@@ -0,0 +1,8 @@
1+
2+import Debug
3+
4+test x =
5+ if x then
6+ 2
7+ else
8+ Debug.crash "unexpected value"