blob: d0b68f731d88f4c13a5604d6f0f8c7c666e7e5ce [file] [log] [blame]
Bram Moolenaarddd1f912018-11-10 19:19:36 +01001" Test the ":move" command.
2
Christian Brabandteb380b92025-07-07 20:53:55 +02003source util/screendump.vim
Bram Moolenaar61fdbfa2023-02-04 13:57:55 +00004
Bram Moolenaarddd1f912018-11-10 19:19:36 +01005func Test_move()
6 enew!
7 call append(0, ['line 1', 'line 2', 'line 3'])
8 g /^$/ delete _
9 set nomodified
10
11 move .
12 call assert_equal(['line 1', 'line 2', 'line 3'], getline(1, 3))
13 call assert_false(&modified)
14
15 1,2move 0
16 call assert_equal(['line 1', 'line 2', 'line 3'], getline(1, 3))
17 call assert_false(&modified)
18
19 1,3move 3
20 call assert_equal(['line 1', 'line 2', 'line 3'], getline(1, 3))
21 call assert_false(&modified)
22
23 1move 2
24 call assert_equal(['line 2', 'line 1', 'line 3'], getline(1, 3))
25 call assert_true(&modified)
26 set nomodified
27
28 3move 0
29 call assert_equal(['line 3', 'line 2', 'line 1'], getline(1, 3))
30 call assert_true(&modified)
31 set nomodified
32
33 2,3move 0
34 call assert_equal(['line 2', 'line 1', 'line 3'], getline(1, 3))
35 call assert_true(&modified)
36 set nomodified
37
Bram Moolenaare2e40752020-09-04 21:18:46 +020038 call assert_fails('1,2move 1', 'E134:')
39 call assert_fails('2,3move 2', 'E134:')
Bram Moolenaar5d98dc22020-01-29 21:57:34 +010040 call assert_fails("move -100", 'E16:')
41 call assert_fails("move +100", 'E16:')
42 call assert_fails('move', 'E16:')
Bram Moolenaarbc2b71d2020-02-17 21:33:30 +010043 call assert_fails("move 'r", 'E20:')
Bram Moolenaarddd1f912018-11-10 19:19:36 +010044
45 %bwipeout!
46endfunc
Bram Moolenaar5d98dc22020-01-29 21:57:34 +010047
Bram Moolenaar61fdbfa2023-02-04 13:57:55 +000048func Test_move_undo()
Drew Vogelea67ba72025-05-07 22:05:17 +020049 CheckScreendump
Bram Moolenaar61fdbfa2023-02-04 13:57:55 +000050 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