Mercurial > vim
annotate src/testdir/test_method.vim @ 26528:4d8226001391 v8.2.3793
patch 8.2.3793: using "g:Func" as a funcref does not work in script context
Commit: https://github.com/vim/vim/commit/ef082e12df2cafe177b2ac9f6922393223ccf83b
Author: Bram Moolenaar <Bram@vim.org>
Date: Sun Dec 12 21:02:03 2021 +0000
patch 8.2.3793: using "g:Func" as a funcref does not work in script context
Problem: Using "g:Func" as a funcref does not work in script context
because "g:" is dropped.
Solution: Keep "g:" in the name. Also add parenthesis to avoid confusing
operator prececence. (closes #9336)
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Sun, 12 Dec 2021 22:15:03 +0100 |
parents | 9e72076e31f8 |
children | 1ce98269be23 |
rev | line source |
---|---|
17612
e259d11e2900
patch 8.1.1803: all builtin functions are global
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1 " Tests for ->method() |
e259d11e2900
patch 8.1.1803: all builtin functions are global
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2 |
19193
9f98957582d6
patch 8.2.0155: warnings from MinGW compiler; tests fail without +float
Bram Moolenaar <Bram@vim.org>
parents:
18225
diff
changeset
|
3 source check.vim |
9f98957582d6
patch 8.2.0155: warnings from MinGW compiler; tests fail without +float
Bram Moolenaar <Bram@vim.org>
parents:
18225
diff
changeset
|
4 |
17646
e5397617d6ca
patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents:
17624
diff
changeset
|
5 func Test_list_method() |
17612
e259d11e2900
patch 8.1.1803: all builtin functions are global
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
6 let l = [1, 2, 3] |
e259d11e2900
patch 8.1.1803: all builtin functions are global
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
7 call assert_equal([1, 2, 3, 4], [1, 2, 3]->add(4)) |
17620
072efa9ca875
patch 8.1.1807: more functions can be used as a method
Bram Moolenaar <Bram@vim.org>
parents:
17612
diff
changeset
|
8 eval l->assert_equal(l) |
072efa9ca875
patch 8.1.1807: more functions can be used as a method
Bram Moolenaar <Bram@vim.org>
parents:
17612
diff
changeset
|
9 eval l->assert_equal(l, 'wrong') |
072efa9ca875
patch 8.1.1807: more functions can be used as a method
Bram Moolenaar <Bram@vim.org>
parents:
17612
diff
changeset
|
10 eval l->assert_notequal([3, 2, 1]) |
072efa9ca875
patch 8.1.1807: more functions can be used as a method
Bram Moolenaar <Bram@vim.org>
parents:
17612
diff
changeset
|
11 eval l->assert_notequal([3, 2, 1], 'wrong') |
17612
e259d11e2900
patch 8.1.1803: all builtin functions are global
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
12 call assert_equal(l, l->copy()) |
17837
f71ee7b04f0b
patch 8.1.1915: more functions can be used as methods
Bram Moolenaar <Bram@vim.org>
parents:
17763
diff
changeset
|
13 call assert_equal(l, l->deepcopy()) |
17612
e259d11e2900
patch 8.1.1803: all builtin functions are global
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
14 call assert_equal(1, l->count(2)) |
e259d11e2900
patch 8.1.1803: all builtin functions are global
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
15 call assert_false(l->empty()) |
e259d11e2900
patch 8.1.1803: all builtin functions are global
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
16 call assert_true([]->empty()) |
17620
072efa9ca875
patch 8.1.1807: more functions can be used as a method
Bram Moolenaar <Bram@vim.org>
parents:
17612
diff
changeset
|
17 call assert_equal(579, ['123', '+', '456']->join()->eval()) |
17612
e259d11e2900
patch 8.1.1803: all builtin functions are global
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
18 call assert_equal([1, 2, 3, 4, 5], [1, 2, 3]->extend([4, 5])) |
e259d11e2900
patch 8.1.1803: all builtin functions are global
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
19 call assert_equal([1, 3], [1, 2, 3]->filter('v:val != 2')) |
e259d11e2900
patch 8.1.1803: all builtin functions are global
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
20 call assert_equal(2, l->get(1)) |
e259d11e2900
patch 8.1.1803: all builtin functions are global
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
21 call assert_equal(1, l->index(2)) |
e259d11e2900
patch 8.1.1803: all builtin functions are global
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
22 call assert_equal([0, 1, 2, 3], [1, 2, 3]->insert(0)) |
17620
072efa9ca875
patch 8.1.1807: more functions can be used as a method
Bram Moolenaar <Bram@vim.org>
parents:
17612
diff
changeset
|
23 call assert_fails('eval l->items()', 'E715:') |
17612
e259d11e2900
patch 8.1.1803: all builtin functions are global
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
24 call assert_equal('1 2 3', l->join()) |
17620
072efa9ca875
patch 8.1.1807: more functions can be used as a method
Bram Moolenaar <Bram@vim.org>
parents:
17612
diff
changeset
|
25 call assert_fails('eval l->keys()', 'E715:') |
17612
e259d11e2900
patch 8.1.1803: all builtin functions are global
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
26 call assert_equal(3, l->len()) |
e259d11e2900
patch 8.1.1803: all builtin functions are global
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
27 call assert_equal([2, 3, 4], [1, 2, 3]->map('v:val + 1')) |
e259d11e2900
patch 8.1.1803: all builtin functions are global
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
28 call assert_equal(3, l->max()) |
e259d11e2900
patch 8.1.1803: all builtin functions are global
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
29 call assert_equal(1, l->min()) |
e259d11e2900
patch 8.1.1803: all builtin functions are global
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
30 call assert_equal(2, [1, 2, 3]->remove(1)) |
e259d11e2900
patch 8.1.1803: all builtin functions are global
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
31 call assert_equal([1, 2, 3, 1, 2, 3], l->repeat(2)) |
e259d11e2900
patch 8.1.1803: all builtin functions are global
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
32 call assert_equal([3, 2, 1], [1, 2, 3]->reverse()) |
e259d11e2900
patch 8.1.1803: all builtin functions are global
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
33 call assert_equal([1, 2, 3, 4], [4, 2, 3, 1]->sort()) |
e259d11e2900
patch 8.1.1803: all builtin functions are global
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
34 call assert_equal('[1, 2, 3]', l->string()) |
e259d11e2900
patch 8.1.1803: all builtin functions are global
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
35 call assert_equal(v:t_list, l->type()) |
e259d11e2900
patch 8.1.1803: all builtin functions are global
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
36 call assert_equal([1, 2, 3], [1, 1, 2, 3, 3]->uniq()) |
17620
072efa9ca875
patch 8.1.1807: more functions can be used as a method
Bram Moolenaar <Bram@vim.org>
parents:
17612
diff
changeset
|
37 call assert_fails('eval l->values()', 'E715:') |
19724
b3e93a05c3ca
patch 8.2.0418: code in eval.c not sufficiently covered by tests
Bram Moolenaar <Bram@vim.org>
parents:
19193
diff
changeset
|
38 call assert_fails('echo []->len', 'E107:') |
17612
e259d11e2900
patch 8.1.1803: all builtin functions are global
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
39 endfunc |
e259d11e2900
patch 8.1.1803: all builtin functions are global
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
40 |
17646
e5397617d6ca
patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents:
17624
diff
changeset
|
41 func Test_dict_method() |
17612
e259d11e2900
patch 8.1.1803: all builtin functions are global
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
42 let d = #{one: 1, two: 2, three: 3} |
e259d11e2900
patch 8.1.1803: all builtin functions are global
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
43 |
e259d11e2900
patch 8.1.1803: all builtin functions are global
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
44 call assert_equal(d, d->copy()) |
17837
f71ee7b04f0b
patch 8.1.1915: more functions can be used as methods
Bram Moolenaar <Bram@vim.org>
parents:
17763
diff
changeset
|
45 call assert_equal(d, d->deepcopy()) |
17612
e259d11e2900
patch 8.1.1803: all builtin functions are global
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
46 call assert_equal(1, d->count(2)) |
e259d11e2900
patch 8.1.1803: all builtin functions are global
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
47 call assert_false(d->empty()) |
e259d11e2900
patch 8.1.1803: all builtin functions are global
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
48 call assert_true({}->empty()) |
e259d11e2900
patch 8.1.1803: all builtin functions are global
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
49 call assert_equal(#{one: 1, two: 2, three: 3, four: 4}, d->extend(#{four: 4})) |
e259d11e2900
patch 8.1.1803: all builtin functions are global
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
50 call assert_equal(#{one: 1, two: 2, three: 3}, d->filter('v:val != 4')) |
e259d11e2900
patch 8.1.1803: all builtin functions are global
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
51 call assert_equal(2, d->get('two')) |
e259d11e2900
patch 8.1.1803: all builtin functions are global
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
52 call assert_fails("let x = d->index(2)", 'E897:') |
e259d11e2900
patch 8.1.1803: all builtin functions are global
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
53 call assert_fails("let x = d->insert(0)", 'E899:') |
17624
4c7097a980a5
patch 8.1.1809: more functions can be used as a method
Bram Moolenaar <Bram@vim.org>
parents:
17620
diff
changeset
|
54 call assert_true(d->has_key('two')) |
17612
e259d11e2900
patch 8.1.1803: all builtin functions are global
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
55 call assert_equal([['one', 1], ['two', 2], ['three', 3]], d->items()) |
e259d11e2900
patch 8.1.1803: all builtin functions are global
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
56 call assert_fails("let x = d->join()", 'E714:') |
e259d11e2900
patch 8.1.1803: all builtin functions are global
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
57 call assert_equal(['one', 'two', 'three'], d->keys()) |
e259d11e2900
patch 8.1.1803: all builtin functions are global
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
58 call assert_equal(3, d->len()) |
e259d11e2900
patch 8.1.1803: all builtin functions are global
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
59 call assert_equal(#{one: 2, two: 3, three: 4}, d->map('v:val + 1')) |
e259d11e2900
patch 8.1.1803: all builtin functions are global
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
60 call assert_equal(#{one: 1, two: 2, three: 3}, d->map('v:val - 1')) |
e259d11e2900
patch 8.1.1803: all builtin functions are global
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
61 call assert_equal(3, d->max()) |
e259d11e2900
patch 8.1.1803: all builtin functions are global
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
62 call assert_equal(1, d->min()) |
e259d11e2900
patch 8.1.1803: all builtin functions are global
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
63 call assert_equal(2, d->remove("two")) |
e259d11e2900
patch 8.1.1803: all builtin functions are global
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
64 let d.two = 2 |
e259d11e2900
patch 8.1.1803: all builtin functions are global
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
65 call assert_fails('let x = d->repeat(2)', 'E731:') |
e259d11e2900
patch 8.1.1803: all builtin functions are global
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
66 call assert_fails('let x = d->reverse()', 'E899:') |
e259d11e2900
patch 8.1.1803: all builtin functions are global
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
67 call assert_fails('let x = d->sort()', 'E686:') |
e259d11e2900
patch 8.1.1803: all builtin functions are global
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
68 call assert_equal("{'one': 1, 'two': 2, 'three': 3}", d->string()) |
e259d11e2900
patch 8.1.1803: all builtin functions are global
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
69 call assert_equal(v:t_dict, d->type()) |
e259d11e2900
patch 8.1.1803: all builtin functions are global
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
70 call assert_fails('let x = d->uniq()', 'E686:') |
e259d11e2900
patch 8.1.1803: all builtin functions are global
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
71 call assert_equal([1, 2, 3], d->values()) |
e259d11e2900
patch 8.1.1803: all builtin functions are global
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
72 endfunc |
17620
072efa9ca875
patch 8.1.1807: more functions can be used as a method
Bram Moolenaar <Bram@vim.org>
parents:
17612
diff
changeset
|
73 |
17646
e5397617d6ca
patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents:
17624
diff
changeset
|
74 func Test_string_method() |
17676
14ac8c31e598
patch 8.1.1835: cannot use printf() as a method
Bram Moolenaar <Bram@vim.org>
parents:
17674
diff
changeset
|
75 eval '1 2 3'->split()->assert_equal(['1', '2', '3']) |
14ac8c31e598
patch 8.1.1835: cannot use printf() as a method
Bram Moolenaar <Bram@vim.org>
parents:
17674
diff
changeset
|
76 eval '1 2 3'->split()->map({i, v -> str2nr(v)})->assert_equal([1, 2, 3]) |
14ac8c31e598
patch 8.1.1835: cannot use printf() as a method
Bram Moolenaar <Bram@vim.org>
parents:
17674
diff
changeset
|
77 eval 'ABC'->str2list()->assert_equal([65, 66, 67]) |
14ac8c31e598
patch 8.1.1835: cannot use printf() as a method
Bram Moolenaar <Bram@vim.org>
parents:
17674
diff
changeset
|
78 eval 'ABC'->strlen()->assert_equal(3) |
14ac8c31e598
patch 8.1.1835: cannot use printf() as a method
Bram Moolenaar <Bram@vim.org>
parents:
17674
diff
changeset
|
79 eval "a\rb\ec"->strtrans()->assert_equal('a^Mb^[c') |
14ac8c31e598
patch 8.1.1835: cannot use printf() as a method
Bram Moolenaar <Bram@vim.org>
parents:
17674
diff
changeset
|
80 eval "aあb"->strwidth()->assert_equal(4) |
14ac8c31e598
patch 8.1.1835: cannot use printf() as a method
Bram Moolenaar <Bram@vim.org>
parents:
17674
diff
changeset
|
81 eval 'abc'->substitute('b', 'x', '')->assert_equal('axc') |
14ac8c31e598
patch 8.1.1835: cannot use printf() as a method
Bram Moolenaar <Bram@vim.org>
parents:
17674
diff
changeset
|
82 |
14ac8c31e598
patch 8.1.1835: cannot use printf() as a method
Bram Moolenaar <Bram@vim.org>
parents:
17674
diff
changeset
|
83 eval 'abc'->printf('the %s arg')->assert_equal('the abc arg') |
17624
4c7097a980a5
patch 8.1.1809: more functions can be used as a method
Bram Moolenaar <Bram@vim.org>
parents:
17620
diff
changeset
|
84 endfunc |
4c7097a980a5
patch 8.1.1809: more functions can be used as a method
Bram Moolenaar <Bram@vim.org>
parents:
17620
diff
changeset
|
85 |
17646
e5397617d6ca
patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents:
17624
diff
changeset
|
86 func Test_method_append() |
17620
072efa9ca875
patch 8.1.1807: more functions can be used as a method
Bram Moolenaar <Bram@vim.org>
parents:
17612
diff
changeset
|
87 new |
072efa9ca875
patch 8.1.1807: more functions can be used as a method
Bram Moolenaar <Bram@vim.org>
parents:
17612
diff
changeset
|
88 eval ['one', 'two', 'three']->append(1) |
072efa9ca875
patch 8.1.1807: more functions can be used as a method
Bram Moolenaar <Bram@vim.org>
parents:
17612
diff
changeset
|
89 call assert_equal(['', 'one', 'two', 'three'], getline(1, '$')) |
072efa9ca875
patch 8.1.1807: more functions can be used as a method
Bram Moolenaar <Bram@vim.org>
parents:
17612
diff
changeset
|
90 |
072efa9ca875
patch 8.1.1807: more functions can be used as a method
Bram Moolenaar <Bram@vim.org>
parents:
17612
diff
changeset
|
91 %del |
072efa9ca875
patch 8.1.1807: more functions can be used as a method
Bram Moolenaar <Bram@vim.org>
parents:
17612
diff
changeset
|
92 let bnr = bufnr('') |
072efa9ca875
patch 8.1.1807: more functions can be used as a method
Bram Moolenaar <Bram@vim.org>
parents:
17612
diff
changeset
|
93 wincmd w |
072efa9ca875
patch 8.1.1807: more functions can be used as a method
Bram Moolenaar <Bram@vim.org>
parents:
17612
diff
changeset
|
94 eval ['one', 'two', 'three']->appendbufline(bnr, 1) |
072efa9ca875
patch 8.1.1807: more functions can be used as a method
Bram Moolenaar <Bram@vim.org>
parents:
17612
diff
changeset
|
95 call assert_equal(['', 'one', 'two', 'three'], getbufline(bnr, 1, '$')) |
072efa9ca875
patch 8.1.1807: more functions can be used as a method
Bram Moolenaar <Bram@vim.org>
parents:
17612
diff
changeset
|
96 |
072efa9ca875
patch 8.1.1807: more functions can be used as a method
Bram Moolenaar <Bram@vim.org>
parents:
17612
diff
changeset
|
97 exe 'bwipe! ' .. bnr |
072efa9ca875
patch 8.1.1807: more functions can be used as a method
Bram Moolenaar <Bram@vim.org>
parents:
17612
diff
changeset
|
98 endfunc |
17646
e5397617d6ca
patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents:
17624
diff
changeset
|
99 |
e5397617d6ca
patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents:
17624
diff
changeset
|
100 func Test_method_funcref() |
e5397617d6ca
patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents:
17624
diff
changeset
|
101 func Concat(one, two, three) |
e5397617d6ca
patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents:
17624
diff
changeset
|
102 return a:one .. a:two .. a:three |
e5397617d6ca
patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents:
17624
diff
changeset
|
103 endfunc |
e5397617d6ca
patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents:
17624
diff
changeset
|
104 let FuncRef = function('Concat') |
e5397617d6ca
patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents:
17624
diff
changeset
|
105 eval 'foo'->FuncRef('bar', 'tail')->assert_equal('foobartail') |
e5397617d6ca
patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents:
17624
diff
changeset
|
106 |
17648
511a03fcdc78
patch 8.1.1821: no test for wrong number of method arguments
Bram Moolenaar <Bram@vim.org>
parents:
17646
diff
changeset
|
107 " not enough arguments |
511a03fcdc78
patch 8.1.1821: no test for wrong number of method arguments
Bram Moolenaar <Bram@vim.org>
parents:
17646
diff
changeset
|
108 call assert_fails("eval 'foo'->FuncRef('bar')", 'E119:') |
511a03fcdc78
patch 8.1.1821: no test for wrong number of method arguments
Bram Moolenaar <Bram@vim.org>
parents:
17646
diff
changeset
|
109 " too many arguments |
511a03fcdc78
patch 8.1.1821: no test for wrong number of method arguments
Bram Moolenaar <Bram@vim.org>
parents:
17646
diff
changeset
|
110 call assert_fails("eval 'foo'->FuncRef('bar', 'tail', 'four')", 'E118:') |
511a03fcdc78
patch 8.1.1821: no test for wrong number of method arguments
Bram Moolenaar <Bram@vim.org>
parents:
17646
diff
changeset
|
111 |
17646
e5397617d6ca
patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents:
17624
diff
changeset
|
112 let Partial = function('Concat', ['two']) |
e5397617d6ca
patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents:
17624
diff
changeset
|
113 eval 'one'->Partial('three')->assert_equal('onetwothree') |
e5397617d6ca
patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents:
17624
diff
changeset
|
114 |
17648
511a03fcdc78
patch 8.1.1821: no test for wrong number of method arguments
Bram Moolenaar <Bram@vim.org>
parents:
17646
diff
changeset
|
115 " not enough arguments |
511a03fcdc78
patch 8.1.1821: no test for wrong number of method arguments
Bram Moolenaar <Bram@vim.org>
parents:
17646
diff
changeset
|
116 call assert_fails("eval 'one'->Partial()", 'E119:') |
511a03fcdc78
patch 8.1.1821: no test for wrong number of method arguments
Bram Moolenaar <Bram@vim.org>
parents:
17646
diff
changeset
|
117 " too many arguments |
511a03fcdc78
patch 8.1.1821: no test for wrong number of method arguments
Bram Moolenaar <Bram@vim.org>
parents:
17646
diff
changeset
|
118 call assert_fails("eval 'one'->Partial('three', 'four')", 'E118:') |
511a03fcdc78
patch 8.1.1821: no test for wrong number of method arguments
Bram Moolenaar <Bram@vim.org>
parents:
17646
diff
changeset
|
119 |
17646
e5397617d6ca
patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents:
17624
diff
changeset
|
120 delfunc Concat |
e5397617d6ca
patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents:
17624
diff
changeset
|
121 endfunc |
17661
da7890e3359b
patch 8.1.1828: not strict enough checking syntax of method invocation
Bram Moolenaar <Bram@vim.org>
parents:
17648
diff
changeset
|
122 |
17763
117c7795a979
patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents:
17732
diff
changeset
|
123 func Test_method_float() |
19193
9f98957582d6
patch 8.2.0155: warnings from MinGW compiler; tests fail without +float
Bram Moolenaar <Bram@vim.org>
parents:
18225
diff
changeset
|
124 CheckFeature float |
17763
117c7795a979
patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents:
17732
diff
changeset
|
125 eval 1.234->string()->assert_equal('1.234') |
117c7795a979
patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents:
17732
diff
changeset
|
126 eval -1.234->string()->assert_equal('-1.234') |
117c7795a979
patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents:
17732
diff
changeset
|
127 endfunc |
117c7795a979
patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents:
17732
diff
changeset
|
128 |
17661
da7890e3359b
patch 8.1.1828: not strict enough checking syntax of method invocation
Bram Moolenaar <Bram@vim.org>
parents:
17648
diff
changeset
|
129 func Test_method_syntax() |
da7890e3359b
patch 8.1.1828: not strict enough checking syntax of method invocation
Bram Moolenaar <Bram@vim.org>
parents:
17648
diff
changeset
|
130 eval [1, 2, 3] ->sort( ) |
da7890e3359b
patch 8.1.1828: not strict enough checking syntax of method invocation
Bram Moolenaar <Bram@vim.org>
parents:
17648
diff
changeset
|
131 eval [1, 2, 3] |
da7890e3359b
patch 8.1.1828: not strict enough checking syntax of method invocation
Bram Moolenaar <Bram@vim.org>
parents:
17648
diff
changeset
|
132 \ ->sort( |
da7890e3359b
patch 8.1.1828: not strict enough checking syntax of method invocation
Bram Moolenaar <Bram@vim.org>
parents:
17648
diff
changeset
|
133 \ ) |
24632
9e72076e31f8
patch 8.2.2855: white space after "->" does not give E274
Bram Moolenaar <Bram@vim.org>
parents:
23713
diff
changeset
|
134 eval [1, 2, 3]->sort() |
23713
572b0f1c2e28
patch 8.2.2398: method test fails
Bram Moolenaar <Bram@vim.org>
parents:
21265
diff
changeset
|
135 |
17661
da7890e3359b
patch 8.1.1828: not strict enough checking syntax of method invocation
Bram Moolenaar <Bram@vim.org>
parents:
17648
diff
changeset
|
136 call assert_fails('eval [1, 2, 3]->sort ()', 'E274:') |
23713
572b0f1c2e28
patch 8.2.2398: method test fails
Bram Moolenaar <Bram@vim.org>
parents:
21265
diff
changeset
|
137 call assert_fails('eval [1, 2, 3] ->sort ()', 'E274:') |
572b0f1c2e28
patch 8.2.2398: method test fails
Bram Moolenaar <Bram@vim.org>
parents:
21265
diff
changeset
|
138 call assert_fails('eval [1, 2, 3]-> sort ()', 'E274:') |
24632
9e72076e31f8
patch 8.2.2855: white space after "->" does not give E274
Bram Moolenaar <Bram@vim.org>
parents:
23713
diff
changeset
|
139 call assert_fails('eval [1, 2, 3]-> sort()', 'E274:') |
17661
da7890e3359b
patch 8.1.1828: not strict enough checking syntax of method invocation
Bram Moolenaar <Bram@vim.org>
parents:
17648
diff
changeset
|
140 endfunc |
17674
06c3e15ad84d
patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents:
17661
diff
changeset
|
141 |
06c3e15ad84d
patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents:
17661
diff
changeset
|
142 func Test_method_lambda() |
06c3e15ad84d
patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents:
17661
diff
changeset
|
143 eval "text"->{x -> x .. " extended"}()->assert_equal('text extended') |
06c3e15ad84d
patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents:
17661
diff
changeset
|
144 eval "text"->{x, y -> x .. " extended " .. y}('more')->assert_equal('text extended more') |
06c3e15ad84d
patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents:
17661
diff
changeset
|
145 |
06c3e15ad84d
patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents:
17661
diff
changeset
|
146 call assert_fails('eval "text"->{x -> x .. " extended"} ()', 'E274:') |
06c3e15ad84d
patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents:
17661
diff
changeset
|
147 |
06c3e15ad84d
patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents:
17661
diff
changeset
|
148 " todo: lambda accepts more arguments than it consumes |
06c3e15ad84d
patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents:
17661
diff
changeset
|
149 " call assert_fails('eval "text"->{x -> x .. " extended"}("more")', 'E99:') |
18225
6c3a8312486d
patch 8.1.2107: various memory leaks reported by asan
Bram Moolenaar <Bram@vim.org>
parents:
17837
diff
changeset
|
150 |
6c3a8312486d
patch 8.1.2107: various memory leaks reported by asan
Bram Moolenaar <Bram@vim.org>
parents:
17837
diff
changeset
|
151 let l = [1, 2, 3] |
6c3a8312486d
patch 8.1.2107: various memory leaks reported by asan
Bram Moolenaar <Bram@vim.org>
parents:
17837
diff
changeset
|
152 eval l->{x -> x}() |
6c3a8312486d
patch 8.1.2107: various memory leaks reported by asan
Bram Moolenaar <Bram@vim.org>
parents:
17837
diff
changeset
|
153 call assert_equal(1, test_refcount(l)) |
17674
06c3e15ad84d
patch 8.1.1834: cannot use a lambda as a method
Bram Moolenaar <Bram@vim.org>
parents:
17661
diff
changeset
|
154 endfunc |
17732
1726c2db81bf
patch 8.1.1863: confusing error when using a builtin function as method
Bram Moolenaar <Bram@vim.org>
parents:
17676
diff
changeset
|
155 |
1726c2db81bf
patch 8.1.1863: confusing error when using a builtin function as method
Bram Moolenaar <Bram@vim.org>
parents:
17676
diff
changeset
|
156 func Test_method_not_supported() |
1726c2db81bf
patch 8.1.1863: confusing error when using a builtin function as method
Bram Moolenaar <Bram@vim.org>
parents:
17676
diff
changeset
|
157 call assert_fails('eval 123->changenr()', 'E276:') |
19787
906269bf83d5
patch 8.2.0450: not enough testing for restricted mode and function calls
Bram Moolenaar <Bram@vim.org>
parents:
19724
diff
changeset
|
158 call assert_fails('echo "abc"->invalidfunc()', 'E117:') |
906269bf83d5
patch 8.2.0450: not enough testing for restricted mode and function calls
Bram Moolenaar <Bram@vim.org>
parents:
19724
diff
changeset
|
159 " Test for too many or too few arguments to a method |
906269bf83d5
patch 8.2.0450: not enough testing for restricted mode and function calls
Bram Moolenaar <Bram@vim.org>
parents:
19724
diff
changeset
|
160 call assert_fails('let n="abc"->len(2)', 'E118:') |
906269bf83d5
patch 8.2.0450: not enough testing for restricted mode and function calls
Bram Moolenaar <Bram@vim.org>
parents:
19724
diff
changeset
|
161 call assert_fails('let n=10->setwinvar()', 'E119:') |
17732
1726c2db81bf
patch 8.1.1863: confusing error when using a builtin function as method
Bram Moolenaar <Bram@vim.org>
parents:
17676
diff
changeset
|
162 endfunc |
19724
b3e93a05c3ca
patch 8.2.0418: code in eval.c not sufficiently covered by tests
Bram Moolenaar <Bram@vim.org>
parents:
19193
diff
changeset
|
163 |
19787
906269bf83d5
patch 8.2.0450: not enough testing for restricted mode and function calls
Bram Moolenaar <Bram@vim.org>
parents:
19724
diff
changeset
|
164 " Test for passing optional arguments to methods |
906269bf83d5
patch 8.2.0450: not enough testing for restricted mode and function calls
Bram Moolenaar <Bram@vim.org>
parents:
19724
diff
changeset
|
165 func Test_method_args() |
906269bf83d5
patch 8.2.0450: not enough testing for restricted mode and function calls
Bram Moolenaar <Bram@vim.org>
parents:
19724
diff
changeset
|
166 let v:errors = [] |
906269bf83d5
patch 8.2.0450: not enough testing for restricted mode and function calls
Bram Moolenaar <Bram@vim.org>
parents:
19724
diff
changeset
|
167 let n = 10->assert_inrange(1, 5, "Test_assert_inrange") |
906269bf83d5
patch 8.2.0450: not enough testing for restricted mode and function calls
Bram Moolenaar <Bram@vim.org>
parents:
19724
diff
changeset
|
168 if v:errors[0] !~ 'Test_assert_inrange' |
906269bf83d5
patch 8.2.0450: not enough testing for restricted mode and function calls
Bram Moolenaar <Bram@vim.org>
parents:
19724
diff
changeset
|
169 call assert_report(v:errors[0]) |
906269bf83d5
patch 8.2.0450: not enough testing for restricted mode and function calls
Bram Moolenaar <Bram@vim.org>
parents:
19724
diff
changeset
|
170 else |
906269bf83d5
patch 8.2.0450: not enough testing for restricted mode and function calls
Bram Moolenaar <Bram@vim.org>
parents:
19724
diff
changeset
|
171 " Test passed |
906269bf83d5
patch 8.2.0450: not enough testing for restricted mode and function calls
Bram Moolenaar <Bram@vim.org>
parents:
19724
diff
changeset
|
172 let v:errors = [] |
906269bf83d5
patch 8.2.0450: not enough testing for restricted mode and function calls
Bram Moolenaar <Bram@vim.org>
parents:
19724
diff
changeset
|
173 endif |
906269bf83d5
patch 8.2.0450: not enough testing for restricted mode and function calls
Bram Moolenaar <Bram@vim.org>
parents:
19724
diff
changeset
|
174 endfunc |
906269bf83d5
patch 8.2.0450: not enough testing for restricted mode and function calls
Bram Moolenaar <Bram@vim.org>
parents:
19724
diff
changeset
|
175 |
906269bf83d5
patch 8.2.0450: not enough testing for restricted mode and function calls
Bram Moolenaar <Bram@vim.org>
parents:
19724
diff
changeset
|
176 " vim: ts=8 sw=2 sts=2 expandtab tw=80 fdm=marker |