OSDN Git Service

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