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