diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2019-11-23 00:05:30 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2019-11-23 00:05:30 +0800 |
commit | 6da2b175e20ed3c03b0dfcfc9046de1e0e5d4444 (patch) | |
tree | fdc22d78150fd1c5edc46732c8b151ccfefb519f /test-beta/definition | |
parent | d0ff66c9abe9d6abbca12fd811e0c3cb69c1033a (diff) | |
download | lua-language-server-6da2b175e20ed3c03b0dfcfc9046de1e0e5d4444.zip |
正路目录
Diffstat (limited to 'test-beta/definition')
-rw-r--r-- | test-beta/definition/arg.lua | 19 | ||||
-rw-r--r-- | test-beta/definition/bug.lua | 102 | ||||
-rw-r--r-- | test-beta/definition/call.lua | 8 | ||||
-rw-r--r-- | test-beta/definition/emmy.lua | 91 | ||||
-rw-r--r-- | test-beta/definition/function.lua | 24 | ||||
-rw-r--r-- | test-beta/definition/init.lua | 67 | ||||
-rw-r--r-- | test-beta/definition/label.lua | 29 | ||||
-rw-r--r-- | test-beta/definition/local.lua | 195 | ||||
-rw-r--r-- | test-beta/definition/method.lua | 31 | ||||
-rw-r--r-- | test-beta/definition/set.lua | 40 | ||||
-rw-r--r-- | test-beta/definition/special.lua | 124 | ||||
-rw-r--r-- | test-beta/definition/table.lua | 135 |
12 files changed, 865 insertions, 0 deletions
diff --git a/test-beta/definition/arg.lua b/test-beta/definition/arg.lua new file mode 100644 index 00000000..9e88b2bf --- /dev/null +++ b/test-beta/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/test-beta/definition/bug.lua b/test-beta/definition/bug.lua new file mode 100644 index 00000000..823db46d --- /dev/null +++ b/test-beta/definition/bug.lua @@ -0,0 +1,102 @@ +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 [[ +self.results = { + <!labels!> = {}, +} +self[self.results.<?labels?>] = lbl +]] + +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/test-beta/definition/call.lua b/test-beta/definition/call.lua new file mode 100644 index 00000000..42502f40 --- /dev/null +++ b/test-beta/definition/call.lua @@ -0,0 +1,8 @@ +TEST [[ +function f() + local <!x!> + return <!x!> +end +local <!y!> = f() +print(<?y?>) +]] diff --git a/test-beta/definition/emmy.lua b/test-beta/definition/emmy.lua new file mode 100644 index 00000000..ee8fa6a7 --- /dev/null +++ b/test-beta/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/test-beta/definition/function.lua b/test-beta/definition/function.lua new file mode 100644 index 00000000..ce20f50b --- /dev/null +++ b/test-beta/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/test-beta/definition/init.lua b/test-beta/definition/init.lua new file mode 100644 index 00000000..645765a2 --- /dev/null +++ b/test-beta/definition/init.lua @@ -0,0 +1,67 @@ +local core = require 'core.definition' +local files = require 'files' + +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) + files.removeAll() + 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('[!?]>', ' ') + files.setText('', new_script) + + local results = core('', pos) + if results then + local positions = {} + for i, result in ipairs(results) do + positions[i] = { result.target.start, result.target.finish } + end + assert(founded(target, positions)) + else + assert(#target == 0) + end +end + +require 'definition.local' +require 'definition.set' +require 'definition.arg' +require 'definition.function' +require 'definition.table' +require 'definition.method' +require 'definition.label' +require 'definition.call' +require 'definition.bug' +require 'definition.special' +--require 'definition.emmy' diff --git a/test-beta/definition/label.lua b/test-beta/definition/label.lua new file mode 100644 index 00000000..205915b6 --- /dev/null +++ b/test-beta/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/test-beta/definition/local.lua b/test-beta/definition/local.lua new file mode 100644 index 00000000..4153bfa0 --- /dev/null +++ b/test-beta/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/test-beta/definition/method.lua b/test-beta/definition/method.lua new file mode 100644 index 00000000..aa7aacdc --- /dev/null +++ b/test-beta/definition/method.lua @@ -0,0 +1,31 @@ +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 +]] diff --git a/test-beta/definition/set.lua b/test-beta/definition/set.lua new file mode 100644 index 00000000..f36be078 --- /dev/null +++ b/test-beta/definition/set.lua @@ -0,0 +1,40 @@ +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?>) +]] diff --git a/test-beta/definition/special.lua b/test-beta/definition/special.lua new file mode 100644 index 00000000..6bbf104c --- /dev/null +++ b/test-beta/definition/special.lua @@ -0,0 +1,124 @@ +TEST [[ +_ENV.<!x!> = 1 +print(<?x?>) +]] + +TEST [[ +_G.<!x!> = 1 +print(<?x?>) +]] + +TEST [[ +<!rawset(_G, 'x', 1)!> +print(<?x?>) +]] + +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 +function mt:<!method1!>() +end + +setmetatable(api, { __index = mt }) +api:<?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?>() +]] + +-- TODO +--TEST [[ +--local mt = {} +--function mt:<!x!>() +--end +-- +--local obj = setmetatable({}, {__index = mt}) +--function obj:x() +--end +-- +--mt:<?x?>() +--]] + +-- TODO 通过代码执行顺序来判断 +--TEST [[ +--local mt = {} +--function mt:x() +--end +-- +--local obj = setmetatable({}, {__index = mt}) +--function obj:<!x!>() +--end +-- +--obj:<?x?>() +--]] diff --git a/test-beta/definition/table.lua b/test-beta/definition/table.lua new file mode 100644 index 00000000..34078413 --- /dev/null +++ b/test-beta/definition/table.lua @@ -0,0 +1,135 @@ +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, +} +t.<?insert?>() +]] + +TEST[[ +local t;t = { + <!insert!> = 1, +} +t.<?insert?>() +]] + +TEST[[ +local t;t = { + <!insert!> = 1, +} +t.<?insert?>() +]] + +--TEST[[ +--local t = { +-- <!insert!> = 1, +--} +--y.<?insert?>() +--]] + +--TEST[[ +--local t = { +-- <!insert!> = 1, +--} +--local y = { +-- insert = 1, +--} +--t.<?insert?>() +--]] |