Mercurial > vim
diff src/testdir/test_method.vim @ 17620:072efa9ca875 v8.1.1807
patch 8.1.1807: more functions can be used as a method
commit https://github.com/vim/vim/commit/25e42231d3ee27feec2568fa4be2aa2bfba82ae5
Author: Bram Moolenaar <Bram@vim.org>
Date: Sun Aug 4 15:04:10 2019 +0200
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.
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Sun, 04 Aug 2019 15:15:06 +0200 |
parents | e259d11e2900 |
children | 4c7097a980a5 |
line wrap: on
line diff
--- a/src/testdir/test_method.vim +++ b/src/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() @@ -59,3 +64,17 @@ func Test_dict() call assert_fails('let x = d->uniq()', 'E686:') 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