-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathcmd_test.go
56 lines (52 loc) · 1.9 KB
/
cmd_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
package main
import (
"slices"
"strings"
"testing"
)
func TestReaderToArgs(t *testing.T) {
var tests = []struct {
input string
want []string
}{
{"", []string{}},
{"# comment\n", []string{}},
{"# comment\nhttp://foo.com\n", []string{"http://foo.com"}},
{"# comment\nhttp://foo.com\nhttp://bar.net\n", []string{"http://foo.com", "http://bar.net"}},
{"# comment\nhttp://foo.com\nhttp://bar.net\n# comment\n", []string{"http://foo.com", "http://bar.net"}},
{"# comment\nhttp://foo.com\nhttp://bar.net\n# comment\nhttp://baz.org\n", []string{"http://foo.com", "http://bar.net", "http://baz.org"}},
{"#comment\nhttp://foo.com\n", []string{"http://foo.com"}},
{" #comment\nhttp://foo.com\n", []string{"http://foo.com"}},
{" # comment\nhttp://foo.com\n", []string{"http://foo.com"}},
{"\n\nhttp://foo.com\n", []string{"http://foo.com"}},
{"\n \nhttp://foo.com\n", []string{"http://foo.com"}},
{"\n \nhttp://foo.com\n", []string{"http://foo.com"}},
{"http://foo.com", []string{"http://foo.com"}},
{"http://foo.com http://baz.org", []string{"http://foo.com", "http://baz.org"}},
{" http://foo.com ", []string{"http://foo.com"}},
{"# http://foo.com ", []string{""}},
{" # http://foo.com ", []string{""}},
{"\n # http://foo.com ", []string{""}},
{"http://foo.com\thttp://baz.org", []string{"http://foo.com", "http://baz.org"}},
{"http://foo.com http://baz.org", []string{"http://foo.com", "http://baz.org"}},
{"http://foo.com http://foo.com", []string{"http://foo.com"}},
}
for _, test := range tests {
t.Run(test.input, func(t *testing.T) {
r := strings.NewReader(test.input)
got, err := readerToArgs(r)
if err != nil {
t.Errorf("readerToArgs() error = %v", err)
return
}
slices.Sort(test.want)
slices.Sort(got)
for i := range got {
if got[i] != test.want[i] {
t.Errorf("readerToArgs() got = %v, want %v", got, test.want)
return
}
}
})
}
}