summaryrefslogtreecommitdiff
path: root/server-beta/test/definition
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2019-09-24 20:45:45 +0800
committer最萌小汐 <sumneko@hotmail.com>2019-09-24 20:45:45 +0800
commitff4f52962550da919b737f0f78bbaa4a507d6ba9 (patch)
treeb6d6e3f6224ac81cec6195f43a2fe238a60a3eee /server-beta/test/definition
parent5c8022df4adaaf813812845f97d9cb9d7c6d4fcc (diff)
downloadlua-language-server-ff4f52962550da919b737f0f78bbaa4a507d6ba9.zip
导入测试
Diffstat (limited to 'server-beta/test/definition')
-rw-r--r--server-beta/test/definition/arg.lua19
-rw-r--r--server-beta/test/definition/bug.lua90
-rw-r--r--server-beta/test/definition/emmy.lua91
-rw-r--r--server-beta/test/definition/function.lua24
-rw-r--r--server-beta/test/definition/init.lua61
-rw-r--r--server-beta/test/definition/label.lua29
-rw-r--r--server-beta/test/definition/local.lua195
-rw-r--r--server-beta/test/definition/method.lua140
-rw-r--r--server-beta/test/definition/set.lua50
-rw-r--r--server-beta/test/definition/table.lua114
10 files changed, 813 insertions, 0 deletions
diff --git a/server-beta/test/definition/arg.lua b/server-beta/test/definition/arg.lua
new file mode 100644
index 00000000..9e88b2bf
--- /dev/null
+++ b/server-beta/test/definition/arg.lua
@@ -0,0 +1,19 @@
+TEST [[
+local function xx (<!xx!>)
+ <?xx?>()
+end
+]]
+
+TEST [[
+local <!mt!>
+function mt:x()
+ <?self?>()
+end
+mt:x()
+]]
+
+TEST [[
+function mt:x(<!self!>)
+ <?self?>()
+end
+]]
diff --git a/server-beta/test/definition/bug.lua b/server-beta/test/definition/bug.lua
new file mode 100644
index 00000000..1d3ab02c
--- /dev/null
+++ b/server-beta/test/definition/bug.lua
@@ -0,0 +1,90 @@
+TEST [[
+local <!x!>
+function _(x)
+end
+function _()
+ <?x?>()
+end
+]]
+
+TEST [[
+function _(<!x!>)
+ do return end
+ <?x?>()
+end
+]]
+
+TEST [[
+local <!a!>
+function a:b()
+ a:b()
+ <?self?>()
+end
+]]
+
+TEST [[
+function _(...)
+ function _()
+ print(<?...?>)
+ end
+end
+]]
+
+TEST [[
+local <!a!>
+(<?a?> / b)()
+]]
+
+TEST [[
+local <!args!>
+io.load(root / <?args?>.source / 'API' / path)
+]]
+
+TEST [[
+obj[#<?obj?>+1] = {}
+]]
+
+TEST [[
+self = {
+ results = {
+ <!labels!> = {},
+ }
+}
+self[self.results.<?labels?>] = lbl
+]]
+
+TEST [[
+local mt = {}
+function mt:<!x!>()
+end
+mt:x()
+mt:<?x?>()
+]]
+
+TEST [[
+local function func(<!a!>)
+ x = {
+ xx(),
+ <?a?>,
+ }
+end
+]]
+
+TEST [[
+local <!x!>
+local t = {
+ ...,
+ <?x?>,
+}
+]]
+
+TEST [[
+local a
+local <!b!>
+return f(), <?b?>
+]]
+
+TEST [[
+local a = os.clock()
+local <?<!b!>?> = os.clock()
+]]
diff --git a/server-beta/test/definition/emmy.lua b/server-beta/test/definition/emmy.lua
new file mode 100644
index 00000000..ee8fa6a7
--- /dev/null
+++ b/server-beta/test/definition/emmy.lua
@@ -0,0 +1,91 @@
+TEST [[
+---@class <!A!>
+---@class B : <?A?>
+]]
+
+TEST [[
+---@class <!A!>
+---@type B|<?A?>
+]]
+
+TEST [[
+---@class A
+local mt = {}
+function mt:<!cast!>()
+end
+
+---@type A
+local obj
+obj:<?cast?>()
+]]
+
+TEST [[
+---@class A
+local <!mt!> = {}
+function mt:cast()
+end
+
+---@type A
+local <!obj!>
+<?obj?>:cast()
+]]
+
+TEST [[
+---@type A
+local <?<!obj!>?>
+
+---@class A
+local <!mt!>
+]]
+
+TEST [[
+---@type A
+local obj
+obj:<?func?>()
+
+---@class A
+local mt
+function mt:<!func!>()
+end
+]]
+
+TEST [[
+---@type A
+local obj
+obj:<?func?>()
+
+local mt = {}
+mt.__index = mt
+function mt:<!func!>()
+end
+---@class A
+local obj = setmetatable({}, mt)
+]]
+
+TEST [[
+---@alias <!B A!>
+---@type <?B?>
+]]
+
+TEST [[
+---@class <!Class!>
+---@param a <?Class?>
+]]
+
+TEST [[
+---@class Class
+---@field <!name string!>
+---@field id integer
+local mt = {}
+mt.<?name?>
+]]
+
+TEST [[
+---@class loli
+local unit
+
+function unit:<!pants!>()
+end
+
+---@see loli#<?pants?>
+]]
diff --git a/server-beta/test/definition/function.lua b/server-beta/test/definition/function.lua
new file mode 100644
index 00000000..ce20f50b
--- /dev/null
+++ b/server-beta/test/definition/function.lua
@@ -0,0 +1,24 @@
+
+TEST [[
+function <!x!> () end
+<?x?>()
+]]
+
+TEST [[
+local function <!x!> () end
+<?x?>()
+]]
+
+TEST [[
+local x
+local function <!x!> ()
+ <?x?>()
+end
+]]
+
+TEST [[
+local <!x!>
+function <!x!>()
+end
+<?x?>()
+]]
diff --git a/server-beta/test/definition/init.lua b/server-beta/test/definition/init.lua
new file mode 100644
index 00000000..5a80273c
--- /dev/null
+++ b/server-beta/test/definition/init.lua
@@ -0,0 +1,61 @@
+local core = require 'core.definition'
+local parser = require 'parser'
+
+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)
+ if #targets ~= #results then
+ return false
+ end
+ for _, target in ipairs(targets) do
+ for _, result in ipairs(results) do
+ if target[1] == result[1] and target[2] == result[2] then
+ goto NEXT
+ end
+ end
+ do return false end
+ ::NEXT::
+ end
+ return true
+end
+
+function TEST(script)
+ local target = catch_target(script)
+ local start = script:find('<?', 1, true)
+ local finish = script:find('?>', 1, true)
+ local pos = (start + finish) // 2 + 1
+ local new_script = script:gsub('<[!?]', ' '):gsub('[!?]>', ' ')
+ local ast = parser:compile(new_script, 'lua', 'Lua 5.3')
+ assert(ast)
+
+ local positions = core(ast, new_script, pos)
+ if positions then
+ assert(founded(target, positions))
+ else
+ assert(#target == 0)
+ end
+end
+
+require 'definition.set'
+require 'definition.local'
+require 'definition.arg'
+require 'definition.function'
+require 'definition.table'
+require 'definition.method'
+require 'definition.label'
+require 'definition.bug'
+require 'definition.emmy'
diff --git a/server-beta/test/definition/label.lua b/server-beta/test/definition/label.lua
new file mode 100644
index 00000000..4859d70e
--- /dev/null
+++ b/server-beta/test/definition/label.lua
@@ -0,0 +1,29 @@
+TEST [[
+::<!LABEL!>::
+goto <?LABEL?>
+]]
+
+TEST [[
+goto <?LABEL?>
+::<!LABEL!>::
+]]
+
+TEST [[
+::LABEL::
+function _()
+ goto <?LABEL?>
+end
+]]
+
+TEST [[
+do
+ goto <?LABEL?>
+end
+::<!LABEL!>::
+]]
+
+TEST [[
+::<!LABEL!>::
+goto <?LABEL?>
+::<!LABEL!>::
+]]
diff --git a/server-beta/test/definition/local.lua b/server-beta/test/definition/local.lua
new file mode 100644
index 00000000..4153bfa0
--- /dev/null
+++ b/server-beta/test/definition/local.lua
@@ -0,0 +1,195 @@
+TEST [[
+local <!x!>
+<?x?>()
+]]
+
+TEST [[
+local z, y, <!x!>
+<?x?>()
+]]
+
+TEST [[
+local <!x!> = 1
+<?x?>()
+]]
+
+TEST [[
+local z, y, <!x!> = 1
+<?x?>()
+]]
+
+TEST [[
+local x
+local <!x!>
+<?x?>()
+]]
+
+TEST [[
+local <!x!>
+do
+ <?x?>()
+end
+]]
+
+TEST [[
+local <!x!>
+do
+ local x
+end
+<?x?>()
+]]
+
+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?>()
+]]
+
+TEST [[
+local <!x!>
+if x then
+ <?x?>()
+elseif x then
+ local x
+else
+ local x
+end
+]]
+
+TEST [[
+local <!x!>
+for x = 1, 10 do
+end
+<?x?>()
+]]
+
+TEST [[
+local x
+for <!x!> = 1, 10 do
+ <?x?>()
+end
+]]
+
+TEST [[
+local <!x!>
+for x in x do
+end
+<?x?>()
+]]
+
+TEST [[
+local <!x!>
+for x in <?x?> do
+end
+]]
+
+TEST [[
+local x
+for <!x!> in x do
+ <?x?>()
+end
+]]
+
+TEST [[
+local x
+for z, y, <!x!> in x do
+ <?x?>()
+end
+]]
+
+TEST [[
+local <!x!>
+while <?x?> do
+end
+]]
+
+TEST [[
+local <!x!>
+while x do
+ <?x?>()
+end
+]]
+
+TEST [[
+local <!x!>
+while x do
+ local x
+end
+<?x?>()
+]]
+
+TEST [[
+local <!x!>
+repeat
+ <?x?>()
+until true
+]]
+
+TEST [[
+local <!x!>
+repeat
+ local x
+until true
+<?x?>()
+]]
+
+TEST [[
+local <!x!>
+repeat
+until <?x?>
+]]
+
+TEST [[
+local x
+repeat
+ local <!x!>
+until <?x?>
+]]
+
+TEST [[
+local <!x!>
+function _()
+ local x
+end
+<?x?>()
+]]
+
+TEST [[
+local <!x!>
+return function ()
+ <?x?>()
+end
+]]
+
+TEST [[
+local <!x!>
+local x = function ()
+ <?x?>()
+end
+]]
+
+TEST [[
+local <?<!x!>?>
+]]
diff --git a/server-beta/test/definition/method.lua b/server-beta/test/definition/method.lua
new file mode 100644
index 00000000..08b56f61
--- /dev/null
+++ b/server-beta/test/definition/method.lua
@@ -0,0 +1,140 @@
+TEST [[
+function mt:<!a!>()
+end
+function mt:b()
+ mt:<?a?>()
+end
+]]
+
+TEST [[
+function mt:<!m1!>()
+end
+function mt:m2()
+ self:<?m1?>()
+end
+]]
+
+TEST [[
+function mt:m3()
+ mt:<?m4?>()
+end
+function mt:<!m4!>()
+end
+]]
+
+TEST [[
+function mt:m3()
+ self:<?m4?>()
+end
+function mt:<!m4!>()
+end
+]]
+
+TEST [[
+local mt
+mt.__index = mt
+function mt:<!method1!>()
+end
+
+local obj = setmetatable({}, mt)
+obj:<?method1?>()
+]]
+
+TEST [[
+local mt
+mt.__index = mt
+function mt:<!method1!>()
+end
+
+local obj = setmetatable({}, mt)
+obj:<?method1?>()
+]]
+
+TEST [[
+local mt
+function mt:<!method1!>()
+end
+
+local obj = setmetatable({}, { __index = mt })
+obj:<?method1?>()
+]]
+
+TEST [[
+local mt
+local api
+function mt:<!method1!>()
+end
+
+setmetatable(api, { __index = mt })
+api:<?method1?>()
+]]
+
+TEST [[
+local mt
+function mt:x()
+ self.<?init?>()
+end
+
+local obj = setmetatable({}, { __index = mt })
+obj.<!init!> = 1
+obj:x()
+]]
+
+TEST [[
+local mt
+function mt:x()
+ self.<?init?>()
+end
+
+local obj = setmetatable({ <!init!> = 1 }, { __index = mt })
+obj:x()
+]]
+
+TEST [[
+local mt
+function mt:x()
+ self.a.<?out?>()
+end
+
+local obj = setmetatable({
+ a = {
+ <!out!> = 1,
+ }
+}, { __index = mt })
+obj:x()
+]]
+
+TEST [[
+local sm = setmetatable
+local mt
+mt.__index = mt
+function mt:<!method1!>()
+end
+
+local obj = sm({}, mt)
+obj:<?method1?>()
+]]
+
+TEST [[
+local mt = {}
+function mt:<!x!>()
+end
+
+local obj = setmetatable({}, {__index = mt})
+function obj:x()
+end
+
+mt:<?x?>()
+]]
+
+TEST [[
+local mt = {}
+function mt:x()
+end
+
+local obj = setmetatable({}, {__index = mt})
+function obj:<!x!>()
+end
+
+obj:<?x?>()
+]]
diff --git a/server-beta/test/definition/set.lua b/server-beta/test/definition/set.lua
new file mode 100644
index 00000000..44277d33
--- /dev/null
+++ b/server-beta/test/definition/set.lua
@@ -0,0 +1,50 @@
+TEST [[
+<!x!> = 1
+<?x?>()
+]]
+
+TEST [[
+do
+ <!global!> = 1
+end
+<?global?>()
+]]
+
+TEST [[
+<!x!> = 1
+do
+ local x = 1
+end
+<?x?>()
+]]
+
+TEST [[
+x = 1
+do
+ local <!x!> = 1
+ do
+ <!x!> = 2
+ end
+ <?x?>()
+end
+]]
+
+TEST [[
+<!x!> = 1
+if y then
+ <!x!> = 2
+else
+ <!x!> = 3
+end
+print(<?x?>)
+]]
+
+TEST [[
+_G.<!x!> = 1
+print(<?x?>)
+]]
+
+TEST [[
+rawset<!(_G, 'x', 1)!>
+print(<?x?>)
+]]
diff --git a/server-beta/test/definition/table.lua b/server-beta/test/definition/table.lua
new file mode 100644
index 00000000..90e7926f
--- /dev/null
+++ b/server-beta/test/definition/table.lua
@@ -0,0 +1,114 @@
+TEST [[
+local <!t!>
+a = {
+ <?t?>
+}
+]]
+
+TEST [[
+local t
+t.<!x!> = 1
+t.<?x?>()
+]]
+
+TEST [[
+t.<!x!> = 1
+t.<?x?>()
+]]
+
+TEST [[
+local <!t!>
+t.x = 1
+<?t?>.x = 1
+]]
+
+TEST [[
+t.<!x!> = 1
+t.<?x?>.y = 1
+]]
+
+TEST [[
+local t
+t.<!x!> = 1
+t.<?x?>()
+]]
+
+TEST [[
+local t
+t[<!1!>] = 1
+t[<?1?>]()
+]]
+
+TEST [[
+local t
+t[<!true!>] = 1
+t[<?true?>]()
+]]
+
+TEST [[
+local t
+t[<!"method"!>] = 1
+t[<?"method"?>]()
+]]
+
+TEST [[
+local t
+t[<!"longString"!>] = 1
+t[<?[==[longString]==]?>]()
+]]
+
+TEST [[
+local t
+t.<!x!> = 1
+t[<?'x'?>]()
+]]
+
+TEST [[
+local t
+t.<!a!> = 1
+t.<?a?>.b()
+]]
+
+TEST [[
+local t
+local <!x!>
+t[<?x?>]()
+]]
+
+TEST[[
+local <!t!>
+local _ = {
+ _ = <?t?>
+}
+]]
+
+TEST[[
+local <!t!>
+t {
+ _ = <?t?>.x
+}
+]]
+
+TEST[[
+local t = {
+ <!insert!> = 1,
+}
+t.<?insert?>()
+]]
+
+--TEST[[
+--local t = {
+-- <!insert!> = 1,
+--}
+--y.<?insert?>()
+--]]
+
+--TEST[[
+--local t = {
+-- <!insert!> = 1,
+--}
+--local y = {
+-- insert = 1,
+--}
+--t.<?insert?>()
+--]]