forked from rescript-lang/rescript
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexception_raise_test.js
223 lines (195 loc) · 5.14 KB
/
exception_raise_test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
'use strict';
var Mt = require("./mt.js");
var Block = require("../../lib/js/block.js");
var Curry = require("../../lib/js/curry.js");
var Js_exn = require("../../lib/js/js_exn.js");
var Caml_exceptions = require("../../lib/js/caml_exceptions.js");
var Caml_js_exceptions = require("../../lib/js/caml_js_exceptions.js");
var Caml_builtin_exceptions = require("../../lib/js/caml_builtin_exceptions.js");
var Local = Caml_exceptions.create("Exception_raise_test.Local");
var B = Caml_exceptions.create("Exception_raise_test.B");
var C = Caml_exceptions.create("Exception_raise_test.C");
var D = Caml_exceptions.create("Exception_raise_test.D");
function appf(g, x) {
var A = Caml_exceptions.create("A");
try {
return Curry._1(g, x);
}
catch (raw_exn){
var exn = Caml_js_exceptions.internalToOCamlException(raw_exn);
var exit = 0;
if (exn === Local) {
return 3;
} else if (exn === Caml_builtin_exceptions.not_found) {
return 2;
} else if (exn[0] === A) {
return 3;
} else if (exn[0] === B) {
var match = exn[1];
if (match) {
var match$1 = match[1];
if (match$1) {
var match$2 = match$1[1];
if (match$2) {
return match$2[0];
} else {
exit = 1;
}
} else {
exit = 1;
}
} else {
exit = 1;
}
} else {
exit = 1;
}
if (exit === 1) {
if (exn[0] === C) {
return exn[1];
} else if (exn[0] === D) {
return exn[1][0];
} else {
return 4;
}
}
}
}
var A = Caml_exceptions.create("Exception_raise_test.A");
var f;
try {
f = ( function () {throw (new Error ("x"))} ());
}
catch (raw_exn){
var exn = Caml_js_exceptions.internalToOCamlException(raw_exn);
f = exn[0] === A ? exn[1] : 2;
}
var ff;
try {
ff = ( function () {throw 3} ());
}
catch (raw_exn$1){
var exn$1 = Caml_js_exceptions.internalToOCamlException(raw_exn$1);
ff = exn$1[0] === A ? exn$1[1] : 2;
}
var fff;
try {
fff = ( function () {throw 2} ());
}
catch (raw_exn$2){
var exn$2 = Caml_js_exceptions.internalToOCamlException(raw_exn$2);
fff = exn$2[0] === A ? exn$2[1] : 2;
}
var a0;
try {
a0 = ( function (){throw 2} () );
}
catch (raw_exn$3){
var exn$3 = Caml_js_exceptions.internalToOCamlException(raw_exn$3);
if (exn$3[0] === A || exn$3[0] === Js_exn.$$Error) {
a0 = exn$3[1];
} else {
throw [
Caml_builtin_exceptions.assert_failure,
/* tuple */[
"exception_raise_test.ml",
102,
9
]
];
}
}
var a1;
try {
a1 = ( function (){throw 2} () );
}
catch (raw_e){
a1 = Caml_js_exceptions.internalToOCamlException(raw_e);
}
var a2;
try {
a2 = ( function (){throw (new Error("x"))} () );
}
catch (raw_e$1){
a2 = Caml_js_exceptions.internalToOCamlException(raw_e$1);
}
var suites = /* record */[/* contents : :: */[
/* tuple */[
"File \"test/exception_raise_test.ml\", line 114, characters 4-11",
(function (param) {
return /* Eq */Block.__(0, [
/* tuple */[
f,
ff,
fff,
a0
],
/* tuple */[
2,
2,
2,
2
]
]);
})
],
/* :: */[
/* tuple */[
"File \"test/exception_raise_test.ml\", line 116, characters 4-11",
(function (param) {
if (a1[0] === Js_exn.$$Error) {
return /* Eq */Block.__(0, [
a1[1],
2
]);
} else {
throw [
Caml_builtin_exceptions.assert_failure,
/* tuple */[
"exception_raise_test.ml",
119,
15
]
];
}
})
],
/* [] */0
]
]];
var test_id = /* record */[/* contents */0];
function eq(loc, x, y) {
return Mt.eq_suites(test_id, suites, loc, x, y);
}
try {
(function (_){throw 2}(/* () */0));
}
catch (raw_e$2){
var e = Caml_js_exceptions.internalToOCamlException(raw_e$2);
eq("File \"test/exception_raise_test.ml\", line 131, characters 7-14", Caml_js_exceptions.caml_as_js_exn(e) !== undefined, true);
}
try {
throw Caml_builtin_exceptions.not_found;
}
catch (raw_e$3){
var e$1 = Caml_js_exceptions.internalToOCamlException(raw_e$3);
eq("File \"test/exception_raise_test.ml\", line 138, characters 7-14", Caml_js_exceptions.caml_as_js_exn(e$1) !== undefined, false);
}
eq("File \"test/exception_raise_test.ml\", line 141, characters 5-12", function (a,b,c,_){return a + b + c }(1, 2, 3, 4), 6);
Mt.from_pair_suites("Exception_raise_test", suites[0]);
exports.Local = Local;
exports.B = B;
exports.C = C;
exports.D = D;
exports.appf = appf;
exports.A = A;
exports.f = f;
exports.ff = ff;
exports.fff = fff;
exports.a0 = a0;
exports.a1 = a1;
exports.a2 = a2;
exports.suites = suites;
exports.test_id = test_id;
exports.eq = eq;
/* f Not a pure module */