annotate src/testdir/test_expand_func.vim @ 17849:73ddc462979d v8.1.1921

patch 8.1.1921: more functions can be used as methods Commit: https://github.com/vim/vim/commit/a4208966fb289a505ebdef62bbc37c214069bab4 Author: Bram Moolenaar <Bram@vim.org> Date: Sat Aug 24 20:50:19 2019 +0200 patch 8.1.1921: more functions can be used as methods Problem: More functions can be used as methods. Solution: Make various functions usable as a method.
author Bram Moolenaar <Bram@vim.org>
date Sat, 24 Aug 2019 21:00:05 +0200
parents 81be817c9d9a
children 6d3c683466f4
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
14700
0a3b9ecf7cb8 patch 8.1.0362: cannot get the script line number when executing a function
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1 " Tests for expand()
0a3b9ecf7cb8 patch 8.1.0362: cannot get the script line number when executing a function
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2
0a3b9ecf7cb8 patch 8.1.0362: cannot get the script line number when executing a function
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3 let s:sfile = expand('<sfile>')
0a3b9ecf7cb8 patch 8.1.0362: cannot get the script line number when executing a function
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4 let s:slnum = str2nr(expand('<slnum>'))
0a3b9ecf7cb8 patch 8.1.0362: cannot get the script line number when executing a function
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5 let s:sflnum = str2nr(expand('<sflnum>'))
0a3b9ecf7cb8 patch 8.1.0362: cannot get the script line number when executing a function
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6
0a3b9ecf7cb8 patch 8.1.0362: cannot get the script line number when executing a function
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
7 func s:expand_sfile()
0a3b9ecf7cb8 patch 8.1.0362: cannot get the script line number when executing a function
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
8 return expand('<sfile>')
0a3b9ecf7cb8 patch 8.1.0362: cannot get the script line number when executing a function
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
9 endfunc
0a3b9ecf7cb8 patch 8.1.0362: cannot get the script line number when executing a function
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
10
0a3b9ecf7cb8 patch 8.1.0362: cannot get the script line number when executing a function
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
11 func s:expand_slnum()
0a3b9ecf7cb8 patch 8.1.0362: cannot get the script line number when executing a function
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
12 return str2nr(expand('<slnum>'))
0a3b9ecf7cb8 patch 8.1.0362: cannot get the script line number when executing a function
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
13 endfunc
0a3b9ecf7cb8 patch 8.1.0362: cannot get the script line number when executing a function
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
14
0a3b9ecf7cb8 patch 8.1.0362: cannot get the script line number when executing a function
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
15 func s:expand_sflnum()
0a3b9ecf7cb8 patch 8.1.0362: cannot get the script line number when executing a function
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
16 return str2nr(expand('<sflnum>'))
0a3b9ecf7cb8 patch 8.1.0362: cannot get the script line number when executing a function
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
17 endfunc
0a3b9ecf7cb8 patch 8.1.0362: cannot get the script line number when executing a function
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
18
0a3b9ecf7cb8 patch 8.1.0362: cannot get the script line number when executing a function
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
19 func Test_expand_sfile()
0a3b9ecf7cb8 patch 8.1.0362: cannot get the script line number when executing a function
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
20 call assert_match('test_expand_func\.vim$', s:sfile)
0a3b9ecf7cb8 patch 8.1.0362: cannot get the script line number when executing a function
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
21 call assert_match('^function .*\.\.Test_expand_sfile$', expand('<sfile>'))
0a3b9ecf7cb8 patch 8.1.0362: cannot get the script line number when executing a function
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
22
0a3b9ecf7cb8 patch 8.1.0362: cannot get the script line number when executing a function
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
23 " Call in script-local function
0a3b9ecf7cb8 patch 8.1.0362: cannot get the script line number when executing a function
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
24 call assert_match('^function .*\.\.Test_expand_sfile\[5\]\.\.<SNR>\d\+_expand_sfile$', s:expand_sfile())
0a3b9ecf7cb8 patch 8.1.0362: cannot get the script line number when executing a function
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
25
0a3b9ecf7cb8 patch 8.1.0362: cannot get the script line number when executing a function
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
26 " Call in command
0a3b9ecf7cb8 patch 8.1.0362: cannot get the script line number when executing a function
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
27 command Sfile echo expand('<sfile>')
0a3b9ecf7cb8 patch 8.1.0362: cannot get the script line number when executing a function
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
28 call assert_match('^function .*\.\.Test_expand_sfile$', trim(execute('Sfile')))
0a3b9ecf7cb8 patch 8.1.0362: cannot get the script line number when executing a function
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
29 delcommand Sfile
0a3b9ecf7cb8 patch 8.1.0362: cannot get the script line number when executing a function
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
30 endfunc
0a3b9ecf7cb8 patch 8.1.0362: cannot get the script line number when executing a function
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
31
0a3b9ecf7cb8 patch 8.1.0362: cannot get the script line number when executing a function
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
32 func Test_expand_slnum()
0a3b9ecf7cb8 patch 8.1.0362: cannot get the script line number when executing a function
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
33 call assert_equal(4, s:slnum)
0a3b9ecf7cb8 patch 8.1.0362: cannot get the script line number when executing a function
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
34 call assert_equal(2, str2nr(expand('<slnum>')))
0a3b9ecf7cb8 patch 8.1.0362: cannot get the script line number when executing a function
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
35
0a3b9ecf7cb8 patch 8.1.0362: cannot get the script line number when executing a function
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
36 " Line-continuation
0a3b9ecf7cb8 patch 8.1.0362: cannot get the script line number when executing a function
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
37 call assert_equal(
0a3b9ecf7cb8 patch 8.1.0362: cannot get the script line number when executing a function
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
38 \ 5,
0a3b9ecf7cb8 patch 8.1.0362: cannot get the script line number when executing a function
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
39 \ str2nr(expand('<slnum>')))
0a3b9ecf7cb8 patch 8.1.0362: cannot get the script line number when executing a function
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
40
0a3b9ecf7cb8 patch 8.1.0362: cannot get the script line number when executing a function
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
41 " Call in script-local function
0a3b9ecf7cb8 patch 8.1.0362: cannot get the script line number when executing a function
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
42 call assert_equal(1, s:expand_slnum())
0a3b9ecf7cb8 patch 8.1.0362: cannot get the script line number when executing a function
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
43
0a3b9ecf7cb8 patch 8.1.0362: cannot get the script line number when executing a function
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
44 " Call in command
0a3b9ecf7cb8 patch 8.1.0362: cannot get the script line number when executing a function
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
45 command Slnum echo expand('<slnum>')
0a3b9ecf7cb8 patch 8.1.0362: cannot get the script line number when executing a function
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
46 call assert_equal(14, str2nr(trim(execute('Slnum'))))
0a3b9ecf7cb8 patch 8.1.0362: cannot get the script line number when executing a function
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
47 delcommand Slnum
0a3b9ecf7cb8 patch 8.1.0362: cannot get the script line number when executing a function
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
48 endfunc
0a3b9ecf7cb8 patch 8.1.0362: cannot get the script line number when executing a function
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
49
0a3b9ecf7cb8 patch 8.1.0362: cannot get the script line number when executing a function
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
50 func Test_expand_sflnum()
0a3b9ecf7cb8 patch 8.1.0362: cannot get the script line number when executing a function
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
51 call assert_equal(5, s:sflnum)
0a3b9ecf7cb8 patch 8.1.0362: cannot get the script line number when executing a function
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
52 call assert_equal(52, str2nr(expand('<sflnum>')))
0a3b9ecf7cb8 patch 8.1.0362: cannot get the script line number when executing a function
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
53
0a3b9ecf7cb8 patch 8.1.0362: cannot get the script line number when executing a function
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
54 " Line-continuation
0a3b9ecf7cb8 patch 8.1.0362: cannot get the script line number when executing a function
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
55 call assert_equal(
0a3b9ecf7cb8 patch 8.1.0362: cannot get the script line number when executing a function
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
56 \ 55,
0a3b9ecf7cb8 patch 8.1.0362: cannot get the script line number when executing a function
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
57 \ str2nr(expand('<sflnum>')))
0a3b9ecf7cb8 patch 8.1.0362: cannot get the script line number when executing a function
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
58
0a3b9ecf7cb8 patch 8.1.0362: cannot get the script line number when executing a function
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
59 " Call in script-local function
0a3b9ecf7cb8 patch 8.1.0362: cannot get the script line number when executing a function
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
60 call assert_equal(16, s:expand_sflnum())
0a3b9ecf7cb8 patch 8.1.0362: cannot get the script line number when executing a function
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
61
0a3b9ecf7cb8 patch 8.1.0362: cannot get the script line number when executing a function
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
62 " Call in command
0a3b9ecf7cb8 patch 8.1.0362: cannot get the script line number when executing a function
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
63 command Flnum echo expand('<sflnum>')
0a3b9ecf7cb8 patch 8.1.0362: cannot get the script line number when executing a function
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
64 call assert_equal(64, str2nr(trim(execute('Flnum'))))
0a3b9ecf7cb8 patch 8.1.0362: cannot get the script line number when executing a function
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
65 delcommand Flnum
0a3b9ecf7cb8 patch 8.1.0362: cannot get the script line number when executing a function
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
66 endfunc
16668
81be817c9d9a patch 8.1.1336: some eval functionality is not covered by tests
Bram Moolenaar <Bram@vim.org>
parents: 14700
diff changeset
67
81be817c9d9a patch 8.1.1336: some eval functionality is not covered by tests
Bram Moolenaar <Bram@vim.org>
parents: 14700
diff changeset
68 func Test_expand()
81be817c9d9a patch 8.1.1336: some eval functionality is not covered by tests
Bram Moolenaar <Bram@vim.org>
parents: 14700
diff changeset
69 new
81be817c9d9a patch 8.1.1336: some eval functionality is not covered by tests
Bram Moolenaar <Bram@vim.org>
parents: 14700
diff changeset
70 call assert_equal("", expand('%:S'))
17849
73ddc462979d patch 8.1.1921: more functions can be used as methods
Bram Moolenaar <Bram@vim.org>
parents: 16668
diff changeset
71 call assert_equal('3', '<slnum>'->expand())
16668
81be817c9d9a patch 8.1.1336: some eval functionality is not covered by tests
Bram Moolenaar <Bram@vim.org>
parents: 14700
diff changeset
72 call assert_equal(['4'], expand('<slnum>', v:false, v:true))
81be817c9d9a patch 8.1.1336: some eval functionality is not covered by tests
Bram Moolenaar <Bram@vim.org>
parents: 14700
diff changeset
73 " Don't add any line above this, otherwise <slnum> will change.
81be817c9d9a patch 8.1.1336: some eval functionality is not covered by tests
Bram Moolenaar <Bram@vim.org>
parents: 14700
diff changeset
74 quit
81be817c9d9a patch 8.1.1336: some eval functionality is not covered by tests
Bram Moolenaar <Bram@vim.org>
parents: 14700
diff changeset
75 endfunc