-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathgwidth_test.go
55 lines (51 loc) · 1.1 KB
/
gwidth_test.go
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
package vaxis
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestRenderedWidth(t *testing.T) {
tests := []struct {
name string
input string
unicodeWidth int
wcwidthWidth int
noZWJWidth int
}{
{
name: "a",
input: "a",
unicodeWidth: 1,
wcwidthWidth: 1,
noZWJWidth: 1,
},
{
name: "emoji with ZWJ",
input: "👩🚀",
unicodeWidth: 2,
wcwidthWidth: 4,
noZWJWidth: 4,
},
{
name: "emoji with VS16 selector",
input: "\xE2\x9D\xA4\xEF\xB8\x8F",
unicodeWidth: 2,
// This is *technically* wrong but most ter
wcwidthWidth: 1,
noZWJWidth: 2,
},
{
name: "emoji with skintone selector",
input: "👋🏿",
unicodeWidth: 2,
wcwidthWidth: 4,
noZWJWidth: 2,
},
}
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
assert.Equal(t, test.unicodeWidth, gwidth(test.input, unicodeStd))
assert.Equal(t, test.wcwidthWidth, gwidth(test.input, wcwidth))
assert.Equal(t, test.noZWJWidth, gwidth(test.input, noZWJ))
})
}
}