1
0
Fork 0
mirror of https://github.com/diamondburned/arikawa.git synced 2024-11-16 11:54:29 +00:00
arikawa/utils/bot/extras/arguments/flag_test.go

56 lines
994 B
Go
Raw Normal View History

2020-02-05 04:29:45 +00:00
package arguments
import (
"reflect"
"strings"
"testing"
)
func TestFlagSet(t *testing.T) {
fs := NewFlagSet()
var b bool
fs.BoolVar(&b, "b", false, "Test boolean")
if usage := fs.Usage(); !strings.Contains(usage, "Test boolean") {
t.Fatal("Unexpected usage:", usage)
}
if err := fs.Parse([]string{"-b", "asdasd"}); err != nil {
t.Fatal("Failed to parse:", err)
}
if !b {
t.Fatal("Test boolean is false")
}
}
func TestFlag(t *testing.T) {
f := Flag{}
2020-05-15 01:07:16 +00:00
if err := f.ParseContent([]string{"--now", "1m4s"}); err != nil {
2020-02-05 04:29:45 +00:00
t.Fatal("Failed to parse:", err)
}
if args := f.Args(); !reflect.DeepEqual(args, []string{"--now", "1m4s"}) {
t.Fatal("Unexpected arguments:", args)
}
fs := NewFlagSet()
var now bool
fs.BoolVar(&now, "now", false, "Now")
if err := f.With(fs.FlagSet); err != nil {
t.Fatal("Failed to parse:", err)
}
if !now {
t.Fatal("now is false")
}
if arg := fs.FlagSet.Arg(0); arg != "1m4s" {
t.Fatal("Unexpected argument:", arg)
}
}