diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2021-09-15 20:31:07 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2021-09-15 20:31:07 +0800 |
commit | c3fc3c4631c8f69cb7250d8e2accd9ac0d8a0fb4 (patch) | |
tree | a2ff2884db41d89f6fff65d8323ff442924431ad /test/definition | |
parent | e70f82c0534c8973b3ad809a5ad72919412a832b (diff) | |
download | lua-language-server-c3fc3c4631c8f69cb7250d8e2accd9ac0d8a0fb4.zip |
update
Diffstat (limited to 'test/definition')
-rw-r--r-- | test/definition/init.lua | 37 |
1 files changed, 7 insertions, 30 deletions
diff --git a/test/definition/init.lua b/test/definition/init.lua index 85bcd5d5..992744d5 100644 --- a/test/definition/init.lua +++ b/test/definition/init.lua @@ -1,23 +1,10 @@ local core = require 'core.definition' local files = require 'files' local vm = require 'vm' +local catch = require 'catch' 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 @@ -36,15 +23,11 @@ end function TEST(script) files.removeAll() - script = script:gsub('\n', '\r\n') - 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 newScript, catched = catch(script, '!?') - local results = core('', pos) + files.setText('', newScript) + + local results = core('', catched['?'][1][1]) if results then local positions = {} for i, result in ipairs(results) do @@ -52,15 +35,9 @@ function TEST(script) positions[i] = { result.target.start, result.target.finish } end end - if not founded(target, positions) then - core('', pos) - end - assert(founded(target, positions)) + assert(founded(catched['!'], positions)) else - if #target ~= 0 then - core('', pos) - end - assert(#target == 0) + assert(#catched['!'] == 0) end end |