From 0141d65d34e670790afb4aae3e30f1d6e8e7c9c6 Mon Sep 17 00:00:00 2001 From: Takashi Sawanaka Date: Sun, 8 Oct 2023 13:03:04 +0900 Subject: [PATCH] DiffWrapper_test.cpp: Add RunFileDiff_IgnoreComments --- .../DiffWrapper/DiffWrapper_test.cpp | 73 +++++++++++++++++++ 1 file changed, 73 insertions(+) diff --git a/Testing/GoogleTest/DiffWrapper/DiffWrapper_test.cpp b/Testing/GoogleTest/DiffWrapper/DiffWrapper_test.cpp index 9e731550f3b..a2dd5b08869 100644 --- a/Testing/GoogleTest/DiffWrapper/DiffWrapper_test.cpp +++ b/Testing/GoogleTest/DiffWrapper/DiffWrapper_test.cpp @@ -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]); + } + } +}