diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2021-09-22 15:23:04 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2021-09-22 15:23:04 +0800 |
commit | a11c1e47a1bbe1004333143431f901ab8ecde4dd (patch) | |
tree | d4d0e675997b98d59efffe4b6dda41c3f0c837c6 /test/crossfile | |
parent | 1ab04aca1e0a3ad9d76aa11fa4e8eefe9781624b (diff) | |
download | lua-language-server-a11c1e47a1bbe1004333143431f901ab8ecde4dd.zip |
cleanup
Diffstat (limited to 'test/crossfile')
-rw-r--r-- | test/crossfile/allreferences.lua | 5 | ||||
-rw-r--r-- | test/crossfile/definition.lua | 79 | ||||
-rw-r--r-- | test/crossfile/references.lua | 66 |
3 files changed, 41 insertions, 109 deletions
diff --git a/test/crossfile/allreferences.lua b/test/crossfile/allreferences.lua index 056fa416..67eb893c 100644 --- a/test/crossfile/allreferences.lua +++ b/test/crossfile/allreferences.lua @@ -9,10 +9,9 @@ TEST { { path = 'lib.lua', content = [[ - return <~function~> () - end + return <!<?function?> () + end!> ]], - target = {22, 50}, }, } diff --git a/test/crossfile/definition.lua b/test/crossfile/definition.lua index 66e9b269..01bf0202 100644 --- a/test/crossfile/definition.lua +++ b/test/crossfile/definition.lua @@ -3,26 +3,10 @@ local furi = require 'file-uri' local core = require 'core.definition' local config = require 'config' local platform = require 'bee.platform' +local catch = require 'catch' rawset(_G, 'TEST', true) -local function catch_target(script, sep) - local list = {} - local cur = 1 - local cut = 0 - while true do - local start, finish = script:find(('<%%%s.-%%%s>'):format(sep, sep), cur) - if not start then - break - end - list[#list+1] = { start - cut, finish - 4 - cut } - cur = finish + 1 - cut = cut + 4 - end - local new_script = script:gsub(('<%%%s(.-)%%%s>'):format(sep, sep), '%1') - return new_script, list -end - local function founded(targets, results) if #targets ~= #results then return false @@ -50,32 +34,26 @@ function TEST(datas) local sourceUri for i, data in ipairs(datas) do local uri = furi.encode(data.path) - local new, list = catch_target(data.content, '!') - if new ~= data.content or data.target then - if data.target then - targetList[#targetList+1] = { - data.target[1], - data.target[2], - uri, - } - else - for _, position in ipairs(list) do - targetList[#targetList+1] = { - position[1], - position[2], - uri, - } - end - end - data.content = new + local newScript, catched = catch(data.content, '!?~') + for _, position in ipairs(catched['!'] or {}) do + targetList[#targetList+1] = { + position[1], + position[2], + uri, + } + end + for _, position in ipairs(catched['~'] or {}) do + targetList[#targetList+1] = { + position[1], + position[2], + uri, + } end - new, list = catch_target(data.content, '?') - if new ~= data.content then - sourceList = list + if catched['?'] or catched['~'] then + sourceList = catched['?'] or catched['~'] sourceUri = uri - data.content = new end - files.setText(uri, data.content) + files.setText(uri, newScript) end local sourcePos = (sourceList[1][1] + sourceList[1][2]) // 2 @@ -98,8 +76,7 @@ end TEST { { path = 'a.lua', - content = '', - target = {0, 0}, + content = '<!!>', }, { path = 'b.lua', @@ -110,8 +87,7 @@ TEST { TEST { { path = 'aaa/bbb.lua', - content = '', - target = {0, 0}, + content = '<!!>', }, { path = 'b.lua', @@ -122,8 +98,7 @@ TEST { TEST { { path = '@bbb.lua', - content = '', - target = {0, 0}, + content = '<!!>', }, { path = 'b.lua', @@ -134,8 +109,7 @@ TEST { TEST { { path = 'aaa/bbb.lua', - content = '', - target = {0, 0}, + content = '<!!>', }, { path = 'b.lua', @@ -150,8 +124,7 @@ TEST { }, { path = 'b.lua', - content = 'local <?t?> = require "a"', - target = {7, 7}, + content = 'local <~t~> = require "a"', }, } @@ -176,8 +149,7 @@ TEST { }, { path = 'b.lua', - content = 'local <?t?> = require "a"', - target = {7, 7}, + content = 'local <~t~> = require "a"', }, } @@ -245,9 +217,8 @@ TEST { { path = 'b.lua', content = [[ - local <?t?> = require 'a' + local <~t~> = require 'a' ]], - target = {19, 19}, }, } diff --git a/test/crossfile/references.lua b/test/crossfile/references.lua index 6c28b34b..145792b5 100644 --- a/test/crossfile/references.lua +++ b/test/crossfile/references.lua @@ -1,6 +1,7 @@ local files = require 'files' local furi = require 'file-uri' local core = require 'core.reference' +local catch = require 'catch' rawset(_G, 'TEST', true) @@ -32,21 +33,6 @@ local function eq(a, b) return a == b end -local function catch_target(script, sep) - local list = {} - local cur = 1 - while true do - local start, finish = script:find(('<%%%s.-%%%s>'):format(sep, sep), cur) - if not start then - break - end - list[#list+1] = { start + 2, finish - 2 } - cur = finish + 1 - end - local new_script = script:gsub(('<%%%s(.-)%%%s>'):format(sep, sep), ' %1 ') - return new_script, list -end - local function founded(targets, results) if #targets ~= #results then return false @@ -74,37 +60,9 @@ function TEST(datas) local sourceUri for i, data in ipairs(datas) do local uri = furi.encode(data.path) - local new, list = catch_target(data.content, '!') - if new ~= data.content or data.target then - if data.target then - targetList[#targetList+1] = { - data.target[1], - data.target[2], - uri, - } - else - for _, position in ipairs(list) do - targetList[#targetList+1] = { - position[1], - position[2], - uri, - } - end - end - data.content = new - end - new, list = catch_target(data.content, '~') - if new ~= data.content then - sourceList = list - sourceUri = uri - data.content = new - end - new, list = catch_target(data.content, '?') - if new ~= data.content then - sourceList = list - sourceUri = uri - data.content = new - for _, position in ipairs(list) do + local newScript, catched = catch(data.content, '!?~') + if catched['!'] or catched['~'] then + for _, position in ipairs(catched['!'] + catched['~']) do targetList[#targetList+1] = { position[1], position[2], @@ -112,7 +70,11 @@ function TEST(datas) } end end - files.setText(uri, data.content) + if catched['?'] or catched['~'] then + sourceList = catched['?'] + catched['~'] + sourceUri = uri + end + files.setText(uri, newScript) end local sourcePos = (sourceList[1][1] + sourceList[1][2]) // 2 @@ -143,7 +105,7 @@ TEST { { path = 'a.lua', content = [[ - local <?f?> = require 'lib' + local <~f~> = require 'lib' ]], }, } @@ -158,7 +120,7 @@ TEST { { path = 'b.lua', content = [[ - print(<?ROOT?>) + print(<~ROOT~>) ]], }, } @@ -167,7 +129,7 @@ TEST { { path = 'a.lua', content = [[ - <?ROOT?> = 1 + <~ROOT~> = 1 ]], }, { @@ -183,7 +145,7 @@ TEST { path = 'a.lua', content = [[ local f = require 'lib' - local <?o?> = f() + local <~o~> = f() ]], }, { @@ -212,7 +174,7 @@ TEST { ---@class A local mt - function mt.<?f?>() + function mt.<~f~>() end ]] } |