Skip to content

Commit

Permalink
DiffWrapper_test.cpp: Add RunFileDiff_IgnoreComments
Browse files Browse the repository at this point in the history
  • Loading branch information
sdottaka committed Oct 8, 2023
1 parent 802193a commit 0141d65
Showing 1 changed file with 73 additions and 0 deletions.
73 changes: 73 additions & 0 deletions Testing/GoogleTest/DiffWrapper/DiffWrapper_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,3 +92,76 @@ TEST(DiffWrapper, RunFileDiff_NoEol)
}
}
}

TEST(DiffWrapper, RunFileDiff_IgnoreComments)
{
CDiffWrapper dw;
DIFFOPTIONS options{};
DIFFRANGE dr;

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

{
DiffList diffList;
TempFile left = WriteToTempFile(_T("a\n/*b1*/\nc"));
TempFile right = WriteToTempFile(_T("a\n/*b2*/\nc"));
dw.SetCreateDiffList(&diffList);
dw.SetPaths({ left.GetPath(), right.GetPath() }, false);
dw.SetOptions(&options);
dw.SetFilterCommentsSourceDef(_T("cpp"));
dw.RunFileDiff();
EXPECT_EQ(1, diffList.GetSize());
diffList.GetDiff(0, dr);
EXPECT_EQ(OP_TRIVIAL, dr.op);
EXPECT_EQ(1, dr.begin[0]);
EXPECT_EQ(1, dr.begin[1]);
EXPECT_EQ(1, dr.end[0]);
EXPECT_EQ(1, dr.end[1]);
}

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

{
DiffList diffList;
TempFile left = WriteToTempFile(_T("a\n//b1\nc"));
TempFile right = WriteToTempFile(_T("a\n//b2\nc"));
dw.SetCreateDiffList(&diffList);
dw.SetPaths({ left.GetPath(), right.GetPath() }, false);
dw.SetOptions(&options);
dw.SetFilterCommentsSourceDef(_T("cpp"));
dw.RunFileDiff();
EXPECT_EQ(1, diffList.GetSize());
diffList.GetDiff(0, dr);
EXPECT_EQ(OP_TRIVIAL, dr.op);
EXPECT_EQ(1, dr.begin[0]);
EXPECT_EQ(1, dr.begin[1]);
EXPECT_EQ(1, dr.end[0]);
EXPECT_EQ(1, dr.end[1]);
}
}
}

0 comments on commit 0141d65

Please sign in to comment.