github.com/primecitizens/pcz/std@v0.2.1/text/unicode/graphic_test.go (about)

     1  // SPDX-License-Identifier: Apache-2.0
     2  // Copyright 2023 The Prime Citizens
     3  //
     4  // Copyright 2011 The Go Authors. All rights reserved.
     5  // Use of this source code is governed by a BSD-style
     6  // license that can be found in the LICENSE file.
     7  
     8  package unicode_test
     9  
    10  import (
    11  	"testing"
    12  	. "unicode"
    13  )
    14  
    15  // Independently check that the special "Is" functions work
    16  // in the Latin-1 range through the property table.
    17  
    18  func TestIsControlLatin1(t *testing.T) {
    19  	for i := rune(0); i <= MaxLatin1; i++ {
    20  		got := IsControl(i)
    21  		want := false
    22  		switch {
    23  		case 0x00 <= i && i <= 0x1F:
    24  			want = true
    25  		case 0x7F <= i && i <= 0x9F:
    26  			want = true
    27  		}
    28  		if got != want {
    29  			t.Errorf("%U incorrect: got %t; want %t", i, got, want)
    30  		}
    31  	}
    32  }
    33  
    34  func TestIsLetterLatin1(t *testing.T) {
    35  	for i := rune(0); i <= MaxLatin1; i++ {
    36  		got := IsLetter(i)
    37  		want := Is(Letter, i)
    38  		if got != want {
    39  			t.Errorf("%U incorrect: got %t; want %t", i, got, want)
    40  		}
    41  	}
    42  }
    43  
    44  func TestIsUpperLatin1(t *testing.T) {
    45  	for i := rune(0); i <= MaxLatin1; i++ {
    46  		got := IsUpper(i)
    47  		want := Is(Upper, i)
    48  		if got != want {
    49  			t.Errorf("%U incorrect: got %t; want %t", i, got, want)
    50  		}
    51  	}
    52  }
    53  
    54  func TestIsLowerLatin1(t *testing.T) {
    55  	for i := rune(0); i <= MaxLatin1; i++ {
    56  		got := IsLower(i)
    57  		want := Is(Lower, i)
    58  		if got != want {
    59  			t.Errorf("%U incorrect: got %t; want %t", i, got, want)
    60  		}
    61  	}
    62  }
    63  
    64  func TestNumberLatin1(t *testing.T) {
    65  	for i := rune(0); i <= MaxLatin1; i++ {
    66  		got := IsNumber(i)
    67  		want := Is(Number, i)
    68  		if got != want {
    69  			t.Errorf("%U incorrect: got %t; want %t", i, got, want)
    70  		}
    71  	}
    72  }
    73  
    74  func TestIsPrintLatin1(t *testing.T) {
    75  	for i := rune(0); i <= MaxLatin1; i++ {
    76  		got := IsPrint(i)
    77  		want := In(i, PrintRanges...)
    78  		if i == ' ' {
    79  			want = true
    80  		}
    81  		if got != want {
    82  			t.Errorf("%U incorrect: got %t; want %t", i, got, want)
    83  		}
    84  	}
    85  }
    86  
    87  func TestIsGraphicLatin1(t *testing.T) {
    88  	for i := rune(0); i <= MaxLatin1; i++ {
    89  		got := IsGraphic(i)
    90  		want := In(i, GraphicRanges...)
    91  		if got != want {
    92  			t.Errorf("%U incorrect: got %t; want %t", i, got, want)
    93  		}
    94  	}
    95  }
    96  
    97  func TestIsPunctLatin1(t *testing.T) {
    98  	for i := rune(0); i <= MaxLatin1; i++ {
    99  		got := IsPunct(i)
   100  		want := Is(Punct, i)
   101  		if got != want {
   102  			t.Errorf("%U incorrect: got %t; want %t", i, got, want)
   103  		}
   104  	}
   105  }
   106  
   107  func TestIsSpaceLatin1(t *testing.T) {
   108  	for i := rune(0); i <= MaxLatin1; i++ {
   109  		got := IsSpace(i)
   110  		want := Is(White_Space, i)
   111  		if got != want {
   112  			t.Errorf("%U incorrect: got %t; want %t", i, got, want)
   113  		}
   114  	}
   115  }
   116  
   117  func TestIsSymbolLatin1(t *testing.T) {
   118  	for i := rune(0); i <= MaxLatin1; i++ {
   119  		got := IsSymbol(i)
   120  		want := Is(Symbol, i)
   121  		if got != want {
   122  			t.Errorf("%U incorrect: got %t; want %t", i, got, want)
   123  		}
   124  	}
   125  }