Bram Moolenaar | f0ab01f | 2019-05-06 22:00:00 +0200 | [diff] [blame] | 1 | " Tests for the :checkpath command |
| 2 | |
| 3 | " Test for 'include' without \zs or \ze |
| 4 | func 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& |
| 28 | endfunc |
| 29 | |
| 30 | func DotsToSlashes() |
| 31 | return substitute(v:fname, '\.', '/', 'g') . '.b' |
| 32 | endfunc |
| 33 | |
| 34 | " Test for 'include' with \zs and \ze |
| 35 | func 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& |
| 64 | endfunc |
| 65 | |
| 66 | func StripNewlineChar() |
| 67 | if v:fname =~ '\n$' |
| 68 | return v:fname[:-2] |
| 69 | endif |
| 70 | return v:fname |
| 71 | endfunc |
| 72 | |
| 73 | " Test for 'include' with \zs and no \ze |
| 74 | func 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& |
| 104 | endfunc |