From 31bf6eed2a0595b84345bcacf4555a439b3de2c8 Mon Sep 17 00:00:00 2001 From: Richard Date: Wed, 17 Jan 2024 23:14:40 -0700 Subject: [PATCH] Extract Function getTestCaseLabel --- Tools/TestCases/TestCases.cpp | 22 ++++++++++++++++++---- Tools/TestCases/TestCases.h | 2 ++ 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/Tools/TestCases/TestCases.cpp b/Tools/TestCases/TestCases.cpp index 8adfd25..1e3eb4e 100644 --- a/Tools/TestCases/TestCases.cpp +++ b/Tools/TestCases/TestCases.cpp @@ -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) diff --git a/Tools/TestCases/TestCases.h b/Tools/TestCases/TestCases.h index 7b2aae6..5165e25 100644 --- a/Tools/TestCases/TestCases.h +++ b/Tools/TestCases/TestCases.h @@ -8,6 +8,8 @@ namespace testCases { +std::string_view getTestCaseLabel(std::string_view line); + class Test { public: