Skip to content

Commit

Permalink
Merge pull request #69 from pborzenkov/update-go-scalar
Browse files Browse the repository at this point in the history
Update go scalar to the latest version
  • Loading branch information
alexflint authored Nov 20, 2018
2 parents f7c0423 + a6af419 commit fb7d95b
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 22 deletions.
4 changes: 2 additions & 2 deletions Godeps/Godeps.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -288,10 +288,10 @@ func (n *NameDotName) MarshalText() (text []byte, err error) {

func main() {
var args struct {
Name *NameDotName
Name NameDotName
}
// set default
args.Name = &NameDotName{"file", "txt"}
args.Name = NameDotName{"file", "txt"}
arg.MustParse(&args)
fmt.Printf("%#v\n", args.Name)
}
Expand All @@ -305,10 +305,10 @@ Options:
--help, -h display this help and exit

$ ./example
&main.NameDotName{Head:"file", Tail:"txt"}
main.NameDotName{Head:"file", Tail:"txt"}

$ ./example --name=foo.bar
&main.NameDotName{Head:"foo", Tail:"bar"}
main.NameDotName{Head:"foo", Tail:"bar"}

$ ./example --name=oops
Usage: example [--name NAME]
Expand Down
48 changes: 42 additions & 6 deletions parse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -580,7 +580,7 @@ func TestEnvironmentVariableRequired(t *testing.T) {
assert.Equal(t, "bar", args.Foo)
}

func TestEnvironmentVariableSliceArgumentString(t *testing.T) {
func TestEnvironmentVariableSliceArgumentString(t *testing.T) {
var args struct {
Foo []string `arg:"env"`
}
Expand All @@ -589,7 +589,7 @@ func TestEnvironmentVariableSliceArgumentString(t *testing.T) {
assert.Equal(t, []string{"bar", "baz, qux"}, args.Foo)
}

func TestEnvironmentVariableSliceArgumentInteger(t *testing.T) {
func TestEnvironmentVariableSliceArgumentInteger(t *testing.T) {
var args struct {
Foo []int `arg:"env"`
}
Expand All @@ -598,7 +598,7 @@ func TestEnvironmentVariableSliceArgumentInteger(t *testing.T) {
assert.Equal(t, []int{1, 99}, args.Foo)
}

func TestEnvironmentVariableSliceArgumentFloat(t *testing.T) {
func TestEnvironmentVariableSliceArgumentFloat(t *testing.T) {
var args struct {
Foo []float32 `arg:"env"`
}
Expand All @@ -607,7 +607,7 @@ func TestEnvironmentVariableSliceArgumentFloat(t *testing.T) {
assert.Equal(t, []float32{1.1, 99.9}, args.Foo)
}

func TestEnvironmentVariableSliceArgumentBool(t *testing.T) {
func TestEnvironmentVariableSliceArgumentBool(t *testing.T) {
var args struct {
Foo []bool `arg:"env"`
}
Expand All @@ -616,7 +616,7 @@ func TestEnvironmentVariableSliceArgumentBool(t *testing.T) {
assert.Equal(t, []bool{true, false, false, true}, args.Foo)
}

func TestEnvironmentVariableSliceArgumentWrongCsv(t *testing.T) {
func TestEnvironmentVariableSliceArgumentWrongCsv(t *testing.T) {
var args struct {
Foo []int `arg:"env"`
}
Expand All @@ -625,7 +625,7 @@ func TestEnvironmentVariableSliceArgumentWrongCsv(t *testing.T) {
assert.Error(t, err)
}

func TestEnvironmentVariableSliceArgumentWrongType(t *testing.T) {
func TestEnvironmentVariableSliceArgumentWrongType(t *testing.T) {
var args struct {
Foo []bool `arg:"env"`
}
Expand All @@ -644,6 +644,16 @@ func (f *textUnmarshaler) UnmarshalText(b []byte) error {
}

func TestTextUnmarshaler(t *testing.T) {
// fields that implement TextUnmarshaler should be parsed using that interface
var args struct {
Foo textUnmarshaler
}
err := parse("--foo abc", &args)
require.NoError(t, err)
assert.Equal(t, 3, args.Foo.val)
}

func TestPtrToTextUnmarshaler(t *testing.T) {
// fields that implement TextUnmarshaler should be parsed using that interface
var args struct {
Foo *textUnmarshaler
Expand All @@ -654,6 +664,19 @@ func TestTextUnmarshaler(t *testing.T) {
}

func TestRepeatedTextUnmarshaler(t *testing.T) {
// fields that implement TextUnmarshaler should be parsed using that interface
var args struct {
Foo []textUnmarshaler
}
err := parse("--foo abc d ef", &args)
require.NoError(t, err)
require.Len(t, args.Foo, 3)
assert.Equal(t, 3, args.Foo[0].val)
assert.Equal(t, 1, args.Foo[1].val)
assert.Equal(t, 2, args.Foo[2].val)
}

func TestRepeatedPtrToTextUnmarshaler(t *testing.T) {
// fields that implement TextUnmarshaler should be parsed using that interface
var args struct {
Foo []*textUnmarshaler
Expand All @@ -667,6 +690,19 @@ func TestRepeatedTextUnmarshaler(t *testing.T) {
}

func TestPositionalTextUnmarshaler(t *testing.T) {
// fields that implement TextUnmarshaler should be parsed using that interface
var args struct {
Foo []textUnmarshaler `arg:"positional"`
}
err := parse("abc d ef", &args)
require.NoError(t, err)
require.Len(t, args.Foo, 3)
assert.Equal(t, 3, args.Foo[0].val)
assert.Equal(t, 1, args.Foo[1].val)
assert.Equal(t, 2, args.Foo[2].val)
}

func TestPositionalPtrToTextUnmarshaler(t *testing.T) {
// fields that implement TextUnmarshaler should be parsed using that interface
var args struct {
Foo []*textUnmarshaler `arg:"positional"`
Expand Down
19 changes: 9 additions & 10 deletions vendor/github.com/alexflint/go-scalar/scalar.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit fb7d95b

Please sign in to comment.