Luigit
repositories / dotfiles

dotfiles

bugabingas dorkfiles

owned by admin

neovim/tests/bugabinga/cmdline/position_spec.lua

Raw
describe('position.at_cursor', function()
  it('returns a table with row and col', function()
    local pos = require 'bugabinga.cmdline.position'
    local result = pos.at_cursor(40)
    assert.is_table(result)
    assert.is_number(result.row)
    assert.is_number(result.col)
  end)

  it('clamps col when width exceeds screen', function()
    vim.o.columns = 80
    vim.o.lines = 24
    local pos = require 'bugabinga.cmdline.position'
    local result = pos.at_cursor(100)
    assert.is_true(result.col <= 80)
  end)

  it('never returns negative row', function()
    local pos = require 'bugabinga.cmdline.position'
    for _ = 1, 10 do
      local result = pos.at_cursor(40)
      assert(result.row >= 0, 'row should never be negative')
    end
  end)
end)

describe('position.get_cmdline_anchor', function()
  before_each(function()
    package.loaded['bugabinga.cmdline.position'] = nil
  end)

  after_each(function()
    local pos = require 'bugabinga.cmdline.position'
    pos.set_cmdline_anchor(nil)
  end)

  it('returns nil by default', function()
    local pos = require 'bugabinga.cmdline.position'
    assert.is_nil(pos.get_cmdline_anchor())
  end)

  it('returns the anchor after being set', function()
    local pos = require 'bugabinga.cmdline.position'
    local anchor = { screenpos = { row = 10, col = 20 }, cursor = 5 }
    pos.set_cmdline_anchor(anchor)
    assert.equal(anchor, pos.get_cmdline_anchor())
  end)
end)

describe('position.set_cmdline_anchor', function()
  before_each(function()
    package.loaded['bugabinga.cmdline.position'] = nil
  end)

  after_each(function()
    local pos = require 'bugabinga.cmdline.position'
    pos.set_cmdline_anchor(nil)
  end)

  it('stores and retrieves anchor', function()
    local pos = require 'bugabinga.cmdline.position'
    local anchor = { screenpos = { row = 5, col = 10 }, cursor = 3 }
    pos.set_cmdline_anchor(anchor)
    local result = assert(pos.get_cmdline_anchor())
    assert.equal(5, result.screenpos.row)
    assert.equal(10, result.screenpos.col)
    assert.equal(3, result.cursor)
  end)
end)