-
Notifications
You must be signed in to change notification settings - Fork 303
/
variable_test.go
81 lines (76 loc) · 1.93 KB
/
variable_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
package tengo_test
import (
"testing"
"github.com/d5/tengo/v2"
"github.com/d5/tengo/v2/require"
)
type VariableTest struct {
Name string
Value interface{}
ValueType string
IntValue int
Int64Value int64
FloatValue float64
CharValue rune
BoolValue bool
StringValue string
Object tengo.Object
IsUndefined bool
}
func TestVariable(t *testing.T) {
vars := []VariableTest{
{
Name: "a",
Value: int64(1),
ValueType: "int",
IntValue: 1,
Int64Value: 1,
FloatValue: 1.0,
CharValue: rune(1),
BoolValue: true,
StringValue: "1",
Object: &tengo.Int{Value: 1},
},
{
Name: "b",
Value: "52.11",
ValueType: "string",
FloatValue: 52.11,
StringValue: "52.11",
BoolValue: true,
Object: &tengo.String{Value: "52.11"},
},
{
Name: "c",
Value: true,
ValueType: "bool",
IntValue: 1,
Int64Value: 1,
FloatValue: 0,
BoolValue: true,
StringValue: "true",
Object: tengo.TrueValue,
},
{
Name: "d",
Value: nil,
ValueType: "undefined",
Object: tengo.UndefinedValue,
IsUndefined: true,
},
}
for _, tc := range vars {
v, err := tengo.NewVariable(tc.Name, tc.Value)
require.NoError(t, err)
require.Equal(t, tc.Value, v.Value(), "Name: %s", tc.Name)
require.Equal(t, tc.ValueType, v.ValueType(), "Name: %s", tc.Name)
require.Equal(t, tc.IntValue, v.Int(), "Name: %s", tc.Name)
require.Equal(t, tc.Int64Value, v.Int64(), "Name: %s", tc.Name)
require.Equal(t, tc.FloatValue, v.Float(), "Name: %s", tc.Name)
require.Equal(t, tc.CharValue, v.Char(), "Name: %s", tc.Name)
require.Equal(t, tc.BoolValue, v.Bool(), "Name: %s", tc.Name)
require.Equal(t, tc.StringValue, v.String(), "Name: %s", tc.Name)
require.Equal(t, tc.Object, v.Object(), "Name: %s", tc.Name)
require.Equal(t, tc.IsUndefined, v.IsUndefined(), "Name: %s", tc.Name)
}
}