Bram Moolenaar | f29c1c6 | 2018-09-10 21:05:02 +0200 | [diff] [blame] | 1 | " Tests for expand() |
| 2 | |
| 3 | let s:sfile = expand('<sfile>') |
| 4 | let s:slnum = str2nr(expand('<slnum>')) |
| 5 | let s:sflnum = str2nr(expand('<sflnum>')) |
| 6 | |
| 7 | func s:expand_sfile() |
| 8 | return expand('<sfile>') |
| 9 | endfunc |
| 10 | |
| 11 | func s:expand_slnum() |
| 12 | return str2nr(expand('<slnum>')) |
| 13 | endfunc |
| 14 | |
| 15 | func s:expand_sflnum() |
| 16 | return str2nr(expand('<sflnum>')) |
| 17 | endfunc |
| 18 | |
| 19 | func 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 |
| 30 | endfunc |
| 31 | |
| 32 | func 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 |
| 48 | endfunc |
| 49 | |
| 50 | func 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 |
| 66 | endfunc |
Bram Moolenaar | 17aca70 | 2019-05-16 22:24:55 +0200 | [diff] [blame] | 67 | |
| 68 | func Test_expand() |
| 69 | new |
| 70 | call assert_equal("", expand('%:S')) |
| 71 | call assert_equal('3', expand('<slnum>')) |
| 72 | call assert_equal(['4'], expand('<slnum>', v:false, v:true)) |
| 73 | " Don't add any line above this, otherwise <slnum> will change. |
| 74 | quit |
| 75 | endfunc |