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 852a4b1 commit d47f7ea
Show file tree
Hide file tree
Showing 2 changed files with 111 additions and 3 deletions.
4 changes: 1 addition & 3 deletions Src/CompareEngines/ByteCompare.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ int ByteCompare::CompareFiles(DiffFileData* diffData)
bfend[i] += rtn;
if (m_pOptions->m_bIgnoreEofNewlinePresence)
{
for (int j = bfstart[i]; j < bfend[i]; ++j)
for (int j = (std::max)(bfstart[i], bfend[i] - 4); j < bfend[i]; ++j)
{
const char c = buff[i][j];
if (c == '\r' || c == '\n')
Expand Down Expand Up @@ -277,9 +277,7 @@ int ByteCompare::CompareFiles(DiffFileData* diffData)

// If either unfinished, they differ
if (ptr0 != end0 || ptr1 != end1)
{
diffcode = (diffcode & DIFFCODE::DIFF);
}
if (diffcode & DIFFCODE::DIFF)
return diffcode | DIFFCODE::DIFF;
else
Expand Down
110 changes: 110 additions & 0 deletions Testing/GoogleTest/ByteCompare/ByteCompare_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -795,6 +795,49 @@ namespace
EXPECT_EQ(DIFFCODE::TEXT | DIFFCODE::DIFF, bc.CompareFiles(&pair.diffData));
}
}

for (int i = 0; i < 4; i++)
{
{// diff left: CRLF+CRLF - right: no EOL
std::vector<char> buf_left(WMCMPBUFF * 2 + i);
std::vector<char> buf_right(WMCMPBUFF * 2 - 4 + i);

memset(buf_left.data(), 'A', buf_left.size());
memset(buf_right.data(), 'A', buf_right.size());

buf_left[buf_left.size() - 4] = '\r';
buf_left[buf_left.size() - 3] = '\n';
buf_left[buf_left.size() - 2] = '\r';
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());

FilePair pair(filename_left, filename_right);

EXPECT_EQ(DIFFCODE::TEXT | DIFFCODE::DIFF, bc.CompareFiles(&pair.diffData));
}

{// diff left: no EOL - right: CRLF+CRLF
std::vector<char> buf_left(WMCMPBUFF * 2 - 4 + i);
std::vector<char> buf_right(WMCMPBUFF * 2 + i);

memset(buf_left.data(), 'A', buf_left.size());
memset(buf_right.data(), 'A', buf_right.size());

buf_right[buf_right.size() - 4] = '\r';
buf_right[buf_right.size() - 3] = '\n';
buf_right[buf_right.size() - 2] = '\r';
buf_right[buf_right.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());

FilePair pair(filename_left, filename_right);

EXPECT_EQ(DIFFCODE::TEXT | DIFFCODE::DIFF, bc.CompareFiles(&pair.diffData));
}
}
}

Check notice

Code scanning / CodeQL

Block with too many statements Note

Block with too many statements (6 complex statements in the block).

TEST_F(ByteCompareTest, IgnoreEofNewlinePresenceAndIgnoreEOLDifference)
Expand Down Expand Up @@ -1072,6 +1115,73 @@ namespace
EXPECT_EQ(DIFFCODE::TEXT | DIFFCODE::DIFF, bc.CompareFiles(&pair.diffData));
}
}

for (int i = 0; i < 4; i++)
{
{// diff left: CRLF+CRLF - right: no EOL
std::vector<char> buf_left(WMCMPBUFF * 2 - 4 + i);
std::vector<char> buf_right(WMCMPBUFF * 2 - 4 + 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[28] = '\r';
buf_right[30] = '\r';
buf_right[31] = '\n';

buf_left[buf_left.size() - 4] = '\r';
buf_left[buf_left.size() - 3] = '\n';
buf_left[buf_left.size() - 2] = '\r';
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());

FilePair pair(filename_left, filename_right);

EXPECT_EQ(DIFFCODE::TEXT | DIFFCODE::DIFF, bc.CompareFiles(&pair.diffData));
}

{// diff left: no EOL - right: CRLF+CRLF
std::vector<char> buf_left(WMCMPBUFF * 2 - 4 + i);
std::vector<char> buf_right(WMCMPBUFF * 2 - 4 + 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[28] = '\r';
buf_left[30] = '\r';
buf_left[31] = '\n';

buf_right[buf_right.size() - 4] = '\r';
buf_right[buf_right.size() - 3] = '\n';
buf_right[buf_right.size() - 2] = '\r';
buf_right[buf_right.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());

FilePair pair(filename_left, filename_right);

EXPECT_EQ(DIFFCODE::TEXT | DIFFCODE::DIFF, bc.CompareFiles(&pair.diffData));
}
}
}

Check notice

Code scanning / CodeQL

Block with too many statements Note

Block with too many statements (6 complex statements in the block).

} // namespace

0 comments on commit d47f7ea

Please sign in to comment.