diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2018-11-20 13:35:16 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2018-11-20 13:35:16 +0800 |
commit | c6e00ba82ab0e15fbbaad59ef91cfb08caeb6f7d (patch) | |
tree | 808fde71dbcd2a3d6436d381e2e6100e78281c29 /test/implementation | |
parent | 4321271853b484150d37b9908fdab46fde0ad8fa (diff) | |
download | lua-language-server-c6e00ba82ab0e15fbbaad59ef91cfb08caeb6f7d.zip |
支持多个实现
Diffstat (limited to 'test/implementation')
-rw-r--r-- | test/implementation/bug.lua | 9 | ||||
-rw-r--r-- | test/implementation/init.lua | 39 |
2 files changed, 43 insertions, 5 deletions
diff --git a/test/implementation/bug.lua b/test/implementation/bug.lua index b0e890ca..8f80030b 100644 --- a/test/implementation/bug.lua +++ b/test/implementation/bug.lua @@ -13,3 +13,12 @@ function _(<!x!>) <?x?> = 1 end ]] + +TEST [[ +local <!x!> +if 1 then + x = 1 +else + <?x?> = 2 +end +]] diff --git a/test/implementation/init.lua b/test/implementation/init.lua index 3033f340..855bf255 100644 --- a/test/implementation/init.lua +++ b/test/implementation/init.lua @@ -2,16 +2,45 @@ local matcher = require 'matcher' 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) + while true do + local target = table.remove(targets) + if not target then + return true + end + for i, result in ipairs(results) do + if target[1] == result[1] and target[2] == result[2] then + table.remove(results, i) + goto CONTINUE + end + end + do return false end + ::CONTINUE:: + end +end + function TEST(script) - local start = script:find('<!', 1, true) + 2 - local finish = script:find('!>', 1, true) - 1 + local target = catch_target(script) local pos = script:find('<?', 1, true) + 2 local new_script = script:gsub('<[!?]', ' '):gsub('[!?]>', ' ') - local suc, a, b = matcher.implementation(new_script, pos) + local suc, result = matcher.implementation(new_script, pos) assert(suc) - assert(a == start) - assert(b == finish) + assert(founded(target, result)) end require 'implementation.set' |