diff --git a/src/nvim/runtime.c b/src/nvim/runtime.c index 59f4f9957e..9cbf140f11 100644 --- a/src/nvim/runtime.c +++ b/src/nvim/runtime.c @@ -1993,14 +1993,19 @@ static char *do_source_buffer_init(source_cookie_T *sp, const exarg_T *eap, bool return NULL; } - if (ex_lua) { - // Use ":{range}lua buffer=" as the script name - snprintf(IObuff, IOSIZE, ":{range}lua buffer=%d", curbuf->b_fnum); + char *fname; + if (curbuf->b_ffname != NULL) { + fname = xstrdup(curbuf->b_ffname); } else { - // Use ":source buffer=" as the script name - snprintf(IObuff, IOSIZE, ":source buffer=%d", curbuf->b_fnum); + if (ex_lua) { + // Use ":{range}lua buffer=" as the script name + snprintf(IObuff, IOSIZE, ":{range}lua buffer=%d", curbuf->b_fnum); + } else { + // Use ":source buffer=" as the script name + snprintf(IObuff, IOSIZE, ":source buffer=%d", curbuf->b_fnum); + } + fname = xstrdup(IObuff); } - char *fname = xstrdup(IObuff); ga_init(&sp->buflines, sizeof(char *), 100); // Copy the lines from the buffer into a grow array diff --git a/test/functional/ex_cmds/source_spec.lua b/test/functional/ex_cmds/source_spec.lua index 4548e51624..f3e00dee0f 100644 --- a/test/functional/ex_cmds/source_spec.lua +++ b/test/functional/ex_cmds/source_spec.lua @@ -247,12 +247,15 @@ describe(':source', function() feed('dd') feed_command(':source') - + local filepath = fn.expand('%:p') + if filepath == '' then + filepath = ':source buffer=1' + end eq(12, eval('g:c')) eq(' \\ 1\n "\\ 2', exec_lua('return _G.a')) - eq(':source buffer=1', api.nvim_get_var('sfile_value')) - eq(':source buffer=1', api.nvim_get_var('stack_value')) - eq(':source buffer=1', api.nvim_get_var('script_value')) + eq(filepath, api.nvim_get_var('sfile_value')) + eq(filepath, api.nvim_get_var('stack_value')) + eq(filepath, api.nvim_get_var('script_value')) end) end diff --git a/test/functional/legacy/029_fuzzy_spec.lua b/test/functional/legacy/029_fuzzy_spec.lua new file mode 100644 index 0000000000..6ee2ff4dfa --- /dev/null +++ b/test/functional/legacy/029_fuzzy_spec.lua @@ -0,0 +1,22 @@ +-- Test for buffer name completion when 'wildoptions' contains "fuzzy" +-- (Confirm that Vim does not crash) +local n = require('test.functional.testnvim')() + +local clear = n.clear +local insert = n.insert +local expect = n.expect +local feed_command = n.feed_command +local command = n.command + +describe('set wildoptions=fuzzy', function() + before_each(clear) + + it('works', function() + insert([[I'm alive!]]) + command('set wildoptions=fuzzy') + command('new buf_a') + feed_command('b buf_a') + command('q!') + expect([[I'm alive!]]) + end) +end) diff --git a/test/functional/legacy/029_join_spec.lua b/test/functional/legacy/029_join_spec.lua deleted file mode 100644 index 8d4cc70d8f..0000000000 --- a/test/functional/legacy/029_join_spec.lua +++ /dev/null @@ -1,345 +0,0 @@ --- Test for joining lines with marks in them (and with 'joinspaces' set/reset) - -local n = require('test.functional.testnvim')() - -local feed = n.feed -local clear = n.clear -local insert = n.insert -local expect = n.expect -local feed_command = n.feed_command - -describe('joining lines', function() - before_each(clear) - - -- luacheck: ignore 613 (Trailing whitespaces in a string) - -- luacheck: ignore 611 (Line contains only whitespaces) - it("keeps marks with different 'joinspaces' settings", function() - insert([[ - firstline - asdfasdf. - asdf - asdfasdf. - asdf - asdfasdf. - asdf - asdfasdf. - asdf - asdfasdf. - asdf - asdfasdf. - asdf - asdfasdf. - asdf - asdfasdf - asdf - asdfasdf - asdf - asdfasdf - asdf - asdfasdf - asdf - asdfasdf - asdf - asdfasdf - asdf - asdfasdf - asdf - zx cvn. - as dfg? - hjkl iop! - ert - ]]) - - -- Switch off 'joinspaces', then join some lines in the buffer using "J". - -- Also set a few marks and record their movement when joining lines. - feed_command('set nojoinspaces') - feed_command('/firstline/') - feed('j"td/^$/') - feed('PJjJjJjJjJjJjJjJjJjJjJjJjJjJ') - feed('j05lmx2j06lmy2k4Jy3l$p`xyl$p`yy2l$p') - - -- Do the same with 'joinspaces' on. - feed_command('set joinspaces') - feed('j"tp') - feed('JjJjJjJjJjJjJjJjJjJjJjJjJjJ') - feed('j05lmx2j06lmy2k4Jy3l$p`xyl$p`yy2l$po') - - feed_command('1d') - - expect([[ - asdfasdf. asdf - asdfasdf. asdf - asdfasdf. asdf - asdfasdf. asdf - asdfasdf. asdf - asdfasdf. asdf - asdfasdf. asdf - asdfasdf asdf - asdfasdf asdf - asdfasdf asdf - asdfasdf asdf - asdfasdf asdf - asdfasdf asdf - asdfasdf asdf - zx cvn. as dfg? hjkl iop! ert ernop - - asdfasdf. asdf - asdfasdf. asdf - asdfasdf. asdf - asdfasdf. asdf - asdfasdf. asdf - asdfasdf. asdf - asdfasdf. asdf - asdfasdf asdf - asdfasdf asdf - asdfasdf asdf - asdfasdf asdf - asdfasdf asdf - asdfasdf asdf - asdfasdf asdf - zx cvn. as dfg? hjkl iop! ert enop - ]]) - end) - - it("removes comment leaders with 'joinspaces' off", function() - insert([[ - { - - /* - * Make sure the previous comment leader is not removed. - */ - - /* - * Make sure the previous comment leader is not removed. - */ - - // Should the next comment leader be left alone? - // Yes. - - // Should the next comment leader be left alone? - // Yes. - - /* Here the comment leader should be left intact. */ - // And so should this one. - - /* Here the comment leader should be left intact. */ - // And so should this one. - - if (condition) // Remove the next comment leader! - // OK, I will. - action(); - - if (condition) // Remove the next comment leader! - // OK, I will. - action(); - } - ]]) - - feed_command('/^{/+1') - feed_command('set comments=s1:/*,mb:*,ex:*/,://') - feed_command('set nojoinspaces') - feed_command('set backspace=eol,start') - - -- With 'joinspaces' switched off, join lines using both "J" and :join and - -- verify that comment leaders are stripped or kept as appropriate. - feed_command('.,+3join') - feed('j4J') - feed_command('.,+2join') - feed('j3J') - feed_command('.,+2join') - feed('j3J') - feed_command('.,+2join') - feed('jj3J') - - expect([[ - { - /* Make sure the previous comment leader is not removed. */ - /* Make sure the previous comment leader is not removed. */ - // Should the next comment leader be left alone? Yes. - // Should the next comment leader be left alone? Yes. - /* Here the comment leader should be left intact. */ // And so should this one. - /* Here the comment leader should be left intact. */ // And so should this one. - if (condition) // Remove the next comment leader! OK, I will. - action(); - if (condition) // Remove the next comment leader! OK, I will. - action(); - } - ]]) - end) - - -- This test case has nothing to do with joining lines. - it("Ctrl-u and 'backspace' compatibility", function() - -- Notice that the buffer text, which is intended to helpfully hint at - -- what's being done in the test, is off by one line. (For example, "this - -- should be deleted" should not be deleted, but the line below it should, - -- and is.) This is likely a mistake, but was kept here for consistency. - insert([[ - 1 this shouldn't be deleted - 2 this shouldn't be deleted - 3 this shouldn't be deleted - 4 this should be deleted - 5 this shouldn't be deleted - 6 this shouldn't be deleted - 7 this shouldn't be deleted - 8 this shouldn't be deleted (not touched yet) - ]]) - - -- As mentioned above, we mimic the wrong initial cursor position in the old - -- test by advancing one line further. - feed_command([[/^\d\+ this]], '+1') - - -- Test with the default 'backspace' setting. - feed('Avim1') - feed('Avim2u') - feed_command('set cpo-=<') - feed_command('inoremap ') - feed('Avim3') - feed_command('iunmap ') - feed('Avim4') - - -- Test with 'backspace' set to the compatible setting. - feed_command('set backspace=') - feed('A vim5A') - feed('A vim6Azweiu') - feed_command('inoremap ') - feed('A vim7') - - expect([[ - 1 this shouldn't be deleted - 2 this shouldn't be deleted - 3 this shouldn't be deleted - 4 this should be deleted3 - - 6 this shouldn't be deleted vim5 - 7 this shouldn't be deleted vim6 - 8 this shouldn't be deleted (not touched yet) vim7 - ]]) - end) - - it("removes comment leaders with 'joinspaces' on", function() - insert([[ - { - - /* - * Make sure the previous comment leader is not removed. - */ - - /* - * Make sure the previous comment leader is not removed. - */ - - /* List: - * - item1 - * foo bar baz - * foo bar baz - * - item2 - * foo bar baz - * foo bar baz - */ - - /* List: - * - item1 - * foo bar baz - * foo bar baz - * - item2 - * foo bar baz - * foo bar baz - */ - - // Should the next comment leader be left alone? - // Yes. - - // Should the next comment leader be left alone? - // Yes. - - /* Here the comment leader should be left intact. */ - // And so should this one. - - /* Here the comment leader should be left intact. */ - // And so should this one. - - if (condition) // Remove the next comment leader! - // OK, I will. - action(); - - if (condition) // Remove the next comment leader! - // OK, I will. - action(); - - int i = 7 /* foo *// 3 - // comment - ; - - int i = 7 /* foo *// 3 - // comment - ; - - ># Note that the last character of the ending comment leader (left angle - # bracket) is a comment leader itself. Make sure that this comment leader is - # not removed from the next line #< - < On this line a new comment is opened which spans 2 lines. This comment should - < retain its comment leader. - - ># Note that the last character of the ending comment leader (left angle - # bracket) is a comment leader itself. Make sure that this comment leader is - # not removed from the next line #< - < On this line a new comment is opened which spans 2 lines. This comment should - < retain its comment leader. - - } - ]]) - - feed_command('/^{/+1') - feed_command([[set comments=sO:*\ -,mO:*\ \ ,exO:*/]]) - feed_command('set comments+=s1:/*,mb:*,ex:*/,://') - feed_command('set comments+=s1:>#,mb:#,ex:#<,:<') - feed_command('set backspace=eol,start') - - -- With 'joinspaces' on (the default setting), again join lines and verify - -- that comment leaders are stripped or kept as appropriate. - feed_command('.,+3join') - feed('j4J') - feed_command('.,+8join') - feed('j9J') - feed_command('.,+2join') - feed('j3J') - feed_command('.,+2join') - feed('j3J') - feed_command('.,+2join') - feed('jj3J') - feed('j') - feed_command('.,+2join') - feed('jj3J') - feed('j') - feed_command('.,+5join') - feed('j6J') - feed( - 'oSome code!// Make sure backspacing does not remove this comment leader.0i' - ) - - expect([[ - { - /* Make sure the previous comment leader is not removed. */ - /* Make sure the previous comment leader is not removed. */ - /* List: item1 foo bar baz foo bar baz item2 foo bar baz foo bar baz */ - /* List: item1 foo bar baz foo bar baz item2 foo bar baz foo bar baz */ - // Should the next comment leader be left alone? Yes. - // Should the next comment leader be left alone? Yes. - /* Here the comment leader should be left intact. */ // And so should this one. - /* Here the comment leader should be left intact. */ // And so should this one. - if (condition) // Remove the next comment leader! OK, I will. - action(); - if (condition) // Remove the next comment leader! OK, I will. - action(); - int i = 7 /* foo *// 3 // comment - ; - int i = 7 /* foo *// 3 // comment - ; - ># Note that the last character of the ending comment leader (left angle bracket) is a comment leader itself. Make sure that this comment leader is not removed from the next line #< < On this line a new comment is opened which spans 2 lines. This comment should retain its comment leader. - ># Note that the last character of the ending comment leader (left angle bracket) is a comment leader itself. Make sure that this comment leader is not removed from the next line #< < On this line a new comment is opened which spans 2 lines. This comment should retain its comment leader. - - Some code!// Make sure backspacing does not remove this comment leader. - } - ]]) - end) -end) diff --git a/test/functional/legacy/join_spec.lua b/test/functional/legacy/join_spec.lua index 397a714b2f..018edae321 100644 --- a/test/functional/legacy/join_spec.lua +++ b/test/functional/legacy/join_spec.lua @@ -5,6 +5,10 @@ local n = require('test.functional.testnvim')() local clear, eq = n.clear, t.eq local eval, command = n.eval, n.command +local feed = n.feed +local insert = n.insert +local expect = n.expect +local feed_command = n.feed_command describe('joining lines', function() before_each(clear) @@ -19,4 +23,336 @@ describe('joining lines', function() command('normal 10J') eq('one two three four', eval('getline(1)')) end) + + -- luacheck: ignore 613 (Trailing whitespaces in a string) + -- luacheck: ignore 611 (Line contains only whitespaces) + it("keeps marks with different 'joinspaces' settings", function() + insert([[ + firstline + asdfasdf. + asdf + asdfasdf. + asdf + asdfasdf. + asdf + asdfasdf. + asdf + asdfasdf. + asdf + asdfasdf. + asdf + asdfasdf. + asdf + asdfasdf + asdf + asdfasdf + asdf + asdfasdf + asdf + asdfasdf + asdf + asdfasdf + asdf + asdfasdf + asdf + asdfasdf + asdf + zx cvn. + as dfg? + hjkl iop! + ert + ]]) + + -- Switch off 'joinspaces', then join some lines in the buffer using "J". + -- Also set a few marks and record their movement when joining lines. + feed_command('set nojoinspaces') + feed_command('/firstline/') + feed('j"td/^$/') + feed('PJjJjJjJjJjJjJjJjJjJjJjJjJjJ') + feed('j05lmx2j06lmy2k4Jy3l$p`xyl$p`yy2l$p') + + -- Do the same with 'joinspaces' on. + feed_command('set joinspaces') + feed('j"tp') + feed('JjJjJjJjJjJjJjJjJjJjJjJjJjJ') + feed('j05lmx2j06lmy2k4Jy3l$p`xyl$p`yy2l$po') + + feed_command('1d') + + expect([[ + asdfasdf. asdf + asdfasdf. asdf + asdfasdf. asdf + asdfasdf. asdf + asdfasdf. asdf + asdfasdf. asdf + asdfasdf. asdf + asdfasdf asdf + asdfasdf asdf + asdfasdf asdf + asdfasdf asdf + asdfasdf asdf + asdfasdf asdf + asdfasdf asdf + zx cvn. as dfg? hjkl iop! ert ernop + + asdfasdf. asdf + asdfasdf. asdf + asdfasdf. asdf + asdfasdf. asdf + asdfasdf. asdf + asdfasdf. asdf + asdfasdf. asdf + asdfasdf asdf + asdfasdf asdf + asdfasdf asdf + asdfasdf asdf + asdfasdf asdf + asdfasdf asdf + asdfasdf asdf + zx cvn. as dfg? hjkl iop! ert enop + ]]) + end) + + it("removes comment leaders with 'joinspaces' off", function() + insert([[ + { + + /* + * Make sure the previous comment leader is not removed. + */ + + /* + * Make sure the previous comment leader is not removed. + */ + + // Should the next comment leader be left alone? + // Yes. + + // Should the next comment leader be left alone? + // Yes. + + /* Here the comment leader should be left intact. */ + // And so should this one. + + /* Here the comment leader should be left intact. */ + // And so should this one. + + if (condition) // Remove the next comment leader! + // OK, I will. + action(); + + if (condition) // Remove the next comment leader! + // OK, I will. + action(); + } + ]]) + + feed_command('/^{/+1') + feed_command('set comments=s1:/*,mb:*,ex:*/,://') + feed_command('set nojoinspaces') + feed_command('set backspace=eol,start') + + -- With 'joinspaces' switched off, join lines using both "J" and :join and + -- verify that comment leaders are stripped or kept as appropriate. + feed_command('.,+3join') + feed('j4J') + feed_command('.,+2join') + feed('j3J') + feed_command('.,+2join') + feed('j3J') + feed_command('.,+2join') + feed('jj3J') + + expect([[ + { + /* Make sure the previous comment leader is not removed. */ + /* Make sure the previous comment leader is not removed. */ + // Should the next comment leader be left alone? Yes. + // Should the next comment leader be left alone? Yes. + /* Here the comment leader should be left intact. */ // And so should this one. + /* Here the comment leader should be left intact. */ // And so should this one. + if (condition) // Remove the next comment leader! OK, I will. + action(); + if (condition) // Remove the next comment leader! OK, I will. + action(); + } + ]]) + end) + + -- This test case has nothing to do with joining lines. + it("Ctrl-u and 'backspace' compatibility", function() + -- Notice that the buffer text, which is intended to helpfully hint at + -- what's being done in the test, is off by one line. (For example, "this + -- should be deleted" should not be deleted, but the line below it should, + -- and is.) This is likely a mistake, but was kept here for consistency. + insert([[ + 1 this shouldn't be deleted + 2 this shouldn't be deleted + 3 this shouldn't be deleted + 4 this should be deleted + 5 this shouldn't be deleted + 6 this shouldn't be deleted + 7 this shouldn't be deleted + 8 this shouldn't be deleted (not touched yet) + ]]) + + -- As mentioned above, we mimic the wrong initial cursor position in the old + -- test by advancing one line further. + feed_command([[/^\d\+ this]], '+1') + + -- Test with the default 'backspace' setting. + feed('Avim1') + feed('Avim2u') + feed_command('set cpo-=<') + feed_command('inoremap ') + feed('Avim3') + feed_command('iunmap ') + feed('Avim4') + + -- Test with 'backspace' set to the compatible setting. + feed_command('set backspace=') + feed('A vim5A') + feed('A vim6Azweiu') + feed_command('inoremap ') + feed('A vim7') + + expect([[ + 1 this shouldn't be deleted + 2 this shouldn't be deleted + 3 this shouldn't be deleted + 4 this should be deleted3 + + 6 this shouldn't be deleted vim5 + 7 this shouldn't be deleted vim6 + 8 this shouldn't be deleted (not touched yet) vim7 + ]]) + end) + + it("removes comment leaders with 'joinspaces' on", function() + insert([[ + { + + /* + * Make sure the previous comment leader is not removed. + */ + + /* + * Make sure the previous comment leader is not removed. + */ + + /* List: + * - item1 + * foo bar baz + * foo bar baz + * - item2 + * foo bar baz + * foo bar baz + */ + + /* List: + * - item1 + * foo bar baz + * foo bar baz + * - item2 + * foo bar baz + * foo bar baz + */ + + // Should the next comment leader be left alone? + // Yes. + + // Should the next comment leader be left alone? + // Yes. + + /* Here the comment leader should be left intact. */ + // And so should this one. + + /* Here the comment leader should be left intact. */ + // And so should this one. + + if (condition) // Remove the next comment leader! + // OK, I will. + action(); + + if (condition) // Remove the next comment leader! + // OK, I will. + action(); + + int i = 7 /* foo *// 3 + // comment + ; + + int i = 7 /* foo *// 3 + // comment + ; + + ># Note that the last character of the ending comment leader (left angle + # bracket) is a comment leader itself. Make sure that this comment leader is + # not removed from the next line #< + < On this line a new comment is opened which spans 2 lines. This comment should + < retain its comment leader. + + ># Note that the last character of the ending comment leader (left angle + # bracket) is a comment leader itself. Make sure that this comment leader is + # not removed from the next line #< + < On this line a new comment is opened which spans 2 lines. This comment should + < retain its comment leader. + + } + ]]) + + feed_command('/^{/+1') + feed_command([[set comments=sO:*\ -,mO:*\ \ ,exO:*/]]) + feed_command('set comments+=s1:/*,mb:*,ex:*/,://') + feed_command('set comments+=s1:>#,mb:#,ex:#<,:<') + feed_command('set backspace=eol,start') + + -- With 'joinspaces' on (the default setting), again join lines and verify + -- that comment leaders are stripped or kept as appropriate. + feed_command('.,+3join') + feed('j4J') + feed_command('.,+8join') + feed('j9J') + feed_command('.,+2join') + feed('j3J') + feed_command('.,+2join') + feed('j3J') + feed_command('.,+2join') + feed('jj3J') + feed('j') + feed_command('.,+2join') + feed('jj3J') + feed('j') + feed_command('.,+5join') + feed('j6J') + feed( + 'oSome code!// Make sure backspacing does not remove this comment leader.0i' + ) + + expect([[ + { + /* Make sure the previous comment leader is not removed. */ + /* Make sure the previous comment leader is not removed. */ + /* List: item1 foo bar baz foo bar baz item2 foo bar baz foo bar baz */ + /* List: item1 foo bar baz foo bar baz item2 foo bar baz foo bar baz */ + // Should the next comment leader be left alone? Yes. + // Should the next comment leader be left alone? Yes. + /* Here the comment leader should be left intact. */ // And so should this one. + /* Here the comment leader should be left intact. */ // And so should this one. + if (condition) // Remove the next comment leader! OK, I will. + action(); + if (condition) // Remove the next comment leader! OK, I will. + action(); + int i = 7 /* foo *// 3 // comment + ; + int i = 7 /* foo *// 3 // comment + ; + ># Note that the last character of the ending comment leader (left angle bracket) is a comment leader itself. Make sure that this comment leader is not removed from the next line #< < On this line a new comment is opened which spans 2 lines. This comment should retain its comment leader. + ># Note that the last character of the ending comment leader (left angle bracket) is a comment leader itself. Make sure that this comment leader is not removed from the next line #< < On this line a new comment is opened which spans 2 lines. This comment should retain its comment leader. + + Some code!// Make sure backspacing does not remove this comment leader. + } + ]]) + end) end) diff --git a/test/old/testdir/test_regexp_utf8.vim b/test/old/testdir/test_regexp_utf8.vim index 17ce2d2627..5cd9c6e967 100644 --- a/test/old/testdir/test_regexp_utf8.vim +++ b/test/old/testdir/test_regexp_utf8.vim @@ -562,12 +562,8 @@ func Test_match_invalid_byte() endfunc func Test_match_illegal_byte() - let lines =<< trim END - silent! buffer ÿ\c - next ÿ - 0scriptnames - source - END + " Text has illegal bytes which need to be set explicitly + let lines = ["norm :set no\x01\", "silent n\xff", "silent norm :b\xff\"] call writefile(lines, 'Xregexp') call system(GetVimCommand() .. ' -X -Z -e -s -S Xregexp -c qa!')