blob: 551c42a24eec82eebacc3f4e2cc0868ad588b266 [file] [log] [blame]
Rob Pike4cbfcae2009-03-10 16:30:27 -07001// 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
Rob Pike149e3d32009-08-31 13:01:25 -07005package unicode_test
Rob Pike4cbfcae2009-03-10 16:30:27 -07006
Rob Pike149e3d32009-08-31 13:01:25 -07007import (
Robert Griesemer45ca9f72009-12-15 15:41:46 -08008 "testing"
9 . "unicode"
Rob Pike149e3d32009-08-31 13:01:25 -070010)
Rob Pike4cbfcae2009-03-10 16:30:27 -070011
Russ Cox7630a102011-10-25 22:23:15 -070012var testDigit = []rune{
Rob Pike94e69152009-08-27 09:14:32 -070013 0x0030,
14 0x0039,
15 0x0661,
16 0x06F1,
17 0x07C9,
18 0x0966,
19 0x09EF,
20 0x0A66,
21 0x0AEF,
22 0x0B66,
23 0x0B6F,
24 0x0BE6,
25 0x0BEF,
26 0x0C66,
27 0x0CEF,
28 0x0D66,
29 0x0D6F,
30 0x0E50,
31 0x0E59,
32 0x0ED0,
33 0x0ED9,
34 0x0F20,
35 0x0F29,
36 0x1040,
37 0x1049,
38 0x1090,
39 0x1091,
40 0x1099,
41 0x17E0,
42 0x17E9,
43 0x1810,
44 0x1819,
45 0x1946,
46 0x194F,
47 0x19D0,
48 0x19D9,
49 0x1B50,
50 0x1B59,
51 0x1BB0,
52 0x1BB9,
53 0x1C40,
54 0x1C49,
55 0x1C50,
56 0x1C59,
57 0xA620,
58 0xA629,
59 0xA8D0,
60 0xA8D9,
61 0xA900,
62 0xA909,
63 0xAA50,
64 0xAA59,
65 0xFF10,
66 0xFF19,
67 0x104A1,
68 0x1D7CE,
Rob Pike4cbfcae2009-03-10 16:30:27 -070069}
70
Russ Cox7630a102011-10-25 22:23:15 -070071var testLetter = []rune{
Rob Pike94e69152009-08-27 09:14:32 -070072 0x0041,
73 0x0061,
74 0x00AA,
75 0x00BA,
76 0x00C8,
77 0x00DB,
78 0x00F9,
79 0x02EC,
80 0x0535,
81 0x06E6,
82 0x093D,
83 0x0A15,
84 0x0B99,
85 0x0DC0,
86 0x0EDD,
Rob Pike4cbfcae2009-03-10 16:30:27 -070087 0x1000,
88 0x1200,
89 0x1312,
90 0x1401,
91 0x1885,
Rob Pike94e69152009-08-27 09:14:32 -070092 0x2C00,
93 0xA800,
94 0xF900,
95 0xFA30,
96 0xFFDA,
97 0xFFDC,
Rob Pike4cbfcae2009-03-10 16:30:27 -070098 0x10000,
99 0x10300,
100 0x10400,
101 0x20000,
Rob Pike94e69152009-08-27 09:14:32 -0700102 0x2F800,
103 0x2FA1D,
Rob Pike4cbfcae2009-03-10 16:30:27 -0700104}
105
Rob Pike24dfb742009-08-26 16:53:07 -0700106func TestDigit(t *testing.T) {
Russ Coxca6a0fe2009-09-15 09:41:59 -0700107 for _, r := range testDigit {
Rob Pike24dfb742009-08-26 16:53:07 -0700108 if !IsDigit(r) {
Rob Pike1959c3a2010-09-23 13:48:56 +1000109 t.Errorf("IsDigit(U+%04X) = false, want true", r)
Rob Pike4cbfcae2009-03-10 16:30:27 -0700110 }
111 }
Russ Coxca6a0fe2009-09-15 09:41:59 -0700112 for _, r := range testLetter {
Rob Pike24dfb742009-08-26 16:53:07 -0700113 if IsDigit(r) {
Rob Pike1959c3a2010-09-23 13:48:56 +1000114 t.Errorf("IsDigit(U+%04X) = true, want false", r)
Rob Pike4cbfcae2009-03-10 16:30:27 -0700115 }
116 }
117}
Rob Pike932def92009-08-31 21:18:40 -0700118
119// Test that the special case in IsDigit agrees with the table
120func TestDigitOptimization(t *testing.T) {
Russ Cox7630a102011-10-25 22:23:15 -0700121 for i := rune(0); i <= MaxLatin1; i++ {
Rob Pike932def92009-08-31 21:18:40 -0700122 if Is(Digit, i) != IsDigit(i) {
Robert Griesemer40621d52009-11-09 12:07:39 -0800123 t.Errorf("IsDigit(U+%04X) disagrees with Is(Digit)", i)
Rob Pike932def92009-08-31 21:18:40 -0700124 }
125 }
126}