script_test.go 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  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. type T struct {
  10. rune rune
  11. script string
  12. }
  13. var inCategoryTest = []T{
  14. {0x0081, "Cc"},
  15. {0x200B, "Cf"},
  16. {0xf0000, "Co"},
  17. {0xdb80, "Cs"},
  18. {0x0236, "Ll"},
  19. {0x1d9d, "Lm"},
  20. {0x07cf, "Lo"},
  21. {0x1f8a, "Lt"},
  22. {0x03ff, "Lu"},
  23. {0x0bc1, "Mc"},
  24. {0x20df, "Me"},
  25. {0x07f0, "Mn"},
  26. {0x1bb2, "Nd"},
  27. {0x10147, "Nl"},
  28. {0x2478, "No"},
  29. {0xfe33, "Pc"},
  30. {0x2011, "Pd"},
  31. {0x301e, "Pe"},
  32. {0x2e03, "Pf"},
  33. {0x2e02, "Pi"},
  34. {0x0022, "Po"},
  35. {0x2770, "Ps"},
  36. {0x00a4, "Sc"},
  37. {0xa711, "Sk"},
  38. {0x25f9, "Sm"},
  39. {0x2108, "So"},
  40. {0x2028, "Zl"},
  41. {0x2029, "Zp"},
  42. {0x202f, "Zs"},
  43. // Unifieds.
  44. {0x04aa, "L"},
  45. {0x0009, "C"},
  46. {0x1712, "M"},
  47. {0x0031, "N"},
  48. {0x00bb, "P"},
  49. {0x00a2, "S"},
  50. {0x00a0, "Z"},
  51. }
  52. var inPropTest = []T{
  53. {0x0046, "ASCII_Hex_Digit"},
  54. {0x200F, "Bidi_Control"},
  55. {0x2212, "Dash"},
  56. {0xE0001, "Deprecated"},
  57. {0x00B7, "Diacritic"},
  58. {0x30FE, "Extender"},
  59. {0xFF46, "Hex_Digit"},
  60. {0x2E17, "Hyphen"},
  61. {0x2FFB, "IDS_Binary_Operator"},
  62. {0x2FF3, "IDS_Trinary_Operator"},
  63. {0xFA6A, "Ideographic"},
  64. {0x200D, "Join_Control"},
  65. {0x0EC4, "Logical_Order_Exception"},
  66. {0x2FFFF, "Noncharacter_Code_Point"},
  67. {0x065E, "Other_Alphabetic"},
  68. {0x2065, "Other_Default_Ignorable_Code_Point"},
  69. {0x0BD7, "Other_Grapheme_Extend"},
  70. {0x0387, "Other_ID_Continue"},
  71. {0x212E, "Other_ID_Start"},
  72. {0x2094, "Other_Lowercase"},
  73. {0x2040, "Other_Math"},
  74. {0x216F, "Other_Uppercase"},
  75. {0x0027, "Pattern_Syntax"},
  76. {0x0020, "Pattern_White_Space"},
  77. {0x06DD, "Prepended_Concatenation_Mark"},
  78. {0x300D, "Quotation_Mark"},
  79. {0x2EF3, "Radical"},
  80. {0x1f1ff, "Regional_Indicator"},
  81. {0x061F, "STerm"}, // Deprecated alias of Sentence_Terminal
  82. {0x061F, "Sentence_Terminal"},
  83. {0x2071, "Soft_Dotted"},
  84. {0x003A, "Terminal_Punctuation"},
  85. {0x9FC3, "Unified_Ideograph"},
  86. {0xFE0F, "Variation_Selector"},
  87. {0x0020, "White_Space"},
  88. }
  89. func TestCategories(t *testing.T) {
  90. notTested := make(map[string]bool)
  91. for k := range Categories {
  92. notTested[k] = true
  93. }
  94. for _, test := range inCategoryTest {
  95. if _, ok := Categories[test.script]; !ok {
  96. t.Fatal(test.script, "not a known category")
  97. }
  98. if !Is(Categories[test.script], test.rune) {
  99. t.Errorf("IsCategory(%U, %s) = false, want true", test.rune, test.script)
  100. }
  101. delete(notTested, test.script)
  102. }
  103. for k := range notTested {
  104. t.Error("category not tested:", k)
  105. }
  106. }
  107. func TestProperties(t *testing.T) {
  108. notTested := make(map[string]bool)
  109. for k := range Properties {
  110. notTested[k] = true
  111. }
  112. for _, test := range inPropTest {
  113. if _, ok := Properties[test.script]; !ok {
  114. t.Fatal(test.script, "not a known prop")
  115. }
  116. if !Is(Properties[test.script], test.rune) {
  117. t.Errorf("IsCategory(%U, %s) = false, want true", test.rune, test.script)
  118. }
  119. delete(notTested, test.script)
  120. }
  121. for k := range notTested {
  122. t.Error("property not tested:", k)
  123. }
  124. }