diff options
author | Justin M. Keyes <justinkz@gmail.com> | 2024-01-03 02:09:18 +0100 |
---|---|---|
committer | Justin M. Keyes <justinkz@gmail.com> | 2024-01-03 02:09:29 +0100 |
commit | 04f2f864e270e772c6326cefdf24947f0130e492 (patch) | |
tree | 46f83f909b888a66c741032ab955afc6eab84292 /test/functional/provider/clipboard_spec.lua | |
parent | 59d117ec99b6037cb9fad5bbfb6d0b18f5012927 (diff) | |
download | rneovim-04f2f864e270e772c6326cefdf24947f0130e492.tar.gz rneovim-04f2f864e270e772c6326cefdf24947f0130e492.tar.bz2 rneovim-04f2f864e270e772c6326cefdf24947f0130e492.zip |
refactor: format test/*
Diffstat (limited to 'test/functional/provider/clipboard_spec.lua')
-rw-r--r-- | test/functional/provider/clipboard_spec.lua | 181 |
1 files changed, 96 insertions, 85 deletions
diff --git a/test/functional/provider/clipboard_spec.lua b/test/functional/provider/clipboard_spec.lua index 004ee6d106..a48404164f 100644 --- a/test/functional/provider/clipboard_spec.lua +++ b/test/functional/provider/clipboard_spec.lua @@ -3,12 +3,13 @@ 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 feed_command, expect, eq, eval, source = helpers.feed_command, helpers.expect, helpers.eq, helpers.eval, helpers.source +local feed_command, expect, eq, eval, source = + helpers.feed_command, helpers.expect, helpers.eq, helpers.eval, helpers.source local command = helpers.command local meths = helpers.meths local function basic_register_test(noblock) - insert("some words") + insert('some words') feed('^dwP') expect('some words') @@ -81,9 +82,9 @@ local function basic_register_test(noblock) -- pasting in visual does unnamed delete of visual selection feed('ggdG') - insert("one and two and three") + insert('one and two and three') feed('"ayiwbbviw"ap^viwp$viw"-p') - expect("two and three and one") + expect('two and three and one') end describe('clipboard', function() @@ -93,10 +94,10 @@ describe('clipboard', function() clear() screen = Screen.new(72, 4) screen:set_default_attr_ids({ - [0] = {bold = true, foreground = Screen.colors.Blue}, - [1] = {foreground = Screen.colors.Grey100, background = Screen.colors.Red}, - [2] = {bold = true, foreground = Screen.colors.SeaGreen4}, - [3] = {bold = true, reverse = true}; + [0] = { bold = true, foreground = Screen.colors.Blue }, + [1] = { foreground = Screen.colors.Grey100, background = Screen.colors.Red }, + [2] = { bold = true, foreground = Screen.colors.SeaGreen4 }, + [3] = { bold = true, reverse = true }, }) screen:attach() end) @@ -160,12 +161,14 @@ describe('clipboard', function() it('`:redir @+>|bogus_cmd|redir END` + invalid g:clipboard must not recurse #7184', function() command("let g:clipboard = 'bogus'") feed_command('redir @+> | bogus_cmd | redir END') - screen:expect{grid=[[ + screen:expect { + grid = [[ {3: }| clipboard: No provider. Try ":checkhealth" or ":h clipboard". | {1:E492: Not an editor command: bogus_cmd | redir END} | {2:Press ENTER or type command to continue}^ | - ]]} + ]], + } end) it('invalid g:clipboard shows hint if :redir is not active', function() @@ -231,11 +234,11 @@ describe('clipboard', function() eq('plus', eval("getreg('+')")) command('call setreg("*", "star", "v")') - eq({{'star'}, 'v'}, eval("g:dummy_clipboard_star")) + eq({ { 'star' }, 'v' }, eval('g:dummy_clipboard_star')) command('call setreg("*", "star", "V")') - eq({{'star', ''}, 'V'}, eval("g:dummy_clipboard_star")) + eq({ { 'star', '' }, 'V' }, eval('g:dummy_clipboard_star')) command('call setreg("*", "star", "b")') - eq({{'star', ''}, 'b'}, eval("g:dummy_clipboard_star")) + eq({ { 'star', '' }, 'b' }, eval('g:dummy_clipboard_star')) end) describe('g:clipboard[paste] Vimscript function', function() @@ -303,28 +306,27 @@ describe('clipboard (with fake clipboard.vim)', function() end) 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') -- Assuming CONTRIBUTING.md has >100 lines. - assert(eval("g:clip_called_set") > 100) + 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")) + 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")) + eq(0, eval('g:clip_called_set')) 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) screen:attach() screen:set_default_attr_ids({ - [0] = {bold = true, foreground = Screen.colors.Blue}, - [1] = {foreground = Screen.colors.Grey100, background = Screen.colors.Red}, + [0] = { bold = true, foreground = Screen.colors.Blue }, + [1] = { foreground = Screen.colors.Grey100, background = Screen.colors.Red }, }) feed_command('redir @+> | bogus_cmd | redir END') screen:expect([[ @@ -335,10 +337,10 @@ describe('clipboard (with fake clipboard.vim)', function() end) it('has independent "* and unnamed registers by default', function() - insert("some words") + insert('some words') feed('^"*dwdw"*P') expect('some ') - eq({{'some '}, 'v'}, eval("g:test_clip['*']")) + eq({ { 'some ' }, 'v' }, eval("g:test_clip['*']")) eq('words', eval("getreg('\"', 1)")) end) @@ -356,31 +358,31 @@ describe('clipboard (with fake clipboard.vim)', function() second line first line]]) -- linewise selection should be encoded as an extra newline - eq({{'third line', ''}, 'V'}, eval("g:test_clip['+']")) - eq({{'second line', ''}, 'V'}, eval("g:test_clip['*']")) + eq({ { 'third line', '' }, 'V' }, eval("g:test_clip['+']")) + eq({ { 'second line', '' }, 'V' }, eval("g:test_clip['*']")) end) it('handles null bytes when pasting and in getreg', function() - insert("some\022000text\n\022000very binary\022000") + insert('some\022000text\n\022000very binary\022000') feed('"*y-+"*p') - eq({{'some\ntext', '\nvery binary\n',''}, 'V'}, eval("g:test_clip['*']")) - expect("some\00text\n\00very binary\00\nsome\00text\n\00very binary\00") + 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('*')")) + 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)")) + eq({ 'some\ntext', '\nvery binary\n' }, eval("getreg('*', 1, 1)")) end) 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") + eq('V', eval("getregtype('*')")) + eq('v', eval("getregtype('+')")) + insert('just some text') feed('"*p"+p') expect([[ just some text @@ -397,12 +399,12 @@ describe('clipboard (with fake clipboard.vim)', function() expect([[ very much blocktext]]) - eq("\0225", eval("getregtype('*')")) + eq('\0225', eval("getregtype('*')")) feed('gg4l<c-v>j4l"+ygg"+P') expect([[ muchvery much ktextblocktext]]) - eq({{' much', 'ktext', ''}, 'b'}, eval("g:test_clip['+']")) + eq({ { ' much', 'ktext', '' }, 'b' }, eval("g:test_clip['+']")) end) it('supports setreg()', function() @@ -426,8 +428,8 @@ describe('clipboard (with fake clipboard.vim)', function() 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['*']")) + eq({ { 'some' }, 'v' }, eval("g:test_clip['+']")) + eq({ { ' other stuff' }, 'v' }, eval("g:test_clip['*']")) feed('"+p"*p') expect('some other stuff') feed_command("let @+ .= ' more'") @@ -438,14 +440,13 @@ describe('clipboard (with fake clipboard.vim)', function() it('pastes unnamed register if the provider fails', function() insert('the text') feed('yy') - feed_command("let g:cliperror = 1") + feed_command('let g:cliperror = 1') feed('"*p') expect([[ the text the text]]) end) - describe('with clipboard=unnamed', function() -- the basic behavior of unnamed register should be the same -- even when handled by clipboard provider @@ -458,20 +459,20 @@ describe('clipboard (with fake clipboard.vim)', function() end) it('works with pure text clipboard', function() - feed_command("let g:cliplossy = 1") + feed_command('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 - insert("some words") + insert('some words') feed('^"*dwdw"*P') expect('words') - eq({{'words'}, 'v'}, eval("g:test_clip['*']")) + eq({ { 'words' }, 'v' }, eval("g:test_clip['*']")) -- "+ shouldn't have changed - eq({''}, eval("g:test_clip['+']")) + eq({ '' }, eval("g:test_clip['+']")) feed_command("let g:test_clip['*'] = ['linewise stuff','']") feed('p') @@ -500,23 +501,23 @@ describe('clipboard (with fake clipboard.vim)', function() end) it('yanks visual selection when pasting', function() - insert("indeed visual") + insert('indeed visual') feed_command("let g:test_clip['*'] = [['clipboard'], 'c']") - feed("viwp") - eq({{'visual'}, 'v'}, eval("g:test_clip['*']")) - expect("indeed clipboard") + feed('viwp') + eq({ { 'visual' }, 'v' }, eval("g:test_clip['*']")) + expect('indeed clipboard') -- explicit "* should do the same feed_command("let g:test_clip['*'] = [['star'], 'c']") feed('viw"*p') - eq({{'clipboard'}, 'v'}, eval("g:test_clip['*']")) - expect("indeed star") + eq({ { 'clipboard' }, 'v' }, eval("g:test_clip['*']")) + expect('indeed star') end) it('unnamed operations work even if the provider fails', function() insert('the text') feed('yy') - feed_command("let g:cliperror = 1") + feed_command('let g:cliperror = 1') feed('p') expect([[ the text @@ -541,7 +542,7 @@ describe('clipboard (with fake clipboard.vim)', function() it('works in the cmdline window', function() feed('q:itext<esc>yy') - eq({{'text', ''}, 'V'}, eval("g:test_clip['*']")) + eq({ { 'text', '' }, 'V' }, eval("g:test_clip['*']")) command("let g:test_clip['*'] = [['star'], 'c']") feed('p') eq('textstar', meths.get_current_line()) @@ -569,13 +570,13 @@ describe('clipboard (with fake clipboard.vim)', function() it('links the "+ and unnamed registers', function() eq('+', eval('v:register')) - insert("one two") + insert('one two') feed('^"+dwdw"+P') expect('two') - eq({{'two'}, 'v'}, eval("g:test_clip['+']")) + eq({ { 'two' }, 'v' }, eval("g:test_clip['+']")) -- "* shouldn't have changed - eq({''}, eval("g:test_clip['*']")) + eq({ '' }, eval("g:test_clip['*']")) feed_command("let g:test_clip['+'] = ['three']") feed('p') @@ -592,14 +593,14 @@ describe('clipboard (with fake clipboard.vim)', function() text really unnamed really unnamed]]) - eq({{'really unnamed', ''}, 'V'}, eval("g:test_clip['+']")) - eq({{'really unnamed', ''}, 'V'}, eval("g:test_clip['*']")) + eq({ { 'really unnamed', '' }, 'V' }, eval("g:test_clip['+']")) + eq({ { 'really unnamed', '' }, 'V' }, eval("g:test_clip['*']")) -- unnamedplus takes precedence when pasting eq('+', eval('v:register')) feed_command("let g:test_clip['+'] = ['the plus','']") feed_command("let g:test_clip['*'] = ['the star','']") - feed("p") + feed('p') expect([[ text really unnamed @@ -632,14 +633,14 @@ describe('clipboard (with fake clipboard.vim)', function() end) it('supports :put', function() - insert("a line") + insert('a line') feed_command("let g:test_clip['*'] = ['some text']") feed_command("let g:test_clip['+'] = ['more', 'text', '']") - feed_command(":put *") + feed_command(':put *') expect([[ a line some text]]) - feed_command(":put +") + feed_command(':put +') expect([[ a line some text @@ -652,8 +653,9 @@ describe('clipboard (with fake clipboard.vim)', function() screen:attach() feed_command("let g:test_clip['*'] = ['some', 'star data','']") feed_command("let g:test_clip['+'] = ['such', 'plus', 'stuff']") - feed_command("registers") - screen:expect([[ + feed_command('registers') + screen:expect( + [[ | {0:~ }|*2 {4: }| @@ -663,12 +665,15 @@ describe('clipboard (with fake clipboard.vim)', function() c "+ such{2:^J}plus{2:^J}stuff | c ": let g:test_clip['+'] = ['such', 'plus', 'stuff'] | {3:Press ENTER or type command to continue}^ | - ]], { - [0] = {bold = true, foreground = Screen.colors.Blue}, - [1] = {bold = true, foreground = Screen.colors.Fuchsia}, - [2] = {foreground = Screen.colors.Blue}, - [3] = {bold = true, foreground = Screen.colors.SeaGreen}, - [4] = {bold = true, reverse = true}}) + ]], + { + [0] = { bold = true, foreground = Screen.colors.Blue }, + [1] = { bold = true, foreground = Screen.colors.Fuchsia }, + [2] = { foreground = Screen.colors.Blue }, + [3] = { bold = true, foreground = Screen.colors.SeaGreen }, + [4] = { bold = true, reverse = true }, + } + ) feed('<cr>') -- clear out of Press ENTER screen end) @@ -685,22 +690,28 @@ describe('clipboard (with fake clipboard.vim)', function() feed_command("let g:test_clip['*'] = ['stuff']") feed_command('redir @*>') -- it is made empty - eq({{''}, 'v'}, eval("g:test_clip['*']")) + eq({ { '' }, 'v' }, eval("g:test_clip['*']")) feed_command('let g:test = doesnotexist') feed('<cr>') - eq({{ - '', - '', - 'E121: Undefined variable: doesnotexist', - }, 'v'}, eval("g:test_clip['*']")) + eq( + { { + '', + '', + 'E121: Undefined variable: doesnotexist', + }, 'v' }, + eval("g:test_clip['*']") + ) feed_command(':echo "Howdy!"') - eq({{ - '', - '', - 'E121: Undefined variable: doesnotexist', - '', - 'Howdy!', - }, 'v'}, eval("g:test_clip['*']")) + eq({ + { + '', + '', + 'E121: Undefined variable: doesnotexist', + '', + 'Howdy!', + }, + 'v', + }, eval("g:test_clip['*']")) end) it('handles middleclick correctly', function() @@ -708,7 +719,7 @@ describe('clipboard (with fake clipboard.vim)', function() local screen = Screen.new(30, 5) screen:set_default_attr_ids({ - [0] = {bold = true, foreground = Screen.colors.Blue}, + [0] = { bold = true, foreground = Screen.colors.Blue }, }) screen:attach() insert([[ @@ -729,7 +740,7 @@ describe('clipboard (with fake clipboard.vim)', function() the a target]]) -- on error, fall back to unnamed register - feed_command("let g:cliperror = 1") + feed_command('let g:cliperror = 1') feed('<MiddleMouse><6,1>') expect([[ the source @@ -753,7 +764,7 @@ describe('clipboard (with fake clipboard.vim)', function() eq('some', eval('getreg("*")')) end) - it('does not fall back to unnamed register with getreg() #24257', function () + it('does not fall back to unnamed register with getreg() #24257', function() eval('setreg("", "wrong")') command('let g:cliperror = 1') eq('', eval('getreg("*")')) |