blob: eff30cf2058e471b69faed1a21326648013ac1e7 [file] [log] [blame]
Bram Moolenaarf0ab01f2019-05-06 22:00:00 +02001" Tests for the :checkpath command
2
3" Test for 'include' without \zs or \ze
4func Test_checkpath1()
5 call mkdir("Xdir1/dir2", "p")
6 call writefile(['#include "bar.a"'], 'Xdir1/dir2/foo.a')
7 call writefile(['#include "baz.a"'], 'Xdir1/dir2/bar.a')
8 call writefile(['#include "foo.a"'], 'Xdir1/dir2/baz.a')
9 call writefile(['#include <foo.a>'], 'Xbase.a')
10
11 edit Xbase.a
12 set path=Xdir1/dir2
13 let res = split(execute("checkpath!"), "\n")
14 call assert_equal([
15 \ '--- Included files in path ---',
16 \ 'Xdir1/dir2/foo.a',
17 \ 'Xdir1/dir2/foo.a -->',
18 \ ' Xdir1/dir2/bar.a',
19 \ ' Xdir1/dir2/bar.a -->',
20 \ ' Xdir1/dir2/baz.a',
21 \ ' Xdir1/dir2/baz.a -->',
22 \ ' "foo.a" (Already listed)'], res)
23
24 enew
25 call delete("./Xbase.a")
26 call delete("Xdir1", "rf")
27 set path&
28endfunc
29
30func DotsToSlashes()
31 return substitute(v:fname, '\.', '/', 'g') . '.b'
32endfunc
33
34" Test for 'include' with \zs and \ze
35func Test_checkpath2()
36 call mkdir("Xdir1/dir2", "p")
37 call writefile(['%inc /bar/'], 'Xdir1/dir2/foo.b')
38 call writefile(['%inc /baz/'], 'Xdir1/dir2/bar.b')
39 call writefile(['%inc /foo/'], 'Xdir1/dir2/baz.b')
40 call writefile(['%inc /foo/'], 'Xbase.b')
41
42 let &include='^\s*%inc\s*/\zs[^/]\+\ze'
43 let &includeexpr='DotsToSlashes()'
44
45 edit Xbase.b
46 set path=Xdir1/dir2
47 let res = split(execute("checkpath!"), "\n")
48 call assert_equal([
49 \ '--- Included files in path ---',
50 \ 'Xdir1/dir2/foo.b',
51 \ 'Xdir1/dir2/foo.b -->',
52 \ ' Xdir1/dir2/bar.b',
53 \ ' Xdir1/dir2/bar.b -->',
54 \ ' Xdir1/dir2/baz.b',
55 \ ' Xdir1/dir2/baz.b -->',
56 \ ' foo (Already listed)'], res)
57
58 enew
59 call delete("./Xbase.b")
60 call delete("Xdir1", "rf")
61 set path&
62 set include&
63 set includeexpr&
64endfunc
65
66func StripNewlineChar()
67 if v:fname =~ '\n$'
68 return v:fname[:-2]
69 endif
70 return v:fname
71endfunc
72
73" Test for 'include' with \zs and no \ze
74func Test_checkpath3()
75 call mkdir("Xdir1/dir2", "p")
76 call writefile(['%inc bar.c'], 'Xdir1/dir2/foo.c')
77 call writefile(['%inc baz.c'], 'Xdir1/dir2/bar.c')
78 call writefile(['%inc foo.c'], 'Xdir1/dir2/baz.c')
79 call writefile(['%inc foo.c'], 'Xdir1/dir2/FALSE.c')
80 call writefile(['%inc FALSE.c foo.c'], 'Xbase.c')
81
82 let &include='^\s*%inc\s*\%([[:upper:]][^[:space:]]*\s\+\)\?\zs\S\+\ze'
83 let &includeexpr='StripNewlineChar()'
84
85 edit Xbase.c
86 set path=Xdir1/dir2
87 let res = split(execute("checkpath!"), "\n")
88 call assert_equal([
89 \ '--- Included files in path ---',
90 \ 'Xdir1/dir2/foo.c',
91 \ 'Xdir1/dir2/foo.c -->',
92 \ ' Xdir1/dir2/bar.c',
93 \ ' Xdir1/dir2/bar.c -->',
94 \ ' Xdir1/dir2/baz.c',
95 \ ' Xdir1/dir2/baz.c -->',
96 \ ' foo.c (Already listed)'], res)
97
98 enew
99 call delete("./Xbase.c")
100 call delete("Xdir1", "rf")
101 set path&
102 set include&
103 set includeexpr&
104endfunc