annotate src/testdir/test_expand_func.vim @ 23303:9af15022894c v8.2.2197

patch 8.2.2197: assert arguments order reversed Commit: https://github.com/vim/vim/commit/9f63a65f22b6a899925ba15adbb711e86251114e Author: Bram Moolenaar <Bram@vim.org> Date: Wed Dec 23 12:50:20 2020 +0100 patch 8.2.2197: assert arguments order reversed Problem: Assert arguments order reversed. Solution: Swap the arguments. (Christian Brabandt, closes https://github.com/vim/vim/issues/7531)
author Bram Moolenaar <Bram@vim.org>
date Wed, 23 Dec 2020 13:00:04 +0100
parents 195a617b405a
children dfe18756f2ad
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
21594
5daca8504c63 patch 8.2.1347: cannot easily get the script ID
Bram Moolenaar <Bram@vim.org>
parents: 21493
diff changeset
3 source shared.vim
5daca8504c63 patch 8.2.1347: cannot easily get the script ID
Bram Moolenaar <Bram@vim.org>
parents: 21493
diff changeset
4
14700
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: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
6 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
7 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
8
0a3b9ecf7cb8 patch 8.1.0362: cannot get the script line number when executing a function
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
9 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
10 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
11 endfunc
0a3b9ecf7cb8 patch 8.1.0362: cannot get the script line number when executing a function
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
12
0a3b9ecf7cb8 patch 8.1.0362: cannot get the script line number when executing a function
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
13 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
14 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
15 endfunc
0a3b9ecf7cb8 patch 8.1.0362: cannot get the script line number when executing a function
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
16
0a3b9ecf7cb8 patch 8.1.0362: cannot get the script line number when executing a function
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
17 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
18 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
19 endfunc
0a3b9ecf7cb8 patch 8.1.0362: cannot get the script line number when executing a function
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
20
21493
7449921216bc patch 8.2.1297: when a test fails it's often not easy to see where
Bram Moolenaar <Bram@vim.org>
parents: 19783
diff changeset
21 " This test depends on the location in the test file, put it first.
7449921216bc patch 8.2.1297: when a test fails it's often not easy to see where
Bram Moolenaar <Bram@vim.org>
parents: 19783
diff changeset
22 func Test_expand_sflnum()
21594
5daca8504c63 patch 8.2.1347: cannot easily get the script ID
Bram Moolenaar <Bram@vim.org>
parents: 21493
diff changeset
23 call assert_equal(7, s:sflnum)
5daca8504c63 patch 8.2.1347: cannot easily get the script ID
Bram Moolenaar <Bram@vim.org>
parents: 21493
diff changeset
24 call assert_equal(24, str2nr(expand('<sflnum>')))
21493
7449921216bc patch 8.2.1297: when a test fails it's often not easy to see where
Bram Moolenaar <Bram@vim.org>
parents: 19783
diff changeset
25
7449921216bc patch 8.2.1297: when a test fails it's often not easy to see where
Bram Moolenaar <Bram@vim.org>
parents: 19783
diff changeset
26 " Line-continuation
7449921216bc patch 8.2.1297: when a test fails it's often not easy to see where
Bram Moolenaar <Bram@vim.org>
parents: 19783
diff changeset
27 call assert_equal(
21594
5daca8504c63 patch 8.2.1347: cannot easily get the script ID
Bram Moolenaar <Bram@vim.org>
parents: 21493
diff changeset
28 \ 27,
21493
7449921216bc patch 8.2.1297: when a test fails it's often not easy to see where
Bram Moolenaar <Bram@vim.org>
parents: 19783
diff changeset
29 \ str2nr(expand('<sflnum>')))
14700
0a3b9ecf7cb8 patch 8.1.0362: cannot get the script line number when executing a function
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
30
0a3b9ecf7cb8 patch 8.1.0362: cannot get the script line number when executing a function
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
31 " Call in script-local function
21594
5daca8504c63 patch 8.2.1347: cannot easily get the script ID
Bram Moolenaar <Bram@vim.org>
parents: 21493
diff changeset
32 call assert_equal(18, s:expand_sflnum())
21493
7449921216bc patch 8.2.1297: when a test fails it's often not easy to see where
Bram Moolenaar <Bram@vim.org>
parents: 19783
diff changeset
33
7449921216bc patch 8.2.1297: when a test fails it's often not easy to see where
Bram Moolenaar <Bram@vim.org>
parents: 19783
diff changeset
34 " Call in command
7449921216bc patch 8.2.1297: when a test fails it's often not easy to see where
Bram Moolenaar <Bram@vim.org>
parents: 19783
diff changeset
35 command Flnum echo expand('<sflnum>')
21594
5daca8504c63 patch 8.2.1347: cannot easily get the script ID
Bram Moolenaar <Bram@vim.org>
parents: 21493
diff changeset
36 call assert_equal(36, str2nr(trim(execute('Flnum'))))
21493
7449921216bc patch 8.2.1297: when a test fails it's often not easy to see where
Bram Moolenaar <Bram@vim.org>
parents: 19783
diff changeset
37 delcommand Flnum
7449921216bc patch 8.2.1297: when a test fails it's often not easy to see where
Bram Moolenaar <Bram@vim.org>
parents: 19783
diff changeset
38 endfunc
7449921216bc patch 8.2.1297: when a test fails it's often not easy to see where
Bram Moolenaar <Bram@vim.org>
parents: 19783
diff changeset
39
7449921216bc patch 8.2.1297: when a test fails it's often not easy to see where
Bram Moolenaar <Bram@vim.org>
parents: 19783
diff changeset
40 func Test_expand_sfile_and_stack()
7449921216bc patch 8.2.1297: when a test fails it's often not easy to see where
Bram Moolenaar <Bram@vim.org>
parents: 19783
diff changeset
41 call assert_match('test_expand_func\.vim$', s:sfile)
22208
a607f02fd17a patch 8.2.1653: expand('<stack>') does not include the final line number
Bram Moolenaar <Bram@vim.org>
parents: 21594
diff changeset
42 let expected = 'script .*testdir/runtest.vim\[\d\+\]\.\.function RunTheTest\[\d\+\]\.\.Test_expand_sfile_and_stack'
a607f02fd17a patch 8.2.1653: expand('<stack>') does not include the final line number
Bram Moolenaar <Bram@vim.org>
parents: 21594
diff changeset
43 call assert_match(expected .. '$', expand('<sfile>'))
a607f02fd17a patch 8.2.1653: expand('<stack>') does not include the final line number
Bram Moolenaar <Bram@vim.org>
parents: 21594
diff changeset
44 call assert_match(expected .. '\[4\]' , expand('<stack>'))
21493
7449921216bc patch 8.2.1297: when a test fails it's often not easy to see where
Bram Moolenaar <Bram@vim.org>
parents: 19783
diff changeset
45
7449921216bc patch 8.2.1297: when a test fails it's often not easy to see where
Bram Moolenaar <Bram@vim.org>
parents: 19783
diff changeset
46 " Call in script-local function
7449921216bc patch 8.2.1297: when a test fails it's often not easy to see where
Bram Moolenaar <Bram@vim.org>
parents: 19783
diff changeset
47 call assert_match('script .*testdir/runtest.vim\[\d\+\]\.\.function RunTheTest\[\d\+\]\.\.Test_expand_sfile_and_stack\[7\]\.\.<SNR>\d\+_expand_sfile$', s:expand_sfile())
14700
0a3b9ecf7cb8 patch 8.1.0362: cannot get the script line number when executing a function
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
48
0a3b9ecf7cb8 patch 8.1.0362: cannot get the script line number when executing a function
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
49 " 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
50 command Sfile echo expand('<sfile>')
21493
7449921216bc patch 8.2.1297: when a test fails it's often not easy to see where
Bram Moolenaar <Bram@vim.org>
parents: 19783
diff changeset
51 call assert_match('script .*testdir/runtest.vim\[\d\+\]\.\.function RunTheTest\[\d\+\]\.\.Test_expand_sfile_and_stack$', trim(execute('Sfile')))
14700
0a3b9ecf7cb8 patch 8.1.0362: cannot get the script line number when executing a function
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
52 delcommand Sfile
21493
7449921216bc patch 8.2.1297: when a test fails it's often not easy to see where
Bram Moolenaar <Bram@vim.org>
parents: 19783
diff changeset
53
7449921216bc patch 8.2.1297: when a test fails it's often not easy to see where
Bram Moolenaar <Bram@vim.org>
parents: 19783
diff changeset
54 " Use <stack> from sourced script.
7449921216bc patch 8.2.1297: when a test fails it's often not easy to see where
Bram Moolenaar <Bram@vim.org>
parents: 19783
diff changeset
55 let lines =<< trim END
22208
a607f02fd17a patch 8.2.1653: expand('<stack>') does not include the final line number
Bram Moolenaar <Bram@vim.org>
parents: 21594
diff changeset
56 " comment here
21493
7449921216bc patch 8.2.1297: when a test fails it's often not easy to see where
Bram Moolenaar <Bram@vim.org>
parents: 19783
diff changeset
57 let g:stack_value = expand('<stack>')
7449921216bc patch 8.2.1297: when a test fails it's often not easy to see where
Bram Moolenaar <Bram@vim.org>
parents: 19783
diff changeset
58 END
7449921216bc patch 8.2.1297: when a test fails it's often not easy to see where
Bram Moolenaar <Bram@vim.org>
parents: 19783
diff changeset
59 call writefile(lines, 'Xstack')
7449921216bc patch 8.2.1297: when a test fails it's often not easy to see where
Bram Moolenaar <Bram@vim.org>
parents: 19783
diff changeset
60 source Xstack
22218
195a617b405a patch 8.2.1658: expand('<stack>') has trailing ".."
Bram Moolenaar <Bram@vim.org>
parents: 22208
diff changeset
61 call assert_match('\<Xstack\[2\]$', g:stack_value)
21493
7449921216bc patch 8.2.1297: when a test fails it's often not easy to see where
Bram Moolenaar <Bram@vim.org>
parents: 19783
diff changeset
62 call delete('Xstack')
14700
0a3b9ecf7cb8 patch 8.1.0362: cannot get the script line number when executing a function
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
63 endfunc
0a3b9ecf7cb8 patch 8.1.0362: cannot get the script line number when executing a function
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
64
0a3b9ecf7cb8 patch 8.1.0362: cannot get the script line number when executing a function
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
65 func Test_expand_slnum()
21594
5daca8504c63 patch 8.2.1347: cannot easily get the script ID
Bram Moolenaar <Bram@vim.org>
parents: 21493
diff changeset
66 call assert_equal(6, s:slnum)
14700
0a3b9ecf7cb8 patch 8.1.0362: cannot get the script line number when executing a function
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
67 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
68
0a3b9ecf7cb8 patch 8.1.0362: cannot get the script line number when executing a function
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
69 " 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
70 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
71 \ 5,
0a3b9ecf7cb8 patch 8.1.0362: cannot get the script line number when executing a function
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
72 \ 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
73
0a3b9ecf7cb8 patch 8.1.0362: cannot get the script line number when executing a function
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
74 " 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
75 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
76
0a3b9ecf7cb8 patch 8.1.0362: cannot get the script line number when executing a function
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
77 " 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
78 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
79 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
80 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
81 endfunc
0a3b9ecf7cb8 patch 8.1.0362: cannot get the script line number when executing a function
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
82
16668
81be817c9d9a patch 8.1.1336: some eval functionality is not covered by tests
Bram Moolenaar <Bram@vim.org>
parents: 14700
diff changeset
83 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
84 new
81be817c9d9a patch 8.1.1336: some eval functionality is not covered by tests
Bram Moolenaar <Bram@vim.org>
parents: 14700
diff changeset
85 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
86 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
87 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
88 " 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
89 quit
81be817c9d9a patch 8.1.1336: some eval functionality is not covered by tests
Bram Moolenaar <Bram@vim.org>
parents: 14700
diff changeset
90 endfunc
19603
6d3c683466f4 patch 8.2.0358: insufficient testing for indent.c
Bram Moolenaar <Bram@vim.org>
parents: 17849
diff changeset
91
21594
5daca8504c63 patch 8.2.1347: cannot easily get the script ID
Bram Moolenaar <Bram@vim.org>
parents: 21493
diff changeset
92 func s:sid_test()
5daca8504c63 patch 8.2.1347: cannot easily get the script ID
Bram Moolenaar <Bram@vim.org>
parents: 21493
diff changeset
93 return 'works'
5daca8504c63 patch 8.2.1347: cannot easily get the script ID
Bram Moolenaar <Bram@vim.org>
parents: 21493
diff changeset
94 endfunc
5daca8504c63 patch 8.2.1347: cannot easily get the script ID
Bram Moolenaar <Bram@vim.org>
parents: 21493
diff changeset
95
5daca8504c63 patch 8.2.1347: cannot easily get the script ID
Bram Moolenaar <Bram@vim.org>
parents: 21493
diff changeset
96 func Test_expand_SID()
5daca8504c63 patch 8.2.1347: cannot easily get the script ID
Bram Moolenaar <Bram@vim.org>
parents: 21493
diff changeset
97 let sid = expand('<SID>')
5daca8504c63 patch 8.2.1347: cannot easily get the script ID
Bram Moolenaar <Bram@vim.org>
parents: 21493
diff changeset
98 execute 'let g:sid_result = ' .. sid .. 'sid_test()'
5daca8504c63 patch 8.2.1347: cannot easily get the script ID
Bram Moolenaar <Bram@vim.org>
parents: 21493
diff changeset
99 call assert_equal('works', g:sid_result)
5daca8504c63 patch 8.2.1347: cannot easily get the script ID
Bram Moolenaar <Bram@vim.org>
parents: 21493
diff changeset
100 endfunc
5daca8504c63 patch 8.2.1347: cannot easily get the script ID
Bram Moolenaar <Bram@vim.org>
parents: 21493
diff changeset
101
5daca8504c63 patch 8.2.1347: cannot easily get the script ID
Bram Moolenaar <Bram@vim.org>
parents: 21493
diff changeset
102
19603
6d3c683466f4 patch 8.2.0358: insufficient testing for indent.c
Bram Moolenaar <Bram@vim.org>
parents: 17849
diff changeset
103 " Test for 'wildignore' with expand()
6d3c683466f4 patch 8.2.0358: insufficient testing for indent.c
Bram Moolenaar <Bram@vim.org>
parents: 17849
diff changeset
104 func Test_expand_wildignore()
6d3c683466f4 patch 8.2.0358: insufficient testing for indent.c
Bram Moolenaar <Bram@vim.org>
parents: 17849
diff changeset
105 set wildignore=*.vim
6d3c683466f4 patch 8.2.0358: insufficient testing for indent.c
Bram Moolenaar <Bram@vim.org>
parents: 17849
diff changeset
106 call assert_equal('', expand('test_expand_func.vim'))
6d3c683466f4 patch 8.2.0358: insufficient testing for indent.c
Bram Moolenaar <Bram@vim.org>
parents: 17849
diff changeset
107 call assert_equal('', expand('test_expand_func.vim', 0))
6d3c683466f4 patch 8.2.0358: insufficient testing for indent.c
Bram Moolenaar <Bram@vim.org>
parents: 17849
diff changeset
108 call assert_equal([], expand('test_expand_func.vim', 0, 1))
6d3c683466f4 patch 8.2.0358: insufficient testing for indent.c
Bram Moolenaar <Bram@vim.org>
parents: 17849
diff changeset
109 call assert_equal('test_expand_func.vim', expand('test_expand_func.vim', 1))
6d3c683466f4 patch 8.2.0358: insufficient testing for indent.c
Bram Moolenaar <Bram@vim.org>
parents: 17849
diff changeset
110 call assert_equal(['test_expand_func.vim'],
6d3c683466f4 patch 8.2.0358: insufficient testing for indent.c
Bram Moolenaar <Bram@vim.org>
parents: 17849
diff changeset
111 \ expand('test_expand_func.vim', 1, 1))
19783
546bdeef35f1 patch 8.2.0448: various functions not properly tested
Bram Moolenaar <Bram@vim.org>
parents: 19603
diff changeset
112 call assert_fails("call expand('*', [])", 'E745:')
19603
6d3c683466f4 patch 8.2.0358: insufficient testing for indent.c
Bram Moolenaar <Bram@vim.org>
parents: 17849
diff changeset
113 set wildignore&
6d3c683466f4 patch 8.2.0358: insufficient testing for indent.c
Bram Moolenaar <Bram@vim.org>
parents: 17849
diff changeset
114 endfunc
6d3c683466f4 patch 8.2.0358: insufficient testing for indent.c
Bram Moolenaar <Bram@vim.org>
parents: 17849
diff changeset
115
6d3c683466f4 patch 8.2.0358: insufficient testing for indent.c
Bram Moolenaar <Bram@vim.org>
parents: 17849
diff changeset
116 " vim: shiftwidth=2 sts=2 expandtab