-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathreg_map_fn_test.go
70 lines (51 loc) · 1.62 KB
/
reg_map_fn_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
package goql
import (
"testing"
"github.com/fzerorubigd/goql/astdata"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestIsMap(t *testing.T) {
st, err := astdata.NewDefinition("map[string]int")
require.NoError(t, err)
g, err := isMapFn(0).Execute(Definition{Definition: st})
assert.NoError(t, err)
assert.Equal(t, Bool{Bool: true}, g)
_, err = isMapFn(0).Execute(nil, nil)
assert.Error(t, err)
g, err = isMapFn(0).Execute(Number{})
assert.NoError(t, err)
assert.Equal(t, Bool{Null: true}, g)
}
func TestMapKey(t *testing.T) {
st, err := astdata.NewDefinition("map[string]int")
require.NoError(t, err)
g, err := mapKeyFn(0).Execute(Definition{Definition: st})
assert.NoError(t, err)
assert.IsType(t, &astdata.IdentType{}, g.Get())
assert.Equal(t, "string", g.Get().(astdata.Definition).String())
g, err = mapKeyFn(0).Execute(g)
assert.NoError(t, err)
assert.Nil(t, g.Get())
_, err = mapKeyFn(0).Execute(nil, nil)
assert.Error(t, err)
g, err = mapKeyFn(0).Execute(Number{})
assert.NoError(t, err)
assert.Equal(t, Definition{}, g)
}
func TestMapValue(t *testing.T) {
st, err := astdata.NewDefinition("map[string]int")
require.NoError(t, err)
g, err := mapValFn(0).Execute(Definition{Definition: st})
assert.NoError(t, err)
assert.IsType(t, &astdata.IdentType{}, g.Get())
assert.Equal(t, "int", g.Get().(astdata.Definition).String())
g, err = mapValFn(0).Execute(g)
assert.NoError(t, err)
assert.Nil(t, g.Get())
_, err = mapValFn(0).Execute(nil, nil)
assert.Error(t, err)
g, err = mapValFn(0).Execute(Number{})
assert.NoError(t, err)
assert.Equal(t, Definition{}, g)
}