OSDN Git Service

new repo
[bytom/vapor.git] / vendor / golang.org / x / text / cases / fold_test.go
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 cases
6
7 import (
8         "testing"
9
10         "golang.org/x/text/internal/testtext"
11 )
12
13 var foldTestCases = []string{
14         "βß\u13f8",        // "βssᏰ"
15         "ab\u13fc\uab7aꭰ", // abᏴᎪᎠ
16         "affifflast",           // affifflast
17         "Iİiı\u0345",      // ii̇iıι
18         "µµΜΜςσΣΣ",        // μμμμσσσσ
19 }
20
21 func TestFold(t *testing.T) {
22         for _, tc := range foldTestCases {
23                 testEntry := func(name string, c Caser, m func(r rune) string) {
24                         want := ""
25                         for _, r := range tc {
26                                 want += m(r)
27                         }
28                         if got := c.String(tc); got != want {
29                                 t.Errorf("%s(%s) = %+q; want %+q", name, tc, got, want)
30                         }
31                         dst := make([]byte, 256) // big enough to hold any result
32                         src := []byte(tc)
33                         v := testtext.AllocsPerRun(20, func() {
34                                 c.Transform(dst, src, true)
35                         })
36                         if v > 0 {
37                                 t.Errorf("%s(%s): number of allocs was %f; want 0", name, tc, v)
38                         }
39                 }
40                 testEntry("FullFold", Fold(), func(r rune) string {
41                         return runeFoldData(r).full
42                 })
43                 // TODO:
44                 // testEntry("SimpleFold", Fold(Compact), func(r rune) string {
45                 //      return runeFoldData(r).simple
46                 // })
47                 // testEntry("SpecialFold", Fold(Turkic), func(r rune) string {
48                 //      return runeFoldData(r).special
49                 // })
50         }
51 }