A modification-free API for Minecraft utilizing log parsing
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

69 lines
1.6 KiB

package commands
import (
"regexp"
"testing"
)
func TestParseCommandArguments(t *testing.T) {
args := ParseCommandArguments("normal \"testing quoted\" and normal \"end closed\"")
expected := []string{"normal", "testing quoted", "and", "normal", "end closed"}
for i := 0; i < len(expected); i++ {
if args[i] != expected[i] {
t.Errorf("Expected %s, got %s at index %d", expected[i], args[i], i)
}
}
}
func TestDispatching(t *testing.T) {
Register("testing", func(ctx *CommandContext) {
// Something
})
if handler := Find("!", "!testing", "testing"); handler == nil {
t.Error("Expected handler for testing")
}
}
func TestRegexpDispatching(t *testing.T) {
RegisterMatch(regexp.MustCompile("^compliment"), func(ctx *CommandContext) {
// Something
})
if handler := Find("", "compliment", "compliment me"); handler == nil {
t.Error("Expected handler for compliment")
}
}
func TestArgumentParsing(t *testing.T) {
holder := parseCommandUsage("test <arg1> <arg2> [arg3]")
if holder.Name != "test" {
t.Error("Unexpected command name")
}
if len(holder.Arguments) != 3 {
t.Error("Invalid number of command arguments:", len(holder.Arguments))
}
if holder.RequiredArgumentCount != 2 {
t.Error("Invalid required argument count")
}
}
func TestArgumentDispatching(t *testing.T) {
holder := parseCommandUsage("test <arg1> <arg2> [arg3]")
if holder.Name != "test" {
t.Error("Unexpected command name")
}
if len(holder.Arguments) != 3 {
t.Error("Invalid number of command arguments:", len(holder.Arguments))
}
if holder.RequiredArgumentCount != 2 {
t.Error("Invalid required argument count")
}
}