1
0
Fork 0
mirror of https://github.com/diamondburned/arikawa.git synced 2024-11-01 20:45:42 +00:00
arikawa/utils/bot/error_test.go

57 lines
1.1 KiB
Go
Raw Normal View History

2020-05-14 03:42:31 +00:00
package bot
import (
"errors"
"strings"
"testing"
)
func TestInvalidUsage(t *testing.T) {
t.Run("fmt", func(t *testing.T) {
err := InvalidUsageError{
2020-05-14 03:42:31 +00:00
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{}
2020-05-14 03:42:31 +00:00
str := err.Error()
2020-05-16 21:14:49 +00:00
if str != "missing arguments. Refer to help." {
2020-05-14 03:42:31 +00:00
t.Fatal("Unexpected error:", str)
}
})
t.Run("no index", func(t *testing.T) {
err := InvalidUsageError{Wrap: errors.New("astolfo")}
2020-05-14 03:42:31 +00:00
str := err.Error()
2020-05-16 21:14:49 +00:00
if str != "invalid usage, error: astolfo." {
2020-05-14 03:42:31 +00:00
t.Fatal("Unexpected error:", str)
}
})
t.Run("unwrap", func(t *testing.T) {
var err = errors.New("hackadoll no. 3")
var wrap = &InvalidUsageError{
2020-05-14 03:42:31 +00:00
Wrap: err,
}
if !errors.Is(wrap, err) {
t.Fatal("Failed to unwrap, errors mismatch.")
}
})
}