|
1 | 1 | import test from 'ava';
|
2 |
| -import m from '.'; |
| 2 | +import stringWidth from '.'; |
3 | 3 |
|
4 | 4 | test('main', t => {
|
5 |
| - t.is(m('abcde'), 5); |
6 |
| - t.is(m('古池や'), 6); |
7 |
| - t.is(m('あいうabc'), 9); |
8 |
| - t.is(m('ノード.js'), 9); |
9 |
| - t.is(m('你好'), 4); |
10 |
| - t.is(m('안녕하세요'), 10); |
11 |
| - t.is(m('A\uD83C\uDE00BC'), 5, 'surrogate'); |
12 |
| - t.is(m('\u001B[31m\u001B[39m'), 0); |
13 |
| - t.is(m('\u{231A}'), 2, '⌚ default emoji presentation character (Emoji_Presentation)'); |
14 |
| - t.is(m('\u{2194}\u{FE0F}'), 2, '↔️ default text presentation character rendered as emoji'); |
15 |
| - t.is(m('\u{1F469}'), 2, '👩 emoji modifier base (Emoji_Modifier_Base)'); |
16 |
| - t.is(m('\u{1F469}\u{1F3FF}'), 2, '👩🏿 emoji modifier base followed by a modifier'); |
| 5 | + t.is(stringWidth('abcde'), 5); |
| 6 | + t.is(stringWidth('古池や'), 6); |
| 7 | + t.is(stringWidth('あいうabc'), 9); |
| 8 | + t.is(stringWidth('ノード.js'), 9); |
| 9 | + t.is(stringWidth('你好'), 4); |
| 10 | + t.is(stringWidth('안녕하세요'), 10); |
| 11 | + t.is(stringWidth('A\uD83C\uDE00BC'), 5, 'surrogate'); |
| 12 | + t.is(stringWidth('\u001B[31m\u001B[39m'), 0); |
| 13 | + t.is(stringWidth('\u{231A}'), 2, '⌚ default emoji presentation character (Emoji_Presentation)'); |
| 14 | + t.is(stringWidth('\u{2194}\u{FE0F}'), 2, '↔️ default text presentation character rendered as emoji'); |
| 15 | + t.is(stringWidth('\u{1F469}'), 2, '👩 emoji modifier base (Emoji_Modifier_Base)'); |
| 16 | + t.is(stringWidth('\u{1F469}\u{1F3FF}'), 2, '👩🏿 emoji modifier base followed by a modifier'); |
17 | 17 | });
|
18 | 18 |
|
19 | 19 | test('ignores control characters', t => {
|
20 |
| - t.is(m(String.fromCharCode(0)), 0); |
21 |
| - t.is(m(String.fromCharCode(31)), 0); |
22 |
| - t.is(m(String.fromCharCode(127)), 0); |
23 |
| - t.is(m(String.fromCharCode(134)), 0); |
24 |
| - t.is(m(String.fromCharCode(159)), 0); |
25 |
| - t.is(m('\u001B'), 0); |
| 20 | + t.is(stringWidth(String.fromCharCode(0)), 0); |
| 21 | + t.is(stringWidth(String.fromCharCode(31)), 0); |
| 22 | + t.is(stringWidth(String.fromCharCode(127)), 0); |
| 23 | + t.is(stringWidth(String.fromCharCode(134)), 0); |
| 24 | + t.is(stringWidth(String.fromCharCode(159)), 0); |
| 25 | + t.is(stringWidth('\u001B'), 0); |
26 | 26 | });
|
27 | 27 |
|
28 | 28 | test('handles combining characters', t => {
|
29 |
| - t.is(m('x\u0300'), 1); |
| 29 | + t.is(stringWidth('x\u0300'), 1); |
30 | 30 | });
|
0 commit comments