forked from hootrhino/rulex
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlua_template_gen_test.go
49 lines (43 loc) · 1.24 KB
/
lua_template_gen_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
package test
import (
"os"
"testing"
"text/template"
)
var s = `
---@diagnostic disable: undefined-global
-- Success
function Success()
end
-- Failed
function Failed(error)
print("Error:", error)
end
-- Actions
Actions = {function(data)
local t = rulexlib:J2T(data)
local V0 = rulexlib:MB(">{{.a}}:16 {{.b}}:16 {{.c}}:16 {{.d}}:16 {{.e}}:16", t['value'], false)
local a = rulexlib:T2J(V0['{{.a}}'])
local b = rulexlib:T2J(V0['{{.b}}'])
local c = rulexlib:T2J(V0['{{.c}}'])
local d = rulexlib:T2J(V0['{{.d}}'])
local e = rulexlib:T2J(V0['{{.e}}'])
print('{{.a}} ==> ', {{.a}}, ' ->', rulexlib:B2I64('>', rulexlib:BS2B(a)))
print('{{.b}} ==> ', {{.b}}, ' ->', rulexlib:B2I64('>', rulexlib:BS2B(b)))
print('{{.c}} ==> ', {{.c}}, ' ->', rulexlib:B2I64('>', rulexlib:BS2B(c)))
print('{{.d}} ==> ', {{.d}}, ' ->', rulexlib:B2I64('>', rulexlib:BS2B(d)))
print('{{.e}} ==> ', {{.e}}, ' ->', rulexlib:B2I64('>', rulexlib:BS2B(e)))
return true, data
end}
`
func Test_gen_template(*testing.T) {
t := template.New("test")
t = template.Must(t.Parse(s))
t.Execute(os.Stdout, map[string]string{
"a": "va",
"b": "vb",
"c": "vc",
"d": "vd",
"e": "ve",
})
}