github.com/maruel/nin@v0.0.0-20220112143044-f35891e3ce7e/string_piece_util_test.go (about) 1 // Copyright 2017 Google Inc. All Rights Reserved. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package nin 16 17 import ( 18 "testing" 19 20 "github.com/google/go-cmp/cmp" 21 ) 22 23 func TestStringPieceUtilTest_ToLowerASCII(t *testing.T) { 24 data := []struct { 25 in byte 26 want byte 27 }{ 28 {'A', 'a'}, 29 {'Z', 'z'}, 30 {'a', 'a'}, 31 {'z', 'z'}, 32 {'/', '/'}, 33 {'1', '1'}, 34 } 35 for _, l := range data { 36 got := toLowerASCII(l.in) 37 if diff := cmp.Diff(l.want, got); diff != "" { 38 t.Fatalf("mismatch (-want +got):\n%s", diff) 39 } 40 } 41 } 42 43 func TestStringPieceUtilTest_EqualsCaseInsensitiveASCII(t *testing.T) { 44 data := []struct { 45 lhs string 46 rhs string 47 want bool 48 }{ 49 { 50 "abc", 51 "abc", 52 true, 53 }, 54 { 55 "abc", 56 "ABC", 57 true, 58 }, 59 { 60 "abc", 61 "aBc", 62 true, 63 }, 64 { 65 "", 66 "", 67 true, 68 }, 69 { 70 "a", 71 "ac", 72 false, 73 }, 74 { 75 "/", 76 "\\", 77 false, 78 }, 79 { 80 "1", 81 "10", 82 false, 83 }, 84 } 85 for _, l := range data { 86 got := equalsCaseInsensitiveASCII(l.lhs, l.rhs) 87 if diff := cmp.Diff(l.want, got); diff != "" { 88 t.Fatalf("mismatch (-want +got):\n%s", diff) 89 } 90 } 91 }