summaryrefslogtreecommitdiff
path: root/test/highlight/init.lua
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2021-09-22 20:03:07 +0800
committer最萌小汐 <sumneko@hotmail.com>2021-09-22 20:03:07 +0800
commiteda1918a82894137c58e19a7fdb1301e3c2bbf30 (patch)
tree79fde9c5cc04b3bdb0cb9dc9cc64583e67ccd163 /test/highlight/init.lua
parent9c79a00b41e1eff3a04a3daea6762ece89bb60eb (diff)
downloadlua-language-server-eda1918a82894137c58e19a7fdb1301e3c2bbf30.zip
update
Diffstat (limited to 'test/highlight/init.lua')
-rw-r--r--test/highlight/init.lua38
1 files changed, 10 insertions, 28 deletions
diff --git a/test/highlight/init.lua b/test/highlight/init.lua
index 2bf639fa..7faa9e08 100644
--- a/test/highlight/init.lua
+++ b/test/highlight/init.lua
@@ -1,22 +1,6 @@
local core = require 'core.highlight'
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 = start + 2,
- finish = finish - 2,
- }
- cur = finish + 1
- end
- return list
-end
+local catch = require 'catch'
local function founded(targets, results)
if #targets ~= #results then
@@ -35,20 +19,18 @@ local function founded(targets, results)
end
function TEST(script)
- local target = catch_target(script)
- for _, enter in ipairs(target) do
- local start, finish = enter.start, enter.finish
- files.removeAll()
+ files.removeAll()
+ local newScript, catched = catch(script, '!')
+ files.setText('', newScript)
+ for _, enter in ipairs(catched['!']) do
+ local start, finish = enter[1], enter[2]
local pos = (start + finish) // 2
- local new_script = script:gsub('<[!?~]', ' '):gsub('[!?~]>', ' ')
- files.setText('', new_script)
-
local positions = core('', pos)
- if positions then
- assert(founded(target, positions))
- else
- assert(#target == 0)
+ local results = {}
+ for _, position in ipairs(positions) do
+ results[#results+1] = { position.start, position.finish }
end
+ assert(founded(catched['!'], results))
end
end