-
Notifications
You must be signed in to change notification settings - Fork 465
/
Copy pathjs_exception_catch_test.js
223 lines (193 loc) · 5.83 KB
/
js_exception_catch_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 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 suites = {
contents: /* [] */0
};
var counter = {
contents: 0
};
function add_test(loc, test) {
counter.contents = counter.contents + 1 | 0;
var id = loc + (" id " + String(counter.contents));
suites.contents = /* :: */{
_0: /* tuple */[
id,
test
],
_1: suites.contents
};
}
function eq(loc, x, y) {
return add_test(loc, (function (param) {
return {
tag: /* Eq */0,
_0: x,
_1: y
};
}));
}
function false_(loc) {
return add_test(loc, (function (param) {
return {
tag: /* Ok */4,
_0: false
};
}));
}
function true_(loc) {
return add_test(loc, (function (param) {
return {
tag: /* Ok */4,
_0: true
};
}));
}
var exit = 0;
var e;
try {
e = JSON.parse(" {\"x\"}");
exit = 1;
}
catch (raw_x){
var x = Caml_js_exceptions.internalToOCamlException(raw_x);
if (x.RE_EXN_ID === Js_exn.$$Error) {
add_test("File \"js_exception_catch_test.ml\", line 21, characters 10-17", (function (param) {
return {
tag: /* Ok */4,
_0: true
};
}));
} else {
throw x;
}
}
if (exit === 1) {
add_test("File \"js_exception_catch_test.ml\", line 22, characters 16-23", (function (param) {
return {
tag: /* Ok */4,
_0: false
};
}));
}
var A = Caml_exceptions.create("Js_exception_catch_test.A");
var B = Caml_exceptions.create("Js_exception_catch_test.B");
var C = Caml_exceptions.create("Js_exception_catch_test.C");
function test(f) {
try {
Curry._1(f, undefined);
return /* No_error */-465676758;
}
catch (raw_e){
var e = Caml_js_exceptions.internalToOCamlException(raw_e);
if (e.RE_EXN_ID === "Not_found") {
return /* Not_found */-358247754;
} else if (e.RE_EXN_ID === "Invalid_argument") {
if (e._1 === "x") {
return /* Invalid_argument */-50278363;
} else {
return /* Invalid_any */545126980;
}
} else if (e.RE_EXN_ID === A) {
if (e._1 !== 2) {
return /* A_any */740357294;
} else {
return /* A2 */14545;
}
} else if (e.RE_EXN_ID === B) {
return /* B */66;
} else if (e.RE_EXN_ID === C) {
if (e._1 !== 1 || e._2 !== 2) {
return /* C_any */-756146768;
} else {
return /* C */67;
}
} else if (e.RE_EXN_ID === Js_exn.$$Error) {
return /* Js_error */634022066;
} else {
return /* Any */3257036;
}
}
}
eq("File \"js_exception_catch_test.ml\", line 43, characters 5-12", test(function (param) {
}), /* No_error */-465676758);
eq("File \"js_exception_catch_test.ml\", line 44, characters 5-12", test(function (param) {
throw {
RE_EXN_ID: "Not_found",
Error: new Error()
};
}), /* Not_found */-358247754);
eq("File \"js_exception_catch_test.ml\", line 45, characters 5-12", test(function (param) {
throw {
RE_EXN_ID: "Invalid_argument",
_1: "x",
Error: new Error()
};
}), /* Invalid_argument */-50278363);
eq("File \"js_exception_catch_test.ml\", line 46, characters 5-12", test(function (param) {
throw {
RE_EXN_ID: "Invalid_argument",
_1: "",
Error: new Error()
};
}), /* Invalid_any */545126980);
eq("File \"js_exception_catch_test.ml\", line 47, characters 5-12", test(function (param) {
throw {
RE_EXN_ID: A,
_1: 2,
Error: new Error()
};
}), /* A2 */14545);
eq("File \"js_exception_catch_test.ml\", line 48, characters 5-12", test(function (param) {
throw {
RE_EXN_ID: A,
_1: 3,
Error: new Error()
};
}), /* A_any */740357294);
eq("File \"js_exception_catch_test.ml\", line 49, characters 5-12", test(function (param) {
throw {
RE_EXN_ID: B,
Error: new Error()
};
}), /* B */66);
eq("File \"js_exception_catch_test.ml\", line 50, characters 5-12", test(function (param) {
throw {
RE_EXN_ID: C,
_1: 1,
_2: 2,
Error: new Error()
};
}), /* C */67);
eq("File \"js_exception_catch_test.ml\", line 51, characters 5-12", test(function (param) {
throw {
RE_EXN_ID: C,
_1: 0,
_2: 2,
Error: new Error()
};
}), /* C_any */-756146768);
eq("File \"js_exception_catch_test.ml\", line 52, characters 5-12", test(function (param) {
throw new Error("x");
}), /* Js_error */634022066);
eq("File \"js_exception_catch_test.ml\", line 53, characters 5-12", test(function (param) {
throw {
RE_EXN_ID: "Failure",
_1: "x",
Error: new Error()
};
}), /* Any */3257036);
Mt.from_pair_suites("Js_exception_catch_test", suites.contents);
exports.suites = suites;
exports.add_test = add_test;
exports.eq = eq;
exports.false_ = false_;
exports.true_ = true_;
exports.A = A;
exports.B = B;
exports.C = C;
exports.test = test;
/* Not a pure module */