Creating empty glob_list_t matches everything

This is more than creating a glob_list_t containing just ‘*’, as the latter does not match hidden files, so it is more like ‘{*,.*}’, which is a bit arcane, so I think it’s better to allow using an empty list in cases where you wish to match everything (but the API accepts a glob list for filtering purposes).
This commit is contained in:
Allan Odgaard
2013-01-16 03:55:59 +01:00
parent fd14df1800
commit 10b794bb96
2 changed files with 21 additions and 0 deletions

View File

@@ -241,6 +241,9 @@ namespace path
bool glob_list_t::exclude (std::string const& path, kPathItemType itemType, bool defaultResult) const
{
if(_globs.empty())
return false;
for(auto record : _globs)
{
if((itemType == kPathItemAny || record.item_type == kPathItemAny || itemType == record.item_type) && record.glob.does_match(path))

View File

@@ -3,6 +3,24 @@
class GlobListTests : public CxxTest::TestSuite
{
public:
void test_empty_glob_list ()
{
path::glob_list_t globs;
TS_ASSERT(globs.include("foo"));
TS_ASSERT(globs.include("bar"));
TS_ASSERT(globs.include(".foo"));
TS_ASSERT(globs.include(".bar"));
}
void test_non_empty_glob_list ()
{
path::glob_list_t globs("*");
TS_ASSERT(globs.include("foo"));
TS_ASSERT(globs.include("bar"));
TS_ASSERT(globs.exclude(".foo"));
TS_ASSERT(globs.exclude(".bar"));
}
void test_glob_list ()
{
path::glob_list_t globs;