digit_test.go 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. // Copyright 2009 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. var testDigit = []rune{
  10. 0x0030,
  11. 0x0039,
  12. 0x0661,
  13. 0x06F1,
  14. 0x07C9,
  15. 0x0966,
  16. 0x09EF,
  17. 0x0A66,
  18. 0x0AEF,
  19. 0x0B66,
  20. 0x0B6F,
  21. 0x0BE6,
  22. 0x0BEF,
  23. 0x0C66,
  24. 0x0CEF,
  25. 0x0D66,
  26. 0x0D6F,
  27. 0x0E50,
  28. 0x0E59,
  29. 0x0ED0,
  30. 0x0ED9,
  31. 0x0F20,
  32. 0x0F29,
  33. 0x1040,
  34. 0x1049,
  35. 0x1090,
  36. 0x1091,
  37. 0x1099,
  38. 0x17E0,
  39. 0x17E9,
  40. 0x1810,
  41. 0x1819,
  42. 0x1946,
  43. 0x194F,
  44. 0x19D0,
  45. 0x19D9,
  46. 0x1B50,
  47. 0x1B59,
  48. 0x1BB0,
  49. 0x1BB9,
  50. 0x1C40,
  51. 0x1C49,
  52. 0x1C50,
  53. 0x1C59,
  54. 0xA620,
  55. 0xA629,
  56. 0xA8D0,
  57. 0xA8D9,
  58. 0xA900,
  59. 0xA909,
  60. 0xAA50,
  61. 0xAA59,
  62. 0xFF10,
  63. 0xFF19,
  64. 0x104A1,
  65. 0x1D7CE,
  66. }
  67. var testLetter = []rune{
  68. 0x0041,
  69. 0x0061,
  70. 0x00AA,
  71. 0x00BA,
  72. 0x00C8,
  73. 0x00DB,
  74. 0x00F9,
  75. 0x02EC,
  76. 0x0535,
  77. 0x06E6,
  78. 0x093D,
  79. 0x0A15,
  80. 0x0B99,
  81. 0x0DC0,
  82. 0x0EDD,
  83. 0x1000,
  84. 0x1200,
  85. 0x1312,
  86. 0x1401,
  87. 0x1885,
  88. 0x2C00,
  89. 0xA800,
  90. 0xF900,
  91. 0xFA30,
  92. 0xFFDA,
  93. 0xFFDC,
  94. 0x10000,
  95. 0x10300,
  96. 0x10400,
  97. 0x20000,
  98. 0x2F800,
  99. 0x2FA1D,
  100. }
  101. func TestDigit(t *testing.T) {
  102. for _, r := range testDigit {
  103. if !IsDigit(r) {
  104. t.Errorf("IsDigit(U+%04X) = false, want true", r)
  105. }
  106. }
  107. for _, r := range testLetter {
  108. if IsDigit(r) {
  109. t.Errorf("IsDigit(U+%04X) = true, want false", r)
  110. }
  111. }
  112. }
  113. // Test that the special case in IsDigit agrees with the table
  114. func TestDigitOptimization(t *testing.T) {
  115. for i := rune(0); i <= MaxLatin1; i++ {
  116. if Is(Digit, i) != IsDigit(i) {
  117. t.Errorf("IsDigit(U+%04X) disagrees with Is(Digit)", i)
  118. }
  119. }
  120. }