Skip to content

Commit

Permalink
style(args_test)
Browse files Browse the repository at this point in the history
  • Loading branch information
umarcor committed Mar 19, 2019
1 parent 8cc6bcf commit 9e2b422
Showing 1 changed file with 61 additions and 91 deletions.
152 changes: 61 additions & 91 deletions args_test.go
Expand Up @@ -5,7 +5,7 @@ import (
"testing"
)

func getCommand(args PositionalArgs, withValid bool) *Command {
func newCommand(args PositionalArgs, withValid bool) *Command {
c := &Command{
Use: "c",
Args: args,
Expand Down Expand Up @@ -54,193 +54,163 @@ func expectError(err error, t *testing.T, ex string) {
// NoArgs

func TestNoArgs(t *testing.T) {
c := getCommand(NoArgs, false)
output, err := executeCommand(c)
expectSuccess(output, err, t)
o, e := executeCommand(newCommand(NoArgs, false))
expectSuccess(o, e, t)
}

func TestNoArgsWithArgs(t *testing.T) {
c := getCommand(NoArgs, false)
_, err := executeCommand(c, "one")
expectError(err, t, "no")
_, e := executeCommand(newCommand(NoArgs, false), "one")
expectError(e, t, "no")
}

func TestNoArgsWithArgsWithValid(t *testing.T) {
c := getCommand(NoArgs, true)
_, err := executeCommand(c, "one")
expectError(err, t, "no")
_, e := executeCommand(newCommand(NoArgs, true), "one")
expectError(e, t, "no")
}

// ArbitraryArgs

func TestArbitraryArgs(t *testing.T) {
c := getCommand(ArbitraryArgs, false)
output, err := executeCommand(c, "a", "b")
expectSuccess(output, err, t)
o, e := executeCommand(newCommand(ArbitraryArgs, false), "a", "b")
expectSuccess(o, e, t)
}

func TestArbitraryArgsWithValid(t *testing.T) {
c := getCommand(ArbitraryArgs, true)
output, err := executeCommand(c, "one", "two")
expectSuccess(output, err, t)
o, e := executeCommand(newCommand(ArbitraryArgs, true), "one", "two")
expectSuccess(o, e, t)
}

func TestArbitraryArgsWithValidWithInvalidArgs(t *testing.T) {
c := getCommand(ArbitraryArgs, true)
_, err := executeCommand(c, "a")
expectError(err, t, "valid")
_, e := executeCommand(newCommand(ArbitraryArgs, true), "a")
expectError(e, t, "valid")
}

// MinimumNArgs

func TestMinimumNArgs(t *testing.T) {
c := getCommand(MinimumNArgs(2), false)
output, err := executeCommand(c, "a", "b", "c")
expectSuccess(output, err, t)
o, e := executeCommand(newCommand(MinimumNArgs(2), false), "a", "b", "c")
expectSuccess(o, e, t)
}

func TestMinimumNArgsWithValid(t *testing.T) {
c := getCommand(MinimumNArgs(2), true)
output, err := executeCommand(c, "one", "three")
expectSuccess(output, err, t)
o, e := executeCommand(newCommand(MinimumNArgs(2), true), "one", "three")
expectSuccess(o, e, t)
}

func TestMinimumNArgsWithValidWithInvalidArgs(t *testing.T) {
c := getCommand(MinimumNArgs(2), true)
_, err := executeCommand(c, "a", "b")
expectError(err, t, "valid")
_, e := executeCommand(newCommand(MinimumNArgs(2), true), "a", "b")
expectError(e, t, "valid")
}

func TestMinimumNArgsWithLessArgs(t *testing.T) {
c := getCommand(MinimumNArgs(2), false)
_, err := executeCommand(c, "a")
expectError(err, t, "min")
_, e := executeCommand(newCommand(MinimumNArgs(2), false), "a")
expectError(e, t, "min")
}

func TestMinimumNArgsWithLessArgsWithValid(t *testing.T) {
c := getCommand(MinimumNArgs(2), true)
_, err := executeCommand(c, "one")
expectError(err, t, "min")
_, e := executeCommand(newCommand(MinimumNArgs(2), true), "one")
expectError(e, t, "min")
}

func TestMinimumNArgsWithLessArgsWithValidWithInvalidArgs(t *testing.T) {
c := getCommand(MinimumNArgs(2), true)
_, err := executeCommand(c, "a")
expectError(err, t, "valid")
_, e := executeCommand(newCommand(MinimumNArgs(2), true), "a")
expectError(e, t, "valid")
}

// MaximumNArgs

func TestMaximumNArgs(t *testing.T) {
c := getCommand(MaximumNArgs(3), false)
output, err := executeCommand(c, "a", "b")
expectSuccess(output, err, t)
o, e := executeCommand(newCommand(MaximumNArgs(3), false), "a", "b")
expectSuccess(o, e, t)
}

func TestMaximumNArgsWithValid(t *testing.T) {
c := getCommand(MaximumNArgs(2), true)
output, err := executeCommand(c, "one", "three")
expectSuccess(output, err, t)
o, e := executeCommand(newCommand(MaximumNArgs(2), true), "one", "three")
expectSuccess(o, e, t)
}

func TestMaximumNArgsWithValidWithInvalidArgs(t *testing.T) {
c := getCommand(MaximumNArgs(2), true)
_, err := executeCommand(c, "a", "b")
expectError(err, t, "valid")
_, e := executeCommand(newCommand(MaximumNArgs(2), true), "a", "b")
expectError(e, t, "valid")
}

func TestMaximumNArgsWithMoreArgs(t *testing.T) {
c := getCommand(MaximumNArgs(2), false)
_, err := executeCommand(c, "a", "b", "c")
expectError(err, t, "max")
_, e := executeCommand(newCommand(MaximumNArgs(2), false), "a", "b", "c")
expectError(e, t, "max")
}

func TestMaximumNArgsWithMoreArgsWithValid(t *testing.T) {
c := getCommand(MaximumNArgs(2), true)
_, err := executeCommand(c, "one", "three", "two")
expectError(err, t, "max")
_, e := executeCommand(newCommand(MaximumNArgs(2), true), "one", "three", "two")
expectError(e, t, "max")
}

func TestMaximumNArgsWithMoreArgsWithValidWithInvalidArgs(t *testing.T) {
c := getCommand(MaximumNArgs(2), true)
_, err := executeCommand(c, "a", "b", "c")
expectError(err, t, "valid")
_, e := executeCommand(newCommand(MaximumNArgs(2), true), "a", "b", "c")
expectError(e, t, "valid")
}

// ExactArgs

func TestExactArgs(t *testing.T) {
c := getCommand(ExactArgs(3), false)
output, err := executeCommand(c, "a", "b", "c")
expectSuccess(output, err, t)
o, e := executeCommand(newCommand(ExactArgs(3), false), "a", "b", "c")
expectSuccess(o, e, t)
}

func TestExactArgsWithValid(t *testing.T) {
c := getCommand(ExactArgs(3), true)
output, err := executeCommand(c, "three", "one", "two")
expectSuccess(output, err, t)
o, e := executeCommand(newCommand(ExactArgs(3), true), "three", "one", "two")
expectSuccess(o, e, t)
}

func TestExactArgsWithValidWithInvalidArgs(t *testing.T) {
c := getCommand(ExactArgs(3), true)
_, err := executeCommand(c, "three", "a", "two")
expectError(err, t, "valid")
_, e := executeCommand(newCommand(ExactArgs(3), true), "three", "a", "two")
expectError(e, t, "valid")
}

func TestExactArgsWithInvalidCount(t *testing.T) {
c := getCommand(ExactArgs(2), false)
_, err := executeCommand(c, "a", "b", "c")
expectError(err, t, "exact")
_, e := executeCommand(newCommand(ExactArgs(2), false), "a", "b", "c")
expectError(e, t, "exact")
}

func TestExactArgsWithInvalidCountWithValid(t *testing.T) {
c := getCommand(ExactArgs(2), true)
_, err := executeCommand(c, "three", "one", "two")
expectError(err, t, "exact")
_, e := executeCommand(newCommand(ExactArgs(2), true), "three", "one", "two")
expectError(e, t, "exact")
}

func TestExactArgsWithInvalidCountWithValidWithInvalidArgs(t *testing.T) {
c := getCommand(ExactArgs(2), true)
_, err := executeCommand(c, "three", "a", "two")
expectError(err, t, "valid")
_, e := executeCommand(newCommand(ExactArgs(2), true), "three", "a", "two")
expectError(e, t, "valid")
}

// RangeArgs

func TestRangeArgs(t *testing.T) {
c := getCommand(RangeArgs(2, 4), false)
output, err := executeCommand(c, "a", "b", "c")
expectSuccess(output, err, t)
o, e := executeCommand(newCommand(RangeArgs(2, 4), false), "a", "b", "c")
expectSuccess(o, e, t)
}

func TestRangeArgsWithValid(t *testing.T) {
c := getCommand(RangeArgs(2, 4), true)
output, err := executeCommand(c, "three", "one", "two")
expectSuccess(output, err, t)
o, e := executeCommand(newCommand(RangeArgs(2, 4), true), "three", "one", "two")
expectSuccess(o, e, t)
}

func TestRangeArgsWithValidWithInvalidArgs(t *testing.T) {
c := getCommand(RangeArgs(2, 4), true)
_, err := executeCommand(c, "three", "a", "two")
expectError(err, t, "valid")
_, e := executeCommand(newCommand(RangeArgs(2, 4), true), "three", "a", "two")
expectError(e, t, "valid")
}

func TestRangeArgsWithInvalidCount(t *testing.T) {
c := getCommand(RangeArgs(2, 4), false)
_, err := executeCommand(c, "a")
expectError(err, t, "range")
_, e := executeCommand(newCommand(RangeArgs(2, 4), false), "a")
expectError(e, t, "range")
}

func TestRangeArgsWithInvalidCountWithValid(t *testing.T) {
c := getCommand(RangeArgs(2, 4), true)
_, err := executeCommand(c, "two")
expectError(err, t, "range")
_, e := executeCommand(newCommand(RangeArgs(2, 4), true), "two")
expectError(e, t, "range")
}

func TestRangeArgsWithInvalidCountWithValidWithInvalidArgs(t *testing.T) {
c := getCommand(RangeArgs(2, 4), true)
_, err := executeCommand(c, "a")
expectError(err, t, "valid")
_, e := executeCommand(newCommand(RangeArgs(2, 4), true), "a")
expectError(e, t, "valid")
}

// Takes(No)Args
Expand Down

0 comments on commit 9e2b422

Please sign in to comment.