2015-07-18 11:36:43 -07:00
|
|
|
-- Test for various eval features.
|
|
|
|
|
2024-04-20 08:44:13 -07:00
|
|
|
local t = require('test.testutil')
|
|
|
|
local n = require('test.functional.testnvim')()
|
|
|
|
|
|
|
|
local assert_alive = n.assert_alive
|
|
|
|
local feed, insert, source = n.feed, n.insert, n.source
|
|
|
|
local clear, command, expect = n.clear, n.command, n.expect
|
|
|
|
local eq, eval, write_file = t.eq, n.eval, t.write_file
|
|
|
|
local poke_eventloop = n.poke_eventloop
|
|
|
|
local exc_exec = n.exc_exec
|
2024-04-08 02:03:20 -07:00
|
|
|
local dedent = t.dedent
|
2015-07-18 11:36:43 -07:00
|
|
|
|
2016-01-26 03:28:19 -07:00
|
|
|
describe('eval', function()
|
2015-07-18 18:47:29 -07:00
|
|
|
setup(function()
|
2015-07-19 03:49:47 -07:00
|
|
|
write_file(
|
|
|
|
'test_eval_setup.vim',
|
|
|
|
[[
|
2015-07-18 11:36:43 -07:00
|
|
|
set noswapfile
|
|
|
|
lang C
|
2015-07-18 18:47:29 -07:00
|
|
|
|
2016-01-27 04:12:50 -07:00
|
|
|
fun AppendRegContents(reg)
|
2016-01-28 22:19:41 -07:00
|
|
|
call AppendRegParts(a:reg, getregtype(a:reg), getreg(a:reg), string(getreg(a:reg, 0, 1)), getreg(a:reg, 1), string(getreg(a:reg, 1, 1)))
|
2015-07-18 11:36:43 -07:00
|
|
|
endfun
|
2015-07-18 18:47:29 -07:00
|
|
|
|
2016-01-27 04:12:50 -07:00
|
|
|
fun AppendRegParts(reg, type, cont, strcont, cont1, strcont1)
|
2016-01-28 22:19:41 -07:00
|
|
|
call append('$', printf('%s: type %s; value: %s (%s), expr: %s (%s)', a:reg, a:type, a:cont, a:strcont, a:cont1, a:strcont1))
|
2015-07-18 11:36:43 -07:00
|
|
|
endfun
|
2015-07-18 18:47:29 -07:00
|
|
|
|
2015-07-18 11:36:43 -07:00
|
|
|
command -nargs=? AR :call AppendRegContents(<q-args>)
|
2015-07-18 18:47:29 -07:00
|
|
|
|
2015-07-18 11:36:43 -07:00
|
|
|
fun SetReg(...)
|
|
|
|
call call('setreg', a:000)
|
|
|
|
call append('$', printf('{{{2 setreg(%s)', string(a:000)[1:-2]))
|
|
|
|
call AppendRegContents(a:1)
|
|
|
|
if a:1 isnot# '='
|
|
|
|
execute "silent normal! Go==\n==\e\"".a:1."P"
|
|
|
|
endif
|
|
|
|
endfun
|
2015-07-19 03:49:47 -07:00
|
|
|
]]
|
|
|
|
)
|
|
|
|
end)
|
2022-03-23 03:58:47 -07:00
|
|
|
before_each(clear)
|
2015-07-19 03:49:47 -07:00
|
|
|
teardown(function()
|
|
|
|
os.remove('test_eval_setup.vim')
|
|
|
|
end)
|
2015-07-18 18:47:29 -07:00
|
|
|
|
2016-01-26 03:28:19 -07:00
|
|
|
it(':let', function()
|
2017-04-08 14:12:26 -07:00
|
|
|
command('so test_eval_setup.vim')
|
|
|
|
command([[let @" = 'abc']])
|
|
|
|
command('AR "')
|
|
|
|
command([[let @" = "abc\n"]])
|
2015-07-18 18:47:29 -07:00
|
|
|
source('AR "')
|
2022-04-25 01:50:50 -07:00
|
|
|
command([[let @" = "abc\<C-m>"]])
|
2017-04-08 14:12:26 -07:00
|
|
|
command('AR "')
|
|
|
|
command([[let @= = '"abc"']])
|
|
|
|
command('AR =')
|
2015-07-18 18:47:29 -07:00
|
|
|
expect([[
|
2017-04-08 14:12:26 -07:00
|
|
|
|
2015-07-18 18:47:29 -07:00
|
|
|
": type v; value: abc (['abc']), expr: abc (['abc'])
|
2016-03-06 15:48:36 -07:00
|
|
|
": type V; value: abc]] .. "\000 (['abc']), expr: abc\000" .. [[ (['abc'])
|
|
|
|
": type V; value: abc]] .. "\r\000 (['abc\r']), expr: abc\r\000 (['abc\r" .. [['])
|
2015-07-18 18:47:29 -07:00
|
|
|
=: type v; value: abc (['abc']), expr: "abc" (['"abc"'])]])
|
2015-07-19 03:49:47 -07:00
|
|
|
end)
|
2015-07-18 18:47:29 -07:00
|
|
|
|
2015-07-19 03:49:47 -07:00
|
|
|
it('basic setreg() tests', function()
|
2017-04-08 14:12:26 -07:00
|
|
|
command('so test_eval_setup.vim')
|
2015-07-19 03:49:47 -07:00
|
|
|
insert('{{{1 Basic setreg tests')
|
2017-04-08 14:12:26 -07:00
|
|
|
command([[call SetReg('a', 'abcA', 'c')]])
|
|
|
|
command([[call SetReg('b', 'abcB', 'v')]])
|
|
|
|
command([[call SetReg('c', 'abcC', 'l')]])
|
|
|
|
command([[call SetReg('d', 'abcD', 'V')]])
|
|
|
|
command([[call SetReg('e', 'abcE', 'b')]])
|
|
|
|
command([[call SetReg('f', 'abcF', "\<C-v>")]])
|
|
|
|
command([[call SetReg('g', 'abcG', 'b10')]])
|
|
|
|
command([[call SetReg('h', 'abcH', "\<C-v>10")]])
|
|
|
|
command([[call SetReg('I', 'abcI')]])
|
2015-07-18 18:47:29 -07:00
|
|
|
|
2015-07-19 03:49:47 -07:00
|
|
|
feed('Go{{{1 Appending single lines with setreg()<esc>')
|
2020-10-19 11:17:51 -07:00
|
|
|
poke_eventloop()
|
2017-04-08 14:12:26 -07:00
|
|
|
command([[call SetReg('A', 'abcAc', 'c')]])
|
|
|
|
command([[call SetReg('A', 'abcAl', 'l')]])
|
|
|
|
command([[call SetReg('A', 'abcAc2','c')]])
|
|
|
|
command([[call SetReg('b', 'abcBc', 'ca')]])
|
|
|
|
command([[call SetReg('b', 'abcBb', 'ba')]])
|
|
|
|
command([[call SetReg('b', 'abcBc2','ca')]])
|
|
|
|
command([[call SetReg('b', 'abcBb2','b50a')]])
|
|
|
|
command([[call SetReg('C', 'abcCl', 'l')]])
|
|
|
|
command([[call SetReg('C', 'abcCc', 'c')]])
|
|
|
|
command([[call SetReg('D', 'abcDb', 'b')]])
|
|
|
|
command([[call SetReg('E', 'abcEb', 'b')]])
|
|
|
|
command([[call SetReg('E', 'abcEl', 'l')]])
|
|
|
|
command([[call SetReg('F', 'abcFc', 'c')]])
|
2015-07-18 11:36:43 -07:00
|
|
|
expect([[
|
|
|
|
{{{1 Basic setreg tests
|
|
|
|
{{{2 setreg('a', 'abcA', 'c')
|
|
|
|
a: type v; value: abcA (['abcA']), expr: abcA (['abcA'])
|
|
|
|
==
|
|
|
|
=abcA=
|
|
|
|
{{{2 setreg('b', 'abcB', 'v')
|
|
|
|
b: type v; value: abcB (['abcB']), expr: abcB (['abcB'])
|
|
|
|
==
|
|
|
|
=abcB=
|
|
|
|
{{{2 setreg('c', 'abcC', 'l')
|
2016-03-06 15:48:36 -07:00
|
|
|
c: type V; value: abcC]] .. "\000 (['abcC']), expr: abcC\000" .. [[ (['abcC'])
|
2015-07-18 11:36:43 -07:00
|
|
|
==
|
|
|
|
abcC
|
|
|
|
==
|
|
|
|
{{{2 setreg('d', 'abcD', 'V')
|
2016-03-06 15:48:36 -07:00
|
|
|
d: type V; value: abcD]] .. "\000 (['abcD']), expr: abcD\000" .. [[ (['abcD'])
|
2015-07-18 11:36:43 -07:00
|
|
|
==
|
|
|
|
abcD
|
|
|
|
==
|
|
|
|
{{{2 setreg('e', 'abcE', 'b')
|
2016-03-06 15:48:36 -07:00
|
|
|
e: type ]] .. '\022' .. [[4; value: abcE (['abcE']), expr: abcE (['abcE'])
|
2015-07-18 11:36:43 -07:00
|
|
|
==
|
|
|
|
=abcE=
|
2016-03-06 15:48:36 -07:00
|
|
|
{{{2 setreg('f', 'abcF', ']] .. '\022' .. [[')
|
|
|
|
f: type ]] .. '\022' .. [[4; value: abcF (['abcF']), expr: abcF (['abcF'])
|
2015-07-18 11:36:43 -07:00
|
|
|
==
|
|
|
|
=abcF=
|
|
|
|
{{{2 setreg('g', 'abcG', 'b10')
|
2016-03-06 15:48:36 -07:00
|
|
|
g: type ]] .. '\022' .. [[10; value: abcG (['abcG']), expr: abcG (['abcG'])
|
2015-07-18 11:36:43 -07:00
|
|
|
==
|
|
|
|
=abcG =
|
2016-03-06 15:48:36 -07:00
|
|
|
{{{2 setreg('h', 'abcH', ']] .. '\022' .. [[10')
|
|
|
|
h: type ]] .. '\022' .. [[10; value: abcH (['abcH']), expr: abcH (['abcH'])
|
2015-07-18 11:36:43 -07:00
|
|
|
==
|
|
|
|
=abcH =
|
|
|
|
{{{2 setreg('I', 'abcI')
|
|
|
|
I: type v; value: abcI (['abcI']), expr: abcI (['abcI'])
|
|
|
|
==
|
|
|
|
=abcI=
|
|
|
|
{{{1 Appending single lines with setreg()
|
|
|
|
{{{2 setreg('A', 'abcAc', 'c')
|
|
|
|
A: type v; value: abcAabcAc (['abcAabcAc']), expr: abcAabcAc (['abcAabcAc'])
|
|
|
|
==
|
|
|
|
=abcAabcAc=
|
|
|
|
{{{2 setreg('A', 'abcAl', 'l')
|
2016-03-06 15:48:36 -07:00
|
|
|
A: type V; value: abcAabcAcabcAl]] .. "\000 (['abcAabcAcabcAl']), expr: abcAabcAcabcAl\000" .. [[ (['abcAabcAcabcAl'])
|
2015-07-18 11:36:43 -07:00
|
|
|
==
|
|
|
|
abcAabcAcabcAl
|
|
|
|
==
|
|
|
|
{{{2 setreg('A', 'abcAc2', 'c')
|
2016-03-06 15:48:36 -07:00
|
|
|
A: type v; value: abcAabcAcabcAl]] .. "\000abcAc2 (['abcAabcAcabcAl', 'abcAc2']), expr: abcAabcAcabcAl\000" .. [[abcAc2 (['abcAabcAcabcAl', 'abcAc2'])
|
2015-07-18 11:36:43 -07:00
|
|
|
==
|
|
|
|
=abcAabcAcabcAl
|
|
|
|
abcAc2=
|
|
|
|
{{{2 setreg('b', 'abcBc', 'ca')
|
|
|
|
b: type v; value: abcBabcBc (['abcBabcBc']), expr: abcBabcBc (['abcBabcBc'])
|
|
|
|
==
|
|
|
|
=abcBabcBc=
|
|
|
|
{{{2 setreg('b', 'abcBb', 'ba')
|
2016-03-06 15:48:36 -07:00
|
|
|
b: type ]] .. '\022' .. [[5; value: abcBabcBcabcBb (['abcBabcBcabcBb']), expr: abcBabcBcabcBb (['abcBabcBcabcBb'])
|
2015-07-18 11:36:43 -07:00
|
|
|
==
|
|
|
|
=abcBabcBcabcBb=
|
|
|
|
{{{2 setreg('b', 'abcBc2', 'ca')
|
2016-03-06 15:48:36 -07:00
|
|
|
b: type v; value: abcBabcBcabcBb]] .. "\000abcBc2 (['abcBabcBcabcBb', 'abcBc2']), expr: abcBabcBcabcBb\000" .. [[abcBc2 (['abcBabcBcabcBb', 'abcBc2'])
|
2015-07-18 11:36:43 -07:00
|
|
|
==
|
|
|
|
=abcBabcBcabcBb
|
|
|
|
abcBc2=
|
|
|
|
{{{2 setreg('b', 'abcBb2', 'b50a')
|
2016-03-06 15:48:36 -07:00
|
|
|
b: type ]] .. "\02250; value: abcBabcBcabcBb\000abcBc2abcBb2 (['abcBabcBcabcBb', 'abcBc2abcBb2']), expr: abcBabcBcabcBb\000" .. [[abcBc2abcBb2 (['abcBabcBcabcBb', 'abcBc2abcBb2'])
|
2015-07-18 11:36:43 -07:00
|
|
|
==
|
|
|
|
=abcBabcBcabcBb =
|
|
|
|
abcBc2abcBb2
|
|
|
|
{{{2 setreg('C', 'abcCl', 'l')
|
2016-03-06 15:48:36 -07:00
|
|
|
C: type V; value: abcC]] .. "\000abcCl\000 (['abcC', 'abcCl']), expr: abcC\000abcCl\000" .. [[ (['abcC', 'abcCl'])
|
2015-07-18 11:36:43 -07:00
|
|
|
==
|
|
|
|
abcC
|
|
|
|
abcCl
|
|
|
|
==
|
|
|
|
{{{2 setreg('C', 'abcCc', 'c')
|
2016-03-06 15:48:36 -07:00
|
|
|
C: type v; value: abcC]] .. "\000abcCl\000abcCc (['abcC', 'abcCl', 'abcCc']), expr: abcC\000abcCl\000" .. [[abcCc (['abcC', 'abcCl', 'abcCc'])
|
2015-07-18 11:36:43 -07:00
|
|
|
==
|
|
|
|
=abcC
|
|
|
|
abcCl
|
|
|
|
abcCc=
|
|
|
|
{{{2 setreg('D', 'abcDb', 'b')
|
2016-03-06 15:48:36 -07:00
|
|
|
D: type ]] .. "\0225; value: abcD\000abcDb (['abcD', 'abcDb']), expr: abcD\000" .. [[abcDb (['abcD', 'abcDb'])
|
2015-07-18 11:36:43 -07:00
|
|
|
==
|
|
|
|
=abcD =
|
|
|
|
abcDb
|
|
|
|
{{{2 setreg('E', 'abcEb', 'b')
|
2016-03-06 15:48:36 -07:00
|
|
|
E: type ]] .. "\0225; value: abcE\000abcEb (['abcE', 'abcEb']), expr: abcE\000" .. [[abcEb (['abcE', 'abcEb'])
|
2015-07-18 11:36:43 -07:00
|
|
|
==
|
|
|
|
=abcE =
|
|
|
|
abcEb
|
|
|
|
{{{2 setreg('E', 'abcEl', 'l')
|
2016-03-06 15:48:36 -07:00
|
|
|
E: type V; value: abcE]] .. "\000abcEb\000abcEl\000 (['abcE', 'abcEb', 'abcEl']), expr: abcE\000abcEb\000abcEl\000" .. [[ (['abcE', 'abcEb', 'abcEl'])
|
2015-07-18 11:36:43 -07:00
|
|
|
==
|
|
|
|
abcE
|
|
|
|
abcEb
|
|
|
|
abcEl
|
|
|
|
==
|
|
|
|
{{{2 setreg('F', 'abcFc', 'c')
|
2016-03-06 15:48:36 -07:00
|
|
|
F: type v; value: abcF]] .. "\000abcFc (['abcF', 'abcFc']), expr: abcF\000" .. [[abcFc (['abcF', 'abcFc'])
|
2015-07-18 11:36:43 -07:00
|
|
|
==
|
|
|
|
=abcF
|
2015-07-19 03:49:47 -07:00
|
|
|
abcFc=]])
|
|
|
|
end)
|
|
|
|
|
|
|
|
it('appending NL with setreg()', function()
|
2017-04-08 14:12:26 -07:00
|
|
|
command('so test_eval_setup.vim')
|
|
|
|
|
|
|
|
command([[call setreg('a', 'abcA2', 'c')]])
|
|
|
|
command([[call setreg('b', 'abcB2', 'v')]])
|
|
|
|
command([[call setreg('c', 'abcC2', 'l')]])
|
|
|
|
command([[call setreg('d', 'abcD2', 'V')]])
|
|
|
|
command([[call setreg('e', 'abcE2', 'b')]])
|
|
|
|
command([[call setreg('f', 'abcF2', "\<C-v>")]])
|
2016-01-26 03:28:19 -07:00
|
|
|
-- These registers where set like this in the old test_eval.in but never
|
|
|
|
-- copied to the output buffer with SetReg(). They do not appear in
|
|
|
|
-- test_eval.ok. Therefore they are commented out.
|
2015-07-19 03:49:47 -07:00
|
|
|
--execute([[call setreg('g', 'abcG2', 'b10')]])
|
|
|
|
--execute([[call setreg('h', 'abcH2', "\<C-v>10")]])
|
|
|
|
--execute([[call setreg('I', 'abcI2')]])
|
|
|
|
|
2017-04-08 14:12:26 -07:00
|
|
|
command([[call SetReg('A', "\n")]])
|
|
|
|
command([[call SetReg('B', "\n", 'c')]])
|
|
|
|
command([[call SetReg('C', "\n")]])
|
|
|
|
command([[call SetReg('D', "\n", 'l')]])
|
|
|
|
command([[call SetReg('E', "\n")]])
|
|
|
|
command([[call SetReg('F', "\n", 'b')]])
|
2015-07-19 03:49:47 -07:00
|
|
|
expect([[
|
2017-04-08 14:12:26 -07:00
|
|
|
|
2016-03-06 15:48:36 -07:00
|
|
|
{{{2 setreg('A', ']] .. '\000' .. [[')
|
|
|
|
A: type V; value: abcA2]] .. "\000 (['abcA2']), expr: abcA2\000" .. [[ (['abcA2'])
|
2015-07-18 11:36:43 -07:00
|
|
|
==
|
|
|
|
abcA2
|
|
|
|
==
|
2016-03-06 15:48:36 -07:00
|
|
|
{{{2 setreg('B', ']] .. '\000' .. [[', 'c')
|
|
|
|
B: type v; value: abcB2]] .. "\000 (['abcB2', '']), expr: abcB2\000" .. [[ (['abcB2', ''])
|
2015-07-18 11:36:43 -07:00
|
|
|
==
|
|
|
|
=abcB2
|
|
|
|
=
|
2016-03-06 15:48:36 -07:00
|
|
|
{{{2 setreg('C', ']] .. '\000' .. [[')
|
|
|
|
C: type V; value: abcC2]] .. "\000\000 (['abcC2', '']), expr: abcC2\000\000" .. [[ (['abcC2', ''])
|
2015-07-18 11:36:43 -07:00
|
|
|
==
|
|
|
|
abcC2
|
2017-04-08 14:12:26 -07:00
|
|
|
|
2015-07-18 11:36:43 -07:00
|
|
|
==
|
2016-03-06 15:48:36 -07:00
|
|
|
{{{2 setreg('D', ']] .. '\000' .. [[', 'l')
|
|
|
|
D: type V; value: abcD2]] .. "\000\000 (['abcD2', '']), expr: abcD2\000\000" .. [[ (['abcD2', ''])
|
2015-07-18 11:36:43 -07:00
|
|
|
==
|
|
|
|
abcD2
|
2017-04-08 14:12:26 -07:00
|
|
|
|
2015-07-18 11:36:43 -07:00
|
|
|
==
|
2016-03-06 15:48:36 -07:00
|
|
|
{{{2 setreg('E', ']] .. '\000' .. [[')
|
|
|
|
E: type V; value: abcE2]] .. "\000\000 (['abcE2', '']), expr: abcE2\000\000" .. [[ (['abcE2', ''])
|
2015-07-18 11:36:43 -07:00
|
|
|
==
|
|
|
|
abcE2
|
2017-04-08 14:12:26 -07:00
|
|
|
|
2015-07-18 11:36:43 -07:00
|
|
|
==
|
2016-03-06 15:48:36 -07:00
|
|
|
{{{2 setreg('F', ']] .. '\000' .. [[', 'b')
|
|
|
|
F: type ]] .. "\0220; value: abcF2\000 (['abcF2', '']), expr: abcF2\000" .. [[ (['abcF2', ''])
|
2015-07-18 11:36:43 -07:00
|
|
|
==
|
|
|
|
=abcF2=
|
2015-07-19 03:49:47 -07:00
|
|
|
]])
|
|
|
|
end)
|
|
|
|
|
|
|
|
it('setting and appending list with setreg()', function()
|
2017-04-08 14:12:26 -07:00
|
|
|
command('so test_eval_setup.vim')
|
|
|
|
|
|
|
|
command([[$put ='{{{1 Setting lists with setreg()']])
|
|
|
|
command([=[call SetReg('a', ['abcA3'], 'c')]=])
|
|
|
|
command([=[call SetReg('b', ['abcB3'], 'l')]=])
|
|
|
|
command([=[call SetReg('c', ['abcC3'], 'b')]=])
|
|
|
|
command([=[call SetReg('d', ['abcD3'])]=])
|
|
|
|
command([=[call SetReg('e', [1, 2, 'abc', 3])]=])
|
|
|
|
command([=[call SetReg('f', [1, 2, 3])]=])
|
|
|
|
|
|
|
|
command([[$put ='{{{1 Appending lists with setreg()']])
|
|
|
|
command([=[call SetReg('A', ['abcA3c'], 'c')]=])
|
|
|
|
command([=[call SetReg('b', ['abcB3l'], 'la')]=])
|
|
|
|
command([=[call SetReg('C', ['abcC3b'], 'lb')]=])
|
|
|
|
command([=[call SetReg('D', ['abcD32'])]=])
|
|
|
|
command([=[call SetReg('A', ['abcA32'])]=])
|
|
|
|
command([=[call SetReg('B', ['abcB3c'], 'c')]=])
|
|
|
|
command([=[call SetReg('C', ['abcC3l'], 'l')]=])
|
|
|
|
command([=[call SetReg('D', ['abcD3b'], 'b')]=])
|
2015-07-19 03:49:47 -07:00
|
|
|
expect([[
|
2017-04-08 14:12:26 -07:00
|
|
|
|
2015-07-18 11:36:43 -07:00
|
|
|
{{{1 Setting lists with setreg()
|
|
|
|
{{{2 setreg('a', ['abcA3'], 'c')
|
|
|
|
a: type v; value: abcA3 (['abcA3']), expr: abcA3 (['abcA3'])
|
|
|
|
==
|
|
|
|
=abcA3=
|
|
|
|
{{{2 setreg('b', ['abcB3'], 'l')
|
2016-03-06 15:48:36 -07:00
|
|
|
b: type V; value: abcB3]] .. "\000 (['abcB3']), expr: abcB3\000" .. [[ (['abcB3'])
|
2015-07-18 11:36:43 -07:00
|
|
|
==
|
|
|
|
abcB3
|
|
|
|
==
|
|
|
|
{{{2 setreg('c', ['abcC3'], 'b')
|
2016-03-06 15:48:36 -07:00
|
|
|
c: type ]] .. '\022' .. [[5; value: abcC3 (['abcC3']), expr: abcC3 (['abcC3'])
|
2015-07-18 11:36:43 -07:00
|
|
|
==
|
|
|
|
=abcC3=
|
|
|
|
{{{2 setreg('d', ['abcD3'])
|
2016-03-06 15:48:36 -07:00
|
|
|
d: type V; value: abcD3]] .. "\000 (['abcD3']), expr: abcD3\000" .. [[ (['abcD3'])
|
2015-07-18 11:36:43 -07:00
|
|
|
==
|
|
|
|
abcD3
|
|
|
|
==
|
|
|
|
{{{2 setreg('e', [1, 2, 'abc', 3])
|
2016-03-06 15:48:36 -07:00
|
|
|
e: type V; value: 1]] .. "\0002\000abc\0003\000 (['1', '2', 'abc', '3']), expr: 1\0002\000abc\0003\000" .. [[ (['1', '2', 'abc', '3'])
|
2015-07-18 11:36:43 -07:00
|
|
|
==
|
|
|
|
1
|
|
|
|
2
|
|
|
|
abc
|
|
|
|
3
|
|
|
|
==
|
|
|
|
{{{2 setreg('f', [1, 2, 3])
|
2016-03-06 15:48:36 -07:00
|
|
|
f: type V; value: 1]] .. "\0002\0003\000 (['1', '2', '3']), expr: 1\0002\0003\000" .. [[ (['1', '2', '3'])
|
2015-07-18 11:36:43 -07:00
|
|
|
==
|
|
|
|
1
|
|
|
|
2
|
|
|
|
3
|
|
|
|
==
|
|
|
|
{{{1 Appending lists with setreg()
|
|
|
|
{{{2 setreg('A', ['abcA3c'], 'c')
|
2016-03-06 15:48:36 -07:00
|
|
|
A: type v; value: abcA3]] .. "\000abcA3c (['abcA3', 'abcA3c']), expr: abcA3\000" .. [[abcA3c (['abcA3', 'abcA3c'])
|
2015-07-18 11:36:43 -07:00
|
|
|
==
|
|
|
|
=abcA3
|
|
|
|
abcA3c=
|
|
|
|
{{{2 setreg('b', ['abcB3l'], 'la')
|
2016-03-06 15:48:36 -07:00
|
|
|
b: type V; value: abcB3]] .. "\000abcB3l\000 (['abcB3', 'abcB3l']), expr: abcB3\000abcB3l\000" .. [[ (['abcB3', 'abcB3l'])
|
2015-07-18 11:36:43 -07:00
|
|
|
==
|
|
|
|
abcB3
|
|
|
|
abcB3l
|
|
|
|
==
|
|
|
|
{{{2 setreg('C', ['abcC3b'], 'lb')
|
2016-03-06 15:48:36 -07:00
|
|
|
C: type ]] .. "\0226; value: abcC3\000abcC3b (['abcC3', 'abcC3b']), expr: abcC3\000" .. [[abcC3b (['abcC3', 'abcC3b'])
|
2015-07-18 11:36:43 -07:00
|
|
|
==
|
|
|
|
=abcC3 =
|
|
|
|
abcC3b
|
|
|
|
{{{2 setreg('D', ['abcD32'])
|
2016-03-06 15:48:36 -07:00
|
|
|
D: type V; value: abcD3]] .. "\000abcD32\000 (['abcD3', 'abcD32']), expr: abcD3\000abcD32\000" .. [[ (['abcD3', 'abcD32'])
|
2015-07-18 11:36:43 -07:00
|
|
|
==
|
|
|
|
abcD3
|
|
|
|
abcD32
|
|
|
|
==
|
|
|
|
{{{2 setreg('A', ['abcA32'])
|
2016-03-06 15:48:36 -07:00
|
|
|
A: type V; value: abcA3]] .. "\000abcA3c\000abcA32\000 (['abcA3', 'abcA3c', 'abcA32']), expr: abcA3\000abcA3c\000abcA32\000" .. [[ (['abcA3', 'abcA3c', 'abcA32'])
|
2015-07-18 11:36:43 -07:00
|
|
|
==
|
|
|
|
abcA3
|
|
|
|
abcA3c
|
|
|
|
abcA32
|
|
|
|
==
|
|
|
|
{{{2 setreg('B', ['abcB3c'], 'c')
|
2016-03-06 15:48:36 -07:00
|
|
|
B: type v; value: abcB3]] .. "\000abcB3l\000abcB3c (['abcB3', 'abcB3l', 'abcB3c']), expr: abcB3\000abcB3l\000" .. [[abcB3c (['abcB3', 'abcB3l', 'abcB3c'])
|
2015-07-18 11:36:43 -07:00
|
|
|
==
|
|
|
|
=abcB3
|
|
|
|
abcB3l
|
|
|
|
abcB3c=
|
|
|
|
{{{2 setreg('C', ['abcC3l'], 'l')
|
2016-03-06 15:48:36 -07:00
|
|
|
C: type V; value: abcC3]] .. "\000abcC3b\000abcC3l\000 (['abcC3', 'abcC3b', 'abcC3l']), expr: abcC3\000abcC3b\000abcC3l\000" .. [[ (['abcC3', 'abcC3b', 'abcC3l'])
|
2015-07-18 11:36:43 -07:00
|
|
|
==
|
|
|
|
abcC3
|
|
|
|
abcC3b
|
|
|
|
abcC3l
|
|
|
|
==
|
|
|
|
{{{2 setreg('D', ['abcD3b'], 'b')
|
2016-03-06 15:48:36 -07:00
|
|
|
D: type ]] .. "\0226; value: abcD3\000abcD32\000abcD3b (['abcD3', 'abcD32', 'abcD3b']), expr: abcD3\000abcD32\000" .. [[abcD3b (['abcD3', 'abcD32', 'abcD3b'])
|
2015-07-18 11:36:43 -07:00
|
|
|
==
|
|
|
|
=abcD3 =
|
|
|
|
abcD32
|
2015-07-19 03:49:47 -07:00
|
|
|
abcD3b]])
|
|
|
|
|
|
|
|
-- From now on we delete the buffer contents after each expect() to make
|
2020-01-30 23:56:34 -07:00
|
|
|
-- the next expect() easier to write. This is necessary because null
|
2015-07-19 03:49:47 -07:00
|
|
|
-- bytes on a line by itself don't play well together with the dedent
|
|
|
|
-- function used in expect().
|
2017-04-08 14:12:26 -07:00
|
|
|
command('%delete')
|
|
|
|
command([[$put ='{{{1 Appending lists with NL with setreg()']])
|
|
|
|
command([=[call SetReg('A', ["\n", 'abcA3l2'], 'l')]=])
|
2015-07-19 03:49:47 -07:00
|
|
|
expect(
|
|
|
|
'\n'
|
|
|
|
.. '{{{1 Appending lists with NL with setreg()\n'
|
2016-03-06 15:48:36 -07:00
|
|
|
.. "{{{2 setreg('A', ['\000', 'abcA3l2'], 'l')\n"
|
|
|
|
.. "A: type V; value: abcA3\000abcA3c\000abcA32\000\000\000abcA3l2\000 (['abcA3', 'abcA3c', 'abcA32', '\000', 'abcA3l2']), expr: abcA3\000abcA3c\000abcA32\000\000\000abcA3l2\000 (['abcA3', 'abcA3c', 'abcA32', '\000', 'abcA3l2'])\n"
|
2015-07-19 03:49:47 -07:00
|
|
|
.. '==\n'
|
|
|
|
.. 'abcA3\n'
|
|
|
|
.. 'abcA3c\n'
|
|
|
|
.. 'abcA32\n'
|
2016-03-06 15:48:36 -07:00
|
|
|
.. '\000\n'
|
2015-07-19 03:49:47 -07:00
|
|
|
.. 'abcA3l2\n'
|
|
|
|
.. '=='
|
|
|
|
)
|
2017-04-08 14:12:26 -07:00
|
|
|
command('%delete')
|
|
|
|
command([=[call SetReg('B', ["\n", 'abcB3c2'], 'c')]=])
|
2015-07-19 03:49:47 -07:00
|
|
|
expect(
|
|
|
|
'\n'
|
2016-03-06 15:48:36 -07:00
|
|
|
.. "{{{2 setreg('B', ['\000', 'abcB3c2'], 'c')\n"
|
|
|
|
.. "B: type v; value: abcB3\000abcB3l\000abcB3c\000\000\000abcB3c2 (['abcB3', 'abcB3l', 'abcB3c', '\000', 'abcB3c2']), expr: abcB3\000abcB3l\000abcB3c\000\000\000abcB3c2 (['abcB3', 'abcB3l', 'abcB3c', '\000', 'abcB3c2'])\n"
|
2015-07-19 03:49:47 -07:00
|
|
|
.. '==\n'
|
|
|
|
.. '=abcB3\n'
|
|
|
|
.. 'abcB3l\n'
|
|
|
|
.. 'abcB3c\n'
|
2016-03-06 15:48:36 -07:00
|
|
|
.. '\000\n'
|
2015-07-19 03:49:47 -07:00
|
|
|
.. 'abcB3c2='
|
|
|
|
)
|
2017-04-08 14:12:26 -07:00
|
|
|
command('%delete')
|
|
|
|
command([=[call SetReg('C', ["\n", 'abcC3b2'], 'b')]=])
|
2015-07-19 03:49:47 -07:00
|
|
|
expect(
|
|
|
|
'\n'
|
2016-03-06 15:48:36 -07:00
|
|
|
.. "{{{2 setreg('C', ['\000', 'abcC3b2'], 'b')\n"
|
|
|
|
.. "C: type \0227; value: abcC3\000abcC3b\000abcC3l\000\000\000abcC3b2 (['abcC3', 'abcC3b', 'abcC3l', '\000', 'abcC3b2']), expr: abcC3\000abcC3b\000abcC3l\000\000\000abcC3b2 (['abcC3', 'abcC3b', 'abcC3l', '\000', 'abcC3b2'])\n"
|
2015-07-19 03:49:47 -07:00
|
|
|
.. '==\n'
|
|
|
|
.. '=abcC3 =\n'
|
|
|
|
.. ' abcC3b\n'
|
|
|
|
.. ' abcC3l\n'
|
2016-03-06 15:48:36 -07:00
|
|
|
.. ' \000\n'
|
2015-07-19 03:49:47 -07:00
|
|
|
.. ' abcC3b2'
|
|
|
|
)
|
2017-04-08 14:12:26 -07:00
|
|
|
command('%delete')
|
|
|
|
command([=[call SetReg('D', ["\n", 'abcD3b50'],'b50')]=])
|
2015-07-19 03:49:47 -07:00
|
|
|
expect(
|
|
|
|
'\n'
|
2016-03-06 15:48:36 -07:00
|
|
|
.. "{{{2 setreg('D', ['\000', 'abcD3b50'], 'b50')\n"
|
|
|
|
.. "D: type \02250; value: abcD3\000abcD32\000abcD3b\000\000\000abcD3b50 (['abcD3', 'abcD32', 'abcD3b', '\000', 'abcD3b50']), expr: abcD3\000abcD32\000abcD3b\000\000\000abcD3b50 (['abcD3', 'abcD32', 'abcD3b', '\000', 'abcD3b50'])\n"
|
2015-07-19 03:49:47 -07:00
|
|
|
.. '==\n'
|
|
|
|
.. '=abcD3 =\n'
|
|
|
|
.. ' abcD32\n'
|
|
|
|
.. ' abcD3b\n'
|
2016-03-06 15:48:36 -07:00
|
|
|
.. ' \000\n'
|
2015-07-19 03:49:47 -07:00
|
|
|
.. ' abcD3b50'
|
|
|
|
)
|
|
|
|
end)
|
|
|
|
|
2020-01-30 23:56:34 -07:00
|
|
|
-- The tests for setting lists with NLs are split into separate it() blocks
|
2015-07-19 03:49:47 -07:00
|
|
|
-- to make the expect() calls easier to write. Otherwise the null byte can
|
2016-01-28 22:19:41 -07:00
|
|
|
-- make trouble on a line on its own.
|
2015-07-19 03:49:47 -07:00
|
|
|
it('setting lists with NLs with setreg(), part 1', function()
|
2017-04-08 14:12:26 -07:00
|
|
|
command('so test_eval_setup.vim')
|
|
|
|
command(
|
|
|
|
[=[call SetReg('a', ['abcA4-0', "\n", "abcA4-2\n", "\nabcA4-3", "abcA4-4\nabcA4-4-2"])]=]
|
|
|
|
)
|
2015-07-19 03:49:47 -07:00
|
|
|
expect(
|
|
|
|
'\n'
|
2016-03-06 15:48:36 -07:00
|
|
|
.. "{{{2 setreg('a', ['abcA4-0', '\000', 'abcA4-2\000', '\000abcA4-3', 'abcA4-4\000abcA4-4-2'])\n"
|
|
|
|
.. "a: type V; value: abcA4-0\000\000\000abcA4-2\000\000\000abcA4-3\000abcA4-4\000abcA4-4-2\000 (['abcA4-0', '\000', 'abcA4-2\000', '\000abcA4-3', 'abcA4-4\000abcA4-4-2']), expr: abcA4-0\000\000\000abcA4-2\000\000\000abcA4-3\000abcA4-4\000abcA4-4-2\000 (['abcA4-0', '\000', 'abcA4-2\000', '\000abcA4-3', 'abcA4-4\000abcA4-4-2'])\n"
|
2015-07-19 03:49:47 -07:00
|
|
|
.. '==\n'
|
|
|
|
.. 'abcA4-0\n'
|
2016-03-06 15:48:36 -07:00
|
|
|
.. '\000\n'
|
|
|
|
.. 'abcA4-2\000\n'
|
|
|
|
.. '\000abcA4-3\n'
|
|
|
|
.. 'abcA4-4\000abcA4-4-2\n'
|
2015-07-19 03:49:47 -07:00
|
|
|
.. '=='
|
|
|
|
)
|
|
|
|
end)
|
|
|
|
|
|
|
|
it('setting lists with NLs with setreg(), part 2', function()
|
2017-04-08 14:12:26 -07:00
|
|
|
command('so test_eval_setup.vim')
|
|
|
|
command(
|
|
|
|
[=[call SetReg('b', ['abcB4c-0', "\n", "abcB4c-2\n", "\nabcB4c-3", "abcB4c-4\nabcB4c-4-2"], 'c')]=]
|
|
|
|
)
|
2015-07-19 03:49:47 -07:00
|
|
|
expect(
|
|
|
|
'\n'
|
2016-03-06 15:48:36 -07:00
|
|
|
.. "{{{2 setreg('b', ['abcB4c-0', '\000', 'abcB4c-2\000', '\000abcB4c-3', 'abcB4c-4\000abcB4c-4-2'], 'c')\n"
|
|
|
|
.. "b: type v; value: abcB4c-0\000\000\000abcB4c-2\000\000\000abcB4c-3\000abcB4c-4\000abcB4c-4-2 (['abcB4c-0', '\000', 'abcB4c-2\000', '\000abcB4c-3', 'abcB4c-4\000abcB4c-4-2']), expr: abcB4c-0\000\000\000abcB4c-2\000\000\000abcB4c-3\000abcB4c-4\000abcB4c-4-2 (['abcB4c-0', '\000', 'abcB4c-2\000', '\000abcB4c-3', 'abcB4c-4\000abcB4c-4-2'])\n"
|
2015-07-19 03:49:47 -07:00
|
|
|
.. '==\n'
|
|
|
|
.. '=abcB4c-0\n'
|
2016-03-06 15:48:36 -07:00
|
|
|
.. '\000\n'
|
|
|
|
.. 'abcB4c-2\000\n'
|
|
|
|
.. '\000abcB4c-3\n'
|
|
|
|
.. 'abcB4c-4\000abcB4c-4-2='
|
|
|
|
)
|
2015-07-19 03:49:47 -07:00
|
|
|
end)
|
|
|
|
|
|
|
|
it('setting lists with NLs with setreg(), part 3', function()
|
2017-04-08 14:12:26 -07:00
|
|
|
command('so test_eval_setup.vim')
|
|
|
|
command(
|
|
|
|
[=[call SetReg('c', ['abcC4l-0', "\n", "abcC4l-2\n", "\nabcC4l-3", "abcC4l-4\nabcC4l-4-2"], 'l')]=]
|
|
|
|
)
|
2015-07-19 03:49:47 -07:00
|
|
|
expect(
|
|
|
|
'\n'
|
2016-03-06 15:48:36 -07:00
|
|
|
.. "{{{2 setreg('c', ['abcC4l-0', '\000', 'abcC4l-2\000', '\000abcC4l-3', 'abcC4l-4\000abcC4l-4-2'], 'l')\n"
|
|
|
|
.. "c: type V; value: abcC4l-0\000\000\000abcC4l-2\000\000\000abcC4l-3\000abcC4l-4\000abcC4l-4-2\000 (['abcC4l-0', '\000', 'abcC4l-2\000', '\000abcC4l-3', 'abcC4l-4\000abcC4l-4-2']), expr: abcC4l-0\000\000\000abcC4l-2\000\000\000abcC4l-3\000abcC4l-4\000abcC4l-4-2\000 (['abcC4l-0', '\000', 'abcC4l-2\000', '\000abcC4l-3', 'abcC4l-4\000abcC4l-4-2'])\n"
|
2015-07-19 03:49:47 -07:00
|
|
|
.. '==\n'
|
|
|
|
.. 'abcC4l-0\n'
|
2016-03-06 15:48:36 -07:00
|
|
|
.. '\000\n'
|
|
|
|
.. 'abcC4l-2\000\n'
|
|
|
|
.. '\000abcC4l-3\n'
|
|
|
|
.. 'abcC4l-4\000abcC4l-4-2\n'
|
2015-07-19 03:49:47 -07:00
|
|
|
.. '=='
|
|
|
|
)
|
|
|
|
end)
|
|
|
|
it('setting lists with NLs with setreg(), part 4', function()
|
2017-04-08 14:12:26 -07:00
|
|
|
command('so test_eval_setup.vim')
|
|
|
|
command(
|
|
|
|
[=[call SetReg('d', ['abcD4b-0', "\n", "abcD4b-2\n", "\nabcD4b-3", "abcD4b-4\nabcD4b-4-2"], 'b')]=]
|
|
|
|
)
|
2015-07-19 03:49:47 -07:00
|
|
|
expect(
|
|
|
|
'\n'
|
2016-03-06 15:48:36 -07:00
|
|
|
.. "{{{2 setreg('d', ['abcD4b-0', '\000', 'abcD4b-2\000', '\000abcD4b-3', 'abcD4b-4\000abcD4b-4-2'], 'b')\n"
|
|
|
|
.. "d: type \02219; value: abcD4b-0\000\000\000abcD4b-2\000\000\000abcD4b-3\000abcD4b-4\000abcD4b-4-2 (['abcD4b-0', '\000', 'abcD4b-2\000', '\000abcD4b-3', 'abcD4b-4\000abcD4b-4-2']), expr: abcD4b-0\000\000\000abcD4b-2\000\000\000abcD4b-3\000abcD4b-4\000abcD4b-4-2 (['abcD4b-0', '\000', 'abcD4b-2\000', '\000abcD4b-3', 'abcD4b-4\000abcD4b-4-2'])\n"
|
2015-07-19 03:49:47 -07:00
|
|
|
.. '==\n'
|
|
|
|
.. '=abcD4b-0 =\n'
|
2016-03-06 15:48:36 -07:00
|
|
|
.. ' \000\n'
|
|
|
|
.. ' abcD4b-2\000\n'
|
|
|
|
.. ' \000abcD4b-3\n'
|
|
|
|
.. ' abcD4b-4\000abcD4b-4-2'
|
|
|
|
)
|
2015-07-19 03:49:47 -07:00
|
|
|
end)
|
|
|
|
it('setting lists with NLs with setreg(), part 5', function()
|
2017-04-08 14:12:26 -07:00
|
|
|
command('so test_eval_setup.vim')
|
|
|
|
command(
|
|
|
|
[=[call SetReg('e', ['abcE4b10-0', "\n", "abcE4b10-2\n", "\nabcE4b10-3", "abcE4b10-4\nabcE4b10-4-2"], 'b10')]=]
|
|
|
|
)
|
2015-07-19 03:49:47 -07:00
|
|
|
expect(
|
|
|
|
'\n'
|
2016-03-06 15:48:36 -07:00
|
|
|
.. "{{{2 setreg('e', ['abcE4b10-0', '\000', 'abcE4b10-2\000', '\000abcE4b10-3', 'abcE4b10-4\000abcE4b10-4-2'], 'b10')\n"
|
|
|
|
.. "e: type \02210; value: abcE4b10-0\000\000\000abcE4b10-2\000\000\000abcE4b10-3\000abcE4b10-4\000abcE4b10-4-2 (['abcE4b10-0', '\000', 'abcE4b10-2\000', '\000abcE4b10-3', 'abcE4b10-4\000abcE4b10-4-2']), expr: abcE4b10-0\000\000\000abcE4b10-2\000\000\000abcE4b10-3\000abcE4b10-4\000abcE4b10-4-2 (['abcE4b10-0', '\000', 'abcE4b10-2\000', '\000abcE4b10-3', 'abcE4b10-4\000abcE4b10-4-2'])\n"
|
2015-07-19 03:49:47 -07:00
|
|
|
.. '==\n'
|
|
|
|
.. '=abcE4b10-0=\n'
|
2016-03-06 15:48:36 -07:00
|
|
|
.. ' \000\n'
|
|
|
|
.. ' abcE4b10-2\000\n'
|
|
|
|
.. ' \000abcE4b10-3\n'
|
|
|
|
.. ' abcE4b10-4\000abcE4b10-4-2'
|
|
|
|
)
|
2015-07-19 03:49:47 -07:00
|
|
|
end)
|
|
|
|
|
2016-04-20 04:44:12 -07:00
|
|
|
it('getreg("a",1,1) returns a valid list when "a is unset', function()
|
|
|
|
-- Precondition: "a is actually unset and "0 is nonempty
|
|
|
|
eq('', eval("getregtype('a')"))
|
|
|
|
eq('', eval("getreg('a')"))
|
2017-04-08 14:12:26 -07:00
|
|
|
command("call setreg('0','text')")
|
2016-04-20 04:44:12 -07:00
|
|
|
|
|
|
|
-- This used to return a NULL list
|
|
|
|
-- which setreg didn't handle
|
2017-04-08 14:12:26 -07:00
|
|
|
command("let x = getreg('a',1,1)")
|
|
|
|
command("call setreg('0',x)")
|
2016-04-20 04:44:12 -07:00
|
|
|
|
|
|
|
-- nvim didn't crash and "0 was emptied
|
2021-09-01 09:42:53 -07:00
|
|
|
assert_alive()
|
2016-04-20 04:44:12 -07:00
|
|
|
eq({}, eval("getreg('0',1,1)"))
|
|
|
|
|
|
|
|
-- x is a mutable list
|
2017-04-08 14:12:26 -07:00
|
|
|
command('let y = x')
|
2016-04-20 04:44:12 -07:00
|
|
|
eq({}, eval('y'))
|
2017-04-08 14:12:26 -07:00
|
|
|
command("call add(x, 'item')")
|
2016-04-20 04:44:12 -07:00
|
|
|
eq({ 'item' }, eval('y'))
|
|
|
|
end)
|
|
|
|
|
2016-05-04 11:17:09 -07:00
|
|
|
it('sets the unnamed register when the "u" option is passed to setreg', function()
|
2017-05-29 08:34:08 -07:00
|
|
|
command("call setreg('a','a reg', 'cu')")
|
2016-05-04 11:17:09 -07:00
|
|
|
eq('a reg', eval('@"'))
|
2017-05-29 08:34:08 -07:00
|
|
|
command("call setreg('b','b reg', 'cu')")
|
2016-05-04 11:17:09 -07:00
|
|
|
eq('b reg', eval('@"'))
|
2017-05-29 08:34:08 -07:00
|
|
|
command("call setreg('c','c reg', 'c')")
|
2016-05-04 11:17:09 -07:00
|
|
|
eq('b reg', eval('@"'))
|
|
|
|
end)
|
|
|
|
|
2015-07-19 03:49:47 -07:00
|
|
|
it('search and expressions', function()
|
2017-04-08 14:12:26 -07:00
|
|
|
command('so test_eval_setup.vim')
|
|
|
|
command([=[call SetReg('/', ['abc/'])]=])
|
|
|
|
command([=[call SetReg('/', ["abc/\n"])]=])
|
|
|
|
command([=[call SetReg('=', ['"abc/"'])]=])
|
|
|
|
command([=[call SetReg('=', ["\"abc/\n\""])]=])
|
2015-07-19 03:49:47 -07:00
|
|
|
expect(
|
|
|
|
[[
|
2017-04-08 14:12:26 -07:00
|
|
|
|
2015-07-18 11:36:43 -07:00
|
|
|
{{{2 setreg('/', ['abc/'])
|
|
|
|
/: type v; value: abc/ (['abc/']), expr: abc/ (['abc/'])
|
|
|
|
==
|
|
|
|
=abc/=
|
2016-03-06 15:48:36 -07:00
|
|
|
{{{2 setreg('/', ['abc/]]
|
|
|
|
.. '\000'
|
|
|
|
.. [['])
|
|
|
|
/: type v; value: abc/]]
|
|
|
|
.. "\000 (['abc/\000']), expr: abc/\000 (['abc/\000"
|
2024-01-02 18:09:18 -07:00
|
|
|
.. [['])
|
2015-07-18 11:36:43 -07:00
|
|
|
==
|
2016-03-06 15:48:36 -07:00
|
|
|
=abc/]]
|
|
|
|
.. '\000'
|
|
|
|
.. [[=
|
2015-07-18 11:36:43 -07:00
|
|
|
{{{2 setreg('=', ['"abc/"'])
|
|
|
|
=: type v; value: abc/ (['abc/']), expr: "abc/" (['"abc/"'])
|
2016-03-06 15:48:36 -07:00
|
|
|
{{{2 setreg('=', ['"abc/]]
|
|
|
|
.. '\000'
|
|
|
|
.. [["'])
|
|
|
|
=: type v; value: abc/]]
|
|
|
|
.. "\000 (['abc/\000"
|
|
|
|
.. [[']), expr: "abc/]]
|
|
|
|
.. '\000'
|
|
|
|
.. [[" (['"abc/]]
|
|
|
|
.. '\000'
|
|
|
|
.. [["'])]]
|
|
|
|
)
|
2015-07-19 03:49:47 -07:00
|
|
|
end)
|
|
|
|
|
2016-06-11 09:58:57 -07:00
|
|
|
describe('system clipboard', function()
|
|
|
|
before_each(function()
|
2017-04-08 14:12:26 -07:00
|
|
|
command('let &runtimepath = "test/functional/fixtures,".&runtimepath')
|
|
|
|
command('call getreg("*")') -- force load of provider
|
2016-06-11 09:58:57 -07:00
|
|
|
end)
|
|
|
|
|
|
|
|
it('works', function()
|
2016-01-27 04:12:50 -07:00
|
|
|
insert([[
|
|
|
|
Some first line (this text was at the top of the old test_eval.in).
|
2017-04-08 14:12:26 -07:00
|
|
|
|
2016-01-27 04:12:50 -07:00
|
|
|
Note: system clipboard is saved, changed and restored.
|
2017-04-08 14:12:26 -07:00
|
|
|
|
2016-01-27 04:12:50 -07:00
|
|
|
clipboard contents
|
|
|
|
something else]])
|
2017-04-08 14:12:26 -07:00
|
|
|
command('so test_eval_setup.vim')
|
2016-01-27 04:12:50 -07:00
|
|
|
-- Save and restore system clipboard.
|
2017-04-08 14:12:26 -07:00
|
|
|
command("let _clipreg = ['*', getreg('*'), getregtype('*')]")
|
|
|
|
command('let _clipopt = &cb')
|
|
|
|
command("let &cb='unnamed'")
|
|
|
|
command('5y')
|
|
|
|
command('AR *')
|
|
|
|
command('tabdo :windo :echo "hi"')
|
|
|
|
command('6y')
|
|
|
|
command('AR *')
|
|
|
|
command('let &cb=_clipopt')
|
|
|
|
command("call call('setreg', _clipreg)")
|
2016-01-27 04:12:50 -07:00
|
|
|
expect(
|
|
|
|
[[
|
|
|
|
Some first line (this text was at the top of the old test_eval.in).
|
2017-04-08 14:12:26 -07:00
|
|
|
|
2016-01-27 04:12:50 -07:00
|
|
|
Note: system clipboard is saved, changed and restored.
|
2017-04-08 14:12:26 -07:00
|
|
|
|
2016-01-27 04:12:50 -07:00
|
|
|
clipboard contents
|
|
|
|
something else
|
|
|
|
*: type V; value: clipboard contents]]
|
|
|
|
.. '\00'
|
|
|
|
.. [[ (['clipboard contents']), expr: clipboard contents]]
|
|
|
|
.. '\00'
|
|
|
|
.. [[ (['clipboard contents'])
|
|
|
|
*: type V; value: something else]]
|
|
|
|
.. '\00'
|
|
|
|
.. [[ (['something else']), expr: something else]]
|
|
|
|
.. '\00'
|
|
|
|
.. [[ (['something else'])]]
|
|
|
|
)
|
|
|
|
end)
|
2016-06-11 09:58:57 -07:00
|
|
|
end)
|
2016-01-27 04:12:50 -07:00
|
|
|
|
2015-07-19 03:49:47 -07:00
|
|
|
it('errors', function()
|
|
|
|
source([[
|
|
|
|
fun ErrExe(str)
|
|
|
|
call append('$', 'Executing '.a:str)
|
|
|
|
try
|
|
|
|
execute a:str
|
|
|
|
catch
|
|
|
|
$put =v:exception
|
|
|
|
endtry
|
|
|
|
endfun]])
|
2017-04-08 14:12:26 -07:00
|
|
|
command([[call ErrExe('call setreg()')]])
|
|
|
|
command([[call ErrExe('call setreg(1)')]])
|
|
|
|
command([[call ErrExe('call setreg(1, 2, 3, 4)')]])
|
|
|
|
command([=[call ErrExe('call setreg([], 2)')]=])
|
|
|
|
command([=[call ErrExe('call setreg(1, 2, [])')]=])
|
|
|
|
command([=[call ErrExe('call setreg("/", ["1", "2"])')]=])
|
|
|
|
command([=[call ErrExe('call setreg("=", ["1", "2"])')]=])
|
|
|
|
command([=[call ErrExe('call setreg(1, ["", "", [], ""])')]=])
|
2015-07-19 03:49:47 -07:00
|
|
|
expect([[
|
2017-04-08 14:12:26 -07:00
|
|
|
|
2015-07-18 11:36:43 -07:00
|
|
|
Executing call setreg()
|
|
|
|
Vim(call):E119: Not enough arguments for function: setreg
|
|
|
|
Executing call setreg(1)
|
|
|
|
Vim(call):E119: Not enough arguments for function: setreg
|
|
|
|
Executing call setreg(1, 2, 3, 4)
|
|
|
|
Vim(call):E118: Too many arguments for function: setreg
|
|
|
|
Executing call setreg([], 2)
|
2023-05-04 16:02:43 -07:00
|
|
|
Vim(call):E730: Using a List as a String
|
2015-07-18 11:36:43 -07:00
|
|
|
Executing call setreg(1, 2, [])
|
2023-05-04 16:02:43 -07:00
|
|
|
Vim(call):E730: Using a List as a String
|
2015-07-18 11:36:43 -07:00
|
|
|
Executing call setreg("/", ["1", "2"])
|
2023-05-04 16:14:39 -07:00
|
|
|
Vim(call):E883: Search pattern and expression register may not contain two or more lines
|
2015-07-18 11:36:43 -07:00
|
|
|
Executing call setreg("=", ["1", "2"])
|
2023-05-04 16:14:39 -07:00
|
|
|
Vim(call):E883: Search pattern and expression register may not contain two or more lines
|
2015-07-18 11:36:43 -07:00
|
|
|
Executing call setreg(1, ["", "", [], ""])
|
2023-05-04 16:02:43 -07:00
|
|
|
Vim(call):E730: Using a List as a String]])
|
2015-07-18 11:36:43 -07:00
|
|
|
end)
|
2015-07-19 03:49:47 -07:00
|
|
|
|
2015-07-22 02:03:17 -07:00
|
|
|
it('function name not starting with a capital', function()
|
2017-04-08 16:29:18 -07:00
|
|
|
eq(
|
|
|
|
'Vim(function):E128: Function name must start with a capital or "s:": g:test()\\nendfunction',
|
|
|
|
exc_exec(dedent([[
|
|
|
|
function! g:test()
|
|
|
|
endfunction]]))
|
2024-01-02 18:09:18 -07:00
|
|
|
)
|
2015-07-22 02:03:17 -07:00
|
|
|
end)
|
|
|
|
|
2016-01-26 03:28:19 -07:00
|
|
|
it('Function name followed by #', function()
|
2017-04-08 16:29:18 -07:00
|
|
|
eq(
|
|
|
|
'Vim(function):E128: Function name must start with a capital or "s:": test2() "#\\nendfunction',
|
|
|
|
exc_exec(dedent([[
|
|
|
|
function! test2() "#
|
|
|
|
endfunction]]))
|
2024-01-02 18:09:18 -07:00
|
|
|
)
|
2015-07-22 02:03:17 -07:00
|
|
|
end)
|
|
|
|
|
|
|
|
it('function name includes a colon', function()
|
2022-10-26 04:04:38 -07:00
|
|
|
eq(
|
|
|
|
'Vim(function):E884: Function name cannot contain a colon: b:test()\\nendfunction',
|
2017-04-08 16:29:18 -07:00
|
|
|
exc_exec(dedent([[
|
|
|
|
function! b:test()
|
|
|
|
endfunction]]))
|
2024-01-02 18:09:18 -07:00
|
|
|
)
|
2015-07-22 02:03:17 -07:00
|
|
|
end)
|
|
|
|
|
|
|
|
it('function name starting with/without "g:", buffer-local funcref', function()
|
2017-04-08 16:29:18 -07:00
|
|
|
command([[
|
|
|
|
function! g:Foo(n)
|
|
|
|
$put ='called Foo(' . a:n . ')'
|
|
|
|
endfunction
|
|
|
|
]])
|
2017-04-08 14:12:26 -07:00
|
|
|
command("let b:my_func = function('Foo')")
|
|
|
|
command('call b:my_func(1)')
|
|
|
|
command('echo g:Foo(2)')
|
|
|
|
command('echo Foo(3)')
|
2015-07-22 02:03:17 -07:00
|
|
|
expect([[
|
2017-04-08 14:12:26 -07:00
|
|
|
|
2015-07-22 02:03:17 -07:00
|
|
|
called Foo(1)
|
|
|
|
called Foo(2)
|
|
|
|
called Foo(3)]])
|
|
|
|
end)
|
|
|
|
|
|
|
|
it('script-local function used in Funcref must exist', function()
|
|
|
|
source([[
|
|
|
|
" Vim script used in test_eval.in. Needed for script-local function.
|
2017-04-08 14:12:26 -07:00
|
|
|
|
2022-02-06 14:34:20 -07:00
|
|
|
func s:Testje()
|
2015-07-22 02:03:17 -07:00
|
|
|
return "foo"
|
|
|
|
endfunc
|
2017-04-08 14:12:26 -07:00
|
|
|
|
2015-07-22 02:03:17 -07:00
|
|
|
let Bar = function('s:Testje')
|
2017-04-08 14:12:26 -07:00
|
|
|
|
2015-07-22 02:03:17 -07:00
|
|
|
$put ='s:Testje exists: ' . exists('s:Testje')
|
|
|
|
$put ='func s:Testje exists: ' . exists('*s:Testje')
|
|
|
|
$put ='Bar exists: ' . exists('Bar')
|
|
|
|
$put ='func Bar exists: ' . exists('*Bar')
|
|
|
|
]])
|
|
|
|
expect([[
|
2017-04-08 14:12:26 -07:00
|
|
|
|
2015-07-22 02:03:17 -07:00
|
|
|
s:Testje exists: 0
|
|
|
|
func s:Testje exists: 1
|
|
|
|
Bar exists: 1
|
|
|
|
func Bar exists: 1]])
|
|
|
|
end)
|
|
|
|
|
|
|
|
it("using $ instead of '$' must give an error", function()
|
2017-04-08 14:12:26 -07:00
|
|
|
eq(
|
|
|
|
'Vim(call):E116: Invalid arguments for function append',
|
|
|
|
exc_exec('call append($, "foobar")')
|
2024-01-02 18:09:18 -07:00
|
|
|
)
|
2015-07-22 02:03:17 -07:00
|
|
|
end)
|
|
|
|
|
|
|
|
it('getcurpos/setpos', function()
|
|
|
|
insert([[
|
|
|
|
012345678
|
|
|
|
012345678
|
|
|
|
|
|
|
|
start:]])
|
2017-04-08 14:12:26 -07:00
|
|
|
command('/^012345678')
|
2015-07-19 03:49:47 -07:00
|
|
|
feed('6l')
|
2020-10-19 11:17:51 -07:00
|
|
|
poke_eventloop()
|
2017-04-08 14:12:26 -07:00
|
|
|
command('let sp = getcurpos()')
|
2015-07-19 03:49:47 -07:00
|
|
|
feed('0')
|
2020-10-19 11:17:51 -07:00
|
|
|
poke_eventloop()
|
2017-04-08 14:12:26 -07:00
|
|
|
command("call setpos('.', sp)")
|
2015-07-19 03:49:47 -07:00
|
|
|
feed('jyl')
|
2020-10-19 11:17:51 -07:00
|
|
|
poke_eventloop()
|
2017-04-08 14:12:26 -07:00
|
|
|
command('$put')
|
2015-07-22 02:03:17 -07:00
|
|
|
expect([[
|
|
|
|
012345678
|
|
|
|
012345678
|
2015-07-19 03:49:47 -07:00
|
|
|
|
2015-07-22 02:03:17 -07:00
|
|
|
start:
|
|
|
|
6]])
|
2015-07-19 03:49:47 -07:00
|
|
|
end)
|
2016-02-27 10:11:39 -07:00
|
|
|
|
|
|
|
it('substring and variable name', function()
|
2017-04-08 14:12:26 -07:00
|
|
|
command("let str = 'abcdef'")
|
|
|
|
command('let n = 3')
|
2016-02-27 10:11:39 -07:00
|
|
|
eq('def', eval('str[n:]'))
|
|
|
|
eq('abcd', eval('str[:n]'))
|
|
|
|
eq('d', eval('str[n:n]'))
|
2017-04-08 14:12:26 -07:00
|
|
|
command('unlet n')
|
|
|
|
command('let nn = 3')
|
2016-02-27 10:11:39 -07:00
|
|
|
eq('def', eval('str[nn:]'))
|
|
|
|
eq('abcd', eval('str[:nn]'))
|
|
|
|
eq('d', eval('str[nn:nn]'))
|
2017-04-08 14:12:26 -07:00
|
|
|
command('unlet nn')
|
|
|
|
command('let b:nn = 4')
|
2016-02-27 10:11:39 -07:00
|
|
|
eq('ef', eval('str[b:nn:]'))
|
|
|
|
eq('abcde', eval('str[:b:nn]'))
|
|
|
|
eq('e', eval('str[b:nn:b:nn]'))
|
|
|
|
end)
|
2015-07-18 11:36:43 -07:00
|
|
|
end)
|