Skip to content

Commit

Permalink
Extract Function getTestCaseLabel
Browse files Browse the repository at this point in the history
  • Loading branch information
LegalizeAdulthood committed Jan 18, 2024
1 parent dc0de96 commit 31bf6ee
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
22 changes: 18 additions & 4 deletions Tools/TestCases/TestCases.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,17 +90,31 @@ void Test::checkLabel(std::string_view label, std::string_view desc)
}
}

void Test::scanTestCaseLine(std::string_view line)
std::string_view getTestCaseLabel(std::string_view line)
{
if (size_t pos = line.find("#TEST#"); pos != std::string::npos)
{
const size_t begin = line.find_first_not_of(" \t", line.find_first_of(' ', pos));
const size_t end = line.find_first_of(' ', begin);
const std::string_view label = line.substr(begin, end - begin);
const std::string_view desc =
end != std::string_view::npos ? line.substr(line.find_first_not_of(' ', end)) : "";
checkLabel(label, desc);
return label;
}
return {};
}

void Test::scanTestCaseLine(std::string_view line)
{
const std::string_view label = getTestCaseLabel(line);
if (label.empty())
{
return;
}

const size_t begin = line.find_first_not_of(" \t", line.find(label) + label.length() - 1);
const size_t end = line.find_first_of(' ', begin);
const std::string_view desc =
end != std::string_view::npos ? line.substr(line.find_first_not_of(' ', end)) : "";
checkLabel(label, desc);
}

void Test::scanTestCaseFile(std::filesystem::path path)
Expand Down
2 changes: 2 additions & 0 deletions Tools/TestCases/TestCases.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
namespace testCases
{

std::string_view getTestCaseLabel(std::string_view line);

class Test
{
public:
Expand Down

0 comments on commit 31bf6ee

Please sign in to comment.