Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
sdottaka committed Dec 16, 2024
1 parent 6e50319 commit 76b5948
Show file tree
Hide file tree
Showing 2 changed files with 80 additions and 14 deletions.
4 changes: 1 addition & 3 deletions Src/CompareEngines/ByteComparator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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))
{
Expand Down Expand Up @@ -424,8 +424,6 @@ ByteComparator::COMP_RESULT ByteComparator::CompareBuffers(
}
goto need_more;
}
result = RESULT_DIFF;
goto exit;
}
}
if (ptr0 == end0 && ptr1 == end1)
Expand Down
90 changes: 79 additions & 11 deletions Testing/GoogleTest/ByteCompare/ByteCompare_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,6 @@ namespace

}


TEST_F(ByteCompareTest, IgnoreAllSpace)
{
CompareEngines::ByteCompare bc;
Expand Down Expand Up @@ -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());

Expand All @@ -833,11 +833,15 @@ namespace

{// same left: no EOL - right: LF
std::vector<char> buf_left(WMCMPBUFF * 2 - 1 + i);
std::vector<char> buf_right(WMCMPBUFF * 2 + i);
std::vector<char> 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());
Expand All @@ -852,12 +856,20 @@ namespace
for (int i = 0; i < 3; i++)
{
{// same left: CRLF - right: no EOL
std::vector<char> buf_left(WMCMPBUFF * 2 + i);
std::vector<char> buf_left(WMCMPBUFF * 2 - 2 + i);
std::vector<char> 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';

Expand All @@ -871,11 +883,19 @@ namespace

{// same left: no EOL - right: CRLF
std::vector<char> buf_left(WMCMPBUFF * 2 - 2 + i);
std::vector<char> buf_right(WMCMPBUFF * 2 + i);
std::vector<char> 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';

Expand All @@ -891,12 +911,20 @@ namespace
for (int i = 0; i < 3; i++)
{
{// diff left: CR+A - right: no EOL
std::vector<char> buf_left(WMCMPBUFF * 2 + i);
std::vector<char> buf_left(WMCMPBUFF * 2 - 2 + i);
std::vector<char> 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';

Expand All @@ -910,11 +938,19 @@ namespace

{// diff left: no EOL - right: CR+A
std::vector<char> buf_left(WMCMPBUFF * 2 - 2 + i);
std::vector<char> buf_right(WMCMPBUFF * 2 + i);
std::vector<char> 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';

Expand All @@ -930,12 +966,20 @@ namespace
for (int i = 0; i < 3; i++)
{
{// diff left: LF+LF - right: no EOL
std::vector<char> buf_left(WMCMPBUFF * 2 + i);
std::vector<char> buf_left(WMCMPBUFF * 2 - 2 + i);
std::vector<char> 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';

Expand All @@ -949,11 +993,19 @@ namespace

{// diff left: no EOL - right: LF+LF
std::vector<char> buf_left(WMCMPBUFF * 2 - 2 + i);
std::vector<char> buf_right(WMCMPBUFF * 2 + i);
std::vector<char> 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';

Expand All @@ -969,12 +1021,20 @@ namespace
for (int i = 0; i < 3; i++)
{
{// diff left: CR+CR - right: no EOL
std::vector<char> buf_left(WMCMPBUFF * 2 + i);
std::vector<char> buf_left(WMCMPBUFF * 2 - 2 + i);
std::vector<char> 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';

Expand All @@ -988,11 +1048,19 @@ namespace

{// diff left: no EOL - right: CR+CR
std::vector<char> buf_left(WMCMPBUFF * 2 - 2 + i);
std::vector<char> buf_right(WMCMPBUFF * 2 + i);
std::vector<char> 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';

Expand Down

0 comments on commit 76b5948

Please sign in to comment.