diff options
author | Justin M. Keyes <justinkz@gmail.com> | 2015-08-01 23:33:54 -0400 |
---|---|---|
committer | Justin M. Keyes <justinkz@gmail.com> | 2015-08-01 23:33:54 -0400 |
commit | efa059c5a4611629890e28987a83aa781952b78c (patch) | |
tree | 5d7ea0510ec08512cc929adc30040acabd8556a8 | |
parent | dd7c7efcfb37342ccd9168977b2431d16de7b3cb (diff) | |
download | rneovim-efa059c5a4611629890e28987a83aa781952b78c.tar.gz rneovim-efa059c5a4611629890e28987a83aa781952b78c.tar.bz2 rneovim-efa059c5a4611629890e28987a83aa781952b78c.zip |
test: call scandir_next_with_dots() more than once
Also cosmetic reduction.
-rw-r--r-- | src/nvim/path.c | 25 | ||||
-rw-r--r-- | test/functional/eval/glob_spec.lua | 4 |
2 files changed, 13 insertions, 16 deletions
diff --git a/src/nvim/path.c b/src/nvim/path.c index 9d9cd933b4..72980fcd0e 100644 --- a/src/nvim/path.c +++ b/src/nvim/path.c @@ -484,23 +484,16 @@ static size_t path_expand(garray_T *gap, const char_u *path, int flags) static const char *scandir_next_with_dots(Directory *dir) { static int count = 0; - const char *entry = NULL; - if (dir == NULL) { + if (dir == NULL) { // initialize count = 0; - } else { - count += 1; - if (count == 1) { - entry = "."; - } else if (count == 2) { - entry = ".."; - } else { - entry = os_scandir_next(dir); - if (entry == NULL) { - count = 0; - } - } + return NULL; + } + + count += 1; + if (count == 1 || count == 2) { + return (count == 1) ? "." : ".."; } - return entry; + return os_scandir_next(dir); } /// Implementation of path_expand(). @@ -623,7 +616,7 @@ static size_t do_path_expand(garray_T *gap, const char_u *path, || os_isdir(*buf == NUL ? (char_u *)"." : (char_u *)buf)) { // Find all matching entries. char_u *name; - scandir_next_with_dots(NULL); + scandir_next_with_dots(NULL /* initialize */); while((name = (char_u *) scandir_next_with_dots(&dir)) && name != NULL) { if ((name[0] != '.' || starts_with_dot) && ((regmatch.regprog != NULL && vim_regexec(®match, name, 0)) diff --git a/test/functional/eval/glob_spec.lua b/test/functional/eval/glob_spec.lua index 977b82d733..136417249c 100644 --- a/test/functional/eval/glob_spec.lua +++ b/test/functional/eval/glob_spec.lua @@ -14,8 +14,12 @@ end) describe('glob()', function() it("glob('.*') returns . and .. ", function() eq({'.', '..'}, eval("glob('.*', 0, 1)")) + -- Do it again to verify scandir_next_with_dots() internal state. + eq({'.', '..'}, eval("glob('.*', 0, 1)")) end) it("glob('*') returns an empty list ", function() eq({}, eval("glob('*', 0, 1)")) + -- Do it again to verify scandir_next_with_dots() internal state. + eq({}, eval("glob('*', 0, 1)")) end) end) |