aboutsummaryrefslogtreecommitdiff
path: root/tests/wildcard/driver.cxx
diff options
context:
space:
mode:
authorKaren Arutyunov <karen@codesynthesis.com>2017-06-07 17:18:54 +0300
committerKaren Arutyunov <karen@codesynthesis.com>2017-06-08 19:57:50 +0300
commit04f4bb3e2492bb6e4b0769b4c7f020493cfa5cc4 (patch)
tree9ab6bf532ea9a906fa9d82570dbd8dd63e582f0a /tests/wildcard/driver.cxx
parent3ea3b1c94f320bb55849d4a9fea1c3009ab3b298 (diff)
Add path_match() and path_search() overloads
Diffstat (limited to 'tests/wildcard/driver.cxx')
-rw-r--r--tests/wildcard/driver.cxx55
1 files changed, 52 insertions, 3 deletions
diff --git a/tests/wildcard/driver.cxx b/tests/wildcard/driver.cxx
index 2397fc8..1e600f6 100644
--- a/tests/wildcard/driver.cxx
+++ b/tests/wildcard/driver.cxx
@@ -2,6 +2,7 @@
// copyright : Copyright (c) 2014-2017 Code Synthesis Ltd
// license : MIT; see accompanying LICENSE file
+#include <map>
#include <string>
#include <vector>
#include <cassert>
@@ -90,8 +91,11 @@ try
assert (i == argc); // All args parsed,
vector<path> paths;
- auto add =
- [&paths, &start] (path&& p, const std::string& pt, bool interim) -> bool
+ map<path, size_t> path_count;
+
+ auto add = [&paths, &path_count, &start] (path&& p,
+ const string& pt,
+ bool interim)
{
bool pd (!pt.empty () && pt[0] == '.'); // Dot-started pattern.
@@ -114,13 +118,58 @@ try
return !skip;
if (!skip)
- paths.emplace_back (move (p.canonicalize ()));
+ {
+ p.canonicalize ();
+
+ auto i (path_count.find (p));
+ if (i == path_count.end ())
+ path_count[p] = 1;
+ else
+ ++(i->second);
+
+ paths.emplace_back (move (p));
+ }
return true;
};
path_search (pattern, add, start);
+ // Test search in the directory tree represented by the path.
+ //
+ for (const auto& p: path_count)
+ {
+ // Will match multiple times if the pattern contains several recursive
+ // components.
+ //
+ size_t match_count (0);
+
+ auto check = [&p, &match_count] (path&& pe, const string&, bool interim)
+ {
+ if (pe == p.first)
+ {
+ if (!interim)
+ ++match_count;
+ else
+ // For self-matching the callback is first called in the interim
+ // mode (through the preopen function) with an empty path.
+ //
+ assert (pe.empty ());
+ }
+
+ return true;
+ };
+
+ path_search (pattern, p.first, check, start);
+ assert (match_count == p.second);
+
+ // Test path match.
+ //
+ assert (path_match (pattern, p.first, start));
+ }
+
+ // Print the found paths.
+ //
if (sort)
std::sort (paths.begin (), paths.end ());