forked from codesandbox/codesandbox-client
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path27.usemap.js
More file actions
executable file
·66 lines (60 loc) · 2.18 KB
/
27.usemap.js
File metadata and controls
executable file
·66 lines (60 loc) · 2.18 KB
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
#!/usr/bin/env mocha -R spec
var assert = require("assert");
var msgpackJS = "../index";
var isBrowser = ("undefined" !== typeof window);
var HAS_MAP = ("undefined" !== typeof Map);
var msgpack = isBrowser && window.msgpack || require(msgpackJS);
var TITLE = __filename.replace(/^.*\//, "");
function pattern(min, max, offset) {
var array = [];
var check = {};
var val = min - 1;
while (val <= max) {
if (min <= val && !check[val]) array.push(val);
check[val++] = 1;
if (val <= max && !check[val]) array.push(val);
check[val++] = 1;
if (val <= max && !check[val]) array.push(val);
check[val--] = 1;
val = val ? val * 2 - 1 : 1;
}
return array;
}
// Run these tests when Map is available
var describeSkip = HAS_MAP ? describe : describe.skip;
describeSkip(TITLE, function() {
it("Map (small)", function() {
pattern(0, 257).forEach(function(length) {
var value = new Map();
assert.equal(true, value instanceof Map);
for (var i = 0; i < length; i++) {
var key = String.fromCharCode(i);
value.set(key, length);
}
assert.equal(value.size, length);
var options = {codec: msgpack.createCodec({usemap: true})};
var encoded = msgpack.encode(value, options);
var decoded = msgpack.decode(encoded, options);
assert.equal(true, decoded instanceof Map);
assert.equal(decoded.size, length);
assert.equal(decoded.get(String.fromCharCode(0)), value.get(String.fromCharCode(0)));
assert.equal(decoded.get(String.fromCharCode(length - 1)), value.get(String.fromCharCode(length - 1)));
});
});
it("Map (large)", function() {
this.timeout(30000);
pattern(65536, 65537).forEach(function(length) {
var value = new Map();
for (var i = 0; i < length; i++) {
value.set(i, length);
}
assert.equal(value.size, length);
var options = {codec: msgpack.createCodec({usemap: true})};
var encoded = msgpack.encode(value, options);
var decoded = msgpack.decode(encoded, options);
assert.equal(decoded.size, length);
assert.equal(decoded.get(0), value.get(0));
assert.equal(decoded.get(length - 1), value.get(length - 1));
});
});
});