-
Notifications
You must be signed in to change notification settings - Fork 465
/
Copy pathjs_exception_catch_test.js
202 lines (172 loc) · 5.4 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
'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 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 = /* :: */[
/* tuple */[
id,
test
],
suites.contents
];
}
function eq(loc, x, y) {
return add_test(loc, (function (param) {
return /* Eq */Block.__(0, [
x,
y
]);
}));
}
function false_(loc) {
return add_test(loc, (function (param) {
return /* Ok */Block.__(4, [false]);
}));
}
function true_(loc) {
return add_test(loc, (function (param) {
return /* Ok */Block.__(4, [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 /* Ok */Block.__(4, [true]);
}));
} else {
throw x;
}
}
if (exit === 1) {
add_test("File \"js_exception_catch_test.ml\", line 22, characters 16-23", (function (param) {
return /* Ok */Block.__(4, [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"
};
})), /* 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"
};
})), /* 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: ""
};
})), /* 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
};
})), /* A2 */14545);
eq("File \"js_exception_catch_test.ml\", line 48, characters 5-12", test((function (param) {
throw {
RE_EXN_ID: A,
_1: 3
};
})), /* A_any */740357294);
eq("File \"js_exception_catch_test.ml\", line 49, characters 5-12", test((function (param) {
throw {
RE_EXN_ID: B
};
})), /* 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
};
})), /* 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
};
})), /* 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"
};
})), /* 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 */