| 1 |
package comparison |
| 2 |
|
| 3 |
import ( |
| 4 |
"testing" |
| 5 |
"unicode" |
| 6 |
|
| 7 |
"github.com/clipperhouse/displaywidth" |
| 8 |
"github.com/mattn/go-runewidth" |
| 9 |
) |
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
func TestAllRunes(t *testing.T) { |
| 15 |
t.Skip("skipping compatibility test") |
| 16 |
if unicode.Version < "15" { |
| 17 |
|
| 18 |
|
| 19 |
return |
| 20 |
} |
| 21 |
|
| 22 |
for r := rune(0); r <= unicode.MaxRune; r++ { |
| 23 |
w1 := displaywidth.Rune(r) |
| 24 |
w2 := runewidth.RuneWidth(r) |
| 25 |
if w1 != w2 { |
| 26 |
if unicode.Is(unicode.Mn, r) { |
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
continue |
| 31 |
} |
| 32 |
if unicode.Is(unicode.Cf, r) { |
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
continue |
| 37 |
} |
| 38 |
if unicode.Is(unicode.Mc, r) { |
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
continue |
| 43 |
} |
| 44 |
t.Errorf("%#x: runewidth is %d, displaywidth is %d, difference is %d", r, w2, w1, w2-w1) |
| 45 |
} |
| 46 |
} |
| 47 |
} |