blob: 18437b75880b8dd8923bff4cef8518e2a39f35d2 [file] [log] [blame]
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001" Tests for expand()
2
3let s:sfile = expand('<sfile>')
4let s:slnum = str2nr(expand('<slnum>'))
5let s:sflnum = str2nr(expand('<sflnum>'))
6
7func s:expand_sfile()
8 return expand('<sfile>')
9endfunc
10
11func s:expand_slnum()
12 return str2nr(expand('<slnum>'))
13endfunc
14
15func s:expand_sflnum()
16 return str2nr(expand('<sflnum>'))
17endfunc
18
19func Test_expand_sfile()
20 call assert_match('test_expand_func\.vim$', s:sfile)
21 call assert_match('^function .*\.\.Test_expand_sfile$', expand('<sfile>'))
22
23 " Call in script-local function
24 call assert_match('^function .*\.\.Test_expand_sfile\[5\]\.\.<SNR>\d\+_expand_sfile$', s:expand_sfile())
25
26 " Call in command
27 command Sfile echo expand('<sfile>')
28 call assert_match('^function .*\.\.Test_expand_sfile$', trim(execute('Sfile')))
29 delcommand Sfile
30endfunc
31
32func Test_expand_slnum()
33 call assert_equal(4, s:slnum)
34 call assert_equal(2, str2nr(expand('<slnum>')))
35
36 " Line-continuation
37 call assert_equal(
38 \ 5,
39 \ str2nr(expand('<slnum>')))
40
41 " Call in script-local function
42 call assert_equal(1, s:expand_slnum())
43
44 " Call in command
45 command Slnum echo expand('<slnum>')
46 call assert_equal(14, str2nr(trim(execute('Slnum'))))
47 delcommand Slnum
48endfunc
49
50func Test_expand_sflnum()
51 call assert_equal(5, s:sflnum)
52 call assert_equal(52, str2nr(expand('<sflnum>')))
53
54 " Line-continuation
55 call assert_equal(
56 \ 55,
57 \ str2nr(expand('<sflnum>')))
58
59 " Call in script-local function
60 call assert_equal(16, s:expand_sflnum())
61
62 " Call in command
63 command Flnum echo expand('<sflnum>')
64 call assert_equal(64, str2nr(trim(execute('Flnum'))))
65 delcommand Flnum
66endfunc
Bram Moolenaar17aca702019-05-16 22:24:55 +020067
68func Test_expand()
69 new
70 call assert_equal("", expand('%:S'))
Bram Moolenaara4208962019-08-24 20:50:19 +020071 call assert_equal('3', '<slnum>'->expand())
Bram Moolenaar17aca702019-05-16 22:24:55 +020072 call assert_equal(['4'], expand('<slnum>', v:false, v:true))
73 " Don't add any line above this, otherwise <slnum> will change.
74 quit
75endfunc
Bram Moolenaarbd7206e2020-03-06 20:36:04 +010076
77" Test for 'wildignore' with expand()
78func Test_expand_wildignore()
79 set wildignore=*.vim
80 call assert_equal('', expand('test_expand_func.vim'))
81 call assert_equal('', expand('test_expand_func.vim', 0))
82 call assert_equal([], expand('test_expand_func.vim', 0, 1))
83 call assert_equal('test_expand_func.vim', expand('test_expand_func.vim', 1))
84 call assert_equal(['test_expand_func.vim'],
85 \ expand('test_expand_func.vim', 1, 1))
Bram Moolenaar0e05de42020-03-25 22:23:46 +010086 call assert_fails("call expand('*', [])", 'E745:')
Bram Moolenaarbd7206e2020-03-06 20:36:04 +010087 set wildignore&
88endfunc
89
90" vim: shiftwidth=2 sts=2 expandtab