Bram Moolenaar | 58adb14 | 2016-01-16 21:50:51 +0100 | [diff] [blame] | 1 | " Test for expanding file names |
| 2 | |
| 3 | func Test_with_directories() |
| 4 | call mkdir('Xdir1') |
| 5 | call mkdir('Xdir2') |
| 6 | call mkdir('Xdir3') |
| 7 | cd Xdir3 |
| 8 | call mkdir('Xdir4') |
| 9 | cd .. |
| 10 | |
| 11 | split Xdir1/file |
| 12 | call setline(1, ['a', 'b']) |
| 13 | w |
| 14 | w Xdir3/Xdir4/file |
| 15 | close |
| 16 | |
| 17 | next Xdir?/*/file |
| 18 | call assert_equal('Xdir3/Xdir4/file', expand('%')) |
Bram Moolenaar | f60b796 | 2016-01-16 22:47:23 +0100 | [diff] [blame] | 19 | if has('unix') |
| 20 | next! Xdir?/*/nofile |
| 21 | call assert_equal('Xdir?/*/nofile', expand('%')) |
| 22 | endif |
Bram Moolenaar | 08b270a | 2016-01-17 18:34:19 +0100 | [diff] [blame] | 23 | " Edit another file, on MS-Windows the swap file would be in use and can't |
| 24 | " be deleted. |
| 25 | edit foo |
Bram Moolenaar | 58adb14 | 2016-01-16 21:50:51 +0100 | [diff] [blame] | 26 | |
Bram Moolenaar | 08b270a | 2016-01-17 18:34:19 +0100 | [diff] [blame] | 27 | call assert_equal(0, delete('Xdir1', 'rf')) |
| 28 | call assert_equal(0, delete('Xdir2', 'rf')) |
| 29 | call assert_equal(0, delete('Xdir3', 'rf')) |
Bram Moolenaar | 58adb14 | 2016-01-16 21:50:51 +0100 | [diff] [blame] | 30 | endfunc |
| 31 | |
| 32 | func Test_with_tilde() |
| 33 | let dir = getcwd() |
| 34 | call mkdir('Xdir ~ dir') |
| 35 | call assert_true(isdirectory('Xdir ~ dir')) |
| 36 | cd Xdir\ ~\ dir |
| 37 | call assert_true(getcwd() =~ 'Xdir \~ dir') |
| 38 | exe 'cd ' . fnameescape(dir) |
| 39 | call delete('Xdir ~ dir', 'd') |
| 40 | call assert_false(isdirectory('Xdir ~ dir')) |
| 41 | endfunc |
Bram Moolenaar | 00136dc | 2018-07-25 21:19:13 +0200 | [diff] [blame] | 42 | |
| 43 | func Test_expand_tilde_filename() |
| 44 | split ~ |
| 45 | call assert_equal('~', expand('%')) |
| 46 | call assert_notequal(expand('%:p'), expand('~/')) |
| 47 | call assert_match('\~', expand('%:p')) |
| 48 | bwipe! |
| 49 | endfunc |
Bram Moolenaar | 80dad48 | 2019-06-09 17:22:31 +0200 | [diff] [blame] | 50 | |
| 51 | func Test_expandcmd() |
| 52 | let $FOO = 'Test' |
| 53 | call assert_equal('e x/Test/y', expandcmd('e x/$FOO/y')) |
| 54 | unlet $FOO |
| 55 | |
| 56 | new |
| 57 | edit Xfile1 |
| 58 | call assert_equal('e Xfile1', expandcmd('e %')) |
| 59 | edit Xfile2 |
| 60 | edit Xfile1 |
Bram Moolenaar | a420896 | 2019-08-24 20:50:19 +0200 | [diff] [blame] | 61 | call assert_equal('e Xfile2', 'e #'->expandcmd()) |
Bram Moolenaar | 80dad48 | 2019-06-09 17:22:31 +0200 | [diff] [blame] | 62 | edit Xfile2 |
| 63 | edit Xfile3 |
| 64 | edit Xfile4 |
| 65 | let bnum = bufnr('Xfile2') |
| 66 | call assert_equal('e Xfile2', expandcmd('e #' . bnum)) |
| 67 | call setline('.', 'Vim!@#') |
| 68 | call assert_equal('e Vim', expandcmd('e <cword>')) |
| 69 | call assert_equal('e Vim!@#', expandcmd('e <cWORD>')) |
| 70 | enew! |
| 71 | edit Xfile.java |
| 72 | call assert_equal('e Xfile.py', expandcmd('e %:r.py')) |
| 73 | call assert_equal('make abc.java', expandcmd('make abc.%:e')) |
| 74 | call assert_equal('make Xabc.java', expandcmd('make %:s?file?abc?')) |
| 75 | edit a1a2a3.rb |
| 76 | call assert_equal('make b1b2b3.rb a1a2a3 Xfile.o', expandcmd('make %:gs?a?b? %< #<.o')) |
| 77 | |
| 78 | call assert_fails('call expandcmd("make <afile>")', 'E495:') |
| 79 | call assert_fails('call expandcmd("make <afile>")', 'E495:') |
| 80 | enew |
| 81 | call assert_fails('call expandcmd("make %")', 'E499:') |
| 82 | close |
| 83 | endfunc |