Refactor implementation of case-insensitivity in tags

By not materializing the lower cased tags ahead of time, we
save allocations at the cost of worsened performance when comparing
two tags.

Since there are rarely many tags, and commonly they are not
compared even if present, this is almost always a win. The new
implementation also improves the robustness of the code
responsible for handling tags in a case-insensitive manner.
This commit is contained in:
Martin Hořeňovský
2021-12-26 22:10:20 +01:00
parent cbb6764fb1
commit 45577a1f4c
10 changed files with 43 additions and 44 deletions

View File

@@ -44,15 +44,12 @@ constexpr Catch::SourceLineInfo dummySourceLineInfo = CATCH_INTERNAL_LINEINFO;
TEST_CASE("shortened hide tags are split apart", "[tags]") {
using Catch::StringRef;
using Catch::Tag;
using Catch::Matchers::VectorContains;
Catch::TestCaseInfo testcase("", {"fake test name", "[.magic-tag]"}, dummySourceLineInfo);
// Extract parsed tags into strings
std::vector<StringRef> tags;
for (auto const& tag : testcase.tags) {
tags.push_back(tag.lowerCased);
}
REQUIRE_THAT(tags, VectorContains("magic-tag"_catch_sr) && VectorContains("."_catch_sr));
Catch::TestCaseInfo testcase("", {"fake test name", "[.magic-tag]"}, dummySourceLineInfo);
REQUIRE_THAT( testcase.tags, VectorContains( Tag( "magic-tag" ) )
&& VectorContains( Tag( "."_catch_sr ) ) );
}
TEST_CASE("tags with dots in later positions are not parsed as hidden", "[tags]") {