This commit is contained in:
+8
-10
@@ -6,7 +6,7 @@ import (
|
||||
)
|
||||
|
||||
func TestValidateArgsRequiresFullMatch(t *testing.T) {
|
||||
intCmd := NewCommand(func(ctx *MsgContext, db NoData) error { return nil }, "int", NewCommandArg("n").SetValueType(CommandValueIntType).SetRequired())
|
||||
intCmd := NewCommand("int", func(ctx *MsgContext, db NoData) error { return nil }, NewCommandArg("n").SetValueType(CommandValueInt).SetRequired())
|
||||
if err := intCmd.validateArgs([]string{"123"}); err != nil {
|
||||
t.Fatalf("expected valid integer argument, got %v", err)
|
||||
}
|
||||
@@ -14,7 +14,7 @@ func TestValidateArgsRequiresFullMatch(t *testing.T) {
|
||||
t.Fatalf("expected ErrCmdArgRegexpMismatch for partial int match, got %v", err)
|
||||
}
|
||||
|
||||
boolCmd := NewCommand(func(ctx *MsgContext, db NoData) error { return nil }, "bool", NewCommandArg("flag").SetValueType(CommandValueBoolType).SetRequired())
|
||||
boolCmd := NewCommand("bool", func(ctx *MsgContext, db NoData) error { return nil }, NewCommandArg("flag").SetValueType(CommandValueBool).SetRequired())
|
||||
if err := boolCmd.validateArgs([]string{"false"}); err != nil {
|
||||
t.Fatalf("expected valid bool argument, got %v", err)
|
||||
}
|
||||
@@ -25,8 +25,8 @@ func TestValidateArgsRequiresFullMatch(t *testing.T) {
|
||||
|
||||
func TestValidateArgsEnforcesRequiredArgIndex(t *testing.T) {
|
||||
cmd := NewCommand(
|
||||
func(ctx *MsgContext, db NoData) error { return nil },
|
||||
"mixed",
|
||||
func(ctx *MsgContext, db NoData) error { return nil },
|
||||
NewCommandArg("optional"),
|
||||
NewCommandArg("required").SetRequired(),
|
||||
)
|
||||
@@ -42,12 +42,11 @@ func TestValidateArgsEnforcesRequiredArgIndex(t *testing.T) {
|
||||
func TestCommandGroupBuildsPrefixedCommandsWithoutMutatingOriginal(t *testing.T) {
|
||||
groupMiddleware := NewMiddleware("group", func(ctx *MsgContext, db NoData) bool { return true })
|
||||
commandMiddleware := NewMiddleware("command", func(ctx *MsgContext, db NoData) bool { return true })
|
||||
cmd := NewCommand(func(ctx *MsgContext, db NoData) error { return nil }, "ban").
|
||||
cmd := NewCommand("ban", func(ctx *MsgContext, db NoData) error { return nil }).
|
||||
SetDescription("Ban user").
|
||||
Use(commandMiddleware)
|
||||
|
||||
group := NewCommandGroup[NoData]("admin").
|
||||
SetSeparator("_").
|
||||
group := NewCommandGroup[NoData]("admin_").
|
||||
Use(groupMiddleware).
|
||||
AddCommand(cmd)
|
||||
|
||||
@@ -80,7 +79,7 @@ func TestCommandGroupBuildsPrefixedCommandsWithoutMutatingOriginal(t *testing.T)
|
||||
func TestCommandGroupBuildIsRepeatable(t *testing.T) {
|
||||
group := NewCommandGroup[NoData]("admin").
|
||||
Use(NewMiddleware("group", func(ctx *MsgContext, db NoData) bool { return true })).
|
||||
AddCommand(NewCommand(func(ctx *MsgContext, db NoData) error { return nil }, "ban").
|
||||
AddCommand(NewCommand("ban", func(ctx *MsgContext, db NoData) error { return nil }).
|
||||
Use(NewMiddleware("command", func(ctx *MsgContext, db NoData) bool { return true })))
|
||||
|
||||
first := group.Build()
|
||||
@@ -103,9 +102,8 @@ func TestCommandGroupBuildIsRepeatable(t *testing.T) {
|
||||
func TestPluginCommandGroupRegistersBuiltCommands(t *testing.T) {
|
||||
plugin := NewPlugin[NoData]("admin")
|
||||
|
||||
plugin.CommandGroup("admin", func(group *CommandGroup[NoData]) {
|
||||
group.SetSeparator("_")
|
||||
group.AddCommand(NewCommand(func(ctx *MsgContext, db NoData) error { return nil }, "ban"))
|
||||
plugin.CommandGroup("admin_", func(group *CommandGroup[NoData]) {
|
||||
group.AddCommand(NewCommand("ban", func(ctx *MsgContext, db NoData) error { return nil }))
|
||||
})
|
||||
|
||||
if _, ok := plugin.commands["admin_ban"]; !ok {
|
||||
|
||||
Reference in New Issue
Block a user