diff options
Diffstat (limited to 'server/test/definition/init.lua')
-rw-r--r-- | server/test/definition/init.lua | 55 |
1 files changed, 41 insertions, 14 deletions
diff --git a/server/test/definition/init.lua b/server/test/definition/init.lua index 1de41c57..de503c81 100644 --- a/server/test/definition/init.lua +++ b/server/test/definition/init.lua @@ -3,26 +3,52 @@ local parser = require 'parser' rawset(_G, 'TEST', true) -function TEST(script) - local start = script:find('<!', 1, true) - local finish = script:find('!>', 1, true) - if start and finish then - start = start + 2 - finish = finish - 1 +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 + break + 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 + if #results == 0 then + return true + else + return false end +end + +function TEST(script) + local target = catch_target(script) local pos = script:find('<?', 1, true) + 2 local new_script = script:gsub('<[!?]', ' '):gsub('[!?]>', ' ') local ast, err = parser:ast(new_script) assert(ast) - local suc, a, b = matcher.definition(ast, pos) - if start and finish then - assert(suc == true) - assert(a == start) - assert(b == finish) - else - assert(suc == false) - end + local suc, result = matcher.definition(ast, pos) + assert(suc) + assert(founded(target, result)) end require 'definition.set' @@ -30,4 +56,5 @@ require 'definition.local' require 'definition.arg' require 'definition.function' require 'definition.table' +require 'definition.method' require 'definition.bug' |