-
Notifications
You must be signed in to change notification settings - Fork 2
/
tag_test.go
56 lines (53 loc) · 957 Bytes
/
tag_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
package fixedwidth
import (
"reflect"
"testing"
)
func Test_tag_getLimitFixedTag(t *testing.T) {
type validFixedTag struct {
Name string `fixed:"10"`
}
var v validFixedTag
type invalidFixedTag struct {
Name string `fixed:"abc"`
}
var i invalidFixedTag
type args struct {
field reflect.StructField
}
tests := []struct {
name string
args args
want int
ok bool
}{
{
name: "success",
args: args{
field: reflect.TypeOf(v).Field(0),
},
want: 10,
ok: true,
},
{
name: "fail",
args: args{
field: reflect.TypeOf(i).Field(0),
},
want: 0,
ok: false,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
ta := tag{}
got, got1 := ta.getLimitFixedTag(tt.args.field)
if got != tt.want {
t.Errorf("getLimitFixedTag() got = %v, want %v", got, tt.want)
}
if got1 != tt.ok {
t.Errorf("getLimitFixedTag() got1 = %v, want %v", got1, tt.ok)
}
})
}
}