robin/laufey

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

Justin M. KeyesMerge #40865 from justinmk/fixcif907614088

master
1.8 KiB64 linesraw
1local t = require('test.testutil')
2local n = require('test.functional.testnvim')()
3
4local describe, it, before_each = t.describe, t.it, t.before_each
5local setpos = n.fn.setpos
6local getpos = n.fn.getpos
7local insert = n.insert
8local clear = n.clear
9local command = n.command
10local eval = n.eval
11local eq = t.eq
12
13describe('setpos() function', function()
14  before_each(function()
15    clear()
16    insert([[
17    First line of text
18    Second line of text
19    Third line of text]])
20    command('new')
21    insert([[
22    Line of text 1
23    Line of text 2
24    Line of text 3]])
25  end)
26  it('can set the current cursor position', function()
27    setpos('.', { 0, 2, 1, 0 })
28    eq({ 0, 2, 1, 0 }, getpos('.'))
29    setpos('.', { 2, 1, 1, 0 })
30    eq({ 0, 1, 1, 0 }, getpos('.'))
31    command('call setpos(".", [1, 1, 1, 0])')
32  end)
33  it('can set lowercase marks in the current buffer', function()
34    setpos("'d", { 0, 2, 1, 0 })
35    eq({ 0, 2, 1, 0 }, getpos("'d"))
36    command('undo')
37    command('call setpos("\'d", [2, 3, 1, 0])')
38    eq({ 0, 3, 1, 0 }, getpos("'d"))
39  end)
40  it('can set lowercase marks in other buffers', function()
41    local retval = setpos("'d", { 1, 2, 1, 0 })
42    eq(0, retval)
43    setpos("'d", { 1, 2, 1, 0 })
44    eq({ 0, 0, 0, 0 }, getpos("'d"))
45    command('wincmd w')
46    eq(1, eval('bufnr("%")'))
47    eq({ 0, 2, 1, 0 }, getpos("'d"))
48  end)
49  it("fails when setting a mark in a buffer that doesn't exist", function()
50    local retval = setpos("'d", { 3, 2, 1, 0 })
51    eq(-1, retval)
52    eq({ 0, 0, 0, 0 }, getpos("'d"))
53    retval = setpos("'D", { 3, 2, 1, 0 })
54    eq(-1, retval)
55    eq({ 0, 0, 0, 0 }, getpos("'D"))
56  end)
57  it('can set uppercase marks', function()
58    setpos("'D", { 2, 2, 3, 0 })
59    eq({ 2, 2, 3, 0 }, getpos("'D"))
60    -- Can set a mark in another buffer
61    setpos("'D", { 1, 2, 2, 0 })
62    eq({ 1, 2, 2, 0 }, getpos("'D"))
63  end)
64end)