blob: c9f289c7f55cb6654b2270152cee2fdf77c1ff06 [file] [log] [blame]
Rob Pike8d64e732011-06-04 07:46:22 +10001// Copyright 2011 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
5package unicode_test
6
7import (
8 "testing"
9 . "unicode"
10)
11
12// Independently check that the special "Is" functions work
13// in the Latin-1 range through the property table.
14
15func TestIsControlLatin1(t *testing.T) {
Russ Cox7630a102011-10-25 22:23:15 -070016 for i := rune(0); i <= MaxLatin1; i++ {
Rob Pike8d64e732011-06-04 07:46:22 +100017 got := IsControl(i)
18 want := false
19 switch {
20 case 0x00 <= i && i <= 0x1F:
21 want = true
22 case 0x7F <= i && i <= 0x9F:
23 want = true
24 }
25 if got != want {
26 t.Errorf("%U incorrect: got %t; want %t", i, got, want)
27 }
28 }
29}
30
31func TestIsLetterLatin1(t *testing.T) {
Russ Cox7630a102011-10-25 22:23:15 -070032 for i := rune(0); i <= MaxLatin1; i++ {
Rob Pike8d64e732011-06-04 07:46:22 +100033 got := IsLetter(i)
34 want := Is(Letter, i)
35 if got != want {
36 t.Errorf("%U incorrect: got %t; want %t", i, got, want)
37 }
38 }
39}
40
41func TestIsUpperLatin1(t *testing.T) {
Russ Cox7630a102011-10-25 22:23:15 -070042 for i := rune(0); i <= MaxLatin1; i++ {
Rob Pike8d64e732011-06-04 07:46:22 +100043 got := IsUpper(i)
44 want := Is(Upper, i)
45 if got != want {
46 t.Errorf("%U incorrect: got %t; want %t", i, got, want)
47 }
48 }
49}
50
51func TestIsLowerLatin1(t *testing.T) {
Russ Cox7630a102011-10-25 22:23:15 -070052 for i := rune(0); i <= MaxLatin1; i++ {
Rob Pike8d64e732011-06-04 07:46:22 +100053 got := IsLower(i)
54 want := Is(Lower, i)
55 if got != want {
56 t.Errorf("%U incorrect: got %t; want %t", i, got, want)
57 }
58 }
59}
60
61func TestNumberLatin1(t *testing.T) {
Russ Cox7630a102011-10-25 22:23:15 -070062 for i := rune(0); i <= MaxLatin1; i++ {
Rob Pike8d64e732011-06-04 07:46:22 +100063 got := IsNumber(i)
64 want := Is(Number, i)
65 if got != want {
66 t.Errorf("%U incorrect: got %t; want %t", i, got, want)
67 }
68 }
69}
70
71func TestIsPrintLatin1(t *testing.T) {
Russ Cox7630a102011-10-25 22:23:15 -070072 for i := rune(0); i <= MaxLatin1; i++ {
Rob Pike8d64e732011-06-04 07:46:22 +100073 got := IsPrint(i)
Rob Pike6a801532013-07-24 10:27:58 +100074 want := In(i, PrintRanges...)
Rob Pike8d64e732011-06-04 07:46:22 +100075 if i == ' ' {
76 want = true
77 }
78 if got != want {
79 t.Errorf("%U incorrect: got %t; want %t", i, got, want)
80 }
81 }
82}
83
84func TestIsGraphicLatin1(t *testing.T) {
Russ Cox7630a102011-10-25 22:23:15 -070085 for i := rune(0); i <= MaxLatin1; i++ {
Rob Pike8d64e732011-06-04 07:46:22 +100086 got := IsGraphic(i)
Rob Pike6a801532013-07-24 10:27:58 +100087 want := In(i, GraphicRanges...)
Rob Pike8d64e732011-06-04 07:46:22 +100088 if got != want {
89 t.Errorf("%U incorrect: got %t; want %t", i, got, want)
90 }
91 }
92}
93
94func TestIsPunctLatin1(t *testing.T) {
Russ Cox7630a102011-10-25 22:23:15 -070095 for i := rune(0); i <= MaxLatin1; i++ {
Rob Pike8d64e732011-06-04 07:46:22 +100096 got := IsPunct(i)
97 want := Is(Punct, i)
98 if got != want {
99 t.Errorf("%U incorrect: got %t; want %t", i, got, want)
100 }
101 }
102}
103
104func TestIsSpaceLatin1(t *testing.T) {
Russ Cox7630a102011-10-25 22:23:15 -0700105 for i := rune(0); i <= MaxLatin1; i++ {
Rob Pike8d64e732011-06-04 07:46:22 +1000106 got := IsSpace(i)
107 want := Is(White_Space, i)
108 if got != want {
109 t.Errorf("%U incorrect: got %t; want %t", i, got, want)
110 }
111 }
112}
113
114func TestIsSymbolLatin1(t *testing.T) {
Russ Cox7630a102011-10-25 22:23:15 -0700115 for i := rune(0); i <= MaxLatin1; i++ {
Rob Pike8d64e732011-06-04 07:46:22 +1000116 got := IsSymbol(i)
117 want := Is(Symbol, i)
118 if got != want {
119 t.Errorf("%U incorrect: got %t; want %t", i, got, want)
120 }
121 }
122}