Use StringRefs in SectionTracker's filter bookkeeping

This commit is contained in:
Martin Hořeňovský 2021-09-09 11:04:34 +02:00
parent 317db82396
commit 12bca890b7
No known key found for this signature in database
GPG Key ID: DE48307B8B0D381A
2 changed files with 11 additions and 10 deletions

View File

@ -186,7 +186,7 @@ namespace TestCaseTracking {
bool complete = true;
if (m_filters.empty()
|| m_filters[0] == ""
|| m_filters[0].empty()
|| std::find(m_filters.begin(), m_filters.end(), m_trimmed_name) != m_filters.end()) {
complete = TrackerBase::isComplete();
}
@ -223,21 +223,21 @@ namespace TestCaseTracking {
void SectionTracker::addInitialFilters( std::vector<std::string> const& filters ) {
if( !filters.empty() ) {
m_filters.reserve( m_filters.size() + filters.size() + 2 );
m_filters.emplace_back(""); // Root - should never be consulted
m_filters.emplace_back(""); // Test Case - not a section filter
m_filters.emplace_back(StringRef{}); // Root - should never be consulted
m_filters.emplace_back(StringRef{}); // Test Case - not a section filter
m_filters.insert( m_filters.end(), filters.begin(), filters.end() );
}
}
void SectionTracker::addNextFilters( std::vector<std::string> const& filters ) {
void SectionTracker::addNextFilters( std::vector<StringRef> const& filters ) {
if( filters.size() > 1 )
m_filters.insert( m_filters.end(), filters.begin()+1, filters.end() );
}
std::vector<std::string> const& SectionTracker::getFilters() const {
std::vector<StringRef> const& SectionTracker::getFilters() const {
return m_filters;
}
std::string const& SectionTracker::trimmedName() const {
StringRef SectionTracker::trimmedName() const {
return m_trimmed_name;
}

View File

@ -10,6 +10,7 @@
#include <catch2/internal/catch_source_line_info.hpp>
#include <catch2/internal/catch_unique_ptr.hpp>
#include <catch2/internal/catch_stringref.hpp>
#include <string>
#include <vector>
@ -164,7 +165,7 @@ namespace TestCaseTracking {
};
class SectionTracker : public TrackerBase {
std::vector<std::string> m_filters;
std::vector<StringRef> m_filters;
std::string m_trimmed_name;
public:
SectionTracker( NameAndLocation const& nameAndLocation, TrackerContext& ctx, ITracker* parent );
@ -178,11 +179,11 @@ namespace TestCaseTracking {
void tryOpen();
void addInitialFilters( std::vector<std::string> const& filters );
void addNextFilters( std::vector<std::string> const& filters );
void addNextFilters( std::vector<StringRef> const& filters );
//! Returns filters active in this tracker
std::vector<std::string> const& getFilters() const;
std::vector<StringRef> const& getFilters() const;
//! Returns whitespace-trimmed name of the tracked section
std::string const& trimmedName() const;
StringRef trimmedName() const;
};
} // namespace TestCaseTracking