Debian Codegraph @

comparison/compatibility_test.go

raw symbols SCIP
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 // Investigate differences between displaywidth and go-runewidth.
12 // Not meant to be a real test, more of a tool, but good to
13 // fail if something changes in the future.
14 func TestAllRunes(t *testing.T) {
15 t.Skip("skipping compatibility test")
16 if unicode.Version < "15" {
17 // We only care about Unicode 15 and above,
18 // which I believe was Go version 1.21.
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 // these are in the trie, known
28 // we will return width 0,
29 // go-runewidth may return width 1
30 continue
31 }
32 if unicode.Is(unicode.Cf, r) {
33 // these are in the trie, known
34 // we will return width 0,
35 // go-runewidth may return width 1
36 continue
37 }
38 if unicode.Is(unicode.Mc, r) {
39 // these are deliberately excluded from the trie, known
40 // we will return width 1,
41 // go-runewidth may return width 0
42 continue
43 }
44 t.Errorf("%#x: runewidth is %d, displaywidth is %d, difference is %d", r, w2, w1, w2-w1)
45 }
46 }
47 }