Add more test cases

This commit is contained in:
Evan Fiordeliso 2023-11-12 17:00:01 -05:00
parent a06e83f96a
commit 9456b4097b
1 changed files with 46 additions and 0 deletions

View File

@ -265,3 +265,49 @@ func TestParseSingleDashValue(t *testing.T) {
t.Errorf("Expected fruit to be '-', got: %s", opt.Value())
}
}
func TestParseLongOptionBadValue(t *testing.T) {
opt := opts.Int("fruit", "f", 0, "")
set := opts.Set{opt}
args := []string{"--fruit=five"}
parser := opts.NewParser(args, set, false)
_, err := parser.Parse()
if err == nil {
t.Error("Expected error")
}
}
func TestParseShortOptionWithSpaceBadValue(t *testing.T) {
opt := opts.Int("fruit", "f", 0, "")
set := opts.Set{opt}
args := []string{"-f", "five"}
parser := opts.NewParser(args, set, false)
_, err := parser.Parse()
if err == nil {
t.Error("Expected error")
}
}
func TestParseShortOptionWithoutEqualBadValue(t *testing.T) {
optG := opts.Bool("green", "g", false, "")
optF := opts.Int("fruit", "f", 0, "")
set := opts.Set{optG, optF}
args := []string{"-ffive"}
parser := opts.NewParser(args, set, false)
_, err := parser.Parse()
if err == nil {
t.Error("Expected error")
}
}
func TestParseShortOptionWithEqualBadValue(t *testing.T) {
optG := opts.Bool("green", "g", false, "")
optF := opts.Int("fruit", "f", 0, "")
set := opts.Set{optG, optF}
args := []string{"-f=five"}
parser := opts.NewParser(args, set, false)
_, err := parser.Parse()
if err == nil {
t.Error("Expected error")
}
}