Repository: neovim/neovim
File: test/functional/ui/float_spec.lua (Lua)

Code before:

  it('no crash with relative="win" after %bdelete #30569', function()
    exec([[
      botright vsplit
      %bdelete
    ]])
    api.nvim_open_win(0, false, { relative = 'win', win = 0, row = 0, col = 5, width = 5, height = 5 })
    assert_alive()
  end)

  describe('with only one tabpage,', function()
    local float_opts = { relative = 'editor', row = 1, col = 1, width = 1, height = 1 }
    local old_buf, old_win
    before_each(function()
      insert('foo')
      old_buf = curbuf()
      old_win = curwin()
    end)
    describe('closing the last non-floating window gives E444', function()
      before_each(function()
        api.nvim_open_win(old_buf, true, float_opts)
      end)
      it('if called from non-floating window', function()
        api.nvim_set_current_win(old_win)
        eq('Vim:E444: Cannot close last window', pcall_err(api.nvim_win_close, old_win, false))

        -- Start with many tab pages, but make autocommands from closing floats leave us with just
        -- one (where we're now the last window).
        command('tabnew | autocmd WinClosed * ++once tabonly')
        api.nvim_open_win(0, false, float_opts)
        eq('Vim:E444: Cannot close last window', pcall_err(api.nvim_win_close, 0, true))
      end)
      it('if called from floating window', function()
        eq('Vim:E444: Cannot close last window', pcall_err(api.nvim_win_close, old_win, false))
      end)
    end)
    describe("deleting the last non-floating window's buffer", function()
      describe('leaves one window with an empty buffer when there is only one buffer', function()
        local same_buf_float
        before_each(function()
          same_buf_float = api.nvim_open_win(old_buf, false, float_opts)
        end)
        after_each(function()
          eq(old_win, curwin())
          expect('')
          eq(1, #api.nvim_list_wins())
        end)
        it('if called from non-floating window', function()
          api.nvim_buf_delete(old_buf, { force = true })
        end)
        it('if called from floating window', function()

Review comment (suggestion):
There are hardly any blank lines in this block. Adding a blank line here seem a bit inconsistent.
```suggestion
```

Code after:

  it('no crash with relative="win" after %bdelete #30569', function()
    exec([[
      botright vsplit
      %bdelete
    ]])
    api.nvim_open_win(0, false, { relative = 'win', win = 0, row = 0, col = 5, width = 5, height = 5 })
    assert_alive()
  end)

  describe('with only one tabpage,', function()
    local float_opts = { relative = 'editor', row = 1, col = 1, width = 1, height = 1 }
    local old_buf, old_win
    before_each(function()
      insert('foo')
      old_buf = curbuf()
      old_win = curwin()
    end)
    describe('closing the last non-floating window gives E444', function()
      before_each(function()
        api.nvim_open_win(old_buf, true, float_opts)
      end)
      it('if called from non-floating window', function()
        api.nvim_set_current_win(old_win)
        eq('Vim:E444: Cannot close last window', pcall_err(api.nvim_win_close, old_win, false))
        -- Start with many tab pages, but make autocommands from closing floats leave us with just
        -- one (where we're now the last window).
        command('tabnew | autocmd WinClosed * ++once tabonly')
        api.nvim_open_win(0, false, float_opts)
        eq('Vim:E444: Cannot close last window', pcall_err(api.nvim_win_close, 0, true))
      end)
      it('if called from floating window', function()
        eq('Vim:E444: Cannot close last window', pcall_err(api.nvim_win_close, old_win, false))
      end)
    end)
    describe("deleting the last non-floating window's buffer", function()
      describe('leaves one window with an empty buffer when there is only one buffer', function()
        local same_buf_float
        before_each(function()
          same_buf_float = api.nvim_open_win(old_buf, false, float_opts)
        end)
        after_each(function()
          eq(old_win, curwin())
          expect('')
          eq(1, #api.nvim_list_wins())
        end)
        it('if called from non-floating window', function()
          api.nvim_buf_delete(old_buf, { force = true })
        end)
        it('if called from floating window', function()
          api.nvim_set_current_win(same_buf_float)