-
Notifications
You must be signed in to change notification settings - Fork 14
/
reg_array_fn_test.go
95 lines (70 loc) · 2.4 KB
/
reg_array_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
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
package goql
import (
"testing"
"github.com/fzerorubigd/goql/astdata"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestIsArray(t *testing.T) {
st, err := astdata.NewDefinition("[]string")
require.NoError(t, err)
g, err := isArrayFn(0).Execute(Definition{Definition: st})
assert.NoError(t, err)
assert.Equal(t, Bool{Bool: true}, g)
_, err = isArrayFn(0).Execute(nil, nil)
assert.Error(t, err)
g, err = isArrayFn(0).Execute(Number{})
assert.NoError(t, err)
assert.Equal(t, Bool{Null: true}, g)
}
func TestArrayItem(t *testing.T) {
at, err := astdata.NewDefinition("[]string")
require.NoError(t, err)
et, err := astdata.NewDefinition("[...]string{}")
require.NoError(t, err)
ident, err := astdata.NewDefinition("int")
require.NoError(t, err)
_, err = arrayItemFn(0).Execute(nil, nil)
assert.Error(t, err)
g, err := arrayItemFn(0).Execute(Definition{})
assert.NoError(t, err)
assert.Nil(t, g.Get())
g, err = arrayItemFn(0).Execute(Definition{Definition: ident})
assert.NoError(t, err)
assert.Nil(t, g.Get())
g, err = arrayItemFn(0).Execute(Definition{Definition: at})
assert.NoError(t, err)
require.IsType(t, &astdata.IdentType{}, g.Get())
assert.Equal(t, "string", g.Get().(astdata.Definition).String())
g, err = arrayItemFn(0).Execute(Definition{Definition: et})
assert.NoError(t, err)
require.IsType(t, &astdata.IdentType{}, g.Get())
assert.Equal(t, "string", g.Get().(astdata.Definition).String())
}
func TestArrayType(t *testing.T) {
at, err := astdata.NewDefinition("[]string")
require.NoError(t, err)
at2, err := astdata.NewDefinition("[10]string")
require.NoError(t, err)
et, err := astdata.NewDefinition("[...]string{}")
require.NoError(t, err)
ident, err := astdata.NewDefinition("int")
require.NoError(t, err)
_, err = arrayTypeFn(0).Execute(nil, nil)
assert.Error(t, err)
g, err := arrayTypeFn(0).Execute(Definition{})
assert.NoError(t, err)
assert.Nil(t, g.Get())
g, err = arrayTypeFn(0).Execute(Definition{Definition: ident})
assert.NoError(t, err)
assert.Nil(t, g.Get())
g, err = arrayTypeFn(0).Execute(Definition{Definition: at})
assert.NoError(t, err)
assert.Equal(t, "slice", g.Get())
g, err = arrayTypeFn(0).Execute(Definition{Definition: at2})
assert.NoError(t, err)
assert.Equal(t, "array", g.Get())
g, err = arrayTypeFn(0).Execute(Definition{Definition: et})
assert.NoError(t, err)
assert.Equal(t, "ellipsis", g.Get())
}