aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/testdir
diff options
context:
space:
mode:
authorSean Dewar <seandewar@users.noreply.github.com>2021-08-06 17:09:47 +0100
committerSean Dewar <seandewar@users.noreply.github.com>2021-08-12 22:35:20 +0100
commit003c8acc8a9863932430bfb51bee8403b964c19b (patch)
treec7f47d87cbc6152a25dbaeffea225842ffc8306b /src/nvim/testdir
parente6be6c307a832d661d2a6269ad2d322e4bf5e9cc (diff)
downloadrneovim-003c8acc8a9863932430bfb51bee8403b964c19b.tar.gz
rneovim-003c8acc8a9863932430bfb51bee8403b964c19b.tar.bz2
rneovim-003c8acc8a9863932430bfb51bee8403b964c19b.zip
vim-patch:8.1.1807: more functions can be used as a method
Problem: More functions can be used as a method. Solution: Add append(), appendbufline(), assert_equal(), etc. Also add the :eval command. https://github.com/vim/vim/commit/25e42231d3ee27feec2568fa4be2aa2bfba82ae5 :eval is already ported.
Diffstat (limited to 'src/nvim/testdir')
-rw-r--r--src/nvim/testdir/test_method.vim25
1 files changed, 22 insertions, 3 deletions
diff --git a/src/nvim/testdir/test_method.vim b/src/nvim/testdir/test_method.vim
index 1c0de01ac5..43ed830aba 100644
--- a/src/nvim/testdir/test_method.vim
+++ b/src/nvim/testdir/test_method.vim
@@ -3,18 +3,23 @@
func Test_list()
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(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('let x = l->items()', 'E715:')
+ call assert_fails('eval l->items()', 'E715:')
call assert_equal('1 2 3', l->join())
- call assert_fails('let x = l->keys()', 'E715:')
+ 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())
@@ -26,7 +31,7 @@ func Test_list()
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('let x = l->values()', 'E715:')
+ call assert_fails('eval l->values()', 'E715:')
endfunc
func Test_dict()
@@ -65,4 +70,18 @@ func Test_dict()
call assert_equal([1, 2, 3], d->values())
endfunc
+func Test_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
+
" vim: shiftwidth=2 sts=2 expandtab