-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathreg_common_fn_test.go
64 lines (51 loc) · 1.64 KB
/
reg_common_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
package goql
import (
"testing"
"github.com/fzerorubigd/goql/astdata"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestEmbedFn(t *testing.T) {
st, err := astdata.NewDefinition(`
struct {
ST1
ST2
}
`)
require.NoError(t, err)
require.IsType(t, &astdata.StructType{}, st)
n, err := embedCountFn(0).Execute(Definition{Definition: st})
assert.NoError(t, err)
assert.Equal(t, 2.0, n.Get())
n, err = embedDefFn(0).Execute(Definition{Definition: st}, Number{Number: 1})
assert.NoError(t, err)
assert.IsType(t, &astdata.IdentType{}, n.Get())
assert.Equal(t, "ST1", n.Get().(astdata.Definition).String())
n, err = embedDefFn(0).Execute(Definition{Definition: st}, Number{Number: 2})
assert.NoError(t, err)
assert.IsType(t, &astdata.IdentType{}, n.Get())
assert.Equal(t, "ST2", n.Get().(astdata.Definition).String())
i, err := astdata.NewDefinition("int")
require.NoError(t, err)
n, err = embedDefFn(0).Execute(Definition{Definition: st})
assert.Error(t, err)
assert.Nil(t, n)
n, err = embedDefFn(0).Execute(Number{}, Number{})
assert.NoError(t, err)
assert.Nil(t, n.Get())
n, err = embedCountFn(0).Execute(Definition{})
assert.NoError(t, err)
assert.Nil(t, n.Get())
n, err = embedCountFn(0).Execute(Definition{Definition: i})
assert.NoError(t, err)
assert.Nil(t, n.Get())
n, err = embedCountFn(0).Execute()
assert.Error(t, err)
assert.Nil(t, n)
n, err = embedDefFn(0).Execute(Definition{Definition: st}, Number{Number: 10})
assert.NoError(t, err)
assert.Nil(t, n.Get())
n, err = embedDefFn(0).Execute(Definition{Definition: i}, Number{Number: 0})
assert.NoError(t, err)
assert.Nil(t, n.Get())
}