Skip to content

Commit

Permalink
UniTests: Add DiffWrapper_test.cpp
Browse files Browse the repository at this point in the history
  • Loading branch information
sdottaka committed Oct 8, 2023
1 parent 63167f6 commit b215265
Show file tree
Hide file tree
Showing 9 changed files with 209 additions and 95 deletions.
2 changes: 2 additions & 0 deletions ALL.vs2017.sln
Original file line number Diff line number Diff line change
Expand Up @@ -1374,8 +1374,10 @@ Global
Src\CompareEngines\CompareEngines.vcxitems*{0f686afa-d587-43c0-bada-2beddc3fa758}*SharedItemsImports = 9
Externals\crystaledit\editlib\editlibparsers.vcxitems*{4170552a-09e2-4fac-b71d-0e2f5eb3c869}*SharedItemsImports = 9
Externals\xdiff\xdiff.vcxitems*{68f1d3a1-9dca-4b3d-b245-f4aca5f16563}*SharedItemsImports = 9
Externals\crystaledit\editlib\editlibparsers.vcxitems*{733e7c0b-ac3d-47ac-a8da-e13644d6294d}*SharedItemsImports = 4
Externals\googletest\googletest\googletest.vcxitems*{733e7c0b-ac3d-47ac-a8da-e13644d6294d}*SharedItemsImports = 4
Externals\xdiff\xdiff.vcxitems*{733e7c0b-ac3d-47ac-a8da-e13644d6294d}*SharedItemsImports = 4
Src\diffutils\diffutils.vcxitems*{733e7c0b-ac3d-47ac-a8da-e13644d6294d}*SharedItemsImports = 4
Plugins\src_VCPP\Common\Common.vcxitems*{7354ba4f-8dab-46ee-a5a2-a148d6ef2443}*SharedItemsImports = 9
Externals\crystaledit\editlib\editlib.vcxitems*{7515ac3c-389a-44cd-b940-a59dde5b8ae3}*SharedItemsImports = 9
Externals\googletest\googletest\googletest.vcxitems*{9ee35458-b145-444f-92b7-27ff72112c42}*SharedItemsImports = 9
Expand Down
2 changes: 2 additions & 0 deletions ALL.vs2019.sln
Original file line number Diff line number Diff line change
Expand Up @@ -1443,8 +1443,10 @@ Global
Src\CompareEngines\CompareEngines.vcxitems*{0f686afa-d587-43c0-bada-2beddc3fa758}*SharedItemsImports = 9
Externals\crystaledit\editlib\editlibparsers.vcxitems*{4170552a-09e2-4fac-b71d-0e2f5eb3c869}*SharedItemsImports = 9
Externals\xdiff\xdiff.vcxitems*{68f1d3a1-9dca-4b3d-b245-f4aca5f16563}*SharedItemsImports = 9
Externals\crystaledit\editlib\editlibparsers.vcxitems*{733e7c0b-ac3d-47ac-a8da-e13644d6294d}*SharedItemsImports = 4
Externals\googletest\googletest\googletest.vcxitems*{733e7c0b-ac3d-47ac-a8da-e13644d6294d}*SharedItemsImports = 4
Externals\xdiff\xdiff.vcxitems*{733e7c0b-ac3d-47ac-a8da-e13644d6294d}*SharedItemsImports = 4
Src\diffutils\diffutils.vcxitems*{733e7c0b-ac3d-47ac-a8da-e13644d6294d}*SharedItemsImports = 4
Plugins\src_VCPP\Common\Common.vcxitems*{7354ba4f-8dab-46ee-a5a2-a148d6ef2443}*SharedItemsImports = 9
Externals\crystaledit\editlib\editlib.vcxitems*{7515ac3c-389a-44cd-b940-a59dde5b8ae3}*SharedItemsImports = 9
Externals\googletest\googletest\googletest.vcxitems*{9ee35458-b145-444f-92b7-27ff72112c42}*SharedItemsImports = 9
Expand Down
2 changes: 2 additions & 0 deletions ALL.vs2022.sln
Original file line number Diff line number Diff line change
Expand Up @@ -1443,8 +1443,10 @@ Global
Src\CompareEngines\CompareEngines.vcxitems*{0f686afa-d587-43c0-bada-2beddc3fa758}*SharedItemsImports = 9
Externals\crystaledit\editlib\editlibparsers.vcxitems*{4170552a-09e2-4fac-b71d-0e2f5eb3c869}*SharedItemsImports = 9
Externals\xdiff\xdiff.vcxitems*{68f1d3a1-9dca-4b3d-b245-f4aca5f16563}*SharedItemsImports = 9
Externals\crystaledit\editlib\editlibparsers.vcxitems*{733e7c0b-ac3d-47ac-a8da-e13644d6294d}*SharedItemsImports = 4
Externals\googletest\googletest\googletest.vcxitems*{733e7c0b-ac3d-47ac-a8da-e13644d6294d}*SharedItemsImports = 4
Externals\xdiff\xdiff.vcxitems*{733e7c0b-ac3d-47ac-a8da-e13644d6294d}*SharedItemsImports = 4
Src\diffutils\diffutils.vcxitems*{733e7c0b-ac3d-47ac-a8da-e13644d6294d}*SharedItemsImports = 4
Plugins\src_VCPP\Common\Common.vcxitems*{7354ba4f-8dab-46ee-a5a2-a148d6ef2443}*SharedItemsImports = 9
Externals\crystaledit\editlib\editlib.vcxitems*{7515ac3c-389a-44cd-b940-a59dde5b8ae3}*SharedItemsImports = 9
Externals\googletest\googletest\googletest.vcxitems*{9ee35458-b145-444f-92b7-27ff72112c42}*SharedItemsImports = 9
Expand Down
94 changes: 94 additions & 0 deletions Testing/GoogleTest/DiffWrapper/DiffWrapper_test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
#include "pch.h"
#include <gtest/gtest.h>
#include "DiffWrapper.h"
#include "PathContext.h"
#include "paths.h"
#include "TempFile.h"
#include "UniFile.h"

const TempFile WriteToTempFile(const String& text)
{
TempFile tmpfile;
tmpfile.Create();
UniStdioFile file;
file.OpenCreateUtf8(tmpfile.GetPath());
file.WriteString(text);
file.Close();
return tmpfile;
}

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

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]);
}

{
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]);
}

{
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]);
}

{
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]);
}
}
}
Loading

0 comments on commit b215265

Please sign in to comment.