-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathparse_test.go
40 lines (33 loc) · 867 Bytes
/
parse_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
package args
import (
"testing"
)
func TestParse(t *testing.T) {
expected := []string{"http://example.com"}
parseAndCompare(t, []string{"curlie", "example.com"}, expected)
}
func TestParsePost(t *testing.T) {
expected := []string{"-X", "POST", "http://example.com"}
parseAndCompare(t, []string{"curlie", "post", "example.com"}, expected)
}
func TestParseHead(t *testing.T) {
expected := []string{"-I", "http://example.com"}
parseAndCompare(t, []string{"curlie", "head", "example.com"}, expected)
}
func parseAndCompare(t *testing.T, args, expected []string) {
opts := Parse(args)
if !compareStrings(opts, expected) {
t.Errorf("Expecting %v, but got %v for %v", expected, opts, args)
}
}
func compareStrings(a, b []string) bool {
if len(a) != len(b) {
return false
}
for i, v := range a {
if b[i] != v {
return false
}
}
return true
}