mirror of
https://github.com/diamondburned/arikawa.git
synced 2024-10-31 20:14:21 +00:00
57 lines
1.1 KiB
Go
57 lines
1.1 KiB
Go
package bot
|
|
|
|
import (
|
|
"errors"
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
func TestInvalidUsage(t *testing.T) {
|
|
t.Run("fmt", func(t *testing.T) {
|
|
err := InvalidUsageError{
|
|
Prefix: "!",
|
|
Args: []string{"hime", "arikawa"},
|
|
Index: 1,
|
|
Wrap: errors.New("test error"),
|
|
}
|
|
str := err.Error()
|
|
|
|
if !strings.Contains(str, "test error") {
|
|
t.Fatal("does not contain 'test error':", str)
|
|
}
|
|
|
|
if !strings.Contains(str, "__arikawa__") {
|
|
t.Fatal("Unexpected highlight index:", str)
|
|
}
|
|
})
|
|
|
|
t.Run("missing arguments", func(t *testing.T) {
|
|
err := InvalidUsageError{}
|
|
str := err.Error()
|
|
|
|
if str != "missing arguments. Refer to help." {
|
|
t.Fatal("Unexpected error:", str)
|
|
}
|
|
})
|
|
|
|
t.Run("no index", func(t *testing.T) {
|
|
err := InvalidUsageError{Wrap: errors.New("astolfo")}
|
|
str := err.Error()
|
|
|
|
if str != "invalid usage, error: astolfo." {
|
|
t.Fatal("Unexpected error:", str)
|
|
}
|
|
})
|
|
|
|
t.Run("unwrap", func(t *testing.T) {
|
|
var err = errors.New("hackadoll no. 3")
|
|
var wrap = &InvalidUsageError{
|
|
Wrap: err,
|
|
}
|
|
|
|
if !errors.Is(wrap, err) {
|
|
t.Fatal("Failed to unwrap, errors mismatch.")
|
|
}
|
|
})
|
|
}
|