aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/functional/eval/capture_spec.lua86
-rw-r--r--test/functional/ex_cmds/menu_spec.lua2
-rw-r--r--test/functional/ex_cmds/write_spec.lua9
-rw-r--r--test/functional/legacy/eval_spec.lua18
-rw-r--r--test/functional/legacy/getcwd_spec.lua86
-rw-r--r--test/functional/terminal/highlight_spec.lua39
-rw-r--r--test/functional/ui/highlight_spec.lua1
-rw-r--r--test/functional/viml/function_spec.lua9
-rw-r--r--test/unit/buffer_spec.lua310
9 files changed, 458 insertions, 102 deletions
diff --git a/test/functional/eval/capture_spec.lua b/test/functional/eval/capture_spec.lua
new file mode 100644
index 0000000000..d9265f1b5b
--- /dev/null
+++ b/test/functional/eval/capture_spec.lua
@@ -0,0 +1,86 @@
+local helpers = require('test.functional.helpers')(after_each)
+local eq = helpers.eq
+local eval = helpers.eval
+local clear = helpers.clear
+local source = helpers.source
+local redir_exec = helpers.redir_exec
+local exc_exec = helpers.exc_exec
+local funcs = helpers.funcs
+local Screen = require('test.functional.ui.screen')
+local feed = helpers.feed
+
+describe('capture()', function()
+ before_each(clear)
+
+ it('returns the same result with :redir', function()
+ eq(redir_exec('messages'), funcs.capture('messages'))
+ end)
+
+ it('returns the output of the commands if the argument is List', function()
+ eq("foobar", funcs.capture({'echon "foo"', 'echon "bar"'}))
+ eq("\nfoo\nbar", funcs.capture({'echo "foo"', 'echo "bar"'}))
+ end)
+
+ it('supports the nested redirection', function()
+ source([[
+ function! g:Foo()
+ let a = ''
+ redir => a
+ silent echon "foo"
+ redir END
+ return a
+ endfunction
+ function! g:Bar()
+ let a = ''
+ redir => a
+ call g:Foo()
+ redir END
+ return a
+ endfunction
+ ]])
+ eq('foo', funcs.capture('call g:Bar()'))
+
+ eq('42', funcs.capture([[echon capture("echon capture('echon 42')")]]))
+ end)
+
+ it('returns the transformed string', function()
+ eq('^A', funcs.capture('echon "\\<C-a>"'))
+ end)
+
+ it('returns the empty string if the argument list is empty', function()
+ eq('', funcs.capture({}))
+ eq(0, exc_exec('let g:ret = capture(v:_null_list)'))
+ eq('', eval('g:ret'))
+ end)
+
+ it('returns the errors', function()
+ local ret
+ ret = exc_exec('call capture(0.0)')
+ eq('Vim(call):E806: using Float as a String', ret)
+ ret = exc_exec('call capture(v:_null_dict)')
+ eq('Vim(call):E731: using Dictionary as a String', ret)
+ ret = exc_exec('call capture(function("tr"))')
+ eq('Vim(call):E729: using Funcref as a String', ret)
+ ret = exc_exec('call capture(["echo 42", 0.0, "echo 44"])')
+ eq('Vim(call):E806: using Float as a String', ret)
+ ret = exc_exec('call capture(["echo 42", v:_null_dict, "echo 44"])')
+ eq('Vim(call):E731: using Dictionary as a String', ret)
+ ret = exc_exec('call capture(["echo 42", function("tr"), "echo 44"])')
+ eq('Vim(call):E729: using Funcref as a String', ret)
+ end)
+
+ it('silences command run inside', function()
+ local screen = Screen.new(20, 5)
+ screen:attach()
+ screen:set_default_attr_ignore({{bold=true, foreground=255}})
+ feed(':let g:mes = capture("echon 42")<CR>')
+ screen:expect([[
+ ^ |
+ ~ |
+ ~ |
+ ~ |
+ |
+ ]])
+ eq('42', eval('g:mes'))
+ end)
+end)
diff --git a/test/functional/ex_cmds/menu_spec.lua b/test/functional/ex_cmds/menu_spec.lua
index 10bcc5b7bb..52df9e1592 100644
--- a/test/functional/ex_cmds/menu_spec.lua
+++ b/test/functional/ex_cmds/menu_spec.lua
@@ -39,7 +39,7 @@ describe(':emenu', function()
end)
it('executes correct bindings in command mode', function()
- feed('ithis is a sentence<esc>^"+yiwo<esc>')
+ feed('ithis is a sentence<esc>^yiwo<esc>')
-- Invoke "Edit.Paste" in normal-mode.
nvim('command', 'emenu Edit.Paste')
diff --git a/test/functional/ex_cmds/write_spec.lua b/test/functional/ex_cmds/write_spec.lua
index 83513d747f..7f5eba1fc8 100644
--- a/test/functional/ex_cmds/write_spec.lua
+++ b/test/functional/ex_cmds/write_spec.lua
@@ -6,10 +6,13 @@ local eq, eval, clear, write_file, execute, source =
helpers.execute, helpers.source
describe(':write', function()
- it('&backupcopy=auto preserves symlinks', function()
- clear('set backupcopy=auto')
+ after_each(function()
os.remove('test_bkc_file.txt')
os.remove('test_bkc_link.txt')
+ end)
+
+ it('&backupcopy=auto preserves symlinks', function()
+ clear('set backupcopy=auto')
write_file('test_bkc_file.txt', 'content0')
execute("silent !ln -s test_bkc_file.txt test_bkc_link.txt")
source([[
@@ -23,8 +26,6 @@ describe(':write', function()
it('&backupcopy=no replaces symlink with new file', function()
clear('set backupcopy=no')
- os.remove('test_bkc_file.txt')
- os.remove('test_bkc_link.txt')
write_file('test_bkc_file.txt', 'content0')
execute("silent !ln -s test_bkc_file.txt test_bkc_link.txt")
source([[
diff --git a/test/functional/legacy/eval_spec.lua b/test/functional/legacy/eval_spec.lua
index b7317045be..3684fe714d 100644
--- a/test/functional/legacy/eval_spec.lua
+++ b/test/functional/legacy/eval_spec.lua
@@ -5,11 +5,6 @@ local feed, insert, source = helpers.feed, helpers.insert, helpers.source
local clear, execute, expect = helpers.clear, helpers.execute, helpers.expect
local eq, eval, write_file = helpers.eq, helpers.eval, helpers.write_file
-local function has_clipboard()
- clear()
- return 1 == eval("has('clipboard')")
-end
-
describe('eval', function()
setup(function()
write_file('test_eval_setup.vim', [[
@@ -539,8 +534,13 @@ describe('eval', function()
=: type v; value: abc/]].."\000 (['abc/\000"..[[']), expr: "abc/]]..'\000'..[[" (['"abc/]]..'\000'..[["'])]])
end)
- if has_clipboard() then
- it('system clipboard', function()
+ describe('system clipboard', function()
+ before_each(function()
+ execute('let &runtimepath = "test/functional/fixtures,".&runtimepath')
+ execute('call getreg("*")') -- force load of provider
+ end)
+
+ it('works', function()
insert([[
Some first line (this text was at the top of the old test_eval.in).
@@ -570,9 +570,7 @@ describe('eval', function()
*: type V; value: clipboard contents]]..'\00'..[[ (['clipboard contents']), expr: clipboard contents]]..'\00'..[[ (['clipboard contents'])
*: type V; value: something else]]..'\00'..[[ (['something else']), expr: something else]]..'\00'..[[ (['something else'])]])
end)
- else
- pending('system clipboard not available', function() end)
- end
+ end)
it('errors', function()
source([[
diff --git a/test/functional/legacy/getcwd_spec.lua b/test/functional/legacy/getcwd_spec.lua
new file mode 100644
index 0000000000..3bb9930b74
--- /dev/null
+++ b/test/functional/legacy/getcwd_spec.lua
@@ -0,0 +1,86 @@
+-- Tests for getcwd(), haslocaldir(), and :lcd
+
+local helpers = require('test.functional.helpers')(after_each)
+local eq, eval, source = helpers.eq, helpers.eval, helpers.source
+local call, clear, execute = helpers.call, helpers.clear, helpers.execute
+
+describe('getcwd', function()
+ before_each(clear)
+
+ after_each(function()
+ helpers.rmdir('Xtopdir')
+ end)
+
+ it('is working', function()
+ source([[
+ function! GetCwdInfo(win, tab)
+ let tab_changed = 0
+ let mod = ":t"
+ if a:tab > 0 && a:tab != tabpagenr()
+ let tab_changed = 1
+ exec "tabnext " . a:tab
+ endif
+ let bufname = fnamemodify(bufname(winbufnr(a:win)), mod)
+ if tab_changed
+ tabprevious
+ endif
+ if a:win == 0 && a:tab == 0
+ let dirname = fnamemodify(getcwd(), mod)
+ let lflag = haslocaldir()
+ elseif a:tab == 0
+ let dirname = fnamemodify(getcwd(a:win), mod)
+ let lflag = haslocaldir(a:win)
+ else
+ let dirname = fnamemodify(getcwd(a:win, a:tab), mod)
+ let lflag = haslocaldir(a:win, a:tab)
+ endif
+ return bufname . ' ' . dirname . ' ' . lflag
+ endfunction
+ ]])
+ execute('new')
+ execute('let cwd=getcwd()')
+ call('mkdir', 'Xtopdir')
+ execute('silent cd Xtopdir')
+ call('mkdir', 'Xdir1')
+ call('mkdir', 'Xdir2')
+ call('mkdir', 'Xdir3')
+ execute('new a')
+ execute('new b')
+ execute('new c')
+ execute('3wincmd w')
+ execute('silent lcd Xdir1')
+ eq('a Xdir1 1', eval('GetCwdInfo(0, 0)'))
+ execute('wincmd W')
+ eq('b Xtopdir 0', eval('GetCwdInfo(0, 0)'))
+ execute('wincmd W')
+ execute('silent lcd Xdir3')
+ eq('c Xdir3 1', eval('GetCwdInfo(0, 0)'))
+ eq('a Xdir1 1', eval('GetCwdInfo(bufwinnr("a"), 0)'))
+ eq('b Xtopdir 0', eval('GetCwdInfo(bufwinnr("b"), 0)'))
+ eq('c Xdir3 1', eval('GetCwdInfo(bufwinnr("c"), 0)'))
+ execute('wincmd W')
+ eq('a Xdir1 1', eval('GetCwdInfo(bufwinnr("a"), tabpagenr())'))
+ eq('b Xtopdir 0', eval('GetCwdInfo(bufwinnr("b"), tabpagenr())'))
+ eq('c Xdir3 1', eval('GetCwdInfo(bufwinnr("c"), tabpagenr())'))
+
+ execute('tabnew x')
+ execute('new y')
+ execute('new z')
+ execute('3wincmd w')
+ eq('x Xtopdir 0', eval('GetCwdInfo(0, 0)'))
+ execute('wincmd W')
+ execute('silent lcd Xdir2')
+ eq('y Xdir2 1', eval('GetCwdInfo(0, 0)'))
+ execute('wincmd W')
+ execute('silent lcd Xdir3')
+ eq('z Xdir3 1', eval('GetCwdInfo(0, 0)'))
+ eq('x Xtopdir 0', eval('GetCwdInfo(bufwinnr("x"), 0)'))
+ eq('y Xdir2 1', eval('GetCwdInfo(bufwinnr("y"), 0)'))
+ eq('z Xdir3 1', eval('GetCwdInfo(bufwinnr("z"), 0)'))
+ execute('let tp_nr = tabpagenr()')
+ execute('tabrewind')
+ eq('x Xtopdir 0', eval('GetCwdInfo(3, tp_nr)'))
+ eq('y Xdir2 1', eval('GetCwdInfo(2, tp_nr)'))
+ eq('z Xdir3 1', eval('GetCwdInfo(1, tp_nr)'))
+ end)
+end)
diff --git a/test/functional/terminal/highlight_spec.lua b/test/functional/terminal/highlight_spec.lua
index 8876c68673..8d7c7451d3 100644
--- a/test/functional/terminal/highlight_spec.lua
+++ b/test/functional/terminal/highlight_spec.lua
@@ -165,24 +165,49 @@ end)
describe('synIDattr()', function()
local screen
-
before_each(function()
clear()
screen = Screen.new(50, 7)
- execute('highlight Normal ctermfg=1 guifg=#ff0000')
+ execute('highlight Normal ctermfg=252 guifg=#ff0000 guibg=Black')
+ -- Salmon #fa8072 Maroon #800000
+ execute('highlight Keyword ctermfg=79 guifg=Salmon guisp=Maroon')
+ end)
+
+ it('returns cterm-color if RGB-capable UI is _not_ attached', function()
+ eq('252', eval('synIDattr(hlID("Normal"), "fg")'))
+ eq('252', eval('synIDattr(hlID("Normal"), "fg#")'))
+ eq('-1', eval('synIDattr(hlID("Normal"), "bg")'))
+ eq('-1', eval('synIDattr(hlID("Normal"), "bg#")'))
+ eq('79', eval('synIDattr(hlID("Keyword"), "fg")'))
+ eq('79', eval('synIDattr(hlID("Keyword"), "fg#")'))
+ eq('', eval('synIDattr(hlID("Keyword"), "sp")'))
+ eq('', eval('synIDattr(hlID("Keyword"), "sp#")'))
end)
- after_each(function()
- screen:detach()
+ it('returns gui-color if "gui" arg is passed', function()
+ eq('Black', eval('synIDattr(hlID("Normal"), "bg", "gui")'))
+ eq('Maroon', eval('synIDattr(hlID("Keyword"), "sp", "gui")'))
+ end)
+
+ it('returns gui-color if RGB-capable UI is attached', function()
+ screen:attach(true)
+ eq('#ff0000', eval('synIDattr(hlID("Normal"), "fg")'))
+ eq('Black', eval('synIDattr(hlID("Normal"), "bg")'))
+ eq('Salmon', eval('synIDattr(hlID("Keyword"), "fg")'))
+ eq('Maroon', eval('synIDattr(hlID("Keyword"), "sp")'))
end)
- it('returns RGB number if GUI', function()
+ it('returns #RRGGBB value for fg#/bg#/sp#', function()
screen:attach(true)
- eq('#ff0000', eval('synIDattr(hlID("Normal"), "fg")'))
+ eq('#ff0000', eval('synIDattr(hlID("Normal"), "fg#")'))
+ eq('#000000', eval('synIDattr(hlID("Normal"), "bg#")'))
+ eq('#fa8072', eval('synIDattr(hlID("Keyword"), "fg#")'))
+ eq('#800000', eval('synIDattr(hlID("Keyword"), "sp#")'))
end)
it('returns color number if non-GUI', function()
screen:attach(false)
- eq('1', eval('synIDattr(hlID("Normal"), "fg")'))
+ eq('252', eval('synIDattr(hlID("Normal"), "fg")'))
+ eq('79', eval('synIDattr(hlID("Keyword"), "fg")'))
end)
end)
diff --git a/test/functional/ui/highlight_spec.lua b/test/functional/ui/highlight_spec.lua
index b156f13885..6ef40fff62 100644
--- a/test/functional/ui/highlight_spec.lua
+++ b/test/functional/ui/highlight_spec.lua
@@ -38,7 +38,6 @@ describe('manual syntax highlight', function()
os.remove('Xtest-functional-ui-highlight.tmp.vim')
end)
- -- test with "set hidden" even if the bug did not occur this way
it("works with buffer switch and 'hidden'", function()
execute('e tmp1.vim')
execute('e Xtest-functional-ui-highlight.tmp.vim')
diff --git a/test/functional/viml/function_spec.lua b/test/functional/viml/function_spec.lua
index 776e760aaf..f0a4406593 100644
--- a/test/functional/viml/function_spec.lua
+++ b/test/functional/viml/function_spec.lua
@@ -2,6 +2,7 @@ local helpers = require('test.functional.helpers')(after_each)
local clear = helpers.clear
local eq = helpers.eq
+local eval = helpers.eval
local exc_exec = helpers.exc_exec
describe('Up to MAX_FUNC_ARGS arguments are handled by', function()
@@ -27,3 +28,11 @@ describe('Up to MAX_FUNC_ARGS arguments are handled by', function()
eq('Vim(call):E740: Too many arguments for function rpcnotify', ret)
end)
end)
+
+describe('api_info()', function()
+ before_each(clear)
+ it('has the right keys', function()
+ local api_keys = eval("sort(keys(api_info()))")
+ eq({'error_types', 'functions', 'types'}, api_keys)
+ end)
+end)
diff --git a/test/unit/buffer_spec.lua b/test/unit/buffer_spec.lua
index b7f82064d7..317c9be6e7 100644
--- a/test/unit/buffer_spec.lua
+++ b/test/unit/buffer_spec.lua
@@ -1,10 +1,9 @@
-local assert = require("luassert")
local helpers = require("test.unit.helpers")
local to_cstr = helpers.to_cstr
+local get_str = helpers.ffi.string
local eq = helpers.eq
-local neq = helpers.neq
local NULL = helpers.NULL
local globals = helpers.cimport("./src/nvim/globals.h")
@@ -211,93 +210,246 @@ describe('buffer functions', function()
end)
describe('build_stl_str_hl', function()
+ local buffer_byte_size = 100
+ local STL_MAX_ITEM = 80
+ local output_buffer = ''
+
+ -- This function builds the statusline
+ --
+ -- @param arg Optional arguments are:
+ -- .pat The statusline format string
+ -- .fillchar The fill character used in the statusline
+ -- .maximum_cell_count The number of cells available in the statusline
+ local function build_stl_str_hl(arg)
+ output_buffer = to_cstr(string.rep(" ", buffer_byte_size))
+
+ local pat = arg.pat or ''
+ local fillchar = arg.fillchar or (' '):byte()
+ local maximum_cell_count = arg.maximum_cell_count or buffer_byte_size
- local output_buffer = to_cstr(string.rep(" ", 100))
-
- local build_stl_str_hl = function(pat)
return buffer.build_stl_str_hl(globals.curwin,
output_buffer,
- 100,
+ buffer_byte_size,
to_cstr(pat),
false,
- 32,
- 80,
+ fillchar,
+ maximum_cell_count,
NULL,
NULL)
end
- it('should copy plain text', function()
- local width = build_stl_str_hl("this is a test")
-
- eq(14, width)
- eq("this is a test", helpers.ffi.string(output_buffer, width))
-
- end)
-
- it('should print no file name', function()
- local width = build_stl_str_hl("%f")
-
- eq(9, width)
- eq("[No Name]", helpers.ffi.string(output_buffer, width))
-
- end)
-
- it('should print the relative file name', function()
- buffer.setfname(globals.curbuf, to_cstr("Makefile"), NULL, 1)
- local width = build_stl_str_hl("%f")
-
- eq(8, width)
- eq("Makefile", helpers.ffi.string(output_buffer, width))
-
- end)
-
- it('should print the full file name', function()
- buffer.setfname(globals.curbuf, to_cstr("Makefile"), NULL, 1)
-
- local width = build_stl_str_hl("%F")
-
- assert.is_true(8 < width)
- neq(NULL, string.find(helpers.ffi.string(output_buffer, width), "Makefile"))
-
- end)
-
- it('should print the tail file name', function()
- buffer.setfname(globals.curbuf, to_cstr("src/nvim/buffer.c"), NULL, 1)
-
- local width = build_stl_str_hl("%t")
-
- eq(8, width)
- eq("buffer.c", helpers.ffi.string(output_buffer, width))
-
- end)
-
- it('should print the buffer number', function()
- buffer.setfname(globals.curbuf, to_cstr("src/nvim/buffer.c"), NULL, 1)
-
- local width = build_stl_str_hl("%n")
-
- eq(1, width)
- eq("1", helpers.ffi.string(output_buffer, width))
- end)
-
- it('should print the current line number in the buffer', function()
- buffer.setfname(globals.curbuf, to_cstr("test/unit/buffer_spec.lua"), NULL, 1)
-
- local width = build_stl_str_hl("%l")
-
- eq(1, width)
- eq("0", helpers.ffi.string(output_buffer, width))
-
- end)
-
- it('should print the number of lines in the buffer', function()
- buffer.setfname(globals.curbuf, to_cstr("test/unit/buffer_spec.lua"), NULL, 1)
-
- local width = build_stl_str_hl("%L")
+ -- Use this function to simplify testing the comparison between
+ -- the format string and the resulting statusline.
+ --
+ -- @param description The description of what the test should be doing
+ -- @param statusline_cell_count The number of cells available in the statusline
+ -- @param input_stl The format string for the statusline
+ -- @param expected_stl The expected result string for the statusline
+ --
+ -- @param arg Options can be placed in an optional dictionary as the last parameter
+ -- .expected_cell_count The expected number of cells build_stl_str_hl will return
+ -- .expected_byte_length The expected byte length of the string
+ -- .file_name The name of the file to be tested (useful in %f type tests)
+ -- .fillchar The character that will be used to fill any 'extra' space in the stl
+ local function statusline_test (description,
+ statusline_cell_count,
+ input_stl,
+ expected_stl,
+ arg)
+
+ -- arg is the optional parameter
+ -- so we either fill in option with arg or an empty dictionary
+ local option = arg or {}
+
+ local fillchar = option.fillchar or (' '):byte()
+ local expected_cell_count = option.expected_cell_count or statusline_cell_count
+ local expected_byte_length = option.expected_byte_length or expected_cell_count
+
+ it(description, function()
+ if option.file_name then
+ buffer.setfname(globals.curbuf, to_cstr(option.file_name), NULL, 1)
+ else
+ buffer.setfname(globals.curbuf, nil, NULL, 1)
+ end
+
+ local result_cell_count = build_stl_str_hl{pat=input_stl,
+ maximum_cell_count=statusline_cell_count,
+ fillchar=fillchar}
+
+ eq(expected_stl, get_str(output_buffer, expected_byte_length))
+ eq(expected_cell_count, result_cell_count)
+ end)
+ end
- eq(1, width)
- eq("1", helpers.ffi.string(output_buffer, width))
+ -- file name testing
+ statusline_test('should print no file name', 10,
+ '%f', '[No Name]',
+ {expected_cell_count=9})
+ statusline_test('should print the relative file name', 30,
+ '%f', 'test/unit/buffer_spec.lua',
+ {file_name='test/unit/buffer_spec.lua', expected_cell_count=25})
+ statusline_test('should print the full file name', 40,
+ '%F', '/test/unit/buffer_spec.lua',
+ {file_name='/test/unit/buffer_spec.lua', expected_cell_count=26})
+
+ -- fillchar testing
+ statusline_test('should handle `!` as a fillchar', 10,
+ 'abcde%=', 'abcde!!!!!',
+ {fillchar=('!'):byte()})
+ statusline_test('should handle `~` as a fillchar', 10,
+ '%=abcde', '~~~~~abcde',
+ {fillchar=('~'):byte()})
+ statusline_test('should put fillchar `!` in between text', 10,
+ 'abc%=def', 'abc!!!!def',
+ {fillchar=('!'):byte()})
+ statusline_test('should put fillchar `~` in between text', 10,
+ 'abc%=def', 'abc~~~~def',
+ {fillchar=('~'):byte()})
+ statusline_test('should print the tail file name', 80,
+ '%t', 'buffer_spec.lua',
+ {file_name='test/unit/buffer_spec.lua', expected_cell_count=15})
+
+ -- standard text testing
+ statusline_test('should copy plain text', 80,
+ 'this is a test', 'this is a test',
+ {expected_cell_count=14})
+
+ -- line number testing
+ statusline_test('should print the buffer number', 80,
+ '%n', '1',
+ {expected_cell_count=1})
+ statusline_test('should print the current line number in the buffer', 80,
+ '%l', '0',
+ {expected_cell_count=1})
+ statusline_test('should print the number of lines in the buffer', 80,
+ '%L', '1',
+ {expected_cell_count=1})
+
+ -- truncation testing
+ statusline_test('should truncate when standard text pattern is too long', 10,
+ '0123456789abcde', '<6789abcde')
+ statusline_test('should truncate when using =', 10,
+ 'abcdef%=ghijkl', 'abcdef<jkl')
+ statusline_test('should truncate centered text when using ==', 10,
+ 'abcde%=gone%=fghij', 'abcde<ghij')
+ statusline_test('should respect the `<` marker', 10,
+ 'abc%<defghijkl', 'abc<ghijkl')
+ statusline_test('should truncate at `<` with one `=`, test 1', 10,
+ 'abc%<def%=ghijklmno', 'abc<jklmno')
+ statusline_test('should truncate at `<` with one `=`, test 2', 10,
+ 'abcdef%=ghijkl%<mno', 'abcdefghi>')
+ statusline_test('should truncate at `<` with one `=`, test 3', 10,
+ 'abc%<def%=ghijklmno', 'abc<jklmno')
+ statusline_test('should truncate at `<` with one `=`, test 4', 10,
+ 'abc%<def%=ghij', 'abcdefghij')
+ statusline_test('should truncate at `<` with one `=`, test 4', 10,
+ 'abc%<def%=ghijk', 'abc<fghijk')
+
+ statusline_test('should truncate at `<` with many `=`, test 4', 10,
+ 'ab%<cdef%=g%=h%=ijk', 'ab<efghijk')
+
+ statusline_test('should truncate at the first `<`', 10,
+ 'abc%<def%<ghijklm', 'abc<hijklm')
+
+ -- alignment testing
+ statusline_test('should right align when using =', 20,
+ 'neo%=vim', 'neo vim')
+ statusline_test('should, when possible, center text when using %=text%=', 20,
+ 'abc%=neovim%=def', 'abc neovim def')
+ statusline_test('should handle uneven spacing in the buffer when using %=text%=', 20,
+ 'abc%=neo_vim%=def', 'abc neo_vim def')
+ statusline_test('should have equal spaces even with non-equal sides when using =', 20,
+ 'foobar%=test%=baz', 'foobar test baz')
+ statusline_test('should have equal spaces even with longer right side when using =', 20,
+ 'a%=test%=longtext', 'a test longtext')
+ statusline_test('should handle an empty left side when using ==', 20,
+ '%=test%=baz', ' test baz')
+ statusline_test('should handle an empty right side when using ==', 20,
+ 'foobar%=test%=', 'foobar test ')
+ statusline_test('should handle consecutive empty ==', 20,
+ '%=%=test%=', ' test ')
+ statusline_test('should handle an = alone', 20,
+ '%=', ' ')
+ statusline_test('should right align text when it is alone with =', 20,
+ '%=foo', ' foo')
+ statusline_test('should left align text when it is alone with =', 20,
+ 'foo%=', 'foo ')
+
+ statusline_test('should approximately center text when using %=text%=', 21,
+ 'abc%=neovim%=def', 'abc neovim def')
+ statusline_test('should completely fill the buffer when using %=text%=', 21,
+ 'abc%=neo_vim%=def', 'abc neo_vim def')
+ statusline_test('should have equal spaces even with non-equal sides when using =', 21,
+ 'foobar%=test%=baz', 'foobar test baz')
+ statusline_test('should have equal spaces even with longer right side when using =', 21,
+ 'a%=test%=longtext', 'a test longtext')
+ statusline_test('should handle an empty left side when using ==', 21,
+ '%=test%=baz', ' test baz')
+ statusline_test('should handle an empty right side when using ==', 21,
+ 'foobar%=test%=', 'foobar test ')
+
+ statusline_test('should quadrant the text when using 3 %=', 40,
+ 'abcd%=n%=eovim%=ef', 'abcd n eovim ef')
+ statusline_test('should work well with %t', 40,
+ '%t%=right_aligned', 'buffer_spec.lua right_aligned',
+ {file_name='test/unit/buffer_spec.lua'})
+ statusline_test('should work well with %t and regular text', 40,
+ 'l%=m_l %t m_r%=r', 'l m_l buffer_spec.lua m_r r',
+ {file_name='test/unit/buffer_spec.lua'})
+ statusline_test('should work well with %=, %t, %L, and %l', 40,
+ '%t %= %L %= %l', 'buffer_spec.lua 1 0',
+ {file_name='test/unit/buffer_spec.lua'})
+
+ statusline_test('should quadrant the text when using 3 %=', 41,
+ 'abcd%=n%=eovim%=ef', 'abcd n eovim ef')
+ statusline_test('should work well with %t', 41,
+ '%t%=right_aligned', 'buffer_spec.lua right_aligned',
+ {file_name='test/unit/buffer_spec.lua'})
+ statusline_test('should work well with %t and regular text', 41,
+ 'l%=m_l %t m_r%=r', 'l m_l buffer_spec.lua m_r r',
+ {file_name='test/unit/buffer_spec.lua'})
+ statusline_test('should work well with %=, %t, %L, and %l', 41,
+ '%t %= %L %= %l', 'buffer_spec.lua 1 0',
+ {file_name='test/unit/buffer_spec.lua'})
+
+ statusline_test('should work with 10 %=', 50,
+ 'aaaa%=b%=c%=d%=e%=fg%=hi%=jk%=lmnop%=qrstuv%=wxyz',
+ 'aaaa b c d e fg hi jk lmnop qrstuv wxyz')
+
+ -- maximum stl item testing
+ statusline_test('should handle a much larger amount of = than buffer locations', 20,
+ ('%='):rep(STL_MAX_ITEM - 1),
+ ' ') -- Should be fine, because within limit
+ statusline_test('should handle a much larger amount of = than stl max item', 20,
+ ('%='):rep(STL_MAX_ITEM + 1),
+ ' E541') -- Should show the VIM error
+ statusline_test('should handle many extra characters', 20,
+ 'a' .. ('a'):rep(STL_MAX_ITEM * 4),
+ '<aaaaaaaaaaaaaaaaaaa') -- Does not show the error because there are no items
+ statusline_test('should handle almost maximum of characters and flags', 20,
+ 'a' .. ('%=a'):rep(STL_MAX_ITEM - 1),
+ 'a<aaaaaaaaaaaaaaaaaa') -- Should not show the VIM error
+ statusline_test('should handle many extra characters and flags', 20,
+ 'a' .. ('%=a'):rep(STL_MAX_ITEM),
+ 'a<aaaaaaaaaaaaa E541') -- Should show the VIM error
+ statusline_test('should handle many extra characters and flags', 20,
+ 'a' .. ('%=a'):rep(STL_MAX_ITEM * 2),
+ 'a<aaaaaaaaaaaaa E541') -- Should show the VIM error
+ statusline_test('should handle many extra characters and flags with truncation', 20,
+ 'aaa%<' .. ('%=a'):rep(STL_MAX_ITEM),
+ 'aaa<aaaaaaaaaaa E541') -- Should show the VIM error
+ statusline_test('should handle many characters and flags before and after truncation', 20,
+ 'a%=a%=a%<' .. ('%=a'):rep(STL_MAX_ITEM),
+ 'aaa<aaaaaaaaaaa E541') -- Should show the VIM error
+
+
+ -- multi-byte testing
+ statusline_test('should handle multibyte characters', 10,
+ 'Ĉ%=x', 'Ĉ x',
+ {expected_byte_length=11})
+ statusline_test('should handle multibyte characters and different fillchars', 10,
+ 'Ą%=mid%=end', 'Ą@mid@@end',
+ {fillchar=('@'):byte(), expected_byte_length=11})
- end)
end)
end)