-
Notifications
You must be signed in to change notification settings - Fork 27
Expand file tree
/
Copy pathparse_args_test.go
More file actions
52 lines (48 loc) · 1.04 KB
/
parse_args_test.go
File metadata and controls
52 lines (48 loc) · 1.04 KB
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
package main
import (
"bytes"
"errors"
"testing"
)
func TestParseArgs(t *testing.T) {
tests := []struct {
args []string
err error
numTimes int
}{
{
args: []string{"-h"},
err: errors.New("flag: help requested"),
numTimes: 0,
},
{
args: []string{"-n", "10"},
err: nil,
numTimes: 10,
},
{
args: []string{"-n", "abc"},
err: errors.New("invalid value \"abc\" for flag -n: parse error"),
numTimes: 0,
},
{
args: []string{"-n", "1", "foo"},
err: errors.New("Positional arguments specified"),
numTimes: 1,
},
}
byteBuf := new(bytes.Buffer)
for _, tc := range tests {
c, err := parseArgs(byteBuf, tc.args)
if tc.err == nil && err != nil {
t.Errorf("Expected nil error, got: %v\n", err)
}
if tc.err != nil && err.Error() != tc.err.Error() {
t.Errorf("Expected error to be: %v, got: %v\n", tc.err, err)
}
if c.numTimes != tc.numTimes {
t.Errorf("Expected numTimes to be: %v, got: %v\n", tc.numTimes, c.numTimes)
}
byteBuf.Reset()
}
}