-
Notifications
You must be signed in to change notification settings - Fork 1
/
test.js
23 lines (18 loc) · 829 Bytes
/
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
const assert = require('assert')
const {strPosToUni, uniToStrPos, uniCount} = require('.')
// Characters in the U+0000-U+D7FF and U+E000-U+FFFF are UTF16 encoded to a single character
;['x', 'ff'].forEach(c => {
const str = c + '123'
assert.strictEqual(strPosToUni(str, 1), 1)
assert.strictEqual(strPosToUni(str), 4)
assert.strictEqual(uniCount(str), 4)
assert.strictEqual(uniToStrPos(str, 1), 1)
assert.strictEqual(uniToStrPos(str, 4), 4)
})
// Characters from U+10000 are encoded using surrogate pairs.
// The U+D800 to U+DFFF range is reserved and will never be assigned.
assert.strictEqual(strPosToUni('💃123', 2), 1)
assert.strictEqual(strPosToUni('💃123'), 4)
assert.strictEqual(uniCount('💃123'), 4)
assert.strictEqual(uniToStrPos('💃123', 1), 2)
assert.strictEqual(uniToStrPos('💃123', 4), 5)