fold_test.go 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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. package cases
  5. import (
  6. "testing"
  7. "golang.org/x/text/internal/testtext"
  8. )
  9. var foldTestCases = []string{
  10. "βß\u13f8", // "βssᏰ"
  11. "ab\u13fc\uab7aꭰ", // abᏴᎪᎠ
  12. "affifflast", // affifflast
  13. "Iİiı\u0345", // ii̇iıι
  14. "µµΜΜςσΣΣ", // μμμμσσσσ
  15. }
  16. func TestFold(t *testing.T) {
  17. for _, tc := range foldTestCases {
  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 := testtext.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. }