OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-dev/] [or1k-gcc/] [libgo/] [go/] [unicode/] [letter_test.go] - Blame information for rev 833

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 747 jeremybenn
// 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
var upperTest = []rune{
13
        0x41,
14
        0xc0,
15
        0xd8,
16
        0x100,
17
        0x139,
18
        0x14a,
19
        0x178,
20
        0x181,
21
        0x376,
22
        0x3cf,
23
        0x1f2a,
24
        0x2102,
25
        0x2c00,
26
        0x2c10,
27
        0x2c20,
28
        0xa650,
29
        0xa722,
30
        0xff3a,
31
        0x10400,
32
        0x1d400,
33
        0x1d7ca,
34
}
35
 
36
var notupperTest = []rune{
37
        0x40,
38
        0x5b,
39
        0x61,
40
        0x185,
41
        0x1b0,
42
        0x377,
43
        0x387,
44
        0x2150,
45
        0xffff,
46
        0x10000,
47
}
48
 
49
var letterTest = []rune{
50
        0x41,
51
        0x61,
52
        0xaa,
53
        0xba,
54
        0xc8,
55
        0xdb,
56
        0xf9,
57
        0x2ec,
58
        0x535,
59
        0x620,
60
        0x6e6,
61
        0x93d,
62
        0xa15,
63
        0xb99,
64
        0xdc0,
65
        0xedd,
66
        0x1000,
67
        0x1200,
68
        0x1312,
69
        0x1401,
70
        0x1885,
71
        0x2c00,
72
        0xa800,
73
        0xf900,
74
        0xfa30,
75
        0xffda,
76
        0xffdc,
77
        0x10000,
78
        0x10300,
79
        0x10400,
80
        0x20000,
81
        0x2f800,
82
        0x2fa1d,
83
}
84
 
85
var notletterTest = []rune{
86
        0x20,
87
        0x35,
88
        0x375,
89
        0x619,
90
        0x700,
91
        0xfffe,
92
        0x1ffff,
93
        0x10ffff,
94
}
95
 
96
// Contains all the special cased Latin-1 chars.
97
var spaceTest = []rune{
98
        0x09,
99
        0x0a,
100
        0x0b,
101
        0x0c,
102
        0x0d,
103
        0x20,
104
        0x85,
105
        0xA0,
106
        0x2000,
107
        0x3000,
108
}
109
 
110
type caseT struct {
111
        cas     int
112
        in, out rune
113
}
114
 
115
var caseTest = []caseT{
116
        // errors
117
        {-1, '\n', 0xFFFD},
118
        {UpperCase, -1, -1},
119
        {UpperCase, 1 << 30, 1 << 30},
120
 
121
        // ASCII (special-cased so test carefully)
122
        {UpperCase, '\n', '\n'},
123
        {UpperCase, 'a', 'A'},
124
        {UpperCase, 'A', 'A'},
125
        {UpperCase, '7', '7'},
126
        {LowerCase, '\n', '\n'},
127
        {LowerCase, 'a', 'a'},
128
        {LowerCase, 'A', 'a'},
129
        {LowerCase, '7', '7'},
130
        {TitleCase, '\n', '\n'},
131
        {TitleCase, 'a', 'A'},
132
        {TitleCase, 'A', 'A'},
133
        {TitleCase, '7', '7'},
134
 
135
        // Latin-1: easy to read the tests!
136
        {UpperCase, 0x80, 0x80},
137
        {UpperCase, 'Å', 'Å'},
138
        {UpperCase, 'å', 'Å'},
139
        {LowerCase, 0x80, 0x80},
140
        {LowerCase, 'Å', 'å'},
141
        {LowerCase, 'å', 'å'},
142
        {TitleCase, 0x80, 0x80},
143
        {TitleCase, 'Å', 'Å'},
144
        {TitleCase, 'å', 'Å'},
145
 
146
        // 0131;LATIN SMALL LETTER DOTLESS I;Ll;0;L;;;;;N;;;0049;;0049
147
        {UpperCase, 0x0131, 'I'},
148
        {LowerCase, 0x0131, 0x0131},
149
        {TitleCase, 0x0131, 'I'},
150
 
151
        // 0133;LATIN SMALL LIGATURE IJ;Ll;0;L; 0069 006A;;;;N;LATIN SMALL LETTER I J;;0132;;0132
152
        {UpperCase, 0x0133, 0x0132},
153
        {LowerCase, 0x0133, 0x0133},
154
        {TitleCase, 0x0133, 0x0132},
155
 
156
        // 212A;KELVIN SIGN;Lu;0;L;004B;;;;N;DEGREES KELVIN;;;006B;
157
        {UpperCase, 0x212A, 0x212A},
158
        {LowerCase, 0x212A, 'k'},
159
        {TitleCase, 0x212A, 0x212A},
160
 
161
        // From an UpperLower sequence
162
        // A640;CYRILLIC CAPITAL LETTER ZEMLYA;Lu;0;L;;;;;N;;;;A641;
163
        {UpperCase, 0xA640, 0xA640},
164
        {LowerCase, 0xA640, 0xA641},
165
        {TitleCase, 0xA640, 0xA640},
166
        // A641;CYRILLIC SMALL LETTER ZEMLYA;Ll;0;L;;;;;N;;;A640;;A640
167
        {UpperCase, 0xA641, 0xA640},
168
        {LowerCase, 0xA641, 0xA641},
169
        {TitleCase, 0xA641, 0xA640},
170
        // A64E;CYRILLIC CAPITAL LETTER NEUTRAL YER;Lu;0;L;;;;;N;;;;A64F;
171
        {UpperCase, 0xA64E, 0xA64E},
172
        {LowerCase, 0xA64E, 0xA64F},
173
        {TitleCase, 0xA64E, 0xA64E},
174
        // A65F;CYRILLIC SMALL LETTER YN;Ll;0;L;;;;;N;;;A65E;;A65E
175
        {UpperCase, 0xA65F, 0xA65E},
176
        {LowerCase, 0xA65F, 0xA65F},
177
        {TitleCase, 0xA65F, 0xA65E},
178
 
179
        // From another UpperLower sequence
180
        // 0139;LATIN CAPITAL LETTER L WITH ACUTE;Lu;0;L;004C 0301;;;;N;LATIN CAPITAL LETTER L ACUTE;;;013A;
181
        {UpperCase, 0x0139, 0x0139},
182
        {LowerCase, 0x0139, 0x013A},
183
        {TitleCase, 0x0139, 0x0139},
184
        // 013F;LATIN CAPITAL LETTER L WITH MIDDLE DOT;Lu;0;L; 004C 00B7;;;;N;;;;0140;
185
        {UpperCase, 0x013f, 0x013f},
186
        {LowerCase, 0x013f, 0x0140},
187
        {TitleCase, 0x013f, 0x013f},
188
        // 0148;LATIN SMALL LETTER N WITH CARON;Ll;0;L;006E 030C;;;;N;LATIN SMALL LETTER N HACEK;;0147;;0147
189
        {UpperCase, 0x0148, 0x0147},
190
        {LowerCase, 0x0148, 0x0148},
191
        {TitleCase, 0x0148, 0x0147},
192
 
193
        // Last block in the 5.1.0 table
194
        // 10400;DESERET CAPITAL LETTER LONG I;Lu;0;L;;;;;N;;;;10428;
195
        {UpperCase, 0x10400, 0x10400},
196
        {LowerCase, 0x10400, 0x10428},
197
        {TitleCase, 0x10400, 0x10400},
198
        // 10427;DESERET CAPITAL LETTER EW;Lu;0;L;;;;;N;;;;1044F;
199
        {UpperCase, 0x10427, 0x10427},
200
        {LowerCase, 0x10427, 0x1044F},
201
        {TitleCase, 0x10427, 0x10427},
202
        // 10428;DESERET SMALL LETTER LONG I;Ll;0;L;;;;;N;;;10400;;10400
203
        {UpperCase, 0x10428, 0x10400},
204
        {LowerCase, 0x10428, 0x10428},
205
        {TitleCase, 0x10428, 0x10400},
206
        // 1044F;DESERET SMALL LETTER EW;Ll;0;L;;;;;N;;;10427;;10427
207
        {UpperCase, 0x1044F, 0x10427},
208
        {LowerCase, 0x1044F, 0x1044F},
209
        {TitleCase, 0x1044F, 0x10427},
210
 
211
        // First one not in the 5.1.0 table
212
        // 10450;SHAVIAN LETTER PEEP;Lo;0;L;;;;;N;;;;;
213
        {UpperCase, 0x10450, 0x10450},
214
        {LowerCase, 0x10450, 0x10450},
215
        {TitleCase, 0x10450, 0x10450},
216
 
217
        // Non-letters with case.
218
        {LowerCase, 0x2161, 0x2171},
219
        {UpperCase, 0x0345, 0x0399},
220
}
221
 
222
func TestIsLetter(t *testing.T) {
223
        for _, r := range upperTest {
224
                if !IsLetter(r) {
225
                        t.Errorf("IsLetter(U+%04X) = false, want true", r)
226
                }
227
        }
228
        for _, r := range letterTest {
229
                if !IsLetter(r) {
230
                        t.Errorf("IsLetter(U+%04X) = false, want true", r)
231
                }
232
        }
233
        for _, r := range notletterTest {
234
                if IsLetter(r) {
235
                        t.Errorf("IsLetter(U+%04X) = true, want false", r)
236
                }
237
        }
238
}
239
 
240
func TestIsUpper(t *testing.T) {
241
        for _, r := range upperTest {
242
                if !IsUpper(r) {
243
                        t.Errorf("IsUpper(U+%04X) = false, want true", r)
244
                }
245
        }
246
        for _, r := range notupperTest {
247
                if IsUpper(r) {
248
                        t.Errorf("IsUpper(U+%04X) = true, want false", r)
249
                }
250
        }
251
        for _, r := range notletterTest {
252
                if IsUpper(r) {
253
                        t.Errorf("IsUpper(U+%04X) = true, want false", r)
254
                }
255
        }
256
}
257
 
258
func caseString(c int) string {
259
        switch c {
260
        case UpperCase:
261
                return "UpperCase"
262
        case LowerCase:
263
                return "LowerCase"
264
        case TitleCase:
265
                return "TitleCase"
266
        }
267
        return "ErrorCase"
268
}
269
 
270
func TestTo(t *testing.T) {
271
        for _, c := range caseTest {
272
                r := To(c.cas, c.in)
273
                if c.out != r {
274
                        t.Errorf("To(U+%04X, %s) = U+%04X want U+%04X", c.in, caseString(c.cas), r, c.out)
275
                }
276
        }
277
}
278
 
279
func TestToUpperCase(t *testing.T) {
280
        for _, c := range caseTest {
281
                if c.cas != UpperCase {
282
                        continue
283
                }
284
                r := ToUpper(c.in)
285
                if c.out != r {
286
                        t.Errorf("ToUpper(U+%04X) = U+%04X want U+%04X", c.in, r, c.out)
287
                }
288
        }
289
}
290
 
291
func TestToLowerCase(t *testing.T) {
292
        for _, c := range caseTest {
293
                if c.cas != LowerCase {
294
                        continue
295
                }
296
                r := ToLower(c.in)
297
                if c.out != r {
298
                        t.Errorf("ToLower(U+%04X) = U+%04X want U+%04X", c.in, r, c.out)
299
                }
300
        }
301
}
302
 
303
func TestToTitleCase(t *testing.T) {
304
        for _, c := range caseTest {
305
                if c.cas != TitleCase {
306
                        continue
307
                }
308
                r := ToTitle(c.in)
309
                if c.out != r {
310
                        t.Errorf("ToTitle(U+%04X) = U+%04X want U+%04X", c.in, r, c.out)
311
                }
312
        }
313
}
314
 
315
func TestIsSpace(t *testing.T) {
316
        for _, c := range spaceTest {
317
                if !IsSpace(c) {
318
                        t.Errorf("IsSpace(U+%04X) = false; want true", c)
319
                }
320
        }
321
        for _, c := range letterTest {
322
                if IsSpace(c) {
323
                        t.Errorf("IsSpace(U+%04X) = true; want false", c)
324
                }
325
        }
326
}
327
 
328
// Check that the optimizations for IsLetter etc. agree with the tables.
329
// We only need to check the Latin-1 range.
330
func TestLetterOptimizations(t *testing.T) {
331
        for i := rune(0); i <= MaxLatin1; i++ {
332
                if Is(Letter, i) != IsLetter(i) {
333
                        t.Errorf("IsLetter(U+%04X) disagrees with Is(Letter)", i)
334
                }
335
                if Is(Upper, i) != IsUpper(i) {
336
                        t.Errorf("IsUpper(U+%04X) disagrees with Is(Upper)", i)
337
                }
338
                if Is(Lower, i) != IsLower(i) {
339
                        t.Errorf("IsLower(U+%04X) disagrees with Is(Lower)", i)
340
                }
341
                if Is(Title, i) != IsTitle(i) {
342
                        t.Errorf("IsTitle(U+%04X) disagrees with Is(Title)", i)
343
                }
344
                if Is(White_Space, i) != IsSpace(i) {
345
                        t.Errorf("IsSpace(U+%04X) disagrees with Is(White_Space)", i)
346
                }
347
                if To(UpperCase, i) != ToUpper(i) {
348
                        t.Errorf("ToUpper(U+%04X) disagrees with To(Upper)", i)
349
                }
350
                if To(LowerCase, i) != ToLower(i) {
351
                        t.Errorf("ToLower(U+%04X) disagrees with To(Lower)", i)
352
                }
353
                if To(TitleCase, i) != ToTitle(i) {
354
                        t.Errorf("ToTitle(U+%04X) disagrees with To(Title)", i)
355
                }
356
        }
357
}
358
 
359
func TestTurkishCase(t *testing.T) {
360
        lower := []rune("abcçdefgğhıijklmnoöprsştuüvyz")
361
        upper := []rune("ABCÇDEFGĞHIİJKLMNOÖPRSŞTUÜVYZ")
362
        for i, l := range lower {
363
                u := upper[i]
364
                if TurkishCase.ToLower(l) != l {
365
                        t.Errorf("lower(U+%04X) is U+%04X not U+%04X", l, TurkishCase.ToLower(l), l)
366
                }
367
                if TurkishCase.ToUpper(u) != u {
368
                        t.Errorf("upper(U+%04X) is U+%04X not U+%04X", u, TurkishCase.ToUpper(u), u)
369
                }
370
                if TurkishCase.ToUpper(l) != u {
371
                        t.Errorf("upper(U+%04X) is U+%04X not U+%04X", l, TurkishCase.ToUpper(l), u)
372
                }
373
                if TurkishCase.ToLower(u) != l {
374
                        t.Errorf("lower(U+%04X) is U+%04X not U+%04X", u, TurkishCase.ToLower(l), l)
375
                }
376
                if TurkishCase.ToTitle(u) != u {
377
                        t.Errorf("title(U+%04X) is U+%04X not U+%04X", u, TurkishCase.ToTitle(u), u)
378
                }
379
                if TurkishCase.ToTitle(l) != u {
380
                        t.Errorf("title(U+%04X) is U+%04X not U+%04X", l, TurkishCase.ToTitle(l), u)
381
                }
382
        }
383
}
384
 
385
var simpleFoldTests = []string{
386
        // SimpleFold could order its returned slices in any order it wants,
387
        // but we know it orders them in increasing order starting at in
388
        // and looping around from MaxRune to 0.
389
 
390
        // Easy cases.
391
        "Aa",
392
        "aA",
393
        "δΔ",
394
        "Δδ",
395
 
396
        // ASCII special cases.
397
        "KkK",
398
        "kKK",
399
        "KKk",
400
        "Ssſ",
401
        "sſS",
402
        "ſSs",
403
 
404
        // Non-ASCII special cases.
405
        "ρϱΡ",
406
        "ϱΡρ",
407
        "Ρρϱ",
408
        "ͅΙιι",
409
        "Ιιιͅ",
410
        "ιιͅΙ",
411
        "ιͅΙι",
412
 
413
        // Extra special cases: has lower/upper but no case fold.
414
        "İ",
415
        "ı",
416
}
417
 
418
func TestSimpleFold(t *testing.T) {
419
        for _, tt := range simpleFoldTests {
420
                cycle := []rune(tt)
421
                r := cycle[len(cycle)-1]
422
                for _, out := range cycle {
423
                        if r := SimpleFold(r); r != out {
424
                                t.Errorf("SimpleFold(%#U) = %#U, want %#U", r, r, out)
425
                        }
426
                        r = out
427
                }
428
        }
429
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.