-
Notifications
You must be signed in to change notification settings - Fork 4
/
url_test.go
62 lines (52 loc) · 1.08 KB
/
url_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
package flagvar_test
import (
"flag"
"net/url"
"reflect"
"testing"
"github.com/sgreben/flagvar"
)
func TestURL(t *testing.T) {
fv := flagvar.URL{}
var fs flag.FlagSet
fs.Var(&fv, "url", "")
err := fs.Parse([]string{"-url", "https://github.com/sgreben/flagvar"})
if err != nil {
t.Fail()
}
uv, _ := url.Parse("https://github.com/sgreben/flagvar")
if !reflect.DeepEqual(fv.Value, uv) {
t.Fail()
}
}
func TestURLFail(t *testing.T) {
fv := flagvar.URL{}
var fs flag.FlagSet
fs.Var(&fv, "url", "")
err := fs.Parse([]string{"-url", ":s[a-"})
if err == nil {
t.Fail()
}
}
func TestURLs(t *testing.T) {
fv := flagvar.URLs{}
var fs flag.FlagSet
fs.Var(&fv, "url", "")
uv, _ := url.Parse("https://github.com/sgreben/flagvar")
err := fs.Parse([]string{"-url", "https://github.com/sgreben/flagvar"})
if err != nil {
t.Fail()
}
if !reflect.DeepEqual(fv.Values, []*url.URL{uv}) {
t.Fail()
}
}
func TestURLsFail(t *testing.T) {
fv := flagvar.URLs{}
var fs flag.FlagSet
fs.Var(&fv, "url", "")
err := fs.Parse([]string{"-url", ":s[a-"})
if err == nil {
t.Fail()
}
}