From 1d46fa4cf15cefc9deb4efad33876d24ed370373 Mon Sep 17 00:00:00 2001 From: sdottaka Date: Wed, 18 Dec 2024 22:19:30 +0900 Subject: [PATCH] WIP --- Src/DiffWrapper.cpp | 2 + .../DiffWrapper/DiffWrapper_test.cpp | 118 ++++++++++++++++++ 2 files changed, 120 insertions(+) diff --git a/Src/DiffWrapper.cpp b/Src/DiffWrapper.cpp index 07deb2f7233..fa9412a8634 100644 --- a/Src/DiffWrapper.cpp +++ b/Src/DiffWrapper.cpp @@ -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()); @@ -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()); diff --git a/Testing/GoogleTest/DiffWrapper/DiffWrapper_test.cpp b/Testing/GoogleTest/DiffWrapper/DiffWrapper_test.cpp index ca3844e2496..2324eb112e3 100644 --- a/Testing/GoogleTest/DiffWrapper/DiffWrapper_test.cpp +++ b/Testing/GoogleTest/DiffWrapper/DiffWrapper_test.cpp @@ -95,6 +95,124 @@ TEST(DiffWrapper, RunFileDiff_NoEol) } } +TEST(DiffWrapper, RunFileDiff_IgnoreEofNewlinePresence) +{ + 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;