From 638ceea092f01675e964a5e5a6adc6af8f28f423 Mon Sep 17 00:00:00 2001 From: Björn Linse Date: Wed, 25 Mar 2015 18:21:02 +0100 Subject: test/clipboard: split unrelated subtests --- .../clipboard/clipboard_provider_spec.lua | 31 +++++++++++----------- 1 file changed, 16 insertions(+), 15 deletions(-) (limited to 'test') diff --git a/test/functional/clipboard/clipboard_provider_spec.lua b/test/functional/clipboard/clipboard_provider_spec.lua index 1a798ec48c..c5577327f9 100644 --- a/test/functional/clipboard/clipboard_provider_spec.lua +++ b/test/functional/clipboard/clipboard_provider_spec.lua @@ -8,6 +8,7 @@ local nvim, run, stop, restart = helpers.nvim, helpers.run, helpers.stop, helper local function reset() clear() execute('let &rtp = "test/functional/clipboard,".&rtp') + execute('call getreg("*")') -- force load of provider end local function basic_register_test() @@ -62,7 +63,8 @@ local function basic_register_test() end describe('clipboard usage', function() - setup(reset) + before_each(reset) + it("works", function() basic_register_test() @@ -71,9 +73,9 @@ describe('clipboard usage', function() feed('^"*dwdw"*P') expect('some ') eq({'some '}, eval("g:test_clip['*']")) - reset() + end) - -- "* and "+ should be independent when the provider supports it + it('supports separate "* and "+ when the provider supports it', function() insert([[ text: first line @@ -89,9 +91,9 @@ describe('clipboard usage', function() -- linewise selection should be encoded as an extra newline eq({'third line', ''}, eval("g:test_clip['+']")) eq({'secound line', ''}, eval("g:test_clip['*']")) - reset() + end) - -- handle null bytes + it('handles null bytes', function() insert("some\022000text\n\022000very binary\022000") feed('"*y-+"*p') eq({'some\ntext', '\nvery binary\n',''}, eval("g:test_clip['*']")) @@ -100,22 +102,21 @@ describe('clipboard usage', function() -- test getreg/getregtype eq('some\ntext\n\nvery binary\n\n', eval("getreg('*', 1)")) eq("V", eval("getregtype('*')")) - reset() + end) - -- blockwise paste + it('support blockwise operations', function() insert([[ much text]]) - feed('"*yy') -- force load of provider execute("let g:test_clip['*'] = [['very','block'],'b']") feed('gg"*P') expect([[ very much blocktext]]) eq("\0225", eval("getregtype('*')")) - reset() + end) - -- test setreg + it('supports setreg', function() execute('call setreg("*", "setted\\ntext", "c")') execute('call setreg("+", "explicitly\\nlines", "l")') feed('"+P"*p') @@ -124,9 +125,9 @@ describe('clipboard usage', function() textxplicitly lines ]]) - reset() + end) - -- test let @+ (issue #1427) + it('supports let @+ (issue #1427)', function() execute("let @+ = 'some'") execute("let @* = ' other stuff'") eq({'some'}, eval("g:test_clip['+']")) @@ -136,8 +137,9 @@ describe('clipboard usage', function() execute("let @+ .= ' more'") feed('dd"+p') expect('some more') - reset() + end) + it('supports clipboard=unnamed', function() -- the basic behavior of unnamed register should be the same -- even when handled by clipboard provider execute('set clipboard=unnamed') @@ -155,7 +157,6 @@ describe('clipboard usage', function() expect([[ words linewise stuff]]) - reset() + end) - end) end) -- cgit From 5600b80c1fcdf9d056bb7a0b5a74e5563dcb991f Mon Sep 17 00:00:00 2001 From: Björn Linse Date: Wed, 18 Mar 2015 22:38:19 +0100 Subject: clipboard: show "* and "+ in :registers Helped-by: Robin Allen Helped-by: Scott Prager --- .../clipboard/clipboard_provider_spec.lua | 24 ++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'test') diff --git a/test/functional/clipboard/clipboard_provider_spec.lua b/test/functional/clipboard/clipboard_provider_spec.lua index c5577327f9..c1c56c94c1 100644 --- a/test/functional/clipboard/clipboard_provider_spec.lua +++ b/test/functional/clipboard/clipboard_provider_spec.lua @@ -1,6 +1,7 @@ -- Test clipboard provider support local helpers = require('test.functional.helpers') +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 nvim, run, stop, restart = helpers.nvim, helpers.run, helpers.stop, helpers.restart @@ -159,4 +160,27 @@ describe('clipboard usage', function() linewise stuff]]) end) + 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") + screen:expect([[ + ~ | + ~ | + ~ | + ~ | + :registers | + {1:--- Registers ---} | + "* some{2:^J}star data{2:^J} | + "+ such{2:^J}plus{2:^J}stuff | + ": let g:test_clip['+'] = ['such', 'plus', 'stuff'] | + {3:Press ENTER or type command to continue}^ | + ]], { + [1] = {bold = true, foreground = Screen.colors.Fuchsia}, + [2] = {foreground = Screen.colors.Blue}, + [3] = {bold = true, foreground = Screen.colors.SeaGreen}}, + {{bold = true, foreground = Screen.colors.Blue}}) + end) end) -- cgit From 34dba3d7cd43b4797d60f636dc9c7c3040a56f3c Mon Sep 17 00:00:00 2001 From: Björn Linse Date: Wed, 18 Mar 2015 23:43:49 +0100 Subject: clipboard: reallow `:put` --- test/functional/clipboard/clipboard_provider_spec.lua | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'test') diff --git a/test/functional/clipboard/clipboard_provider_spec.lua b/test/functional/clipboard/clipboard_provider_spec.lua index c1c56c94c1..f1e011f12d 100644 --- a/test/functional/clipboard/clipboard_provider_spec.lua +++ b/test/functional/clipboard/clipboard_provider_spec.lua @@ -160,6 +160,22 @@ describe('clipboard usage', function() linewise stuff]]) end) + it('supports :put', function() + insert("a line") + execute("let g:test_clip['*'] = ['some text']") + execute("let g:test_clip['+'] = ['more', 'text', '']") + execute(":put *") + expect([[ + a line + some text]]) + execute(":put +") + expect([[ + a line + some text + more + text]]) + end) + it('supports "+ and "* in registers', function() local screen = Screen.new(60, 10) screen:attach() -- cgit From 7422843f5c86b0dc18e26e5a2436f9d8e7013e12 Mon Sep 17 00:00:00 2001 From: Björn Linse Date: Sat, 28 Mar 2015 20:57:06 +0100 Subject: clipboard: improve the handling of newlines in `get_clipboard` This makes the interpretion consistent with the way newlines are used in the VIMENC format, while keeping the same fallback behaviour when regtype is unspecified. Also check both cases explicitly in the tests. --- .../clipboard/autoload/provider/clipboard.vim | 2 +- .../clipboard/clipboard_provider_spec.lua | 45 ++++++++++++++++++---- 2 files changed, 38 insertions(+), 9 deletions(-) (limited to 'test') diff --git a/test/functional/clipboard/autoload/provider/clipboard.vim b/test/functional/clipboard/autoload/provider/clipboard.vim index 6c05a19fc3..c7fd630782 100644 --- a/test/functional/clipboard/autoload/provider/clipboard.vim +++ b/test/functional/clipboard/autoload/provider/clipboard.vim @@ -7,7 +7,7 @@ function! s:methods.get(reg) endfunction function! s:methods.set(lines, regtype, reg) - let g:test_clip[a:reg] = a:lines + let g:test_clip[a:reg] = [a:lines, a:regtype] endfunction diff --git a/test/functional/clipboard/clipboard_provider_spec.lua b/test/functional/clipboard/clipboard_provider_spec.lua index f1e011f12d..363dcb1d11 100644 --- a/test/functional/clipboard/clipboard_provider_spec.lua +++ b/test/functional/clipboard/clipboard_provider_spec.lua @@ -73,7 +73,7 @@ describe('clipboard usage', function() insert("some words") feed('^"*dwdw"*P') expect('some ') - eq({'some '}, eval("g:test_clip['*']")) + eq({{'some '}, 'v'}, eval("g:test_clip['*']")) end) it('supports separate "* and "+ when the provider supports it', function() @@ -90,19 +90,36 @@ describe('clipboard usage', function() secound line first line]]) -- linewise selection should be encoded as an extra newline - eq({'third line', ''}, eval("g:test_clip['+']")) - eq({'secound line', ''}, eval("g:test_clip['*']")) + eq({{'third line', ''}, 'V'}, eval("g:test_clip['+']")) + eq({{'secound line', ''}, 'V'}, eval("g:test_clip['*']")) end) - it('handles null bytes', function() + it('handles null bytes when pasting and in getreg', function() insert("some\022000text\n\022000very binary\022000") feed('"*y-+"*p') - eq({'some\ntext', '\nvery binary\n',''}, eval("g:test_clip['*']")) + eq({{'some\ntext', '\nvery binary\n',''}, 'V'}, eval("g:test_clip['*']")) expect("some\00text\n\00very binary\00\nsome\00text\n\00very binary\00") -- test getreg/getregtype eq('some\ntext\n\nvery binary\n\n', eval("getreg('*', 1)")) eq("V", eval("getregtype('*')")) + + -- getreg supports three arguments + eq('some\ntext\n\nvery binary\n\n', eval("getreg('*', 1, 0)")) + 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']") + eq("V", eval("getregtype('*')")) + eq("v", eval("getregtype('+')")) + insert("just some text") + feed('"*p"+p') + expect([[ + just some text + lcharwise + stuffinewise stuff]]) end) it('support blockwise operations', function() @@ -115,6 +132,11 @@ describe('clipboard usage', function() very much blocktext]]) eq("\0225", eval("getregtype('*')")) + feed('gg4lj4l"+ygg"+P') + expect([[ + muchvery much + ktextblocktext]]) + eq({{' much', 'ktext', ''}, 'b'}, eval("g:test_clip['+']")) end) it('supports setreg', function() @@ -126,13 +148,20 @@ describe('clipboard usage', function() textxplicitly lines ]]) + execute('call setreg("+", "blocky\\nindeed", "b")') + feed('"+p') + expect([[ + esblockyetted + teindeedxtxplicitly + lines + ]]) end) it('supports let @+ (issue #1427)', function() execute("let @+ = 'some'") execute("let @* = ' other stuff'") - eq({'some'}, eval("g:test_clip['+']")) - eq({' other stuff'}, eval("g:test_clip['*']")) + 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'") @@ -151,7 +180,7 @@ describe('clipboard usage', function() insert("some words") feed('^"*dwdw"*P') expect('words') - eq({'words'}, eval("g:test_clip['*']")) + eq({{'words'}, 'v'}, eval("g:test_clip['*']")) execute("let g:test_clip['*'] = ['linewise stuff','']") feed('p') -- cgit From db92fcdba3f596838f524a049efe1c7e82bb734f Mon Sep 17 00:00:00 2001 From: Björn Linse Date: Sun, 29 Mar 2015 12:20:26 +0200 Subject: test/clipboard: more clipboard test cleanups --- .../clipboard/autoload/provider/clipboard.vim | 10 ++- .../clipboard/clipboard_provider_spec.lua | 82 +++++++++++++++------- 2 files changed, 64 insertions(+), 28 deletions(-) (limited to 'test') diff --git a/test/functional/clipboard/autoload/provider/clipboard.vim b/test/functional/clipboard/autoload/provider/clipboard.vim index c7fd630782..d88b68464e 100644 --- a/test/functional/clipboard/autoload/provider/clipboard.vim +++ b/test/functional/clipboard/autoload/provider/clipboard.vim @@ -2,8 +2,16 @@ let g:test_clip = { '+': [''], '*': [''], } let s:methods = {} +let g:cliplossy = 0 + function! s:methods.get(reg) - return g:test_clip[a:reg] + if g:cliplossy + " behave like pure text clipboard + return g:test_clip[a:reg][0] + else + "behave like VIMENC clipboard + return g:test_clip[a:reg] + end endfunction function! s:methods.set(lines, regtype, reg) diff --git a/test/functional/clipboard/clipboard_provider_spec.lua b/test/functional/clipboard/clipboard_provider_spec.lua index 363dcb1d11..74a3bf4ae0 100644 --- a/test/functional/clipboard/clipboard_provider_spec.lua +++ b/test/functional/clipboard/clipboard_provider_spec.lua @@ -6,13 +6,7 @@ local clear, feed, insert = helpers.clear, helpers.feed, helpers.insert local execute, expect, eq, eval = helpers.execute, helpers.expect, helpers.eq, helpers.eval local nvim, run, stop, restart = helpers.nvim, helpers.run, helpers.stop, helpers.restart -local function reset() - clear() - execute('let &rtp = "test/functional/clipboard,".&rtp') - execute('call getreg("*")') -- force load of provider -end - -local function basic_register_test() +local function basic_register_test(noblock) insert("some words") feed('^dwP') @@ -60,20 +54,41 @@ local function basic_register_test() expect([[ , stuff and some more some textsome some text, stuff and some more]]) - reset() -end -describe('clipboard usage', function() - before_each(reset) + feed('ggwjwyggP') + if noblock then + expect([[ + stuf + me t + , stuff and some more + some textsome some text, stuff and some more]]) + else + expect([[ + stuf, stuff and some more + me tsome textsome some text, stuff and some more]]) + end +end - it("works", function() +describe('the unnamed register', function() + before_each(clear) + it('works without provider', function() basic_register_test() + end) +end) - -- "* and unnamed should function as independent registers +describe('clipboard usage', function() + before_each(function() + clear() + execute('let &rtp = "test/functional/clipboard,".&rtp') + execute('call getreg("*")') -- force load of provider + end) + + it('has independent "* and unnamed registers per default', function() insert("some words") feed('^"*dwdw"*P') expect('some ') eq({{'some '}, 'v'}, eval("g:test_clip['*']")) + eq('words', eval("getreg('\"', 1)")) end) it('supports separate "* and "+ when the provider supports it', function() @@ -169,24 +184,37 @@ describe('clipboard usage', function() expect('some more') end) - it('supports clipboard=unnamed', function() + describe('with clipboard=unnamed', function() -- the basic behavior of unnamed register should be the same -- even when handled by clipboard provider - execute('set clipboard=unnamed') - basic_register_test() + before_each(function() + execute('set clipboard=unnamed') + end) - -- with cb=unnamed, "* and unnamed will be the same register - execute('set clipboard=unnamed') - insert("some words") - feed('^"*dwdw"*P') - expect('words') - eq({{'words'}, 'v'}, eval("g:test_clip['*']")) + it('works', function() + basic_register_test() + end) - execute("let g:test_clip['*'] = ['linewise stuff','']") - feed('p') - expect([[ - words - linewise stuff]]) + it('works with pure text clipboard', function() + execute("let g:cliplossy = 1") + -- expect failure for block mode + basic_register_test(true) + end) + + it('links the "* and unnamed registers', function() + -- with cb=unnamed, "* and unnamed will be the same register + execute('set clipboard=unnamed') + insert("some words") + feed('^"*dwdw"*P') + expect('words') + eq({{'words'}, 'v'}, eval("g:test_clip['*']")) + + execute("let g:test_clip['*'] = ['linewise stuff','']") + feed('p') + expect([[ + words + linewise stuff]]) + end) end) it('supports :put', function() -- cgit From adcf268a72827be38510b1830b67b287dec50c4a Mon Sep 17 00:00:00 2001 From: Björn Linse Date: Sun, 29 Mar 2015 12:39:52 +0200 Subject: clipboard: handle clipboard reading directly in `get_yank_register` This makes :* work as expected and avoids clobbering zero register ("0) when pasting unnamed clipboard Helped-By: Scott Prager Helped-By: Michael Reed --- .../clipboard/clipboard_provider_spec.lua | 23 +++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) (limited to 'test') diff --git a/test/functional/clipboard/clipboard_provider_spec.lua b/test/functional/clipboard/clipboard_provider_spec.lua index 74a3bf4ae0..e7ca183a0e 100644 --- a/test/functional/clipboard/clipboard_provider_spec.lua +++ b/test/functional/clipboard/clipboard_provider_spec.lua @@ -203,7 +203,6 @@ describe('clipboard usage', function() it('links the "* and unnamed registers', function() -- with cb=unnamed, "* and unnamed will be the same register - execute('set clipboard=unnamed') insert("some words") feed('^"*dwdw"*P') expect('words') @@ -215,6 +214,19 @@ describe('clipboard usage', function() words linewise stuff]]) end) + + it('does not clobber "0 when pasting', function() + insert('a line') + feed('yy') + execute("let g:test_clip['*'] = ['b line','']") + feed('"0pp"0p') + expect([[ + a line + a line + b line + a line]]) + end) + end) it('supports :put', function() @@ -256,4 +268,13 @@ describe('clipboard usage', function() [3] = {bold = true, foreground = Screen.colors.SeaGreen}}, {{bold = true, foreground = Screen.colors.Blue}}) end) + + it('can paste "* to the commandline', function() + insert('s/s/t/') + feed('gg"*y$:*') + expect('t/s/t/') + execute("let g:test_clip['*'] = ['s/s/u']") + feed(':*') + expect('t/u/t/') + end) end) -- cgit