annotate src/testdir/test_expand.vim @ 17437:5f71f12bdb8c

Added tag v8.1.1716 for changeset e1b5c15f5fee70aaa68aa8286030cf713a403aee
author Bram Moolenaar <Bram@vim.org>
date Fri, 19 Jul 2019 23:30:05 +0200
parents 1841c03a9b5e
children 73ddc462979d
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
7617
80bc36419c21 commit https://github.com/vim/vim/commit/58adb14739fa240ca6020cede9ab1f1cb07bd90a
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1 " Test for expanding file names
80bc36419c21 commit https://github.com/vim/vim/commit/58adb14739fa240ca6020cede9ab1f1cb07bd90a
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2
80bc36419c21 commit https://github.com/vim/vim/commit/58adb14739fa240ca6020cede9ab1f1cb07bd90a
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3 func Test_with_directories()
80bc36419c21 commit https://github.com/vim/vim/commit/58adb14739fa240ca6020cede9ab1f1cb07bd90a
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4 call mkdir('Xdir1')
80bc36419c21 commit https://github.com/vim/vim/commit/58adb14739fa240ca6020cede9ab1f1cb07bd90a
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5 call mkdir('Xdir2')
80bc36419c21 commit https://github.com/vim/vim/commit/58adb14739fa240ca6020cede9ab1f1cb07bd90a
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6 call mkdir('Xdir3')
80bc36419c21 commit https://github.com/vim/vim/commit/58adb14739fa240ca6020cede9ab1f1cb07bd90a
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
7 cd Xdir3
80bc36419c21 commit https://github.com/vim/vim/commit/58adb14739fa240ca6020cede9ab1f1cb07bd90a
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
8 call mkdir('Xdir4')
80bc36419c21 commit https://github.com/vim/vim/commit/58adb14739fa240ca6020cede9ab1f1cb07bd90a
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
9 cd ..
80bc36419c21 commit https://github.com/vim/vim/commit/58adb14739fa240ca6020cede9ab1f1cb07bd90a
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
10
80bc36419c21 commit https://github.com/vim/vim/commit/58adb14739fa240ca6020cede9ab1f1cb07bd90a
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
11 split Xdir1/file
80bc36419c21 commit https://github.com/vim/vim/commit/58adb14739fa240ca6020cede9ab1f1cb07bd90a
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
12 call setline(1, ['a', 'b'])
80bc36419c21 commit https://github.com/vim/vim/commit/58adb14739fa240ca6020cede9ab1f1cb07bd90a
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
13 w
80bc36419c21 commit https://github.com/vim/vim/commit/58adb14739fa240ca6020cede9ab1f1cb07bd90a
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
14 w Xdir3/Xdir4/file
80bc36419c21 commit https://github.com/vim/vim/commit/58adb14739fa240ca6020cede9ab1f1cb07bd90a
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
15 close
80bc36419c21 commit https://github.com/vim/vim/commit/58adb14739fa240ca6020cede9ab1f1cb07bd90a
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
16
80bc36419c21 commit https://github.com/vim/vim/commit/58adb14739fa240ca6020cede9ab1f1cb07bd90a
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
17 next Xdir?/*/file
80bc36419c21 commit https://github.com/vim/vim/commit/58adb14739fa240ca6020cede9ab1f1cb07bd90a
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
18 call assert_equal('Xdir3/Xdir4/file', expand('%'))
7623
2720952e9acb commit https://github.com/vim/vim/commit/f60b796fa9870bdfc4cdeb91653bac041916077d
Christian Brabandt <cb@256bit.org>
parents: 7617
diff changeset
19 if has('unix')
2720952e9acb commit https://github.com/vim/vim/commit/f60b796fa9870bdfc4cdeb91653bac041916077d
Christian Brabandt <cb@256bit.org>
parents: 7617
diff changeset
20 next! Xdir?/*/nofile
2720952e9acb commit https://github.com/vim/vim/commit/f60b796fa9870bdfc4cdeb91653bac041916077d
Christian Brabandt <cb@256bit.org>
parents: 7617
diff changeset
21 call assert_equal('Xdir?/*/nofile', expand('%'))
2720952e9acb commit https://github.com/vim/vim/commit/f60b796fa9870bdfc4cdeb91653bac041916077d
Christian Brabandt <cb@256bit.org>
parents: 7617
diff changeset
22 endif
7643
2b2e90fcd72b commit https://github.com/vim/vim/commit/08b270a8a4544be9a7fecce311834fde2b457634
Christian Brabandt <cb@256bit.org>
parents: 7623
diff changeset
23 " Edit another file, on MS-Windows the swap file would be in use and can't
2b2e90fcd72b commit https://github.com/vim/vim/commit/08b270a8a4544be9a7fecce311834fde2b457634
Christian Brabandt <cb@256bit.org>
parents: 7623
diff changeset
24 " be deleted.
2b2e90fcd72b commit https://github.com/vim/vim/commit/08b270a8a4544be9a7fecce311834fde2b457634
Christian Brabandt <cb@256bit.org>
parents: 7623
diff changeset
25 edit foo
7617
80bc36419c21 commit https://github.com/vim/vim/commit/58adb14739fa240ca6020cede9ab1f1cb07bd90a
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
26
7643
2b2e90fcd72b commit https://github.com/vim/vim/commit/08b270a8a4544be9a7fecce311834fde2b457634
Christian Brabandt <cb@256bit.org>
parents: 7623
diff changeset
27 call assert_equal(0, delete('Xdir1', 'rf'))
2b2e90fcd72b commit https://github.com/vim/vim/commit/08b270a8a4544be9a7fecce311834fde2b457634
Christian Brabandt <cb@256bit.org>
parents: 7623
diff changeset
28 call assert_equal(0, delete('Xdir2', 'rf'))
2b2e90fcd72b commit https://github.com/vim/vim/commit/08b270a8a4544be9a7fecce311834fde2b457634
Christian Brabandt <cb@256bit.org>
parents: 7623
diff changeset
29 call assert_equal(0, delete('Xdir3', 'rf'))
7617
80bc36419c21 commit https://github.com/vim/vim/commit/58adb14739fa240ca6020cede9ab1f1cb07bd90a
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
30 endfunc
80bc36419c21 commit https://github.com/vim/vim/commit/58adb14739fa240ca6020cede9ab1f1cb07bd90a
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
31
80bc36419c21 commit https://github.com/vim/vim/commit/58adb14739fa240ca6020cede9ab1f1cb07bd90a
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
32 func Test_with_tilde()
80bc36419c21 commit https://github.com/vim/vim/commit/58adb14739fa240ca6020cede9ab1f1cb07bd90a
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
33 let dir = getcwd()
80bc36419c21 commit https://github.com/vim/vim/commit/58adb14739fa240ca6020cede9ab1f1cb07bd90a
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
34 call mkdir('Xdir ~ dir')
80bc36419c21 commit https://github.com/vim/vim/commit/58adb14739fa240ca6020cede9ab1f1cb07bd90a
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
35 call assert_true(isdirectory('Xdir ~ dir'))
80bc36419c21 commit https://github.com/vim/vim/commit/58adb14739fa240ca6020cede9ab1f1cb07bd90a
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
36 cd Xdir\ ~\ dir
80bc36419c21 commit https://github.com/vim/vim/commit/58adb14739fa240ca6020cede9ab1f1cb07bd90a
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
37 call assert_true(getcwd() =~ 'Xdir \~ dir')
80bc36419c21 commit https://github.com/vim/vim/commit/58adb14739fa240ca6020cede9ab1f1cb07bd90a
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
38 exe 'cd ' . fnameescape(dir)
80bc36419c21 commit https://github.com/vim/vim/commit/58adb14739fa240ca6020cede9ab1f1cb07bd90a
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
39 call delete('Xdir ~ dir', 'd')
80bc36419c21 commit https://github.com/vim/vim/commit/58adb14739fa240ca6020cede9ab1f1cb07bd90a
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
40 call assert_false(isdirectory('Xdir ~ dir'))
80bc36419c21 commit https://github.com/vim/vim/commit/58adb14739fa240ca6020cede9ab1f1cb07bd90a
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
41 endfunc
14393
c62601adad69 patch 8.1.0211: expanding a file name "~" results in $HOME
Christian Brabandt <cb@256bit.org>
parents: 7643
diff changeset
42
c62601adad69 patch 8.1.0211: expanding a file name "~" results in $HOME
Christian Brabandt <cb@256bit.org>
parents: 7643
diff changeset
43 func Test_expand_tilde_filename()
c62601adad69 patch 8.1.0211: expanding a file name "~" results in $HOME
Christian Brabandt <cb@256bit.org>
parents: 7643
diff changeset
44 split ~
c62601adad69 patch 8.1.0211: expanding a file name "~" results in $HOME
Christian Brabandt <cb@256bit.org>
parents: 7643
diff changeset
45 call assert_equal('~', expand('%'))
c62601adad69 patch 8.1.0211: expanding a file name "~" results in $HOME
Christian Brabandt <cb@256bit.org>
parents: 7643
diff changeset
46 call assert_notequal(expand('%:p'), expand('~/'))
c62601adad69 patch 8.1.0211: expanding a file name "~" results in $HOME
Christian Brabandt <cb@256bit.org>
parents: 7643
diff changeset
47 call assert_match('\~', expand('%:p'))
c62601adad69 patch 8.1.0211: expanding a file name "~" results in $HOME
Christian Brabandt <cb@256bit.org>
parents: 7643
diff changeset
48 bwipe!
c62601adad69 patch 8.1.0211: expanding a file name "~" results in $HOME
Christian Brabandt <cb@256bit.org>
parents: 7643
diff changeset
49 endfunc
17020
1841c03a9b5e patch 8.1.1510: a plugin cannot easily expand a command like done internally
Bram Moolenaar <Bram@vim.org>
parents: 14393
diff changeset
50
1841c03a9b5e patch 8.1.1510: a plugin cannot easily expand a command like done internally
Bram Moolenaar <Bram@vim.org>
parents: 14393
diff changeset
51 func Test_expandcmd()
1841c03a9b5e patch 8.1.1510: a plugin cannot easily expand a command like done internally
Bram Moolenaar <Bram@vim.org>
parents: 14393
diff changeset
52 let $FOO = 'Test'
1841c03a9b5e patch 8.1.1510: a plugin cannot easily expand a command like done internally
Bram Moolenaar <Bram@vim.org>
parents: 14393
diff changeset
53 call assert_equal('e x/Test/y', expandcmd('e x/$FOO/y'))
1841c03a9b5e patch 8.1.1510: a plugin cannot easily expand a command like done internally
Bram Moolenaar <Bram@vim.org>
parents: 14393
diff changeset
54 unlet $FOO
1841c03a9b5e patch 8.1.1510: a plugin cannot easily expand a command like done internally
Bram Moolenaar <Bram@vim.org>
parents: 14393
diff changeset
55
1841c03a9b5e patch 8.1.1510: a plugin cannot easily expand a command like done internally
Bram Moolenaar <Bram@vim.org>
parents: 14393
diff changeset
56 new
1841c03a9b5e patch 8.1.1510: a plugin cannot easily expand a command like done internally
Bram Moolenaar <Bram@vim.org>
parents: 14393
diff changeset
57 edit Xfile1
1841c03a9b5e patch 8.1.1510: a plugin cannot easily expand a command like done internally
Bram Moolenaar <Bram@vim.org>
parents: 14393
diff changeset
58 call assert_equal('e Xfile1', expandcmd('e %'))
1841c03a9b5e patch 8.1.1510: a plugin cannot easily expand a command like done internally
Bram Moolenaar <Bram@vim.org>
parents: 14393
diff changeset
59 edit Xfile2
1841c03a9b5e patch 8.1.1510: a plugin cannot easily expand a command like done internally
Bram Moolenaar <Bram@vim.org>
parents: 14393
diff changeset
60 edit Xfile1
1841c03a9b5e patch 8.1.1510: a plugin cannot easily expand a command like done internally
Bram Moolenaar <Bram@vim.org>
parents: 14393
diff changeset
61 call assert_equal('e Xfile2', expandcmd('e #'))
1841c03a9b5e patch 8.1.1510: a plugin cannot easily expand a command like done internally
Bram Moolenaar <Bram@vim.org>
parents: 14393
diff changeset
62 edit Xfile2
1841c03a9b5e patch 8.1.1510: a plugin cannot easily expand a command like done internally
Bram Moolenaar <Bram@vim.org>
parents: 14393
diff changeset
63 edit Xfile3
1841c03a9b5e patch 8.1.1510: a plugin cannot easily expand a command like done internally
Bram Moolenaar <Bram@vim.org>
parents: 14393
diff changeset
64 edit Xfile4
1841c03a9b5e patch 8.1.1510: a plugin cannot easily expand a command like done internally
Bram Moolenaar <Bram@vim.org>
parents: 14393
diff changeset
65 let bnum = bufnr('Xfile2')
1841c03a9b5e patch 8.1.1510: a plugin cannot easily expand a command like done internally
Bram Moolenaar <Bram@vim.org>
parents: 14393
diff changeset
66 call assert_equal('e Xfile2', expandcmd('e #' . bnum))
1841c03a9b5e patch 8.1.1510: a plugin cannot easily expand a command like done internally
Bram Moolenaar <Bram@vim.org>
parents: 14393
diff changeset
67 call setline('.', 'Vim!@#')
1841c03a9b5e patch 8.1.1510: a plugin cannot easily expand a command like done internally
Bram Moolenaar <Bram@vim.org>
parents: 14393
diff changeset
68 call assert_equal('e Vim', expandcmd('e <cword>'))
1841c03a9b5e patch 8.1.1510: a plugin cannot easily expand a command like done internally
Bram Moolenaar <Bram@vim.org>
parents: 14393
diff changeset
69 call assert_equal('e Vim!@#', expandcmd('e <cWORD>'))
1841c03a9b5e patch 8.1.1510: a plugin cannot easily expand a command like done internally
Bram Moolenaar <Bram@vim.org>
parents: 14393
diff changeset
70 enew!
1841c03a9b5e patch 8.1.1510: a plugin cannot easily expand a command like done internally
Bram Moolenaar <Bram@vim.org>
parents: 14393
diff changeset
71 edit Xfile.java
1841c03a9b5e patch 8.1.1510: a plugin cannot easily expand a command like done internally
Bram Moolenaar <Bram@vim.org>
parents: 14393
diff changeset
72 call assert_equal('e Xfile.py', expandcmd('e %:r.py'))
1841c03a9b5e patch 8.1.1510: a plugin cannot easily expand a command like done internally
Bram Moolenaar <Bram@vim.org>
parents: 14393
diff changeset
73 call assert_equal('make abc.java', expandcmd('make abc.%:e'))
1841c03a9b5e patch 8.1.1510: a plugin cannot easily expand a command like done internally
Bram Moolenaar <Bram@vim.org>
parents: 14393
diff changeset
74 call assert_equal('make Xabc.java', expandcmd('make %:s?file?abc?'))
1841c03a9b5e patch 8.1.1510: a plugin cannot easily expand a command like done internally
Bram Moolenaar <Bram@vim.org>
parents: 14393
diff changeset
75 edit a1a2a3.rb
1841c03a9b5e patch 8.1.1510: a plugin cannot easily expand a command like done internally
Bram Moolenaar <Bram@vim.org>
parents: 14393
diff changeset
76 call assert_equal('make b1b2b3.rb a1a2a3 Xfile.o', expandcmd('make %:gs?a?b? %< #<.o'))
1841c03a9b5e patch 8.1.1510: a plugin cannot easily expand a command like done internally
Bram Moolenaar <Bram@vim.org>
parents: 14393
diff changeset
77
1841c03a9b5e patch 8.1.1510: a plugin cannot easily expand a command like done internally
Bram Moolenaar <Bram@vim.org>
parents: 14393
diff changeset
78 call assert_fails('call expandcmd("make <afile>")', 'E495:')
1841c03a9b5e patch 8.1.1510: a plugin cannot easily expand a command like done internally
Bram Moolenaar <Bram@vim.org>
parents: 14393
diff changeset
79 call assert_fails('call expandcmd("make <afile>")', 'E495:')
1841c03a9b5e patch 8.1.1510: a plugin cannot easily expand a command like done internally
Bram Moolenaar <Bram@vim.org>
parents: 14393
diff changeset
80 enew
1841c03a9b5e patch 8.1.1510: a plugin cannot easily expand a command like done internally
Bram Moolenaar <Bram@vim.org>
parents: 14393
diff changeset
81 call assert_fails('call expandcmd("make %")', 'E499:')
1841c03a9b5e patch 8.1.1510: a plugin cannot easily expand a command like done internally
Bram Moolenaar <Bram@vim.org>
parents: 14393
diff changeset
82 close
1841c03a9b5e patch 8.1.1510: a plugin cannot easily expand a command like done internally
Bram Moolenaar <Bram@vim.org>
parents: 14393
diff changeset
83 endfunc