github.com/vidu171/dell-ecs-s3-client@v0.0.0-20210418120815-4ce80f55ccac/internal/strings/strings_test.go (about)

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