This repository has been archived by the owner on May 11, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.js
49 lines (43 loc) · 2.13 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
var assert = require('assert')
var m = require('./index')
assert.strictEqual(m.splitRaw('Short and sweet').length, 1, 'Should not split short messages')
assert.strictEqual(m.split('Short and sweet').length, 1, 'Should not split short messages')
// Hangul characters are grouped by syllable, but each syllable contains
// multiple letters and multiple bytes.
// plug.dj splits on the byte level, so it would cut off the last 안영하세요
// below in the middle of the 세 character.
var hangulStr = '안영하세요 안영하세요 안영하세요 안영하세요 안영하세요 안영하세요 안영하세요 ' +
'안영하세요 안영하세요 안영하세요 안영하세요 안영하세요 안영하세요 안영하세요 ' +
'안영하세요 안영하세요'
var result = m.splitRaw(hangulStr)
assert.strictEqual(result[0],
'안영하세요 안영하세요 안영하세요 안영하세요 안영하세요 안영하세요 안영하세요 ' +
'안영하세요 안영하세요 안영하세요 안영하세요 안영하세요 안영하세요 안영하세요 ' +
'안영하세요 안영하',
'Should cut off before the 세 character'
)
assert.strictEqual(result[1],
'세요',
'Should put the remaining full characters in a new chunk'
)
result = m.split(hangulStr)
assert.strictEqual(result[0],
'안영하세요 안영하세요 안영하세요 안영하세요 안영하세요 안영하세요 안영하세요 ' +
'안영하세요 안영하세요 안영하세요 안영하세요 안영하세요 안영하세요 안영하세요 ' +
'안영하세요',
'Should cut off before the last word and trim ending whitespace'
)
assert.strictEqual(result[1],
'안영하세요',
'Should put the remaining words in a new chunk'
)
// 63 >s are escaped to >, and then cut off in the middle of the last
// escaped character. After unescaping, the message would look like:
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>&g
var gtStr = '>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>'
assert.strictEqual(
m.truncate(gtStr).length,
62,
'Should truncate before the last >'
)
console.log('ok')