-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathstrmask_test.go
97 lines (95 loc) · 1.67 KB
/
strmask_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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
package strmask
import (
"testing"
)
func TestApply(t *testing.T) {
type args struct {
mask string
value string
}
tests := []struct {
name string
args args
want string
wantErr bool
}{
{
name: "mask-# (any letter or digit)",
args: args{
mask: "####-####-####-####",
value: "qwer TYUI 0123-4567",
},
want: "qwer-TYUI-0123-4567",
},
{
name: "mask-0 (only digit)",
args: args{
mask: "+0 (000) 000-00-00",
value: "A12345678900",
},
want: "+1 (234) 567-89-00",
},
{
name: "mask-L (lower letter or digit)",
args: args{
mask: "LLLL-LLLL",
value: "QWER 1234",
},
want: "qwer-1234",
},
{
name: "mask-l (lower letter)",
args: args{
mask: "llll-llll",
value: "QWER 1234 zxCV",
},
want: "qwer-zxcv",
},
{
name: "mask-U (upper letter or digit)",
args: args{
mask: "UUUU-UUUU",
value: "qwer 1234",
},
want: "QWER-1234",
},
{
name: "mask-u (upper letter)",
args: args{
mask: "uuuu-uuuu",
value: "qwer 1234 ASDV",
},
want: "QWER-ASDV",
},
{
name: "error mask",
args: args{
mask: "uuuu-uuuu",
value: "123345",
},
want: "",
wantErr: true,
},
{
name: "error mask with value",
args: args{
mask: "uuuu-uuuu",
value: "qwer",
},
want: "QWER-",
wantErr: true,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got, err := Apply(tt.args.mask, tt.args.value)
if (err != nil) != tt.wantErr {
t.Errorf("Apply() error = %v, wantErr %v", err, tt.wantErr)
return
}
if got != tt.want {
t.Errorf("Apply() got = %v, want %v", got, tt.want)
}
})
}
}