forked from rescript-lang/rescript
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathext_bytes_test.js
221 lines (193 loc) · 5.54 KB
/
ext_bytes_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
'use strict';
var Mt = require("./mt.js");
var Char = require("../../lib/js/char.js");
var Bytes = require("../../lib/js/bytes.js");
var Curry = require("../../lib/js/curry.js");
var Caml_bytes = require("../../lib/js/caml_bytes.js");
var Caml_int64 = require("../../lib/js/caml_int64.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 test_id = {
contents: 0
};
function eq(loc, x, y) {
return Mt.eq_suites(test_id, suites, loc, x, y);
}
function escaped(s) {
var n = 0;
for(var i = 0 ,i_finish = s.length; i < i_finish; ++i){
var match = s[i];
var tmp;
if (match >= 32) {
var switcher = match - 34 | 0;
tmp = switcher > 58 || switcher < 0 ? (
switcher >= 93 ? 4 : 1
) : (
switcher > 57 || switcher < 1 ? 2 : 1
);
} else {
tmp = match >= 11 ? (
match !== 13 ? 4 : 2
) : (
match >= 8 ? 2 : 4
);
}
n = n + tmp | 0;
}
if (n === s.length) {
return Bytes.copy(s);
}
var s$prime = Caml_bytes.caml_create_bytes(n);
n = 0;
for(var i$1 = 0 ,i_finish$1 = s.length; i$1 < i_finish$1; ++i$1){
var c = s[i$1];
var exit = 0;
if (c >= 35) {
if (c !== 92) {
if (c >= 127) {
exit = 1;
} else {
s$prime[n] = c;
}
} else {
exit = 2;
}
} else if (c >= 32) {
if (c >= 34) {
exit = 2;
} else {
s$prime[n] = c;
}
} else if (c >= 14) {
exit = 1;
} else {
switch (c) {
case 8 :
s$prime[n] = /* "\\" */92;
n = n + 1 | 0;
s$prime[n] = /* "b" */98;
break;
case 9 :
s$prime[n] = /* "\\" */92;
n = n + 1 | 0;
s$prime[n] = /* "t" */116;
break;
case 10 :
s$prime[n] = /* "\\" */92;
n = n + 1 | 0;
s$prime[n] = /* "n" */110;
break;
case 0 :
case 1 :
case 2 :
case 3 :
case 4 :
case 5 :
case 6 :
case 7 :
case 11 :
case 12 :
exit = 1;
break;
case 13 :
s$prime[n] = /* "\\" */92;
n = n + 1 | 0;
s$prime[n] = /* "r" */114;
break;
}
}
switch (exit) {
case 1 :
s$prime[n] = /* "\\" */92;
n = n + 1 | 0;
s$prime[n] = 48 + (c / 100 | 0) | 0;
n = n + 1 | 0;
s$prime[n] = 48 + (c / 10 | 0) % 10 | 0;
n = n + 1 | 0;
s$prime[n] = 48 + c % 10 | 0;
break;
case 2 :
s$prime[n] = /* "\\" */92;
n = n + 1 | 0;
s$prime[n] = c;
break;
}
n = n + 1 | 0;
}
return s$prime;
}
function starts_with(xs, prefix, p) {
var H = Caml_exceptions.create("H");
var len1 = xs.length;
var len2 = prefix.length;
if (len2 > len1) {
return false;
}
try {
for(var i = 0; i < len2; ++i){
if (!Curry._2(p, Caml_bytes.get(xs, i), Caml_bytes.get(prefix, i))) {
throw {
RE_EXN_ID: H,
Error: new Error()
};
}
}
return true;
}
catch (raw_exn){
var exn = Caml_js_exceptions.internalToOCamlException(raw_exn);
if (exn.RE_EXN_ID === H) {
return false;
}
throw exn;
}
}
var a = Bytes.init(100, Char.chr);
Bytes.blit(a, 5, a, 10, 10);
eq("File \"ext_bytes_test.ml\", line 96, characters 7-14", a, Bytes.of_string("\0\x01\x02\x03\x04\x05\x06\x07\b\t\x05\x06\x07\b\t\n\x0b\f\r\x0e\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abc"));
var a$1 = Bytes.init(100, Char.chr);
Bytes.blit(a$1, 10, a$1, 5, 10);
eq("File \"ext_bytes_test.ml\", line 102, characters 7-14", a$1, Bytes.of_string("\0\x01\x02\x03\x04\n\x0b\f\r\x0e\x0f\x10\x11\x12\x13\x0f\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abc"));
var f = Char.chr;
var a$2 = Caml_bytes.bytes_to_string(Bytes.init(100, f));
var b = Bytes.init(100, (function (i) {
return /* "\000" */0;
}));
Bytes.blit_string(a$2, 10, b, 5, 10);
eq("File \"ext_bytes_test.ml\", line 109, characters 7-14", b, Bytes.of_string("\0\0\0\0\0\n\x0b\f\r\x0e\x0f\x10\x11\x12\x13\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"));
var s = Bytes.init(50000, (function (i) {
return Char.chr(i % 137);
}));
var s1 = Bytes.to_string(s);
var s2 = Bytes.of_string(s1);
eq("File \"ext_bytes_test.ml\", line 115, characters 7-14", s, s2);
function f$1(a, b) {
return [
Caml_bytes.caml_bytes_greaterthan(a, b),
Caml_bytes.caml_bytes_greaterequal(a, b),
Caml_bytes.caml_bytes_lessthan(a, b),
Caml_bytes.caml_bytes_lessequal(a, b),
Caml_bytes.caml_bytes_equal(a, b)
];
}
function f_0(a, b) {
return [
Caml_int64.gt(a, b),
Caml_int64.ge(a, b),
Caml_int64.lt(a, b),
Caml_int64.le(a, b),
Caml_int64.eq(a, b)
];
}
Mt.from_pair_suites("Ext_bytes_test", suites.contents);
exports.suites = suites;
exports.test_id = test_id;
exports.eq = eq;
exports.escaped = escaped;
exports.starts_with = starts_with;
exports.f = f$1;
exports.f_0 = f_0;
/* a Not a pure module */