forked from playcanvas/engine
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstring.test.mjs
More file actions
77 lines (57 loc) · 2.73 KB
/
string.test.mjs
File metadata and controls
77 lines (57 loc) · 2.73 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
import { expect } from 'chai';
import { string } from '../../src/core/string.js';
describe('string', function () {
describe('#format', function () {
it('handles no args', function () {
const src = 'a string';
const result = string.format(src);
expect(result).to.equal('a string');
});
it('handles one arg', function () {
const src = 'a string {0}';
const result = string.format(src, 'abc');
expect(result).to.equal('a string abc');
});
it('handles two args', function () {
const src = '{0} a string {1}';
const result = string.format(src, 'abc', 'def');
expect(result).to.equal('abc a string def');
});
});
describe('#getSymbols', function () {
it('returns an array of the expected length', function () {
expect(string.getSymbols('ABC').length).to.equal(3);
expect(string.getSymbols('A🇺🇸').length).to.equal(2);
expect(string.getSymbols('👨🏿').length).to.equal(1);
expect(string.getSymbols('👁️🗨️').length).to.equal(1);
expect(string.getSymbols('3️⃣').length).to.equal(1);
expect(string.getSymbols('🏴☠️').length).to.equal(1);
});
});
describe('#fromCodePoint', function () {
it('converts basic ASCII code points to characters', function () {
expect(string.fromCodePoint(65)).to.equal('A');
expect(string.fromCodePoint(66, 67)).to.equal('BC');
expect(string.fromCodePoint(97, 98, 99)).to.equal('abc');
});
it('handles code points beyond the BMP (Basic Multilingual Plane)', function () {
// Emoji: 😀 (U+1F600 GRINNING FACE)
expect(string.fromCodePoint(0x1F600)).to.equal('😀');
// Musical note: 𝄞 (U+1D11E MUSICAL SYMBOL G CLEF)
expect(string.fromCodePoint(0x1D11E)).to.equal('𝄞');
});
it('handles multiple code points including surrogate pairs', function () {
// Mix of BMP and astral code points
expect(string.fromCodePoint(65, 0x1F600, 66)).to.equal('A😀B');
// Multiple astral code points: 💩 (U+1F4A9) and 🚀 (U+1F680)
expect(string.fromCodePoint(0x1F4A9, 0x1F680)).to.equal('💩🚀');
});
it('matches native String.fromCodePoint behavior', function () {
// Only run if native method is available
if (String.fromCodePoint) {
const testPoints = [65, 0x1F600, 0x1D11E, 0x10437];
expect(string.fromCodePoint(...testPoints)).to.equal(String.fromCodePoint(...testPoints));
}
});
});
});