robin/laufey

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

robinmerge: 9a29622b3b00ddb601

master
26.8 KiB915 linesraw
1local t = require('test.testutil')
2local n = require('test.functional.testnvim')()
3
4local describe, it, before_each = t.describe, t.it, t.before_each
5local clear = n.clear
6local insert = n.insert
7local feed = n.feed
8local expect = n.expect
9local eq = t.eq
10local map = vim.tbl_map
11local filter = vim.tbl_filter
12local command = n.command
13local curbuf_contents = n.curbuf_contents
14local fn = n.fn
15local dedent = t.dedent
16
17local function reset()
18  command('bwipe! | new')
19  insert([[
20  Line of words 1
21  Line of words 2]])
22  command('goto 1')
23  feed('itest_string.<esc>u')
24  fn.setreg('a', 'test_stringa', 'V')
25  fn.setreg('b', 'test_stringb\ntest_stringb\ntest_stringb', 'b')
26  fn.setreg('"', 'test_string"', 'v')
27end
28
29-- We check the last inserted register ". in each of these tests because it is
30-- implemented completely differently in do_put().
31-- It is implemented differently so that control characters and imap'ped
32-- characters work in the same manner when pasted as when inserted.
33describe('put command', function()
34  clear()
35  before_each(reset)
36
37  local function visual_marks_zero()
38    for _, v in pairs(fn.getpos("'<")) do
39      if v ~= 0 then
40        return false
41      end
42    end
43    for _, v in pairs(fn.getpos("'>")) do
44      if v ~= 0 then
45        return false
46      end
47    end
48    return true
49  end
50
51  -- {{{ Where test definitions are run
52  local function run_test_variations(test_variations, extra_setup)
53    reset()
54    if extra_setup then
55      extra_setup()
56    end
57    local init_contents = curbuf_contents()
58    local init_cursorpos = fn.getcurpos()
59    local assert_no_change = function()
60      expect(init_contents)
61      eq(init_cursorpos, fn.getcurpos())
62    end
63
64    for _, test in pairs(test_variations) do
65      it(test.description, function()
66        if extra_setup then
67          extra_setup()
68        end
69        local orig_dotstr = fn.getreg('.')
70        t.ok(visual_marks_zero())
71        -- Make sure every test starts from the same conditions
72        assert_no_change()
73        local was_cli = test.test_action()
74        test.test_assertions(test.exception_table, false)
75        -- Undo puts the cursor and text back to before the change.
76        feed('u')
77        assert_no_change()
78
79        -- Should not have changed the ". register
80        -- If we paste the ". register with a count we can't avoid
81        -- changing this register, hence avoid this check.
82        if not test.exception_table.dot_reg_changed then
83          eq(orig_dotstr, fn.getreg('.'))
84        end
85
86        -- Doing something, undoing it, and then redoing it should
87        -- leave us in the same state as just doing it once.
88        -- For :ex actions we want '@:', for normal actions we want '.'
89
90        -- The '.' redo doesn't work for visual put so just exit if
91        -- it was tested.
92        -- We check that visual put was used by checking if the '< and
93        -- '> marks were changed.
94        if not visual_marks_zero() then
95          return
96        end
97
98        if was_cli then
99          feed('@:')
100        else
101          feed('.')
102        end
103
104        test.test_assertions(test.exception_table, true)
105      end)
106    end
107  end -- run_test_variations()
108  -- }}}
109
110  local function create_test_defs(
111    test_defs,
112    command_base,
113    command_creator, -- {{{
114    expect_base,
115    expect_creator
116  )
117    local rettab = {}
118    local exceptions
119    for _, v in pairs(test_defs) do
120      if v[4] then
121        exceptions = v[4]
122      else
123        exceptions = {}
124      end
125      table.insert(rettab, {
126        test_action = command_creator(command_base, v[1]),
127        test_assertions = expect_creator(expect_base, v[2]),
128        description = v[3],
129        exception_table = exceptions,
130      })
131    end
132    return rettab
133  end -- create_test_defs() }}}
134
135  local function find_cursor_position(expect_string) -- {{{
136    -- There must only be one occurrence of the character 'x' in
137    -- expect_string.
138    -- This function removes that occurrence, and returns the position that
139    -- it was in.
140    -- This returns the cursor position that would leave the 'x' in that
141    -- place if we feed 'ix<esc>' and the string existed before it.
142    for linenum, line in pairs(fn.split(expect_string, '\n', 1)) do
143      local column = line:find('x')
144      if column then
145        return { linenum, column }, expect_string:gsub('x', '')
146      end
147    end
148  end -- find_cursor_position() }}}
149
150  -- Action function creators {{{
151  local function create_p_action(test_map, substitution)
152    local temp_val = test_map:gsub('p', substitution)
153    return function()
154      feed(temp_val)
155      return false
156    end
157  end
158
159  local function create_put_action(command_base, substitution)
160    local temp_val = command_base:gsub('put', substitution)
161    return function()
162      feed(':' .. temp_val .. '<CR>')
163      return true
164    end
165  end
166  -- }}}
167
168  -- Expect function creator {{{
169  local function expect_creator(conversion_function, expect_base, conversion_table)
170    local temp_expect_string = conversion_function(expect_base, conversion_table)
171    local cursor_position, expect_string = find_cursor_position(temp_expect_string)
172    return function(exception_table, after_redo)
173      expect(expect_string)
174
175      -- Have to use getcurpos() instead of api.nvim_win_get_cursor(0) in
176      -- order to account for virtualedit.
177      -- We always want the curswant element in getcurpos(), which is
178      -- sometimes different to the column element in
179      -- api.nvim_win_get_cursor(0).
180      -- NOTE: The ".gp command leaves the cursor after the pasted text
181      -- when running, but does not when the command is redone with the
182      -- '.' command.
183      if not (exception_table.redo_position and after_redo) then
184        local actual_position = fn.getcurpos()
185        eq(cursor_position, { actual_position[2], actual_position[5] })
186      end
187    end
188  end -- expect_creator() }}}
189
190  -- Test definitions {{{
191  local function copy_def(def)
192    local rettab = { '', {}, '', nil }
193    rettab[1] = def[1]
194    for k, v in pairs(def[2]) do
195      rettab[2][k] = v
196    end
197    rettab[3] = def[3]
198    if def[4] then
199      rettab[4] = {}
200      for k, v in pairs(def[4]) do
201        rettab[4][k] = v
202      end
203    end
204    return rettab
205  end
206
207  local normal_command_defs = {
208    {
209      'p',
210      { cursor_after = false, put_backwards = false, dot_register = false },
211      'pastes after cursor with p',
212    },
213    {
214      'gp',
215      { cursor_after = true, put_backwards = false, dot_register = false },
216      'leaves cursor after text with gp',
217    },
218    {
219      '".p',
220      { cursor_after = false, put_backwards = false, dot_register = true },
221      'works with the ". register',
222    },
223    {
224      '".gp',
225      { cursor_after = true, put_backwards = false, dot_register = true },
226      'gp works with the ". register',
227      { redo_position = true },
228    },
229    {
230      'P',
231      { cursor_after = false, put_backwards = true, dot_register = false },
232      'pastes before cursor with P',
233    },
234    {
235      'gP',
236      { cursor_after = true, put_backwards = true, dot_register = false },
237      'gP pastes before cursor and leaves cursor after text',
238    },
239    {
240      '".P',
241      { cursor_after = false, put_backwards = true, dot_register = true },
242      'P works with ". register',
243    },
244    {
245      '".gP',
246      { cursor_after = true, put_backwards = true, dot_register = true },
247      'gP works with ". register',
248      { redo_position = true },
249    },
250  }
251
252  -- Add a definition applying a count for each definition above.
253  -- Could do this for each transformation (p -> P, p -> gp etc), but I think
254  -- it's neater this way (balance between being explicit and too verbose).
255  for i = 1, #normal_command_defs do
256    local cur = normal_command_defs[i]
257
258    -- Make modified copy of current definition that includes a count.
259    local newdef = copy_def(cur)
260    newdef[2].count = 2
261    cur[2].count = 1
262    newdef[1] = '2' .. newdef[1]
263    newdef[3] = 'double ' .. newdef[3]
264
265    if cur[2].dot_register then
266      if not cur[4] then
267        newdef[4] = {}
268      end
269      newdef[4].dot_reg_changed = true
270    end
271
272    normal_command_defs[#normal_command_defs + 1] = newdef
273  end
274
275  local ex_command_defs = {
276    {
277      'put',
278      { put_backwards = false, dot_register = false },
279      'pastes linewise forwards with :put',
280    },
281    {
282      'put!',
283      { put_backwards = true, dot_register = false },
284      'pastes linewise backwards with :put!',
285    },
286    {
287      'put .',
288      { put_backwards = false, dot_register = true },
289      'pastes linewise with the dot register',
290    },
291    {
292      'put! .',
293      { put_backwards = true, dot_register = true },
294      'pastes linewise backwards with the dot register',
295    },
296  }
297
298  local function non_dotdefs(def_table)
299    return filter(function(d)
300      return not d[2].dot_register
301    end, def_table)
302  end
303
304  -- }}}
305
306  -- Conversion functions {{{
307  local function convert_charwise(expect_base, conversion_table, virtualedit_end, visual_put)
308    expect_base = dedent(expect_base)
309    -- There is no difference between 'P' and 'p' when VIsual_active
310    if not visual_put then
311      if conversion_table.put_backwards then
312        -- Special case for virtualedit at the end of a line.
313        local replace_string
314        if not virtualedit_end then
315          replace_string = 'test_stringx"%1'
316        else
317          replace_string = 'test_stringx"'
318        end
319        expect_base = expect_base:gsub('(.)test_stringx"', replace_string)
320      end
321    end
322    if conversion_table.count > 1 then
323      local rep_string = 'test_string"'
324      local extra_puts = rep_string:rep(conversion_table.count - 1)
325      expect_base = expect_base:gsub('test_stringx"', extra_puts .. 'test_stringx"')
326    end
327    if conversion_table.cursor_after then
328      expect_base = expect_base:gsub('test_stringx"', 'test_string"x')
329    end
330    if conversion_table.dot_register then
331      expect_base = expect_base:gsub('(test_stringx?)"', '%1.')
332    end
333    return expect_base
334  end -- convert_charwise()
335
336  local function make_back(string)
337    local prev_line
338    local rettab = {}
339    local string_found = false
340    for _, line in pairs(fn.split(string, '\n', 1)) do
341      if line:find('test_string') then
342        string_found = true
343        table.insert(rettab, line)
344      else
345        if string_found then
346          if prev_line then
347            table.insert(rettab, prev_line)
348            prev_line = nil
349          end
350          table.insert(rettab, line)
351        else
352          table.insert(rettab, prev_line)
353          prev_line = line
354        end
355      end
356    end
357    -- In case there are no lines after the text that was put.
358    if prev_line and string_found then
359      table.insert(rettab, prev_line)
360    end
361    return table.concat(rettab, '\n')
362  end -- make_back()
363
364  local function convert_linewise(expect_base, conversion_table, _, use_a, indent)
365    expect_base = dedent(expect_base)
366    if conversion_table.put_backwards then
367      expect_base = make_back(expect_base)
368    end
369    local p_str = 'test_string"'
370    if use_a then
371      p_str = 'test_stringa'
372    end
373
374    if conversion_table.dot_register then
375      expect_base = expect_base:gsub('x' .. p_str, 'xtest_string.')
376      p_str = 'test_string.'
377    end
378
379    if conversion_table.cursor_after then
380      expect_base = expect_base:gsub('x' .. p_str .. '\n', p_str .. '\nx')
381    end
382
383    -- The 'indent' argument is only used here because a single put with an
384    -- indent doesn't require special handling. It doesn't require special
385    -- handling because the cursor is never put before the indent, hence
386    -- the modification of 'test_stringx"' gives the same overall answer as
387    -- modifying '    test_stringx"'.
388
389    -- Only happens when using normal mode command actions.
390    if conversion_table.count and conversion_table.count > 1 then
391      if not indent then
392        indent = ''
393      end
394      local rep_string = indent .. p_str .. '\n'
395      local extra_puts = rep_string:rep(conversion_table.count - 1)
396      local orig_string, new_string
397      if conversion_table.cursor_after then
398        orig_string = indent .. p_str .. '\nx'
399        new_string = extra_puts .. orig_string
400      else
401        orig_string = indent .. 'x' .. p_str .. '\n'
402        new_string = orig_string .. extra_puts
403      end
404      expect_base = expect_base:gsub(orig_string, new_string)
405    end
406    return expect_base
407  end
408
409  local function put_x_last(orig_line, p_str)
410    local prev_end, cur_end, cur_start = 0, 0, 0
411    while cur_start do
412      prev_end = cur_end
413      cur_start, cur_end = orig_line:find(p_str, prev_end)
414    end
415    -- Assume (because that is the only way I call it) that p_str matches
416    -- the pattern 'test_string.'
417    return orig_line:sub(1, prev_end - 1) .. 'x' .. orig_line:sub(prev_end)
418  end
419
420  local function convert_blockwise(
421    expect_base,
422    conversion_table,
423    visual,
424    use_b,
425    trailing_whitespace
426  )
427    expect_base = dedent(expect_base)
428    local p_str = 'test_string"'
429    if use_b then
430      p_str = 'test_stringb'
431    end
432
433    if conversion_table.dot_register then
434      expect_base = expect_base:gsub('(x?)' .. p_str, '%1test_string.')
435      -- Looks strange, but the dot is a special character in the pattern
436      -- and a literal character in the replacement.
437      expect_base = expect_base:gsub('test_stringx.', 'test_stringx.')
438      p_str = 'test_string.'
439    end
440
441    -- No difference between 'p' and 'P' in visual mode.
442    if not visual then
443      if conversion_table.put_backwards then
444        -- One for the line where the cursor is left, one for all other
445        -- lines.
446        expect_base = expect_base:gsub('([^x])' .. p_str, p_str .. '%1')
447        expect_base = expect_base:gsub('([^x])x' .. p_str, 'x' .. p_str .. '%1')
448        if not trailing_whitespace then
449          expect_base = expect_base:gsub(' \n', '\n')
450          expect_base = expect_base:gsub(' $', '')
451        end
452      end
453    end
454
455    if conversion_table.count and conversion_table.count > 1 then
456      local p_pattern = p_str:gsub('%.', '%%.')
457      expect_base = expect_base:gsub(p_pattern, p_str:rep(conversion_table.count))
458      expect_base =
459        expect_base:gsub('test_stringx([b".])', p_str:rep(conversion_table.count - 1) .. '%0')
460    end
461
462    if conversion_table.cursor_after then
463      if not visual then
464        local prev_line
465        local rettab = {}
466        local prev_in_block = false
467        for _, line in pairs(fn.split(expect_base, '\n', 1)) do
468          if line:find('test_string') then
469            if prev_line then
470              prev_line = prev_line:gsub('x', '')
471              table.insert(rettab, prev_line)
472            end
473            prev_line = line
474            prev_in_block = true
475          else
476            if prev_in_block then
477              prev_line = put_x_last(prev_line, p_str)
478              table.insert(rettab, prev_line)
479              prev_in_block = false
480            end
481            table.insert(rettab, line)
482          end
483        end
484        if prev_line and prev_in_block then
485          table.insert(rettab, put_x_last(prev_line, p_str))
486        end
487
488        expect_base = table.concat(rettab, '\n')
489      else
490        expect_base = expect_base:gsub('x(.)', '%1x')
491      end
492    end
493
494    return expect_base
495  end
496  -- }}}
497
498  -- Convenience functions {{{
499  local function run_normal_mode_tests(
500    test_string,
501    base_map,
502    extra_setup,
503    virtualedit_end,
504    selection_string
505  )
506    local function convert_closure(e, c)
507      return convert_charwise(e, c, virtualedit_end, selection_string)
508    end
509    local function expect_normal_creator(expect_base, conversion_table)
510      local test_expect = expect_creator(convert_closure, expect_base, conversion_table)
511      return function(exception_table, after_redo)
512        test_expect(exception_table, after_redo)
513        if selection_string then
514          if not conversion_table.put_backwards then
515            eq(selection_string, fn.getreg('"'))
516          end
517        else
518          eq('test_string"', fn.getreg('"'))
519        end
520      end
521    end
522    run_test_variations(
523      create_test_defs(
524        normal_command_defs,
525        base_map,
526        create_p_action,
527        test_string,
528        expect_normal_creator
529      ),
530      extra_setup
531    )
532  end -- run_normal_mode_tests()
533
534  local function convert_linewiseer(expect_base, conversion_table)
535    return expect_creator(convert_linewise, expect_base, conversion_table)
536  end
537
538  local function run_linewise_tests(expect_base, base_command, extra_setup)
539    local linewise_test_defs = create_test_defs(
540      ex_command_defs,
541      base_command,
542      create_put_action,
543      expect_base,
544      convert_linewiseer
545    )
546    run_test_variations(linewise_test_defs, extra_setup)
547  end -- run_linewise_tests()
548  -- }}}
549
550  -- Actual tests
551  describe('default pasting', function()
552    local expect_string = [[
553    Ltest_stringx"ine of words 1
554    Line of words 2]]
555    run_normal_mode_tests(expect_string, 'p')
556
557    run_linewise_tests(
558      [[
559      Line of words 1
560      xtest_string"
561      Line of words 2]],
562      'put'
563    )
564  end)
565
566  describe('linewise register', function()
567    -- put with 'p'
568    local local_ex_command_defs = non_dotdefs(normal_command_defs)
569    local base_expect_string = [[
570    Line of words 1
571    xtest_stringa
572    Line of words 2]]
573    local function local_convert_linewise(expect_base, conversion_table)
574      return convert_linewise(expect_base, conversion_table, nil, true)
575    end
576    local function expect_lineput(expect_base, conversion_table)
577      return expect_creator(local_convert_linewise, expect_base, conversion_table)
578    end
579    run_test_variations(
580      create_test_defs(
581        local_ex_command_defs,
582        '"ap',
583        create_p_action,
584        base_expect_string,
585        expect_lineput
586      )
587    )
588
589    -- put with :put
590    local linewise_put_defs = non_dotdefs(ex_command_defs)
591    base_expect_string = [[
592    Line of words 1
593    xtest_stringa
594    Line of words 2]]
595    run_test_variations(
596      create_test_defs(
597        linewise_put_defs,
598        'put a',
599        create_put_action,
600        base_expect_string,
601        convert_linewiseer
602      )
603    )
604  end)
605
606  describe('blockwise register', function()
607    local blockwise_put_defs = non_dotdefs(normal_command_defs)
608    local test_base = [[
609    Lxtest_stringbine of words 1
610    Ltest_stringbine of words 2
611     test_stringb]]
612
613    local function expect_block_creator(expect_base, conversion_table)
614      return expect_creator(function(e, c)
615        return convert_blockwise(e, c, nil, true)
616      end, expect_base, conversion_table)
617    end
618
619    run_test_variations(
620      create_test_defs(blockwise_put_defs, '"bp', create_p_action, test_base, expect_block_creator)
621    )
622  end)
623
624  it('adds correct indentation when put with [p and ]p', function()
625    feed('G>>"a]pix<esc>')
626    -- luacheck: ignore
627    expect([[
628    Line of words 1
629    	Line of words 2
630    	xtest_stringa]])
631    feed('uu"a[pix<esc>')
632    -- luacheck: ignore
633    expect([[
634    Line of words 1
635    	xtest_stringa
636    	Line of words 2]])
637  end)
638
639  describe('linewise paste with autoindent', function()
640    -- luacheck: ignore
641    run_linewise_tests(
642      [[
643        Line of words 1
644        	Line of words 2
645        xtest_string"]],
646      'put',
647      function()
648        fn.setline('$', '	Line of words 2')
649        -- Set curswant to '8' to be at the end of the tab character
650        -- This is where the cursor is put back after the 'u' command.
651        fn.setpos('.', { 0, 2, 1, 0, 8 })
652        command('set autoindent')
653      end
654    )
655  end)
656
657  describe('put inside tabs with virtualedit', function()
658    local test_string = [[
659    Line of words 1
660       test_stringx"     Line of words 2]]
661    run_normal_mode_tests(test_string, 'p', function()
662      fn.setline('$', '	Line of words 2')
663      command('setlocal virtualedit=all')
664      fn.setpos('.', { 0, 2, 1, 2, 3 })
665    end)
666  end)
667
668  describe('put after the line with virtualedit', function()
669    -- luacheck: ignore 621
670    local test_string = [[
671    Line of words 1  test_stringx"
672    	Line of words 2]]
673    run_normal_mode_tests(test_string, 'p', function()
674      fn.setline('$', '	Line of words 2')
675      command('setlocal virtualedit=all')
676      fn.setpos('.', { 0, 1, 16, 1, 17 })
677    end, true)
678  end)
679
680  describe('Visual put', function()
681    describe('basic put', function()
682      local test_string = [[
683      test_stringx" words 1
684      Line of words 2]]
685      run_normal_mode_tests(test_string, 'v2ep', nil, nil, 'Line of')
686    end)
687    describe('over trailing newline', function()
688      local test_string = 'Line of test_stringx"Line of words 2'
689      run_normal_mode_tests(test_string, 'v$p', function()
690        fn.setpos('.', { 0, 1, 9, 0, 9 })
691      end, nil, 'words 1\n')
692    end)
693    describe('linewise mode', function()
694      local test_string = [[
695      xtest_string"
696      Line of words 2]]
697      local function expect_vis_linewise(expect_base, conversion_table)
698        return expect_creator(function(e, c)
699          return convert_linewise(e, c, nil, nil)
700        end, expect_base, conversion_table)
701      end
702      run_test_variations(
703        create_test_defs(
704          normal_command_defs,
705          'Vp',
706          create_p_action,
707          test_string,
708          expect_vis_linewise
709        ),
710        function()
711          fn.setpos('.', { 0, 1, 1, 0, 1 })
712        end
713      )
714
715      describe('with whitespace at bol', function()
716        local function expect_vis_lineindented(expect_base, conversion_table)
717          local test_expect = expect_creator(function(e, c)
718            return convert_linewise(e, c, nil, nil, '    ')
719          end, expect_base, conversion_table)
720          return function(exception_table, after_redo)
721            test_expect(exception_table, after_redo)
722            if not conversion_table.put_backwards then
723              eq('Line of words 1\n', fn.getreg('"'))
724            end
725          end
726        end
727        local base_expect_string = [[
728            xtest_string"
729        Line of words 2]]
730        run_test_variations(
731          create_test_defs(
732            normal_command_defs,
733            'Vp',
734            create_p_action,
735            base_expect_string,
736            expect_vis_lineindented
737          ),
738          function()
739            feed('i    test_string.<esc>u')
740            fn.setreg('"', '    test_string"', 'v')
741          end
742        )
743      end)
744    end)
745
746    describe('blockwise visual mode', function()
747      local test_base = [[
748        test_stringx"e of words 1
749        test_string"e of words 2]]
750
751      local function expect_block_creator(expect_base, conversion_table)
752        local test_expect = expect_creator(function(e, c)
753          return convert_blockwise(e, c, true)
754        end, expect_base, conversion_table)
755        return function(e, c)
756          test_expect(e, c)
757          if not conversion_table.put_backwards then
758            eq('Lin\nLin', fn.getreg('"'))
759          end
760        end
761      end
762
763      local select_down_test_defs = create_test_defs(
764        normal_command_defs,
765        '<C-v>jllp',
766        create_p_action,
767        test_base,
768        expect_block_creator
769      )
770      run_test_variations(select_down_test_defs)
771
772      -- "." repeat of an upward visual block put applies at the restored cursor, so the put text
773      -- lands elsewhere: skip the position check after redo.
774      local undo_redo_no = map(function(table)
775        local rettab = copy_def(table)
776        if not rettab[4] then
777          rettab[4] = {}
778        end
779        rettab[4].redo_position = true
780        return rettab
781      end, normal_command_defs)
782
783      -- Selection direction doesn't matter
784      run_test_variations(
785        create_test_defs(
786          undo_redo_no,
787          '<C-v>kllp',
788          create_p_action,
789          test_base,
790          expect_block_creator
791        ),
792        function()
793          fn.setpos('.', { 0, 2, 1, 0, 1 })
794        end
795      )
796
797      describe('blockwise cursor after undo', function()
798        -- Undo and CTRL-R restore the pre-change cursor position, even for an upward selection
799        -- (the harness only covers "." redo, not CTRL-R).
800        local function assertion_creator(_, _)
801          return function(_, _)
802            feed('u')
803            -- Have to use feed('u') here to set curswant, because
804            -- ex_undo() doesn't do that.
805            eq({ 0, 2, 1, 0, 1 }, fn.getcurpos())
806            feed('<C-r>')
807            eq({ 0, 2, 1, 0, 1 }, fn.getcurpos())
808          end
809        end
810
811        run_test_variations(
812          create_test_defs(undo_redo_no, '<C-v>kllp', create_p_action, test_base, assertion_creator),
813          function()
814            fn.setpos('.', { 0, 2, 1, 0, 1 })
815          end
816        )
817      end)
818    end)
819
820    describe("with 'virtualedit'", function()
821      describe('splitting a tab character', function()
822        local base_expect_string = [[
823        Line of words 1
824          test_stringx"     Line of words 2]]
825        run_normal_mode_tests(base_expect_string, 'vp', function()
826          fn.setline('$', '	Line of words 2')
827          command('setlocal virtualedit=all')
828          fn.setpos('.', { 0, 2, 1, 2, 3 })
829        end, nil, ' ')
830      end)
831      describe('after end of line', function()
832        local base_expect_string = [[
833        Line of words 1  test_stringx"
834        Line of words 2]]
835        run_normal_mode_tests(base_expect_string, 'vp', function()
836          command('setlocal virtualedit=all')
837          fn.setpos('.', { 0, 1, 16, 2, 18 })
838        end, true, ' ')
839      end)
840    end)
841  end)
842
843  describe('. register special tests', function()
844    -- luacheck: ignore 621
845    before_each(reset)
846    it('applies control character actions', function()
847      feed('i<C-t><esc>u')
848      expect([[
849      Line of words 1
850      Line of words 2]])
851      feed('".p')
852      expect([[
853      	Line of words 1
854      Line of words 2]])
855      feed('u1go<C-v>j".p')
856      eq(
857        [[
858	ine of words 1
859	ine of words 2]],
860        curbuf_contents()
861      )
862    end)
863
864    -- Asserts whether `keys` makes Nvim beep.
865    local function bell_test(keys, should_ring)
866      local cmd = 'normal! ' .. keys
867      if should_ring then
868        eq(0, fn.assert_beeps(cmd))
869      else
870        eq(0, fn.assert_nobeep(cmd))
871      end
872    end
873
874    it('should not ring the bell with gp at end of line', function()
875      bell_test('$".gp')
876
877      -- Even if the last character is a multibyte character.
878      reset()
879      fn.setline(1, 'helloม')
880      bell_test('$".gp')
881    end)
882
883    it('should not ring the bell with gp and end of file', function()
884      fn.setpos('.', { 0, 2, 1, 0 })
885      bell_test('$vl".gp')
886    end)
887
888    it('should ring the bell when deleting if not appropriate', function()
889      t.skip(t.is_os('bsd'), 'crashes on freebsd')
890
891      command('goto 2')
892      feed('i<bs><esc>')
893      expect([[
894      ine of words 1
895      Line of words 2]])
896      bell_test('".P', true)
897    end)
898
899    it('should restore cursor position after undo of ".p', function()
900      local origpos = fn.getcurpos()
901      feed('".pu')
902      eq(origpos, fn.getcurpos())
903    end)
904
905    it("should be unaffected by 'autoindent' with V\".2p", function()
906      command('set autoindent')
907      feed('i test_string.<esc>u')
908      feed('V".2p')
909      expect([[
910       test_string.
911       test_string.
912      Line of words 2]])
913    end)
914  end)
915end)