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

Code before:
    -- Unless it is the current window.
    api.nvim_set_current_win(win)
    eq(3, fn.winnr('$'))
    eq(3, fn.winnr())
    eq(3, fn.win_id2win(win))
    eq(3, fn.getwininfo(win)[1].winnr)
    eq({ 2, 3 }, fn.win_id2tabwin(win))
    eq(3, fn.tabpagewinnr(2, '$'))
    eq(3, fn.tabpagewinnr(2))
    eq(win, fn.win_getid(3))
    eq(win, fn.win_getid(3, 2))
    eq(3, fn.bufwinnr(float_buf))
    matches('3resize', fn.winrestcmd())

    -- When switching tabpages it should still have a winnr, as it's current in the other tabpage.
    command('tabfirst')
    eq({ 2, 3 }, fn.win_id2tabwin(win))
    eq(3, fn.getwininfo(win)[1].winnr)
    eq(win, fn.win_getid(3, 2))
    eq(3, fn.tabpagewinnr(2, '$'))
    eq(3, fn.tabpagewinnr(2))

    -- ...but not if it's non-current in that tabpage.
    api.nvim_tabpage_set_win(tp, split_win)
    eq({ 0, 0 }, fn.win_id2tabwin(win))
    eq(0, fn.getwininfo(win)[1].winnr)
    eq(0, fn.win_getid(3, 2))
    eq(2, fn.tabpagewinnr(2, '$'))
    eq(1, fn.tabpagewinnr(2))
  end)

  it('no crash for unallocated relative window grid', function()
    local win = api.nvim_open_win(0, false, { relative = 'editor', row = 0, col = 0, height = 1, width = 1 })
    exec_lua(function()
      vim.api.nvim_create_autocmd('CmdwinEnter', {
        callback = function()
          vim.api.nvim_win_set_config(win, { relative = 'win', win = 0, row = 0, col = 0 })
          vim.api.nvim__redraw({ flush = true })
        end,
      })
    end)
    feed('q:')
    assert_alive()
  end)

  it("no error for zero height with 'winminheight'", function()
    local win = api.nvim_open_win(0, false, { relative = 'editor', row = 0, col = 0, height = 1, width = 1 })
    api.nvim_set_option_value('winminheight', 0, {})
    api.nvim_win_set_height(win, 0)
    api.nvim_win_set_config(win, api.nvim_win_get_config(win))
  end)

Review comment (suggestion):
Maybe this should return `[tp, 0]` instead, but that might be odd (and it'd have to be documented).

(Eh, I guess `getwininfo` does that now anyway, so maybe it should...)

Code after:

    -- Unless it is the current window.
    api.nvim_set_current_win(win)
    eq(3, fn.winnr('$'))
    eq(3, fn.winnr())
    eq(3, fn.win_id2win(win))
    eq(3, fn.getwininfo(win)[1].winnr)
    eq({ 2, 3 }, fn.win_id2tabwin(win))
    eq(3, fn.tabpagewinnr(2, '$'))
    eq(3, fn.tabpagewinnr(2))
    eq(win, fn.win_getid(3))
    eq(win, fn.win_getid(3, 2))
    eq(3, fn.bufwinnr(float_buf))
    matches('3resize', fn.winrestcmd())

    -- When switching tabpages it should still have a winnr, as it's current in the other tabpage.
    command('tabfirst')
    eq({ 2, 3 }, fn.win_id2tabwin(win))
    eq(3, fn.getwininfo(win)[1].winnr)
    eq(win, fn.win_getid(3, 2))
    eq(3, fn.tabpagewinnr(2, '$'))
    eq(3, fn.tabpagewinnr(2))

    -- ...but not if it's non-current in that tabpage.
    api.nvim_tabpage_set_win(tp, split_win)
    eq({ 0, 0 }, fn.win_id2tabwin(win))
    eq(0, fn.getwininfo(win)[1].winnr)
    eq(0, fn.win_getid(3, 2))
    eq(2, fn.tabpagewinnr(2, '$'))
    eq(1, fn.tabpagewinnr(2))
  end)

  it('no crash for unallocated relative window grid', function()
    local win = api.nvim_open_win(0, false, { relative = 'editor', row = 0, col = 0, height = 1, width = 1 })
    exec_lua(function()
      vim.api.nvim_create_autocmd('CmdwinEnter', {
        callback = function()
          vim.api.nvim_win_set_config(win, { relative = 'win', win = 0, row = 0, col = 0 })
          vim.api.nvim__redraw({ flush = true })
        end,
      })
    end)
    feed('q:')
    assert_alive()
  end)

  it("no error for zero height with 'winminheight'", function()
    local win = api.nvim_open_win(0, false, { relative = 'editor', row = 0, col = 0, height = 1, width = 1 })
    api.nvim_set_option_value('winminheight', 0, {})
    api.nvim_win_set_height(win, 0)
    api.nvim_win_set_config(win, api.nvim_win_get_config(win))