diff options
Diffstat (limited to 'test/functional')
-rw-r--r-- | test/functional/helpers.lua | 19 | ||||
-rw-r--r-- | test/functional/lua/buffer_updates_spec.lua | 18 | ||||
-rw-r--r-- | test/functional/ui/decorations_spec.lua | 118 |
3 files changed, 139 insertions, 16 deletions
diff --git a/test/functional/helpers.lua b/test/functional/helpers.lua index e4fb95442c..99cbf30c7c 100644 --- a/test/functional/helpers.lua +++ b/test/functional/helpers.lua @@ -22,6 +22,7 @@ local ok = global_helpers.ok local sleep = global_helpers.sleep local tbl_contains = global_helpers.tbl_contains local write_file = global_helpers.write_file +local fail = global_helpers.fail local module = { NIL = mpack.NIL, @@ -592,6 +593,24 @@ function module.expect_any(contents) return ok(nil ~= string.find(module.curbuf_contents(), contents, 1, true)) end +function module.expect_events(expected, received, kind) + local inspect = require'vim.inspect' + if not pcall(eq, expected, received) then + local msg = 'unexpected '..kind..' received.\n\n' + + msg = msg .. 'received events:\n' + for _, e in ipairs(received) do + msg = msg .. ' ' .. inspect(e) .. ';\n' + end + msg = msg .. '\nexpected events:\n' + for _, e in ipairs(expected) do + msg = msg .. ' ' .. inspect(e) .. ';\n' + end + fail(msg) + end + return received +end + -- Checks that the Nvim session did not terminate. function module.assert_alive() assert(2 == module.eval('1+1'), 'crash? request failed') diff --git a/test/functional/lua/buffer_updates_spec.lua b/test/functional/lua/buffer_updates_spec.lua index fa31880782..7e4de7c39a 100644 --- a/test/functional/lua/buffer_updates_spec.lua +++ b/test/functional/lua/buffer_updates_spec.lua @@ -1,8 +1,6 @@ -- Test suite for testing interactions with API bindings local helpers = require('test.functional.helpers')(after_each) -local inspect = require'vim.inspect' - local command = helpers.command local meths = helpers.meths local funcs = helpers.funcs @@ -12,6 +10,7 @@ local fail = helpers.fail local exec_lua = helpers.exec_lua local feed = helpers.feed local deepcopy = helpers.deepcopy +local expect_events = helpers.expect_events local origlines = {"original line 1", "original line 2", @@ -297,20 +296,7 @@ describe('lua: nvim_buf_attach on_bytes', function() local verify_name = "test1" local function check_events(expected) local events = exec_lua("return get_events(...)" ) - - if not pcall(eq, expected, events) then - local msg = 'unexpected byte updates received.\n\n' - - msg = msg .. 'received events:\n' - for _, e in ipairs(events) do - msg = msg .. ' ' .. inspect(e) .. ';\n' - end - msg = msg .. '\nexpected events:\n' - for _, e in ipairs(expected) do - msg = msg .. ' ' .. inspect(e) .. ';\n' - end - fail(msg) - end + expect_events(expected, events, "byte updates") if not verify then return diff --git a/test/functional/ui/decorations_spec.lua b/test/functional/ui/decorations_spec.lua new file mode 100644 index 0000000000..304c5aecb1 --- /dev/null +++ b/test/functional/ui/decorations_spec.lua @@ -0,0 +1,118 @@ +local helpers = require('test.functional.helpers')(after_each) +local Screen = require('test.functional.ui.screen') + +local clear = helpers.clear +local feed = helpers.feed +local insert = helpers.insert +local exec_lua = helpers.exec_lua +local expect_events = helpers.expect_events + +describe('decorations provider', function() + local screen + before_each(function() + clear() + screen = Screen.new(40, 8) + screen:attach() + screen:set_default_attr_ids({ + [1] = {bold=true, foreground=Screen.colors.Blue}, + }) + end) + + local mudholland = [[ + // just to see if there was an accident + // on Mulholland Drive + try_start(); + bufref_T save_buf; + switch_buffer(&save_buf, buf); + posp = getmark(mark, false); + restore_buffer(&save_buf); ]] + + local function setup_provider(code) + exec_lua ([[ + local a = vim.api + test1 = a.nvim_create_namespace "test1" + ]] .. (code or [[ + beamtrace = {} + function on_do(kind, ...) + table.insert(beamtrace, {kind, ...}) + end + ]]) .. [[ + a.nvim_set_decoration_provider( + test1, { + on_start = on_do; on_buf = on_do; + on_win = on_do; on_line = on_do; + on_end = on_do; + }) + ]]) + end + + local function check_trace(expected) + local actual = exec_lua [[ local b = beamtrace beamtrace = {} return b ]] + expect_events(expected, actual, "beam trace") + end + + it('leaves a trace', function() + insert(mudholland) + + setup_provider() + + screen:expect{grid=[[ + // just to see if there was an accident | + // on Mulholland Drive | + try_start(); | + bufref_T save_buf; | + switch_buffer(&save_buf, buf); | + posp = getmark(mark, false); | + restore_buffer(&save_buf);^ | + | + ]]} + check_trace { + { "start", 4, 40 }; + { "win", 1000, 1, 0, 8 }; + { "line", 1000, 1, 0 }; + { "line", 1000, 1, 1 }; + { "line", 1000, 1, 2 }; + { "line", 1000, 1, 3 }; + { "line", 1000, 1, 4 }; + { "line", 1000, 1, 5 }; + { "line", 1000, 1, 6 }; + { "end", 4 }; + } + + feed "iü<esc>" + screen:expect{grid=[[ + // just to see if there was an accident | + // on Mulholland Drive | + try_start(); | + bufref_T save_buf; | + switch_buffer(&save_buf, buf); | + posp = getmark(mark, false); | + restore_buffer(&save_buf);^ü | + | + ]]} + check_trace { + { "start", 5, 10 }; + { "buf", 1 }; + { "win", 1000, 1, 0, 8 }; + { "line", 1000, 1, 6 }; + { "end", 5 }; + } + end) + + it('single provider', function() + insert(mudholland) + setup_provider [[ + local hl = a.nvim_get_hl_id_by_name "ErrorMsg" + function do_it(event, ...) + if event == "line" then + local win, buf, line = ... + a.nvim_buf_set_extmark(buf, test_ns, line, line, + { end_line = line, end_col = line+1, + hl_group = hl, + ephemeral = true + }) + end + end + ]] + end) +end) |