github.com/Qualstor/aws-sdk-go-v2@v1.16.16/internal/strings/strings_test.go (about)

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