blob: 0412097541b163876eadba3a3f3c16da41ed75c5 [file] [log] [blame]
Bram Moolenaarddd1f912018-11-10 19:19:36 +01001" Test the ":move" command.
2
Bram Moolenaar61fdbfa2023-02-04 13:57:55 +00003source check.vim
4source screendump.vim
5
Bram Moolenaarddd1f912018-11-10 19:19:36 +01006func Test_move()
7 enew!
8 call append(0, ['line 1', 'line 2', 'line 3'])
9 g /^$/ delete _
10 set nomodified
11
12 move .
13 call assert_equal(['line 1', 'line 2', 'line 3'], getline(1, 3))
14 call assert_false(&modified)
15
16 1,2move 0
17 call assert_equal(['line 1', 'line 2', 'line 3'], getline(1, 3))
18 call assert_false(&modified)
19
20 1,3move 3
21 call assert_equal(['line 1', 'line 2', 'line 3'], getline(1, 3))
22 call assert_false(&modified)
23
24 1move 2
25 call assert_equal(['line 2', 'line 1', 'line 3'], getline(1, 3))
26 call assert_true(&modified)
27 set nomodified
28
29 3move 0
30 call assert_equal(['line 3', 'line 2', 'line 1'], getline(1, 3))
31 call assert_true(&modified)
32 set nomodified
33
34 2,3move 0
35 call assert_equal(['line 2', 'line 1', 'line 3'], getline(1, 3))
36 call assert_true(&modified)
37 set nomodified
38
Bram Moolenaare2e40752020-09-04 21:18:46 +020039 call assert_fails('1,2move 1', 'E134:')
40 call assert_fails('2,3move 2', 'E134:')
Bram Moolenaar5d98dc22020-01-29 21:57:34 +010041 call assert_fails("move -100", 'E16:')
42 call assert_fails("move +100", 'E16:')
43 call assert_fails('move', 'E16:')
Bram Moolenaarbc2b71d2020-02-17 21:33:30 +010044 call assert_fails("move 'r", 'E20:')
Bram Moolenaarddd1f912018-11-10 19:19:36 +010045
46 %bwipeout!
47endfunc
Bram Moolenaar5d98dc22020-01-29 21:57:34 +010048
Bram Moolenaar61fdbfa2023-02-04 13:57:55 +000049func Test_move_undo()
50 CheckRunVimInTerminal
51
52 let lines =<< trim END
53 call setline(1, ['First', 'Second', 'Third', 'Fourth'])
54 END
55 call writefile(lines, 'Xtest_move_undo.vim', 'D')
56 let buf = RunVimInTerminal('-S Xtest_move_undo.vim', #{rows: 10, cols: 60, statusoff: 2})
57
58 call term_sendkeys(buf, "gg:move +1\<CR>")
59 call VerifyScreenDump(buf, 'Test_move_undo_1', {})
60
61 " here the display would show the last few lines scrolled down
62 call term_sendkeys(buf, "u")
63 call term_sendkeys(buf, ":\<Esc>")
64 call VerifyScreenDump(buf, 'Test_move_undo_2', {})
65
66 call StopVimInTerminal(buf)
67endfunc
68
69
Bram Moolenaar5d98dc22020-01-29 21:57:34 +010070" vim: shiftwidth=2 sts=2 expandtab