aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/functional/autocmd/textyankpost_spec.lua216
-rw-r--r--test/functional/eval/operators_spec.lua28
-rw-r--r--test/functional/eval/string_spec.lua175
-rw-r--r--test/functional/eval/vvar_event_spec.lua15
-rw-r--r--test/functional/fixtures/shell-test.c66
-rw-r--r--test/functional/legacy/036_regexp_character_classes_spec.lua7
-rw-r--r--test/functional/legacy/062_tab_pages_spec.lua4
-rw-r--r--test/functional/terminal/edit_spec.lua75
-rw-r--r--test/functional/ui/bufhl_spec.lua261
-rw-r--r--test/functional/ui/screen.lua21
-rw-r--r--test/functional/viml/errorlist_spec.lua49
-rw-r--r--test/functional/viml/function_spec.lua29
12 files changed, 921 insertions, 25 deletions
diff --git a/test/functional/autocmd/textyankpost_spec.lua b/test/functional/autocmd/textyankpost_spec.lua
new file mode 100644
index 0000000000..965b19581a
--- /dev/null
+++ b/test/functional/autocmd/textyankpost_spec.lua
@@ -0,0 +1,216 @@
+local helpers = require('test.functional.helpers')
+local clear, eval, eq, insert = helpers.clear, helpers.eval, helpers.eq, helpers.insert
+local feed, execute, expect, command = helpers.feed, helpers.execute, helpers.expect, helpers.command
+local curbufmeths, funcs, neq = helpers.curbufmeths, helpers.funcs, helpers.neq
+
+describe('TextYankPost', function()
+ before_each(function()
+ clear()
+
+ -- emulate the clipboard so system clipboard isn't affected
+ execute('let &rtp = "test/functional/fixtures,".&rtp')
+
+ execute('let g:count = 0')
+ execute('autocmd TextYankPost * let g:event = copy(v:event)')
+ execute('autocmd TextYankPost * let g:count += 1')
+
+ curbufmeths.set_line_slice(0, -1, true, true, {
+ 'foo\0bar',
+ 'baz text',
+ })
+ end)
+
+ it('is executed after yank and handles register types', function()
+ feed('yy')
+ eq({
+ operator = 'y',
+ regcontents = { 'foo\nbar' },
+ regname = '',
+ regtype = 'V'
+ }, eval('g:event'))
+ eq(1, eval('g:count'))
+
+ -- v:event is cleared after the autocommand is done
+ eq({}, eval('v:event'))
+
+ feed('+yw')
+ eq({
+ operator = 'y',
+ regcontents = { 'baz ' },
+ regname = '',
+ regtype = 'v'
+ }, eval('g:event'))
+ eq(2, eval('g:count'))
+
+ feed('<c-v>eky')
+ eq({
+ operator = 'y',
+ regcontents = { 'foo', 'baz' },
+ regname = '',
+ regtype = "\0223" -- ^V + block width
+ }, eval('g:event'))
+ eq(3, eval('g:count'))
+ end)
+
+ it('makes v:event immutable', function()
+ feed('yy')
+ eq({
+ operator = 'y',
+ regcontents = { 'foo\nbar' },
+ regname = '',
+ regtype = 'V'
+ }, eval('g:event'))
+
+ execute('set debug=msg')
+ -- the regcontents should not be changed without copy.
+ local status, err = pcall(command,'call extend(g:event.regcontents, ["more text"])')
+ eq(status,false)
+ neq(nil, string.find(err, ':E742:'))
+
+ -- can't mutate keys inside the autocommand
+ execute('autocmd! TextYankPost * let v:event.regcontents = 0')
+ status, err = pcall(command,'normal yy')
+ eq(status,false)
+ neq(nil, string.find(err, ':E46:'))
+
+ -- can't add keys inside the autocommand
+ execute('autocmd! TextYankPost * let v:event.mykey = 0')
+ status, err = pcall(command,'normal yy')
+ eq(status,false)
+ neq(nil, string.find(err, ':E742:'))
+ end)
+
+ it('is not invoked recursively', function()
+ execute('autocmd TextYankPost * normal "+yy')
+ feed('yy')
+ eq({
+ operator = 'y',
+ regcontents = { 'foo\nbar' },
+ regname = '',
+ regtype = 'V'
+ }, eval('g:event'))
+ eq(1, eval('g:count'))
+ eq({ 'foo\nbar' }, funcs.getreg('+',1,1))
+ end)
+
+ it('is executed after delete and change', function()
+ feed('dw')
+ eq({
+ operator = 'd',
+ regcontents = { 'foo' },
+ regname = '',
+ regtype = 'v'
+ }, eval('g:event'))
+ eq(1, eval('g:count'))
+
+ feed('dd')
+ eq({
+ operator = 'd',
+ regcontents = { '\nbar' },
+ regname = '',
+ regtype = 'V'
+ }, eval('g:event'))
+ eq(2, eval('g:count'))
+
+ feed('cwspam<esc>')
+ eq({
+ operator = 'c',
+ regcontents = { 'baz' },
+ regname = '',
+ regtype = 'v'
+ }, eval('g:event'))
+ eq(3, eval('g:count'))
+ end)
+
+ it('is not executed after black-hole operation', function()
+ feed('"_dd')
+ eq(0, eval('g:count'))
+
+ feed('"_cwgood<esc>')
+ eq(0, eval('g:count'))
+
+ expect([[
+ good text]])
+ feed('"_yy')
+ eq(0, eval('g:count'))
+
+ execute('delete _')
+ eq(0, eval('g:count'))
+ end)
+
+ it('gives the correct register name', function()
+ feed('$"byiw')
+ eq({
+ operator = 'y',
+ regcontents = { 'bar' },
+ regname = 'b',
+ regtype = 'v'
+ }, eval('g:event'))
+
+ feed('"*yy')
+ eq({
+ operator = 'y',
+ regcontents = { 'foo\nbar' },
+ regname = '*',
+ regtype = 'V'
+ }, eval('g:event'))
+
+ execute("set clipboard=unnamed")
+
+ -- regname still shows the name the user requested
+ feed('yy')
+ eq({
+ operator = 'y',
+ regcontents = { 'foo\nbar' },
+ regname = '',
+ regtype = 'V'
+ }, eval('g:event'))
+
+ feed('"*yy')
+ eq({
+ operator = 'y',
+ regcontents = { 'foo\nbar' },
+ regname = '*',
+ regtype = 'V'
+ }, eval('g:event'))
+ end)
+
+ it('works with Ex commands', function()
+ execute('1delete +')
+ eq({
+ operator = 'd',
+ regcontents = { 'foo\nbar' },
+ regname = '+',
+ regtype = 'V'
+ }, eval('g:event'))
+ eq(1, eval('g:count'))
+
+ execute('yank')
+ eq({
+ operator = 'y',
+ regcontents = { 'baz text' },
+ regname = '',
+ regtype = 'V'
+ }, eval('g:event'))
+ eq(2, eval('g:count'))
+
+ execute('normal yw')
+ eq({
+ operator = 'y',
+ regcontents = { 'baz ' },
+ regname = '',
+ regtype = 'v'
+ }, eval('g:event'))
+ eq(3, eval('g:count'))
+
+ execute('normal! dd')
+ eq({
+ operator = 'd',
+ regcontents = { 'baz text' },
+ regname = '',
+ regtype = 'V'
+ }, eval('g:event'))
+ eq(4, eval('g:count'))
+ end)
+
+end)
diff --git a/test/functional/eval/operators_spec.lua b/test/functional/eval/operators_spec.lua
new file mode 100644
index 0000000000..bc9a17935c
--- /dev/null
+++ b/test/functional/eval/operators_spec.lua
@@ -0,0 +1,28 @@
+local helpers = require('test.functional.helpers')
+local eq = helpers.eq
+local eval = helpers.eval
+local clear = helpers.clear
+
+describe('Division operator', function()
+ before_each(clear)
+
+ it('returns infinity on {positive}/0.0', function()
+ eq('str2float(\'inf\')', eval('string(1.0/0.0)'))
+ eq('str2float(\'inf\')', eval('string(1.0e-100/0.0)'))
+ eq('str2float(\'inf\')', eval('string(1.0e+100/0.0)'))
+ eq('str2float(\'inf\')', eval('string((1.0/0.0)/0.0)'))
+ end)
+
+ it('returns -infinity on {negative}/0.0', function()
+ eq('-str2float(\'inf\')', eval('string((-1.0)/0.0)'))
+ eq('-str2float(\'inf\')', eval('string((-1.0e-100)/0.0)'))
+ eq('-str2float(\'inf\')', eval('string((-1.0e+100)/0.0)'))
+ eq('-str2float(\'inf\')', eval('string((-1.0/0.0)/0.0)'))
+ end)
+
+ it('returns NaN on 0.0/0.0', function()
+ eq('str2float(\'nan\')', eval('string(0.0/0.0)'))
+ eq('str2float(\'nan\')', eval('string(-(0.0/0.0))'))
+ eq('str2float(\'nan\')', eval('string((-0.0)/0.0)'))
+ end)
+end)
diff --git a/test/functional/eval/string_spec.lua b/test/functional/eval/string_spec.lua
new file mode 100644
index 0000000000..f7f5dca70a
--- /dev/null
+++ b/test/functional/eval/string_spec.lua
@@ -0,0 +1,175 @@
+local helpers = require('test.functional.helpers')
+local clear = helpers.clear
+local eq = helpers.eq
+local command = helpers.command
+local meths = helpers.meths
+local eval = helpers.eval
+local exc_exec = helpers.exc_exec
+local redir_exec = helpers.redir_exec
+local funcs = helpers.funcs
+local write_file = helpers.write_file
+
+describe('string() function', function()
+ before_each(clear)
+
+ describe('used to represent floating-point values', function()
+ it('dumps NaN values', function()
+ eq('str2float(\'nan\')', eval('string(str2float(\'nan\'))'))
+ end)
+
+ it('dumps infinite values', function()
+ eq('str2float(\'inf\')', eval('string(str2float(\'inf\'))'))
+ eq('-str2float(\'inf\')', eval('string(str2float(\'-inf\'))'))
+ end)
+
+ it('dumps regular values', function()
+ eq('1.5', funcs.string(1.5))
+ eq('1.56e-20', funcs.string(1.56000e-020))
+ eq('0.0', eval('string(0.0)'))
+ end)
+
+ it('dumps values with at most six digits after the decimal point',
+ function()
+ eq('1.234568e-20', funcs.string(1.23456789123456789123456789e-020))
+ eq('1.234568', funcs.string(1.23456789123456789123456789))
+ end)
+
+ it('dumps values with at most seven digits before the decimal point',
+ function()
+ eq('1234567.891235', funcs.string(1234567.89123456789123456789))
+ eq('1.234568e7', funcs.string(12345678.9123456789123456789))
+ end)
+
+ it('dumps negative values', function()
+ eq('-1.5', funcs.string(-1.5))
+ eq('-1.56e-20', funcs.string(-1.56000e-020))
+ eq('-1.234568e-20', funcs.string(-1.23456789123456789123456789e-020))
+ eq('-1.234568', funcs.string(-1.23456789123456789123456789))
+ eq('-1234567.891235', funcs.string(-1234567.89123456789123456789))
+ eq('-1.234568e7', funcs.string(-12345678.9123456789123456789))
+ end)
+ end)
+
+ describe('used to represent numbers', function()
+ it('dumps regular values', function()
+ eq('0', funcs.string(0))
+ eq('-1', funcs.string(-1))
+ eq('1', funcs.string(1))
+ end)
+
+ it('dumps large values', function()
+ eq('2147483647', funcs.string(2^31-1))
+ eq('-2147483648', funcs.string(-2^31))
+ end)
+ end)
+
+ describe('used to represent strings', function()
+ it('dumps regular strings', function()
+ eq('\'test\'', funcs.string('test'))
+ end)
+
+ it('dumps empty strings', function()
+ eq('\'\'', funcs.string(''))
+ end)
+
+ it('dumps strings with \' inside', function()
+ eq('\'\'\'\'\'\'\'\'', funcs.string('\'\'\''))
+ eq('\'a\'\'b\'\'\'\'\'', funcs.string('a\'b\'\''))
+ eq('\'\'\'b\'\'\'\'d\'', funcs.string('\'b\'\'d'))
+ eq('\'a\'\'b\'\'c\'\'d\'', funcs.string('a\'b\'c\'d'))
+ end)
+ end)
+
+ describe('used to represent funcrefs', function()
+ local fname = 'Xtest-functional-eval-string_spec-fref-script.vim'
+
+ before_each(function()
+ write_file(fname, [[
+ function Test1()
+ endfunction
+
+ function s:Test2()
+ endfunction
+
+ function g:Test3()
+ endfunction
+
+ let g:Test2_f = function('s:Test2')
+ ]])
+ command('source ' .. fname)
+ end)
+
+ after_each(function()
+ os.remove(fname)
+ end)
+
+ it('dumps references to built-in functions', function()
+ eq('function(\'function\')', eval('string(function("function"))'))
+ end)
+
+ it('dumps references to user functions', function()
+ eq('function(\'Test1\')', eval('string(function("Test1"))'))
+ eq('function(\'g:Test3\')', eval('string(function("g:Test3"))'))
+ end)
+
+ it('dumps references to script functions', function()
+ eq('function(\'<SNR>1_Test2\')', eval('string(Test2_f)'))
+ end)
+ end)
+
+ describe('used to represent lists', function()
+ it('dumps empty list', function()
+ eq('[]', funcs.string({}))
+ end)
+
+ it('dumps nested lists', function()
+ eq('[[[[[]]]]]', funcs.string({{{{{}}}}}))
+ end)
+
+ it('dumps nested non-empty lists', function()
+ eq('[1, [[3, [[5], 4]], 2]]', funcs.string({1, {{3, {{5}, 4}}, 2}}))
+ end)
+
+ it('errors when dumping recursive lists', function()
+ meths.set_var('l', {})
+ eval('add(l, l)')
+ eq('Vim(echo):E724: unable to correctly dump variable with self-referencing container',
+ exc_exec('echo string(l)'))
+ end)
+
+ it('dumps recursive lists despite the error', function()
+ meths.set_var('l', {})
+ eval('add(l, l)')
+ eq('\nE724: unable to correctly dump variable with self-referencing container\n[{E724@0}]',
+ redir_exec('echo string(l)'))
+ eq('\nE724: unable to correctly dump variable with self-referencing container\n[[{E724@1}]]',
+ redir_exec('echo string([l])'))
+ end)
+ end)
+
+ describe('used to represent dictionaries', function()
+ it('dumps empty dictionary', function()
+ eq('{}', eval('string({})'))
+ end)
+
+ it('dumps non-empty dictionary', function()
+ eq('{\'t\'\'est\': 1}', funcs.string({['t\'est']=1}))
+ end)
+
+ it('errors when dumping recursive dictionaries', function()
+ meths.set_var('d', {d=1})
+ eval('extend(d, {"d": d})')
+ eq('Vim(echo):E724: unable to correctly dump variable with self-referencing container',
+ exc_exec('echo string(d)'))
+ end)
+
+ it('dumps recursive dictionaries despite the error', function()
+ meths.set_var('d', {d=1})
+ eval('extend(d, {"d": d})')
+ eq('\nE724: unable to correctly dump variable with self-referencing container\n{\'d\': {E724@0}}',
+ redir_exec('echo string(d)'))
+ eq('\nE724: unable to correctly dump variable with self-referencing container\n{\'out\': {\'d\': {E724@1}}}',
+ redir_exec('echo string({"out": d})'))
+ end)
+ end)
+end)
diff --git a/test/functional/eval/vvar_event_spec.lua b/test/functional/eval/vvar_event_spec.lua
new file mode 100644
index 0000000000..bbac86524f
--- /dev/null
+++ b/test/functional/eval/vvar_event_spec.lua
@@ -0,0 +1,15 @@
+local helpers = require('test.functional.helpers')
+local clear, eval, eq = helpers.clear, helpers.eval, helpers.eq
+local command = helpers.command
+describe('v:event', function()
+ before_each(clear)
+ it('is empty before any autocommand', function()
+ eq({}, eval('v:event'))
+ end)
+
+ it('is immutable', function()
+ eq(false, pcall(command, 'let v:event = {}'))
+ eq(false, pcall(command, 'let v:event.mykey = {}'))
+ end)
+end)
+
diff --git a/test/functional/fixtures/shell-test.c b/test/functional/fixtures/shell-test.c
index 5fa8a58049..d9ec254aff 100644
--- a/test/functional/fixtures/shell-test.c
+++ b/test/functional/fixtures/shell-test.c
@@ -1,25 +1,59 @@
-// A simple implementation of a shell for testing
-// `termopen([&sh, &shcf, '{cmd'}])` and `termopen([&sh])`.
-//
-// If launched with no arguments, prints "ready $ ", otherwise prints
-// "ready $ {cmd}\n".
-
#include <stdio.h>
#include <string.h>
+#include <stdint.h>
+
+static void help(void)
+{
+ puts("A simple implementation of a shell for testing termopen().");
+ puts("");
+ puts("Usage:");
+ puts(" shell-test --help");
+ puts(" Prints this help to stdout.");
+ puts(" shell-test");
+ puts(" shell-test EXE");
+ puts(" Prints \"ready $ \" to stderr.");
+ puts(" shell-test EXE \"prog args...\"");
+ puts(" Prints \"ready $ prog args...\\n\" to stderr.");
+ puts(" shell-test REP {byte} \"line line line\"");
+ puts(" Prints \"{lnr}: line line line\\n\" to stdout {byte} times.");
+ puts(" I.e. for `shell-test REP ab \"test\"'");
+ puts(" 0: test");
+ puts(" ...");
+ puts(" 96: test");
+ puts(" will be printed because byte `a' is equal to 97.");
+}
int main(int argc, char **argv)
{
- fprintf(stderr, "ready $ ");
+ if (argc == 2 && strcmp(argv[1], "--help") == 0) {
+ help();
+ }
- if (argc == 3) {
- // argv should be {"terminal-test", "EXE", "prog args..."}
- if (strcmp(argv[1], "EXE") != 0) {
- fprintf(stderr, "first argument must be 'EXE'\n");
- return 2;
+ if (argc >= 2) {
+ if (strcmp(argv[1], "EXE") == 0) {
+ fprintf(stderr, "ready $ ");
+ if (argc >= 3) {
+ fprintf(stderr, "%s\n", argv[2]);
+ }
+ } else if (strcmp(argv[1], "REP") == 0) {
+ if (argc < 4) {
+ fprintf(stderr, "Not enough REP arguments\n");
+ return 4;
+ }
+ uint8_t number = (uint8_t) *argv[2];
+ for (uint8_t i = 0; i < number; i++) {
+ printf("%d: %s\n", (int) i, argv[3]);
+ }
+ } else {
+ fprintf(stderr, "Unknown first argument\n");
+ return 3;
}
-
- fprintf(stderr, "%s\n", argv[2]);
+ return 0;
+ } else if (argc == 1) {
+ fprintf(stderr, "ready $ ");
+ return 0;
+ } else {
+ fprintf(stderr, "Missing first argument\n");
+ return 2;
}
-
- return 0;
}
diff --git a/test/functional/legacy/036_regexp_character_classes_spec.lua b/test/functional/legacy/036_regexp_character_classes_spec.lua
index 205922eac2..3c264423ff 100644
--- a/test/functional/legacy/036_regexp_character_classes_spec.lua
+++ b/test/functional/legacy/036_regexp_character_classes_spec.lua
@@ -2,13 +2,12 @@
local helpers = require('test.functional.helpers')
local ffi = require('ffi')
-local feed, insert, source = helpers.feed, helpers.insert, helpers.source
-local clear, execute, expect, eq, eval = helpers.clear, helpers.execute, helpers.expect, helpers.eq, helpers.eval
-local write_file = helpers.write_file
+local clear, execute, expect = helpers.clear, helpers.execute, helpers.expect
+local source, write_file = helpers.source, helpers.write_file
local function sixlines(text)
local result = ''
- for i = 1, 6 do
+ for _ = 1, 6 do
result = result .. text .. '\n'
end
return result
diff --git a/test/functional/legacy/062_tab_pages_spec.lua b/test/functional/legacy/062_tab_pages_spec.lua
index f1c8b8d58b..c3cdcac471 100644
--- a/test/functional/legacy/062_tab_pages_spec.lua
+++ b/test/functional/legacy/062_tab_pages_spec.lua
@@ -139,6 +139,7 @@ describe('tab pages', function()
autocmd TabLeave * :call add(g:r, 'TabLeave')
autocmd WinLeave * :call add(g:r, 'WinLeave')
autocmd BufLeave * :call add(g:r, 'BufLeave')
+ autocmd TabNew * :call add(g:r, 'TabNew')
let t:a='a'
C tab split
let t:a='b'
@@ -185,11 +186,13 @@ describe('tab pages', function()
=== tab split ===
WinLeave
TabLeave
+ TabNew
WinEnter
TabEnter
=== tabnew ===
WinLeave
TabLeave
+ TabNew
WinEnter
TabEnter
BufLeave
@@ -222,6 +225,7 @@ describe('tab pages', function()
=== tabnew ===
WinLeave
TabLeave
+ TabNew
WinEnter
TabEnter
BufLeave
diff --git a/test/functional/terminal/edit_spec.lua b/test/functional/terminal/edit_spec.lua
new file mode 100644
index 0000000000..6da1521121
--- /dev/null
+++ b/test/functional/terminal/edit_spec.lua
@@ -0,0 +1,75 @@
+local helpers = require('test.functional.helpers')
+local screen = require('test.functional.ui.screen')
+
+local curbufmeths = helpers.curbufmeths
+local curwinmeths = helpers.curwinmeths
+local nvim_dir = helpers.nvim_dir
+local command = helpers.command
+local meths = helpers.meths
+local clear = helpers.clear
+local eq = helpers.eq
+
+describe(':edit term://*', function()
+ local get_screen = function(columns, lines)
+ local scr = screen.new(columns, lines)
+ scr:attach(false)
+ return scr
+ end
+
+ before_each(function()
+ clear()
+ meths.set_option('shell', nvim_dir .. '/shell-test')
+ meths.set_option('shellcmdflag', 'EXE')
+ end)
+
+ it('runs TermOpen event', function()
+ meths.set_var('termopen_runs', {})
+ command('autocmd TermOpen * :call add(g:termopen_runs, expand("<amatch>"))')
+ command('edit term://')
+ local termopen_runs = meths.get_var('termopen_runs')
+ eq(1, #termopen_runs)
+ eq(termopen_runs[1], termopen_runs[1]:match('^term://.//%d+:$'))
+ end)
+
+ it('runs TermOpen early enough to respect terminal_scrollback_buffer_size', function()
+ local columns, lines = 20, 4
+ local scr = get_screen(columns, lines)
+ local rep = 'a'
+ meths.set_option('shellcmdflag', 'REP ' .. rep)
+ local rep_size = rep:byte()
+ local sb = 10
+ local gsb = 20
+ meths.set_var('terminal_scrollback_buffer_size', gsb)
+ command('autocmd TermOpen * :let b:terminal_scrollback_buffer_size = '
+ .. tostring(sb))
+ command('edit term://foobar')
+ local bufcontents = {}
+ local winheight = curwinmeths.get_height()
+ -- I have no idea why there is + 4 needed. But otherwise it works fine with
+ -- different scrollbacks.
+ local shift = -4
+ local buf_cont_start = rep_size - 1 - sb - winheight - shift
+ local bufline = function(i) return ('%d: foobar'):format(i) end
+ for i = buf_cont_start,(rep_size - 1) do
+ bufcontents[#bufcontents + 1] = bufline(i)
+ end
+ bufcontents[#bufcontents + 1] = ''
+ bufcontents[#bufcontents + 1] = '[Process exited 0]'
+ -- Do not ask me why displayed screen is one line *before* buffer
+ -- contents: buffer starts with 87:, screen with 86:.
+ local exp_screen = '\n'
+ local did_cursor = false
+ for i = 0,(winheight - 1) do
+ local line = bufline(buf_cont_start + i - 1)
+ exp_screen = (exp_screen
+ .. (did_cursor and '' or '^')
+ .. line
+ .. (' '):rep(columns - #line)
+ .. '|\n')
+ did_cursor = true
+ end
+ exp_screen = exp_screen .. (' '):rep(columns) .. '|\n'
+ scr:expect(exp_screen)
+ eq(bufcontents, curbufmeths.get_line_slice(1, -1, true, true))
+ end)
+end)
diff --git a/test/functional/ui/bufhl_spec.lua b/test/functional/ui/bufhl_spec.lua
new file mode 100644
index 0000000000..58f5b11de0
--- /dev/null
+++ b/test/functional/ui/bufhl_spec.lua
@@ -0,0 +1,261 @@
+local helpers = require('test.functional.helpers')
+local Screen = require('test.functional.ui.screen')
+local clear, feed, insert = helpers.clear, helpers.feed, helpers.insert
+local execute, request, neq = helpers.execute, helpers.request, helpers.neq
+
+
+describe('Buffer highlighting', function()
+ local screen
+ local curbuf
+
+ local hl_colors = {
+ NonText = Screen.colors.Blue,
+ Question = Screen.colors.SeaGreen,
+ String = Screen.colors.Fuchsia,
+ Statement = Screen.colors.Brown,
+ Special = Screen.colors.SlateBlue,
+ Identifier = Screen.colors.DarkCyan
+ }
+
+ before_each(function()
+ clear()
+ execute("syntax on")
+ screen = Screen.new(40, 8)
+ screen:attach()
+ screen:set_default_attr_ignore( {{bold=true, foreground=hl_colors.NonText}} )
+ screen:set_default_attr_ids({
+ [1] = {foreground = hl_colors.String},
+ [2] = {foreground = hl_colors.Statement, bold = true},
+ [3] = {foreground = hl_colors.Special},
+ [4] = {bold = true, foreground = hl_colors.Special},
+ [5] = {foreground = hl_colors.Identifier},
+ [6] = {bold = true},
+ [7] = {underline = true, bold = true, foreground = hl_colors.Special},
+ [8] = {foreground = hl_colors.Special, underline = true}
+ })
+ curbuf = request('vim_get_current_buffer')
+ end)
+
+ after_each(function()
+ screen:detach()
+ end)
+
+ local function add_hl(...)
+ return request('buffer_add_highlight', curbuf, ...)
+ end
+
+ local function clear_hl(...)
+ return request('buffer_clear_highlight', curbuf, ...)
+ end
+
+
+ it('works', function()
+ insert([[
+ these are some lines
+ with colorful text]])
+ feed('+')
+
+ screen:expect([[
+ these are some lines |
+ with colorful tex^t |
+ ~ |
+ ~ |
+ ~ |
+ ~ |
+ ~ |
+ |
+ ]])
+
+ add_hl(-1, "String", 0 , 10, 14)
+ add_hl(-1, "Statement", 1 , 5, -1)
+
+ screen:expect([[
+ these are {1:some} lines |
+ with {2:colorful tex^t} |
+ ~ |
+ ~ |
+ ~ |
+ ~ |
+ ~ |
+ |
+ ]])
+
+ feed("ggo<esc>")
+ screen:expect([[
+ these are {1:some} lines |
+ ^ |
+ with {2:colorful text} |
+ ~ |
+ ~ |
+ ~ |
+ ~ |
+ |
+ ]])
+
+ clear_hl(-1, 0 , -1)
+ screen:expect([[
+ these are some lines |
+ ^ |
+ with colorful text |
+ ~ |
+ ~ |
+ ~ |
+ ~ |
+ |
+ ]])
+ end)
+
+ describe('support adding multiple sources', function()
+ local id1, id2
+ before_each(function()
+ insert([[
+ a longer example
+ in order to demonstrate
+ combining highlights
+ from different sources]])
+
+ execute("hi ImportantWord gui=bold cterm=bold")
+ id1 = add_hl(0, "ImportantWord", 0, 2, 8)
+ add_hl(id1, "ImportantWord", 1, 12, -1)
+ add_hl(id1, "ImportantWord", 2, 0, 9)
+ add_hl(id1, "ImportantWord", 3, 5, 14)
+
+ id2 = add_hl(0, "Special", 0, 2, 8)
+ add_hl(id2, "Identifier", 1, 3, 8)
+ add_hl(id2, "Special", 1, 14, 20)
+ add_hl(id2, "Underlined", 2, 6, 12)
+ add_hl(id2, "Underlined", 3, 0, 9)
+ neq(id1, id2)
+
+ screen:expect([[
+ a {4:longer} example |
+ in {5:order} to {6:de}{4:monstr}{6:ate} |
+ {6:combin}{7:ing}{8: hi}ghlights |
+ {8:from }{7:diff}{6:erent} source^s |
+ ~ |
+ ~ |
+ ~ |
+ :hi ImportantWord gui=bold cterm=bold |
+ ]])
+ end)
+
+ it('and clearing the first added', function()
+ clear_hl(id1, 0, -1)
+ screen:expect([[
+ a {3:longer} example |
+ in {5:order} to de{3:monstr}ate |
+ combin{8:ing hi}ghlights |
+ {8:from diff}erent source^s |
+ ~ |
+ ~ |
+ ~ |
+ :hi ImportantWord gui=bold cterm=bold |
+ ]])
+ end)
+
+ it('and clearing the second added', function()
+ clear_hl(id2, 0, -1)
+ screen:expect([[
+ a {6:longer} example |
+ in order to {6:demonstrate} |
+ {6:combining} highlights |
+ from {6:different} source^s |
+ ~ |
+ ~ |
+ ~ |
+ :hi ImportantWord gui=bold cterm=bold |
+ ]])
+ end)
+
+ it('and clearing line ranges', function()
+ clear_hl(-1, 0, 1)
+ clear_hl(id1, 1, 2)
+ clear_hl(id2, 2, -1)
+ screen:expect([[
+ a longer example |
+ in {5:order} to de{3:monstr}ate |
+ {6:combining} highlights |
+ from {6:different} source^s |
+ ~ |
+ ~ |
+ ~ |
+ :hi ImportantWord gui=bold cterm=bold |
+ ]])
+ end)
+
+ it('and renumbering lines', function()
+ feed('3Gddggo<esc>')
+ screen:expect([[
+ a {4:longer} example |
+ ^ |
+ in {5:order} to {6:de}{4:monstr}{6:ate} |
+ {8:from }{7:diff}{6:erent} sources |
+ ~ |
+ ~ |
+ ~ |
+ |
+ ]])
+
+ execute(':3move 4')
+ screen:expect([[
+ a {4:longer} example |
+ |
+ {8:from }{7:diff}{6:erent} sources |
+ ^in {5:order} to {6:de}{4:monstr}{6:ate} |
+ ~ |
+ ~ |
+ ~ |
+ ::3move 4 |
+ ]])
+ end)
+ end)
+
+ it('prioritizes latest added highlight', function()
+ insert([[
+ three overlapping colors]])
+ add_hl(0, "Identifier", 0, 6, 17)
+ add_hl(0, "String", 0, 14, 23)
+ local id = add_hl(0, "Special", 0, 0, 9)
+
+ screen:expect([[
+ {3:three ove}{5:rlapp}{1:ing color}^s |
+ ~ |
+ ~ |
+ ~ |
+ ~ |
+ ~ |
+ ~ |
+ |
+ ]])
+
+ clear_hl(id, 0, 1)
+ screen:expect([[
+ three {5:overlapp}{1:ing color}^s |
+ ~ |
+ ~ |
+ ~ |
+ ~ |
+ ~ |
+ ~ |
+ |
+ ]])
+ end)
+
+ it('works with multibyte text', function()
+ insert([[
+ Ta båten över sjön!]])
+ add_hl(-1, "Identifier", 0, 3, 9)
+ add_hl(-1, "String", 0, 16, 21)
+
+ screen:expect([[
+ Ta {5:båten} över {1:sjön}^! |
+ ~ |
+ ~ |
+ ~ |
+ ~ |
+ ~ |
+ ~ |
+ |
+ ]])
+ end)
+end)
diff --git a/test/functional/ui/screen.lua b/test/functional/ui/screen.lua
index 80f46326ee..b35e0cde69 100644
--- a/test/functional/ui/screen.lua
+++ b/test/functional/ui/screen.lua
@@ -219,12 +219,23 @@ function Screen:expect(expected, attr_ids, attr_ignore)
local ids = attr_ids or self._default_attr_ids
local ignore = attr_ignore or self._default_attr_ignore
self:wait(function()
+ local actual_rows = {}
for i = 1, self._height do
- local expected_row = expected_rows[i]
- local actual_row = self:_row_repr(self._rows[i], ids, ignore)
- if expected_row ~= actual_row then
- return 'Row '..tostring(i)..' didn\'t match.\nExpected: "'..
- expected_row..'"\nActual: "'..actual_row..'"'
+ actual_rows[i] = self:_row_repr(self._rows[i], ids, ignore)
+ end
+ for i = 1, self._height do
+ if expected_rows[i] ~= actual_rows[i] then
+ local msg_expected_rows = {}
+ for j = 1, #expected_rows do
+ msg_expected_rows[j] = expected_rows[j]
+ end
+ msg_expected_rows[i] = '*' .. msg_expected_rows[i]
+ actual_rows[i] = '*' .. actual_rows[i]
+ return (
+ 'Row ' .. tostring(i) .. ' didn\'t match.\n'
+ .. 'Expected:\n|' .. table.concat(msg_expected_rows, '|\n|') .. '|\n'
+ .. 'Actual:\n|' .. table.concat(actual_rows, '|\n|') .. '|'
+ )
end
end
end)
diff --git a/test/functional/viml/errorlist_spec.lua b/test/functional/viml/errorlist_spec.lua
new file mode 100644
index 0000000000..78e25297f2
--- /dev/null
+++ b/test/functional/viml/errorlist_spec.lua
@@ -0,0 +1,49 @@
+local helpers = require('test.functional.helpers')
+
+local clear = helpers.clear
+local command = helpers.command
+local eq = helpers.eq
+local get_cur_win_var = helpers.curwinmeths.get_var
+-- local exc_exec = helpers.exc_exec
+
+describe('setqflist()', function()
+ local setqflist = helpers.funcs.setqflist
+
+ before_each(clear)
+
+ it('sets w:quickfix_title', function()
+ setqflist({''}, 'r', 'foo')
+ command('copen')
+ eq(':foo', get_cur_win_var('quickfix_title'))
+ end)
+
+ it('expects a proper type for {title}', function()
+ command('copen')
+ setqflist({''}, 'r', '5')
+ eq(':5', get_cur_win_var('quickfix_title'))
+ setqflist({''}, 'r', 6)
+ eq(':setqflist()', get_cur_win_var('quickfix_title'))
+ -- local exc = exc_exec('call setqflist([""], "r", function("function"))')
+ -- eq('Vim(call):E729: using Funcref as a String', exc)
+ -- exc = exc_exec('call setqflist([""], "r", [])')
+ -- eq('Vim(call):E730: using List as a String', exc)
+ -- exc = exc_exec('call setqflist([""], "r", {})')
+ -- eq('Vim(call):E731: using Dictionary as a String', exc)
+ end)
+end)
+
+describe('setloclist()', function()
+ local setloclist = helpers.funcs.setloclist
+
+ before_each(clear)
+
+ it('sets w:quickfix_title for the correct window', function()
+ command('rightbelow vsplit')
+ setloclist(1, {''}, 'r', 'foo')
+ setloclist(2, {''}, 'r', 'bar')
+ command('lopen')
+ eq(':bar', get_cur_win_var('quickfix_title'))
+ command('lclose | wincmd w | lopen')
+ eq(':foo', get_cur_win_var('quickfix_title'))
+ end)
+end)
diff --git a/test/functional/viml/function_spec.lua b/test/functional/viml/function_spec.lua
new file mode 100644
index 0000000000..665f5d4467
--- /dev/null
+++ b/test/functional/viml/function_spec.lua
@@ -0,0 +1,29 @@
+local helpers = require('test.functional.helpers')
+
+local clear = helpers.clear
+local eq = helpers.eq
+local exc_exec = helpers.exc_exec
+
+describe('Up to MAX_FUNC_ARGS arguments are handled by', function()
+ local max_func_args = 20 -- from eval.h
+ local range = helpers.funcs.range
+
+ before_each(clear)
+
+ it('printf()', function()
+ local printf = helpers.funcs.printf
+ local rep = helpers.funcs['repeat']
+ local expected = '2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,'
+ eq(expected, printf(rep('%d,', max_func_args-1), unpack(range(2, max_func_args))))
+ local ret = exc_exec('call printf("", 2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21)')
+ eq('Vim(call):E740: Too many arguments for function printf', ret)
+ end)
+
+ it('rpcnotify()', function()
+ local rpcnotify = helpers.funcs.rpcnotify
+ local ret = rpcnotify(0, 'foo', unpack(range(3, max_func_args)))
+ eq(1, ret)
+ ret = exc_exec('call rpcnotify(0, "foo", 3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21)')
+ eq('Vim(call):E740: Too many arguments for function rpcnotify', ret)
+ end)
+end)