github.com/primecitizens/pcz/std@v0.2.1/text/ascii/print_test.go (about) 1 // SPDX-License-Identifier: Apache-2.0 2 // Copyright 2023 The Prime Citizens 3 // 4 // Copyright 2021 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 ascii 9 10 import "testing" 11 12 func TestEqualFold(t *testing.T) { 13 var tests = []struct { 14 name string 15 a, b string 16 want bool 17 }{ 18 { 19 name: "empty", 20 want: true, 21 }, 22 { 23 name: "simple match", 24 a: "CHUNKED", 25 b: "chunked", 26 want: true, 27 }, 28 { 29 name: "same string", 30 a: "chunked", 31 b: "chunked", 32 want: true, 33 }, 34 { 35 name: "Unicode Kelvin symbol", 36 a: "chunKed", // This "K" is 'KELVIN SIGN' (\u212A) 37 b: "chunked", 38 want: false, 39 }, 40 } 41 for _, tt := range tests { 42 t.Run(tt.name, func(t *testing.T) { 43 if got := EqualFold(tt.a, tt.b); got != tt.want { 44 t.Errorf("AsciiEqualFold(%q,%q): got %v want %v", tt.a, tt.b, got, tt.want) 45 } 46 }) 47 } 48 } 49 50 func TestIsPrint(t *testing.T) { 51 var tests = []struct { 52 name string 53 in string 54 want bool 55 }{ 56 { 57 name: "empty", 58 want: true, 59 }, 60 { 61 name: "ASCII low", 62 in: "This is a space: ' '", 63 want: true, 64 }, 65 { 66 name: "ASCII high", 67 in: "This is a tilde: '~'", 68 want: true, 69 }, 70 { 71 name: "ASCII low non-print", 72 in: "This is a unit separator: \x1F", 73 want: false, 74 }, 75 { 76 name: "Ascii high non-print", 77 in: "This is a Delete: \x7F", 78 want: false, 79 }, 80 { 81 name: "Unicode letter", 82 in: "Today it's 280K outside: it's freezing!", // This "K" is 'KELVIN SIGN' (\u212A) 83 want: false, 84 }, 85 { 86 name: "Unicode emoji", 87 in: "Gophers like 🧀", 88 want: false, 89 }, 90 } 91 for _, tt := range tests { 92 t.Run(tt.name, func(t *testing.T) { 93 if got := IsPrint(tt.in); got != tt.want { 94 t.Errorf("IsASCIIPrint(%q): got %v want %v", tt.in, got, tt.want) 95 } 96 }) 97 } 98 }