annotate src/testdir/test_findfile.vim @ 19701:9412cc889072 v8.2.0407

patch 8.2.0407: no early check if :find and :sfind have an argument Commit: https://github.com/vim/vim/commit/2d10cd478047df8ba144d4b0fcc46480993af57f Author: Bram Moolenaar <Bram@vim.org> Date: Thu Mar 19 14:37:30 2020 +0100 patch 8.2.0407: no early check if :find and :sfind have an argument Problem: No early check if :find and :sfind have an argument. Solution: Add EX_NEEDARG.
author Bram Moolenaar <Bram@vim.org>
date Thu, 19 Mar 2020 14:45:04 +0100
parents 67fbe280a502
children 08940efa6b4e
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
15689
977a05589b65 patch 8.1.0852: findfile() and finddir() are not properly tested
Bram Moolenaar <Bram@vim.org>
parents: 10940
diff changeset
1 " Test findfile() and finddir()
977a05589b65 patch 8.1.0852: findfile() and finddir() are not properly tested
Bram Moolenaar <Bram@vim.org>
parents: 10940
diff changeset
2
977a05589b65 patch 8.1.0852: findfile() and finddir() are not properly tested
Bram Moolenaar <Bram@vim.org>
parents: 10940
diff changeset
3 let s:files = [ 'Xdir1/foo',
977a05589b65 patch 8.1.0852: findfile() and finddir() are not properly tested
Bram Moolenaar <Bram@vim.org>
parents: 10940
diff changeset
4 \ 'Xdir1/bar',
977a05589b65 patch 8.1.0852: findfile() and finddir() are not properly tested
Bram Moolenaar <Bram@vim.org>
parents: 10940
diff changeset
5 \ 'Xdir1/Xdir2/foo',
977a05589b65 patch 8.1.0852: findfile() and finddir() are not properly tested
Bram Moolenaar <Bram@vim.org>
parents: 10940
diff changeset
6 \ 'Xdir1/Xdir2/foobar',
977a05589b65 patch 8.1.0852: findfile() and finddir() are not properly tested
Bram Moolenaar <Bram@vim.org>
parents: 10940
diff changeset
7 \ 'Xdir1/Xdir2/Xdir3/bar',
977a05589b65 patch 8.1.0852: findfile() and finddir() are not properly tested
Bram Moolenaar <Bram@vim.org>
parents: 10940
diff changeset
8 \ 'Xdir1/Xdir2/Xdir3/barfoo' ]
977a05589b65 patch 8.1.0852: findfile() and finddir() are not properly tested
Bram Moolenaar <Bram@vim.org>
parents: 10940
diff changeset
9
977a05589b65 patch 8.1.0852: findfile() and finddir() are not properly tested
Bram Moolenaar <Bram@vim.org>
parents: 10940
diff changeset
10 func CreateFiles()
977a05589b65 patch 8.1.0852: findfile() and finddir() are not properly tested
Bram Moolenaar <Bram@vim.org>
parents: 10940
diff changeset
11 call mkdir('Xdir1/Xdir2/Xdir3/Xdir2', 'p')
977a05589b65 patch 8.1.0852: findfile() and finddir() are not properly tested
Bram Moolenaar <Bram@vim.org>
parents: 10940
diff changeset
12 for f in s:files
977a05589b65 patch 8.1.0852: findfile() and finddir() are not properly tested
Bram Moolenaar <Bram@vim.org>
parents: 10940
diff changeset
13 call writefile([], f)
977a05589b65 patch 8.1.0852: findfile() and finddir() are not properly tested
Bram Moolenaar <Bram@vim.org>
parents: 10940
diff changeset
14 endfor
977a05589b65 patch 8.1.0852: findfile() and finddir() are not properly tested
Bram Moolenaar <Bram@vim.org>
parents: 10940
diff changeset
15 endfunc
977a05589b65 patch 8.1.0852: findfile() and finddir() are not properly tested
Bram Moolenaar <Bram@vim.org>
parents: 10940
diff changeset
16
977a05589b65 patch 8.1.0852: findfile() and finddir() are not properly tested
Bram Moolenaar <Bram@vim.org>
parents: 10940
diff changeset
17 func CleanFiles()
977a05589b65 patch 8.1.0852: findfile() and finddir() are not properly tested
Bram Moolenaar <Bram@vim.org>
parents: 10940
diff changeset
18 " Safer to delete each file even if it's more verbose
977a05589b65 patch 8.1.0852: findfile() and finddir() are not properly tested
Bram Moolenaar <Bram@vim.org>
parents: 10940
diff changeset
19 " than doing a recursive delete('Xdir1', 'rf').
977a05589b65 patch 8.1.0852: findfile() and finddir() are not properly tested
Bram Moolenaar <Bram@vim.org>
parents: 10940
diff changeset
20 for f in s:files
977a05589b65 patch 8.1.0852: findfile() and finddir() are not properly tested
Bram Moolenaar <Bram@vim.org>
parents: 10940
diff changeset
21 call delete(f)
977a05589b65 patch 8.1.0852: findfile() and finddir() are not properly tested
Bram Moolenaar <Bram@vim.org>
parents: 10940
diff changeset
22 endfor
977a05589b65 patch 8.1.0852: findfile() and finddir() are not properly tested
Bram Moolenaar <Bram@vim.org>
parents: 10940
diff changeset
23
977a05589b65 patch 8.1.0852: findfile() and finddir() are not properly tested
Bram Moolenaar <Bram@vim.org>
parents: 10940
diff changeset
24 call delete('Xdir1/Xdir2/Xdir3/Xdir2', 'd')
977a05589b65 patch 8.1.0852: findfile() and finddir() are not properly tested
Bram Moolenaar <Bram@vim.org>
parents: 10940
diff changeset
25 call delete('Xdir1/Xdir2/Xdir3', 'd')
977a05589b65 patch 8.1.0852: findfile() and finddir() are not properly tested
Bram Moolenaar <Bram@vim.org>
parents: 10940
diff changeset
26 call delete('Xdir1/Xdir2', 'd')
977a05589b65 patch 8.1.0852: findfile() and finddir() are not properly tested
Bram Moolenaar <Bram@vim.org>
parents: 10940
diff changeset
27 call delete('Xdir1', 'd')
977a05589b65 patch 8.1.0852: findfile() and finddir() are not properly tested
Bram Moolenaar <Bram@vim.org>
parents: 10940
diff changeset
28 endfunc
977a05589b65 patch 8.1.0852: findfile() and finddir() are not properly tested
Bram Moolenaar <Bram@vim.org>
parents: 10940
diff changeset
29
977a05589b65 patch 8.1.0852: findfile() and finddir() are not properly tested
Bram Moolenaar <Bram@vim.org>
parents: 10940
diff changeset
30 " Test findfile({name} [, {path} [, {count}]])
10940
a479b7064550 patch 8.0.0359: 'number' and 'relativenumber' are not properly tested
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
31 func Test_findfile()
15689
977a05589b65 patch 8.1.0852: findfile() and finddir() are not properly tested
Bram Moolenaar <Bram@vim.org>
parents: 10940
diff changeset
32 let save_path = &path
977a05589b65 patch 8.1.0852: findfile() and finddir() are not properly tested
Bram Moolenaar <Bram@vim.org>
parents: 10940
diff changeset
33 let save_shellslash = &shellslash
977a05589b65 patch 8.1.0852: findfile() and finddir() are not properly tested
Bram Moolenaar <Bram@vim.org>
parents: 10940
diff changeset
34 let save_dir = getcwd()
977a05589b65 patch 8.1.0852: findfile() and finddir() are not properly tested
Bram Moolenaar <Bram@vim.org>
parents: 10940
diff changeset
35 set shellslash
977a05589b65 patch 8.1.0852: findfile() and finddir() are not properly tested
Bram Moolenaar <Bram@vim.org>
parents: 10940
diff changeset
36 call CreateFiles()
977a05589b65 patch 8.1.0852: findfile() and finddir() are not properly tested
Bram Moolenaar <Bram@vim.org>
parents: 10940
diff changeset
37 cd Xdir1
977a05589b65 patch 8.1.0852: findfile() and finddir() are not properly tested
Bram Moolenaar <Bram@vim.org>
parents: 10940
diff changeset
38 e Xdir2/foo
977a05589b65 patch 8.1.0852: findfile() and finddir() are not properly tested
Bram Moolenaar <Bram@vim.org>
parents: 10940
diff changeset
39
977a05589b65 patch 8.1.0852: findfile() and finddir() are not properly tested
Bram Moolenaar <Bram@vim.org>
parents: 10940
diff changeset
40 " With ,, in path, findfile() searches in current directory.
977a05589b65 patch 8.1.0852: findfile() and finddir() are not properly tested
Bram Moolenaar <Bram@vim.org>
parents: 10940
diff changeset
41 set path=,,
977a05589b65 patch 8.1.0852: findfile() and finddir() are not properly tested
Bram Moolenaar <Bram@vim.org>
parents: 10940
diff changeset
42 call assert_equal('foo', findfile('foo'))
977a05589b65 patch 8.1.0852: findfile() and finddir() are not properly tested
Bram Moolenaar <Bram@vim.org>
parents: 10940
diff changeset
43 call assert_equal('bar', findfile('bar'))
977a05589b65 patch 8.1.0852: findfile() and finddir() are not properly tested
Bram Moolenaar <Bram@vim.org>
parents: 10940
diff changeset
44 call assert_equal('', findfile('foobar'))
977a05589b65 patch 8.1.0852: findfile() and finddir() are not properly tested
Bram Moolenaar <Bram@vim.org>
parents: 10940
diff changeset
45
977a05589b65 patch 8.1.0852: findfile() and finddir() are not properly tested
Bram Moolenaar <Bram@vim.org>
parents: 10940
diff changeset
46 " Directories should not be found (finddir() finds them).
977a05589b65 patch 8.1.0852: findfile() and finddir() are not properly tested
Bram Moolenaar <Bram@vim.org>
parents: 10940
diff changeset
47 call assert_equal('', findfile('Xdir2'))
977a05589b65 patch 8.1.0852: findfile() and finddir() are not properly tested
Bram Moolenaar <Bram@vim.org>
parents: 10940
diff changeset
48
977a05589b65 patch 8.1.0852: findfile() and finddir() are not properly tested
Bram Moolenaar <Bram@vim.org>
parents: 10940
diff changeset
49 " With . in 'path', findfile() searches relatively to current file.
977a05589b65 patch 8.1.0852: findfile() and finddir() are not properly tested
Bram Moolenaar <Bram@vim.org>
parents: 10940
diff changeset
50 set path=.
977a05589b65 patch 8.1.0852: findfile() and finddir() are not properly tested
Bram Moolenaar <Bram@vim.org>
parents: 10940
diff changeset
51 call assert_equal('Xdir2/foo', findfile('foo'))
977a05589b65 patch 8.1.0852: findfile() and finddir() are not properly tested
Bram Moolenaar <Bram@vim.org>
parents: 10940
diff changeset
52 call assert_equal('', findfile('bar'))
17849
73ddc462979d patch 8.1.1921: more functions can be used as methods
Bram Moolenaar <Bram@vim.org>
parents: 15736
diff changeset
53 call assert_equal('Xdir2/foobar', 'foobar'->findfile())
15689
977a05589b65 patch 8.1.0852: findfile() and finddir() are not properly tested
Bram Moolenaar <Bram@vim.org>
parents: 10940
diff changeset
54
977a05589b65 patch 8.1.0852: findfile() and finddir() are not properly tested
Bram Moolenaar <Bram@vim.org>
parents: 10940
diff changeset
55 " Empty {path} 2nd argument is the same as no 2nd argument.
977a05589b65 patch 8.1.0852: findfile() and finddir() are not properly tested
Bram Moolenaar <Bram@vim.org>
parents: 10940
diff changeset
56 call assert_equal('Xdir2/foo', findfile('foo', ''))
977a05589b65 patch 8.1.0852: findfile() and finddir() are not properly tested
Bram Moolenaar <Bram@vim.org>
parents: 10940
diff changeset
57 call assert_equal('', findfile('bar', ''))
977a05589b65 patch 8.1.0852: findfile() and finddir() are not properly tested
Bram Moolenaar <Bram@vim.org>
parents: 10940
diff changeset
58
977a05589b65 patch 8.1.0852: findfile() and finddir() are not properly tested
Bram Moolenaar <Bram@vim.org>
parents: 10940
diff changeset
59 " Test with *
977a05589b65 patch 8.1.0852: findfile() and finddir() are not properly tested
Bram Moolenaar <Bram@vim.org>
parents: 10940
diff changeset
60 call assert_equal('Xdir2/foo', findfile('foo', '*'))
977a05589b65 patch 8.1.0852: findfile() and finddir() are not properly tested
Bram Moolenaar <Bram@vim.org>
parents: 10940
diff changeset
61 call assert_equal('', findfile('bar', '*'))
977a05589b65 patch 8.1.0852: findfile() and finddir() are not properly tested
Bram Moolenaar <Bram@vim.org>
parents: 10940
diff changeset
62 call assert_equal('Xdir2/Xdir3/bar', findfile('bar', '*/*'))
977a05589b65 patch 8.1.0852: findfile() and finddir() are not properly tested
Bram Moolenaar <Bram@vim.org>
parents: 10940
diff changeset
63 call assert_equal('Xdir2/Xdir3/bar', findfile('bar', 'Xdir2/*'))
977a05589b65 patch 8.1.0852: findfile() and finddir() are not properly tested
Bram Moolenaar <Bram@vim.org>
parents: 10940
diff changeset
64 call assert_equal('Xdir2/Xdir3/bar', findfile('bar', 'Xdir*/Xdir3'))
977a05589b65 patch 8.1.0852: findfile() and finddir() are not properly tested
Bram Moolenaar <Bram@vim.org>
parents: 10940
diff changeset
65 call assert_equal('Xdir2/Xdir3/bar', findfile('bar', '*2/*3'))
977a05589b65 patch 8.1.0852: findfile() and finddir() are not properly tested
Bram Moolenaar <Bram@vim.org>
parents: 10940
diff changeset
66
977a05589b65 patch 8.1.0852: findfile() and finddir() are not properly tested
Bram Moolenaar <Bram@vim.org>
parents: 10940
diff changeset
67 " Test with **
977a05589b65 patch 8.1.0852: findfile() and finddir() are not properly tested
Bram Moolenaar <Bram@vim.org>
parents: 10940
diff changeset
68 call assert_equal('bar', findfile('bar', '**'))
977a05589b65 patch 8.1.0852: findfile() and finddir() are not properly tested
Bram Moolenaar <Bram@vim.org>
parents: 10940
diff changeset
69 call assert_equal('Xdir2/Xdir3/bar', findfile('bar', '**/Xdir3'))
977a05589b65 patch 8.1.0852: findfile() and finddir() are not properly tested
Bram Moolenaar <Bram@vim.org>
parents: 10940
diff changeset
70 call assert_equal('Xdir2/Xdir3/bar', findfile('bar', 'Xdir2/**'))
977a05589b65 patch 8.1.0852: findfile() and finddir() are not properly tested
Bram Moolenaar <Bram@vim.org>
parents: 10940
diff changeset
71
977a05589b65 patch 8.1.0852: findfile() and finddir() are not properly tested
Bram Moolenaar <Bram@vim.org>
parents: 10940
diff changeset
72 call assert_equal('Xdir2/Xdir3/barfoo', findfile('barfoo', '**2'))
977a05589b65 patch 8.1.0852: findfile() and finddir() are not properly tested
Bram Moolenaar <Bram@vim.org>
parents: 10940
diff changeset
73 call assert_equal('', findfile('barfoo', '**1'))
977a05589b65 patch 8.1.0852: findfile() and finddir() are not properly tested
Bram Moolenaar <Bram@vim.org>
parents: 10940
diff changeset
74 call assert_equal('Xdir2/foobar', findfile('foobar', '**1'))
977a05589b65 patch 8.1.0852: findfile() and finddir() are not properly tested
Bram Moolenaar <Bram@vim.org>
parents: 10940
diff changeset
75
977a05589b65 patch 8.1.0852: findfile() and finddir() are not properly tested
Bram Moolenaar <Bram@vim.org>
parents: 10940
diff changeset
76 " Test with {count} 3rd argument.
977a05589b65 patch 8.1.0852: findfile() and finddir() are not properly tested
Bram Moolenaar <Bram@vim.org>
parents: 10940
diff changeset
77 call assert_equal('bar', findfile('bar', '**', 0))
977a05589b65 patch 8.1.0852: findfile() and finddir() are not properly tested
Bram Moolenaar <Bram@vim.org>
parents: 10940
diff changeset
78 call assert_equal('bar', findfile('bar', '**', 1))
977a05589b65 patch 8.1.0852: findfile() and finddir() are not properly tested
Bram Moolenaar <Bram@vim.org>
parents: 10940
diff changeset
79 call assert_equal('Xdir2/Xdir3/bar', findfile('bar', '**', 2))
977a05589b65 patch 8.1.0852: findfile() and finddir() are not properly tested
Bram Moolenaar <Bram@vim.org>
parents: 10940
diff changeset
80 call assert_equal('', findfile('bar', '**', 3))
977a05589b65 patch 8.1.0852: findfile() and finddir() are not properly tested
Bram Moolenaar <Bram@vim.org>
parents: 10940
diff changeset
81 call assert_equal(['bar', 'Xdir2/Xdir3/bar'], findfile('bar', '**', -1))
10940
a479b7064550 patch 8.0.0359: 'number' and 'relativenumber' are not properly tested
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
82
15689
977a05589b65 patch 8.1.0852: findfile() and finddir() are not properly tested
Bram Moolenaar <Bram@vim.org>
parents: 10940
diff changeset
83 " Test upwards search.
977a05589b65 patch 8.1.0852: findfile() and finddir() are not properly tested
Bram Moolenaar <Bram@vim.org>
parents: 10940
diff changeset
84 cd Xdir2/Xdir3
977a05589b65 patch 8.1.0852: findfile() and finddir() are not properly tested
Bram Moolenaar <Bram@vim.org>
parents: 10940
diff changeset
85 call assert_equal('bar', findfile('bar', ';'))
977a05589b65 patch 8.1.0852: findfile() and finddir() are not properly tested
Bram Moolenaar <Bram@vim.org>
parents: 10940
diff changeset
86 call assert_match('.*/Xdir1/Xdir2/foo', findfile('foo', ';'))
977a05589b65 patch 8.1.0852: findfile() and finddir() are not properly tested
Bram Moolenaar <Bram@vim.org>
parents: 10940
diff changeset
87 call assert_match('.*/Xdir1/Xdir2/foo', findfile('foo', ';', 1))
977a05589b65 patch 8.1.0852: findfile() and finddir() are not properly tested
Bram Moolenaar <Bram@vim.org>
parents: 10940
diff changeset
88 call assert_match('.*/Xdir1/foo', findfile('foo', ';', 2))
977a05589b65 patch 8.1.0852: findfile() and finddir() are not properly tested
Bram Moolenaar <Bram@vim.org>
parents: 10940
diff changeset
89 call assert_match('.*/Xdir1/foo', findfile('foo', ';', 2))
977a05589b65 patch 8.1.0852: findfile() and finddir() are not properly tested
Bram Moolenaar <Bram@vim.org>
parents: 10940
diff changeset
90 call assert_match('.*/Xdir1/Xdir2/foo', findfile('foo', 'Xdir2;', 1))
977a05589b65 patch 8.1.0852: findfile() and finddir() are not properly tested
Bram Moolenaar <Bram@vim.org>
parents: 10940
diff changeset
91 call assert_equal('', findfile('foo', 'Xdir2;', 2))
977a05589b65 patch 8.1.0852: findfile() and finddir() are not properly tested
Bram Moolenaar <Bram@vim.org>
parents: 10940
diff changeset
92
977a05589b65 patch 8.1.0852: findfile() and finddir() are not properly tested
Bram Moolenaar <Bram@vim.org>
parents: 10940
diff changeset
93 " List l should have at least 2 values (possibly more if foo file
977a05589b65 patch 8.1.0852: findfile() and finddir() are not properly tested
Bram Moolenaar <Bram@vim.org>
parents: 10940
diff changeset
94 " happens to be found upwards above Xdir1).
977a05589b65 patch 8.1.0852: findfile() and finddir() are not properly tested
Bram Moolenaar <Bram@vim.org>
parents: 10940
diff changeset
95 let l = findfile('foo', ';', -1)
977a05589b65 patch 8.1.0852: findfile() and finddir() are not properly tested
Bram Moolenaar <Bram@vim.org>
parents: 10940
diff changeset
96 call assert_match('.*/Xdir1/Xdir2/foo', l[0])
977a05589b65 patch 8.1.0852: findfile() and finddir() are not properly tested
Bram Moolenaar <Bram@vim.org>
parents: 10940
diff changeset
97 call assert_match('.*/Xdir1/foo', l[1])
977a05589b65 patch 8.1.0852: findfile() and finddir() are not properly tested
Bram Moolenaar <Bram@vim.org>
parents: 10940
diff changeset
98
977a05589b65 patch 8.1.0852: findfile() and finddir() are not properly tested
Bram Moolenaar <Bram@vim.org>
parents: 10940
diff changeset
99 " Test upwards search with stop-directory.
977a05589b65 patch 8.1.0852: findfile() and finddir() are not properly tested
Bram Moolenaar <Bram@vim.org>
parents: 10940
diff changeset
100 cd Xdir2
977a05589b65 patch 8.1.0852: findfile() and finddir() are not properly tested
Bram Moolenaar <Bram@vim.org>
parents: 10940
diff changeset
101 let l = findfile('bar', ';' . save_dir . '/Xdir1/Xdir2/', -1)
977a05589b65 patch 8.1.0852: findfile() and finddir() are not properly tested
Bram Moolenaar <Bram@vim.org>
parents: 10940
diff changeset
102 call assert_equal(1, len(l))
977a05589b65 patch 8.1.0852: findfile() and finddir() are not properly tested
Bram Moolenaar <Bram@vim.org>
parents: 10940
diff changeset
103 call assert_match('.*/Xdir1/Xdir2/Xdir3/bar', l[0])
977a05589b65 patch 8.1.0852: findfile() and finddir() are not properly tested
Bram Moolenaar <Bram@vim.org>
parents: 10940
diff changeset
104
977a05589b65 patch 8.1.0852: findfile() and finddir() are not properly tested
Bram Moolenaar <Bram@vim.org>
parents: 10940
diff changeset
105 let l = findfile('bar', ';' . save_dir . '/Xdir1/', -1)
977a05589b65 patch 8.1.0852: findfile() and finddir() are not properly tested
Bram Moolenaar <Bram@vim.org>
parents: 10940
diff changeset
106 call assert_equal(2, len(l))
977a05589b65 patch 8.1.0852: findfile() and finddir() are not properly tested
Bram Moolenaar <Bram@vim.org>
parents: 10940
diff changeset
107 call assert_match('.*/Xdir1/Xdir2/Xdir3/bar', l[0])
977a05589b65 patch 8.1.0852: findfile() and finddir() are not properly tested
Bram Moolenaar <Bram@vim.org>
parents: 10940
diff changeset
108 call assert_match('.*/Xdir1/bar', l[1])
977a05589b65 patch 8.1.0852: findfile() and finddir() are not properly tested
Bram Moolenaar <Bram@vim.org>
parents: 10940
diff changeset
109
977a05589b65 patch 8.1.0852: findfile() and finddir() are not properly tested
Bram Moolenaar <Bram@vim.org>
parents: 10940
diff changeset
110 " Test combined downwards and upwards search from Xdir2/.
977a05589b65 patch 8.1.0852: findfile() and finddir() are not properly tested
Bram Moolenaar <Bram@vim.org>
parents: 10940
diff changeset
111 cd ../..
977a05589b65 patch 8.1.0852: findfile() and finddir() are not properly tested
Bram Moolenaar <Bram@vim.org>
parents: 10940
diff changeset
112 call assert_equal('Xdir3/bar', findfile('bar', '**;', 1))
977a05589b65 patch 8.1.0852: findfile() and finddir() are not properly tested
Bram Moolenaar <Bram@vim.org>
parents: 10940
diff changeset
113 call assert_match('.*/Xdir1/bar', findfile('bar', '**;', 2))
977a05589b65 patch 8.1.0852: findfile() and finddir() are not properly tested
Bram Moolenaar <Bram@vim.org>
parents: 10940
diff changeset
114
977a05589b65 patch 8.1.0852: findfile() and finddir() are not properly tested
Bram Moolenaar <Bram@vim.org>
parents: 10940
diff changeset
115 bwipe!
18568
26a04a556982 patch 8.1.2278: using "cd" with "exe" may fail
Bram Moolenaar <Bram@vim.org>
parents: 17849
diff changeset
116 call chdir(save_dir)
15689
977a05589b65 patch 8.1.0852: findfile() and finddir() are not properly tested
Bram Moolenaar <Bram@vim.org>
parents: 10940
diff changeset
117 call CleanFiles()
977a05589b65 patch 8.1.0852: findfile() and finddir() are not properly tested
Bram Moolenaar <Bram@vim.org>
parents: 10940
diff changeset
118 let &path = save_path
977a05589b65 patch 8.1.0852: findfile() and finddir() are not properly tested
Bram Moolenaar <Bram@vim.org>
parents: 10940
diff changeset
119 let &shellslash = save_shellslash
977a05589b65 patch 8.1.0852: findfile() and finddir() are not properly tested
Bram Moolenaar <Bram@vim.org>
parents: 10940
diff changeset
120 endfunc
10940
a479b7064550 patch 8.0.0359: 'number' and 'relativenumber' are not properly tested
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
121
15736
6839f99d2269 patch 8.1.0875: not all errors of marks and findfile()/finddir() are tested
Bram Moolenaar <Bram@vim.org>
parents: 15689
diff changeset
122 func Test_findfile_error()
6839f99d2269 patch 8.1.0875: not all errors of marks and findfile()/finddir() are tested
Bram Moolenaar <Bram@vim.org>
parents: 15689
diff changeset
123 call assert_fails('call findfile([])', 'E730:')
6839f99d2269 patch 8.1.0875: not all errors of marks and findfile()/finddir() are tested
Bram Moolenaar <Bram@vim.org>
parents: 15689
diff changeset
124 call assert_fails('call findfile("x", [])', 'E730:')
6839f99d2269 patch 8.1.0875: not all errors of marks and findfile()/finddir() are tested
Bram Moolenaar <Bram@vim.org>
parents: 15689
diff changeset
125 call assert_fails('call findfile("x", "", [])', 'E745:')
6839f99d2269 patch 8.1.0875: not all errors of marks and findfile()/finddir() are tested
Bram Moolenaar <Bram@vim.org>
parents: 15689
diff changeset
126 call assert_fails('call findfile("x", "**x")', 'E343:')
6839f99d2269 patch 8.1.0875: not all errors of marks and findfile()/finddir() are tested
Bram Moolenaar <Bram@vim.org>
parents: 15689
diff changeset
127 call assert_fails('call findfile("x", repeat("x", 5000))', 'E854:')
6839f99d2269 patch 8.1.0875: not all errors of marks and findfile()/finddir() are tested
Bram Moolenaar <Bram@vim.org>
parents: 15689
diff changeset
128 endfunc
6839f99d2269 patch 8.1.0875: not all errors of marks and findfile()/finddir() are tested
Bram Moolenaar <Bram@vim.org>
parents: 15689
diff changeset
129
15689
977a05589b65 patch 8.1.0852: findfile() and finddir() are not properly tested
Bram Moolenaar <Bram@vim.org>
parents: 10940
diff changeset
130 " Test finddir({name} [, {path} [, {count}]])
977a05589b65 patch 8.1.0852: findfile() and finddir() are not properly tested
Bram Moolenaar <Bram@vim.org>
parents: 10940
diff changeset
131 func Test_finddir()
977a05589b65 patch 8.1.0852: findfile() and finddir() are not properly tested
Bram Moolenaar <Bram@vim.org>
parents: 10940
diff changeset
132 let save_path = &path
977a05589b65 patch 8.1.0852: findfile() and finddir() are not properly tested
Bram Moolenaar <Bram@vim.org>
parents: 10940
diff changeset
133 let save_shellslash = &shellslash
977a05589b65 patch 8.1.0852: findfile() and finddir() are not properly tested
Bram Moolenaar <Bram@vim.org>
parents: 10940
diff changeset
134 let save_dir = getcwd()
977a05589b65 patch 8.1.0852: findfile() and finddir() are not properly tested
Bram Moolenaar <Bram@vim.org>
parents: 10940
diff changeset
135 set path=,,
977a05589b65 patch 8.1.0852: findfile() and finddir() are not properly tested
Bram Moolenaar <Bram@vim.org>
parents: 10940
diff changeset
136 call CreateFiles()
977a05589b65 patch 8.1.0852: findfile() and finddir() are not properly tested
Bram Moolenaar <Bram@vim.org>
parents: 10940
diff changeset
137 cd Xdir1
977a05589b65 patch 8.1.0852: findfile() and finddir() are not properly tested
Bram Moolenaar <Bram@vim.org>
parents: 10940
diff changeset
138
977a05589b65 patch 8.1.0852: findfile() and finddir() are not properly tested
Bram Moolenaar <Bram@vim.org>
parents: 10940
diff changeset
139 call assert_equal('Xdir2', finddir('Xdir2'))
17849
73ddc462979d patch 8.1.1921: more functions can be used as methods
Bram Moolenaar <Bram@vim.org>
parents: 15736
diff changeset
140 call assert_equal('', 'Xdir3'->finddir())
15689
977a05589b65 patch 8.1.0852: findfile() and finddir() are not properly tested
Bram Moolenaar <Bram@vim.org>
parents: 10940
diff changeset
141
977a05589b65 patch 8.1.0852: findfile() and finddir() are not properly tested
Bram Moolenaar <Bram@vim.org>
parents: 10940
diff changeset
142 " Files should not be found (findfile() finds them).
977a05589b65 patch 8.1.0852: findfile() and finddir() are not properly tested
Bram Moolenaar <Bram@vim.org>
parents: 10940
diff changeset
143 call assert_equal('', finddir('foo'))
977a05589b65 patch 8.1.0852: findfile() and finddir() are not properly tested
Bram Moolenaar <Bram@vim.org>
parents: 10940
diff changeset
144
977a05589b65 patch 8.1.0852: findfile() and finddir() are not properly tested
Bram Moolenaar <Bram@vim.org>
parents: 10940
diff changeset
145 call assert_equal('Xdir2', finddir('Xdir2', '**'))
977a05589b65 patch 8.1.0852: findfile() and finddir() are not properly tested
Bram Moolenaar <Bram@vim.org>
parents: 10940
diff changeset
146 call assert_equal('Xdir2/Xdir3', finddir('Xdir3', '**'))
977a05589b65 patch 8.1.0852: findfile() and finddir() are not properly tested
Bram Moolenaar <Bram@vim.org>
parents: 10940
diff changeset
147
977a05589b65 patch 8.1.0852: findfile() and finddir() are not properly tested
Bram Moolenaar <Bram@vim.org>
parents: 10940
diff changeset
148 call assert_equal('Xdir2', finddir('Xdir2', '**', 1))
977a05589b65 patch 8.1.0852: findfile() and finddir() are not properly tested
Bram Moolenaar <Bram@vim.org>
parents: 10940
diff changeset
149 call assert_equal('Xdir2/Xdir3/Xdir2', finddir('Xdir2', '**', 2))
977a05589b65 patch 8.1.0852: findfile() and finddir() are not properly tested
Bram Moolenaar <Bram@vim.org>
parents: 10940
diff changeset
150 call assert_equal(['Xdir2',
977a05589b65 patch 8.1.0852: findfile() and finddir() are not properly tested
Bram Moolenaar <Bram@vim.org>
parents: 10940
diff changeset
151 \ 'Xdir2/Xdir3/Xdir2'], finddir('Xdir2', '**', -1))
977a05589b65 patch 8.1.0852: findfile() and finddir() are not properly tested
Bram Moolenaar <Bram@vim.org>
parents: 10940
diff changeset
152
977a05589b65 patch 8.1.0852: findfile() and finddir() are not properly tested
Bram Moolenaar <Bram@vim.org>
parents: 10940
diff changeset
153 call assert_equal('Xdir2', finddir('Xdir2', '**1'))
977a05589b65 patch 8.1.0852: findfile() and finddir() are not properly tested
Bram Moolenaar <Bram@vim.org>
parents: 10940
diff changeset
154 call assert_equal('Xdir2', finddir('Xdir2', '**0'))
977a05589b65 patch 8.1.0852: findfile() and finddir() are not properly tested
Bram Moolenaar <Bram@vim.org>
parents: 10940
diff changeset
155 call assert_equal('Xdir2/Xdir3', finddir('Xdir3', '**1'))
977a05589b65 patch 8.1.0852: findfile() and finddir() are not properly tested
Bram Moolenaar <Bram@vim.org>
parents: 10940
diff changeset
156 call assert_equal('', finddir('Xdir3', '**0'))
977a05589b65 patch 8.1.0852: findfile() and finddir() are not properly tested
Bram Moolenaar <Bram@vim.org>
parents: 10940
diff changeset
157
977a05589b65 patch 8.1.0852: findfile() and finddir() are not properly tested
Bram Moolenaar <Bram@vim.org>
parents: 10940
diff changeset
158 " Test upwards dir search.
977a05589b65 patch 8.1.0852: findfile() and finddir() are not properly tested
Bram Moolenaar <Bram@vim.org>
parents: 10940
diff changeset
159 cd Xdir2/Xdir3
977a05589b65 patch 8.1.0852: findfile() and finddir() are not properly tested
Bram Moolenaar <Bram@vim.org>
parents: 10940
diff changeset
160 call assert_match('.*/Xdir1', finddir('Xdir1', ';'))
977a05589b65 patch 8.1.0852: findfile() and finddir() are not properly tested
Bram Moolenaar <Bram@vim.org>
parents: 10940
diff changeset
161
977a05589b65 patch 8.1.0852: findfile() and finddir() are not properly tested
Bram Moolenaar <Bram@vim.org>
parents: 10940
diff changeset
162 " Test upwards search with stop-directory.
977a05589b65 patch 8.1.0852: findfile() and finddir() are not properly tested
Bram Moolenaar <Bram@vim.org>
parents: 10940
diff changeset
163 call assert_match('.*/Xdir1', finddir('Xdir1', ';' . save_dir . '/'))
977a05589b65 patch 8.1.0852: findfile() and finddir() are not properly tested
Bram Moolenaar <Bram@vim.org>
parents: 10940
diff changeset
164 call assert_equal('', finddir('Xdir1', ';' . save_dir . '/Xdir1/'))
977a05589b65 patch 8.1.0852: findfile() and finddir() are not properly tested
Bram Moolenaar <Bram@vim.org>
parents: 10940
diff changeset
165
977a05589b65 patch 8.1.0852: findfile() and finddir() are not properly tested
Bram Moolenaar <Bram@vim.org>
parents: 10940
diff changeset
166 " Test combined downwards and upwards dir search from Xdir2/.
10940
a479b7064550 patch 8.0.0359: 'number' and 'relativenumber' are not properly tested
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
167 cd ..
15689
977a05589b65 patch 8.1.0852: findfile() and finddir() are not properly tested
Bram Moolenaar <Bram@vim.org>
parents: 10940
diff changeset
168 call assert_match('.*/Xdir1', finddir('Xdir1', '**;', 1))
977a05589b65 patch 8.1.0852: findfile() and finddir() are not properly tested
Bram Moolenaar <Bram@vim.org>
parents: 10940
diff changeset
169 call assert_equal('Xdir3/Xdir2', finddir('Xdir2', '**;', 1))
977a05589b65 patch 8.1.0852: findfile() and finddir() are not properly tested
Bram Moolenaar <Bram@vim.org>
parents: 10940
diff changeset
170 call assert_match('.*/Xdir1/Xdir2', finddir('Xdir2', '**;', 2))
977a05589b65 patch 8.1.0852: findfile() and finddir() are not properly tested
Bram Moolenaar <Bram@vim.org>
parents: 10940
diff changeset
171 call assert_equal('Xdir3', finddir('Xdir3', '**;', 1))
10940
a479b7064550 patch 8.0.0359: 'number' and 'relativenumber' are not properly tested
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
172
18568
26a04a556982 patch 8.1.2278: using "cd" with "exe" may fail
Bram Moolenaar <Bram@vim.org>
parents: 17849
diff changeset
173 call chdir(save_dir)
15689
977a05589b65 patch 8.1.0852: findfile() and finddir() are not properly tested
Bram Moolenaar <Bram@vim.org>
parents: 10940
diff changeset
174 call CleanFiles()
977a05589b65 patch 8.1.0852: findfile() and finddir() are not properly tested
Bram Moolenaar <Bram@vim.org>
parents: 10940
diff changeset
175 let &path = save_path
977a05589b65 patch 8.1.0852: findfile() and finddir() are not properly tested
Bram Moolenaar <Bram@vim.org>
parents: 10940
diff changeset
176 let &shellslash = save_shellslash
10940
a479b7064550 patch 8.0.0359: 'number' and 'relativenumber' are not properly tested
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
177 endfunc
15736
6839f99d2269 patch 8.1.0875: not all errors of marks and findfile()/finddir() are tested
Bram Moolenaar <Bram@vim.org>
parents: 15689
diff changeset
178
6839f99d2269 patch 8.1.0875: not all errors of marks and findfile()/finddir() are tested
Bram Moolenaar <Bram@vim.org>
parents: 15689
diff changeset
179 func Test_finddir_error()
6839f99d2269 patch 8.1.0875: not all errors of marks and findfile()/finddir() are tested
Bram Moolenaar <Bram@vim.org>
parents: 15689
diff changeset
180 call assert_fails('call finddir([])', 'E730:')
6839f99d2269 patch 8.1.0875: not all errors of marks and findfile()/finddir() are tested
Bram Moolenaar <Bram@vim.org>
parents: 15689
diff changeset
181 call assert_fails('call finddir("x", [])', 'E730:')
6839f99d2269 patch 8.1.0875: not all errors of marks and findfile()/finddir() are tested
Bram Moolenaar <Bram@vim.org>
parents: 15689
diff changeset
182 call assert_fails('call finddir("x", "", [])', 'E745:')
6839f99d2269 patch 8.1.0875: not all errors of marks and findfile()/finddir() are tested
Bram Moolenaar <Bram@vim.org>
parents: 15689
diff changeset
183 call assert_fails('call finddir("x", "**x")', 'E343:')
6839f99d2269 patch 8.1.0875: not all errors of marks and findfile()/finddir() are tested
Bram Moolenaar <Bram@vim.org>
parents: 15689
diff changeset
184 call assert_fails('call finddir("x", repeat("x", 5000))', 'E854:')
6839f99d2269 patch 8.1.0875: not all errors of marks and findfile()/finddir() are tested
Bram Moolenaar <Bram@vim.org>
parents: 15689
diff changeset
185 endfunc
19425
67fbe280a502 patch 8.2.0270: some code not covered by tests
Bram Moolenaar <Bram@vim.org>
parents: 18568
diff changeset
186
67fbe280a502 patch 8.2.0270: some code not covered by tests
Bram Moolenaar <Bram@vim.org>
parents: 18568
diff changeset
187 " Test for the :find, :sfind and :tabfind commands
67fbe280a502 patch 8.2.0270: some code not covered by tests
Bram Moolenaar <Bram@vim.org>
parents: 18568
diff changeset
188 func Test_find_cmd()
67fbe280a502 patch 8.2.0270: some code not covered by tests
Bram Moolenaar <Bram@vim.org>
parents: 18568
diff changeset
189 new
67fbe280a502 patch 8.2.0270: some code not covered by tests
Bram Moolenaar <Bram@vim.org>
parents: 18568
diff changeset
190 let save_path = &path
67fbe280a502 patch 8.2.0270: some code not covered by tests
Bram Moolenaar <Bram@vim.org>
parents: 18568
diff changeset
191 let save_dir = getcwd()
67fbe280a502 patch 8.2.0270: some code not covered by tests
Bram Moolenaar <Bram@vim.org>
parents: 18568
diff changeset
192 set path=.,./**/*
67fbe280a502 patch 8.2.0270: some code not covered by tests
Bram Moolenaar <Bram@vim.org>
parents: 18568
diff changeset
193 call CreateFiles()
67fbe280a502 patch 8.2.0270: some code not covered by tests
Bram Moolenaar <Bram@vim.org>
parents: 18568
diff changeset
194 cd Xdir1
67fbe280a502 patch 8.2.0270: some code not covered by tests
Bram Moolenaar <Bram@vim.org>
parents: 18568
diff changeset
195
67fbe280a502 patch 8.2.0270: some code not covered by tests
Bram Moolenaar <Bram@vim.org>
parents: 18568
diff changeset
196 " Test for :find
67fbe280a502 patch 8.2.0270: some code not covered by tests
Bram Moolenaar <Bram@vim.org>
parents: 18568
diff changeset
197 find foo
67fbe280a502 patch 8.2.0270: some code not covered by tests
Bram Moolenaar <Bram@vim.org>
parents: 18568
diff changeset
198 call assert_equal('foo', expand('%:.'))
67fbe280a502 patch 8.2.0270: some code not covered by tests
Bram Moolenaar <Bram@vim.org>
parents: 18568
diff changeset
199 2find foo
67fbe280a502 patch 8.2.0270: some code not covered by tests
Bram Moolenaar <Bram@vim.org>
parents: 18568
diff changeset
200 call assert_equal('Xdir2/foo', expand('%:.'))
67fbe280a502 patch 8.2.0270: some code not covered by tests
Bram Moolenaar <Bram@vim.org>
parents: 18568
diff changeset
201 call assert_fails('3find foo', 'E347:')
67fbe280a502 patch 8.2.0270: some code not covered by tests
Bram Moolenaar <Bram@vim.org>
parents: 18568
diff changeset
202
67fbe280a502 patch 8.2.0270: some code not covered by tests
Bram Moolenaar <Bram@vim.org>
parents: 18568
diff changeset
203 " Test for :sfind
67fbe280a502 patch 8.2.0270: some code not covered by tests
Bram Moolenaar <Bram@vim.org>
parents: 18568
diff changeset
204 enew
67fbe280a502 patch 8.2.0270: some code not covered by tests
Bram Moolenaar <Bram@vim.org>
parents: 18568
diff changeset
205 sfind barfoo
67fbe280a502 patch 8.2.0270: some code not covered by tests
Bram Moolenaar <Bram@vim.org>
parents: 18568
diff changeset
206 call assert_equal('Xdir2/Xdir3/barfoo', expand('%:.'))
67fbe280a502 patch 8.2.0270: some code not covered by tests
Bram Moolenaar <Bram@vim.org>
parents: 18568
diff changeset
207 call assert_equal(3, winnr('$'))
67fbe280a502 patch 8.2.0270: some code not covered by tests
Bram Moolenaar <Bram@vim.org>
parents: 18568
diff changeset
208 close
67fbe280a502 patch 8.2.0270: some code not covered by tests
Bram Moolenaar <Bram@vim.org>
parents: 18568
diff changeset
209 call assert_fails('sfind baz', 'E345:')
67fbe280a502 patch 8.2.0270: some code not covered by tests
Bram Moolenaar <Bram@vim.org>
parents: 18568
diff changeset
210 call assert_equal(2, winnr('$'))
67fbe280a502 patch 8.2.0270: some code not covered by tests
Bram Moolenaar <Bram@vim.org>
parents: 18568
diff changeset
211
67fbe280a502 patch 8.2.0270: some code not covered by tests
Bram Moolenaar <Bram@vim.org>
parents: 18568
diff changeset
212 " Test for :tabfind
67fbe280a502 patch 8.2.0270: some code not covered by tests
Bram Moolenaar <Bram@vim.org>
parents: 18568
diff changeset
213 enew
67fbe280a502 patch 8.2.0270: some code not covered by tests
Bram Moolenaar <Bram@vim.org>
parents: 18568
diff changeset
214 tabfind foobar
67fbe280a502 patch 8.2.0270: some code not covered by tests
Bram Moolenaar <Bram@vim.org>
parents: 18568
diff changeset
215 call assert_equal('Xdir2/foobar', expand('%:.'))
67fbe280a502 patch 8.2.0270: some code not covered by tests
Bram Moolenaar <Bram@vim.org>
parents: 18568
diff changeset
216 call assert_equal(2, tabpagenr('$'))
67fbe280a502 patch 8.2.0270: some code not covered by tests
Bram Moolenaar <Bram@vim.org>
parents: 18568
diff changeset
217 tabclose
67fbe280a502 patch 8.2.0270: some code not covered by tests
Bram Moolenaar <Bram@vim.org>
parents: 18568
diff changeset
218 call assert_fails('tabfind baz', 'E345:')
67fbe280a502 patch 8.2.0270: some code not covered by tests
Bram Moolenaar <Bram@vim.org>
parents: 18568
diff changeset
219 call assert_equal(1, tabpagenr('$'))
67fbe280a502 patch 8.2.0270: some code not covered by tests
Bram Moolenaar <Bram@vim.org>
parents: 18568
diff changeset
220
67fbe280a502 patch 8.2.0270: some code not covered by tests
Bram Moolenaar <Bram@vim.org>
parents: 18568
diff changeset
221 call chdir(save_dir)
67fbe280a502 patch 8.2.0270: some code not covered by tests
Bram Moolenaar <Bram@vim.org>
parents: 18568
diff changeset
222 call CleanFiles()
67fbe280a502 patch 8.2.0270: some code not covered by tests
Bram Moolenaar <Bram@vim.org>
parents: 18568
diff changeset
223 let &path = save_path
67fbe280a502 patch 8.2.0270: some code not covered by tests
Bram Moolenaar <Bram@vim.org>
parents: 18568
diff changeset
224 close
19701
9412cc889072 patch 8.2.0407: no early check if :find and :sfind have an argument
Bram Moolenaar <Bram@vim.org>
parents: 19425
diff changeset
225
9412cc889072 patch 8.2.0407: no early check if :find and :sfind have an argument
Bram Moolenaar <Bram@vim.org>
parents: 19425
diff changeset
226 call assert_fails('find', 'E471:')
9412cc889072 patch 8.2.0407: no early check if :find and :sfind have an argument
Bram Moolenaar <Bram@vim.org>
parents: 19425
diff changeset
227 call assert_fails('sfind', 'E471:')
9412cc889072 patch 8.2.0407: no early check if :find and :sfind have an argument
Bram Moolenaar <Bram@vim.org>
parents: 19425
diff changeset
228 call assert_fails('tabfind', 'E471:')
19425
67fbe280a502 patch 8.2.0270: some code not covered by tests
Bram Moolenaar <Bram@vim.org>
parents: 18568
diff changeset
229 endfunc