diff --git a/Src/CompareEngines/ByteComparator.cpp b/Src/CompareEngines/ByteComparator.cpp index bcd253c0819..3567c1c30fd 100644 --- a/Src/CompareEngines/ByteComparator.cpp +++ b/Src/CompareEngines/ByteComparator.cpp @@ -349,7 +349,7 @@ ByteComparator::COMP_RESULT ByteComparator::CompareBuffers( // these flags mean possible split CR/LF goto need_more; } - if (m_eol0 || m_eol1) + if (!m_ignore_eof_newline_presence && (m_eol0 || m_eol1)) { if ((!m_eol0 || !m_eol1) && (orig0 == end0 || orig1 == end1)) { @@ -424,8 +424,6 @@ ByteComparator::COMP_RESULT ByteComparator::CompareBuffers( } goto need_more; } - result = RESULT_DIFF; - goto exit; } } if (ptr0 == end0 && ptr1 == end1) diff --git a/Testing/GoogleTest/ByteCompare/ByteCompare_test.cpp b/Testing/GoogleTest/ByteCompare/ByteCompare_test.cpp index 6c53c76282d..05786432de5 100644 --- a/Testing/GoogleTest/ByteCompare/ByteCompare_test.cpp +++ b/Testing/GoogleTest/ByteCompare/ByteCompare_test.cpp @@ -133,7 +133,6 @@ namespace } - TEST_F(ByteCompareTest, IgnoreAllSpace) { CompareEngines::ByteCompare bc; @@ -819,10 +818,11 @@ namespace memset(buf_right.data(), 'A', buf_right.size()); buf_left[10] = '\n'; - buf_left[buf_left.size() - 1] = '\n'; buf_right[10] = '\r'; buf_right[11] = '\n'; + buf_left[buf_left.size() - 1] = '\n'; + TempFile file_left(filename_left, buf_left.data(), buf_left.size()); TempFile file_right(filename_right, buf_right.data(), buf_right.size()); @@ -833,11 +833,15 @@ namespace {// same left: no EOL - right: LF std::vector buf_left(WMCMPBUFF * 2 - 1 + i); - std::vector buf_right(WMCMPBUFF * 2 + i); + std::vector buf_right(WMCMPBUFF * 2 - 1 + i); memset(buf_left.data(), 'A', buf_left.size()); memset(buf_right.data(), 'A', buf_right.size()); + buf_right[10] = '\n'; + buf_left[10] = '\r'; + buf_left[11] = '\n'; + buf_right[buf_right.size() - 1] = '\n'; TempFile file_left(filename_left, buf_left.data(), buf_left.size()); @@ -852,12 +856,20 @@ namespace for (int i = 0; i < 3; i++) { {// same left: CRLF - right: no EOL - std::vector buf_left(WMCMPBUFF * 2 + i); + std::vector buf_left(WMCMPBUFF * 2 - 2 + i); std::vector buf_right(WMCMPBUFF * 2 - 2 + i); memset(buf_left.data(), 'A', buf_left.size()); memset(buf_right.data(), 'A', buf_right.size()); + buf_left[10] = '\n'; + buf_right[10] = '\r'; + buf_right[11] = '\n'; + + buf_left[19] = '\r'; + buf_right[20] = '\r'; + buf_right[21] = '\n'; + buf_left[buf_left.size() - 2] = '\r'; buf_left[buf_left.size() - 1] = '\n'; @@ -871,11 +883,19 @@ namespace {// same left: no EOL - right: CRLF std::vector buf_left(WMCMPBUFF * 2 - 2 + i); - std::vector buf_right(WMCMPBUFF * 2 + i); + std::vector buf_right(WMCMPBUFF * 2 - 2 + i); memset(buf_left.data(), 'A', buf_left.size()); memset(buf_right.data(), 'A', buf_right.size()); + buf_right[10] = '\n'; + buf_left[10] = '\r'; + buf_left[11] = '\n'; + + buf_right[19] = '\r'; + buf_left[20] = '\r'; + buf_left[21] = '\n'; + buf_right[buf_right.size() - 2] = '\r'; buf_right[buf_right.size() - 1] = '\n'; @@ -891,12 +911,20 @@ namespace for (int i = 0; i < 3; i++) { {// diff left: CR+A - right: no EOL - std::vector buf_left(WMCMPBUFF * 2 + i); + std::vector buf_left(WMCMPBUFF * 2 - 2 + i); std::vector buf_right(WMCMPBUFF * 2 - 2 + i); memset(buf_left.data(), 'A', buf_left.size()); memset(buf_right.data(), 'A', buf_right.size()); + buf_left[10] = '\n'; + buf_right[10] = '\r'; + buf_right[11] = '\n'; + + buf_left[19] = '\r'; + buf_right[20] = '\r'; + buf_right[21] = '\n'; + buf_left[buf_left.size() - 2] = '\r'; buf_left[buf_left.size() - 1] = 'A'; @@ -910,11 +938,19 @@ namespace {// diff left: no EOL - right: CR+A std::vector buf_left(WMCMPBUFF * 2 - 2 + i); - std::vector buf_right(WMCMPBUFF * 2 + i); + std::vector buf_right(WMCMPBUFF * 2 - 2 + i); memset(buf_left.data(), 'A', buf_left.size()); memset(buf_right.data(), 'A', buf_right.size()); + buf_right[10] = '\n'; + buf_left[10] = '\r'; + buf_left[11] = '\n'; + + buf_right[19] = '\r'; + buf_left[20] = '\r'; + buf_left[21] = '\n'; + buf_right[buf_right.size() - 2] = '\r'; buf_right[buf_right.size() - 1] = 'A'; @@ -930,12 +966,20 @@ namespace for (int i = 0; i < 3; i++) { {// diff left: LF+LF - right: no EOL - std::vector buf_left(WMCMPBUFF * 2 + i); + std::vector buf_left(WMCMPBUFF * 2 - 2 + i); std::vector buf_right(WMCMPBUFF * 2 - 2 + i); memset(buf_left.data(), 'A', buf_left.size()); memset(buf_right.data(), 'A', buf_right.size()); + buf_left[10] = '\n'; + buf_right[10] = '\r'; + buf_right[11] = '\n'; + + buf_left[19] = '\r'; + buf_right[20] = '\r'; + buf_right[21] = '\n'; + buf_left[buf_left.size() - 2] = '\n'; buf_left[buf_left.size() - 1] = '\n'; @@ -949,11 +993,19 @@ namespace {// diff left: no EOL - right: LF+LF std::vector buf_left(WMCMPBUFF * 2 - 2 + i); - std::vector buf_right(WMCMPBUFF * 2 + i); + std::vector buf_right(WMCMPBUFF * 2 - 2 + i); memset(buf_left.data(), 'A', buf_left.size()); memset(buf_right.data(), 'A', buf_right.size()); + buf_right[10] = '\n'; + buf_left[10] = '\r'; + buf_left[11] = '\n'; + + buf_right[19] = '\r'; + buf_left[20] = '\r'; + buf_left[21] = '\n'; + buf_right[buf_right.size() - 2] = '\n'; buf_right[buf_right.size() - 1] = '\n'; @@ -969,12 +1021,20 @@ namespace for (int i = 0; i < 3; i++) { {// diff left: CR+CR - right: no EOL - std::vector buf_left(WMCMPBUFF * 2 + i); + std::vector buf_left(WMCMPBUFF * 2 - 2 + i); std::vector buf_right(WMCMPBUFF * 2 - 2 + i); memset(buf_left.data(), 'A', buf_left.size()); memset(buf_right.data(), 'A', buf_right.size()); + buf_left[10] = '\n'; + buf_right[10] = '\r'; + buf_right[11] = '\n'; + + buf_left[19] = '\r'; + buf_right[20] = '\r'; + buf_right[21] = '\n'; + buf_left[buf_left.size() - 2] = '\r'; buf_left[buf_left.size() - 1] = '\r'; @@ -988,11 +1048,19 @@ namespace {// diff left: no EOL - right: CR+CR std::vector buf_left(WMCMPBUFF * 2 - 2 + i); - std::vector buf_right(WMCMPBUFF * 2 + i); + std::vector buf_right(WMCMPBUFF * 2 - 2 + i); memset(buf_left.data(), 'A', buf_left.size()); memset(buf_right.data(), 'A', buf_right.size()); + buf_right[10] = '\n'; + buf_left[10] = '\r'; + buf_left[11] = '\n'; + + buf_right[19] = '\r'; + buf_left[20] = '\r'; + buf_left[21] = '\n'; + buf_right[buf_right.size() - 2] = '\r'; buf_right[buf_right.size() - 1] = '\r';