1
2
3
4
5
6
7
8
9
10
11
12
13
14
15 package flags
16
17 import (
18 "testing"
19 )
20
21 func TestSelectiveStringValue(t *testing.T) {
22 tests := []struct {
23 vals []string
24
25 val string
26 pass bool
27 }{
28
29 {[]string{"abc", "def"}, "abc", true},
30 {[]string{"on", "off", "false"}, "on", true},
31
32
33 {[]string{"abc", "def"}, "ghi", false},
34 {[]string{"on", "off"}, "", false},
35 }
36 for i, tt := range tests {
37 sf := NewSelectiveStringValue(tt.vals...)
38 if sf.v != tt.vals[0] {
39 t.Errorf("#%d: want default val=%v,but got %v", i, tt.vals[0], sf.v)
40 }
41 err := sf.Set(tt.val)
42 if tt.pass != (err == nil) {
43 t.Errorf("#%d: want pass=%t, but got err=%v", i, tt.pass, err)
44 }
45 }
46 }
47
48 func TestSelectiveStringsValue(t *testing.T) {
49 tests := []struct {
50 vals []string
51
52 val string
53 pass bool
54 }{
55 {[]string{"abc", "def"}, "abc", true},
56 {[]string{"abc", "def"}, "abc,def", true},
57 {[]string{"abc", "def"}, "abc, def", false},
58 {[]string{"on", "off", "false"}, "on,false", true},
59 {[]string{"abc", "def"}, "ghi", false},
60 {[]string{"on", "off"}, "", false},
61 {[]string{"a", "b", "c", "d", "e"}, "a,c,e", true},
62 }
63 for i, tt := range tests {
64 sf := NewSelectiveStringsValue(tt.vals...)
65 err := sf.Set(tt.val)
66 if tt.pass != (err == nil) {
67 t.Errorf("#%d: want pass=%t, but got err=%v", i, tt.pass, err)
68 }
69 }
70 }
71
View as plain text