tables_test.go 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. // Copyright 2015 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 width
  5. import (
  6. "testing"
  7. "golang.org/x/text/internal/testtext"
  8. )
  9. const (
  10. loSurrogate = 0xD800
  11. hiSurrogate = 0xDFFF
  12. )
  13. func TestTables(t *testing.T) {
  14. testtext.SkipIfNotLong(t)
  15. runes := map[rune]Kind{}
  16. getWidthData(func(r rune, tag elem, _ rune) {
  17. runes[r] = tag.kind()
  18. })
  19. for r := rune(0); r < 0x10FFFF; r++ {
  20. if loSurrogate <= r && r <= hiSurrogate {
  21. continue
  22. }
  23. p := LookupRune(r)
  24. if got, want := p.Kind(), runes[r]; got != want {
  25. t.Errorf("Kind of %U was %s; want %s.", r, got, want)
  26. }
  27. want, mapped := foldRune(r)
  28. if got := p.Folded(); (got == 0) == mapped || got != 0 && got != want {
  29. t.Errorf("Folded(%U) = %U; want %U", r, got, want)
  30. }
  31. want, mapped = widenRune(r)
  32. if got := p.Wide(); (got == 0) == mapped || got != 0 && got != want {
  33. t.Errorf("Wide(%U) = %U; want %U", r, got, want)
  34. }
  35. want, mapped = narrowRune(r)
  36. if got := p.Narrow(); (got == 0) == mapped || got != 0 && got != want {
  37. t.Errorf("Narrow(%U) = %U; want %U", r, got, want)
  38. }
  39. }
  40. }
  41. // TestAmbiguous verifies that ambiguous runes with a mapping always map to
  42. // a halfwidth rune.
  43. func TestAmbiguous(t *testing.T) {
  44. for r, m := range mapRunes {
  45. if m.e != tagAmbiguous {
  46. continue
  47. }
  48. if k := mapRunes[m.r].e.kind(); k != EastAsianHalfwidth {
  49. t.Errorf("Rune %U is ambiguous and maps to a rune of type %v", r, k)
  50. }
  51. }
  52. }