github.com/lianghucheng/zrddz@v0.0.0-20200923083010-c71f680932e2/src/golang.org/x/text/unicode/runenames/runenames_test.go (about)

     1  // Copyright 2016 The Go Authors. All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     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  // Copied from gen.go.
    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  }