graphic_test.go 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. // Copyright 2011 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 unicode_test
  5. import (
  6. "testing"
  7. . "unicode"
  8. )
  9. // Independently check that the special "Is" functions work
  10. // in the Latin-1 range through the property table.
  11. func TestIsControlLatin1(t *testing.T) {
  12. for i := rune(0); i <= MaxLatin1; i++ {
  13. got := IsControl(i)
  14. want := false
  15. switch {
  16. case 0x00 <= i && i <= 0x1F:
  17. want = true
  18. case 0x7F <= i && i <= 0x9F:
  19. want = true
  20. }
  21. if got != want {
  22. t.Errorf("%U incorrect: got %t; want %t", i, got, want)
  23. }
  24. }
  25. }
  26. func TestIsLetterLatin1(t *testing.T) {
  27. for i := rune(0); i <= MaxLatin1; i++ {
  28. got := IsLetter(i)
  29. want := Is(Letter, i)
  30. if got != want {
  31. t.Errorf("%U incorrect: got %t; want %t", i, got, want)
  32. }
  33. }
  34. }
  35. func TestIsUpperLatin1(t *testing.T) {
  36. for i := rune(0); i <= MaxLatin1; i++ {
  37. got := IsUpper(i)
  38. want := Is(Upper, i)
  39. if got != want {
  40. t.Errorf("%U incorrect: got %t; want %t", i, got, want)
  41. }
  42. }
  43. }
  44. func TestIsLowerLatin1(t *testing.T) {
  45. for i := rune(0); i <= MaxLatin1; i++ {
  46. got := IsLower(i)
  47. want := Is(Lower, i)
  48. if got != want {
  49. t.Errorf("%U incorrect: got %t; want %t", i, got, want)
  50. }
  51. }
  52. }
  53. func TestNumberLatin1(t *testing.T) {
  54. for i := rune(0); i <= MaxLatin1; i++ {
  55. got := IsNumber(i)
  56. want := Is(Number, i)
  57. if got != want {
  58. t.Errorf("%U incorrect: got %t; want %t", i, got, want)
  59. }
  60. }
  61. }
  62. func TestIsPrintLatin1(t *testing.T) {
  63. for i := rune(0); i <= MaxLatin1; i++ {
  64. got := IsPrint(i)
  65. want := In(i, PrintRanges...)
  66. if i == ' ' {
  67. want = true
  68. }
  69. if got != want {
  70. t.Errorf("%U incorrect: got %t; want %t", i, got, want)
  71. }
  72. }
  73. }
  74. func TestIsGraphicLatin1(t *testing.T) {
  75. for i := rune(0); i <= MaxLatin1; i++ {
  76. got := IsGraphic(i)
  77. want := In(i, GraphicRanges...)
  78. if got != want {
  79. t.Errorf("%U incorrect: got %t; want %t", i, got, want)
  80. }
  81. }
  82. }
  83. func TestIsPunctLatin1(t *testing.T) {
  84. for i := rune(0); i <= MaxLatin1; i++ {
  85. got := IsPunct(i)
  86. want := Is(Punct, i)
  87. if got != want {
  88. t.Errorf("%U incorrect: got %t; want %t", i, got, want)
  89. }
  90. }
  91. }
  92. func TestIsSpaceLatin1(t *testing.T) {
  93. for i := rune(0); i <= MaxLatin1; i++ {
  94. got := IsSpace(i)
  95. want := Is(White_Space, i)
  96. if got != want {
  97. t.Errorf("%U incorrect: got %t; want %t", i, got, want)
  98. }
  99. }
  100. }
  101. func TestIsSymbolLatin1(t *testing.T) {
  102. for i := rune(0); i <= MaxLatin1; i++ {
  103. got := IsSymbol(i)
  104. want := Is(Symbol, i)
  105. if got != want {
  106. t.Errorf("%U incorrect: got %t; want %t", i, got, want)
  107. }
  108. }
  109. }