diff --git a/test/indentmini_spec.lua b/test/indentmini_spec.lua index f87165e..90e1415 100644 --- a/test/indentmini_spec.lua +++ b/test/indentmini_spec.lua @@ -1,4 +1,3 @@ -local api = vim.api require('indentmini').setup() local channel, job_id @@ -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' }) @@ -53,26 +41,21 @@ 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 () + after_each(function() clean() end) @@ -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 ', @@ -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()', @@ -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)