Repository navigation
Expand file tree
/
Copy pathcharacters.ts
More file actions
97 lines (80 loc) · 2.37 KB
/
Copy pathcharacters.ts
File metadata and controls
97 lines (80 loc) · 2.37 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
import { decodeUnicodeEscapeSequence, isHighSurrogate, isLowSurrogate, isSurrogatePair } from '../src/utils/characters';
import { describe, expect, test } from 'vitest';
describe('isHighSurrogate', () => {
const cases: [string, boolean][] = [
['', false],
['\ud7ff', false],
['\ud800', true],
['\udbff', true],
['\udc00', false],
['\udfff', false],
['\ue000', false],
];
test.concurrent.each(cases)('"%s" -> %s', (input, expected) => {
expect(isHighSurrogate(input)).toBe(expected);
});
test.concurrent('index out of range', () => {
expect(isHighSurrogate('\uD800', 1)).toBe(false);
});
});
describe('isLowSurrogate', () => {
const cases: [string, boolean][] = [
['', false],
['\ud7ff', false],
['\ud800', false],
['\udbff', false],
['\udc00', true],
['\udfff', true],
['\ue000', false],
];
test.concurrent.each(cases)('"%s" -> %s', (input, expected) => {
expect(isLowSurrogate(input)).toBe(expected);
});
test.concurrent('index out of range', () => {
expect(isLowSurrogate('\DC00', 1)).toBe(false);
});
});
describe('isSurrogatePair', () => {
const cases: [string, boolean][] = [
['\ud842\udfb7', true],
['\ud83e\udd2f', true],
['a', false],
['\u85cd', false],
['\ud842', false],
['\ud8000', false],
['0\udc00', false],
['_\ud842\udfb7', false],
];
test.concurrent.each(cases)('"%s" -> %s', (input, expected) => {
expect(isSurrogatePair(input)).toBe(expected);
});
test.concurrent.each(cases)('start given', () => {
expect(isSurrogatePair('_\ud842\udfb7', 1)).toBe(true);
});
});
describe('decodeUnicodeEscapeSequence', () => {
test('plain', () => {
expect(decodeUnicodeEscapeSequence('abc123')).toBe('abc123');
});
test('escape', () => {
expect(decodeUnicodeEscapeSequence('\\u0041')).toBe('A');
});
test('escape lowercase', () => {
expect(decodeUnicodeEscapeSequence('\\u85cd')).toBe('藍');
});
test('escape uppercase', () => {
expect(decodeUnicodeEscapeSequence('\\u85CD')).toBe('藍');
});
test('expects "u", unexpected end', () => {
expect(() => decodeUnicodeEscapeSequence('\\')).toThrow();
});
test('expects "u"', () => {
expect(() => decodeUnicodeEscapeSequence('\\0')).toThrow();
});
test('expects digit, unexpected end', () => {
expect(() => decodeUnicodeEscapeSequence('\\u00')).toThrow();
});
test('expects digit', () => {
expect(() => decodeUnicodeEscapeSequence('\\ug')).toThrow();
});
});