Added test case for paths include filter (Fixes #113)

This commit is contained in:
Bartek Kryza
2023-03-27 20:03:22 +02:00
parent 97177e09a1
commit e9a4504827
11 changed files with 154 additions and 8 deletions

View File

@@ -64,7 +64,8 @@ bool diagram::should_include(const element &e) const
if (filter_.get() == nullptr)
return true;
return filter_->should_include(e);
return filter_->should_include(e) &&
filter_->should_include(dynamic_cast<const source_location &>(e));
}
bool diagram::should_include(const std::string &name) const

View File

@@ -121,6 +121,12 @@ tvl::value_t filter_visitor::match(
return {};
}
tvl::value_t filter_visitor::match(
const diagram & /*d*/, const common::model::source_location & /*f*/) const
{
return {};
}
bool filter_visitor::is_inclusive() const
{
return type_ == filter_t::kInclusive;
@@ -413,7 +419,7 @@ paths_filter::paths_filter(filter_t type, const std::filesystem::path &root,
}
catch (std::filesystem::filesystem_error &e) {
LOG_WARN("Cannot add non-existent path {} to paths filter",
path.string());
absolute_path.string());
continue;
}
@@ -447,6 +453,31 @@ tvl::value_t paths_filter::match(
return false;
}
tvl::value_t paths_filter::match(
const diagram & /*d*/, const common::model::source_location &p) const
{
if (paths_.empty()) {
return {};
}
auto sl_path = std::filesystem::path{p.file()};
// Matching source paths doesn't make sens if they are not absolute or empty
if (p.file().empty() || sl_path.is_relative()) {
return {};
}
for (const auto &path : paths_) {
if (sl_path.root_name().string() == path.root_name().string() &&
util::starts_with(sl_path.relative_path(), path.relative_path())) {
return true;
}
}
return false;
}
diagram_filter::diagram_filter(
const common::model::diagram &d, const config::diagram &c)
: diagram_{d}

View File

@@ -75,6 +75,9 @@ public:
virtual tvl::value_t match(
const diagram &d, const common::model::source_file &f) const;
virtual tvl::value_t match(
const diagram &d, const common::model::source_location &f) const;
bool is_inclusive() const;
bool is_exclusive() const;
@@ -332,6 +335,9 @@ struct paths_filter : public filter_visitor {
tvl::value_t match(
const diagram &d, const common::model::source_file &r) const override;
tvl::value_t match(const diagram &d,
const common::model::source_location &sl) const override;
private:
std::vector<std::filesystem::path> paths_;
std::filesystem::path root_;

View File

@@ -400,6 +400,7 @@ template <> struct convert<class_diagram> {
get_option(node, rhs.generate_packages);
get_option(node, rhs.relationship_hints);
get_option(node, rhs.type_aliases);
get_option(node, rhs.relative_to);
get_option(node, rhs.comment_parser);
rhs.initialize_relationship_hints();