-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathtests.js
More file actions
104 lines (91 loc) · 4.08 KB
/
tests.js
File metadata and controls
104 lines (91 loc) · 4.08 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
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
'use strict';
var supportsStrictMode = require('has-strict-mode')();
module.exports = function (codePointAt, t) {
t.test('String that starts with a BMP symbol', function (st) {
st.equal(codePointAt('abc\uD834\uDF06def', -1), undefined);
st.equal(codePointAt('abc\uD834\uDF06def', -0), 0x61);
st.equal(codePointAt('abc\uD834\uDF06def', 0), 0x61);
st.equal(codePointAt('abc\uD834\uDF06def', 3), 0x1D306);
st.equal(codePointAt('abc\uD834\uDF06def', 4), 0xDF06);
st.equal(codePointAt('abc\uD834\uDF06def', 5), 0x64);
st.equal(codePointAt('abc\uD834\uDF06def', 42), undefined);
st.end();
});
t.test('String that starts with a BMP symbol - cast position', function (st) {
st.equal(codePointAt('abc\uD834\uDF06def', ''), 0x61);
st.equal(codePointAt('abc\uD834\uDF06def', '_'), 0x61);
st.equal(codePointAt('abc\uD834\uDF06def'), 0x61);
st.equal(codePointAt('abc\uD834\uDF06def', -Infinity), undefined);
st.equal(codePointAt('abc\uD834\uDF06def', Infinity), undefined);
st.equal(codePointAt('abc\uD834\uDF06def', Infinity), undefined);
st.equal(codePointAt('abc\uD834\uDF06def', NaN), 0x61);
st.equal(codePointAt('abc\uD834\uDF06def', false), 0x61);
st.equal(codePointAt('abc\uD834\uDF06def', null), 0x61);
st.equal(codePointAt('abc\uD834\uDF06def', undefined), 0x61);
st.end();
});
t.test('String that starts with an astral symbol', function (st) {
st.equal(codePointAt('\uD834\uDF06def', -1), undefined);
st.equal(codePointAt('\uD834\uDF06def', -0), 0x1D306);
st.equal(codePointAt('\uD834\uDF06def', 0), 0x1D306);
st.equal(codePointAt('\uD834\uDF06def', 1), 0xDF06);
st.equal(codePointAt('\uD834\uDF06def', 42), undefined);
st.end();
});
t.test('String that starts with an astral symbol - cast position', function (st) {
st.equal(codePointAt('\uD834\uDF06def', ''), 0x1D306);
st.equal(codePointAt('\uD834\uDF06def', '1'), 0xDF06);
st.equal(codePointAt('\uD834\uDF06def', '_'), 0x1D306);
st.equal(codePointAt('\uD834\uDF06def'), 0x1D306);
st.equal(codePointAt('\uD834\uDF06def', false), 0x1D306);
st.equal(codePointAt('\uD834\uDF06def', null), 0x1D306);
st.equal(codePointAt('\uD834\uDF06def', undefined), 0x1D306);
st.end();
});
t.test('Lone high surrogates', function (st) {
st.equal(codePointAt('\uD834abc', -1), undefined);
st.equal(codePointAt('\uD834abc', -0), 0xD834);
st.equal(codePointAt('\uD834abc', 0), 0xD834);
st.end();
});
t.test('Lone high surrogates - cast position', function (st) {
st.equal(codePointAt('\uD834abc', ''), 0xD834);
st.equal(codePointAt('\uD834abc', '_'), 0xD834);
st.equal(codePointAt('\uD834abc'), 0xD834);
st.equal(codePointAt('\uD834abc', false), 0xD834);
st.equal(codePointAt('\uD834abc', NaN), 0xD834);
st.equal(codePointAt('\uD834abc', null), 0xD834);
st.equal(codePointAt('\uD834abc', undefined), 0xD834);
st.end();
});
t.test('Lone low surrogates', function (st) {
st.equal(codePointAt('\uDF06abc', -1), undefined);
st.equal(codePointAt('\uDF06abc', -0), 0xDF06);
st.equal(codePointAt('\uDF06abc', 0), 0xDF06);
st.end();
});
t.test('Lone low surrogates - cast position', function (st) {
st.equal(codePointAt('\uDF06abc', ''), 0xDF06);
st.equal(codePointAt('\uDF06abc', '_'), 0xDF06);
st.equal(codePointAt('\uDF06abc'), 0xDF06);
st.equal(codePointAt('\uDF06abc', false), 0xDF06);
st.equal(codePointAt('\uDF06abc', NaN), 0xDF06);
st.equal(codePointAt('\uDF06abc', null), 0xDF06);
st.equal(codePointAt('\uDF06abc', undefined), 0xDF06);
st.end();
});
t.test('bad string/this value', { skip: !supportsStrictMode }, function (st) {
st['throws'](function () { return codePointAt(undefined, 'a'); }, TypeError, 'undefined is not an object');
st['throws'](function () { return codePointAt(null, 'a'); }, TypeError, 'null is not an object');
st.end();
});
t.test('cast this value', function (st) {
st.equal(codePointAt(42, 0), 0x34);
st.equal(codePointAt(42, 1), 0x32);
st.equal(codePointAt({ toString: function () { return 'abc'; } }, 2), 0x63);
var tmp = 0;
st.equal(codePointAt({ toString: function () { tmp += 1; return String(tmp); } }, 0), 0x31);
st.equal(tmp, 1);
st.end();
});
};