Made macroName and capturedExpression StringRefs

This commit is contained in:
Phil Nash 2017-08-08 01:22:21 +01:00
parent 59f9bcf1ed
commit f8148ebae1
5 changed files with 16 additions and 15 deletions

View File

@ -14,7 +14,7 @@ namespace Catch {
bool DecomposedExpression::isBinaryExpression() const {
return false;
}
void AssertionResultData::negate( bool parenthesize ) {
negated = !negated;
parenthesized = parenthesize;
@ -68,16 +68,16 @@ namespace Catch {
std::string AssertionResult::getExpression() const {
if (isFalseTest(m_info.resultDisposition))
return '!' + std::string(m_info.capturedExpression);
return '!' + std::string(m_info.capturedExpression.c_str());
else
return std::string(m_info.capturedExpression);
return std::string(m_info.capturedExpression.c_str());
}
std::string AssertionResult::getExpressionInMacro() const {
if( m_info.macroName[0] == 0 )
return std::string(m_info.capturedExpression);
return std::string(m_info.capturedExpression.c_str());
else
return std::string(m_info.macroName) + "( " + m_info.capturedExpression + " )";
return std::string(m_info.macroName.c_str()) + "( " + m_info.capturedExpression.c_str() + " )";
}
bool AssertionResult::hasExpandedExpression() const {
@ -96,7 +96,7 @@ namespace Catch {
}
std::string AssertionResult::getTestMacroName() const {
return m_info.macroName;
return m_info.macroName.c_str();
}
void AssertionResult::discardDecomposedExpression() const {

View File

@ -11,6 +11,7 @@
#include <string>
#include "catch_result_type.h"
#include "catch_common.h"
#include "catch_stringref.h"
namespace Catch {
@ -39,9 +40,9 @@ namespace Catch {
struct AssertionInfo
{
char const * macroName;
StringRef macroName;
SourceLineInfo lineInfo;
char const * capturedExpression;
StringRef capturedExpression;
ResultDisposition::Flags resultDisposition;
AssertionInfo() = delete;

View File

@ -40,7 +40,7 @@ namespace Catch {
if( assertionResult.hasMessage() ) {
// Copy message into messages list.
// !TBD This should have been done earlier, somewhere
MessageBuilder builder( assertionResult.getTestMacroName(), assertionResult.getSourceInfo(), assertionResult.getResultType() );
MessageBuilder builder( assertionResult.getTestMacroName().c_str(), assertionResult.getSourceInfo(), assertionResult.getResultType() );
builder << assertionResult.getMessage();
builder.m_info.message = builder.m_stream.str();

View File

@ -30,9 +30,9 @@ namespace Catch {
}
ResultBuilder::ResultBuilder( char const* macroName,
ResultBuilder::ResultBuilder( StringRef macroName,
SourceLineInfo const& lineInfo,
char const* capturedExpression,
StringRef capturedExpression,
ResultDisposition::Flags resultDisposition )
: m_assertionInfo{ macroName, lineInfo, capturedExpression, resultDisposition }
{
@ -99,7 +99,7 @@ namespace Catch {
assert( !isFalseTest( m_assertionInfo.resultDisposition ) );
AssertionResultData data = m_data;
data.resultType = ResultWas::Ok;
data.reconstructedExpression = m_assertionInfo.capturedExpression;
data.reconstructedExpression = m_assertionInfo.capturedExpression.c_str();
std::string actualMessage = Catch::translateActiveException();
if( !matcher.match( actualMessage ) ) {
@ -166,7 +166,7 @@ namespace Catch {
}
void ResultBuilder::reconstructExpression( std::string& dest ) const {
dest = m_assertionInfo.capturedExpression;
dest = m_assertionInfo.capturedExpression.c_str();
}
void ResultBuilder::setExceptionGuard() {

View File

@ -31,9 +31,9 @@ namespace Catch {
class ResultBuilder : public DecomposedExpression {
public:
ResultBuilder( char const* macroName,
ResultBuilder( StringRef macroName,
SourceLineInfo const& lineInfo,
char const* capturedExpression,
StringRef capturedExpression,
ResultDisposition::Flags resultDisposition);
~ResultBuilder();