aboutsummaryrefslogtreecommitdiff
path: root/test/functional
diff options
context:
space:
mode:
Diffstat (limited to 'test/functional')
-rw-r--r--test/functional/api/extmark_spec.lua9
-rw-r--r--test/functional/lua/buffer_updates_spec.lua147
-rw-r--r--test/functional/ui/fold_spec.lua22
3 files changed, 143 insertions, 35 deletions
diff --git a/test/functional/api/extmark_spec.lua b/test/functional/api/extmark_spec.lua
index a2a188d036..ab913ba4a4 100644
--- a/test/functional/api/extmark_spec.lua
+++ b/test/functional/api/extmark_spec.lua
@@ -100,6 +100,15 @@ describe('API/extmarks', function()
ns2 = request('nvim_create_namespace', "my-fancy-plugin2")
end)
+ it("can end extranges past final newline using end_col = 0", function()
+ set_extmark(ns, marks[1], 0, 0, {
+ end_col = 0,
+ end_line = 1
+ })
+ eq("end_col value outside range",
+ pcall_err(set_extmark, ns, marks[2], 0, 0, { end_col = 1, end_line = 1 }))
+ end)
+
it('adds, updates and deletes marks', function()
local rv = set_extmark(ns, marks[1], positions[1][1], positions[1][2])
eq(marks[1], rv)
diff --git a/test/functional/lua/buffer_updates_spec.lua b/test/functional/lua/buffer_updates_spec.lua
index 5be47070a7..439cc12192 100644
--- a/test/functional/lua/buffer_updates_spec.lua
+++ b/test/functional/lua/buffer_updates_spec.lua
@@ -5,6 +5,7 @@ local inspect = require'vim.inspect'
local command = helpers.command
local meths = helpers.meths
+local funcs = helpers.funcs
local clear = helpers.clear
local eq = helpers.eq
local fail = helpers.fail
@@ -256,9 +257,9 @@ describe('lua: nvim_buf_attach on_bytes', function()
-- assert the wrong thing), but masks errors with unflushed lines (as
-- nvim_buf_get_offset forces a flush of the memline). To be safe run the
-- test both ways.
- local function setup_eventcheck(verify)
- meths.buf_set_lines(0, 0, -1, true, origlines)
- local shadow = deepcopy(origlines)
+ local function setup_eventcheck(verify, start_txt)
+ meths.buf_set_lines(0, 0, -1, true, start_txt)
+ local shadow = deepcopy(start_txt)
local shadowbytes = table.concat(shadow, '\n') .. '\n'
-- TODO: while we are brewing the real strong coffe,
-- verify should check buf_get_offset after every check_events
@@ -273,7 +274,7 @@ describe('lua: nvim_buf_attach on_bytes', function()
local events = exec_lua("return get_events(...)" )
if not pcall(eq, expected, events) then
- local msg = 'unexpected byte updates received.\n\nBABBLA MER \n\n'
+ local msg = 'unexpected byte updates received.\n\n'
msg = msg .. 'received events:\n'
for _, e in ipairs(events) do
@@ -286,26 +287,36 @@ describe('lua: nvim_buf_attach on_bytes', function()
fail(msg)
end
- if verify then
- for _, event in ipairs(events) do
- if event[1] == verify_name and event[2] == "bytes" then
- local _, _, _, _, _, _, start_byte, _, _, old_byte, _, _, new_byte = unpack(event)
- local before = string.sub(shadowbytes, 1, start_byte)
- -- no text in the tests will contain 0xff bytes (invalid UTF-8)
- -- so we can use it as marker for unknown bytes
- local unknown = string.rep('\255', new_byte)
- local after = string.sub(shadowbytes, start_byte + old_byte + 1)
- shadowbytes = before .. unknown .. after
+ if not verify then
+ return
+ end
+
+ for _, event in ipairs(events) do
+ for _, elem in ipairs(event) do
+ if type(elem) == "number" and elem < 0 then
+ fail(string.format("Received event has negative values"))
end
end
- local text = meths.buf_get_lines(0, 0, -1, true)
- local bytes = table.concat(text, '\n') .. '\n'
- eq(string.len(bytes), string.len(shadowbytes), shadowbytes)
- for i = 1, string.len(shadowbytes) do
- local shadowbyte = string.sub(shadowbytes, i, i)
- if shadowbyte ~= '\255' then
- eq(string.sub(bytes, i, i), shadowbyte, i)
- end
+
+ if event[1] == verify_name and event[2] == "bytes" then
+ local _, _, _, _, _, _, start_byte, _, _, old_byte, _, _, new_byte = unpack(event)
+ local before = string.sub(shadowbytes, 1, start_byte)
+ -- no text in the tests will contain 0xff bytes (invalid UTF-8)
+ -- so we can use it as marker for unknown bytes
+ local unknown = string.rep('\255', new_byte)
+ local after = string.sub(shadowbytes, start_byte + old_byte + 1)
+ shadowbytes = before .. unknown .. after
+ end
+ end
+
+ local text = meths.buf_get_lines(0, 0, -1, true)
+ local bytes = table.concat(text, '\n') .. '\n'
+
+ eq(string.len(bytes), string.len(shadowbytes), '\non_bytes: total bytecount of buffer is wrong')
+ for i = 1, string.len(shadowbytes) do
+ local shadowbyte = string.sub(shadowbytes, i, i)
+ if shadowbyte ~= '\255' then
+ eq(string.sub(bytes, i, i), shadowbyte, i)
end
end
end
@@ -316,7 +327,7 @@ describe('lua: nvim_buf_attach on_bytes', function()
-- Yes, we can do both
local function do_both(verify)
it('single and multiple join', function()
- local check_events = setup_eventcheck(verify)
+ local check_events = setup_eventcheck(verify, origlines)
feed 'ggJ'
check_events {
{'test1', 'bytes', 1, 3, 0, 15, 15, 1, 0, 1, 0, 1, 1};
@@ -330,7 +341,7 @@ describe('lua: nvim_buf_attach on_bytes', function()
end)
it('opening lines', function()
- local check_events = setup_eventcheck(verify)
+ local check_events = setup_eventcheck(verify, origlines)
-- meths.buf_set_option(0, 'autoindent', true)
feed 'Go'
check_events {
@@ -343,7 +354,7 @@ describe('lua: nvim_buf_attach on_bytes', function()
end)
it('opening lines with autoindent', function()
- local check_events = setup_eventcheck(verify)
+ local check_events = setup_eventcheck(verify, origlines)
meths.buf_set_option(0, 'autoindent', true)
feed 'Go'
check_events {
@@ -355,6 +366,92 @@ describe('lua: nvim_buf_attach on_bytes', function()
{ "test1", "bytes", 1, 5, 7, 4, 118, 0, 0, 0, 1, 4, 5 };
}
end)
+
+ it('setline(num, line)', function()
+ local check_events = setup_eventcheck(verify, origlines)
+ funcs.setline(2, "babla")
+ check_events {
+ { "test1", "bytes", 1, 3, 1, 0, 16, 0, 15, 15, 0, 5, 5 };
+ }
+
+ funcs.setline(2, {"foo", "bar"})
+ check_events {
+ { "test1", "bytes", 1, 4, 1, 0, 16, 0, 5, 5, 0, 3, 3 };
+ { "test1", "bytes", 1, 5, 2, 0, 20, 0, 15, 15, 0, 3, 3 };
+ }
+
+ local buf_len = meths.buf_line_count(0)
+ funcs.setline(buf_len + 1, "baz")
+ check_events {
+ { "test1", "bytes", 1, 6, 7, 0, 90, 0, 0, 0, 1, 0, 4 };
+ }
+ end)
+
+ it('continuing comments with fo=or', function()
+ local check_events = setup_eventcheck(verify, {'// Comment'})
+ meths.buf_set_option(0, 'formatoptions', 'ro')
+ meths.buf_set_option(0, 'filetype', 'c')
+ feed 'A<CR>'
+ check_events {
+ { "test1", "bytes", 1, 4, 0, 10, 10, 0, 0, 0, 1, 3, 4 };
+ }
+
+ feed '<ESC>'
+ check_events {
+ { "test1", "bytes", 1, 4, 1, 2, 13, 0, 1, 1, 0, 0, 0 };
+ }
+
+ feed 'ggo' -- goto first line to continue testing
+ check_events {
+ { "test1", "bytes", 1, 6, 1, 0, 11, 0, 0, 0, 1, 0, 4 };
+ }
+
+ feed '<CR>'
+ check_events {
+ { "test1", "bytes", 1, 6, 2, 2, 16, 0, 1, 1, 0, 0, 0 };
+ { "test1", "bytes", 1, 7, 1, 3, 14, 0, 0, 0, 1, 3, 4 };
+ }
+ end)
+
+ it('editing empty buffers', function()
+ local check_events = setup_eventcheck(verify, {})
+
+ feed 'ia'
+ check_events {
+ { "test1", "bytes", 1, 3, 0, 0, 0, 0, 0, 0, 0, 1, 1 };
+ }
+ end)
+
+ it("changing lines", function()
+ local check_events = setup_eventcheck(verify, origlines)
+
+ feed "cc"
+ check_events {
+ { "test1", "bytes", 1, 4, 0, 0, 0, 0, 15, 15, 0, 0, 0 };
+ }
+
+ feed "<ESC>"
+ check_events {}
+
+ feed "c3j"
+ check_events {
+ { "test1", "bytes", 1, 4, 1, 0, 1, 3, 0, 48, 0, 0, 0 };
+ }
+ end)
+
+ it("visual charwise paste", function()
+ local check_events = setup_eventcheck(verify, {'1234567890'})
+ funcs.setreg('a', '___')
+
+ feed '1G1|vll'
+ check_events {}
+
+ feed '"ap'
+ check_events {
+ { "test1", "bytes", 1, 3, 0, 0, 0, 0, 3, 3, 0, 0, 0 };
+ { "test1", "bytes", 1, 5, 0, 0, 0, 0, 0, 0, 0, 3, 3 };
+ }
+ end)
end
describe('(with verify) handles', function()
diff --git a/test/functional/ui/fold_spec.lua b/test/functional/ui/fold_spec.lua
index 6ec45064da..fe67b9f6b0 100644
--- a/test/functional/ui/fold_spec.lua
+++ b/test/functional/ui/fold_spec.lua
@@ -21,6 +21,8 @@ describe("folded lines", function()
[5] = {foreground = Screen.colors.DarkBlue, background = Screen.colors.LightGrey},
[6] = {background = Screen.colors.Yellow},
[7] = {foreground = Screen.colors.DarkBlue, background = Screen.colors.WebGray},
+ [8] = {foreground = Screen.colors.Brown },
+ [9] = {bold = true, foreground = Screen.colors.Brown}
})
end)
@@ -29,7 +31,7 @@ describe("folded lines", function()
feed("i<cr><esc>")
feed("vkzf")
screen:expect([[
- {5: ^+-- 2 lines: ·············}|
+ {7: }{5:^+-- 2 lines: ·············}|
{1:~ }|
{1:~ }|
{1:~ }|
@@ -49,8 +51,8 @@ describe("folded lines", function()
funcs.setline(4, 'line 2')
feed("j")
screen:expect([[
- {7:+ }{5: 1 +-- 2 lines: ·························}|
- {7:+ }{5: 0 ^+-- 2 lines: ·························}|
+ {7:+ }{8: 1 }{5:+-- 2 lines: ·························}|
+ {7:+ }{9: 0 }{5:^+-- 2 lines: ·························}|
{1:~ }|
{1:~ }|
{1:~ }|
@@ -130,8 +132,8 @@ describe("folded lines", function()
]])
feed('vkzf')
- screen:expect([[
- {5:^+-- 2 lines: å 语 x̎͂̀̂͛͛ ﺎﻠﻋَﺮَﺒِﻳَّﺓ·················}|
+ screen:expect{grid=[[
+ {5:^+-- 2 lines: å 语 x̎͂̀̂͛͛ العَرَبِيَّة·················}|
{1:~ }|
{1:~ }|
{1:~ }|
@@ -139,7 +141,7 @@ describe("folded lines", function()
{1:~ }|
{1:~ }|
|
- ]])
+ ]]}
feed_command("set noarabicshape")
screen:expect([[
@@ -155,7 +157,7 @@ describe("folded lines", function()
feed_command("set number foldcolumn=2")
screen:expect([[
- {7:+ }{5: 1 ^+-- 2 lines: å 语 x̎͂̀̂͛͛ العَرَبِيَّة···········}|
+ {7:+ }{8: 1 }{5:^+-- 2 lines: å 语 x̎͂̀̂͛͛ العَرَبِيَّة···········}|
{1:~ }|
{1:~ }|
{1:~ }|
@@ -168,7 +170,7 @@ describe("folded lines", function()
-- Note: too much of the folded line gets cut off.This is a vim bug.
feed_command("set rightleft")
screen:expect([[
- {5:+-- 2 lines: å ······················^· 1 }{7: +}|
+ {5:···········ةيَّبِرَعَلا x̎͂̀̂͛͛ 语 å :senil 2 --^+}{8: 1 }{7: +}|
{1: ~}|
{1: ~}|
{1: ~}|
@@ -180,7 +182,7 @@ describe("folded lines", function()
feed_command("set nonumber foldcolumn=0")
screen:expect([[
- {5:+-- 2 lines: å 语 x̎͂̀̂͛͛ ال·····················^·}|
+ {5:·················ةيَّبِرَعَلا x̎͂̀̂͛͛ 语 å :senil 2 --^+}|
{1: ~}|
{1: ~}|
{1: ~}|
@@ -192,7 +194,7 @@ describe("folded lines", function()
feed_command("set arabicshape")
screen:expect([[
- {5:+-- 2 lines: å 语 x̎͂̀̂͛͛ ﺍﻟ·····················^·}|
+ {5:·················ةيَّبِرَعَلا x̎͂̀̂͛͛ 语 å :senil 2 --^+}|
{1: ~}|
{1: ~}|
{1: ~}|