-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathtests.js
More file actions
63 lines (55 loc) · 2.16 KB
/
tests.js
File metadata and controls
63 lines (55 loc) · 2.16 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
'use strict';
module.exports = function (fromCodePoint, t) {
t.equal(fromCodePoint(), '', 'no arguments');
t.test('cast to 0', function (st) {
st.equal(fromCodePoint(''), '\0');
st.equal(fromCodePoint(-0), '\0');
st.equal(fromCodePoint(0), '\0');
st.equal(fromCodePoint(false), '\0');
st.equal(fromCodePoint(null), '\0');
st.end();
});
t.test('astral code points', function (st) {
st.equal(fromCodePoint(0x1D306), '\uD834\uDF06');
st.equal(fromCodePoint(0x1D306, 0x61, 0x1D307), '\uD834\uDF06a\uD834\uDF07');
st.equal(fromCodePoint(0x61, 0x62, 0x1D307), 'ab\uD834\uDF07');
st.end();
});
t.test('invalid code points', function (st) {
st['throws'](function () { fromCodePoint('_'); }, RangeError);
st['throws'](function () { fromCodePoint('+Infinity'); }, RangeError);
st['throws'](function () { fromCodePoint('-Infinity'); }, RangeError);
st['throws'](function () { fromCodePoint(-1); }, RangeError);
st['throws'](function () { fromCodePoint(0x10FFFF + 1); }, RangeError);
st['throws'](function () { fromCodePoint(3.14); }, RangeError);
st['throws'](function () { fromCodePoint(3e-2); }, RangeError);
st['throws'](function () { fromCodePoint(-Infinity); }, RangeError);
st['throws'](function () { fromCodePoint(Number(Infinity)); }, RangeError);
st['throws'](function () { fromCodePoint(NaN); }, RangeError);
st['throws'](function () { fromCodePoint(undefined); }, RangeError);
st['throws'](function () { fromCodePoint({}); }, RangeError);
st['throws'](function () { fromCodePoint(/./); }, RangeError);
st.end();
});
t.test('cast code point', function (st) {
var tmp = 0x60;
st.equal(fromCodePoint({ valueOf: function () { ++tmp; return tmp; } }), 'a');
st.equal(tmp, 0x61);
st.end();
});
t.test('long arguments list', function (st) {
var counter = Math.pow(2, 15) * 3 / 2;
var result = [];
while (--counter >= 0) {
result.push(0); // one code unit per symbol
}
fromCodePoint.apply(null, result); // must not throw
counter = Math.pow(2, 15) * 3 / 2;
result = [];
while (--counter >= 0) {
result.push(0xFFFF + 1); // two code units per symbol
}
fromCodePoint.apply(null, result); // must not throw
st.end();
});
};