diff options
Diffstat (limited to 'src/nvim/testdir')
-rw-r--r-- | src/nvim/testdir/sautest/autoload/foo.vim | 4 | ||||
-rw-r--r-- | src/nvim/testdir/test_arglist.vim | 4 | ||||
-rw-r--r-- | src/nvim/testdir/test_assert.vim | 2 | ||||
-rw-r--r-- | src/nvim/testdir/test_autoload.vim | 2 | ||||
-rw-r--r-- | src/nvim/testdir/test_bufline.vim | 8 | ||||
-rw-r--r-- | src/nvim/testdir/test_bufwintabinfo.vim | 2 | ||||
-rw-r--r-- | src/nvim/testdir/test_cindent.vim | 10 | ||||
-rw-r--r-- | src/nvim/testdir/test_diffmode.vim | 14 | ||||
-rw-r--r-- | src/nvim/testdir/test_float_func.vim | 27 | ||||
-rw-r--r-- | src/nvim/testdir/test_functions.vim | 57 | ||||
-rw-r--r-- | src/nvim/testdir/test_hide.vim | 2 | ||||
-rw-r--r-- | src/nvim/testdir/test_lambda.vim | 2 | ||||
-rw-r--r-- | src/nvim/testdir/test_match.vim | 2 | ||||
-rw-r--r-- | src/nvim/testdir/test_method.vim | 159 | ||||
-rw-r--r-- | src/nvim/testdir/test_popup.vim | 6 | ||||
-rw-r--r-- | src/nvim/testdir/test_syntax.vim | 4 | ||||
-rw-r--r-- | src/nvim/testdir/test_system.vim | 4 | ||||
-rw-r--r-- | src/nvim/testdir/test_user_func.vim | 18 | ||||
-rw-r--r-- | src/nvim/testdir/test_vimscript.vim | 4 |
19 files changed, 298 insertions, 33 deletions
diff --git a/src/nvim/testdir/sautest/autoload/foo.vim b/src/nvim/testdir/sautest/autoload/foo.vim index d7dcd5ce3d..298e7275d8 100644 --- a/src/nvim/testdir/sautest/autoload/foo.vim +++ b/src/nvim/testdir/sautest/autoload/foo.vim @@ -5,3 +5,7 @@ let foo#bar = {} func foo#bar.echo() let g:called_foo_bar_echo += 1 endfunc + +func foo#addFoo(head) + return a:head .. 'foo' +endfunc diff --git a/src/nvim/testdir/test_arglist.vim b/src/nvim/testdir/test_arglist.vim index a1ef8325ec..01d8f32893 100644 --- a/src/nvim/testdir/test_arglist.vim +++ b/src/nvim/testdir/test_arglist.vim @@ -90,8 +90,8 @@ func Test_argadd_empty_curbuf() call assert_equal('', bufname('%')) call assert_equal(1, line('$')) rew - call assert_notequal(curbuf, bufnr('%')) - call assert_equal('Xargadd', bufname('%')) + call assert_notequal(curbuf, '%'->bufnr()) + call assert_equal('Xargadd', '%'->bufname()) call assert_equal(2, line('$')) %argd diff --git a/src/nvim/testdir/test_assert.vim b/src/nvim/testdir/test_assert.vim index 1d114221dc..52f243aaea 100644 --- a/src/nvim/testdir/test_assert.vim +++ b/src/nvim/testdir/test_assert.vim @@ -7,7 +7,7 @@ func Test_assert_equalfile() let goodtext = ["one", "two", "three"] call writefile(goodtext, 'Xone') - call assert_equal(1, assert_equalfile('Xone', 'xyzxyz')) + call assert_equal(1, 'Xone'->assert_equalfile('xyzxyz')) call assert_match("E485: Can't read file xyzxyz", v:errors[0]) call remove(v:errors, 0) diff --git a/src/nvim/testdir/test_autoload.vim b/src/nvim/testdir/test_autoload.vim index 7396c227c9..b8c4fa251f 100644 --- a/src/nvim/testdir/test_autoload.vim +++ b/src/nvim/testdir/test_autoload.vim @@ -8,6 +8,8 @@ func Test_autoload_dict_func() call g:foo#bar.echo() call assert_equal(1, g:loaded_foo_vim) call assert_equal(1, g:called_foo_bar_echo) + + eval 'bar'->g:foo#addFoo()->assert_equal('barfoo') endfunc func Test_source_autoload() diff --git a/src/nvim/testdir/test_bufline.vim b/src/nvim/testdir/test_bufline.vim index e038bce08e..b4e8a0bc71 100644 --- a/src/nvim/testdir/test_bufline.vim +++ b/src/nvim/testdir/test_bufline.vim @@ -102,7 +102,7 @@ func Test_deletebufline() call assert_equal(0, deletebufline(b, 2, 8)) call assert_equal(['aaa'], getbufline(b, 1, 2)) exe "bd!" b - call assert_equal(1, deletebufline(b, 1)) + call assert_equal(1, b->deletebufline(1)) split Xtest call setline(1, ['a', 'b', 'c']) @@ -131,11 +131,11 @@ func Test_appendbufline_redraw() endif let lines =<< trim END new foo - let winnr=bufwinnr('foo') - let buf=bufnr('foo') + let winnr = 'foo'->bufwinnr() + let buf = bufnr('foo') wincmd p call appendbufline(buf, '$', range(1,200)) - exe winnr. 'wincmd w' + exe winnr .. 'wincmd w' norm! G wincmd p call deletebufline(buf, 1, '$') diff --git a/src/nvim/testdir/test_bufwintabinfo.vim b/src/nvim/testdir/test_bufwintabinfo.vim index cb7ab44798..4b5b55e6bf 100644 --- a/src/nvim/testdir/test_bufwintabinfo.vim +++ b/src/nvim/testdir/test_bufwintabinfo.vim @@ -18,7 +18,7 @@ function Test_getbufwintabinfo() let l = getbufinfo('%') call assert_equal(bufnr('%'), l[0].bufnr) call assert_equal('vim', l[0].variables.editor) - call assert_notequal(-1, index(l[0].windows, bufwinid('%'))) + call assert_notequal(-1, index(l[0].windows, '%'->bufwinid())) " Test for getbufinfo() with 'bufmodified' call assert_equal(0, len(getbufinfo({'bufmodified' : 1}))) diff --git a/src/nvim/testdir/test_cindent.vim b/src/nvim/testdir/test_cindent.vim index b6c2d1467e..562867f548 100644 --- a/src/nvim/testdir/test_cindent.vim +++ b/src/nvim/testdir/test_cindent.vim @@ -118,6 +118,16 @@ b = something(); bw! endfunc +func Test_cindent_func() + new + setlocal cindent + call setline(1, ['int main(void)', '{', 'return 0;', '}']) + call assert_equal(-1, cindent(0)) + call assert_equal(&sw, 3->cindent()) + call assert_equal(-1, cindent(line('$')+1)) + bwipe! +endfunc + " this was going beyond the end of the line. func Test_cindent_case() new diff --git a/src/nvim/testdir/test_diffmode.vim b/src/nvim/testdir/test_diffmode.vim index f39cda7663..efa7f552e0 100644 --- a/src/nvim/testdir/test_diffmode.vim +++ b/src/nvim/testdir/test_diffmode.vim @@ -725,7 +725,7 @@ func Test_diff_filler() diffthis redraw - call assert_equal([0, 0, 0, 0, 0, 0, 0, 1, 0], map(range(-1, 7), 'diff_filler(v:val)')) + call assert_equal([0, 0, 0, 0, 0, 0, 0, 1, 0], map(range(-1, 7), 'v:val->diff_filler()')) wincmd w call assert_equal([0, 0, 0, 0, 2, 0, 0, 0], map(range(-1, 6), 'diff_filler(v:val)')) @@ -741,16 +741,16 @@ func Test_diff_hlID() diffthis redraw - call assert_equal(synIDattr(diff_hlID(-1, 1), "name"), "") + call diff_hlID(-1, 1)->synIDattr("name")->assert_equal("") call assert_equal(diff_hlID(1, 1), hlID("DiffChange")) - call assert_equal(synIDattr(diff_hlID(1, 1), "name"), "DiffChange") + call diff_hlID(1, 1)->synIDattr("name")->assert_equal("DiffChange") call assert_equal(diff_hlID(1, 2), hlID("DiffText")) - call assert_equal(synIDattr(diff_hlID(1, 2), "name"), "DiffText") - call assert_equal(synIDattr(diff_hlID(2, 1), "name"), "") + call diff_hlID(1, 2)->synIDattr("name")->assert_equal("DiffText") + call diff_hlID(2, 1)->synIDattr("name")->assert_equal("") call assert_equal(diff_hlID(3, 1), hlID("DiffAdd")) - call assert_equal(synIDattr(diff_hlID(3, 1), "name"), "DiffAdd") - call assert_equal(synIDattr(diff_hlID(4, 1), "name"), "") + call diff_hlID(3, 1)->synIDattr("name")->assert_equal("DiffAdd") + call diff_hlID(4, 1)->synIDattr("name")->assert_equal("") wincmd w call assert_equal(diff_hlID(1, 1), hlID("DiffChange")) diff --git a/src/nvim/testdir/test_float_func.vim b/src/nvim/testdir/test_float_func.vim index 154ef570e0..78675d7016 100644 --- a/src/nvim/testdir/test_float_func.vim +++ b/src/nvim/testdir/test_float_func.vim @@ -7,6 +7,8 @@ end func Test_abs() call assert_equal('1.23', string(abs(1.23))) call assert_equal('1.23', string(abs(-1.23))) + eval -1.23->abs()->string()->assert_equal('1.23') + call assert_equal('0.0', string(abs(0.0))) call assert_equal('0.0', string(abs(1.0/(1.0/0.0)))) call assert_equal('0.0', string(abs(-1.0/(1.0/0.0)))) @@ -22,6 +24,7 @@ endfunc func Test_sqrt() call assert_equal('0.0', string(sqrt(0.0))) call assert_equal('1.414214', string(sqrt(2.0))) + eval 2.0->sqrt()->string()->assert_equal('1.414214') call assert_equal("str2float('inf')", string(sqrt(1.0/0.0))) call assert_equal("str2float('nan')", string(sqrt(-1.0))) call assert_equal("str2float('nan')", string(sqrt(0.0/0.0))) @@ -31,6 +34,7 @@ endfunc func Test_log() call assert_equal('0.0', string(log(1.0))) call assert_equal('-0.693147', string(log(0.5))) + eval 0.5->log()->string()->assert_equal('-0.693147') call assert_equal("-str2float('inf')", string(log(0.0))) call assert_equal("str2float('nan')", string(log(-1.0))) call assert_equal("str2float('inf')", string(log(1.0/0.0))) @@ -42,6 +46,7 @@ func Test_log10() call assert_equal('0.0', string(log10(1.0))) call assert_equal('2.0', string(log10(100.0))) call assert_equal('2.079181', string(log10(120.0))) + eval 120.0->log10()->string()->assert_equal('2.079181') call assert_equal("-str2float('inf')", string(log10(0.0))) call assert_equal("str2float('nan')", string(log10(-1.0))) call assert_equal("str2float('inf')", string(log10(1.0/0.0))) @@ -53,6 +58,7 @@ func Test_exp() call assert_equal('1.0', string(exp(0.0))) call assert_equal('7.389056', string(exp(2.0))) call assert_equal('0.367879', string(exp(-1.0))) + eval -1.0->exp()->string()->assert_equal('0.367879') call assert_equal("str2float('inf')", string(exp(1.0/0.0))) call assert_equal('0.0', string(exp(-1.0/0.0))) call assert_equal("str2float('nan')", string(exp(0.0/0.0))) @@ -63,6 +69,7 @@ func Test_sin() call assert_equal('0.0', string(sin(0.0))) call assert_equal('0.841471', string(sin(1.0))) call assert_equal('-0.479426', string(sin(-0.5))) + eval -0.5->sin()->string()->assert_equal('-0.479426') call assert_equal("str2float('nan')", string(sin(0.0/0.0))) call assert_equal("str2float('nan')", string(sin(1.0/0.0))) call assert_equal('0.0', string(sin(1.0/(1.0/0.0)))) @@ -73,6 +80,8 @@ endfunc func Test_asin() call assert_equal('0.0', string(asin(0.0))) call assert_equal('1.570796', string(asin(1.0))) + eval 1.0->asin()->string()->assert_equal('1.570796') + call assert_equal('-0.523599', string(asin(-0.5))) call assert_equal("str2float('nan')", string(asin(1.1))) call assert_equal("str2float('nan')", string(asin(1.0/0.0))) @@ -84,6 +93,7 @@ func Test_sinh() call assert_equal('0.0', string(sinh(0.0))) call assert_equal('0.521095', string(sinh(0.5))) call assert_equal('-1.026517', string(sinh(-0.9))) + eval -0.9->sinh()->string()->assert_equal('-1.026517') call assert_equal("str2float('inf')", string(sinh(1.0/0.0))) call assert_equal("-str2float('inf')", string(sinh(-1.0/0.0))) call assert_equal("str2float('nan')", string(sinh(0.0/0.0))) @@ -94,6 +104,7 @@ func Test_cos() call assert_equal('1.0', string(cos(0.0))) call assert_equal('0.540302', string(cos(1.0))) call assert_equal('0.877583', string(cos(-0.5))) + eval -0.5->cos()->string()->assert_equal('0.877583') call assert_equal("str2float('nan')", string(cos(0.0/0.0))) call assert_equal("str2float('nan')", string(cos(1.0/0.0))) call assert_fails('call cos("")', 'E808:') @@ -103,6 +114,7 @@ func Test_acos() call assert_equal('1.570796', string(acos(0.0))) call assert_equal('0.0', string(acos(1.0))) call assert_equal('3.141593', string(acos(-1.0))) + eval -1.0->acos()->string()->assert_equal('3.141593') call assert_equal('2.094395', string(acos(-0.5))) call assert_equal("str2float('nan')", string(acos(1.1))) call assert_equal("str2float('nan')", string(acos(1.0/0.0))) @@ -113,6 +125,7 @@ endfunc func Test_cosh() call assert_equal('1.0', string(cosh(0.0))) call assert_equal('1.127626', string(cosh(0.5))) + eval 0.5->cosh()->string()->assert_equal('1.127626') call assert_equal("str2float('inf')", string(cosh(1.0/0.0))) call assert_equal("str2float('inf')", string(cosh(-1.0/0.0))) call assert_equal("str2float('nan')", string(cosh(0.0/0.0))) @@ -123,6 +136,7 @@ func Test_tan() call assert_equal('0.0', string(tan(0.0))) call assert_equal('0.546302', string(tan(0.5))) call assert_equal('-0.546302', string(tan(-0.5))) + eval -0.5->tan()->string()->assert_equal('-0.546302') call assert_equal("str2float('nan')", string(tan(1.0/0.0))) call assert_equal("str2float('nan')", string(cos(0.0/0.0))) call assert_equal('0.0', string(tan(1.0/(1.0/0.0)))) @@ -134,6 +148,7 @@ func Test_atan() call assert_equal('0.0', string(atan(0.0))) call assert_equal('0.463648', string(atan(0.5))) call assert_equal('-0.785398', string(atan(-1.0))) + eval -1.0->atan()->string()->assert_equal('-0.785398') call assert_equal('1.570796', string(atan(1.0/0.0))) call assert_equal('-1.570796', string(atan(-1.0/0.0))) call assert_equal("str2float('nan')", string(atan(0.0/0.0))) @@ -144,6 +159,7 @@ func Test_atan2() call assert_equal('-2.356194', string(atan2(-1, -1))) call assert_equal('2.356194', string(atan2(1, -1))) call assert_equal('0.0', string(atan2(1.0, 1.0/0.0))) + eval 1.0->atan2(1.0/0.0)->string()->assert_equal('0.0') call assert_equal('1.570796', string(atan2(1.0/0.0, 1.0))) call assert_equal("str2float('nan')", string(atan2(0.0/0.0, 1.0))) call assert_fails('call atan2("", -1)', 'E808:') @@ -154,6 +170,7 @@ func Test_tanh() call assert_equal('0.0', string(tanh(0.0))) call assert_equal('0.462117', string(tanh(0.5))) call assert_equal('-0.761594', string(tanh(-1.0))) + eval -1.0->tanh()->string()->assert_equal('-0.761594') call assert_equal('1.0', string(tanh(1.0/0.0))) call assert_equal('-1.0', string(tanh(-1.0/0.0))) call assert_equal("str2float('nan')", string(tanh(0.0/0.0))) @@ -164,6 +181,7 @@ func Test_fmod() call assert_equal('0.13', string(fmod(12.33, 1.22))) call assert_equal('-0.13', string(fmod(-12.33, 1.22))) call assert_equal("str2float('nan')", string(fmod(1.0/0.0, 1.0))) + eval (1.0/0.0)->fmod(1.0)->string()->assert_equal("str2float('nan')") " On Windows we get "nan" instead of 1.0, accept both. let res = string(fmod(1.0, 1.0/0.0)) if res != "str2float('nan')" @@ -177,6 +195,7 @@ endfunc func Test_pow() call assert_equal('1.0', string(pow(0.0, 0.0))) call assert_equal('8.0', string(pow(2.0, 3.0))) + eval 2.0->pow(3.0)->string()->assert_equal('8.0') call assert_equal("str2float('nan')", string(pow(2.0, 0.0/0.0))) call assert_equal("str2float('nan')", string(pow(0.0/0.0, 3.0))) call assert_equal("str2float('nan')", string(pow(0.0/0.0, 3.0))) @@ -192,6 +211,7 @@ func Test_str2float() call assert_equal('1.0', string(str2float(' 1.0 '))) call assert_equal('1.23', string(str2float('1.23'))) call assert_equal('1.23', string(str2float('1.23abc'))) + eval '1.23abc'->str2float()->string()->assert_equal('1.23') call assert_equal('1.0e40', string(str2float('1e40'))) call assert_equal('-1.23', string(str2float('-1.23'))) call assert_equal('1.23', string(str2float(' + 1.23 '))) @@ -228,6 +248,7 @@ func Test_float2nr() call assert_equal(1, float2nr(1.234)) call assert_equal(123, float2nr(1.234e2)) call assert_equal(12, float2nr(123.4e-1)) + eval 123.4e-1->float2nr()->assert_equal(12) let max_number = 1/0 let min_number = -max_number call assert_equal(max_number/2+1, float2nr(pow(2, 62))) @@ -242,6 +263,7 @@ func Test_floor() call assert_equal('2.0', string(floor(2.0))) call assert_equal('2.0', string(floor(2.11))) call assert_equal('2.0', string(floor(2.99))) + eval 2.99->floor()->string()->assert_equal('2.0') call assert_equal('-3.0', string(floor(-2.11))) call assert_equal('-3.0', string(floor(-2.99))) call assert_equal("str2float('nan')", string(floor(0.0/0.0))) @@ -255,6 +277,7 @@ func Test_ceil() call assert_equal('3.0', string(ceil(2.11))) call assert_equal('3.0', string(ceil(2.99))) call assert_equal('-2.0', string(ceil(-2.11))) + eval -2.11->ceil()->string()->assert_equal('-2.0') call assert_equal('-2.0', string(ceil(-2.99))) call assert_equal("str2float('nan')", string(ceil(0.0/0.0))) call assert_equal("str2float('inf')", string(ceil(1.0/0.0))) @@ -266,6 +289,7 @@ func Test_round() call assert_equal('2.0', string(round(2.1))) call assert_equal('3.0', string(round(2.5))) call assert_equal('3.0', string(round(2.9))) + eval 2.9->round()->string()->assert_equal('3.0') call assert_equal('-2.0', string(round(-2.1))) call assert_equal('-3.0', string(round(-2.5))) call assert_equal('-3.0', string(round(-2.9))) @@ -279,6 +303,7 @@ func Test_trunc() call assert_equal('2.0', string(trunc(2.1))) call assert_equal('2.0', string(trunc(2.5))) call assert_equal('2.0', string(trunc(2.9))) + eval 2.9->trunc()->string()->assert_equal('2.0') call assert_equal('-2.0', string(trunc(-2.1))) call assert_equal('-2.0', string(trunc(-2.5))) call assert_equal('-2.0', string(trunc(-2.9))) @@ -291,6 +316,7 @@ endfunc func Test_isinf() call assert_equal(1, isinf(1.0/0.0)) call assert_equal(-1, isinf(-1.0/0.0)) + eval (-1.0/0.0)->isinf()->assert_equal(-1) call assert_false(isinf(1.0)) call assert_false(isinf(0.0/0.0)) call assert_false(isinf('a')) @@ -302,6 +328,7 @@ func Test_isnan() call assert_true(isnan(0.0/0.0)) call assert_false(isnan(1.0)) call assert_false(isnan(1.0/0.0)) + eval (1.0/0.0)->isnan()->assert_false() call assert_false(isnan(-1.0/0.0)) call assert_false(isnan('a')) call assert_false(isnan([])) diff --git a/src/nvim/testdir/test_functions.vim b/src/nvim/testdir/test_functions.vim index 48f97be96b..6cb3e24201 100644 --- a/src/nvim/testdir/test_functions.vim +++ b/src/nvim/testdir/test_functions.vim @@ -852,7 +852,7 @@ func Test_byte2line_line2byte() set fileformat=mac call assert_equal([-1, -1, 1, 1, 2, 2, 2, 3, 3, -1], - \ map(range(-1, 8), 'byte2line(v:val)')) + \ map(range(-1, 8), 'v:val->byte2line()')) call assert_equal([-1, -1, 1, 3, 6, 8, -1], \ map(range(-1, 5), 'line2byte(v:val)')) @@ -875,6 +875,34 @@ func Test_byte2line_line2byte() bw! endfunc +func Test_byteidx() + let a = '.é.' " one char of two bytes + call assert_equal(0, byteidx(a, 0)) + call assert_equal(0, byteidxcomp(a, 0)) + call assert_equal(1, byteidx(a, 1)) + call assert_equal(1, byteidxcomp(a, 1)) + call assert_equal(3, byteidx(a, 2)) + call assert_equal(3, byteidxcomp(a, 2)) + call assert_equal(4, byteidx(a, 3)) + call assert_equal(4, byteidxcomp(a, 3)) + call assert_equal(-1, byteidx(a, 4)) + call assert_equal(-1, byteidxcomp(a, 4)) + + let b = '.é.' " normal e with composing char + call assert_equal(0, b->byteidx(0)) + call assert_equal(1, b->byteidx(1)) + call assert_equal(4, b->byteidx(2)) + call assert_equal(5, b->byteidx(3)) + call assert_equal(-1, b->byteidx(4)) + + call assert_equal(0, b->byteidxcomp(0)) + call assert_equal(1, b->byteidxcomp(1)) + call assert_equal(2, b->byteidxcomp(2)) + call assert_equal(4, b->byteidxcomp(3)) + call assert_equal(5, b->byteidxcomp(4)) + call assert_equal(-1, b->byteidxcomp(5)) +endfunc + " Test for charidx() func Test_charidx() let a = 'xáb́y' @@ -1065,7 +1093,7 @@ func Test_col() call assert_equal(7, col('$')) call assert_equal(4, col("'x")) call assert_equal(6, col("'Y")) - call assert_equal(2, col([1, 2])) + call assert_equal(2, [1, 2]->col()) call assert_equal(7, col([1, '$'])) call assert_equal(0, col('')) @@ -1413,13 +1441,13 @@ func Test_bufadd_bufload() call assert_equal([''], getbufline(buf, 1, '$')) let curbuf = bufnr('') - call writefile(['some', 'text'], 'otherName') - let buf = bufadd('otherName') + call writefile(['some', 'text'], 'XotherName') + let buf = 'XotherName'->bufadd() call assert_notequal(0, buf) - call assert_equal(1, bufexists('otherName')) + eval 'XotherName'->bufexists()->assert_equal(1) call assert_equal(0, getbufvar(buf, '&buflisted')) call assert_equal(0, bufloaded(buf)) - call bufload(buf) + eval buf->bufload() call assert_equal(1, bufloaded(buf)) call assert_equal(['some', 'text'], getbufline(buf, 1, '$')) call assert_equal(curbuf, bufnr('')) @@ -1439,8 +1467,9 @@ func Test_bufadd_bufload() call assert_equal(0, bufexists(buf2)) bwipe someName - bwipe otherName + bwipe XotherName call assert_equal(0, bufexists('someName')) + call delete('XotherName') endfunc func Test_readdir() @@ -1473,6 +1502,20 @@ func Test_readdir() call delete('Xdir', 'rf') endfunc +func Test_call() + call assert_equal(3, call('len', [123])) + call assert_equal(3, 'len'->call([123])) + call assert_fails("call call('len', 123)", 'E714:') + call assert_equal(0, call('', [])) + + function Mylen() dict + return len(self.data) + endfunction + let mydict = {'data': [0, 1, 2, 3], 'len': function("Mylen")} + eval mydict.len->call([], mydict)->assert_equal(4) + call assert_fails("call call('Mylen', [], 0)", 'E715:') +endfunc + " Test for the eval() function func Test_eval() call assert_fails("call eval('5 a')", 'E488:') diff --git a/src/nvim/testdir/test_hide.vim b/src/nvim/testdir/test_hide.vim index 128b8ff945..41b1a4ad7c 100644 --- a/src/nvim/testdir/test_hide.vim +++ b/src/nvim/testdir/test_hide.vim @@ -37,7 +37,7 @@ function Test_hide() " :hide as a command hide call assert_equal([orig_bname, orig_winnr], [bufname(''), winnr('$')]) - call assert_equal([1, 1], [buflisted('Xf1'), bufloaded('Xf1')]) + call assert_equal([1, 1], ['Xf1'->buflisted(), 'Xf1'->bufloaded()]) bwipeout! Xf1 new Xf1 diff --git a/src/nvim/testdir/test_lambda.vim b/src/nvim/testdir/test_lambda.vim index f026c8a55f..63bb4ae1ef 100644 --- a/src/nvim/testdir/test_lambda.vim +++ b/src/nvim/testdir/test_lambda.vim @@ -61,7 +61,7 @@ endfunction function Test_lambda_fails() call assert_equal(3, {a, b -> a + b}(1, 2)) - call assert_fails('echo {a, a -> a + a}(1, 2)', 'E15:') + call assert_fails('echo {a, a -> a + a}(1, 2)', 'E853:') call assert_fails('echo {a, b -> a + b)}(1, 2)', 'E15:') endfunc diff --git a/src/nvim/testdir/test_match.vim b/src/nvim/testdir/test_match.vim index 0fd76a23ea..505a052a19 100644 --- a/src/nvim/testdir/test_match.vim +++ b/src/nvim/testdir/test_match.vim @@ -242,7 +242,7 @@ func Test_matchaddpos_otherwin() \] call assert_equal(expect, savematches) - call clearmatches(winid) + eval winid->clearmatches() call assert_equal([], getmatches(winid)) call setmatches(savematches, winid) diff --git a/src/nvim/testdir/test_method.vim b/src/nvim/testdir/test_method.vim new file mode 100644 index 0000000000..7a6e6aa19d --- /dev/null +++ b/src/nvim/testdir/test_method.vim @@ -0,0 +1,159 @@ +" Tests for ->method() + +func Test_list_method() + let l = [1, 2, 3] + call assert_equal([1, 2, 3, 4], [1, 2, 3]->add(4)) + eval l->assert_equal(l) + eval l->assert_equal(l, 'wrong') + eval l->assert_notequal([3, 2, 1]) + eval l->assert_notequal([3, 2, 1], 'wrong') + call assert_equal(l, l->copy()) + call assert_equal(l, l->deepcopy()) + call assert_equal(1, l->count(2)) + call assert_false(l->empty()) + call assert_true([]->empty()) + call assert_equal(579, ['123', '+', '456']->join()->eval()) + call assert_equal([1, 2, 3, 4, 5], [1, 2, 3]->extend([4, 5])) + call assert_equal([1, 3], [1, 2, 3]->filter('v:val != 2')) + call assert_equal(2, l->get(1)) + call assert_equal(1, l->index(2)) + call assert_equal([0, 1, 2, 3], [1, 2, 3]->insert(0)) + call assert_fails('eval l->items()', 'E715:') + call assert_equal('1 2 3', l->join()) + call assert_fails('eval l->keys()', 'E715:') + call assert_equal(3, l->len()) + call assert_equal([2, 3, 4], [1, 2, 3]->map('v:val + 1')) + call assert_equal(3, l->max()) + call assert_equal(1, l->min()) + call assert_equal(2, [1, 2, 3]->remove(1)) + call assert_equal([1, 2, 3, 1, 2, 3], l->repeat(2)) + call assert_equal([3, 2, 1], [1, 2, 3]->reverse()) + call assert_equal([1, 2, 3, 4], [4, 2, 3, 1]->sort()) + call assert_equal('[1, 2, 3]', l->string()) + call assert_equal(v:t_list, l->type()) + call assert_equal([1, 2, 3], [1, 1, 2, 3, 3]->uniq()) + call assert_fails('eval l->values()', 'E715:') +endfunc + +func Test_dict_method() + let d = #{one: 1, two: 2, three: 3} + + call assert_equal(d, d->copy()) + call assert_equal(d, d->deepcopy()) + call assert_equal(1, d->count(2)) + call assert_false(d->empty()) + call assert_true({}->empty()) + call assert_equal(#{one: 1, two: 2, three: 3, four: 4}, d->extend(#{four: 4})) + call assert_equal(#{one: 1, two: 2, three: 3}, d->filter('v:val != 4')) + call assert_equal(2, d->get('two')) + " Nvim doesn't support Blobs yet; expect a different emsg + " call assert_fails("let x = d->index(2)", 'E897:') + " call assert_fails("let x = d->insert(0)", 'E899:') + call assert_fails("let x = d->index(2)", 'E714:') + call assert_fails("let x = d->insert(0)", 'E686:') + call assert_true(d->has_key('two')) + call assert_equal([['one', 1], ['two', 2], ['three', 3]], d->items()) + call assert_fails("let x = d->join()", 'E714:') + call assert_equal(['one', 'two', 'three'], d->keys()) + call assert_equal(3, d->len()) + call assert_equal(#{one: 2, two: 3, three: 4}, d->map('v:val + 1')) + call assert_equal(#{one: 1, two: 2, three: 3}, d->map('v:val - 1')) + call assert_equal(3, d->max()) + call assert_equal(1, d->min()) + call assert_equal(2, d->remove("two")) + let d.two = 2 + call assert_fails('let x = d->repeat(2)', 'E731:') + " Nvim doesn't support Blobs yet; expect a different emsg + " call assert_fails('let x = d->reverse()', 'E899:') + call assert_fails('let x = d->reverse()', 'E686:') + call assert_fails('let x = d->sort()', 'E686:') + call assert_equal("{'one': 1, 'two': 2, 'three': 3}", d->string()) + call assert_equal(v:t_dict, d->type()) + call assert_fails('let x = d->uniq()', 'E686:') + call assert_equal([1, 2, 3], d->values()) +endfunc + +func Test_string_method() + eval '1 2 3'->split()->assert_equal(['1', '2', '3']) + eval '1 2 3'->split()->map({i, v -> str2nr(v)})->assert_equal([1, 2, 3]) + eval 'ABC'->str2list()->assert_equal([65, 66, 67]) + eval 'ABC'->strlen()->assert_equal(3) + eval "a\rb\ec"->strtrans()->assert_equal('a^Mb^[c') + eval "aあb"->strwidth()->assert_equal(4) + eval 'abc'->substitute('b', 'x', '')->assert_equal('axc') + + eval 'abc'->printf('the %s arg')->assert_equal('the abc arg') +endfunc + +func Test_method_append() + new + eval ['one', 'two', 'three']->append(1) + call assert_equal(['', 'one', 'two', 'three'], getline(1, '$')) + + %del + let bnr = bufnr('') + wincmd w + eval ['one', 'two', 'three']->appendbufline(bnr, 1) + call assert_equal(['', 'one', 'two', 'three'], getbufline(bnr, 1, '$')) + + exe 'bwipe! ' .. bnr +endfunc + +func Test_method_funcref() + func Concat(one, two, three) + return a:one .. a:two .. a:three + endfunc + let FuncRef = function('Concat') + eval 'foo'->FuncRef('bar', 'tail')->assert_equal('foobartail') + + " not enough arguments + call assert_fails("eval 'foo'->FuncRef('bar')", 'E119:') + " too many arguments + call assert_fails("eval 'foo'->FuncRef('bar', 'tail', 'four')", 'E118:') + + let Partial = function('Concat', ['two']) + eval 'one'->Partial('three')->assert_equal('onetwothree') + + " not enough arguments + call assert_fails("eval 'one'->Partial()", 'E119:') + " too many arguments + call assert_fails("eval 'one'->Partial('three', 'four')", 'E118:') + + delfunc Concat +endfunc + +func Test_method_float() + eval 1.234->string()->assert_equal('1.234') + eval -1.234->string()->assert_equal('-1.234') +endfunc + +func Test_method_syntax() + eval [1, 2, 3] ->sort( ) + eval [1, 2, 3] + \ ->sort( + \ ) + call assert_fails('eval [1, 2, 3]-> sort()', 'E260:') + call assert_fails('eval [1, 2, 3]->sort ()', 'E274:') + call assert_fails('eval [1, 2, 3]-> sort ()', 'E260:') +endfunc + +func Test_method_lambda() + eval "text"->{x -> x .. " extended"}()->assert_equal('text extended') + eval "text"->{x, y -> x .. " extended " .. y}('more')->assert_equal('text extended more') + + call assert_fails('eval "text"->{x -> x .. " extended"} ()', 'E274:') + + " todo: lambda accepts more arguments than it consumes + " call assert_fails('eval "text"->{x -> x .. " extended"}("more")', 'E99:') + + " Nvim doesn't include test_refcount(). + " let l = [1, 2, 3] + " eval l->{x -> x}() + " call assert_equal(1, test_refcount(l)) +endfunc + +func Test_method_not_supported() + call assert_fails('eval 123->changenr()', 'E276:') +endfunc + +" vim: shiftwidth=2 sts=2 expandtab diff --git a/src/nvim/testdir/test_popup.vim b/src/nvim/testdir/test_popup.vim index 06bdb1236a..710450293c 100644 --- a/src/nvim/testdir/test_popup.vim +++ b/src/nvim/testdir/test_popup.vim @@ -250,7 +250,7 @@ endfunc func Test_noinsert_complete() func! s:complTest1() abort - call complete(1, ['source', 'soundfold']) + eval ['source', 'soundfold']->complete(1) return '' endfunc @@ -403,7 +403,7 @@ func DummyCompleteFour(findstart, base) return 0 else call complete_add('four1') - call complete_add('four2') + eval 'four2'->complete_add() call complete_check() call complete_add('four3') call complete_add('four4') @@ -989,7 +989,7 @@ func GetCompleteInfo() if empty(g:compl_what) let g:compl_info = complete_info() else - let g:compl_info = complete_info(g:compl_what) + let g:compl_info = g:compl_what->complete_info() endif return '' endfunc diff --git a/src/nvim/testdir/test_syntax.vim b/src/nvim/testdir/test_syntax.vim index 875e23894f..2344bac498 100644 --- a/src/nvim/testdir/test_syntax.vim +++ b/src/nvim/testdir/test_syntax.vim @@ -546,8 +546,8 @@ func Test_synstack_synIDtrans() call assert_equal([], synstack(1, 1)) norm f/ - call assert_equal(['cComment', 'cCommentStart'], map(synstack(line("."), col(".")), 'synIDattr(v:val, "name")')) - call assert_equal(['Comment', 'Comment'], map(synstack(line("."), col(".")), 'synIDattr(synIDtrans(v:val), "name")')) + eval synstack(line("."), col("."))->map('synIDattr(v:val, "name")')->assert_equal(['cComment', 'cCommentStart']) + eval synstack(line("."), col("."))->map('synIDattr(synIDtrans(v:val), "name")')->assert_equal(['Comment', 'Comment']) norm fA call assert_equal(['cComment'], map(synstack(line("."), col(".")), 'synIDattr(v:val, "name")')) diff --git a/src/nvim/testdir/test_system.vim b/src/nvim/testdir/test_system.vim index 6bbe714d19..7b8ee778cc 100644 --- a/src/nvim/testdir/test_system.vim +++ b/src/nvim/testdir/test_system.vim @@ -7,10 +7,10 @@ func Test_System() if !executable('echo') || !executable('cat') || !executable('wc') return endif - let out = system('echo 123') + let out = 'echo 123'->system() call assert_equal("123\n", out) - let out = systemlist('echo 123') + let out = 'echo 123'->systemlist() if &shell =~# 'cmd.exe$' call assert_equal(["123\r"], out) else diff --git a/src/nvim/testdir/test_user_func.vim b/src/nvim/testdir/test_user_func.vim index 7dcd92a54b..5231ef7b4f 100644 --- a/src/nvim/testdir/test_user_func.vim +++ b/src/nvim/testdir/test_user_func.vim @@ -47,7 +47,7 @@ func FuncWithRef(a) endfunc func Test_user_func() - let g:FuncRef=function("FuncWithRef") + let g:FuncRef = function("FuncWithRef") let g:counter = 0 inoremap <expr> ( ListItem() inoremap <expr> [ ListReset() @@ -62,6 +62,14 @@ func Test_user_func() call assert_equal(9, g:retval) call assert_equal(333, g:FuncRef(333)) + let g:retval = "nop" + call assert_equal('xxx4asdf', "xxx"->Table(4, "asdf")) + call assert_equal('fail', 45->Compute(0, "retval")) + call assert_equal('nop', g:retval) + call assert_equal('ok', 45->Compute(5, "retval")) + call assert_equal(9, g:retval) + " call assert_equal(333, 333->g:FuncRef()) + enew normal oXX+-XX @@ -150,6 +158,14 @@ func Test_default_arg() \ execute('func Args2')) endfunc +func s:addFoo(lead) + return a:lead .. 'foo' +endfunc + +func Test_user_method() + eval 'bar'->s:addFoo()->assert_equal('barfoo') +endfunc + func Test_failed_call_in_try() try | call UnknownFunc() | catch | endtry endfunc diff --git a/src/nvim/testdir/test_vimscript.vim b/src/nvim/testdir/test_vimscript.vim index 5922660ef9..d5837e88c9 100644 --- a/src/nvim/testdir/test_vimscript.vim +++ b/src/nvim/testdir/test_vimscript.vim @@ -1372,6 +1372,7 @@ func Test_bitwise_functions() " and call assert_equal(127, and(127, 127)) call assert_equal(16, and(127, 16)) + eval 127->and(16)->assert_equal(16) call assert_equal(0, and(127, 128)) call assert_fails("call and(1.0, 1)", 'E805:') call assert_fails("call and([], 1)", 'E745:') @@ -1382,6 +1383,7 @@ func Test_bitwise_functions() " or call assert_equal(23, or(16, 7)) call assert_equal(15, or(8, 7)) + eval 8->or(7)->assert_equal(15) call assert_equal(123, or(0, 123)) call assert_fails("call or(1.0, 1)", 'E805:') call assert_fails("call or([], 1)", 'E745:') @@ -1392,6 +1394,7 @@ func Test_bitwise_functions() " xor call assert_equal(0, xor(127, 127)) call assert_equal(111, xor(127, 16)) + eval 127->xor(16)->assert_equal(111) call assert_equal(255, xor(127, 128)) call assert_fails("call xor(1.0, 1)", 'E805:') call assert_fails("call xor([], 1)", 'E745:') @@ -1401,6 +1404,7 @@ func Test_bitwise_functions() call assert_fails("call xor(1, {})", 'E728:') " invert call assert_equal(65408, and(invert(127), 65535)) + eval 127->invert()->and(65535)->assert_equal(65408) call assert_equal(65519, and(invert(16), 65535)) call assert_equal(65407, and(invert(128), 65535)) call assert_fails("call invert(1.0)", 'E805:') |