test: feed_command is deprecated #33674

This commit is contained in:
Justin M. Keyes
2025-04-27 09:46:53 -07:00
committed by GitHub
parent e991133058
commit ef16a02a76
3 changed files with 57 additions and 60 deletions

View File

@@ -1,7 +1,7 @@
local t = require('test.testutil') local t = require('test.testutil')
local n = require('test.functional.testnvim')() local n = require('test.functional.testnvim')()
local clear, feed_command, feed = n.clear, n.feed_command, n.feed local clear, feed = n.clear, n.feed
local eq, neq, eval = t.eq, t.neq, n.eval local eq, neq, eval = t.eq, t.neq, n.eval
describe('&encoding', function() describe('&encoding', function()
@@ -13,10 +13,7 @@ describe('&encoding', function()
end) end)
it('cannot be changed after setup', function() it('cannot be changed after setup', function()
feed_command('set encoding=latin1') t.matches('E519%:', t.pcall_err(n.command, 'set encoding=latin1'))
-- error message expected
feed('<cr>')
neq(nil, string.find(eval('v:errmsg'), '^E519:'))
eq('utf-8', eval('&encoding')) eq('utf-8', eval('&encoding'))
-- check nvim is still in utf-8 mode -- check nvim is still in utf-8 mode
eq(3, eval('strwidth("Bär")')) eq(3, eval('strwidth("Bär")'))
@@ -32,7 +29,7 @@ describe('&encoding', function()
end) end)
it('can be set to utf-8 without error', function() it('can be set to utf-8 without error', function()
feed_command('set encoding=utf-8') n.command('set encoding=utf-8')
eq('', eval('v:errmsg')) eq('', eval('v:errmsg'))
clear('--cmd', 'set enc=utf-8') clear('--cmd', 'set enc=utf-8')

View File

@@ -1,7 +1,7 @@
local t = require('test.testutil') local t = require('test.testutil')
local n = require('test.functional.testnvim')() local n = require('test.functional.testnvim')()
local clear, feed_command, feed, ok, eval = n.clear, n.feed_command, n.feed, t.ok, n.eval local clear, ok, eval = n.clear, t.ok, n.eval
describe(':grep', function() describe(':grep', function()
before_each(clear) before_each(clear)
@@ -12,11 +12,11 @@ describe(':grep', function()
return return
end end
feed_command([[set grepprg=grep\ -r]]) n.command([[set grepprg=grep\ -r]])
-- Change to test directory so that the test does not run too long. -- Change to test directory so that the test does not run too long.
feed_command('cd test') n.command('cd test')
feed_command('grep a **/*') n.feed(':grep a **/*<cr>')
feed('<cr>') -- Press ENTER n.feed('<cr>') -- Press ENTER
ok(eval('len(getqflist())') > 9000) -- IT'S OVER 9000!!1 ok(eval('len(getqflist())') > 9000) -- IT'S OVER 9000!!1
end) end)
end) end)

View File

@@ -5,7 +5,7 @@ local n = require('test.functional.testnvim')()
local Screen = require('test.functional.ui.screen') local Screen = require('test.functional.ui.screen')
local clear, feed, insert = n.clear, n.feed, n.insert local clear, feed, insert = n.clear, n.feed, n.insert
local feed_command, expect, eq, eval, source = n.feed_command, n.expect, t.eq, n.eval, n.source local expect, eq, eval, source = n.expect, t.eq, n.eval, n.source
local command = n.command local command = n.command
local api = n.api local api = n.api
@@ -144,7 +144,7 @@ describe('clipboard', function()
it('`:redir @+>` with invalid g:clipboard shows exactly one error #7184', function() it('`:redir @+>` with invalid g:clipboard shows exactly one error #7184', function()
command("let g:clipboard = 'bogus'") command("let g:clipboard = 'bogus'")
feed_command('redir @+> | :silent echo system("cat CONTRIBUTING.md") | redir END') command('redir @+> | :silent echo system("cat CONTRIBUTING.md") | redir END')
screen:expect([[ screen:expect([[
^ | ^ |
{1:~ }|*2 {1:~ }|*2
@@ -154,7 +154,7 @@ describe('clipboard', function()
it('`:redir @+>|bogus_cmd|redir END` + invalid g:clipboard must not recurse #7184', function() it('`:redir @+>|bogus_cmd|redir END` + invalid g:clipboard must not recurse #7184', function()
command("let g:clipboard = 'bogus'") command("let g:clipboard = 'bogus'")
feed_command('redir @+> | bogus_cmd | redir END') feed(':redir @+> | bogus_cmd | redir END<cr>')
screen:expect { screen:expect {
grid = [[ grid = [[
{3: }| {3: }|
@@ -172,7 +172,7 @@ describe('clipboard', function()
command("let g:clipboard = 'bogus'") command("let g:clipboard = 'bogus'")
-- Explicit clipboard attempt, should show a hint message. -- Explicit clipboard attempt, should show a hint message.
feed_command('let @+="foo"') feed(':let @+="foo"<cr>')
screen:expect([[ screen:expect([[
^ | ^ |
{1:~ }|*2 {1:~ }|*2
@@ -296,12 +296,12 @@ describe('clipboard (with fake clipboard.vim)', function()
before_each(function() before_each(function()
reset() reset()
feed_command('call getreg("*")') -- force load of provider command('call getreg("*")') -- force load of provider
end) end)
it('`:redir @+>` invokes clipboard once-per-message', function() it('`:redir @+>` invokes clipboard once-per-message', function()
eq(0, eval('g:clip_called_set')) eq(0, eval('g:clip_called_set'))
feed_command('redir @+> | :silent echo system("cat CONTRIBUTING.md") | redir END') command('redir @+> | :silent echo system("cat CONTRIBUTING.md") | redir END')
-- Assuming CONTRIBUTING.md has >100 lines. -- Assuming CONTRIBUTING.md has >100 lines.
assert(eval('g:clip_called_set') > 100) assert(eval('g:clip_called_set') > 100)
end) end)
@@ -311,13 +311,13 @@ describe('clipboard (with fake clipboard.vim)', function()
-- NOT propagate to the clipboard. This is consistent with Vim. -- NOT propagate to the clipboard. This is consistent with Vim.
command('set clipboard=unnamedplus') command('set clipboard=unnamedplus')
eq(0, eval('g:clip_called_set')) eq(0, eval('g:clip_called_set'))
feed_command('redir @"> | :silent echo system("cat CONTRIBUTING.md") | redir END') command('redir @"> | :silent echo system("cat CONTRIBUTING.md") | redir END')
eq(0, eval('g:clip_called_set')) eq(0, eval('g:clip_called_set'))
end) end)
it('`:redir @+>|bogus_cmd|redir END` must not recurse #7184', function() it('`:redir @+>|bogus_cmd|redir END` must not recurse #7184', function()
local screen = Screen.new(72, 4) local screen = Screen.new(72, 4)
feed_command('redir @+> | bogus_cmd | redir END') feed(':redir @+> | bogus_cmd | redir END<cr>')
screen:expect([[ screen:expect([[
^ | ^ |
{1:~ }|*2 {1:~ }|*2
@@ -367,8 +367,8 @@ describe('clipboard (with fake clipboard.vim)', function()
end) end)
it('autodetects regtype', function() it('autodetects regtype', function()
feed_command("let g:test_clip['*'] = ['linewise stuff','']") command("let g:test_clip['*'] = ['linewise stuff','']")
feed_command("let g:test_clip['+'] = ['charwise','stuff']") command("let g:test_clip['+'] = ['charwise','stuff']")
eq('V', eval("getregtype('*')")) eq('V', eval("getregtype('*')"))
eq('v', eval("getregtype('+')")) eq('v', eval("getregtype('+')"))
insert('just some text') insert('just some text')
@@ -383,7 +383,7 @@ describe('clipboard (with fake clipboard.vim)', function()
insert([[ insert([[
much much
text]]) text]])
feed_command("let g:test_clip['*'] = [['very','block'],'b']") command("let g:test_clip['*'] = [['very','block'],'b']")
feed('gg"*P') feed('gg"*P')
expect([[ expect([[
very much very much
@@ -397,15 +397,15 @@ describe('clipboard (with fake clipboard.vim)', function()
end) end)
it('supports setreg()', function() it('supports setreg()', function()
feed_command('call setreg("*", "setted\\ntext", "c")') command('call setreg("*", "setted\\ntext", "c")')
feed_command('call setreg("+", "explicitly\\nlines", "l")') command('call setreg("+", "explicitly\\nlines", "l")')
feed('"+P"*p') feed('"+P"*p')
expect([[ expect([[
esetted esetted
textxplicitly textxplicitly
lines lines
]]) ]])
feed_command('call setreg("+", "blocky\\nindeed", "b")') command('call setreg("+", "blocky\\nindeed", "b")')
feed('"+p') feed('"+p')
expect([[ expect([[
esblockyetted esblockyetted
@@ -415,13 +415,13 @@ describe('clipboard (with fake clipboard.vim)', function()
end) end)
it('supports :let @+ (issue #1427)', function() it('supports :let @+ (issue #1427)', function()
feed_command("let @+ = 'some'") command("let @+ = 'some'")
feed_command("let @* = ' other stuff'") command("let @* = ' other stuff'")
eq({ { 'some' }, 'v' }, eval("g:test_clip['+']")) eq({ { 'some' }, 'v' }, eval("g:test_clip['+']"))
eq({ { ' other stuff' }, 'v' }, eval("g:test_clip['*']")) eq({ { ' other stuff' }, 'v' }, eval("g:test_clip['*']"))
feed('"+p"*p') feed('"+p"*p')
expect('some other stuff') expect('some other stuff')
feed_command("let @+ .= ' more'") command("let @+ .= ' more'")
feed('dd"+p') feed('dd"+p')
expect('some more') expect('some more')
end) end)
@@ -429,7 +429,7 @@ describe('clipboard (with fake clipboard.vim)', function()
it('pastes unnamed register if the provider fails', function() it('pastes unnamed register if the provider fails', function()
insert('the text') insert('the text')
feed('yy') feed('yy')
feed_command('let g:cliperror = 1') command('let g:cliperror = 1')
feed('"*p') feed('"*p')
expect([[ expect([[
the text the text
@@ -440,7 +440,7 @@ describe('clipboard (with fake clipboard.vim)', function()
-- the basic behavior of unnamed register should be the same -- the basic behavior of unnamed register should be the same
-- even when handled by clipboard provider -- even when handled by clipboard provider
before_each(function() before_each(function()
feed_command('set clipboard=unnamed') feed(':set clipboard=unnamed<cr>')
end) end)
it('works', function() it('works', function()
@@ -448,7 +448,7 @@ describe('clipboard (with fake clipboard.vim)', function()
end) end)
it('works with pure text clipboard', function() it('works with pure text clipboard', function()
feed_command('let g:cliplossy = 1') command('let g:cliplossy = 1')
-- expect failure for block mode -- expect failure for block mode
basic_register_test(true) basic_register_test(true)
end) end)
@@ -463,7 +463,7 @@ describe('clipboard (with fake clipboard.vim)', function()
-- "+ shouldn't have changed -- "+ shouldn't have changed
eq({ '' }, eval("g:test_clip['+']")) eq({ '' }, eval("g:test_clip['+']"))
feed_command("let g:test_clip['*'] = ['linewise stuff','']") command("let g:test_clip['*'] = ['linewise stuff','']")
feed('p') feed('p')
expect([[ expect([[
words words
@@ -473,7 +473,7 @@ describe('clipboard (with fake clipboard.vim)', function()
it('does not clobber "0 when pasting', function() it('does not clobber "0 when pasting', function()
insert('a line') insert('a line')
feed('yy') feed('yy')
feed_command("let g:test_clip['*'] = ['b line','']") command("let g:test_clip['*'] = ['b line','']")
feed('"0pp"0p') feed('"0pp"0p')
expect([[ expect([[
a line a line
@@ -484,20 +484,20 @@ describe('clipboard (with fake clipboard.vim)', function()
it('supports v:register and getreg() without parameters', function() it('supports v:register and getreg() without parameters', function()
eq('*', eval('v:register')) eq('*', eval('v:register'))
feed_command("let g:test_clip['*'] = [['some block',''], 'b']") command("let g:test_clip['*'] = [['some block',''], 'b']")
eq('some block', eval('getreg()')) eq('some block', eval('getreg()'))
eq('\02210', eval('getregtype()')) eq('\02210', eval('getregtype()'))
end) end)
it('yanks visual selection when pasting', function() it('yanks visual selection when pasting', function()
insert('indeed visual') insert('indeed visual')
feed_command("let g:test_clip['*'] = [['clipboard'], 'c']") command("let g:test_clip['*'] = [['clipboard'], 'c']")
feed('viwp') feed('viwp')
eq({ { 'visual' }, 'v' }, eval("g:test_clip['*']")) eq({ { 'visual' }, 'v' }, eval("g:test_clip['*']"))
expect('indeed clipboard') expect('indeed clipboard')
-- explicit "* should do the same -- explicit "* should do the same
feed_command("let g:test_clip['*'] = [['star'], 'c']") command("let g:test_clip['*'] = [['star'], 'c']")
feed('viw"*p') feed('viw"*p')
eq({ { 'clipboard' }, 'v' }, eval("g:test_clip['*']")) eq({ { 'clipboard' }, 'v' }, eval("g:test_clip['*']"))
expect('indeed star') expect('indeed star')
@@ -506,7 +506,7 @@ describe('clipboard (with fake clipboard.vim)', function()
it('unnamed operations work even if the provider fails', function() it('unnamed operations work even if the provider fails', function()
insert('the text') insert('the text')
feed('yy') feed('yy')
feed_command('let g:cliperror = 1') command('let g:cliperror = 1')
feed('p') feed('p')
expect([[ expect([[
the text the text
@@ -520,11 +520,11 @@ describe('clipboard (with fake clipboard.vim)', function()
match match
text text
]]) ]])
feed_command('g/match/d') command('g/match/d')
eq('match\n', eval('getreg("*")')) eq('match\n', eval('getreg("*")'))
feed('u') feed('u')
eval('setreg("*", "---")') eval('setreg("*", "---")')
feed_command('g/test/') command('g/test/')
feed('<esc>') feed('<esc>')
eq('---', eval('getreg("*")')) eq('---', eval('getreg("*")'))
end) end)
@@ -554,7 +554,7 @@ describe('clipboard (with fake clipboard.vim)', function()
describe('clipboard=unnamedplus', function() describe('clipboard=unnamedplus', function()
before_each(function() before_each(function()
feed_command('set clipboard=unnamedplus') feed(':set clipboard=unnamedplus<cr>')
end) end)
it('links the "+ and unnamed registers', function() it('links the "+ and unnamed registers', function()
@@ -567,13 +567,13 @@ describe('clipboard (with fake clipboard.vim)', function()
-- "* shouldn't have changed -- "* shouldn't have changed
eq({ '' }, eval("g:test_clip['*']")) eq({ '' }, eval("g:test_clip['*']"))
feed_command("let g:test_clip['+'] = ['three']") command("let g:test_clip['+'] = ['three']")
feed('p') feed('p')
expect('twothree') expect('twothree')
end) end)
it('and unnamed, yanks to both', function() it('and unnamed, yanks to both', function()
feed_command('set clipboard=unnamedplus,unnamed') command('set clipboard=unnamedplus,unnamed')
insert([[ insert([[
really unnamed really unnamed
text]]) text]])
@@ -587,8 +587,8 @@ describe('clipboard (with fake clipboard.vim)', function()
-- unnamedplus takes precedence when pasting -- unnamedplus takes precedence when pasting
eq('+', eval('v:register')) eq('+', eval('v:register'))
feed_command("let g:test_clip['+'] = ['the plus','']") command("let g:test_clip['+'] = ['the plus','']")
feed_command("let g:test_clip['*'] = ['the star','']") command("let g:test_clip['*'] = ['the star','']")
feed('p') feed('p')
expect([[ expect([[
text text
@@ -604,11 +604,11 @@ describe('clipboard (with fake clipboard.vim)', function()
match match
text text
]]) ]])
feed_command('g/match/d') command('g/match/d')
eq('match\n', eval('getreg("+")')) eq('match\n', eval('getreg("+")'))
feed('u') feed('u')
eval('setreg("+", "---")') eval('setreg("+", "---")')
feed_command('g/test/') command('g/test/')
feed('<esc>') feed('<esc>')
eq('---', eval('getreg("+")')) eq('---', eval('getreg("+")'))
end) end)
@@ -623,13 +623,13 @@ describe('clipboard (with fake clipboard.vim)', function()
it('supports :put', function() it('supports :put', function()
insert('a line') insert('a line')
feed_command("let g:test_clip['*'] = ['some text']") command("let g:test_clip['*'] = ['some text']")
feed_command("let g:test_clip['+'] = ['more', 'text', '']") command("let g:test_clip['+'] = ['more', 'text', '']")
feed_command(':put *') command(':put *')
expect([[ expect([[
a line a line
some text]]) some text]])
feed_command(':put +') command(':put +')
expect([[ expect([[
a line a line
some text some text
@@ -639,9 +639,9 @@ describe('clipboard (with fake clipboard.vim)', function()
it('supports "+ and "* in registers', function() it('supports "+ and "* in registers', function()
local screen = Screen.new(60, 10) local screen = Screen.new(60, 10)
feed_command("let g:test_clip['*'] = ['some', 'star data','']") feed(":let g:test_clip['*'] = ['some', 'star data','']<cr>")
feed_command("let g:test_clip['+'] = ['such', 'plus', 'stuff']") feed(":let g:test_clip['+'] = ['such', 'plus', 'stuff']<cr>")
feed_command('registers') feed(':registers<cr>')
screen:expect( screen:expect(
[[ [[
| |
@@ -669,17 +669,17 @@ describe('clipboard (with fake clipboard.vim)', function()
insert('s/s/t/') insert('s/s/t/')
feed('gg"*y$:<c-r>*<cr>') feed('gg"*y$:<c-r>*<cr>')
expect('t/s/t/') expect('t/s/t/')
feed_command("let g:test_clip['*'] = ['s/s/u']") command("let g:test_clip['*'] = ['s/s/u']")
feed(':<c-r>*<cr>') feed(':<c-r>*<cr>')
expect('t/u/t/') expect('t/u/t/')
end) end)
it('supports :redir @*>', function() it('supports :redir @*>', function()
feed_command("let g:test_clip['*'] = ['stuff']") command("let g:test_clip['*'] = ['stuff']")
feed_command('redir @*>') command('redir @*>')
-- it is made empty -- it is made empty
eq({ { '' }, 'v' }, eval("g:test_clip['*']")) eq({ { '' }, 'v' }, eval("g:test_clip['*']"))
feed_command('let g:test = doesnotexist') feed(':let g:test = doesnotexist<cr>')
feed('<cr>') feed('<cr>')
eq( eq(
{ { { {
@@ -689,7 +689,7 @@ describe('clipboard (with fake clipboard.vim)', function()
}, 'v' }, }, 'v' },
eval("g:test_clip['*']") eval("g:test_clip['*']")
) )
feed_command(':echo "Howdy!"') feed(':echo "Howdy!"<cr>')
eq({ eq({
{ {
'', '',
@@ -703,7 +703,7 @@ describe('clipboard (with fake clipboard.vim)', function()
end) end)
it('handles middleclick correctly', function() it('handles middleclick correctly', function()
feed_command('set mouse=a') command('set mouse=a')
local screen = Screen.new(30, 5) local screen = Screen.new(30, 5)
insert([[ insert([[
@@ -724,7 +724,7 @@ describe('clipboard (with fake clipboard.vim)', function()
the a target]]) the a target]])
-- on error, fall back to unnamed register -- on error, fall back to unnamed register
feed_command('let g:cliperror = 1') command('let g:cliperror = 1')
feed('<MiddleMouse><6,1>') feed('<MiddleMouse><6,1>')
expect([[ expect([[
the source the source