This repository has been archived by the owner on Oct 13, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathtest.js
66 lines (60 loc) · 2.33 KB
/
test.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
import test from 'ava';
import m from './';
test(t => {
t.is(m('🐴'), 0x1F434);
// borrowed from:
// https://github.com/mathiasbynens/String.prototype.codePointAt/blob/075017413b4a99568d0bf290250c8b17ff5441be/tests/tests.js
// String that starts with a BMP symbol
t.is(m('abc\uD834\uDF06def', ''), 0x61);
t.is(m('abc\uD834\uDF06def', '_'), 0x61);
t.is(m('abc\uD834\uDF06def'), 0x61);
t.is(m('abc\uD834\uDF06def', -Infinity), undefined);
t.is(m('abc\uD834\uDF06def', -1), undefined);
t.is(m('abc\uD834\uDF06def', -0), 0x61);
t.is(m('abc\uD834\uDF06def', 0), 0x61);
t.is(m('abc\uD834\uDF06def', 3), 0x1D306);
t.is(m('abc\uD834\uDF06def', 4), 0xDF06);
t.is(m('abc\uD834\uDF06def', 5), 0x64);
t.is(m('abc\uD834\uDF06def', 42), undefined);
t.is(m('abc\uD834\uDF06def', Infinity), undefined);
t.is(m('abc\uD834\uDF06def', Infinity), undefined);
t.is(m('abc\uD834\uDF06def', NaN), 0x61);
t.is(m('abc\uD834\uDF06def', false), 0x61);
t.is(m('abc\uD834\uDF06def', null), 0x61);
t.is(m('abc\uD834\uDF06def', undefined), 0x61);
// String that starts with an astral symbol
t.is(m('\uD834\uDF06def', ''), 0x1D306);
t.is(m('\uD834\uDF06def', '1'), 0xDF06);
t.is(m('\uD834\uDF06def', '_'), 0x1D306);
t.is(m('\uD834\uDF06def'), 0x1D306);
t.is(m('\uD834\uDF06def', -1), undefined);
t.is(m('\uD834\uDF06def', -0), 0x1D306);
t.is(m('\uD834\uDF06def', 0), 0x1D306);
t.is(m('\uD834\uDF06def', 1), 0xDF06);
t.is(m('\uD834\uDF06def', 42), undefined);
t.is(m('\uD834\uDF06def', false), 0x1D306);
t.is(m('\uD834\uDF06def', null), 0x1D306);
t.is(m('\uD834\uDF06def', undefined), 0x1D306);
// Lone high surrogates
t.is(m('\uD834abc', ''), 0xD834);
t.is(m('\uD834abc', '_'), 0xD834);
t.is(m('\uD834abc'), 0xD834);
t.is(m('\uD834abc', -1), undefined);
t.is(m('\uD834abc', -0), 0xD834);
t.is(m('\uD834abc', 0), 0xD834);
t.is(m('\uD834abc', false), 0xD834);
t.is(m('\uD834abc', NaN), 0xD834);
t.is(m('\uD834abc', null), 0xD834);
t.is(m('\uD834abc', undefined), 0xD834);
// Lone low surrogates
t.is(m('\uDF06abc', ''), 0xDF06);
t.is(m('\uDF06abc', '_'), 0xDF06);
t.is(m('\uDF06abc'), 0xDF06);
t.is(m('\uDF06abc', -1), undefined);
t.is(m('\uDF06abc', -0), 0xDF06);
t.is(m('\uDF06abc', 0), 0xDF06);
t.is(m('\uDF06abc', false), 0xDF06);
t.is(m('\uDF06abc', NaN), 0xDF06);
t.is(m('\uDF06abc', null), 0xDF06);
t.is(m('\uDF06abc', undefined), 0xDF06);
});