-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexpression_test.go
More file actions
73 lines (65 loc) · 1.43 KB
/
expression_test.go
File metadata and controls
73 lines (65 loc) · 1.43 KB
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
package formula_engine
import (
"fmt"
"testing"
)
// fakeCell 模拟真实单元格 获取相关环境变量
type fakeCell struct {
data map[string]string
}
func (fc fakeCell) GetEnvValue(str string) interface{} {
if fc.data == nil {
return nil
}
if v, ok := fc.data[str]; ok == false {
return nil
} else {
return v
}
}
type SayHello struct {
}
func (sh SayHello) Invoke(env *Wrapper, args ...*Token) (*Token, error) {
str := args[0].getStringValue()
return newStringToken(fmt.Sprintf("Hello %s", str)), nil
}
func TestNewExpression2(t *testing.T) {
wb := &WrapperBuilder{}
wb.AddFormula(NewFormulaEnv("SAYHELLO", "", []string{fmt.Sprintf("%s[LOCK]", ArgStringType)}, ArgStringType), SayHello{})
w := wb.Build()
expression, err := NewExpression("SAYHELLO(My)")
if err != nil {
panic(err)
}
expression.WithOtherWrapper(w)
s := &scope{
data: map[string]interface{}{
"My": "You",
},
}
invoke, err := expression.Invoke(s)
if err != nil {
panic(err)
}
fmt.Println(invoke)
}
func TestGt(t *testing.T) {
exp, _ := NewExpression("GT(ATTR_VALUE,202012)")
w := NewWrapperEnv(nil)
w.AddEnv("ATTR_VALUE", "2022222")
result, _ := exp.Invoke(w)
fmt.Println(result)
}
func TestE(t *testing.T) {
expression, err := NewExpression("num1*(-1)")
if err != nil {
panic(err)
}
env := NewWrapperEnv(nil)
env.AddEnv("num1", 10.0)
result, err := expression.Invoke(nil)
if err != nil {
panic(err)
}
fmt.Println(result)
}