...
1
2
3
4
5 package runenames
6
7 import (
8 "strings"
9 "testing"
10 "unicode"
11
12 "golang.org/x/text/internal/gen"
13 "golang.org/x/text/internal/testtext"
14 "golang.org/x/text/internal/ucd"
15 )
16
17 func TestName(t *testing.T) {
18 testtext.SkipIfNotLong(t)
19
20 wants := make([]string, 1+unicode.MaxRune)
21 ucd.Parse(gen.OpenUCDFile("UnicodeData.txt"), func(p *ucd.Parser) {
22 wants[p.Rune(0)] = getName(p)
23 })
24
25 nErrors := 0
26 for r, want := range wants {
27 got := Name(rune(r))
28 if got != want {
29 t.Errorf("r=%#08x: got %q, want %q", r, got, want)
30 nErrors++
31 if nErrors == 100 {
32 t.Fatal("too many errors")
33 }
34 }
35 }
36 }
37
38
39 func getName(p *ucd.Parser) string {
40 s := p.String(ucd.Name)
41 if s == "" {
42 return ""
43 }
44 if s[0] == '<' {
45 const first = ", First>"
46 if i := strings.Index(s, first); i >= 0 {
47 s = s[:i] + ">"
48 }
49
50 }
51 return s
52 }
53
View as plain text