github.com/ader1990/go@v0.0.0-20140630135419-8c24447fa791/src/pkg/unicode/script_test.go (about) 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 5 package unicode_test 6 7 import ( 8 "testing" 9 . "unicode" 10 ) 11 12 type T struct { 13 rune rune 14 script string 15 } 16 17 // Hand-chosen tests from Unicode 5.1.0, 6.0.0 and 6.2.0 mostly to discover when new 18 // scripts and categories arise. 19 var inTest = []T{ 20 {0x06e2, "Arabic"}, 21 {0x0567, "Armenian"}, 22 {0x10b20, "Avestan"}, 23 {0x1b37, "Balinese"}, 24 {0xa6af, "Bamum"}, 25 {0x1be1, "Batak"}, 26 {0x09c2, "Bengali"}, 27 {0x3115, "Bopomofo"}, 28 {0x282d, "Braille"}, 29 {0x1a1a, "Buginese"}, 30 {0x1747, "Buhid"}, 31 {0x11011, "Brahmi"}, 32 {0x156d, "Canadian_Aboriginal"}, 33 {0x102a9, "Carian"}, 34 {0x11111, "Chakma"}, 35 {0xaa4d, "Cham"}, 36 {0x13c2, "Cherokee"}, 37 {0x0020, "Common"}, 38 {0x1d4a5, "Common"}, 39 {0x2cfc, "Coptic"}, 40 {0x12420, "Cuneiform"}, 41 {0x1080c, "Cypriot"}, 42 {0xa663, "Cyrillic"}, 43 {0x10430, "Deseret"}, 44 {0x094a, "Devanagari"}, 45 {0x13001, "Egyptian_Hieroglyphs"}, 46 {0x1271, "Ethiopic"}, 47 {0x10fc, "Georgian"}, 48 {0x2c40, "Glagolitic"}, 49 {0x10347, "Gothic"}, 50 {0x03ae, "Greek"}, 51 {0x0abf, "Gujarati"}, 52 {0x0a24, "Gurmukhi"}, 53 {0x3028, "Han"}, 54 {0x11b8, "Hangul"}, 55 {0x1727, "Hanunoo"}, 56 {0x05a0, "Hebrew"}, 57 {0x3058, "Hiragana"}, 58 {0x10841, "Imperial_Aramaic"}, 59 {0x20e6, "Inherited"}, 60 {0x10b70, "Inscriptional_Pahlavi"}, 61 {0x10b5a, "Inscriptional_Parthian"}, 62 {0xa9d0, "Javanese"}, 63 {0x1109f, "Kaithi"}, 64 {0x0cbd, "Kannada"}, 65 {0x30a6, "Katakana"}, 66 {0xa928, "Kayah_Li"}, 67 {0x10a11, "Kharoshthi"}, 68 {0x17c6, "Khmer"}, 69 {0x0eaa, "Lao"}, 70 {0x1d79, "Latin"}, 71 {0x1c10, "Lepcha"}, 72 {0x1930, "Limbu"}, 73 {0x1003c, "Linear_B"}, 74 {0xa4e1, "Lisu"}, 75 {0x10290, "Lycian"}, 76 {0x10930, "Lydian"}, 77 {0x0d42, "Malayalam"}, 78 {0x0843, "Mandaic"}, 79 {0xabd0, "Meetei_Mayek"}, 80 {0x1099f, "Meroitic_Hieroglyphs"}, 81 {0x109a0, "Meroitic_Cursive"}, 82 {0x16f00, "Miao"}, 83 {0x1822, "Mongolian"}, 84 {0x104c, "Myanmar"}, 85 {0x19c3, "New_Tai_Lue"}, 86 {0x07f8, "Nko"}, 87 {0x169b, "Ogham"}, 88 {0x1c6a, "Ol_Chiki"}, 89 {0x10310, "Old_Italic"}, 90 {0x103c9, "Old_Persian"}, 91 {0x10a6f, "Old_South_Arabian"}, 92 {0x10c20, "Old_Turkic"}, 93 {0x0b3e, "Oriya"}, 94 {0x10491, "Osmanya"}, 95 {0xa860, "Phags_Pa"}, 96 {0x10918, "Phoenician"}, 97 {0xa949, "Rejang"}, 98 {0x16c0, "Runic"}, 99 {0x081d, "Samaritan"}, 100 {0xa892, "Saurashtra"}, 101 {0x111a0, "Sharada"}, 102 {0x10463, "Shavian"}, 103 {0x0dbd, "Sinhala"}, 104 {0x110d0, "Sora_Sompeng"}, 105 {0x1ba3, "Sundanese"}, 106 {0xa803, "Syloti_Nagri"}, 107 {0x070f, "Syriac"}, 108 {0x170f, "Tagalog"}, 109 {0x176f, "Tagbanwa"}, 110 {0x1972, "Tai_Le"}, 111 {0x1a62, "Tai_Tham"}, 112 {0xaadc, "Tai_Viet"}, 113 {0x116c9, "Takri"}, 114 {0x0bbf, "Tamil"}, 115 {0x0c55, "Telugu"}, 116 {0x07a7, "Thaana"}, 117 {0x0e46, "Thai"}, 118 {0x0f36, "Tibetan"}, 119 {0x2d55, "Tifinagh"}, 120 {0x10388, "Ugaritic"}, 121 {0xa60e, "Vai"}, 122 {0xa216, "Yi"}, 123 } 124 125 var outTest = []T{ // not really worth being thorough 126 {0x20, "Telugu"}, 127 } 128 129 var inCategoryTest = []T{ 130 {0x0081, "Cc"}, 131 {0x200B, "Cf"}, 132 {0xf0000, "Co"}, 133 {0xdb80, "Cs"}, 134 {0x0236, "Ll"}, 135 {0x1d9d, "Lm"}, 136 {0x07cf, "Lo"}, 137 {0x1f8a, "Lt"}, 138 {0x03ff, "Lu"}, 139 {0x0bc1, "Mc"}, 140 {0x20df, "Me"}, 141 {0x07f0, "Mn"}, 142 {0x1bb2, "Nd"}, 143 {0x10147, "Nl"}, 144 {0x2478, "No"}, 145 {0xfe33, "Pc"}, 146 {0x2011, "Pd"}, 147 {0x301e, "Pe"}, 148 {0x2e03, "Pf"}, 149 {0x2e02, "Pi"}, 150 {0x0022, "Po"}, 151 {0x2770, "Ps"}, 152 {0x00a4, "Sc"}, 153 {0xa711, "Sk"}, 154 {0x25f9, "Sm"}, 155 {0x2108, "So"}, 156 {0x2028, "Zl"}, 157 {0x2029, "Zp"}, 158 {0x202f, "Zs"}, 159 // Unifieds. 160 {0x04aa, "L"}, 161 {0x0009, "C"}, 162 {0x1712, "M"}, 163 {0x0031, "N"}, 164 {0x00bb, "P"}, 165 {0x00a2, "S"}, 166 {0x00a0, "Z"}, 167 } 168 169 var inPropTest = []T{ 170 {0x0046, "ASCII_Hex_Digit"}, 171 {0x200F, "Bidi_Control"}, 172 {0x2212, "Dash"}, 173 {0xE0001, "Deprecated"}, 174 {0x00B7, "Diacritic"}, 175 {0x30FE, "Extender"}, 176 {0xFF46, "Hex_Digit"}, 177 {0x2E17, "Hyphen"}, 178 {0x2FFB, "IDS_Binary_Operator"}, 179 {0x2FF3, "IDS_Trinary_Operator"}, 180 {0xFA6A, "Ideographic"}, 181 {0x200D, "Join_Control"}, 182 {0x0EC4, "Logical_Order_Exception"}, 183 {0x2FFFF, "Noncharacter_Code_Point"}, 184 {0x065E, "Other_Alphabetic"}, 185 {0x2065, "Other_Default_Ignorable_Code_Point"}, 186 {0x0BD7, "Other_Grapheme_Extend"}, 187 {0x0387, "Other_ID_Continue"}, 188 {0x212E, "Other_ID_Start"}, 189 {0x2094, "Other_Lowercase"}, 190 {0x2040, "Other_Math"}, 191 {0x216F, "Other_Uppercase"}, 192 {0x0027, "Pattern_Syntax"}, 193 {0x0020, "Pattern_White_Space"}, 194 {0x300D, "Quotation_Mark"}, 195 {0x2EF3, "Radical"}, 196 {0x061F, "STerm"}, 197 {0x2071, "Soft_Dotted"}, 198 {0x003A, "Terminal_Punctuation"}, 199 {0x9FC3, "Unified_Ideograph"}, 200 {0xFE0F, "Variation_Selector"}, 201 {0x0020, "White_Space"}, 202 } 203 204 func TestScripts(t *testing.T) { 205 notTested := make(map[string]bool) 206 for k := range Scripts { 207 notTested[k] = true 208 } 209 for _, test := range inTest { 210 if _, ok := Scripts[test.script]; !ok { 211 t.Fatal(test.script, "not a known script") 212 } 213 if !Is(Scripts[test.script], test.rune) { 214 t.Errorf("IsScript(%U, %s) = false, want true", test.rune, test.script) 215 } 216 delete(notTested, test.script) 217 } 218 for _, test := range outTest { 219 if Is(Scripts[test.script], test.rune) { 220 t.Errorf("IsScript(%U, %s) = true, want false", test.rune, test.script) 221 } 222 } 223 for k := range notTested { 224 t.Error("script not tested:", k) 225 } 226 } 227 228 func TestCategories(t *testing.T) { 229 notTested := make(map[string]bool) 230 for k := range Categories { 231 notTested[k] = true 232 } 233 for _, test := range inCategoryTest { 234 if _, ok := Categories[test.script]; !ok { 235 t.Fatal(test.script, "not a known category") 236 } 237 if !Is(Categories[test.script], test.rune) { 238 t.Errorf("IsCategory(%U, %s) = false, want true", test.rune, test.script) 239 } 240 delete(notTested, test.script) 241 } 242 for k := range notTested { 243 t.Error("category not tested:", k) 244 } 245 } 246 247 func TestProperties(t *testing.T) { 248 notTested := make(map[string]bool) 249 for k := range Properties { 250 notTested[k] = true 251 } 252 for _, test := range inPropTest { 253 if _, ok := Properties[test.script]; !ok { 254 t.Fatal(test.script, "not a known prop") 255 } 256 if !Is(Properties[test.script], test.rune) { 257 t.Errorf("IsCategory(%U, %s) = false, want true", test.rune, test.script) 258 } 259 delete(notTested, test.script) 260 } 261 for k := range notTested { 262 t.Error("property not tested:", k) 263 } 264 }