diff options
Diffstat (limited to 'test/functional/legacy')
20 files changed, 430 insertions, 553 deletions
diff --git a/test/functional/legacy/021_control_wi_spec.lua b/test/functional/legacy/021_control_wi_spec.lua index 87d9deed7a..94871433cd 100644 --- a/test/functional/legacy/021_control_wi_spec.lua +++ b/test/functional/legacy/021_control_wi_spec.lua @@ -18,7 +18,7 @@ describe('CTRL-W CTRL-I', function() start found wrong line test text]]) - -- Search for the second occurence of start and append to register + -- Search for the second occurrence of start and append to register feed_command('/start') feed('2[<C-i>') feed_command('yank A') diff --git a/test/functional/legacy/022_line_ending_spec.lua b/test/functional/legacy/022_line_ending_spec.lua deleted file mode 100644 index fb4b782011..0000000000 --- a/test/functional/legacy/022_line_ending_spec.lua +++ /dev/null @@ -1,25 +0,0 @@ --- Tests for file with some lines ending in CTRL-M, some not - -local helpers = require('test.functional.helpers')(after_each) -local clear, feed = helpers.clear, helpers.feed -local feed_command, expect = helpers.feed_command, helpers.expect - -describe('line ending', function() - setup(clear) - - it('is working', function() - feed('i', [[ - this lines ends in a<C-V><C-M> - this one doesn't - this one does<C-V><C-M> - and the last one doesn't]], '<ESC>') - - feed_command('set ta tx') - feed_command('e!') - - expect("this lines ends in a\r\n".. - "this one doesn't\n".. - "this one does\r\n".. - "and the last one doesn't") - end) -end) diff --git a/test/functional/legacy/041_writing_and_reading_hundred_kbyte_spec.lua b/test/functional/legacy/041_writing_and_reading_hundred_kbyte_spec.lua deleted file mode 100644 index b526d82519..0000000000 --- a/test/functional/legacy/041_writing_and_reading_hundred_kbyte_spec.lua +++ /dev/null @@ -1,43 +0,0 @@ --- Test for writing and reading a file of over 100 Kbyte - -local helpers = require('test.functional.helpers')(after_each) - -local clear, feed, insert = helpers.clear, helpers.feed, helpers.insert -local command, expect = helpers.command, helpers.expect -local wait = helpers.wait - -describe('writing and reading a file of over 100 Kbyte', function() - setup(clear) - - it('is working', function() - insert([[ - This is the start - This is the leader - This is the middle - This is the trailer - This is the end]]) - - feed('kY3000p2GY3000p') - wait() - - command('w! test.out') - command('%d') - command('e! test.out') - command('yank A') - command('3003yank A') - command('6005yank A') - command('%d') - command('0put a') - command('$d') - command('w!') - - expect([[ - This is the start - This is the middle - This is the end]]) - end) - - teardown(function() - os.remove('test.out') - end) -end) diff --git a/test/functional/legacy/045_folding_spec.lua b/test/functional/legacy/045_folding_spec.lua index 6ca1176aea..1e5239ceac 100644 --- a/test/functional/legacy/045_folding_spec.lua +++ b/test/functional/legacy/045_folding_spec.lua @@ -14,9 +14,6 @@ describe('folding', function() screen = Screen.new(20, 8) screen:attach() end) - after_each(function() - screen:detach() - end) it('creation, opening, moving (to the end) and closing', function() insert([[ diff --git a/test/functional/legacy/063_match_and_matchadd_spec.lua b/test/functional/legacy/063_match_and_matchadd_spec.lua index 518d79861b..a4f5d6ac5b 100644 --- a/test/functional/legacy/063_match_and_matchadd_spec.lua +++ b/test/functional/legacy/063_match_and_matchadd_spec.lua @@ -14,6 +14,10 @@ describe('063: Test for ":match", "matchadd()" and related functions', function( it('is working', function() local screen = Screen.new(40, 5) screen:attach() + screen:set_default_attr_ids({ + [0] = {bold = true, foreground = Screen.colors.Blue}, + [1] = {background = Screen.colors.Red}, + }) -- Check that "matcharg()" returns the correct group and pattern if a match -- is defined. @@ -126,22 +130,22 @@ describe('063: Test for ":match", "matchadd()" and related functions', function( command("call matchaddpos('MyGroup1', [[1, 5], [1, 8, 3]], 10, 3)") screen:expect([[ abcd{1:e}fg{1:hij}klmnop^q | - ~ | - ~ | - ~ | + {0:~ }| + {0:~ }| + {0:~ }| | - ]], {[1] = {background = Screen.colors.Red}}, {{bold = true, foreground = Screen.colors.Blue}}) + ]]) command("call clearmatches()") command("call setline(1, 'abcdΣabcdef')") command("call matchaddpos('MyGroup1', [[1, 4, 2], [1, 9, 2]])") screen:expect([[ abc{1:dΣ}ab{1:cd}e^f | - ~ | - ~ | - ~ | + {0:~ }| + {0:~ }| + {0:~ }| | - ]],{[1] = {background = Screen.colors.Red}}, {{bold = true, foreground = Screen.colors.Blue}}) + ]]) end) end) diff --git a/test/functional/legacy/075_maparg_spec.lua b/test/functional/legacy/075_maparg_spec.lua index 0164f5077a..ee2b041b51 100644 --- a/test/functional/legacy/075_maparg_spec.lua +++ b/test/functional/legacy/075_maparg_spec.lua @@ -49,9 +49,9 @@ describe('maparg()', function() -- Assert buffer contents. expect([[ is<F4>foo - {'lnum': 0, 'silent': 0, 'noremap': 0, 'lhs': 'foo<C-V>', 'mode': ' ', 'nowait': 0, 'expr': 0, 'sid': 0, 'rhs': 'is<F4>foo', 'buffer': 0} - {'lnum': 0, 'silent': 1, 'noremap': 1, 'lhs': 'bar', 'mode': 'v', 'nowait': 0, 'expr': 1, 'sid': 0, 'rhs': 'isbar', 'buffer': 1} - {'lnum': 0, 'silent': 0, 'noremap': 0, 'lhs': 'foo', 'mode': ' ', 'nowait': 1, 'expr': 0, 'sid': 0, 'rhs': 'bar', 'buffer': 1} + {'lnum': 0, 'script': 0, 'silent': 0, 'noremap': 0, 'lhs': 'foo<C-V>', 'mode': ' ', 'nowait': 0, 'expr': 0, 'sid': 0, 'rhs': 'is<F4>foo', 'buffer': 0} + {'lnum': 0, 'script': 1, 'silent': 1, 'noremap': 1, 'lhs': 'bar', 'mode': 'v', 'nowait': 0, 'expr': 1, 'sid': 0, 'rhs': 'isbar', 'buffer': 1} + {'lnum': 0, 'script': 0, 'silent': 0, 'noremap': 0, 'lhs': 'foo', 'mode': ' ', 'nowait': 1, 'expr': 0, 'sid': 0, 'rhs': 'bar', 'buffer': 1} xrx yRy abcd]]) diff --git a/test/functional/legacy/077_mf_hash_grow_spec.lua b/test/functional/legacy/077_mf_hash_grow_spec.lua deleted file mode 100644 index 4719a3ecbf..0000000000 --- a/test/functional/legacy/077_mf_hash_grow_spec.lua +++ /dev/null @@ -1,52 +0,0 @@ --- Inserts 2 million lines with consecutive integers starting from 1 --- (essentially, the output of GNU's seq 1 2000000), writes them to Xtest --- and calculates its cksum. --- We need 2 million lines to trigger a call to mf_hash_grow(). If it would mess --- up the lines the checksum would differ. --- cksum is part of POSIX and so should be available on most Unixes. --- If it isn't available then the test will be skipped. - -local helpers = require('test.functional.helpers')(after_each) - -local feed = helpers.feed -local wait = helpers.wait -local clear = helpers.clear -local expect = helpers.expect -local command = helpers.command - -describe('mf_hash_grow()', function() - setup(clear) - - -- Check to see if cksum exists, otherwise skip the test - local null = helpers.iswin() and 'nul' or '/dev/null' - if os.execute('cksum --help >' .. null .. ' 2>&1') ~= 0 then - pending('was not tested because cksum was not found', function() end) - else - it('is working', function() - command('set fileformat=unix undolevels=-1') - - -- Fill the buffer with numbers 1 - 2000000 - command('let i = 1') - command('while i <= 2000000 | call append(i, range(i, i + 99)) | let i += 100 | endwhile') - - -- Delete empty first line, save to Xtest, and clear buffer - feed('ggdd<cr>') - wait() - command('w! Xtest') - feed('ggdG<cr>') - wait() - - -- Calculate the cksum of Xtest and delete first line - command('r !cksum Xtest') - feed('ggdd<cr>') - - -- Assert correct output of cksum. - expect([[ - 3678979763 14888896 Xtest]]) - end) - end - - teardown(function() - os.remove('Xtest') - end) -end) diff --git a/test/functional/legacy/084_curswant_spec.lua b/test/functional/legacy/084_curswant_spec.lua deleted file mode 100644 index 42cb2fc56d..0000000000 --- a/test/functional/legacy/084_curswant_spec.lua +++ /dev/null @@ -1,49 +0,0 @@ --- Tests for curswant not changing when setting an option. - -local helpers = require('test.functional.helpers')(after_each) -local insert, source = helpers.insert, helpers.source -local clear, expect = helpers.clear, helpers.expect - -describe('curswant', function() - setup(clear) - - -- luacheck: ignore 621 (Indentation) - it('is working', function() - insert([[ - start target options - tabstop - timeoutlen - ttimeoutlen - end target options]]) - - source([[ - /^start target options$/+1,/^end target options$/-1 yank - let target_option_names = split(@0) - function TestCurswant(option_name) - normal! ggf8j - let curswant_before = winsaveview().curswant - execute 'let' '&'.a:option_name '=' '&'.a:option_name - let curswant_after = winsaveview().curswant - return [a:option_name, curswant_before, curswant_after] - endfunction - - new - put =['1234567890', '12345'] - 1 delete _ - let result = [] - for option_name in target_option_names - call add(result, TestCurswant(option_name)) - endfor - - new - put =map(copy(result), 'join(v:val, '' '')') - 1 delete _ - ]]) - - -- Assert buffer contents. - expect([[ - tabstop 7 4 - timeoutlen 7 7 - ttimeoutlen 7 7]]) - end) -end) diff --git a/test/functional/legacy/095_regexp_multibyte_spec.lua b/test/functional/legacy/095_regexp_multibyte_spec.lua index 845ebaaad7..fad0dc8023 100644 --- a/test/functional/legacy/095_regexp_multibyte_spec.lua +++ b/test/functional/legacy/095_regexp_multibyte_spec.lua @@ -1,5 +1,5 @@ -- Test for regexp patterns with multi-byte support, using utf-8. --- See test64 for the non-multi-byte tests. +-- See test_regexp_latin.vim for the non-multi-byte tests. -- A pattern that gives the expected result produces OK, so that we know it was -- actually tried. diff --git a/test/functional/legacy/097_glob_path_spec.lua b/test/functional/legacy/097_glob_path_spec.lua index ccd93fed60..dd5a26ad3b 100644 --- a/test/functional/legacy/097_glob_path_spec.lua +++ b/test/functional/legacy/097_glob_path_spec.lua @@ -52,7 +52,7 @@ describe('glob() and globpath()', function() command([[$put =glob('Xxx\{')]]) command([[$put =glob('Xxx\$')]]) - command('silent w! Xxx{') + command('silent w! Xxx\\{') command([[w! Xxx\$]]) command([[$put =glob('Xxx\{')]]) command([[$put =glob('Xxx\$')]]) diff --git a/test/functional/legacy/098_scrollbind_spec.lua b/test/functional/legacy/098_scrollbind_spec.lua deleted file mode 100644 index d22aefdcbc..0000000000 --- a/test/functional/legacy/098_scrollbind_spec.lua +++ /dev/null @@ -1,48 +0,0 @@ --- Test for 'scrollbind' causing an unexpected scroll of one of the windows. - -local helpers = require('test.functional.helpers')(after_each) -local source = helpers.source -local clear, expect = helpers.clear, helpers.expect - -describe('scrollbind', function() - setup(clear) - - it('is working', function() - source([[ - set laststatus=0 - let g:totalLines = &lines * 20 - let middle = g:totalLines / 2 - wincmd n - wincmd o - for i in range(1, g:totalLines) - call setline(i, 'LINE ' . i) - endfor - exe string(middle) - normal zt - normal M - aboveleft vert new - for i in range(1, g:totalLines) - call setline(i, 'line ' . i) - endfor - exe string(middle) - normal zt - normal M - setl scb | wincmd p - setl scb - wincmd w - let topLineLeft = line('w0') - wincmd p - let topLineRight = line('w0') - setl noscrollbind - wincmd p - setl noscrollbind - q! - %del _ - call setline(1, 'Difference between the top lines (left - right): ' . string(topLineLeft - topLineRight)) - brewind - ]]) - - -- Assert buffer contents. - expect("Difference between the top lines (left - right): 0") - end) -end) diff --git a/test/functional/legacy/104_let_assignment_spec.lua b/test/functional/legacy/104_let_assignment_spec.lua deleted file mode 100644 index a03bb026f6..0000000000 --- a/test/functional/legacy/104_let_assignment_spec.lua +++ /dev/null @@ -1,54 +0,0 @@ --- Tests for :let. - -local helpers = require('test.functional.helpers')(after_each) -local clear, source = helpers.clear, helpers.source -local command, expect = helpers.command, helpers.expect - -describe(':let', function() - setup(clear) - - it('is working', function() - command('set runtimepath+=test/functional/fixtures') - - -- Test to not autoload when assigning. It causes internal error. - source([[ - try - let Test104#numvar = function('tr') - $put ='OK: ' . string(Test104#numvar) - catch - $put ='FAIL: ' . v:exception - endtry - let a = 1 - let b = 2 - for letargs in ['a b', '{0 == 1 ? "a" : "b"}', '{0 == 1 ? "a" : "b"} a', 'a {0 == 1 ? "a" : "b"}'] - try - redir => messages - execute 'let' letargs - redir END - $put ='OK:' - $put =split(substitute(messages, '\n', '\0 ', 'g'), '\n') - catch - $put ='FAIL: ' . v:exception - redir END - endtry - endfor]]) - - -- Remove empty line - command('1d') - - -- Assert buffer contents. - expect([[ - OK: function('tr') - OK: - a #1 - b #2 - OK: - b #2 - OK: - b #2 - a #1 - OK: - a #1 - b #2]]) - end) -end) diff --git a/test/functional/legacy/assert_spec.lua b/test/functional/legacy/assert_spec.lua index 8df2d89b70..d48b8882af 100644 --- a/test/functional/legacy/assert_spec.lua +++ b/test/functional/legacy/assert_spec.lua @@ -3,6 +3,7 @@ local nvim, call = helpers.meths, helpers.call local clear, eq = helpers.clear, helpers.eq local source, command = helpers.source, helpers.command local exc_exec = helpers.exc_exec +local eval = helpers.eval local function expected_errors(errors) eq(errors, nvim.get_vvar('errors')) @@ -37,6 +38,9 @@ describe('assert function:', function() call assert_equal(4, n) let l = [1, 2, 3] call assert_equal([1, 2, 3], l) + call assert_equal(v:_null_list, v:_null_list) + call assert_equal(v:_null_list, []) + call assert_equal([], v:_null_list) fu Func() endfu let F1 = function('Func') @@ -47,18 +51,18 @@ describe('assert function:', function() end) it('should not change v:errors when expected is equal to actual', function() - call('assert_equal', '', '') - call('assert_equal', 'string', 'string') + eq(0, call('assert_equal', '', '')) + eq(0, call('assert_equal', 'string', 'string')) expected_empty() end) it('should change v:errors when expected is not equal to actual', function() - call('assert_equal', 0, {0}) + eq(1, call('assert_equal', 0, {0})) expected_errors({'Expected 0 but got [0]'}) end) it('should change v:errors when expected is not equal to actual', function() - call('assert_equal', 0, "0") + eq(1, call('assert_equal', 0, "0")) expected_errors({"Expected 0 but got '0'"}) end) @@ -91,18 +95,23 @@ describe('assert function:', function() call('assert_equal', 'foo', 'bar', 'testing') expected_errors({"testing: Expected 'foo' but got 'bar'"}) end) + + it('should shorten a long message', function() + call ('assert_equal', 'XxxxxxxxxxxxxxxxxxxxxxX', 'XyyyyyyyyyyyyyyyyyyyyyyyyyX') + expected_errors({"Expected 'X\\[x occurs 21 times]X' but got 'X\\[y occurs 25 times]X'"}) + end) end) -- assert_notequal({expected}, {actual}[, {msg}]) describe('assert_notequal', function() it('should not change v:errors when expected differs from actual', function() - call('assert_notequal', 'foo', 4) - call('assert_notequal', {1, 2, 3}, 'foo') + eq(0, call('assert_notequal', 'foo', 4)) + eq(0, call('assert_notequal', {1, 2, 3}, 'foo')) expected_empty() end) it('should change v:errors when expected is equal to actual', function() - call('assert_notequal', 'foo', 'foo') + eq(1, call('assert_notequal', 'foo', 'foo')) expected_errors({"Expected not equal to 'foo'"}) end) end) @@ -110,13 +119,13 @@ describe('assert function:', function() -- assert_false({actual}, [, {msg}]) describe('assert_false', function() it('should not change v:errors when actual is false', function() - call('assert_false', 0) - call('assert_false', false) + eq(0, call('assert_false', 0)) + eq(0, call('assert_false', false)) expected_empty() end) it('should change v:errors when actual is not false', function() - call('assert_false', 1) + eq(1, call('assert_false', 1)) expected_errors({'Expected False but got 1'}) end) @@ -129,14 +138,14 @@ describe('assert function:', function() -- assert_true({actual}, [, {msg}]) describe('assert_true', function() it('should not change v:errors when actual is true', function() - call('assert_true', 1) - call('assert_true', -1) -- In Vim script, non-zero Numbers are TRUE. - call('assert_true', true) + eq(0, call('assert_true', 1)) + eq(0, call('assert_true', -1)) -- In Vim script, non-zero Numbers are TRUE. + eq(0, call('assert_true', true)) expected_empty() end) it('should change v:errors when actual is not true', function() - call('assert_true', 1.5) + eq(1, call('assert_true', 1.5)) expected_errors({'Expected True but got 1.5'}) end) end) @@ -233,20 +242,31 @@ describe('assert function:', function() -- assert_fails({cmd}, [, {error}]) describe('assert_fails', function() it('should change v:errors when error does not match v:errmsg', function() - command([[call assert_fails('xxx', {})]]) + eq(1, eval([[assert_fails('xxx', {})]])) command([[call assert_match("Expected {} but got 'E731:", v:errors[0])]]) expected_errors({"Expected {} but got 'E731: using Dictionary as a String'"}) end) it('should not change v:errors when cmd errors', function() - call('assert_fails', 'NonexistentCmd') + eq(0, eval([[assert_fails('NonexistentCmd')]])) expected_empty() end) it('should change v:errors when cmd succeeds', function() - call('assert_fails', 'call empty("")') + eq(1, eval([[assert_fails('call empty("")', '')]])) expected_errors({'command did not fail: call empty("")'}) end) + + it('can specify and get a message about what failed', function() + eq(1, eval([[assert_fails('xxx', {}, 'stupid')]])) + command([[call assert_match("stupid: Expected {} but got 'E731:", v:errors[0])]]) + expected_errors({"stupid: Expected {} but got 'E731: using Dictionary as a String'"}) + end) + + it('can specify and get a message even when cmd succeeds', function() + eq(1, eval([[assert_fails('echo', '', 'echo command')]])) + expected_errors({'command did not fail: echo command'}) + end) end) -- assert_inrange({lower}, {upper}, {actual}[, {msg}]) @@ -277,7 +297,7 @@ describe('assert function:', function() -- assert_report({msg}) describe('assert_report()', function() it('should add a message to v:errors', function() - command("call assert_report('something is wrong')") + eq(1, call('assert_report', 'something is wrong')) command("call assert_match('something is wrong', v:errors[0])") command('call remove(v:errors, 0)') expected_empty() @@ -291,7 +311,7 @@ describe('assert function:', function() try nocommand catch - call assert_exception('E492') + call assert_equal(0, assert_exception('E492')) endtry ]]) expected_empty() @@ -304,9 +324,9 @@ describe('assert function:', function() catch try " illegal argument, get NULL for error - call assert_exception([]) + call assert_equal(1, assert_exception([])) catch - call assert_exception('E730') + call assert_equal(0, assert_exception('E730')) endtry endtry ]]) diff --git a/test/functional/legacy/breakindent_spec.lua b/test/functional/legacy/breakindent_spec.lua deleted file mode 100644 index fd25e809e0..0000000000 --- a/test/functional/legacy/breakindent_spec.lua +++ /dev/null @@ -1,214 +0,0 @@ --- Test for breakindent - -local helpers = require('test.functional.helpers')(after_each) -local feed, insert = helpers.feed, helpers.insert -local clear, feed_command, expect = helpers.clear, helpers.feed_command, helpers.expect - -describe('breakindent', function() - setup(clear) - - -- luacheck: ignore 621 (Indentation) - -- luacheck: ignore 613 (Trailing whitespace in a string) - -- luacheck: ignore 611 (Line contains only whitespaces) - it('is working', function() - insert('dummy text') - - feed_command('set wildchar=^E') - feed_command('10new') - feed_command('vsp') - feed_command('vert resize 20') - feed_command([[put =\"\tabcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOP\"]]) - feed_command('set ts=4 sw=4 sts=4 breakindent') - feed_command('fu! ScreenChar(line, width)') - feed_command(' let c=""') - feed_command(' for i in range(1,a:width)') - feed_command(' let c.=nr2char(screenchar(a:line, i))') - feed_command(' endfor') - feed_command([[ let c.="\n"]]) - feed_command(' for i in range(1,a:width)') - feed_command(' let c.=nr2char(screenchar(a:line+1, i))') - feed_command(' endfor') - feed_command([[ let c.="\n"]]) - feed_command(' for i in range(1,a:width)') - feed_command(' let c.=nr2char(screenchar(a:line+2, i))') - feed_command(' endfor') - feed_command(' return c') - feed_command('endfu') - feed_command('fu DoRecordScreen()') - feed_command(' wincmd l') - feed_command([[ $put =printf(\"\n%s\", g:test)]]) - feed_command(' $put =g:line1') - feed_command(' wincmd p') - feed_command('endfu') - feed_command('set briopt=min:0') - feed_command('let g:test="Test 1: Simple breakindent"') - feed_command('let line1=ScreenChar(line("."),8)') - feed_command('call DoRecordScreen()') - feed_command('let g:test="Test 2: Simple breakindent + sbr=>>"') - feed_command('set sbr=>>') - feed_command('let line1=ScreenChar(line("."),8)') - feed_command('call DoRecordScreen()') - feed_command('let g:test ="Test 3: Simple breakindent + briopt:sbr"') - feed_command('set briopt=sbr,min:0 sbr=++') - feed_command('let line1=ScreenChar(line("."),8)') - feed_command('call DoRecordScreen()') - feed_command('let g:test ="Test 4: Simple breakindent + min width: 18"') - feed_command('set sbr= briopt=min:18') - feed_command('let line1=ScreenChar(line("."),8)') - feed_command('call DoRecordScreen()') - feed_command('let g:test =" Test 5: Simple breakindent + shift by 2"') - feed_command('set briopt=shift:2,min:0') - feed_command('let line1=ScreenChar(line("."),8)') - feed_command('call DoRecordScreen()') - feed_command('let g:test=" Test 6: Simple breakindent + shift by -1"') - feed_command('set briopt=shift:-1,min:0') - feed_command('let line1=ScreenChar(line("."),8)') - feed_command('call DoRecordScreen()') - feed_command('let g:test=" Test 7: breakindent + shift by +1 + nu + sbr=? briopt:sbr"') - feed_command('set briopt=shift:1,sbr,min:0 nu sbr=? nuw=4') - feed_command('let line1=ScreenChar(line("."),10)') - feed_command('call DoRecordScreen()') - feed_command('let g:test=" Test 8: breakindent + shift:1 + nu + sbr=# list briopt:sbr"') - feed_command('set briopt=shift:1,sbr,min:0 nu sbr=# list lcs&vi') - feed_command('let line1=ScreenChar(line("."),10)') - feed_command('call DoRecordScreen()') - feed_command([[let g:test=" Test 9: breakindent + shift by +1 + 'nu' + sbr=# list"]]) - feed_command('set briopt-=sbr') - feed_command('let line1=ScreenChar(line("."),10)') - feed_command('call DoRecordScreen()') - feed_command([[let g:test=" Test 10: breakindent + shift by +1 + 'nu' + sbr=~ cpo+=n"]]) - feed_command('set cpo+=n sbr=~ nu nuw=4 nolist briopt=sbr,min:0') - feed_command('let line1=ScreenChar(line("."),10)') - feed_command('call DoRecordScreen()') - feed_command('wincmd p') - feed_command([[let g:test="\n Test 11: strdisplaywidth when breakindent is on"]]) - feed_command('set cpo-=n sbr=>> nu nuw=4 nolist briopt= ts=4') - -- Skip leading tab when calculating text width. - feed_command('let text=getline(2)') - -- Text wraps 3 times. - feed_command('let width = strlen(text[1:])+indent(2)*4+strlen(&sbr)*3') - feed_command('$put =g:test') - feed_command([[$put =printf(\"strdisplaywidth: %d == calculated: %d\", strdisplaywidth(text), width)]]) - feed_command([[let g:str="\t\t\t\t\t{"]]) - feed_command('let g:test=" Test 12: breakindent + long indent"') - feed_command('wincmd p') - feed_command('set all& breakindent linebreak briopt=min:10 nu numberwidth=3 ts=4') - feed_command('$put =g:str') - feed('zt') - feed_command('let line1=ScreenChar(1,10)') - feed_command('wincmd p') - feed_command('call DoRecordScreen()') - - -- Test, that the string " a\tb\tc\td\te" is correctly displayed in a - -- 20 column wide window (see bug report - -- https://groups.google.com/d/msg/vim_dev/ZOdg2mc9c9Y/TT8EhFjEy0IJ ). - feed_command('only') - feed_command('vert 20new') - feed_command('set all& breakindent briopt=min:10') - feed_command([[call setline(1, [" a\tb\tc\td\te", " z y x w v"])]]) - feed_command([[/^\s*a]]) - feed('fbgjyl') - feed_command('let line1 = @0') - feed_command([[?^\s*z]]) - feed('fygjyl') - feed_command('let line2 = @0') - feed_command('quit!') - feed_command([[$put ='Test 13: breakindent with wrapping Tab']]) - feed_command('$put =line1') - feed_command('$put =line2') - - feed_command('let g:test="Test 14: breakindent + visual blockwise delete #1"') - feed_command('set all& breakindent shada+=nX-test-breakindent.shada') - feed_command('30vnew') - feed_command('normal! 3a1234567890') - feed_command('normal! a abcde') - feed_command([[exec "normal! 0\<C-V>tex"]]) - feed_command('let line1=ScreenChar(line("."),8)') - feed_command('call DoRecordScreen()') - - feed_command('let g:test="Test 15: breakindent + visual blockwise delete #2"') - feed_command('%d') - feed_command('normal! 4a1234567890') - feed_command([[exec "normal! >>\<C-V>3f0x"]]) - feed_command('let line1=ScreenChar(line("."),20)') - feed_command('call DoRecordScreen()') - feed_command('quit!') - - -- Assert buffer contents. - expect([[ - - abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOP - - Test 1: Simple breakindent - abcd - qrst - GHIJ - - Test 2: Simple breakindent + sbr=>> - abcd - >>qr - >>EF - - Test 3: Simple breakindent + briopt:sbr - abcd - ++ qrst - ++ GHIJ - - Test 4: Simple breakindent + min width: 18 - abcd - qrstuv - IJKLMN - - Test 5: Simple breakindent + shift by 2 - abcd - qr - EF - - Test 6: Simple breakindent + shift by -1 - abcd - qrstu - HIJKL - - Test 7: breakindent + shift by +1 + nu + sbr=? briopt:sbr - 2 ab - ? m - ? x - - Test 8: breakindent + shift:1 + nu + sbr=# list briopt:sbr - 2 ^Iabcd - # opq - # BCD - - Test 9: breakindent + shift by +1 + 'nu' + sbr=# list - 2 ^Iabcd - #op - #AB - - Test 10: breakindent + shift by +1 + 'nu' + sbr=~ cpo+=n - 2 ab - ~ mn - ~ yz - - Test 11: strdisplaywidth when breakindent is on - strdisplaywidth: 46 == calculated: 64 - { - - Test 12: breakindent + long indent - 56 - - ~ - Test 13: breakindent with wrapping Tab - d - w - - Test 14: breakindent + visual blockwise delete #1 - e - ~ - ~ - - Test 15: breakindent + visual blockwise delete #2 - 1234567890 - ~ - ~ ]]) - end) -end) diff --git a/test/functional/legacy/delete_spec.lua b/test/functional/legacy/delete_spec.lua index 9ea3269828..f2ced8942d 100644 --- a/test/functional/legacy/delete_spec.lua +++ b/test/functional/legacy/delete_spec.lua @@ -56,7 +56,7 @@ describe('Test for delete()', function() endif ]]) if eval('v:shell_error') ~= 0 then - pending('Cannot create symlink', function()end) + pending('Cannot create symlink') end -- Delete the link, not the file eq(0, eval("delete('Xlink')")) diff --git a/test/functional/legacy/eval_spec.lua b/test/functional/legacy/eval_spec.lua index c5d38d6d05..4198ea8bfe 100644 --- a/test/functional/legacy/eval_spec.lua +++ b/test/functional/legacy/eval_spec.lua @@ -360,7 +360,7 @@ describe('eval', function() abcD3b]]) -- From now on we delete the buffer contents after each expect() to make - -- the next expect() easier to write. This is neccessary because null + -- the next expect() easier to write. This is necessary because null -- bytes on a line by itself don't play well together with the dedent -- function used in expect(). command('%delete') @@ -416,7 +416,7 @@ describe('eval', function() ' abcD3b50') end) - -- The tests for setting lists with NLs are split into seperate it() blocks + -- The tests for setting lists with NLs are split into separate it() blocks -- to make the expect() calls easier to write. Otherwise the null byte can -- make trouble on a line on its own. it('setting lists with NLs with setreg(), part 1', function() diff --git a/test/functional/legacy/expand_spec.lua b/test/functional/legacy/expand_spec.lua index 1b735080f4..f238128b31 100644 --- a/test/functional/legacy/expand_spec.lua +++ b/test/functional/legacy/expand_spec.lua @@ -70,6 +70,40 @@ describe('expand file name', function() call assert_match('\~', expand('%:p')) bwipe! endfunc + + func Test_expandcmd() + let $FOO = 'Test' + call assert_equal('e x/Test/y', expandcmd('e x/$FOO/y')) + unlet $FOO + + new + edit Xfile1 + call assert_equal('e Xfile1', expandcmd('e %')) + edit Xfile2 + edit Xfile1 + call assert_equal('e Xfile2', expandcmd('e #')) + edit Xfile2 + edit Xfile3 + edit Xfile4 + let bnum = bufnr('Xfile2') + call assert_equal('e Xfile2', expandcmd('e #' . bnum)) + call setline('.', 'Vim!@#') + call assert_equal('e Vim', expandcmd('e <cword>')) + call assert_equal('e Vim!@#', expandcmd('e <cWORD>')) + enew! + edit Xfile.java + call assert_equal('e Xfile.py', expandcmd('e %:r.py')) + call assert_equal('make abc.java', expandcmd('make abc.%:e')) + call assert_equal('make Xabc.java', expandcmd('make %:s?file?abc?')) + edit a1a2a3.rb + call assert_equal('make b1b2b3.rb a1a2a3 Xfile.o', expandcmd('make %:gs?a?b? %< #<.o')) + + call assert_fails('call expandcmd("make <afile>")', 'E495:') + call assert_fails('call expandcmd("make <afile>")', 'E495:') + enew + call assert_fails('call expandcmd("make %")', 'E499:') + close + endfunc ]]) end) @@ -87,4 +121,9 @@ describe('expand file name', function() call('Test_expand_tilde_filename') expected_empty() end) + + it('works with expandcmd()', function() + call('Test_expandcmd') + expected_empty() + end) end) diff --git a/test/functional/legacy/memory_usage_spec.lua b/test/functional/legacy/memory_usage_spec.lua new file mode 100644 index 0000000000..251e6a5ea4 --- /dev/null +++ b/test/functional/legacy/memory_usage_spec.lua @@ -0,0 +1,169 @@ +local helpers = require('test.functional.helpers')(after_each) +local clear = helpers.clear +local eval = helpers.eval +local eq = helpers.eq +local feed_command = helpers.feed_command +local iswin = helpers.iswin +local retry = helpers.retry +local ok = helpers.ok +local source = helpers.source +local wait = helpers.wait +local uname = helpers.uname +local load_adjust = helpers.load_adjust + +local monitor_memory_usage = { + memory_usage = function(self) + local handle + if iswin() then + handle = io.popen('wmic process where processid=' ..self.pid..' get WorkingSetSize') + else + handle = io.popen('ps -o rss= -p '..self.pid) + end + return tonumber(handle:read('*a'):match('%d+')) + end, + op = function(self) + retry(nil, 10000, function() + local val = self.memory_usage(self) + if self.max < val then + self.max = val + end + table.insert(self.hist, val) + ok(#self.hist > 20) + local result = {} + for key,value in ipairs(self.hist) do + if value ~= self.hist[key + 1] then + table.insert(result, value) + end + end + table.remove(self.hist, 1) + self.last = self.hist[#self.hist] + eq(#result, 1) + end) + end, + dump = function(self) + return 'max: '..self.max ..', last: '..self.last + end, + monitor_memory_usage = function(self, pid) + local obj = { + pid = pid, + max = 0, + last = 0, + hist = {}, + } + setmetatable(obj, { __index = self }) + obj:op() + return obj + end +} +setmetatable(monitor_memory_usage, +{__call = function(self, pid) + return monitor_memory_usage.monitor_memory_usage(self, pid) +end}) + +describe('memory usage', function() + local function check_result(tbl, status, result) + if not status then + print('') + for key, val in pairs(tbl) do + print(key, val:dump()) + end + error(result) + end + end + + local function isasan() + local version = eval('execute("version")') + return version:match('-fsanitize=[a-z,]*address') + end + + before_each(clear) + + --[[ + Case: if a local variable captures a:000, funccall object will be free + just after it finishes. + ]]-- + it('function capture vargs', function() + if isasan() then + pending('ASAN build is difficult to estimate memory usage') + end + if iswin() and eval("executable('wmic')") == 0 then + pending('missing "wmic" command') + elseif eval("executable('ps')") == 0 then + pending('missing "ps" command') + end + + local pid = eval('getpid()') + local before = monitor_memory_usage(pid) + source([[ + func s:f(...) + let x = a:000 + endfunc + for _ in range(10000) + call s:f(0) + endfor + ]]) + wait() + local after = monitor_memory_usage(pid) + -- Estimate the limit of max usage as 2x initial usage. + -- The lower limit can fluctuate a bit, use 97%. + check_result({before=before, after=after}, + pcall(ok, before.last * 97 / 100 < after.max)) + check_result({before=before, after=after}, + pcall(ok, before.last * 2 > after.max)) + -- In this case, garbage collecting is not needed. + -- The value might fluctuate a bit, allow for 3% tolerance below and 5% above. + -- Based on various test runs. + local lower = after.last * 97 / 100 + local upper = after.last * 105 / 100 + check_result({before=before, after=after}, pcall(ok, lower < after.max)) + check_result({before=before, after=after}, pcall(ok, after.max < upper)) + end) + + --[[ + Case: if a local variable captures l: dict, funccall object will not be + free until garbage collector runs, but after that memory usage doesn't + increase so much even when rerun Xtest.vim since system memory caches. + ]]-- + it('function capture lvars', function() + if isasan() then + pending('ASAN build is difficult to estimate memory usage') + end + if iswin() and eval("executable('wmic')") == 0 then + pending('missing "wmic" command') + elseif eval("executable('ps')") == 0 then + pending('missing "ps" command') + end + + local pid = eval('getpid()') + local before = monitor_memory_usage(pid) + local fname = source([[ + if !exists('s:defined_func') + func s:f() + let x = l: + endfunc + endif + let s:defined_func = 1 + for _ in range(10000) + call s:f() + endfor + ]]) + wait() + local after = monitor_memory_usage(pid) + for _ = 1, 3 do + feed_command('so '..fname) + wait() + end + local last = monitor_memory_usage(pid) + -- The usage may be a bit less than the last value, use 80%. + -- Allow for 20% tolerance at the upper limit. That's very permissive, but + -- otherwise the test fails sometimes. On Sourcehut CI with FreeBSD we need to + -- be even more permissive. + local upper_multiplier = uname() == 'freebsd' and 15 or 12 + local lower = before.last * 8 / 10 + local upper = load_adjust((after.max + (after.last - before.last)) * upper_multiplier / 10) + check_result({before=before, after=after, last=last}, + pcall(ok, lower < last.last)) + check_result({before=before, after=after, last=last}, + pcall(ok, last.last < upper)) + end) +end) diff --git a/test/functional/legacy/prompt_buffer_spec.lua b/test/functional/legacy/prompt_buffer_spec.lua new file mode 100644 index 0000000000..513be807be --- /dev/null +++ b/test/functional/legacy/prompt_buffer_spec.lua @@ -0,0 +1,153 @@ +local helpers = require('test.functional.helpers')(after_each) +local Screen = require('test.functional.ui.screen') +local feed= helpers.feed +local source = helpers.source +local clear = helpers.clear +local feed_command = helpers.feed_command + +describe('prompt buffer', function() + local screen + + before_each(function() + clear() + screen = Screen.new(25, 10) + screen:attach() + source([[ + func TextEntered(text) + if a:text == "exit" + set nomodified + stopinsert + close + else + call append(line("$") - 1, 'Command: "' . a:text . '"') + set nomodfied + call timer_start(20, {id -> TimerFunc(a:text)}) + endif + endfunc + + func TimerFunc(text) + call append(line("$") - 1, 'Result: "' . a:text .'"') + endfunc + ]]) + feed_command("set noshowmode | set laststatus=0") + feed_command("call setline(1, 'other buffer')") + feed_command("new") + feed_command("set buftype=prompt") + feed_command("call prompt_setcallback(bufnr(''), function('TextEntered'))") + end) + + after_each(function() + screen:detach() + end) + + it('works', function() + screen:expect([[ + ^ | + ~ | + ~ | + ~ | + [Prompt] | + other buffer | + ~ | + ~ | + ~ | + | + ]]) + feed("i") + feed("hello\n") + screen:expect([[ + % hello | + Command: "hello" | + Result: "hello" | + % ^ | + [Prompt] [+] | + other buffer | + ~ | + ~ | + ~ | + | + ]]) + feed("exit\n") + screen:expect([[ + ^other buffer | + ~ | + ~ | + ~ | + ~ | + ~ | + ~ | + ~ | + ~ | + | + ]]) + end) + + it('editing', function() + screen:expect([[ + ^ | + ~ | + ~ | + ~ | + [Prompt] | + other buffer | + ~ | + ~ | + ~ | + | + ]]) + feed("i") + feed("hello<BS><BS>") + screen:expect([[ + % hel^ | + ~ | + ~ | + ~ | + [Prompt] [+] | + other buffer | + ~ | + ~ | + ~ | + | + ]]) + feed("<Left><Left><Left><BS>-") + screen:expect([[ + % -^hel | + ~ | + ~ | + ~ | + [Prompt] [+] | + other buffer | + ~ | + ~ | + ~ | + | + ]]) + feed("<End>x") + screen:expect([[ + % -helx^ | + ~ | + ~ | + ~ | + [Prompt] [+] | + other buffer | + ~ | + ~ | + ~ | + | + ]]) + feed("<C-U>exit\n") + screen:expect([[ + ^other buffer | + ~ | + ~ | + ~ | + ~ | + ~ | + ~ | + ~ | + ~ | + | + ]]) + end) + +end) diff --git a/test/functional/legacy/search_spec.lua b/test/functional/legacy/search_spec.lua index 3ed06a22e7..a207b176d3 100644 --- a/test/functional/legacy/search_spec.lua +++ b/test/functional/legacy/search_spec.lua @@ -17,7 +17,10 @@ describe('search cmdline', function() screen = Screen.new(20, 3) screen:attach() screen:set_default_attr_ids({ - inc = {reverse = true} + inc = {reverse = true}, + err = { foreground = Screen.colors.Grey100, background = Screen.colors.Red }, + more = { bold = true, foreground = Screen.colors.SeaGreen4 }, + tilde = { bold = true, foreground = Screen.colors.Blue1 }, }) end) @@ -404,15 +407,7 @@ describe('search cmdline', function() end) it('keeps the view after deleting a char from the search', function() - screen:detach() - screen = Screen.new(20, 6) - screen:attach() - screen:set_default_attr_ids({ - inc = {reverse = true} - }) - screen:set_default_attr_ignore({ - {bold=true, reverse=true}, {bold=true, foreground=Screen.colors.Blue1} - }) + screen:try_resize(20, 6) tenlines() feed('/foo') @@ -448,14 +443,7 @@ describe('search cmdline', function() end) it('restores original view after failed search', function() - screen:detach() - screen = Screen.new(40, 3) - screen:attach() - screen:set_default_attr_ids({ - inc = {reverse = true}, - err = { foreground = Screen.colors.Grey100, background = Screen.colors.Red }, - more = { bold = true, foreground = Screen.colors.SeaGreen4 }, - }) + screen:try_resize(40, 3) tenlines() feed('0') feed('/foo') @@ -484,15 +472,7 @@ describe('search cmdline', function() it("CTRL-G with 'incsearch' and ? goes in the right direction", function() -- oldtest: Test_search_cmdline4(). - screen:detach() - screen = Screen.new(40, 4) - screen:attach() - screen:set_default_attr_ids({ - inc = {reverse = true}, - err = { foreground = Screen.colors.Grey100, background = Screen.colors.Red }, - more = { bold = true, foreground = Screen.colors.SeaGreen4 }, - tilde = { bold = true, foreground = Screen.colors.Blue1 }, - }) + screen:try_resize(40, 4) command('enew!') funcs.setline(1, {' 1 the first', ' 2 the second', ' 3 the third'}) command('set laststatus=0 shortmess+=s') |