Skip to content

Commit

Permalink
feat: wcwidth: tidy and add more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
aymanbagabas committed Oct 21, 2024
1 parent 8140f28 commit c527e24
Showing 1 changed file with 37 additions and 32 deletions.
69 changes: 37 additions & 32 deletions wcwidth/wcwidth_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,39 +31,42 @@ func TestStringWidth(t *testing.T) {
}

var runewidthtests = []struct {
in rune
out int
eaout int
nseout int
in rune
out int
}{
{'世', 2, 2, 2},
{'界', 2, 2, 2},
{'セ', 1, 1, 1},
{'カ', 1, 1, 1},
{'イ', 1, 1, 1},
{'☆', 1, 2, 2}, // double width in ambiguous
{'☺', 1, 1, 2},
{'☻', 1, 1, 2},
{'♥', 1, 2, 2},
{'♦', 1, 1, 2},
{'♣', 1, 2, 2},
{'♠', 1, 2, 2},
{'♂', 1, 2, 2},
{'♀', 1, 2, 2},
{'♪', 1, 2, 2},
{'♫', 1, 1, 2},
{'☼', 1, 1, 2},
{'↕', 1, 2, 2},
{'‼', 1, 1, 2},
{'↔', 1, 2, 2},
{'\x00', 0, 0, 0},
{'\x01', 0, 0, 0},
{'\u0300', 0, 0, 0},
{'\u2028', 0, 0, 0},
{'\u2029', 0, 0, 0},
{'a', 1, 1, 1}, // ASCII classified as "na" (narrow)
{'⟦', 1, 1, 1}, // non-ASCII classified as "na" (narrow)
{'👁', 1, 1, 2},
{'世', 2},
{'界', 2},
{'セ', 1},
{'カ', 1},
{'イ', 1},
{'☆', 1}, // double width in ambiguous
{'☺', 1},
{'☻', 1},
{'♥', 1},
{'♦', 1},
{'♣', 1},
{'♠', 1},
{'♂', 1},
{'♀', 1},
{'♪', 1},
{'♫', 1},
{'☼', 1},
{'↕', 1},
{'‼', 1},
{'↔', 1},
{'\x00', 0},
{'\x01', 0},
{'\u0300', 0},
{'\u2028', 0},
{'\u2029', 0},
{'a', 1}, // ASCII classified as "na" (narrow)
{'⟦', 1}, // non-ASCII classified as "na" (narrow)
{'👁', 1},
{'\u0301', 0}, // Combining acute accent
{'a', 1},
{'Ω', 1},
{'好', 2},
{'か', 2},
}

func BenchmarkRuneWidth(b *testing.B) {
Expand Down Expand Up @@ -95,6 +98,8 @@ func TestZeroWidthJoiner(t *testing.T) {
{"あ👩\u200d🍳い", 8},
{"あ\u200d🍳い", 6},
{"あ\u200dい", 4},
{"abc", 3},
{"你好", 4},
}

for _, tt := range tests {
Expand Down

0 comments on commit c527e24

Please sign in to comment.