on master help sign in
Merge pull request #1044 from laszlopandy/expected-js-for-pattern-matching

Good and bad compiler tests for pattern matching.

commit723bccdf1d992e7c30c7afc4df58a9d7c85866ea authorEvan Czaplicki <info@elm-lang.org> dateFri 4 Sep 2015, 22:14 (11 years ago) parent616aff9ac4e451
3 files changed+81
tests/test-files/bad/IncompletePatternMatch.elm+17 tests/test-files/good-expected-js/CaseExpression3.elm.js+47 tests/test-files/good/CaseExpression3.elm+17
tests/test-files/bad/IncompletePatternMatch.elmnew file+17
@@ -0,0 +1,17 @@
1+
2+type List a
3+ = Nil
4+ | Cons a (List a)
5+
6+
7+zip : List a -> List b -> List (a, b)
8+zip list1 list2 =
9+ case (list1, list2) of
10+ (Nil, _) ->
11+ Nil
12+
13+ (Cons x xs, Cons y ys) ->
14+ Cons (x, y) (zip xs ys)
15+
16+ -- incomplete pattern match is an error
17+ -- missing: (_, Nil) -> Nil
tests/test-files/good-expected-js/CaseExpression3.elm.jsnew file+47
@@ -0,0 +1,47 @@
1+Elm.Main = Elm.Main || {};
2+Elm.Main.make = function (_elm) {
3+ "use strict";
4+ _elm.Main = _elm.Main || {};
5+ if (_elm.Main.values)
6+ return _elm.Main.values;
7+ var _op = {},
8+ _N = Elm.Native,
9+ _U = _N.Utils.make(_elm),
10+ _L = _N.List.make(_elm),
11+ $moduleName = "Main";
12+ var Cons = F2(function (a,b) {
13+ return {ctor: "Cons"
14+ ,_0: a
15+ ,_1: b};
16+ });
17+ var Nil = {ctor: "Nil"};
18+ var zip = F2(function (list1,
19+ list2) {
20+ var _v0 = {ctor: "_Tuple2"
21+ ,_0: list1
22+ ,_1: list2};
23+ switch (_v0.ctor)
24+ {case "_Tuple2":
25+ switch (_v0._0.ctor)
26+ {case "Nil": return Nil;}
27+ switch (_v0._1.ctor)
28+ {case "Nil": return Nil;}
29+ switch (_v0._0.ctor)
30+ {case "Cons":
31+ switch (_v0._1.ctor)
32+ {case "Cons": return A2(Cons,
33+ {ctor: "_Tuple2"
34+ ,_0: _v0._0._0
35+ ,_1: _v0._1._0},
36+ A2(zip,_v0._0._1,_v0._1._1));}
37+ break;}
38+ break;}
39+ _U.badCase($moduleName,
40+ "bugs in reporting the exact location right now");
41+ });
42+ _elm.Main.values = {_op: _op
43+ ,Nil: Nil
44+ ,Cons: Cons
45+ ,zip: zip};
46+ return _elm.Main.values;
47+};
tests/test-files/good/CaseExpression3.elmnew file+17
@@ -0,0 +1,17 @@
1+
2+type List a
3+ = Nil
4+ | Cons a (List a)
5+
6+
7+zip : List a -> List b -> List (a, b)
8+zip list1 list2 =
9+ case (list1, list2) of
10+ (Nil, _) ->
11+ Nil
12+
13+ (_, Nil) ->
14+ Nil
15+
16+ (Cons x xs, Cons y ys) ->
17+ Cons (x, y) (zip xs ys)