testStrEq() better diff
This commit is contained in:
+1
-48
@@ -167,15 +167,6 @@ testCase& testCase::setPassMatch(const std::string& expr, const std::string& inp
|
||||
|
||||
namespace detail {
|
||||
|
||||
static
|
||||
size_t findNextLine(const std::string& s, size_t pos=0u)
|
||||
{
|
||||
size_t next = s.find_first_of('\n', pos);
|
||||
if(next!=std::string::npos)
|
||||
next++;
|
||||
return next;
|
||||
}
|
||||
|
||||
testCase _testStrTest(unsigned op, const char *sLHS, const char* rlhs, const char *sRHS, const char* rrhs)
|
||||
{
|
||||
bool eq;
|
||||
@@ -187,45 +178,7 @@ testCase _testStrTest(unsigned op, const char *sLHS, const char* rlhs, const cha
|
||||
eq = strcmp(rlhs, rrhs)==0;
|
||||
testCase ret(eq==op);
|
||||
ret<<sLHS<<(op ? " == " : " != ")<<sRHS<<"\n";
|
||||
|
||||
std::string lhs(rlhs ? rlhs : "<null>");
|
||||
std::string rhs(rrhs ? rrhs : "<null>");
|
||||
|
||||
size_t posL=0u, posR=0u;
|
||||
|
||||
while(posL<lhs.size() && posR<rhs.size()) {
|
||||
size_t eolL = findNextLine(lhs, posL);
|
||||
size_t eolR = findNextLine(rhs, posR);
|
||||
|
||||
auto L = lhs.substr(posL, eolL-posL);
|
||||
auto R = rhs.substr(posR, eolR-posR);
|
||||
|
||||
if(L==R) {
|
||||
ret<<" \""<<escape(L)<<"\"\n";
|
||||
} else {
|
||||
ret<<"+ \""<<escape(R)<<"\"\n";
|
||||
ret<<"- \""<<escape(L)<<"\"\n";
|
||||
}
|
||||
|
||||
posL = eolL;
|
||||
posR = eolR;
|
||||
}
|
||||
|
||||
while(posR<rhs.size()) {
|
||||
size_t eol = findNextLine(rhs, posR);
|
||||
auto line = rhs.substr(posR, eol-posR);
|
||||
ret<<"+ \""<<escape(line)<<"\"\n";
|
||||
|
||||
posR = eol;
|
||||
}
|
||||
|
||||
while(posL<lhs.size()) {
|
||||
size_t eol = findNextLine(lhs, posL);
|
||||
auto line = lhs.substr(posL, eol-posL);
|
||||
ret<<"- \""<<escape(line)<<"\"\n";
|
||||
|
||||
posL = eol;
|
||||
}
|
||||
strDiff(ret.stream(), rlhs, rrhs);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user