Skip to content

Commit

Permalink
Augment tests to cover new functions better
Browse files Browse the repository at this point in the history
  • Loading branch information
vsachs committed Aug 1, 2022
1 parent b53ab63 commit 10d85f1
Showing 1 changed file with 29 additions and 2 deletions.
31 changes: 29 additions & 2 deletions argparse_test.go
Expand Up @@ -2797,9 +2797,9 @@ func TestCommandPositionalErr(t *testing.T) {
func TestCommandPositionals(t *testing.T) {
testArgs1 := []string{"posint", "5", "abc", "1.0"}
parser := NewParser("posint", "")
intval := parser.IntPositional(nil)
intval := parser.IntPositional(&Options{Required: false})
strval := parser.StringPositional(nil)
floatval := parser.FloatPositional(nil)
floatval := parser.FloatPositional(&Options{Default: 1.5})

if err := parser.Parse(testArgs1); err != nil {
t.Error(err.Error())
Expand All @@ -2826,6 +2826,20 @@ func TestCommandPositionalsErr(t *testing.T) {
}
}

// Just test we don't panic on add
// Actual I/O during unit tests already covered by TestFileSimple1
func TestFilePositional(t *testing.T) {
parser := NewParser("pos", "")
t1 := parser.FilePositional(os.O_RDWR, 0666, nil)
t2 := parser.FilePositional(os.O_RDWR, 0666, &Options{Help: "beep!"})

if t1 == nil {
t.Error("File pos was nil")
} else if t2 == nil {
t.Error("File pos was nil")
}
}

func TestPos1(t *testing.T) {
testArgs1 := []string{"pos", "subcommand1", "-i", "2", "abc"}
parser := NewParser("pos", "")
Expand Down Expand Up @@ -2929,6 +2943,19 @@ func TestPos6(t *testing.T) {
}
}

func TestPos7(t *testing.T) {
testArgs1 := []string{"pos", "beep"}
parser := NewParser("pos", "")

strval := parser.SelectorPositional([]string{"beep"}, &Options{Help: "wow"})

if err := parser.Parse(testArgs1); err != nil {
t.Error(err.Error())
} else if *strval != "beep" {
t.Error("Strval did not match expected")
}
}

func TestPosErr1(t *testing.T) {
errArgs1 := []string{"pos", "subcommand1"}
parser := NewParser("pos", "")
Expand Down

0 comments on commit 10d85f1

Please sign in to comment.