command/flag_test.go

30 lines
546 B
Go
Raw Permalink Normal View History

2024-10-24 07:15:25 +08:00
package command
import (
"testing"
)
func TestParseSingle(t *testing.T) {
type targs struct {
Test string `flag_default:"test" flag_usage:"this is test"`
TestBool bool `flag_short:"b"`
TestInt int
}
sargs := &targs{}
v, _ := NewFVSet(sargs)
v.Usage()
err := Parse([]string{"--test", "test", "--test-bool", "--test-int", "1"}, v)
if err != nil {
t.Error(err)
}
if sargs.Test != "test" {
t.Error("test failed")
}
if !sargs.TestBool {
t.Error("test failed")
}
if sargs.TestInt != 1 {
t.Error("test failed")
}
}