2015-08-23 23:57:54 +00:00
|
|
|
package sliceflag
|
2015-08-16 21:34:38 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"flag"
|
|
|
|
"reflect"
|
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
2015-08-23 23:57:54 +00:00
|
|
|
func TestStringFlag_implements(t *testing.T) {
|
2015-08-16 21:34:38 +00:00
|
|
|
var raw interface{}
|
2015-08-23 23:57:54 +00:00
|
|
|
raw = new(StringFlag)
|
2015-08-16 21:34:38 +00:00
|
|
|
if _, ok := raw.(flag.Value); !ok {
|
2015-08-23 23:57:54 +00:00
|
|
|
t.Fatalf("StringFlag should be a Value")
|
2015-08-16 21:34:38 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-08-23 23:57:54 +00:00
|
|
|
func TestStringFlagSet(t *testing.T) {
|
|
|
|
sv := new(StringFlag)
|
2015-08-16 21:34:38 +00:00
|
|
|
err := sv.Set("foo")
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("err: %s", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
err = sv.Set("bar")
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("err: %s", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
expected := []string{"foo", "bar"}
|
|
|
|
if !reflect.DeepEqual([]string(*sv), expected) {
|
|
|
|
t.Fatalf("Bad: %#v", sv)
|
|
|
|
}
|
|
|
|
}
|