aboutsummaryrefslogtreecommitdiff
path: root/test/functional/ui/decorations_spec.lua
diff options
context:
space:
mode:
authorBjörn Linse <bjorn.linse@gmail.com>2020-09-21 10:37:28 +0200
committerBjörn Linse <bjorn.linse@gmail.com>2020-10-10 15:16:45 +0200
commit0b615dae073c14078c0a92b8aaed1da24575afcf (patch)
treed46cec554e489a92ed0d81ea6c5780d9c27dd87e /test/functional/ui/decorations_spec.lua
parent11ec53e558b547bbe49c93d206a8e4ab4247511b (diff)
downloadrneovim-0b615dae073c14078c0a92b8aaed1da24575afcf.tar.gz
rneovim-0b615dae073c14078c0a92b8aaed1da24575afcf.tar.bz2
rneovim-0b615dae073c14078c0a92b8aaed1da24575afcf.zip
api: multiple decoration providers at once
Diffstat (limited to 'test/functional/ui/decorations_spec.lua')
-rw-r--r--test/functional/ui/decorations_spec.lua118
1 files changed, 118 insertions, 0 deletions
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)