Skip to content

Commit

Permalink
test: fix test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
glepnir committed May 24, 2024
1 parent a432ba5 commit fcff107
Showing 1 changed file with 12 additions and 88 deletions.
100 changes: 12 additions & 88 deletions test/indentmini_spec.lua
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
local api = vim.api
require('indentmini').setup()

local channel, job_id
Expand All @@ -16,25 +15,14 @@ local function nvim_instance()
return vim.fn.sockconnect('pipe', address, { rpc = true })
end

local function nvim_set_cursor(line, col)
vim.rpcrequest(channel, 'nvim_win_set_cursor', 0, { line, col })
end

local function get_indent_ns()
local t = vim.rpcrequest(channel, 'nvim_get_namespaces')
for k, v in pairs(t) do
if k == 'IndentLine' then
return v
end
end
end

local function screen(lines)
if not channel then
channel = nvim_instance()
end
local current_dir = vim.fn.getcwd()
vim.rpcrequest(channel, 'nvim_set_option_value', 'rtp', current_dir, { scope = 'global' })
local current_dir = vim.uv.cwd()
local rtp = vim.rpcrequest(channel, 'nvim_get_option_value', 'rtp', {scope = 'global'})
rtp = ("%s,%s"):format(rtp, current_dir)
vim.rpcrequest(channel, 'nvim_set_option_value', 'rtp', rtp, { scope = 'global' })
vim.rpcrequest(channel, 'nvim_exec_lua', 'require("indentmini").setup({})', {})
vim.rpcrequest(channel, 'nvim_set_option_value', 'columns', 26, { scope = 'global' })
vim.rpcrequest(channel, 'nvim_set_option_value', 'lines', #lines + 2, { scope = 'global' })
Expand All @@ -53,24 +41,19 @@ local function screen(lines)
return vim.rpcrequest(channel, 'nvim_exec_lua', 'return vim.fn.screenstring(...)', { row, col })
end

local screen = function()
local cols = vim.rpcrequest(channel, 'nvim_get_option', 'columns')
local res = {}
for i = 1, #lines do
local line = ''
for j = 1, cols do
line = line .. screenstring(i, j)
end
res[#res + 1] = line
local cols = vim.rpcrequest(channel, 'nvim_get_option', 'columns')
local res = {}
for i = 1, #lines do
local line = ''
for j = 1, cols do
line = line .. screenstring(i, j)
end

return res
res[#res + 1] = line
end

return screen()
return res
end

--TODO(glepnir): after use vim.iter on on_win the vusted is hang at test
describe('indent mini', function()
after_each(function ()
clean()
Expand All @@ -91,9 +74,6 @@ describe('indent mini', function()
'end',
}
local screenstr = screen(lines)
-- for _, line in ipairs(screenstr) do
-- print(vim.inspect(line))
-- end
local expected = {
'local function test() ',
'│ local a = 10 ',
Expand All @@ -110,23 +90,6 @@ describe('indent mini', function()
assert.same(expected, screenstr)
end)

it('not work when line has tab character', function()
local lines = {
'functio test_tab()',
'\tprint("hello")',
'\tprint("world")',
'end',
}
local screenstr = screen(lines)
local expected = {
'functio test_tab() ',
' print("hello") ',
' print("world") ',
'end ',
}
assert.same(expected, screenstr)
end)

it('works on blank line', function()
local lines = {
'local function test()',
Expand Down Expand Up @@ -160,43 +123,4 @@ describe('indent mini', function()
}
assert.same(expected, screenstr)
end)

-- it('works on highlight current level', function()
-- local lines = {
-- 'local function test_b()',
-- ' local a = 10 ',
-- ' ',
-- ' if true then ',
-- ' if true then ',
-- ' local b = 20 ',
-- ' ',
-- ' while true do ',
-- ' print("hello") ',
-- ' end ',
-- ' ',
-- ' print("here") ',
-- ' end ',
-- ' end ',
-- 'end ',
-- ' ',
-- 'local function test() ',
-- ' local a = 10 ',
-- ' ',
-- ' if true then ',
-- ' if true then ',
-- ' local b = 20 ',
-- ' ',
-- ' while true do ',
-- ' print("hello") ',
-- ' end ',
-- ' ',
-- ' print("here") ',
-- ' end ',
-- ' end ',
-- 'end ',
-- }
-- screen(lines)
-- nvim_set_cursor(6, 8)
-- assert.same(7, count_current_hl())
-- end)
end)

0 comments on commit fcff107

Please sign in to comment.