-
Notifications
You must be signed in to change notification settings - Fork 31
/
type_test.go
43 lines (33 loc) · 1.08 KB
/
type_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package errorx
import (
"errors"
"testing"
"github.com/stretchr/testify/require"
)
func TestTypeName(t *testing.T) {
require.Equal(t, "foo.bar", testType.FullName())
}
func TestSubTypeName(t *testing.T) {
require.Equal(t, "foo.bar.internal.wat", testSubtype1.FullName())
}
func TestErrorTypeCheck(t *testing.T) {
require.True(t, testSubtype1.IsOfType(testSubtype1))
require.False(t, testSubtype1.IsOfType(NewNamespace("a").NewType("b")))
}
func TestErrorTypeCheckNonErrorx(t *testing.T) {
require.False(t, IsOfType(errors.New("test"), testSubtype1))
}
func TestErrorTypeUpCast(t *testing.T) {
require.True(t, testSubtype1.IsOfType(testSubtype0))
require.True(t, testSubtype1.IsOfType(testType))
}
func TestErrorTypeDownCast(t *testing.T) {
require.False(t, testSubtype0.IsOfType(testSubtype1))
require.False(t, testType.IsOfType(testSubtype1))
}
func TestErrorTypeSiblingsCast(t *testing.T) {
subtype10 := testSubtype0.NewSubtype("wat!")
subtype11 := testSubtype0.NewSubtype("oops")
require.False(t, subtype10.IsOfType(subtype11))
require.False(t, subtype11.IsOfType(subtype10))
}