]> Cypherpunks repositories - gostls13.git/commitdiff
test that ASCII optimizations agree with the unicode tables
authorRob Pike <r@golang.org>
Tue, 1 Sep 2009 04:18:40 +0000 (21:18 -0700)
committerRob Pike <r@golang.org>
Tue, 1 Sep 2009 04:18:40 +0000 (21:18 -0700)
R=rsc
DELTA=40  (40 added, 0 deleted, 0 changed)
OCL=34168
CL=34176

src/pkg/unicode/digit_test.go
src/pkg/unicode/letter_test.go

index a63404ebd800ec14cf77412d0a0581aca751af21..a95051f3e61709fac4086dab0e91c11c22b0fa69 100644 (file)
@@ -115,3 +115,12 @@ func TestDigit(t *testing.T) {
                }
        }
 }
+
+// Test that the special case in IsDigit agrees with the table
+func TestDigitOptimization(t *testing.T) {
+       for i := 0; i < 0x100; i++ {
+               if Is(Digit, i) != IsDigit(i) {
+                       t.Errorf("IsDigit(U+%04X) disagrees with Is(Digit)", i)
+               }
+       }
+}
index f5cb72f7f8b3b708b290675ec1a7769373a6dd36..b62335456ef12fa3fa6f6892c1127d0e1ac88071 100644 (file)
@@ -318,3 +318,34 @@ func TestIsSpace(t *testing.T) {
                }
        }
 }
+
+// Check that the optimizations for IsLetter etc. agree with the tables.
+// We only need to check the Latin-1 range.
+func TestLetterOptimizations(t *testing.T) {
+       for i := 0; i < 0x100; i++ {
+               if Is(Letter, i) != IsLetter(i) {
+                       t.Errorf("IsLetter(U+%04X) disagrees with Is(Letter)", i)
+               }
+               if Is(Upper, i) != IsUpper(i) {
+                       t.Errorf("IsUpper(U+%04X) disagrees with Is(Upper)", i)
+               }
+               if Is(Lower, i) != IsLower(i) {
+                       t.Errorf("IsLower(U+%04X) disagrees with Is(Lower)", i)
+               }
+               if Is(Title, i) != IsTitle(i) {
+                       t.Errorf("IsTitle(U+%04X) disagrees with Is(Title)", i)
+               }
+               if Is(White_Space, i) != IsSpace(i) {
+                       t.Errorf("IsSpace(U+%04X) disagrees with Is(White_Space)", i)
+               }
+               if To(UpperCase, i) != ToUpper(i) {
+                       t.Errorf("ToUpper(U+%04X) disagrees with To(Upper)", i)
+               }
+               if To(LowerCase, i) != ToLower(i) {
+                       t.Errorf("ToLower(U+%04X) disagrees with To(Lower)", i)
+               }
+               if To(TitleCase, i) != ToTitle(i) {
+                       t.Errorf("ToTitle(U+%04X) disagrees with To(Title)", i)
+               }
+       }
+}