Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
sdottaka committed Dec 18, 2024
1 parent a2c5c43 commit 1d46fa4
Show file tree
Hide file tree
Showing 2 changed files with 120 additions and 0 deletions.
2 changes: 2 additions & 0 deletions Src/DiffWrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1227,6 +1227,7 @@ CDiffWrapper::LoadWinMergeDiffsFromDiffUtilsScript(struct change * script, const
struct change *next = script;

const bool usefilters = m_options.m_filterCommentsLines ||
m_options.m_bIgnoreEofNewlinePresence ||
(m_pFilterList && m_pFilterList->HasRegExps()) ||
(m_pSubstitutionList && m_pSubstitutionList->HasRegExps());

Expand Down Expand Up @@ -1398,6 +1399,7 @@ CDiffWrapper::LoadWinMergeDiffsFromDiffUtilsScript3(
diff12.Clear();

const bool usefilters = m_options.m_filterCommentsLines ||
m_options.m_bIgnoreEofNewlinePresence ||
(m_pFilterList && m_pFilterList->HasRegExps()) ||
(m_pSubstitutionList && m_pSubstitutionList->HasRegExps());

Expand Down
118 changes: 118 additions & 0 deletions Testing/GoogleTest/DiffWrapper/DiffWrapper_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,124 @@ TEST(DiffWrapper, RunFileDiff_NoEol)
}
}

TEST(DiffWrapper, RunFileDiff_IgnoreEofNewlinePresence)

Check warning

Code scanning / CodeQL

Poorly documented large function Warning

Poorly documented function: fewer than 2% comments for a function of 117 lines.
{
CDiffWrapper dw;
DIFFOPTIONS options{};
DIFFRANGE dr;

options.bIgnoreEofNewlinePresence = true;
for (auto algo : { DIFF_ALGORITHM_DEFAULT, DIFF_ALGORITHM_MINIMAL, DIFF_ALGORITHM_PATIENCE, DIFF_ALGORITHM_HISTOGRAM, DIFF_ALGORITHM_NONE })
{
options.nDiffAlgorithm = algo;

{
DiffList diffList;
TempFile left = WriteToTempFile(_T("a\nb\nc1"));
TempFile right = WriteToTempFile(_T("a\nb\nc2"));
dw.SetCreateDiffList(&diffList);
dw.SetPaths({ left.GetPath(), right.GetPath() }, false);
dw.SetOptions(&options);
dw.RunFileDiff();
EXPECT_EQ(1, diffList.GetSize());
diffList.GetDiff(0, dr);
EXPECT_EQ(2, dr.begin[0]);
EXPECT_EQ(2, dr.begin[1]);
EXPECT_EQ(2, dr.end[0]);
EXPECT_EQ(2, dr.end[1]);
EXPECT_EQ(OP_DIFF, dr.op);
}

{
DiffList diffList;
TempFile left = WriteToTempFile(_T("a\nb\nc1\n"));
TempFile right = WriteToTempFile(_T("a\nb\nc2"));
dw.SetCreateDiffList(&diffList);
dw.SetPaths({ left.GetPath(), right.GetPath() }, false);
dw.SetOptions(&options);
dw.RunFileDiff();
EXPECT_EQ(1, diffList.GetSize());
diffList.GetDiff(0, dr);
EXPECT_EQ(2, dr.begin[0]);
EXPECT_EQ(2, dr.begin[1]);
EXPECT_EQ(2, dr.end[0]);
EXPECT_EQ(2, dr.end[1]);
EXPECT_EQ(OP_DIFF, dr.op);
}

{
DiffList diffList;
TempFile left = WriteToTempFile(_T("a\nb\nc1"));
TempFile right = WriteToTempFile(_T("a\nb\nc2\n"));
dw.SetCreateDiffList(&diffList);
dw.SetPaths({ left.GetPath(), right.GetPath() }, false);
dw.SetOptions(&options);
dw.RunFileDiff();
EXPECT_EQ(1, diffList.GetSize());
diffList.GetDiff(0, dr);
EXPECT_EQ(2, dr.begin[0]);
EXPECT_EQ(2, dr.begin[1]);
EXPECT_EQ(2, dr.end[0]);
EXPECT_EQ(2, dr.end[1]);
EXPECT_EQ(OP_DIFF, dr.op);
}

{
DiffList diffList;
TempFile left = WriteToTempFile(_T("a\nb1\nc"));
TempFile right = WriteToTempFile(_T("a\nb2\nc"));
dw.SetCreateDiffList(&diffList);
dw.SetPaths({ left.GetPath(), right.GetPath() }, false);
dw.SetOptions(&options);
dw.RunFileDiff();
EXPECT_EQ(1, diffList.GetSize());
diffList.GetDiff(0, dr);
EXPECT_EQ(1, dr.begin[0]);
EXPECT_EQ(1, dr.begin[1]);
EXPECT_EQ(1, dr.end[0]);
EXPECT_EQ(1, dr.end[1]);
EXPECT_EQ(OP_DIFF, dr.op);
}

for (const auto& eol : { _T("\n"), _T("\r"), _T("\r\n") })
{
DiffList diffList;
TempFile left = WriteToTempFile(_T("a\nb\nc"));
TempFile right = WriteToTempFile(_T("a\nb\nc") + String(eol));
dw.SetCreateDiffList(&diffList);
dw.SetPaths({ left.GetPath(), right.GetPath() }, false);
dw.SetOptions(&options);
dw.RunFileDiff();
EXPECT_EQ(1, diffList.GetSize());
diffList.GetDiff(0, dr);
EXPECT_EQ(2, dr.begin[0]);
EXPECT_EQ(2, dr.begin[1]);
EXPECT_EQ(2, dr.end[0]);
EXPECT_EQ(2, dr.end[1]);
EXPECT_EQ(OP_TRIVIAL, dr.op);
}

for (const auto& eol : { _T("\n"), _T("\r"), _T("\r\n") })
{
DiffList diffList;
TempFile left = WriteToTempFile(_T("a\nb\nc") + String(eol));
TempFile right = WriteToTempFile(_T("a\nb\nc"));
dw.SetCreateDiffList(&diffList);
dw.SetPaths({ left.GetPath(), right.GetPath() }, false);
dw.SetOptions(&options);
dw.RunFileDiff();
EXPECT_EQ(1, diffList.GetSize());
diffList.GetDiff(0, dr);
EXPECT_EQ(2, dr.begin[0]);
EXPECT_EQ(2, dr.begin[1]);
EXPECT_EQ(2, dr.end[0]);
EXPECT_EQ(2, dr.end[1]);
EXPECT_EQ(OP_TRIVIAL, dr.op);
}

}
}

TEST(DiffWrapper, RunFileDiff_IgnoreComments)
{
CDiffWrapper dw;
Expand Down

0 comments on commit 1d46fa4

Please sign in to comment.