36 lines
723 B
Python
Raw Normal View History

import pika_lua
# 测试数字
2023-06-24 19:15:07 +08:00
assert pika_lua.evals('return 1 + 1') == 2
# 测试字符串
2023-06-24 19:15:07 +08:00
assert pika_lua.evals('return "hello"') == "hello"
# 测试布尔值
2023-06-24 19:15:07 +08:00
assert pika_lua.evals('return true') == True
# 测试nil
2023-06-24 19:15:07 +08:00
assert pika_lua.evals('return nil') == None
# 测试变量赋值
2023-06-24 19:15:07 +08:00
pika_lua.evals('x = 10')
assert pika_lua.evals('return x') == 10
# 测试函数调用
2023-06-24 19:15:07 +08:00
pika_lua.evals('function add(a, b) return a + b end')
assert pika_lua.evals('return add(1, 2)') == 3
2023-05-14 22:50:24 +08:00
# table to list
2023-06-24 19:15:07 +08:00
l = pika_lua.evals('return {1, 2, 3}')
2023-05-14 22:50:24 +08:00
assert l[0] == 1
assert l[1] == 2
assert l[2] == 3
# table to dict
2023-06-24 19:15:07 +08:00
d = pika_lua.evals('return {a = 1, b = 2, c = 3}')
2023-05-14 22:50:24 +08:00
assert d['a'] == 1
assert d['b'] == 2
assert d['c'] == 3
print('PASS')