1" Tests for expand()
2
3source shared.vim
4
5let s:sfile = expand('<sfile>')
6let s:slnum = str2nr(expand('<slnum>'))
7let s:sflnum = str2nr(expand('<sflnum>'))
8
9func s:expand_sfile()
10  return expand('<sfile>')
11endfunc
12
13func s:expand_slnum()
14  return str2nr(expand('<slnum>'))
15endfunc
16
17func s:expand_sflnum()
18  return str2nr(expand('<sflnum>'))
19endfunc
20
21" This test depends on the location in the test file, put it first.
22func Test_expand_sflnum()
23  call assert_equal(7, s:sflnum)
24  call assert_equal(24, str2nr(expand('<sflnum>')))
25
26  " Line-continuation
27  call assert_equal(
28        \ 27,
29        \ str2nr(expand('<sflnum>')))
30
31  " Call in script-local function
32  call assert_equal(18, s:expand_sflnum())
33
34  " Call in command
35  command Flnum echo expand('<sflnum>')
36  call assert_equal(36, str2nr(trim(execute('Flnum'))))
37  delcommand Flnum
38endfunc
39
40func Test_expand()
41  new
42  call assert_equal("",  expand('%:S'))
43  call assert_equal('3', '<slnum>'->expand())
44  call assert_equal(['4'], expand('<slnum>', v:false, v:true))
45  " Don't add any line above this, otherwise <slnum> will change.
46  quit
47endfunc
48
49func Test_expand_sfile()
50  call assert_match('test_expand_func\.vim$', s:sfile)
51  call assert_match('^function .*\.\.Test_expand_sfile$', expand('<sfile>'))
52
53  " Call in script-local function
54  call assert_match('^function .*\.\.Test_expand_sfile\[5\]\.\.<SNR>\d\+_expand_sfile$', s:expand_sfile())
55
56  " Call in command
57  command Sfile echo expand('<sfile>')
58  call assert_match('^function .*\.\.Test_expand_sfile$', trim(execute('Sfile')))
59  delcommand Sfile
60endfunc
61
62func Test_expand_slnum()
63  call assert_equal(6, s:slnum)
64  call assert_equal(2, str2nr(expand('<slnum>')))
65
66  " Line-continuation
67  call assert_equal(
68        \ 5,
69        \ str2nr(expand('<slnum>')))
70
71  " Call in script-local function
72  call assert_equal(1, s:expand_slnum())
73
74  " Call in command
75  command Slnum echo expand('<slnum>')
76  call assert_equal(14, str2nr(trim(execute('Slnum'))))
77  delcommand Slnum
78endfunc
79
80func s:sid_test()
81  return 'works'
82endfunc
83
84func Test_expand_SID()
85  let sid = expand('<SID>')
86  execute 'let g:sid_result = ' .. sid .. 'sid_test()'
87  call assert_equal('works', g:sid_result)
88endfunc
89
90" vim: shiftwidth=2 sts=2 expandtab
91