-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathlist_test.go
99 lines (90 loc) · 1.81 KB
/
list_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
98
99
// Copyright 2013 Google Inc. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package getopt
import "testing"
var listTests = []struct {
where string
in []string
l, list []string
err string
}{
{
loc(),
[]string{},
nil, nil,
"",
},
{
loc(),
[]string{"test", "-l", "one"},
[]string{"one"}, nil,
"",
},
{
loc(),
[]string{"test", "-lone", "-ltwo"},
[]string{"one", "two"}, nil,
"",
},
{
loc(),
[]string{"test", "--list", "one"},
nil, []string{"one"},
"",
},
{
loc(),
[]string{"test", "--list=one", "--list=two"},
nil, []string{"one", "two"},
"",
},
{
loc(),
[]string{"test", "--list=one,two"},
nil, []string{"one", "two"},
"",
},
}
func TestList(t *testing.T) {
for _, tt := range listTests {
reset()
l := List('l')
list := ListLong("list", 0)
parse(tt.in)
if s := checkError(tt.err); s != "" {
t.Errorf("%s: %s", tt.where, s)
}
if badSlice(*l, tt.l) {
t.Errorf("%s: got s = %q, want %q", tt.where, *l, tt.l)
}
if badSlice(*list, tt.list) {
t.Errorf("%s: got s = %q, want %q", tt.where, *list, tt.list)
}
}
}
func TestDefaultList(t *testing.T) {
reset()
list := []string{"d1", "d2", "d3"}
ListVar(&list, 'l')
parse([]string{"test"})
want := []string{"d1", "d2", "d3"}
if badSlice(list, want) {
t.Errorf("got s = %q, want %q", list, want)
}
parse([]string{"test", "-l", "one"})
want = []string{"one"}
if badSlice(list, want) {
t.Errorf("got s = %q, want %q", list, want)
}
parse([]string{"test", "-l", "two"})
want = []string{"one", "two"}
if badSlice(list, want) {
t.Errorf("got s = %q, want %q", list, want)
}
Lookup('l').Reset()
want = []string{"d1", "d2", "d3"}
if badSlice(list, want) {
t.Errorf("got s = %q, want %q", list, want)
}
}