-
Notifications
You must be signed in to change notification settings - Fork 1
/
option_test.go
58 lines (49 loc) · 1.04 KB
/
option_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
package gopass
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestOptions(t *testing.T) {
tests := map[string]struct {
pattern string
optFunc func() Option
}{
"with numbers": {
pattern: `^[0-9]+$`,
optFunc: Numbers,
},
"with lower case": {
pattern: `^[a-z]+$`,
optFunc: LowerCase,
},
"with upper case": {
pattern: `^[A-Z]+$`,
optFunc: UpperCase,
},
"with letters": {
pattern: `^[a-zA-Z]+$`,
optFunc: Letters,
},
"with symbols": {
pattern: `^[[~!@#$%^&*()_+{}|:<>?,./\]]+$`,
optFunc: Symbols,
},
}
for name, tt := range tests {
t.Run(name, func(t *testing.T) {
g := &Generator{}
g.With(tt.optFunc())
assert.Regexp(t, tt.pattern, g.chars.String())
})
}
t.Run("with string", func(t *testing.T) {
g := &Generator{}
g.With(String("abc123!@#"))
assert.Regexp(t, `^[123abc!@#]+$`, g.chars.String())
})
t.Run("with bytes", func(t *testing.T) {
g := &Generator{}
g.With(Bytes([]byte("abc123!@#")))
assert.Regexp(t, `^[123abc!@#]+$`, g.chars.String())
})
}