summaryrefslogtreecommitdiff
path: root/test/full
diff options
context:
space:
mode:
Diffstat (limited to 'test/full')
-rw-r--r--test/full/dirty.lua15
-rw-r--r--test/full/example.lua42
-rw-r--r--test/full/init.lua16
-rw-r--r--test/full/normal.lua157
4 files changed, 230 insertions, 0 deletions
diff --git a/test/full/dirty.lua b/test/full/dirty.lua
new file mode 100644
index 00000000..5fe4e998
--- /dev/null
+++ b/test/full/dirty.lua
@@ -0,0 +1,15 @@
+TEST [[
+a.
+]]
+
+TEST [[
+a:
+]]
+
+TEST [[
+end
+]]
+
+TEST [[
+table.02X
+]]
diff --git a/test/full/example.lua b/test/full/example.lua
new file mode 100644
index 00000000..a096f83d
--- /dev/null
+++ b/test/full/example.lua
@@ -0,0 +1,42 @@
+local fs = require 'bee.filesystem'
+local core = require 'core'
+local parser = require 'parser'
+
+TEST(io.load(ROOT / 'src' / 'vm' / 'vm.lua'))
+
+-- 临时
+local function testIfExit(path)
+ local buf = io.load(fs.path(path))
+ if buf then
+ local vm
+
+ local clock = os.clock()
+ local max = 100
+ local need
+ for i = 1, max do
+ vm = TEST(buf)
+ local passed = os.clock() - clock
+ if passed >= 1.0 or i == max then
+ need = passed / i
+ break
+ end
+ end
+ print(('基准编译测试[%s]单次耗时:%.10f'):format(path:filename():string(), need))
+
+ local clock = os.clock()
+ local max = 100
+ local need
+ local lines = parser:lines(buf, 'utf8')
+ for i = 1, max do
+ core.diagnostics(vm, lines, 'test')
+ local passed = os.clock() - clock
+ if passed >= 1.0 or i == max then
+ need = passed / i
+ break
+ end
+ end
+ print(('基准诊断测试[%s]单次耗时:%.10f'):format(path:filename():string(), need))
+ end
+end
+testIfExit(ROOT / 'test' / 'example' / 'vm.txt')
+testIfExit(ROOT / 'test' / 'example' / 'largeGlobal.txt')
diff --git a/test/full/init.lua b/test/full/init.lua
new file mode 100644
index 00000000..3d0661cb
--- /dev/null
+++ b/test/full/init.lua
@@ -0,0 +1,16 @@
+local buildVM = require 'vm'
+local parser = require 'parser'
+
+rawset(_G, 'TEST', true)
+
+function TEST(script)
+ local ast = parser:parse(script, 'lua', 'Lua 5.3')
+ assert(ast)
+ local vm, err = buildVM(ast)
+ assert(vm, err)
+ return vm
+end
+
+require 'full.normal'
+require 'full.example'
+require 'full.dirty'
diff --git a/test/full/normal.lua b/test/full/normal.lua
new file mode 100644
index 00000000..a673e74b
--- /dev/null
+++ b/test/full/normal.lua
@@ -0,0 +1,157 @@
+TEST [[
+do
+ x = 1
+end
+]]
+
+TEST [[
+return nil, 1, true, 'xx'
+]]
+
+TEST [[
+return a
+]]
+
+TEST [[
+retrun a.b:c(1, 2, ...)[1][name]
+]]
+
+TEST [[
+return 1 + 1
+]]
+
+TEST [[
+return -1
+]]
+
+TEST [[
+return ...
+]]
+
+TEST [[
+return function (a, b, ...)
+end
+]]
+
+TEST [[
+return {
+ a = 1,
+ b = {
+ c = d,
+ e = f,
+ },
+ g,
+ h,
+ 1,
+}
+]]
+
+TEST [[
+::LABEL::
+goto LABEL
+goto NEXT
+::NEXT::
+]]
+
+TEST [[
+a, b, c = 1, 2, ...
+]]
+
+TEST [[
+local a, b, c = 1, 2, ...
+]]
+
+TEST [[
+a[#a+1] = 1
+]]
+
+TEST [[
+xx(a, b, 2, 3, ...)
+]]
+
+TEST [[
+if a then
+elseif b then
+elseif c then
+else
+end
+]]
+
+TEST [[
+for i = 1, 10, 1 do
+end
+]]
+
+TEST [[
+for a, b, c in pairs(t) do
+end
+]]
+
+TEST [[
+while true do
+end
+]]
+
+TEST [[
+repeat
+until true
+]]
+
+TEST [[
+function xx:yy(a, b, c, ...)
+end
+]]
+
+TEST [[
+local function xx(a, b, c, ...)
+end
+]]
+
+TEST [[
+local v = 1
+local function xx()
+ print(v)
+end
+local v = 2
+xx()
+]]
+
+TEST [[
+return {
+ 1, 2, 3
+}
+]]
+
+TEST [[
+return function ()
+end
+]]
+
+TEST [[
+t[...] = 1
+]]
+
+TEST [[
+return {
+ [...] = ...
+}
+]]
+
+TEST [[
+-- 选取单位
+---@param center point
+---@param radius number
+---@param height number
+---@return unit[]
+function scene:selectByCylinder(center, radius, height)
+end
+]]
+
+TEST [[
+local x = ,
+]]
+
+TEST [[
+---@type any|fun():nil
+local t
+]]