1
0
Fork 0
mirror of https://github.com/diamondburned/arikawa.git synced 2024-12-13 08:55:12 +00:00
arikawa/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 := ErrInvalidUsage{
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 := ErrInvalidUsage{}
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 := ErrInvalidUsage{Wrap: errors.New("astolfo")}
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 = &ErrInvalidUsage{
Wrap: err,
}
if !errors.Is(wrap, err) {
t.Fatal("Failed to unwrap, errors mismatch.")
}
})
}