Skip to content

Commit 345dbd3

Browse files
committed
Simplify tests
1 parent f61dde7 commit 345dbd3

File tree

1 file changed

+56
-247
lines changed

1 file changed

+56
-247
lines changed

tests/tests.js

Lines changed: 56 additions & 247 deletions
Original file line numberDiff line numberDiff line change
@@ -1,254 +1,63 @@
11
var assert = require('assert');
2+
var assertEquals = assert.equal;
23

34
require('../codepointat.js');
45

5-
var tests = [
6-
// String that starts with a BMP symbol
7-
{
8-
'string': 'abc\uD834\uDF06def',
9-
'position': -1,
10-
'result': undefined
11-
},
12-
{
13-
'string': 'abc\uD834\uDF06def',
14-
'position': -0,
15-
'result': 0x61
16-
},
17-
{
18-
'string': 'abc\uD834\uDF06def',
19-
'position': 0,
20-
'result': 0x61
21-
},
22-
{
23-
'string': 'abc\uD834\uDF06def',
24-
'position': null,
25-
'result': 0x61
26-
},
27-
{
28-
'string': 'abc\uD834\uDF06def',
29-
'position': undefined,
30-
'result': 0x61
31-
},
32-
{
33-
'string': 'abc\uD834\uDF06def',
34-
'position': false,
35-
'result': 0x61
36-
},
37-
{
38-
'string': 'abc\uD834\uDF06def',
39-
'position': NaN,
40-
'result': 0x61
41-
},
42-
{
43-
'string': 'abc\uD834\uDF06def',
44-
'position': '',
45-
'result': 0x61
46-
},
47-
{
48-
'string': 'abc\uD834\uDF06def',
49-
'position': '_',
50-
'result': 0x61
51-
},
52-
{
53-
'string': 'abc\uD834\uDF06def',
54-
'position': 3,
55-
'result': 0x1D306
56-
},
57-
{
58-
'string': 'abc\uD834\uDF06def',
59-
'position': 4,
60-
'result': 0xDF06
61-
},
62-
{
63-
'string': 'abc\uD834\uDF06def',
64-
'position': 5,
65-
'result': 0x64
66-
},
67-
{
68-
'string': 'abc\uD834\uDF06def',
69-
'position': 42,
70-
'result': undefined
71-
},
72-
{
73-
'string': 'abc\uD834\uDF06def',
74-
'position': Infinity,
75-
'result': undefined
76-
},
77-
{
78-
'string': 'abc\uD834\uDF06def',
79-
'position': -Infinity,
80-
'result': undefined
81-
},
82-
// String that starts with an astral symbol
83-
{
84-
'string': '\uD834\uDF06def',
85-
'position': -1,
86-
'result': undefined
87-
},
88-
{
89-
'string': '\uD834\uDF06def',
90-
'position': -0,
91-
'result': 0x1D306
92-
},
93-
{
94-
'string': '\uD834\uDF06def',
95-
'position': 0,
96-
'result': 0x1D306
97-
},
98-
{
99-
'string': '\uD834\uDF06def',
100-
'position': null,
101-
'result': 0x1D306
102-
},
103-
{
104-
'string': '\uD834\uDF06def',
105-
'position': undefined,
106-
'result': 0x1D306
107-
},
108-
{
109-
'string': '\uD834\uDF06def',
110-
'position': false,
111-
'result': 0x1D306
112-
},
113-
{
114-
'string': '\uD834\uDF06def',
115-
'position': '',
116-
'result': 0x1D306
117-
},
118-
{
119-
'string': '\uD834\uDF06def',
120-
'position': '_',
121-
'result': 0x1D306
122-
},
123-
{
124-
'string': '\uD834\uDF06def',
125-
'position': 42,
126-
'result': undefined
127-
},
128-
{
129-
'string': '\uD834\uDF06def',
130-
'position': 1,
131-
'result': 0xDF06
132-
},
133-
{
134-
'string': '\uD834\uDF06def',
135-
'position': '1',
136-
'result': 0xDF06
137-
},
138-
// Lone high surrogates
139-
{
140-
'string': '\uD834abc',
141-
'position': -1,
142-
'result': undefined
143-
},
144-
{
145-
'string': '\uD834abc',
146-
'position': -0,
147-
'result': 0xD834
148-
},
149-
{
150-
'string': '\uD834abc',
151-
'position': 0,
152-
'result': 0xD834
153-
},
154-
{
155-
'string': '\uD834abc',
156-
'position': null,
157-
'result': 0xD834
158-
},
159-
{
160-
'string': '\uD834abc',
161-
'position': undefined,
162-
'result': 0xD834
163-
},
164-
{
165-
'string': '\uD834abc',
166-
'position': false,
167-
'result': 0xD834
168-
},
169-
{
170-
'string': '\uD834abc',
171-
'position': NaN,
172-
'result': 0xD834
173-
},
174-
{
175-
'string': '\uD834abc',
176-
'position': '',
177-
'result': 0xD834
178-
},
179-
{
180-
'string': '\uD834abc',
181-
'position': '_',
182-
'result': 0xD834
183-
},
184-
// Lone low surrogates
185-
{
186-
'string': '\uDF06abc',
187-
'position': -1,
188-
'result': undefined
189-
},
190-
{
191-
'string': '\uDF06abc',
192-
'position': -0,
193-
'result': 0xDF06
194-
},
195-
{
196-
'string': '\uDF06abc',
197-
'position': 0,
198-
'result': 0xDF06
199-
},
200-
{
201-
'string': '\uDF06abc',
202-
'position': null,
203-
'result': 0xDF06
204-
},
205-
{
206-
'string': '\uDF06abc',
207-
'position': undefined,
208-
'result': 0xDF06
209-
},
210-
{
211-
'string': '\uDF06abc',
212-
'position': false,
213-
'result': 0xDF06
214-
},
215-
{
216-
'string': '\uDF06abc',
217-
'position': NaN,
218-
'result': 0xDF06
219-
},
220-
{
221-
'string': '\uDF06abc',
222-
'position': '',
223-
'result': 0xDF06
224-
},
225-
{
226-
'string': '\uDF06abc',
227-
'position': '_',
228-
'result': 0xDF06
229-
}
230-
];
6+
assertEquals(String.prototype.codePointAt.length, 1);
2317

232-
assert.equal(String.prototype.codePointAt.length, 1);
8+
// String that starts with a BMP symbol
9+
assertEquals('abc\uD834\uDF06def'.codePointAt(''), 0x61);
10+
assertEquals('abc\uD834\uDF06def'.codePointAt('_'), 0x61);
11+
assertEquals('abc\uD834\uDF06def'.codePointAt(), 0x61);
12+
assertEquals('abc\uD834\uDF06def'.codePointAt(-Infinity), undefined);
13+
assertEquals('abc\uD834\uDF06def'.codePointAt(-1), undefined);
14+
assertEquals('abc\uD834\uDF06def'.codePointAt(-0), 0x61);
15+
assertEquals('abc\uD834\uDF06def'.codePointAt(0), 0x61);
16+
assertEquals('abc\uD834\uDF06def'.codePointAt(3), 0x1D306);
17+
assertEquals('abc\uD834\uDF06def'.codePointAt(4), 0xDF06);
18+
assertEquals('abc\uD834\uDF06def'.codePointAt(5), 0x64);
19+
assertEquals('abc\uD834\uDF06def'.codePointAt(42), undefined);
20+
assertEquals('abc\uD834\uDF06def'.codePointAt(Infinity), undefined);
21+
assertEquals('abc\uD834\uDF06def'.codePointAt(Infinity), undefined);
22+
assertEquals('abc\uD834\uDF06def'.codePointAt(NaN), 0x61);
23+
assertEquals('abc\uD834\uDF06def'.codePointAt(false), 0x61);
24+
assertEquals('abc\uD834\uDF06def'.codePointAt(null), 0x61);
25+
assertEquals('abc\uD834\uDF06def'.codePointAt(undefined), 0x61);
23326

234-
var errors = 0;
235-
tests.forEach(function(test, index) {
236-
try {
237-
assert.equal(
238-
test.string.codePointAt(test.position),
239-
test.result,
240-
index
241-
);
242-
} catch(error) {
243-
errors++;
244-
console.log(error.stack);
245-
}
246-
});
27+
// String that starts with an astral symbol
28+
assertEquals('\uD834\uDF06def'.codePointAt(''), 0x1D306);
29+
assertEquals('\uD834\uDF06def'.codePointAt('1'), 0xDF06);
30+
assertEquals('\uD834\uDF06def'.codePointAt('_'), 0x1D306);
31+
assertEquals('\uD834\uDF06def'.codePointAt(), 0x1D306);
32+
assertEquals('\uD834\uDF06def'.codePointAt(-1), undefined);
33+
assertEquals('\uD834\uDF06def'.codePointAt(-0), 0x1D306);
34+
assertEquals('\uD834\uDF06def'.codePointAt(0), 0x1D306);
35+
assertEquals('\uD834\uDF06def'.codePointAt(1), 0xDF06);
36+
assertEquals('\uD834\uDF06def'.codePointAt(42), undefined);
37+
assertEquals('\uD834\uDF06def'.codePointAt(false), 0x1D306);
38+
assertEquals('\uD834\uDF06def'.codePointAt(null), 0x1D306);
39+
assertEquals('\uD834\uDF06def'.codePointAt(undefined), 0x1D306);
24740

248-
console.log(
249-
'Ran %d tests.\n%d assertions failed.\n%d assertions passed.',
250-
tests.length, errors, tests.length - errors
251-
);
252-
if (errors) {
253-
process.exit(1);
254-
}
41+
// Lone high surrogates
42+
assertEquals('\uD834abc'.codePointAt(''), 0xD834);
43+
assertEquals('\uD834abc'.codePointAt('_'), 0xD834);
44+
assertEquals('\uD834abc'.codePointAt(), 0xD834);
45+
assertEquals('\uD834abc'.codePointAt(-1), undefined);
46+
assertEquals('\uD834abc'.codePointAt(-0), 0xD834);
47+
assertEquals('\uD834abc'.codePointAt(0), 0xD834);
48+
assertEquals('\uD834abc'.codePointAt(false), 0xD834);
49+
assertEquals('\uD834abc'.codePointAt(NaN), 0xD834);
50+
assertEquals('\uD834abc'.codePointAt(null), 0xD834);
51+
assertEquals('\uD834abc'.codePointAt(undefined), 0xD834);
52+
53+
// Lone low surrogates
54+
assertEquals('\uDF06abc'.codePointAt(''), 0xDF06);
55+
assertEquals('\uDF06abc'.codePointAt('_'), 0xDF06);
56+
assertEquals('\uDF06abc'.codePointAt(), 0xDF06);
57+
assertEquals('\uDF06abc'.codePointAt(-1), undefined);
58+
assertEquals('\uDF06abc'.codePointAt(-0), 0xDF06);
59+
assertEquals('\uDF06abc'.codePointAt(0), 0xDF06);
60+
assertEquals('\uDF06abc'.codePointAt(false), 0xDF06);
61+
assertEquals('\uDF06abc'.codePointAt(NaN), 0xDF06);
62+
assertEquals('\uDF06abc'.codePointAt(null), 0xDF06);
63+
assertEquals('\uDF06abc'.codePointAt(undefined), 0xDF06);

0 commit comments

Comments
 (0)