summaryrefslogtreecommitdiff
path: root/server/test
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2018-11-20 18:40:33 +0800
committer最萌小汐 <sumneko@hotmail.com>2018-11-20 18:40:33 +0800
commit67f6a20b27c98788843883c3712c648e110d781f (patch)
tree209705e0bc3c2c44d5ffade78cc2c7041eeffdda /server/test
parenta65a1ddb13854c2dfde4c04630a0a942abdafa32 (diff)
downloadlua-language-server-67f6a20b27c98788843883c3712c648e110d781f.zip
转移目录
Diffstat (limited to 'server/test')
-rw-r--r--server/test/definition/arg.lua23
-rw-r--r--server/test/definition/bug.lua15
-rw-r--r--server/test/definition/function.lua24
-rw-r--r--server/test/definition/init.lua22
-rw-r--r--server/test/definition/local.lua191
-rw-r--r--server/test/definition/set.lua30
-rw-r--r--server/test/definition/table.lua6
-rw-r--r--server/test/implementation/arg.lua23
-rw-r--r--server/test/implementation/bug.lua15
-rw-r--r--server/test/implementation/function.lua24
-rw-r--r--server/test/implementation/if.lua106
-rw-r--r--server/test/implementation/init.lua57
-rw-r--r--server/test/implementation/local.lua191
-rw-r--r--server/test/implementation/set.lua31
-rw-r--r--server/test/implementation/table.lua6
-rw-r--r--server/test/main.lua31
16 files changed, 795 insertions, 0 deletions
diff --git a/server/test/definition/arg.lua b/server/test/definition/arg.lua
new file mode 100644
index 00000000..2004d666
--- /dev/null
+++ b/server/test/definition/arg.lua
@@ -0,0 +1,23 @@
+TEST [[
+local function xx (<!xx!>)
+ <?xx?> = 1
+end
+]]
+
+TEST [[
+local function x (x, <!...!>)
+ x = <?...?>
+end
+]]
+
+TEST [[
+function mt<!:!>x()
+ <?self?> = 1
+end
+]]
+
+TEST [[
+function mt:x(<!self!>)
+ <?self?> = 1
+end
+]]
diff --git a/server/test/definition/bug.lua b/server/test/definition/bug.lua
new file mode 100644
index 00000000..b0e890ca
--- /dev/null
+++ b/server/test/definition/bug.lua
@@ -0,0 +1,15 @@
+TEST [[
+local <!x!>
+function _(x)
+end
+function _()
+ <?x?>
+end
+]]
+
+TEST [[
+function _(<!x!>)
+ do return end
+ <?x?> = 1
+end
+]]
diff --git a/server/test/definition/function.lua b/server/test/definition/function.lua
new file mode 100644
index 00000000..1ef6a463
--- /dev/null
+++ b/server/test/definition/function.lua
@@ -0,0 +1,24 @@
+
+TEST [[
+function <!x!> () end
+<?x?> = 1
+]]
+
+TEST [[
+local function <!x!> () end
+<?x?> = 1
+]]
+
+TEST [[
+local x
+local function <!x!> ()
+ <?x?> = 1
+end
+]]
+
+TEST [[
+local <!x!>
+function x()
+end
+<?x?> = 1
+]]
diff --git a/server/test/definition/init.lua b/server/test/definition/init.lua
new file mode 100644
index 00000000..9bd7a1d8
--- /dev/null
+++ b/server/test/definition/init.lua
@@ -0,0 +1,22 @@
+local matcher = require 'matcher'
+
+rawset(_G, 'TEST', true)
+
+function TEST(script)
+ local start = script:find('<!', 1, true) + 2
+ local finish = script:find('!>', 1, true) - 1
+ local pos = script:find('<?', 1, true) + 2
+ local new_script = script:gsub('<[!?]', ' '):gsub('[!?]>', ' ')
+
+ local suc, a, b = matcher.definition(new_script, pos)
+ assert(suc)
+ assert(a == start)
+ assert(b == finish)
+end
+
+require 'definition.set'
+require 'definition.local'
+require 'definition.arg'
+require 'definition.function'
+--require 'definition.table'
+require 'definition.bug'
diff --git a/server/test/definition/local.lua b/server/test/definition/local.lua
new file mode 100644
index 00000000..0737443d
--- /dev/null
+++ b/server/test/definition/local.lua
@@ -0,0 +1,191 @@
+TEST [[
+local <!x!>
+<?x?> = 1
+]]
+
+TEST [[
+local z, y, <!x!>
+<?x?> = 1
+]]
+
+TEST [[
+local <!x!> = 1
+<?x?> = 1
+]]
+
+TEST [[
+local z, y, <!x!> = 1
+<?x?> = 1
+]]
+
+TEST [[
+local x
+local <!x!>
+<?x?> = 1
+]]
+
+TEST [[
+local <!x!>
+do
+ <?x?> = 1
+end
+]]
+
+TEST [[
+local <!x!>
+do
+ local x
+end
+<?x?> = 1
+]]
+
+TEST [[
+local <!x!>
+if <?x?> then
+ local x
+end
+]]
+
+TEST [[
+local <!x!>
+if x then
+ local x
+elseif <?x?> then
+ local x
+end
+]]
+
+TEST [[
+local <!x!>
+if x then
+ local x
+elseif x then
+ local x
+else
+ local x
+end
+<?x?> = 1
+]]
+
+TEST [[
+local <!x!>
+if x then
+ <?x?> = 1
+elseif x then
+ local x
+else
+ local x
+end
+]]
+
+TEST [[
+local <!x!>
+for x = 1, 10 do
+end
+<?x?> = 1
+]]
+
+TEST [[
+local x
+for <!x!> = 1, 10 do
+ <?x?> = 1
+end
+]]
+
+TEST [[
+local <!x!>
+for x in x do
+end
+<?x?> = 1
+]]
+
+TEST [[
+local <!x!>
+for x in <?x?> do
+end
+]]
+
+TEST [[
+local x
+for <!x!> in x do
+ <?x?> = 1
+end
+]]
+
+TEST [[
+local x
+for z, y, <!x!> in x do
+ <?x?> = 1
+end
+]]
+
+TEST [[
+local <!x!>
+while <?x?> do
+end
+]]
+
+TEST [[
+local <!x!>
+while x do
+ <?x?> = 1
+end
+]]
+
+TEST [[
+local <!x!>
+while x do
+ local x
+end
+<?x?> = 1
+]]
+
+TEST [[
+local <!x!>
+repeat
+ <?x?> = 1
+until true
+]]
+
+TEST [[
+local <!x!>
+repeat
+ local x
+until true
+<?x?> = 1
+]]
+
+TEST [[
+local <!x!>
+repeat
+until <?x?>
+]]
+
+TEST [[
+local x
+repeat
+ local <!x!>
+until <?x?>
+]]
+
+TEST [[
+local <!x!>
+function _()
+ local x
+end
+<?x?> = 1
+]]
+
+TEST [[
+local <!x!>
+return function ()
+ <?x?> = 1
+end
+]]
+
+TEST [[
+local <!x!>
+local x = function ()
+ <?x?> = 1
+end
+]]
diff --git a/server/test/definition/set.lua b/server/test/definition/set.lua
new file mode 100644
index 00000000..2e48e490
--- /dev/null
+++ b/server/test/definition/set.lua
@@ -0,0 +1,30 @@
+TEST [[
+<!x!> = 1
+<?x?> = 1
+]]
+
+TEST [[
+do
+ <!global!> = 1
+end
+<?global?> = 1
+]]
+
+TEST [[
+<!x!> = 1
+do
+ local x = 1
+end
+<?x?> = 1
+]]
+
+TEST [[
+x = 1
+do
+ local <!x!> = 1
+ do
+ x = 2
+ end
+ <?x?> = 1
+end
+]]
diff --git a/server/test/definition/table.lua b/server/test/definition/table.lua
new file mode 100644
index 00000000..13a3b555
--- /dev/null
+++ b/server/test/definition/table.lua
@@ -0,0 +1,6 @@
+TEST [[
+local t = {
+ <!x!> = 1,
+}
+t.<?x?> = 1
+]]
diff --git a/server/test/implementation/arg.lua b/server/test/implementation/arg.lua
new file mode 100644
index 00000000..2004d666
--- /dev/null
+++ b/server/test/implementation/arg.lua
@@ -0,0 +1,23 @@
+TEST [[
+local function xx (<!xx!>)
+ <?xx?> = 1
+end
+]]
+
+TEST [[
+local function x (x, <!...!>)
+ x = <?...?>
+end
+]]
+
+TEST [[
+function mt<!:!>x()
+ <?self?> = 1
+end
+]]
+
+TEST [[
+function mt:x(<!self!>)
+ <?self?> = 1
+end
+]]
diff --git a/server/test/implementation/bug.lua b/server/test/implementation/bug.lua
new file mode 100644
index 00000000..b0e890ca
--- /dev/null
+++ b/server/test/implementation/bug.lua
@@ -0,0 +1,15 @@
+TEST [[
+local <!x!>
+function _(x)
+end
+function _()
+ <?x?>
+end
+]]
+
+TEST [[
+function _(<!x!>)
+ do return end
+ <?x?> = 1
+end
+]]
diff --git a/server/test/implementation/function.lua b/server/test/implementation/function.lua
new file mode 100644
index 00000000..90b75da8
--- /dev/null
+++ b/server/test/implementation/function.lua
@@ -0,0 +1,24 @@
+
+TEST [[
+function <!x!> () end
+<?x?> = 1
+]]
+
+TEST [[
+local function <!x!> () end
+<?x?> = 1
+]]
+
+TEST [[
+local x
+local function <!x!> ()
+ <?x?> = 1
+end
+]]
+
+TEST [[
+local x
+function <!x!>()
+end
+<?x?> = 1
+]]
diff --git a/server/test/implementation/if.lua b/server/test/implementation/if.lua
new file mode 100644
index 00000000..0da8be1a
--- /dev/null
+++ b/server/test/implementation/if.lua
@@ -0,0 +1,106 @@
+TEST [[
+<!x!> = 1
+if 1 then
+ x = 1
+else
+ <?x?> = 1
+end
+]]
+
+TEST [[
+<!x!> = 1
+if 1 then
+ <!x!> = 1
+else
+ <!x!> = 1
+end
+<?x?> = 1
+]]
+
+TEST [[
+<!x!> = 1
+if 1 then
+ <!x!> = 1
+elseif 1 then
+ <!x!> = 1
+else
+ <!x!> = 1
+end
+<?x?> = 1
+]]
+
+TEST [[
+<!x!> = 1
+if 1 then
+ <!x!> = 1
+elseif 1 then
+ <!x!> = 1
+ if 1 then
+ <!x!> = 1
+ end
+else
+ <!x!> = 1
+end
+<?x?> = 1
+]]
+
+TEST [[
+<!x!> = 1
+while true do
+ <!x!> = 1
+end
+<?x?> = 1
+]]
+
+TEST [[
+<!x!> = 1
+for _ in _ do
+ <!x!> = 1
+end
+<?x?> = 1
+]]
+
+TEST [[
+<!x!> = 1
+for _ = 1, 1 do
+ <!x!> = 1
+end
+<?x?> = 1
+]]
+
+TEST [[
+x3 = 1
+repeat
+ <!x3!> = 1
+until <?x3?> == 1
+]]
+
+TEST [[
+<!x!> = 1
+repeat
+ <!x!> = 1
+until 1
+<?x?> = 1
+]]
+
+TEST [[
+<!x!> = 1
+while 1 do
+ x = 1
+ <!x!> = 1
+end
+<?x?> = 1
+]]
+
+TEST [[
+<!x!> = 1
+if 1 then
+ if 1 then
+ x = 1
+ end
+else
+ if 1 then
+ <?x?> = 1
+ end
+end
+]]
diff --git a/server/test/implementation/init.lua b/server/test/implementation/init.lua
new file mode 100644
index 00000000..de8d9d63
--- /dev/null
+++ b/server/test/implementation/init.lua
@@ -0,0 +1,57 @@
+local matcher = require 'matcher'
+
+rawset(_G, 'TEST', true)
+
+local function catch_target(script)
+ local list = {}
+ local cur = 1
+ while true do
+ local start, finish = script:find('<!.-!>', cur)
+ if not start then
+ break
+ end
+ list[#list+1] = { start + 2, finish - 2 }
+ cur = finish + 1
+ end
+ return list
+end
+
+local function founded(targets, results)
+ while true do
+ local target = table.remove(targets)
+ if not target then
+ break
+ end
+ for i, result in ipairs(results) do
+ if target[1] == result[1] and target[2] == result[2] then
+ table.remove(results, i)
+ goto CONTINUE
+ end
+ end
+ do return false end
+ ::CONTINUE::
+ end
+ if #results == 0 then
+ return true
+ else
+ return false
+ end
+end
+
+function TEST(script)
+ local target = catch_target(script)
+ local pos = script:find('<?', 1, true) + 2
+ local new_script = script:gsub('<[!?]', ' '):gsub('[!?]>', ' ')
+
+ local suc, result = matcher.implementation(new_script, pos)
+ assert(suc)
+ assert(founded(target, result))
+end
+
+require 'implementation.set'
+require 'implementation.local'
+require 'implementation.arg'
+require 'implementation.function'
+require 'implementation.if'
+--require 'implementation.table'
+require 'implementation.bug'
diff --git a/server/test/implementation/local.lua b/server/test/implementation/local.lua
new file mode 100644
index 00000000..7e9b3db0
--- /dev/null
+++ b/server/test/implementation/local.lua
@@ -0,0 +1,191 @@
+TEST [[
+local <!x!>
+<?x?> = 1
+]]
+
+TEST [[
+local z, y, <!x!>
+<?x?> = 1
+]]
+
+TEST [[
+local <!x!> = 1
+<?x?> = 1
+]]
+
+TEST [[
+local z, y, <!x!> = 1
+<?x?> = 1
+]]
+
+TEST [[
+local x
+local <!x!>
+<?x?> = 1
+]]
+
+TEST [[
+local <!x!>
+do
+ <?x?> = 1
+end
+]]
+
+TEST [[
+local <!x!>
+do
+ local x
+end
+<?x?> = 1
+]]
+
+TEST [[
+local <!x!>
+if <?x?> then
+ local x
+end
+]]
+
+TEST [[
+local <!x2!>
+if x2 then
+ local x2
+elseif <?x2?> then
+ local x2
+end
+]]
+
+TEST [[
+local <!x!>
+if x then
+ local x
+elseif x then
+ local x
+else
+ local x
+end
+<?x?> = 1
+]]
+
+TEST [[
+local <!x!>
+if x then
+ <?x?> = 1
+elseif x then
+ local x
+else
+ local x
+end
+]]
+
+TEST [[
+local <!x!>
+for x = 1, 10 do
+end
+<?x?> = 1
+]]
+
+TEST [[
+local x
+for <!x!> = 1, 10 do
+ <?x?> = 1
+end
+]]
+
+TEST [[
+local <!x!>
+for x in x do
+end
+<?x?> = 1
+]]
+
+TEST [[
+local <!x!>
+for x in <?x?> do
+end
+]]
+
+TEST [[
+local x
+for <!x!> in x do
+ <?x?> = 1
+end
+]]
+
+TEST [[
+local x
+for z, y, <!x!> in x do
+ <?x?> = 1
+end
+]]
+
+TEST [[
+local <!x!>
+while <?x?> do
+end
+]]
+
+TEST [[
+local <!x!>
+while x do
+ <?x?> = 1
+end
+]]
+
+TEST [[
+local <!x!>
+while x do
+ local x
+end
+<?x?> = 1
+]]
+
+TEST [[
+local <!x!>
+repeat
+ <?x?> = 1
+until true
+]]
+
+TEST [[
+local <!x!>
+repeat
+ local x
+until true
+<?x?> = 1
+]]
+
+TEST [[
+local <!x!>
+repeat
+until <?x?>
+]]
+
+TEST [[
+local x
+repeat
+ local <!x!>
+until <?x?>
+]]
+
+TEST [[
+local <!x!>
+function _()
+ local x
+end
+<?x?> = 1
+]]
+
+TEST [[
+local <!x!>
+return function ()
+ <?x?> = 1
+end
+]]
+
+TEST [[
+local <!x!>
+local x = function ()
+ <?x?> = 1
+end
+]]
diff --git a/server/test/implementation/set.lua b/server/test/implementation/set.lua
new file mode 100644
index 00000000..5c4a1a2e
--- /dev/null
+++ b/server/test/implementation/set.lua
@@ -0,0 +1,31 @@
+TEST [[
+<!x!> = 1
+<?x?> = 1
+]]
+
+TEST [[
+global = 1
+do
+ <!global!> = 2
+end
+<?global?> = 3
+]]
+
+TEST [[
+<!x!> = 1
+do
+ local x = 1
+end
+<?x?> = 1
+]]
+
+TEST [[
+x = 1
+do
+ local x = 1
+ do
+ <!x!> = 2
+ end
+ <?x?> = 1
+end
+]]
diff --git a/server/test/implementation/table.lua b/server/test/implementation/table.lua
new file mode 100644
index 00000000..13a3b555
--- /dev/null
+++ b/server/test/implementation/table.lua
@@ -0,0 +1,6 @@
+TEST [[
+local t = {
+ <!x!> = 1,
+}
+t.<?x?> = 1
+]]
diff --git a/server/test/main.lua b/server/test/main.lua
new file mode 100644
index 00000000..c33526c6
--- /dev/null
+++ b/server/test/main.lua
@@ -0,0 +1,31 @@
+require 'filesystem'
+ROOT = fs.current_path()
+package.path = (ROOT / 'src' / '?.lua'):string()
+ .. ';' .. (ROOT / 'src' / '?' / 'init.lua'):string()
+ .. ';' .. (ROOT / 'test' / '?.lua'):string()
+ .. ';' .. (ROOT / 'test' / '?' / 'init.lua'):string()
+
+log = require 'log'
+log.init(ROOT, ROOT / 'log' / 'test.log')
+log.debug('测试开始')
+
+require 'utility'
+require 'global_protect'
+
+local function main()
+ local function test(name)
+ local clock = os.clock()
+ print(('测试[%s]...'):format(name))
+ require(name)
+ print(('测试[%s]用时[%.3f]'):format(name, os.clock() - clock))
+ end
+
+ test 'definition'
+ test 'implementation'
+
+ print('测试完成')
+end
+
+main()
+
+log.debug('测试完成')