setpos_spec.lua (1873B)
1 local t = require('test.testutil') 2 local n = require('test.functional.testnvim')() 3 4 local setpos = n.fn.setpos 5 local getpos = n.fn.getpos 6 local insert = n.insert 7 local clear = n.clear 8 local command = n.command 9 local eval = n.eval 10 local eq = t.eq 11 local exc_exec = n.exc_exec 12 13 describe('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 local ret = exc_exec('call setpos(".", [1, 1, 1, 0])') 32 eq(0, ret) 33 end) 34 it('can set lowercase marks in the current buffer', function() 35 setpos("'d", { 0, 2, 1, 0 }) 36 eq({ 0, 2, 1, 0 }, getpos("'d")) 37 command('undo') 38 command('call setpos("\'d", [2, 3, 1, 0])') 39 eq({ 0, 3, 1, 0 }, getpos("'d")) 40 end) 41 it('can set lowercase marks in other buffers', function() 42 local retval = setpos("'d", { 1, 2, 1, 0 }) 43 eq(0, retval) 44 setpos("'d", { 1, 2, 1, 0 }) 45 eq({ 0, 0, 0, 0 }, getpos("'d")) 46 command('wincmd w') 47 eq(1, eval('bufnr("%")')) 48 eq({ 0, 2, 1, 0 }, getpos("'d")) 49 end) 50 it("fails when setting a mark in a buffer that doesn't exist", function() 51 local retval = setpos("'d", { 3, 2, 1, 0 }) 52 eq(-1, retval) 53 eq({ 0, 0, 0, 0 }, getpos("'d")) 54 retval = setpos("'D", { 3, 2, 1, 0 }) 55 eq(-1, retval) 56 eq({ 0, 0, 0, 0 }, getpos("'D")) 57 end) 58 it('can set uppercase marks', function() 59 setpos("'D", { 2, 2, 3, 0 }) 60 eq({ 2, 2, 3, 0 }, getpos("'D")) 61 -- Can set a mark in another buffer 62 setpos("'D", { 1, 2, 2, 0 }) 63 eq({ 1, 2, 2, 0 }, getpos("'D")) 64 end) 65 end)