aboutsummaryrefslogtreecommitdiff
path: root/test/functional/clipboard/clipboard_provider_spec.lua
diff options
context:
space:
mode:
authorZyX <kp-pav@yandex.ru>2017-12-03 16:49:30 +0300
committerZyX <kp-pav@yandex.ru>2017-12-03 16:49:30 +0300
commitc49e22d3964d6c7ae1c24e8ad01b5fec4ca40b57 (patch)
treeb7e59c416d1435725c65f8952b6e55c70544d97e /test/functional/clipboard/clipboard_provider_spec.lua
parent62108c3b0be46936c83f6d4c98b44ceb5e6f77fd (diff)
parent27a577586eace687c47e7398845178208cae524a (diff)
downloadrneovim-c49e22d3964d6c7ae1c24e8ad01b5fec4ca40b57.tar.gz
rneovim-c49e22d3964d6c7ae1c24e8ad01b5fec4ca40b57.tar.bz2
rneovim-c49e22d3964d6c7ae1c24e8ad01b5fec4ca40b57.zip
Merge branch 'master' into s-dash-stdin
Diffstat (limited to 'test/functional/clipboard/clipboard_provider_spec.lua')
-rw-r--r--test/functional/clipboard/clipboard_provider_spec.lua199
1 files changed, 148 insertions, 51 deletions
diff --git a/test/functional/clipboard/clipboard_provider_spec.lua b/test/functional/clipboard/clipboard_provider_spec.lua
index d969d4a487..a3ea3b568f 100644
--- a/test/functional/clipboard/clipboard_provider_spec.lua
+++ b/test/functional/clipboard/clipboard_provider_spec.lua
@@ -3,7 +3,9 @@
local helpers = require('test.functional.helpers')(after_each)
local Screen = require('test.functional.ui.screen')
local clear, feed, insert = helpers.clear, helpers.feed, helpers.insert
-local execute, expect, eq, eval = helpers.execute, helpers.expect, helpers.eq, helpers.eval
+local feed_command, expect, eq, eval = helpers.feed_command, helpers.expect, helpers.eq, helpers.eval
+local command = helpers.command
+local meths = helpers.meths
local function basic_register_test(noblock)
insert("some words")
@@ -80,25 +82,112 @@ local function basic_register_test(noblock)
expect("two and three and one")
end
-describe('the unnamed register', function()
+describe('clipboard', function()
before_each(clear)
- it('works without provider', function()
+
+ it('unnamed register works without provider', function()
eq('"', eval('v:register'))
basic_register_test()
end)
+
+ it('`:redir @+>` with invalid g:clipboard shows exactly one error #7184',
+ function()
+ local screen = Screen.new(72, 4)
+ screen:attach()
+ command("let g:clipboard = 'bogus'")
+ feed_command('redir @+> | :silent echo system("cat CONTRIBUTING.md") | redir END')
+ screen:expect([[
+ ^ |
+ ~ |
+ ~ |
+ clipboard: No provider. Try ":checkhealth" or ":h clipboard". |
+ ]], nil, {{bold = true, foreground = Screen.colors.Blue}})
+ end)
+
+ it('`:redir @+>|bogus_cmd|redir END` + invalid g:clipboard must not recurse #7184',
+ function()
+ local screen = Screen.new(72, 4)
+ screen:attach()
+ command("let g:clipboard = 'bogus'")
+ feed_command('redir @+> | bogus_cmd | redir END')
+ screen:expect([[
+ ~ |
+ clipboard: No provider. Try ":checkhealth" or ":h clipboard". |
+ E492: Not an editor command: bogus_cmd | redir END |
+ Press ENTER or type command to continue^ |
+ ]], nil, {{bold = true, foreground = Screen.colors.Blue}})
+ end)
+
+ it('invalid g:clipboard shows hint if :redir is not active', function()
+ command("let g:clipboard = 'bogus'")
+ eq('', eval('provider#clipboard#Executable()'))
+ eq('clipboard: invalid g:clipboard', eval('provider#clipboard#Error()'))
+
+ local screen = Screen.new(72, 4)
+ screen:attach()
+ command("let g:clipboard = 'bogus'")
+ -- Explicit clipboard attempt, should show a hint message.
+ feed_command('let @+="foo"')
+ screen:expect([[
+ ^ |
+ ~ |
+ ~ |
+ clipboard: No provider. Try ":checkhealth" or ":h clipboard". |
+ ]], nil, {{bold = true, foreground = Screen.colors.Blue}})
+ end)
+
+ it('valid g:clipboard', function()
+ -- provider#clipboard#Executable() only checks the structure.
+ meths.set_var('clipboard', {
+ ['name'] = 'clippy!',
+ ['copy'] = { ['+'] = 'any command', ['*'] = 'some other' },
+ ['paste'] = { ['+'] = 'any command', ['*'] = 'some other' },
+ })
+ eq('clippy!', eval('provider#clipboard#Executable()'))
+ eq('', eval('provider#clipboard#Error()'))
+ end)
end)
-describe('clipboard usage', function()
+describe('clipboard', function()
local function reset(...)
clear('--cmd', 'let &rtp = "test/functional/fixtures,".&rtp', ...)
end
before_each(function()
reset()
- execute('call getreg("*")') -- force load of provider
+ feed_command('call getreg("*")') -- force load of provider
+ end)
+
+ it('`:redir @+>` invokes clipboard once-per-message', function()
+ eq(0, eval("g:clip_called_set"))
+ feed_command('redir @+> | :silent echo system("cat CONTRIBUTING.md") | redir END')
+ -- Assuming CONTRIBUTING.md has >100 lines.
+ assert(eval("g:clip_called_set") > 100)
+ end)
+
+ it('`:redir @">` does NOT invoke clipboard', function()
+ -- :redir to a non-clipboard register, with `:set clipboard=unnamed` does
+ -- NOT propagate to the clipboard. This is consistent with Vim.
+ command("set clipboard=unnamedplus")
+ eq(0, eval("g:clip_called_set"))
+ feed_command('redir @"> | :silent echo system("cat CONTRIBUTING.md") | redir END')
+ eq(0, eval("g:clip_called_set"))
end)
- it('has independent "* and unnamed registers per default', function()
+ it('`:redir @+>|bogus_cmd|redir END` must not recurse #7184',
+ function()
+ local screen = Screen.new(72, 4)
+ screen:attach()
+ feed_command('redir @+> | bogus_cmd | redir END')
+ screen:expect([[
+ ^ |
+ ~ |
+ ~ |
+ E492: Not an editor command: bogus_cmd | redir END |
+ ]], nil, {{bold = true, foreground = Screen.colors.Blue}})
+ end)
+
+ it('has independent "* and unnamed registers by default', function()
insert("some words")
feed('^"*dwdw"*P')
expect('some ')
@@ -139,9 +228,9 @@ describe('clipboard usage', function()
eq({'some\ntext', '\nvery binary\n'}, eval("getreg('*', 1, 1)"))
end)
- it('support autodectection of regtype', function()
- execute("let g:test_clip['*'] = ['linewise stuff','']")
- execute("let g:test_clip['+'] = ['charwise','stuff']")
+ it('autodetects regtype', function()
+ feed_command("let g:test_clip['*'] = ['linewise stuff','']")
+ feed_command("let g:test_clip['+'] = ['charwise','stuff']")
eq("V", eval("getregtype('*')"))
eq("v", eval("getregtype('+')"))
insert("just some text")
@@ -156,7 +245,7 @@ describe('clipboard usage', function()
insert([[
much
text]])
- execute("let g:test_clip['*'] = [['very','block'],'b']")
+ feed_command("let g:test_clip['*'] = [['very','block'],'b']")
feed('gg"*P')
expect([[
very much
@@ -169,16 +258,16 @@ describe('clipboard usage', function()
eq({{' much', 'ktext', ''}, 'b'}, eval("g:test_clip['+']"))
end)
- it('supports setreg', function()
- execute('call setreg("*", "setted\\ntext", "c")')
- execute('call setreg("+", "explicitly\\nlines", "l")')
+ it('supports setreg()', function()
+ feed_command('call setreg("*", "setted\\ntext", "c")')
+ feed_command('call setreg("+", "explicitly\\nlines", "l")')
feed('"+P"*p')
expect([[
esetted
textxplicitly
lines
]])
- execute('call setreg("+", "blocky\\nindeed", "b")')
+ feed_command('call setreg("+", "blocky\\nindeed", "b")')
feed('"+p')
expect([[
esblockyetted
@@ -187,14 +276,14 @@ describe('clipboard usage', function()
]])
end)
- it('supports let @+ (issue #1427)', function()
- execute("let @+ = 'some'")
- execute("let @* = ' other stuff'")
+ it('supports :let @+ (issue #1427)', function()
+ feed_command("let @+ = 'some'")
+ feed_command("let @* = ' other stuff'")
eq({{'some'}, 'v'}, eval("g:test_clip['+']"))
eq({{' other stuff'}, 'v'}, eval("g:test_clip['*']"))
feed('"+p"*p')
expect('some other stuff')
- execute("let @+ .= ' more'")
+ feed_command("let @+ .= ' more'")
feed('dd"+p')
expect('some more')
end)
@@ -202,7 +291,7 @@ describe('clipboard usage', function()
it('pastes unnamed register if the provider fails', function()
insert('the text')
feed('yy')
- execute("let g:cliperror = 1")
+ feed_command("let g:cliperror = 1")
feed('"*p')
expect([[
the text
@@ -214,7 +303,7 @@ describe('clipboard usage', function()
-- the basic behavior of unnamed register should be the same
-- even when handled by clipboard provider
before_each(function()
- execute('set clipboard=unnamed')
+ feed_command('set clipboard=unnamed')
end)
it('works', function()
@@ -222,7 +311,7 @@ describe('clipboard usage', function()
end)
it('works with pure text clipboard', function()
- execute("let g:cliplossy = 1")
+ feed_command("let g:cliplossy = 1")
-- expect failure for block mode
basic_register_test(true)
end)
@@ -237,7 +326,7 @@ describe('clipboard usage', function()
-- "+ shouldn't have changed
eq({''}, eval("g:test_clip['+']"))
- execute("let g:test_clip['*'] = ['linewise stuff','']")
+ feed_command("let g:test_clip['*'] = ['linewise stuff','']")
feed('p')
expect([[
words
@@ -247,7 +336,7 @@ describe('clipboard usage', function()
it('does not clobber "0 when pasting', function()
insert('a line')
feed('yy')
- execute("let g:test_clip['*'] = ['b line','']")
+ feed_command("let g:test_clip['*'] = ['b line','']")
feed('"0pp"0p')
expect([[
a line
@@ -258,20 +347,20 @@ describe('clipboard usage', function()
it('supports v:register and getreg() without parameters', function()
eq('*', eval('v:register'))
- execute("let g:test_clip['*'] = [['some block',''], 'b']")
+ feed_command("let g:test_clip['*'] = [['some block',''], 'b']")
eq('some block', eval('getreg()'))
eq('\02210', eval('getregtype()'))
end)
it('yanks visual selection when pasting', function()
insert("indeed visual")
- execute("let g:test_clip['*'] = [['clipboard'], 'c']")
+ feed_command("let g:test_clip['*'] = [['clipboard'], 'c']")
feed("viwp")
eq({{'visual'}, 'v'}, eval("g:test_clip['*']"))
expect("indeed clipboard")
-- explicit "* should do the same
- execute("let g:test_clip['*'] = [['star'], 'c']")
+ feed_command("let g:test_clip['*'] = [['star'], 'c']")
feed('viw"*p')
eq({{'clipboard'}, 'v'}, eval("g:test_clip['*']"))
expect("indeed star")
@@ -280,7 +369,7 @@ describe('clipboard usage', function()
it('unamed operations work even if the provider fails', function()
insert('the text')
feed('yy')
- execute("let g:cliperror = 1")
+ feed_command("let g:cliperror = 1")
feed('p')
expect([[
the text
@@ -294,20 +383,27 @@ describe('clipboard usage', function()
match
text
]])
- execute('g/match/d')
+ feed_command('g/match/d')
eq('match\n', eval('getreg("*")'))
feed('u')
eval('setreg("*", "---")')
- execute('g/test/')
+ feed_command('g/test/')
feed('<esc>')
eq('---', eval('getreg("*")'))
end)
+ it('works in the cmdline window', function()
+ feed('q:itext<esc>yy')
+ eq({{'text', ''}, 'V'}, eval("g:test_clip['*']"))
+ command("let g:test_clip['*'] = [['star'], 'c']")
+ feed('p')
+ eq('textstar', meths.get_current_line())
+ end)
end)
- describe('with clipboard=unnamedplus', function()
+ describe('clipboard=unnamedplus', function()
before_each(function()
- execute('set clipboard=unnamedplus')
+ feed_command('set clipboard=unnamedplus')
end)
it('links the "+ and unnamed registers', function()
@@ -320,13 +416,13 @@ describe('clipboard usage', function()
-- "* shouldn't have changed
eq({''}, eval("g:test_clip['*']"))
- execute("let g:test_clip['+'] = ['three']")
+ feed_command("let g:test_clip['+'] = ['three']")
feed('p')
expect('twothree')
end)
it('and unnamed, yanks to both', function()
- execute('set clipboard=unnamedplus,unnamed')
+ feed_command('set clipboard=unnamedplus,unnamed')
insert([[
really unnamed
text]])
@@ -340,8 +436,8 @@ describe('clipboard usage', function()
-- unnamedplus takes predecence when pasting
eq('+', eval('v:register'))
- execute("let g:test_clip['+'] = ['the plus','']")
- execute("let g:test_clip['*'] = ['the star','']")
+ feed_command("let g:test_clip['+'] = ['the plus','']")
+ feed_command("let g:test_clip['*'] = ['the star','']")
feed("p")
expect([[
text
@@ -349,6 +445,7 @@ describe('clipboard usage', function()
really unnamed
the plus]])
end)
+
it('is updated on global changes', function()
insert([[
text
@@ -356,11 +453,11 @@ describe('clipboard usage', function()
match
text
]])
- execute('g/match/d')
+ feed_command('g/match/d')
eq('match\n', eval('getreg("+")'))
feed('u')
eval('setreg("+", "---")')
- execute('g/test/')
+ feed_command('g/test/')
feed('<esc>')
eq('---', eval('getreg("+")'))
end)
@@ -375,13 +472,13 @@ describe('clipboard usage', function()
it('supports :put', function()
insert("a line")
- execute("let g:test_clip['*'] = ['some text']")
- execute("let g:test_clip['+'] = ['more', 'text', '']")
- execute(":put *")
+ feed_command("let g:test_clip['*'] = ['some text']")
+ feed_command("let g:test_clip['+'] = ['more', 'text', '']")
+ feed_command(":put *")
expect([[
a line
some text]])
- execute(":put +")
+ feed_command(":put +")
expect([[
a line
some text
@@ -392,9 +489,9 @@ describe('clipboard usage', function()
it('supports "+ and "* in registers', function()
local screen = Screen.new(60, 10)
screen:attach()
- execute("let g:test_clip['*'] = ['some', 'star data','']")
- execute("let g:test_clip['+'] = ['such', 'plus', 'stuff']")
- execute("registers")
+ feed_command("let g:test_clip['*'] = ['some', 'star data','']")
+ feed_command("let g:test_clip['+'] = ['such', 'plus', 'stuff']")
+ feed_command("registers")
screen:expect([[
~ |
~ |
@@ -418,17 +515,17 @@ describe('clipboard usage', function()
insert('s/s/t/')
feed('gg"*y$:<c-r>*<cr>')
expect('t/s/t/')
- execute("let g:test_clip['*'] = ['s/s/u']")
+ feed_command("let g:test_clip['*'] = ['s/s/u']")
feed(':<c-r>*<cr>')
expect('t/u/t/')
end)
it('supports :redir @*>', function()
- execute("let g:test_clip['*'] = ['stuff']")
- execute('redir @*>')
+ feed_command("let g:test_clip['*'] = ['stuff']")
+ feed_command('redir @*>')
-- it is made empty
eq({{''}, 'v'}, eval("g:test_clip['*']"))
- execute('let g:test = doesnotexist')
+ feed_command('let g:test = doesnotexist')
feed('<cr>')
eq({{
'',
@@ -436,7 +533,7 @@ describe('clipboard usage', function()
'E121: Undefined variable: doesnotexist',
'E15: Invalid expression: doesnotexist',
}, 'v'}, eval("g:test_clip['*']"))
- execute(':echo "Howdy!"')
+ feed_command(':echo "Howdy!"')
eq({{
'',
'',
@@ -448,7 +545,7 @@ describe('clipboard usage', function()
end)
it('handles middleclick correctly', function()
- execute('set mouse=a')
+ feed_command('set mouse=a')
local screen = Screen.new(30, 5)
screen:attach()
@@ -471,7 +568,7 @@ describe('clipboard usage', function()
the a target]])
-- on error, fall back to unnamed register
- execute("let g:cliperror = 1")
+ feed_command("let g:cliperror = 1")
feed('<MiddleMouse><6,1>')
expect([[
the source