forked from expr-lang/expr
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathderef_test.go
111 lines (86 loc) · 1.94 KB
/
deref_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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
package deref_test
import (
"reflect"
"testing"
"github.com/stretchr/testify/assert"
"github.com/expr-lang/expr/internal/deref"
)
func TestDeref(t *testing.T) {
a := uint(42)
b := &a
c := &b
d := &c
got := deref.Deref(d)
assert.Equal(t, uint(42), got)
}
func TestDeref_mix_ptr_with_interface(t *testing.T) {
a := uint(42)
var b any = &a
var c any = &b
d := &c
got := deref.Deref(d)
assert.Equal(t, uint(42), got)
}
func TestDeref_nil(t *testing.T) {
var a *int
assert.Nil(t, deref.Deref(a))
assert.Nil(t, deref.Deref(nil))
}
func TestType(t *testing.T) {
a := uint(42)
b := &a
c := &b
d := &c
dt := deref.Type(reflect.TypeOf(d))
assert.Equal(t, reflect.Uint, dt.Kind())
}
func TestType_two_ptr_with_interface(t *testing.T) {
a := uint(42)
var b any = &a
dt := deref.Type(reflect.TypeOf(b))
assert.Equal(t, reflect.Uint, dt.Kind())
}
func TestType_three_ptr_with_interface(t *testing.T) {
a := uint(42)
var b any = &a
var c any = &b
dt := deref.Type(reflect.TypeOf(c))
assert.Equal(t, reflect.Interface, dt.Kind())
}
func TestType_nil(t *testing.T) {
assert.Nil(t, deref.Type(nil))
}
func TestValue(t *testing.T) {
a := uint(42)
b := &a
c := &b
d := &c
got := deref.Value(reflect.ValueOf(d))
assert.Equal(t, uint(42), got.Interface())
}
func TestValue_two_ptr_with_interface(t *testing.T) {
a := uint(42)
var b any = &a
got := deref.Value(reflect.ValueOf(b))
assert.Equal(t, uint(42), got.Interface())
}
func TestValue_three_ptr_with_interface(t *testing.T) {
a := uint(42)
var b any = &a
c := &b
got := deref.Value(reflect.ValueOf(c))
assert.Equal(t, uint(42), got.Interface())
}
func TestValue_nil(t *testing.T) {
got := deref.Value(reflect.ValueOf(nil))
assert.False(t, got.IsValid())
}
func TestValue_nil_in_chain(t *testing.T) {
var a any = nil
var b any = &a
c := &b
got := deref.Value(reflect.ValueOf(c))
assert.True(t, got.IsValid())
assert.True(t, got.IsNil())
assert.Nil(t, got.Interface())
}