mirror of
https://github.com/catchorg/Catch2.git
synced 2025-08-01 21:05:39 +02:00
Allow quotes in CAPTURE arguments (#1608)
* Allow quotes in CAPTURE arguments Fix CAPTURE to handle string and character literals properly
This commit is contained in:

committed by
Martin Hořeňovský

parent
979bbf03bb
commit
9c741fe960
@@ -9,6 +9,7 @@
|
||||
#include "catch_message.h"
|
||||
#include "catch_interfaces_capture.h"
|
||||
#include "catch_uncaught_exceptions.h"
|
||||
#include "catch_enforce.h"
|
||||
|
||||
#include <cassert>
|
||||
#include <stack>
|
||||
@@ -76,6 +77,15 @@ namespace Catch {
|
||||
}
|
||||
return names.substr(start, end - start + 1);
|
||||
};
|
||||
auto skipq = [&] (size_t start, char quote) {
|
||||
for (auto i = start + 1; i < names.size() ; ++i) {
|
||||
if (names[i] == quote)
|
||||
return i;
|
||||
if (names[i] == '\\')
|
||||
++i;
|
||||
}
|
||||
CATCH_INTERNAL_ERROR("CAPTURE parsing encountered unmatched parentheses");
|
||||
};
|
||||
|
||||
size_t start = 0;
|
||||
std::stack<char> openings;
|
||||
@@ -96,6 +106,10 @@ namespace Catch {
|
||||
// case '>':
|
||||
openings.pop();
|
||||
break;
|
||||
case '"':
|
||||
case '\'':
|
||||
pos = skipq(pos, c);
|
||||
break;
|
||||
case ',':
|
||||
if (start != pos && openings.size() == 0) {
|
||||
m_messages.emplace_back(macroName, lineInfo, resultType);
|
||||
|
Reference in New Issue
Block a user