comparison src/testdir/test_expand_func.vim @ 21594:5daca8504c63 v8.2.1347

patch 8.2.1347: cannot easily get the script ID Commit: https://github.com/vim/vim/commit/909443028b57d7514ce3c71f00e9d808f2126b4f Author: Bram Moolenaar <Bram@vim.org> Date: Sat Aug 1 20:45:11 2020 +0200 patch 8.2.1347: cannot easily get the script ID Problem: Cannot easily get the script ID. Solution: Support expand('<SID>').
author Bram Moolenaar <Bram@vim.org>
date Sat, 01 Aug 2020 21:00:04 +0200
parents 7449921216bc
children a607f02fd17a
comparison
equal deleted inserted replaced
21593:6015f5f423ba 21594:5daca8504c63
1 " Tests for expand() 1 " Tests for expand()
2
3 source shared.vim
2 4
3 let s:sfile = expand('<sfile>') 5 let s:sfile = expand('<sfile>')
4 let s:slnum = str2nr(expand('<slnum>')) 6 let s:slnum = str2nr(expand('<slnum>'))
5 let s:sflnum = str2nr(expand('<sflnum>')) 7 let s:sflnum = str2nr(expand('<sflnum>'))
6 8
16 return str2nr(expand('<sflnum>')) 18 return str2nr(expand('<sflnum>'))
17 endfunc 19 endfunc
18 20
19 " This test depends on the location in the test file, put it first. 21 " This test depends on the location in the test file, put it first.
20 func Test_expand_sflnum() 22 func Test_expand_sflnum()
21 call assert_equal(5, s:sflnum) 23 call assert_equal(7, s:sflnum)
22 call assert_equal(22, str2nr(expand('<sflnum>'))) 24 call assert_equal(24, str2nr(expand('<sflnum>')))
23 25
24 " Line-continuation 26 " Line-continuation
25 call assert_equal( 27 call assert_equal(
26 \ 25, 28 \ 27,
27 \ str2nr(expand('<sflnum>'))) 29 \ str2nr(expand('<sflnum>')))
28 30
29 " Call in script-local function 31 " Call in script-local function
30 call assert_equal(16, s:expand_sflnum()) 32 call assert_equal(18, s:expand_sflnum())
31 33
32 " Call in command 34 " Call in command
33 command Flnum echo expand('<sflnum>') 35 command Flnum echo expand('<sflnum>')
34 call assert_equal(34, str2nr(trim(execute('Flnum')))) 36 call assert_equal(36, str2nr(trim(execute('Flnum'))))
35 delcommand Flnum 37 delcommand Flnum
36 endfunc 38 endfunc
37 39
38 func Test_expand_sfile_and_stack() 40 func Test_expand_sfile_and_stack()
39 call assert_match('test_expand_func\.vim$', s:sfile) 41 call assert_match('test_expand_func\.vim$', s:sfile)
58 call assert_match('\<Xstack$', g:stack_value) 60 call assert_match('\<Xstack$', g:stack_value)
59 call delete('Xstack') 61 call delete('Xstack')
60 endfunc 62 endfunc
61 63
62 func Test_expand_slnum() 64 func Test_expand_slnum()
63 call assert_equal(4, s:slnum) 65 call assert_equal(6, s:slnum)
64 call assert_equal(2, str2nr(expand('<slnum>'))) 66 call assert_equal(2, str2nr(expand('<slnum>')))
65 67
66 " Line-continuation 68 " Line-continuation
67 call assert_equal( 69 call assert_equal(
68 \ 5, 70 \ 5,
84 call assert_equal(['4'], expand('<slnum>', v:false, v:true)) 86 call assert_equal(['4'], expand('<slnum>', v:false, v:true))
85 " Don't add any line above this, otherwise <slnum> will change. 87 " Don't add any line above this, otherwise <slnum> will change.
86 quit 88 quit
87 endfunc 89 endfunc
88 90
91 func s:sid_test()
92 return 'works'
93 endfunc
94
95 func Test_expand_SID()
96 let sid = expand('<SID>')
97 execute 'let g:sid_result = ' .. sid .. 'sid_test()'
98 call assert_equal('works', g:sid_result)
99 endfunc
100
101
89 " Test for 'wildignore' with expand() 102 " Test for 'wildignore' with expand()
90 func Test_expand_wildignore() 103 func Test_expand_wildignore()
91 set wildignore=*.vim 104 set wildignore=*.vim
92 call assert_equal('', expand('test_expand_func.vim')) 105 call assert_equal('', expand('test_expand_func.vim'))
93 call assert_equal('', expand('test_expand_func.vim', 0)) 106 call assert_equal('', expand('test_expand_func.vim', 0))