robin/laufey

git clone https://git.robinwobin.dev/robin/laufey

Justin M. KeyesMerge #40865 from justinmk/fixcif907614088

master
23.5 KiB790 linesraw
1-- Test clipboard provider support
2
3local t = require('test.testutil')
4local n = require('test.functional.testnvim')()
5local Screen = require('test.functional.ui.screen')
6
7local describe, it, before_each = t.describe, t.it, t.before_each
8local clear, feed, insert = n.clear, n.feed, n.insert
9local expect, eq, eval, source = n.expect, t.eq, n.eval, n.source
10local command = n.command
11local api = n.api
12
13local function basic_register_test(noblock)
14  insert('some words')
15
16  feed('^dwP')
17  expect('some words')
18
19  feed('veyP')
20  expect('some words words')
21
22  feed('^dwywe"-p')
23  expect('wordssome  words')
24
25  feed('p')
26  expect('wordssome words  words')
27
28  feed('yyp')
29  expect([[
30    wordssome words  words
31    wordssome words  words]])
32  feed('d-')
33
34  insert([[
35    some text, and some more
36    random text stuff]])
37  feed('ggtav+2ed$p')
38  expect([[
39    some text, stuff and some more
40    random text]])
41
42  -- deleting line or word uses "1/"- and doesn't clobber "0
43  -- and deleting word to unnamed doesn't clobber "1
44  feed('ggyyjdddw"0p"1p"-P')
45  expect([[
46    text, stuff and some more
47    some text, stuff and some more
48    some random text]])
49
50  -- delete line doesn't clobber "-
51  feed('dd"-P')
52  expect([[
53    text, stuff and some more
54    some some text, stuff and some more]])
55
56  -- deleting a word to named ("a) doesn't update "1 or "-
57  feed('gg"adwj"1P^"-P')
58  expect([[
59    , stuff and some more
60    some some random text
61    some some text, stuff and some more]])
62
63  -- deleting a line does update ""
64  feed('ggdd""P')
65  expect([[
66    , stuff and some more
67    some some random text
68    some some text, stuff and some more]])
69
70  feed('ggw<c-v>jwyggP')
71  if noblock then
72    expect([[
73      stuf
74      me s
75      , stuff and some more
76      some some random text
77      some some text, stuff and some more]])
78  else
79    expect([[
80      stuf, stuff and some more
81      me ssome some random text
82      some some text, stuff and some more]])
83  end
84
85  -- pasting in visual does unnamed delete of visual selection
86  feed('ggdG')
87  insert('one and two and three')
88  feed('"ayiwbbviw"ap^viwp$viw"-p')
89  expect('two and three and one')
90end
91
92describe('clipboard', function()
93  local screen
94
95  before_each(function()
96    clear()
97    screen = Screen.new(72, 4)
98  end)
99
100  it('unnamed register works without provider', function()
101    eq('"', eval('v:register'))
102    basic_register_test()
103  end)
104
105  it('using "+ in Normal mode with invalid g:clipboard always shows error', function()
106    insert('a')
107    command("let g:clipboard = 'bogus'")
108    feed('"+yl')
109    screen:expect([[
110      ^a                                                                       |
111      {1:~                                                                       }|*2
112      clipboard: No provider. Try ":checkhealth" or ":h clipboard".           |
113    ]])
114    feed('"+p')
115    screen:expect([[
116      a^a                                                                      |
117      {1:~                                                                       }|*2
118      clipboard: No provider. Try ":checkhealth" or ":h clipboard".           |
119    ]])
120  end)
121
122  it('using clipboard=unnamedplus with invalid g:clipboard shows error once', function()
123    insert('a')
124    command("let g:clipboard = 'bogus'")
125    command('set clipboard=unnamedplus')
126    feed('yl')
127    screen:expect([[
128      ^a                                                                       |
129      {1:~                                                                       }|*2
130      clipboard: No provider. Try ":checkhealth" or ":h clipboard".           |
131    ]])
132    feed(':<CR>')
133    screen:expect([[
134      ^a                                                                       |
135      {1:~                                                                       }|*2
136      :                                                                       |
137    ]])
138    feed('p')
139    screen:expect([[
140      a^a                                                                      |
141      {1:~                                                                       }|*2
142      :                                                                       |
143    ]])
144  end)
145
146  it('`:redir @+>` with invalid g:clipboard shows exactly one error #7184', function()
147    command("let g:clipboard = 'bogus'")
148    n.exec([[
149      redir @+>
150        silent echo system("cat test/functional/fixtures/tty-test.c")
151      redir END
152    ]])
153    screen:expect([[
154      ^                                                                        |
155      {1:~                                                                       }|*2
156      clipboard: No provider. Try ":checkhealth" or ":h clipboard".           |
157    ]])
158  end)
159
160  it('`:redir @+>|bogus_cmd|redir END` + invalid g:clipboard must not recurse #7184', function()
161    command("let g:clipboard = 'bogus'")
162    feed(':redir @+> | bogus_cmd | redir END<cr>')
163    screen:expect {
164      grid = [[
165    {3:                                                                        }|
166    clipboard: No provider. Try ":checkhealth" or ":h clipboard".           |
167    {9:E492: Not an editor command: bogus_cmd | redir END}                      |
168    {6:Press ENTER or type command to continue}^                                 |
169    ]],
170    }
171  end)
172
173  it('invalid g:clipboard shows hint if :redir is not active', function()
174    command("let g:clipboard = 'bogus'")
175    eq('', eval('provider#clipboard#Executable()'))
176    eq('clipboard: invalid g:clipboard', eval('provider#clipboard#Error()'))
177
178    command("let g:clipboard = 'bogus'")
179    -- Explicit clipboard attempt, should show a hint message.
180    feed(':let @+="foo"<cr>')
181    screen:expect([[
182      ^                                                                        |
183      {1:~                                                                       }|*2
184      clipboard: No provider. Try ":checkhealth" or ":h clipboard".           |
185    ]])
186  end)
187
188  it('valid g:clipboard', function()
189    -- provider#clipboard#Executable() only checks the structure.
190    api.nvim_set_var('clipboard', {
191      ['name'] = 'clippy!',
192      ['copy'] = { ['+'] = 'any command', ['*'] = 'some other' },
193      ['paste'] = { ['+'] = 'any command', ['*'] = 'some other' },
194    })
195    eq('clippy!', eval('provider#clipboard#Executable()'))
196    eq('', eval('provider#clipboard#Error()'))
197  end)
198
199  it('g:clipboard using lists', function()
200    source([[let g:clipboard = {
201            \  'name': 'custom',
202            \  'copy': { '+': ['any', 'command'], '*': ['some', 'other'] },
203            \  'paste': { '+': ['any', 'command'], '*': ['some', 'other'] },
204            \}]])
205    eq('custom', eval('provider#clipboard#Executable()'))
206    eq('', eval('provider#clipboard#Error()'))
207  end)
208
209  it('g:clipboard using Vimscript functions', function()
210    -- Implements a fake clipboard provider. cache_enabled is meaningless here.
211    source([[let g:clipboard = {
212            \  'name': 'custom',
213            \  'copy': {
214            \     '+': {lines, regtype -> extend(g:, {'dummy_clipboard_plus': [lines, regtype]}) },
215            \     '*': {lines, regtype -> extend(g:, {'dummy_clipboard_star': [lines, regtype]}) },
216            \   },
217            \  'paste': {
218            \     '+': {-> get(g:, 'dummy_clipboard_plus', [])},
219            \     '*': {-> get(g:, 'dummy_clipboard_star', [])},
220            \  },
221            \  'cache_enabled': 1,
222            \}]])
223
224    eq('', eval('provider#clipboard#Error()'))
225    eq('custom', eval('provider#clipboard#Executable()'))
226
227    eq('', eval("getreg('*')"))
228    eq('', eval("getreg('+')"))
229
230    command('call setreg("*", "star")')
231    command('call setreg("+", "plus")')
232    eq('star', eval("getreg('*')"))
233    eq('plus', eval("getreg('+')"))
234
235    command('call setreg("*", "star", "v")')
236    eq({ { 'star' }, 'v' }, eval('g:dummy_clipboard_star'))
237    command('call setreg("*", "star", "V")')
238    eq({ { 'star', '' }, 'V' }, eval('g:dummy_clipboard_star'))
239    command('call setreg("*", "star", "b")')
240    eq({ { 'star', '' }, 'b' }, eval('g:dummy_clipboard_star'))
241  end)
242
243  describe('g:clipboard[paste] Vimscript function', function()
244    it('can return empty list for empty clipboard', function()
245      source([[let g:dummy_clipboard = []
246              let g:clipboard = {
247              \  'name': 'custom',
248              \  'copy': { '*': {lines, regtype ->  0} },
249              \  'paste': { '*': {-> g:dummy_clipboard} },
250              \}]])
251      eq('', eval('provider#clipboard#Error()'))
252      eq('custom', eval('provider#clipboard#Executable()'))
253      eq('', eval("getreg('*')"))
254    end)
255
256    it('can return a list with a single string', function()
257      source([=[let g:dummy_clipboard = ['hello']
258              let g:clipboard = {
259              \  'name': 'custom',
260              \  'copy': { '*': {lines, regtype ->  0} },
261              \  'paste': { '*': {-> g:dummy_clipboard} },
262              \}]=])
263      eq('', eval('provider#clipboard#Error()'))
264      eq('custom', eval('provider#clipboard#Executable()'))
265
266      eq('hello', eval("getreg('*')"))
267      source([[let g:dummy_clipboard = [''] ]])
268      eq('', eval("getreg('*')"))
269    end)
270
271    it('can return a list of lines if a regtype is provided', function()
272      source([=[let g:dummy_clipboard = [['hello'], 'v']
273              let g:clipboard = {
274              \  'name': 'custom',
275              \  'copy': { '*': {lines, regtype ->  0} },
276              \  'paste': { '*': {-> g:dummy_clipboard} },
277              \}]=])
278      eq('', eval('provider#clipboard#Error()'))
279      eq('custom', eval('provider#clipboard#Executable()'))
280      eq('hello', eval("getreg('*')"))
281    end)
282
283    it('can return a list of lines instead of [lines, regtype]', function()
284      source([=[let g:dummy_clipboard = ['hello', 'v']
285              let g:clipboard = {
286              \  'name': 'custom',
287              \  'copy': { '*': {lines, regtype ->  0} },
288              \  'paste': { '*': {-> g:dummy_clipboard} },
289              \}]=])
290      eq('', eval('provider#clipboard#Error()'))
291      eq('custom', eval('provider#clipboard#Executable()'))
292      eq('hello\nv', eval("getreg('*')"))
293    end)
294  end)
295end)
296
297describe('clipboard (with fake clipboard.vim)', function()
298  local function reset(...)
299    clear('--cmd', 'set rtp^=test/functional/fixtures', ...)
300  end
301
302  before_each(function()
303    reset()
304    command('call getreg("*")') -- force load of provider
305  end)
306
307  it('`:redir @+>` invokes clipboard once-per-message', function()
308    eq(0, eval('g:clip_called_set'))
309    n.exec([[
310      redir @+>
311        silent echo system("cat test/functional/fixtures/tty-test.c")
312      redir END
313    ]])
314    -- Assuming tty-test.c has >100 lines.
315    assert(eval('g:clip_called_set') > 100)
316  end)
317
318  it('`:redir @">` does NOT invoke clipboard', function()
319    -- :redir to a non-clipboard register, with `:set clipboard=unnamed` does
320    -- NOT propagate to the clipboard. This is consistent with Vim.
321    command('set clipboard=unnamedplus')
322    eq(0, eval('g:clip_called_set'))
323    n.exec([[
324      redir @">
325        silent echo system("cat test/functional/fixtures/tty-test.c")
326      redir END
327    ]])
328    eq(0, eval('g:clip_called_set'))
329  end)
330
331  it('`:redir @+>|bogus_cmd|redir END` must not recurse #7184', function()
332    local screen = Screen.new(72, 4)
333    feed(':redir @+> | bogus_cmd | redir END<cr>')
334    screen:expect([[
335      ^                                                                        |
336      {1:~                                                                       }|*2
337      {9:E492: Not an editor command: bogus_cmd | redir END}                      |
338    ]])
339  end)
340
341  it('has independent "* and unnamed registers by default', function()
342    insert('some words')
343    feed('^"*dwdw"*P')
344    expect('some ')
345    eq({ { 'some ' }, 'v' }, eval("g:test_clip['*']"))
346    eq('words', eval("getreg('\"', 1)"))
347  end)
348
349  it('supports separate "* and "+ when the provider supports it', function()
350    insert([[
351      text:
352      first line
353      second line
354      third line]])
355
356    feed('G"+dd"*dddd"+p"*pp')
357    expect([[
358      text:
359      third line
360      second line
361      first line]])
362    -- linewise selection should be encoded as an extra newline
363    eq({ { 'third line', '' }, 'V' }, eval("g:test_clip['+']"))
364    eq({ { 'second line', '' }, 'V' }, eval("g:test_clip['*']"))
365  end)
366
367  it('handles null bytes when pasting and in getreg', function()
368    insert('some\022000text\n\022000very binary\022000')
369    feed('"*y-+"*p')
370    eq({ { 'some\ntext', '\nvery binary\n', '' }, 'V' }, eval("g:test_clip['*']"))
371    expect('some\00text\n\00very binary\00\nsome\00text\n\00very binary\00')
372
373    -- test getreg/getregtype
374    eq('some\ntext\n\nvery binary\n\n', eval("getreg('*', 1)"))
375    eq('V', eval("getregtype('*')"))
376
377    -- getreg supports three arguments
378    eq('some\ntext\n\nvery binary\n\n', eval("getreg('*', 1, 0)"))
379    eq({ 'some\ntext', '\nvery binary\n' }, eval("getreg('*', 1, 1)"))
380  end)
381
382  it('autodetects regtype', function()
383    command("let g:test_clip['*'] = ['linewise stuff','']")
384    command("let g:test_clip['+'] = ['charwise','stuff']")
385    eq('V', eval("getregtype('*')"))
386    eq('v', eval("getregtype('+')"))
387    insert('just some text')
388    feed('"*p"+p')
389    expect([[
390      just some text
391      lcharwise
392      stuffinewise stuff]])
393  end)
394
395  it('support blockwise operations', function()
396    insert([[
397      much
398      text]])
399    command("let g:test_clip['*'] = [['very','block'],'b']")
400    feed('gg"*P')
401    expect([[
402      very much
403      blocktext]])
404    eq('\0225', eval("getregtype('*')"))
405    feed('gg4l<c-v>j4l"+ygg"+P')
406    expect([[
407       muchvery much
408      ktextblocktext]])
409    eq({ { ' much', 'ktext', '' }, 'b' }, eval("g:test_clip['+']"))
410  end)
411
412  it('supports setreg()', function()
413    command('call setreg("*", "setted\\ntext", "c")')
414    command('call setreg("+", "explicitly\\nlines", "l")')
415    feed('"+P"*p')
416    expect([[
417        esetted
418        textxplicitly
419        lines
420        ]])
421    command('call setreg("+", "blocky\\nindeed", "b")')
422    feed('"+p')
423    expect([[
424        esblockyetted
425        teindeedxtxplicitly
426        lines
427        ]])
428  end)
429
430  it('supports :let @+ (issue #1427)', function()
431    command("let @+ = 'some'")
432    command("let @* = ' other stuff'")
433    eq({ { 'some' }, 'v' }, eval("g:test_clip['+']"))
434    eq({ { ' other stuff' }, 'v' }, eval("g:test_clip['*']"))
435    feed('"+p"*p')
436    expect('some other stuff')
437    command("let @+ .= ' more'")
438    feed('dd"+p')
439    expect('some more')
440  end)
441
442  it('pastes unnamed register if the provider fails', function()
443    insert('the text')
444    feed('yy')
445    command('let g:cliperror = 1')
446    feed('"*p')
447    expect([[
448      the text
449      the text]])
450  end)
451
452  describe('with clipboard=unnamed', function()
453    -- the basic behavior of unnamed register should be the same
454    -- even when handled by clipboard provider
455    before_each(function()
456      feed(':set clipboard=unnamed<cr>')
457    end)
458
459    it('works', function()
460      basic_register_test()
461    end)
462
463    it('works with pure text clipboard', function()
464      command('let g:cliplossy = 1')
465      -- expect failure for block mode
466      basic_register_test(true)
467    end)
468
469    it('links the "* and unnamed registers', function()
470      -- with cb=unnamed, "* and unnamed will be the same register
471      insert('some words')
472      feed('^"*dwdw"*P')
473      expect('words')
474      eq({ { 'words' }, 'v' }, eval("g:test_clip['*']"))
475
476      -- "+ shouldn't have changed
477      eq({ '' }, eval("g:test_clip['+']"))
478
479      command("let g:test_clip['*'] = ['linewise stuff','']")
480      feed('p')
481      expect([[
482        words
483        linewise stuff]])
484    end)
485
486    it('does not clobber "0 when pasting', function()
487      insert('a line')
488      feed('yy')
489      command("let g:test_clip['*'] = ['b line','']")
490      feed('"0pp"0p')
491      expect([[
492        a line
493        a line
494        b line
495        a line]])
496    end)
497
498    it('supports v:register and getreg() without parameters', function()
499      eq('*', eval('v:register'))
500      command("let g:test_clip['*'] = [['some block',''], 'b']")
501      eq('some block', eval('getreg()'))
502      eq('\02210', eval('getregtype()'))
503    end)
504
505    it('yanks visual selection when pasting', function()
506      insert('indeed visual')
507      command("let g:test_clip['*'] = [['clipboard'], 'c']")
508      feed('viwp')
509      eq({ { 'visual' }, 'v' }, eval("g:test_clip['*']"))
510      expect('indeed clipboard')
511
512      -- explicit "* should do the same
513      command("let g:test_clip['*'] = [['star'], 'c']")
514      feed('viw"*p')
515      eq({ { 'clipboard' }, 'v' }, eval("g:test_clip['*']"))
516      expect('indeed star')
517    end)
518
519    it('unnamed operations work even if the provider fails', function()
520      insert('the text')
521      feed('yy')
522      command('let g:cliperror = 1')
523      feed('p')
524      expect([[
525        the text
526        the text]])
527    end)
528
529    it('is updated on global changes', function()
530      insert([[
531	text
532	match
533	match
534	text
535      ]])
536      command('g/match/d')
537      eq('match\n', eval('getreg("*")'))
538      feed('u')
539      eval('setreg("*", "---")')
540      command('g/test/')
541      feed('<esc>')
542      eq('---', eval('getreg("*")'))
543    end)
544
545    it('works in the cmdline window', function()
546      feed('q:itext<esc>yy')
547      eq({ { 'text', '' }, 'V' }, eval("g:test_clip['*']"))
548      command("let g:test_clip['*'] = [['star'], 'c']")
549      feed('p')
550      eq('textstar', api.nvim_get_current_line())
551    end)
552
553    it('block paste works correctly', function()
554      insert([[
555        aabbcc
556        ddeeff
557      ]])
558      feed('gg^<C-v>') -- Goto start of top line enter visual block mode
559      feed('3ljy^k') -- yank 4x2 block & goto initial location
560      feed('P') -- Paste it before cursor
561      expect([[
562        aabbaabbcc
563        ddeeddeeff
564      ]])
565    end)
566
567    it('block paste computes block width correctly #35034', function()
568      insert('あいうえお')
569      feed('0<C-V>ly')
570      feed('P')
571      expect('あいあいうえお')
572      feed('A\nxxx\nxx<Esc>')
573      feed('0<C-V>kkly')
574      feed('P')
575      expect([[
576        あいあいあいうえお
577        xxx xxx
578        xx  xx]])
579      feed('G0<C-V>ky')
580      feed('P')
581      expect([[
582        あいあいあいうえお
583        xxxx xxx
584        xxx  xx]])
585    end)
586  end)
587
588  describe('clipboard=unnamedplus', function()
589    before_each(function()
590      feed(':set clipboard=unnamedplus<cr>')
591    end)
592
593    it('links the "+ and unnamed registers', function()
594      eq('+', eval('v:register'))
595      insert('one two')
596      feed('^"+dwdw"+P')
597      expect('two')
598      eq({ { 'two' }, 'v' }, eval("g:test_clip['+']"))
599
600      -- "* shouldn't have changed
601      eq({ '' }, eval("g:test_clip['*']"))
602
603      command("let g:test_clip['+'] = ['three']")
604      feed('p')
605      expect('twothree')
606    end)
607
608    it('and unnamed, yanks to both', function()
609      command('set clipboard=unnamedplus,unnamed')
610      insert([[
611        really unnamed
612        text]])
613      feed('ggdd"*p"+p')
614      expect([[
615        text
616        really unnamed
617        really unnamed]])
618      eq({ { 'really unnamed', '' }, 'V' }, eval("g:test_clip['+']"))
619      eq({ { 'really unnamed', '' }, 'V' }, eval("g:test_clip['*']"))
620
621      -- unnamedplus takes precedence when pasting
622      eq('+', eval('v:register'))
623      command("let g:test_clip['+'] = ['the plus','']")
624      command("let g:test_clip['*'] = ['the star','']")
625      feed('p')
626      expect([[
627        text
628        really unnamed
629        really unnamed
630        the plus]])
631    end)
632
633    it('is updated on global changes', function()
634      insert([[
635	text
636	match
637	match
638	text
639      ]])
640      command('g/match/d')
641      eq('match\n', eval('getreg("+")'))
642      feed('u')
643      eval('setreg("+", "---")')
644      command('g/test/')
645      feed('<esc>')
646      eq('---', eval('getreg("+")'))
647    end)
648  end)
649
650  it('sets v:register after startup', function()
651    reset()
652    eq('"', eval('v:register'))
653    reset('--cmd', 'set clipboard=unnamed')
654    eq('*', eval('v:register'))
655  end)
656
657  it('supports :put', function()
658    insert('a line')
659    command("let g:test_clip['*'] = ['some text']")
660    command("let g:test_clip['+'] = ['more', 'text', '']")
661    command(':put *')
662    expect([[
663    a line
664    some text]])
665    command(':put +')
666    expect([[
667    a line
668    some text
669    more
670    text]])
671  end)
672
673  it('supports "+ and "* in registers', function()
674    local screen = Screen.new(60, 10)
675    feed(":let g:test_clip['*'] = ['some', 'star data','']<cr>")
676    feed(":let g:test_clip['+'] = ['such', 'plus', 'stuff']<cr>")
677    feed(':registers<cr>')
678    screen:expect(
679      [[
680                                                                  |
681      {0:~                                                           }|*2
682      {4:                                                            }|
683      :registers                                                  |
684      {1:Type Name Content}                                           |
685        l  "*   some{2:^J}star data{2:^J}                                 |
686        c  "+   such{2:^J}plus{2:^J}stuff                                 |
687        c  ":   let g:test_clip['+'] = ['such', 'plus', 'stuff']  |
688      {3:Press ENTER or type command to continue}^                     |
689    ]],
690      {
691        [0] = { bold = true, foreground = Screen.colors.Blue },
692        [1] = { bold = true, foreground = Screen.colors.Fuchsia },
693        [2] = { foreground = Screen.colors.Blue },
694        [3] = { bold = true, foreground = Screen.colors.SeaGreen },
695        [4] = { bold = true, reverse = true },
696      }
697    )
698    feed('<cr>') -- clear out of Press ENTER screen
699  end)
700
701  it('can paste "* to the commandline', function()
702    insert('s/s/t/')
703    feed('gg"*y$:<c-r>*<cr>')
704    expect('t/s/t/')
705    command("let g:test_clip['*'] = ['s/s/u']")
706    feed(':<c-r>*<cr>')
707    expect('t/u/t/')
708  end)
709
710  it('supports :redir @*>', function()
711    command("let g:test_clip['*'] = ['stuff']")
712    command('redir @*>')
713    -- it is made empty
714    eq({ { '' }, 'v' }, eval("g:test_clip['*']"))
715    feed(':let g:test = doesnotexist<cr>')
716    feed('<cr>')
717    eq(
718      { {
719        '',
720        '',
721        'E121: Undefined variable: doesnotexist',
722      }, 'v' },
723      eval("g:test_clip['*']")
724    )
725    feed(':echo "Howdy!"<cr>')
726    eq({
727      {
728        '',
729        '',
730        'E121: Undefined variable: doesnotexist',
731        '',
732        'Howdy!',
733      },
734      'v',
735    }, eval("g:test_clip['*']"))
736  end)
737
738  it('handles middleclick correctly', function()
739    command('set mouse=a')
740
741    local screen = Screen.new(30, 5)
742    insert([[
743      the source
744      a target]])
745    feed('gg"*ywwyw')
746    -- clicking depends on the exact visual layout, so expect it:
747    screen:expect([[
748      the ^source                    |
749      a target                      |
750      {1:~                             }|*2
751                                    |
752    ]])
753
754    feed('<MiddleMouse><0,1>')
755    expect([[
756      the source
757      the a target]])
758
759    -- on error, fall back to unnamed register
760    command('let g:cliperror = 1')
761    feed('<MiddleMouse><6,1>')
762    expect([[
763      the source
764      the a sourcetarget]])
765  end)
766
767  it('setreg("*") with clipboard=unnamed #5646', function()
768    source([=[
769      function! Paste_without_yank(direction) range
770        let [reg_save,regtype_save] = [getreg('*'), getregtype('*')]
771        normal! gvp
772        call setreg('*', reg_save, regtype_save)
773      endfunction
774      xnoremap p :call Paste_without_yank('p')<CR>
775      set clipboard=unnamed
776    ]=])
777    insert('some words')
778    feed('gg0yiw')
779    feed('wviwp')
780    expect('some some')
781    eq('some', eval('getreg("*")'))
782  end)
783
784  it('does not fall back to unnamed register with getreg() #24257', function()
785    eval('setreg("", "wrong")')
786    command('let g:cliperror = 1')
787    eq('', eval('getreg("*")'))
788    eq('', eval('getreg("+")'))
789  end)
790end)