From 04f4bb3e2492bb6e4b0769b4c7f020493cfa5cc4 Mon Sep 17 00:00:00 2001 From: Karen Arutyunov Date: Wed, 7 Jun 2017 17:18:54 +0300 Subject: Add path_match() and path_search() overloads --- tests/wildcard/driver.cxx | 55 ++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 52 insertions(+), 3 deletions(-) (limited to 'tests/wildcard') 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 #include #include #include @@ -90,8 +91,11 @@ try assert (i == argc); // All args parsed, vector paths; - auto add = - [&paths, &start] (path&& p, const std::string& pt, bool interim) -> bool + map 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 ()); -- cgit v1.1