mirror of
https://github.com/catchorg/Catch2.git
synced 2025-04-29 04:03:51 +00:00
This commit extends the Matchers feature with the ability to have type-independent (e.g. templated) matchers. This is done by adding a new base type that Matchers can extend, `MatcherGenericBase`, and overloads of operators `!`, `&&` and `||` that handle matchers extending `MatcherGenericBase` in a special manner. These new matchers can also take their arguments as values and non-const references. Closes #1307 Closes #1553 Closes #1554 Co-authored-by: Martin Hořeňovský <martin.horenovsky@gmail.com>
33 lines
1.1 KiB
C++
33 lines
1.1 KiB
C++
#include <catch2/catch_matchers_templates.hpp>
|
|
|
|
namespace Catch {
|
|
namespace Matchers {
|
|
namespace Impl {
|
|
MatcherGenericBase::~MatcherGenericBase() {}
|
|
|
|
std::string describe_multi_matcher(StringRef combine, std::string const* descriptions_begin, std::string const* descriptions_end) {
|
|
std::string description;
|
|
std::size_t combined_size = 4;
|
|
for ( auto desc = descriptions_begin; desc != descriptions_end; ++desc ) {
|
|
combined_size += desc->size();
|
|
}
|
|
combined_size += (descriptions_end - descriptions_begin - 1) * combine.size();
|
|
|
|
description.reserve(combined_size);
|
|
|
|
description += "( ";
|
|
bool first = true;
|
|
for( auto desc = descriptions_begin; desc != descriptions_end; ++desc ) {
|
|
if( first )
|
|
first = false;
|
|
else
|
|
description += combine;
|
|
description += *desc;
|
|
}
|
|
description += " )";
|
|
return description;
|
|
}
|
|
}
|
|
} // namespace Matchers
|
|
} // namespace Catch
|