robin/laufey

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

Justin M. KeyesMerge #40865 from justinmk/fixcif907614088

master
3.3 KiB101 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 command = n.command
7local clear, feed, feed_command = n.clear, n.feed, n.feed_command
8local exec = n.exec
9
10describe(':drop', function()
11  local screen
12
13  before_each(function()
14    clear()
15    screen = Screen.new(35, 10)
16    screen:set_default_attr_ids({
17      [0] = { bold = true, foreground = Screen.colors.Blue },
18      [1] = { bold = true, reverse = true },
19      [2] = { reverse = true },
20      [3] = { bold = true },
21    })
22    command('set nohidden laststatus=2 shortmess-=F')
23  end)
24
25  it('works like :e when called with only one window open', function()
26    feed_command('drop tmp1.vim')
27    screen:expect([[
28      ^                                   |
29      {0:~                                  }|*7
30      {1:tmp1.vim                           }|
31      "tmp1.vim" [New]                   |
32    ]])
33  end)
34
35  it('switches to an open window showing the buffer', function()
36    feed_command('edit tmp1')
37    feed_command('vsplit')
38    feed_command('edit tmp2')
39    feed_command('drop tmp1')
40    screen:expect([[
41                    │^                    |
42      {0:~             }│{0:~                   }|*7
43      {2:tmp2           }{1:tmp1                }|
44      "tmp1" [New]                       |
45    ]])
46  end)
47
48  it("splits off a new window when a buffer can't be abandoned", function()
49    feed_command('edit tmp1')
50    feed_command('vsplit')
51    feed_command('edit tmp2')
52    feed('iABC<esc>')
53    feed_command('drop tmp3')
54    screen:expect([[
55      ^                    │              |
56      {0:~                   }│{0:~             }|*3
57      {1:tmp3                }│{0:~             }|
58      ABC                 │{0:~             }|
59      {0:~                   }│{0:~             }|*2
60      {2:tmp2 [+]             tmp1          }|
61      "tmp3" [New]                       |
62    ]])
63  end)
64
65  -- oldtest: Test_drop_modified_file()
66  it('does not cause E37 with modified same file', function()
67    exec([[
68      edit Xdrop_modified.txt
69      call setline(1, 'The quick brown fox jumped over the lazy dogs')
70    ]])
71    feed_command('drop Xdrop_modified.txt')
72    screen:expect([[
73      ^The quick brown fox jumped over the|
74       lazy dogs                         |
75      {0:~                                  }|*6
76      {1:Xdrop_modified.txt [+]             }|
77      :drop Xdrop_modified.txt           |
78    ]])
79  end)
80
81  it('jumps to line number when passed +line', function()
82    exec([[
83      edit Xdrop_line.txt
84      call append(0, "I just miss doing art. Don't you?")
85      call append(1, "It is not so hard as we have supposed.")
86      call append(2, "We are propelled by disaster. We are moving swiftly.")
87    ]])
88    feed_command('drop +2 Xdrop_line.txt')
89    screen:expect([[
90      I just miss doing art. Don't you?  |
91      ^It is not so hard as we have suppos|
92      ed.                                |
93      We are propelled by disaster. We ar|
94      e moving swiftly.                  |
95                                         |
96      {0:~                                  }|*2
97      {1:Xdrop_line.txt [+]                 }|
98      :drop +2 Xdrop_line.txt            |
99    ]])
100  end)
101end)