Repository: neovim/neovim
File: test/functional/api/buffer_spec.lua (Lua)

Code before:
      command('mark v')
      eq({ 3, 0 }, api.nvim_buf_get_mark(0, 'v'))
    end)
  end)

  describe('nvim_buf_set_mark', function()
    it('works with buffer local marks', function()
      api.nvim_buf_set_lines(0, -1, -1, true, { 'a', 'bit of', 'text' })
      eq(true, api.nvim_buf_set_mark(0, 'z', 1, 1, {}))
      eq({ 1, 1 }, api.nvim_buf_get_mark(0, 'z'))
      eq({ 0, 1, 2, 0 }, fn.getpos("'z"))
    end)
    it('works with file/uppercase marks', function()
      api.nvim_buf_set_lines(0, -1, -1, true, { 'a', 'bit of', 'text' })
      eq(true, api.nvim_buf_set_mark(0, 'Z', 3, 2, {}))
      eq({ 3, 2 }, api.nvim_buf_get_mark(0, 'Z'))
      eq({ api.nvim_get_current_buf(), 3, 3, 0 }, fn.getpos("'Z"))
    end)
    it('fails when invalid marks names are used', function()
      eq(false, pcall(api.nvim_buf_set_mark, 0, '!', 1, 0, {}))
      eq(false, pcall(api.nvim_buf_set_mark, 0, 'fail', 1, 0, {}))
    end)
    it('fails when invalid buffer number is used', function()
      eq(false, pcall(api.nvim_buf_set_mark, 99, 'a', 1, 1, {}))
    end)
    it('nvim_buf_set_mark auto-loads unloaded buffer', function()
      local new_bufnr = fn.bufnr('set_mark', true)
      eq(false, api.nvim_buf_is_loaded(new_bufnr))
      eq(true, api.nvim_buf_set_mark(new_bufnr, 'A', 0, 0, {}))
      eq(true, api.nvim_buf_is_loaded(new_bufnr))
      eq({ 0, 0 }, api.nvim_buf_get_mark(new_bufnr, 'A'))
    end)
  end)

  describe('nvim_buf_del_mark', function()
    it('works with buffer local marks', function()
      api.nvim_buf_set_lines(0, -1, -1, true, { 'a', 'bit of', 'text' })
      api.nvim_buf_set_mark(0, 'z', 3, 1, {})
      eq(true, api.nvim_buf_del_mark(0, 'z'))
      eq({ 0, 0 }, api.nvim_buf_get_mark(0, 'z'))
    end)
    it('works with file/uppercase marks', function()
      api.nvim_buf_set_lines(0, -1, -1, true, { 'a', 'bit of', 'text' })
      api.nvim_buf_set_mark(0, 'Z', 3, 3, {})
      eq(true, api.nvim_buf_del_mark(0, 'Z'))
      eq({ 0, 0 }, api.nvim_buf_get_mark(0, 'Z'))
    end)
    it('returns false in marks not set in this buffer', function()
      local abuf = api.nvim_create_buf(false, true)
      api.nvim_buf_set_lines(abuf, -1, -1, true, { 'a', 'bit of', 'text' })
      api.nvim_buf_set_mark(abuf, 'A', 2, 2, {})

Review comment (suggestion):
```suggestion
    it('auto-loads unloaded buffer', function()
```

Code after:
      command('mark v')
      eq({ 3, 0 }, api.nvim_buf_get_mark(0, 'v'))
    end)
  end)

  describe('nvim_buf_set_mark', function()
    it('works with buffer local marks', function()
      api.nvim_buf_set_lines(0, -1, -1, true, { 'a', 'bit of', 'text' })
      eq(true, api.nvim_buf_set_mark(0, 'z', 1, 1, {}))
      eq({ 1, 1 }, api.nvim_buf_get_mark(0, 'z'))
      eq({ 0, 1, 2, 0 }, fn.getpos("'z"))
    end)
    it('works with file/uppercase marks', function()
      api.nvim_buf_set_lines(0, -1, -1, true, { 'a', 'bit of', 'text' })
      eq(true, api.nvim_buf_set_mark(0, 'Z', 3, 2, {}))
      eq({ 3, 2 }, api.nvim_buf_get_mark(0, 'Z'))
      eq({ api.nvim_get_current_buf(), 3, 3, 0 }, fn.getpos("'Z"))
    end)
    it('fails when invalid marks names are used', function()
      eq(false, pcall(api.nvim_buf_set_mark, 0, '!', 1, 0, {}))
      eq(false, pcall(api.nvim_buf_set_mark, 0, 'fail', 1, 0, {}))
    end)
    it('fails when invalid buffer number is used', function()
      eq(false, pcall(api.nvim_buf_set_mark, 99, 'a', 1, 1, {}))
    end)
    it('auto-loads unloaded buffer', function()
      local new_bufnr = fn.bufnr('set_mark', true)
      eq(false, api.nvim_buf_is_loaded(new_bufnr))
      eq(true, api.nvim_buf_set_mark(new_bufnr, 'A', 0, 0, {}))
      eq(true, api.nvim_buf_is_loaded(new_bufnr))
      eq({ 0, 0 }, api.nvim_buf_get_mark(new_bufnr, 'A'))
    end)
  end)

  describe('nvim_buf_del_mark', function()
    it('works with buffer local marks', function()
      api.nvim_buf_set_lines(0, -1, -1, true, { 'a', 'bit of', 'text' })
      api.nvim_buf_set_mark(0, 'z', 3, 1, {})
      eq(true, api.nvim_buf_del_mark(0, 'z'))
      eq({ 0, 0 }, api.nvim_buf_get_mark(0, 'z'))
    end)
    it('works with file/uppercase marks', function()
      api.nvim_buf_set_lines(0, -1, -1, true, { 'a', 'bit of', 'text' })
      api.nvim_buf_set_mark(0, 'Z', 3, 3, {})
      eq(true, api.nvim_buf_del_mark(0, 'Z'))
      eq({ 0, 0 }, api.nvim_buf_get_mark(0, 'Z'))
    end)
    it('returns false in marks not set in this buffer', function()
      local abuf = api.nvim_create_buf(false, true)
      api.nvim_buf_set_lines(abuf, -1, -1, true, { 'a', 'bit of', 'text' })
      api.nvim_buf_set_mark(abuf, 'A', 2, 2, {})