robin/laufey

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

Justin M. KeyesMerge #40865 from justinmk/fixcif907614088

master
4.0 KiB121 linesraw
1local n = require('test.functional.testnvim')()
2local t = require('test.testutil')
3local Screen = require('test.functional.ui.screen')
4
5local describe, it, before_each = t.describe, t.it, t.before_each
6local clear = n.clear
7local command = n.command
8local expect = n.expect
9local feed = n.feed
10local sleep = vim.uv.sleep
11
12before_each(clear)
13
14describe('edit', function()
15  -- oldtest: Test_autoindent_remove_indent()
16  it('autoindent removes indent when Insert mode is stopped', function()
17    command('set autoindent')
18    -- leaving insert mode in a new line with indent added by autoindent, should
19    -- remove the indent.
20    feed('i<Tab>foo<CR><Esc>')
21    -- Need to delay for sometime, otherwise the code in input.c will not be
22    -- exercised.
23    sleep(50)
24    -- when a line is wrapped and the cursor is at the start of the second line,
25    -- leaving insert mode, should move the cursor back to the first line.
26    feed('o' .. ('x'):rep(20) .. '<Esc>')
27    -- Need to delay for sometime, otherwise the code in input.c will not be
28    -- exercised.
29    sleep(50)
30    expect('\tfoo\n\n' .. ('x'):rep(20))
31  end)
32
33  -- oldtest: Test_edit_insert_reg()
34  it('inserting a register using CTRL-R', function()
35    local screen = Screen.new(10, 6)
36    feed('a<C-R>')
37    screen:expect([[
38      {18:^"}           |
39      {1:~           }|*4
40      {5:-- INSERT --}|
41    ]])
42    feed('=')
43    screen:expect([[
44      {18:"}           |
45      {1:~           }|*4
46      =^           |
47    ]])
48    feed([['r'<CR><Esc>]])
49    expect('r')
50    -- Test for inserting null and empty list
51    feed('a<C-R>=v:_null_list<CR><Esc>')
52    feed('a<C-R>=[]<CR><Esc>')
53    expect('r')
54  end)
55
56  -- oldtest: Test_edit_ctrl_r_failed()
57  it('positioning cursor after CTRL-R expression failed', function()
58    local screen = Screen.new(60, 6)
59
60    feed('i<C-R>')
61    screen:expect([[
62      {18:^"}                                                           |
63      {1:~                                                           }|*4
64      {5:-- INSERT --}                                                |
65    ]])
66    feed('=0z')
67    screen:expect([[
68      {18:"}                                                           |
69      {1:~                                                           }|*4
70      ={26:0}{9:z}^                                                         |
71    ]])
72    -- trying to insert a blob produces an error
73    feed('<CR>')
74    screen:expect([[
75      {18:"}                                                           |
76      {1:~                                                           }|
77      {3:                                                            }|
78      ={26:0}{9:z}                                                         |
79      {9:E976: Using a Blob as a String}                              |
80      {6:Press ENTER or type command to continue}^                     |
81    ]])
82
83    feed(':')
84    screen:expect([[
85      :^                                                           |
86      {1:~                                                           }|*4
87      {5:-- INSERT --}                                                |
88    ]])
89    -- ending Insert mode should put the cursor back on the ':'
90    feed('<Esc>')
91    screen:expect([[
92      ^:                                                           |
93      {1:~                                                           }|*4
94                                                                  |
95    ]])
96  end)
97
98  -- oldtest: Test_edit_CAR()
99  it('Enter inserts newline with pum at original text after adding leader', function()
100    local screen = Screen.new(10, 6)
101    command('set cot=menu,menuone,noselect')
102    feed('Shello hero<CR>h<C-X><C-N>e')
103    screen:expect([[
104      hello hero  |
105      he^          |
106      {4:hello       }|
107      {4:hero        }|
108      {1:~           }|
109      {5:--}          |
110    ]])
111
112    feed('<CR>')
113    screen:expect([[
114      hello hero  |
115      he          |
116      ^            |
117      {1:~           }|*2
118      {5:-- INSERT --}|
119    ]])
120  end)
121end)