-
Notifications
You must be signed in to change notification settings - Fork 2.3k
/
get.js
83 lines (74 loc) · 2.38 KB
/
get.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
"use strict";
var assert = require("assert");
var testUtils = require("./helpers/util.js");
var join = Promise.join;
describe("indexed getter", function() {
var p = Promise.resolve([0, 1, 2, 3, 4, 5, 7, 5,10]);
specify("gets positive index", function() {
var first = p.get(0);
var fourth = p.get(3);
var last = p.get(8);
return join(first, fourth, last, function(a, b, c) {
assert(a === 0);
assert(b === 3);
assert(c === 10);
});
});
specify("gets negative index", function() {
var last = p.get(-1);
var first = p.get(-20);
return join(last, first, function(a, b) {
assert.equal(a, 10);
assert.equal(b, 0);
});
});
});
describe("identifier getter", function() {
var p = Promise.resolve(new RegExp("", ""));
specify("gets property", function() {
var ci = p.get("ignoreCase");
var g = p.get("global");
var lastIndex = p.get("lastIndex");
var multiline = p.get("multiline");
return join(ci, g, lastIndex, multiline, function(ci, g, lastIndex, multiline) {
assert(ci === false);
assert(g === false);
assert(lastIndex === 0);
assert(multiline === false);
});
});
specify("gets same property", function() {
var o = {o: 1};
var o2 = {o: 2};
o = Promise.resolve(o).get("o");
o2 = Promise.resolve(o2).get("o");
return join(o, o2, function(one, two) {
assert.strictEqual(1, one);
assert.strictEqual(2, two);
});
});
});
describe("non identifier getters", function() {
var p = Promise.resolve({"-": "val"});
specify("get property", function() {
return p.get("-").then(function(val) {
assert(val === "val");
});
});
specify.skip("overflow cache", function() {
var a = new Array(1024);
var o = {};
for (var i = 0; i < a.length; ++i) {
a[i] = "get" + i;
o["get" + i] = i*2;
}
var b = Promise.map(a, function(item, index) {
return Promise.resolve(o).get(a[index]);
}).filter(function(value, index) {
return value === index * 2;
}).then(function(values) {
assert.strictEqual(values.length, a.length);
});
return b;
});
});