diff options
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' |