gitee.com/quant1x/pkg@v0.2.8/gocsv/reflect_test.go (about)

     1  package gocsv
     2  
     3  import "testing"
     4  
     5  func Test_fieldInfo_matchesKey(t *testing.T) {
     6  	type fields struct {
     7  		keys         []string
     8  		omitEmpty    bool
     9  		IndexChain   []int
    10  		defaultValue string
    11  		partial      bool
    12  	}
    13  	type args struct {
    14  		key string
    15  	}
    16  	tests := []struct {
    17  		name   string
    18  		fields fields
    19  		args   args
    20  		want   bool
    21  	}{
    22  		{
    23  			name: "valid value",
    24  			fields: fields{
    25  				keys: []string{"date"},
    26  			},
    27  			args: args{"date"},
    28  			want: true,
    29  		},
    30  		{
    31  			name: "zero width space (U+200B)",
    32  			fields: fields{
    33  				keys: []string{"date"},
    34  			},
    35  			args: args{"\u200Bdate"},
    36  			want: true,
    37  		},
    38  		{
    39  			name: "zero width non-joiner (U+200C)",
    40  			fields: fields{
    41  				keys: []string{"date"},
    42  			},
    43  			args: args{"\u200Cdate"},
    44  			want: true,
    45  		},
    46  		{
    47  			name: "zero width joiner (U+200D)",
    48  			fields: fields{
    49  				keys: []string{"date"},
    50  			},
    51  			args: args{"\u200Ddate"},
    52  			want: true,
    53  		},
    54  		{
    55  			name: "zero width no-break space (U+FEFF)",
    56  			fields: fields{
    57  				keys: []string{"date"},
    58  			},
    59  			args: args{"\uFEFFdate"},
    60  			want: true,
    61  		},
    62  		{
    63  			name: "zero width no-break space (U+FEFF) in the middle of the string",
    64  			fields: fields{
    65  				keys: []string{"date"},
    66  			},
    67  			args: args{"da\uFEFFte"},
    68  			want: true,
    69  		},
    70  		{
    71  			name: "zero width no-break space (U+FEFF) in the end of the string",
    72  			fields: fields{
    73  				keys: []string{"date"},
    74  			},
    75  			args: args{"date\uFEFF"},
    76  			want: true,
    77  		},
    78  	}
    79  	for _, tt := range tests {
    80  		t.Run(tt.name, func(t *testing.T) {
    81  			f := fieldInfo{
    82  				keys:         tt.fields.keys,
    83  				omitEmpty:    tt.fields.omitEmpty,
    84  				IndexChain:   tt.fields.IndexChain,
    85  				defaultValue: tt.fields.defaultValue,
    86  				partial:      tt.fields.partial,
    87  			}
    88  			if got := f.matchesKey(tt.args.key); got != tt.want {
    89  				t.Errorf("matchesKey() = %v, want %v", got, tt.want)
    90  			}
    91  		})
    92  	}
    93  }