-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathreflector_nil_test.go
More file actions
44 lines (37 loc) · 845 Bytes
/
reflector_nil_test.go
File metadata and controls
44 lines (37 loc) · 845 Bytes
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
44
package lookup
import (
"errors"
"testing"
)
func TestReflectNilTypeMethodsDoNotPanic(t *testing.T) {
p := Reflect(nil)
assertNoPanic := func(name string, fn func()) {
t.Helper()
defer func() {
if r := recover(); r != nil {
t.Fatalf("%s panicked for nil reflector: %v", name, r)
}
}()
fn()
}
assertNoPanic("IsNil", func() {
if !p.IsNil() {
t.Fatalf("expected IsNil() to be true")
}
})
assertNoPanic("IsString", func() {
if p.IsString() {
t.Fatalf("expected IsString() to be false")
}
})
assertNoPanic("AsString", func() {
if _, err := p.AsString(); err == nil || !errors.Is(err, ErrNotString) {
t.Fatalf("expected ErrNotString, got %v", err)
}
})
assertNoPanic("Type", func() {
if got := p.Type(); got != nil {
t.Fatalf("expected nil type for nil reflector, got %v", got)
}
})
}