github.com/aws/aws-sdk-go@v1.44.288/internal/strings/strings_test.go (about) 1 //go:build go1.7 2 // +build go1.7 3 4 package strings 5 6 import ( 7 "strings" 8 "testing" 9 ) 10 11 func TestHasPrefixFold(t *testing.T) { 12 type args struct { 13 s string 14 prefix string 15 } 16 tests := map[string]struct { 17 args args 18 want bool 19 }{ 20 "empty strings and prefix": { 21 args: args{ 22 s: "", 23 prefix: "", 24 }, 25 want: true, 26 }, 27 "strings starts with prefix": { 28 args: args{ 29 s: "some string", 30 prefix: "some", 31 }, 32 want: true, 33 }, 34 "prefix longer then string": { 35 args: args{ 36 s: "some", 37 prefix: "some string", 38 }, 39 }, 40 "equal length string and prefix": { 41 args: args{ 42 s: "short string", 43 prefix: "short string", 44 }, 45 want: true, 46 }, 47 "different cases": { 48 args: args{ 49 s: "ShOrT StRING", 50 prefix: "short", 51 }, 52 want: true, 53 }, 54 "empty prefix not empty string": { 55 args: args{ 56 s: "ShOrT StRING", 57 prefix: "", 58 }, 59 want: true, 60 }, 61 "mixed-case prefixes": { 62 args: args{ 63 s: "SoMe String", 64 prefix: "sOme", 65 }, 66 want: true, 67 }, 68 } 69 for name, tt := range tests { 70 t.Run(name, func(t *testing.T) { 71 if got := HasPrefixFold(tt.args.s, tt.args.prefix); got != tt.want { 72 t.Errorf("HasPrefixFold() = %v, want %v", got, tt.want) 73 } 74 }) 75 } 76 } 77 78 func BenchmarkHasPrefixFold(b *testing.B) { 79 HasPrefixFold("SoME string", "sOmE") 80 } 81 82 func BenchmarkHasPrefix(b *testing.B) { 83 strings.HasPrefix(strings.ToLower("SoME string"), strings.ToLower("sOmE")) 84 }