diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2021-09-14 20:43:33 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2021-09-14 20:43:33 +0800 |
commit | 5a072004414ff1f8de416c62a4067774f72e7097 (patch) | |
tree | 098b490fadec58205a1c8f944ec590c957e86a1c /test | |
parent | 4d1b606cc875803cc07031c63cde351300ea664a (diff) | |
download | lua-language-server-5a072004414ff1f8de416c62a4067774f72e7097.zip |
cleanup
Diffstat (limited to 'test')
-rw-r--r-- | test/basic/noder.lua | 2 | ||||
-rw-r--r-- | test/catch.lua | 28 | ||||
-rw-r--r-- | test/references/init.lua | 27 |
3 files changed, 32 insertions, 25 deletions
diff --git a/test/basic/noder.lua b/test/basic/noder.lua index 4c0a1620..87b34e12 100644 --- a/test/basic/noder.lua +++ b/test/basic/noder.lua @@ -33,7 +33,7 @@ local function TEST(script) files.removeAll() local newScript, catched = catch(script, '?') files.setText('', newScript) - local source = getSource(catched[1][1]) + local source = getSource(catched['?'][1][1]) assert(source) local result = { id = noder.getID(source), diff --git a/test/catch.lua b/test/catch.lua index 910c368f..09b55929 100644 --- a/test/catch.lua +++ b/test/catch.lua @@ -1,3 +1,22 @@ +local mt = {} + +local function catchedTable() + return setmetatable({}, mt) +end + +function mt.__add(a, b) + if not a or not b then + return a or b + end + local t = catchedTable() + for _, v in ipairs(a) do + t[#t+1] = v + end + for _, v in ipairs(b) do + t[#t+1] = v + end + return t +end local function getLine(offset, lns) for i = 0, #lns do @@ -20,7 +39,7 @@ end ---@param script string ---@param sep string return function (script, sep) - local pattern = ('()<%%%s.-%%%s>()'):format(sep, sep) + local pattern = ('()<(%s).-%s>()'):format(sep, sep) local lns = {} lns[0] = 0 for pos in script:gmatch '()\n' do @@ -33,7 +52,7 @@ return function (script, sep) local list = {} local cuted = 0 local lastLine = 0 - for a, b in script:gmatch(pattern) do + for a, char, b in script:gmatch(pattern) do codes[#codes+1] = script:sub(pos, a - 1) codes[#codes+1] = script:sub(a + 2, b - 3) pos = b @@ -51,7 +70,10 @@ return function (script, sep) end local right = getPosition(b - 3, lns) - cuted cuted = cuted + 2 - list[#list+1] = { left, right } + if not list[char] then + list[char] = catchedTable() + end + list[char][#list[char]+1] = { left, right } end codes[#codes+1] = script:sub(pos) return table.concat(codes), list diff --git a/test/references/init.lua b/test/references/init.lua index 2fba92e5..a14f0a02 100644 --- a/test/references/init.lua +++ b/test/references/init.lua @@ -1,19 +1,6 @@ local core = require 'core.reference' local files = require 'files' - -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 catch = require 'catch' local function founded(targets, results) if #targets ~= #results then @@ -33,14 +20,12 @@ end function TEST(script) files.removeAll() - local expect = catch_target(script) - local start = script:find('<[?~]') - local finish = script:find('[?~]>') - local pos = (start + finish) // 2 + 1 - local new_script = script:gsub('<[!?~]', ' '):gsub('[!?~]>', ' ') - files.setText('', new_script) + local newScript, catched = catch(script, '[!?~]') + files.setText('', newScript) - local results = core('', pos) + local input = catched['?'] + catched['~'] + local expect = catched['!'] + catched['?'] + catched['~'] + local results = core('', input[1][1]) if results then local positions = {} for i, result in ipairs(results) do |