Tighten the directory name mathing with -i.
Only match full directory names as parts of whole paths. So -isrc matches src/file.cpp and proj/src/file.cpp. But does not match mysrc/file.cpp or proj/srcfiles/file.cpp.
This commit is contained in:
parent
e9ec4bc3e4
commit
f65fa338a5
|
@ -35,7 +35,14 @@ bool PathMatch::Match(const std::string &path)
|
||||||
if (findpath[findpath.length() - 1] != '/')
|
if (findpath[findpath.length() - 1] != '/')
|
||||||
findpath = RemoveFilename(findpath);
|
findpath = RemoveFilename(findpath);
|
||||||
|
|
||||||
if (findpath.find(*iterMask) != std::string::npos)
|
// Match relative paths starting with mask
|
||||||
|
// -isrc matches src/foo.cpp
|
||||||
|
if (findpath.compare(0, (*iterMask).size(), *iterMask) == 0)
|
||||||
|
return true;
|
||||||
|
// Match only full directory name in middle or end of the path
|
||||||
|
// -isrc matches myproject/src/ but does not match
|
||||||
|
// myproject/srcfiles/ or myproject/mysrc/
|
||||||
|
if (findpath.find("/" + *iterMask) != std::string::npos)
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
|
|
@ -38,6 +38,10 @@ private:
|
||||||
TEST_CASE(onemaskemptypath);
|
TEST_CASE(onemaskemptypath);
|
||||||
TEST_CASE(onemasksamepath);
|
TEST_CASE(onemasksamepath);
|
||||||
TEST_CASE(onemasksamepathwithfile);
|
TEST_CASE(onemasksamepathwithfile);
|
||||||
|
TEST_CASE(onemaskdifferentdir1);
|
||||||
|
TEST_CASE(onemaskdifferentdir2);
|
||||||
|
TEST_CASE(onemaskdifferentdir3);
|
||||||
|
TEST_CASE(onemaskdifferentdir4);
|
||||||
TEST_CASE(onemasklongerpath1);
|
TEST_CASE(onemasklongerpath1);
|
||||||
TEST_CASE(onemasklongerpath2);
|
TEST_CASE(onemasklongerpath2);
|
||||||
TEST_CASE(onemasklongerpath3);
|
TEST_CASE(onemasklongerpath3);
|
||||||
|
@ -95,6 +99,38 @@ private:
|
||||||
ASSERT(match.Match("src/file.txt"));
|
ASSERT(match.Match("src/file.txt"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void onemaskdifferentdir1()
|
||||||
|
{
|
||||||
|
std::vector<std::string> masks;
|
||||||
|
masks.push_back("src/");
|
||||||
|
PathMatch match(masks);
|
||||||
|
ASSERT(!match.Match("srcfiles/file.txt"));
|
||||||
|
}
|
||||||
|
|
||||||
|
void onemaskdifferentdir2()
|
||||||
|
{
|
||||||
|
std::vector<std::string> masks;
|
||||||
|
masks.push_back("src/");
|
||||||
|
PathMatch match(masks);
|
||||||
|
ASSERT(!match.Match("proj/srcfiles/file.txt"));
|
||||||
|
}
|
||||||
|
|
||||||
|
void onemaskdifferentdir3()
|
||||||
|
{
|
||||||
|
std::vector<std::string> masks;
|
||||||
|
masks.push_back("src/");
|
||||||
|
PathMatch match(masks);
|
||||||
|
ASSERT(!match.Match("proj/mysrc/file.txt"));
|
||||||
|
}
|
||||||
|
|
||||||
|
void onemaskdifferentdir4()
|
||||||
|
{
|
||||||
|
std::vector<std::string> masks;
|
||||||
|
masks.push_back("src/");
|
||||||
|
PathMatch match(masks);
|
||||||
|
ASSERT(!match.Match("proj/mysrcfiles/file.txt"));
|
||||||
|
}
|
||||||
|
|
||||||
void onemasklongerpath1()
|
void onemasklongerpath1()
|
||||||
{
|
{
|
||||||
std::vector<std::string> masks;
|
std::vector<std::string> masks;
|
||||||
|
|
Loading…
Reference in New Issue