Skip to content

Commit 3a24be7

Browse files
committed
Create a test for PatchWhitespaceMode.
1 parent 16f17b0 commit 3a24be7

File tree

1 file changed

+66
-1
lines changed

1 file changed

+66
-1
lines changed

‎LibGit2Sharp.Tests/DiffTreeToTreeFixture.cs‎

Lines changed: 66 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
usingSystem.Text;
55
usingLibGit2Sharp.Tests.TestHelpers;
66
usingXunit;
7-
usingXunit.Extensions;
87

98
namespaceLibGit2Sharp.Tests
109
{
@@ -1219,5 +1218,71 @@ public void UsingPatienceAlgorithmCompareOptionProducesPatienceDiff()
12191218
Assert.Equal(diffPatience,changes);
12201219
}
12211220
}
1221+
1222+
[Fact]
1223+
publicvoidPatchWhitespaceModeIsObeyed()
1224+
{
1225+
stringrepoPath=InitNewRepository();
1226+
1227+
varcompareOptions=Enum
1228+
.GetValues(typeof(PatchWhitespaceMode))
1229+
.Cast<PatchWhitespaceMode>()
1230+
.Select(whitespaceOption =>newCompareOptions(){PatchWhitespaceMode=whitespaceOption});
1231+
1232+
using(varrepo=newRepository(repoPath))
1233+
{
1234+
conststringfileName="file.txt";
1235+
varcommits=newSystem.Collections.Generic.List<Commit>();
1236+
1237+
Touch(repo.Info.WorkingDirectory,fileName,"White space is not wastedspace.");
1238+
Commands.Stage(repo,fileName);
1239+
commits.Add(repo.Commit("Initial",Constants.Signature,Constants.Signature));
1240+
1241+
Touch(repo.Info.WorkingDirectory,fileName,"White space is not wastedspace. \t");
1242+
Commands.Stage(repo,fileName);
1243+
commits.Add(repo.Commit("Add trailing whitespace.",Constants.Signature,Constants.Signature));
1244+
1245+
Touch(repo.Info.WorkingDirectory,fileName,"White space\tis not wastedspace. ");
1246+
Commands.Stage(repo,fileName);
1247+
commits.Add(repo.Commit("Change whitespace.",Constants.Signature,Constants.Signature));
1248+
1249+
Touch(repo.Info.WorkingDirectory,fileName," Whitespace is not wasted space.");
1250+
Commands.Stage(repo,fileName);
1251+
commits.Add(repo.Commit("Insert whitespace.",Constants.Signature,Constants.Signature));
1252+
1253+
Touch(repo.Info.WorkingDirectory,fileName,"Completely different content.");
1254+
Commands.Stage(repo,fileName);
1255+
commits.Add(repo.Commit("Completely different.",Constants.Signature,Constants.Signature));
1256+
1257+
varcommitPairs=commits
1258+
.Select((oldCommit,index)=>new{oldCommit,index})
1259+
.Zip(commits.Skip(1),(old,newCommit)=>new{old.oldCommit,newCommit,old.index});
1260+
1261+
foreach(varcommitPairincommitPairs)
1262+
foreach(varcompareOptionincompareOptions)
1263+
using(varpatch=repo.Diff.Compare<Patch>(commitPair.oldCommit.Tree,commitPair.newCommit.Tree,compareOption))
1264+
{
1265+
intexpectedDiffLines;
1266+
switch(compareOption.PatchWhitespaceMode)
1267+
{
1268+
casePatchWhitespaceMode.DontIgnoreWhitespace:
1269+
expectedDiffLines=1;
1270+
break;
1271+
casePatchWhitespaceMode.IgnoreAllWhitespace:
1272+
expectedDiffLines=commitPair.index>2?1:0;
1273+
break;
1274+
casePatchWhitespaceMode.IgnoreWhitespaceChange:
1275+
expectedDiffLines=commitPair.index>1?1:0;
1276+
break;
1277+
casePatchWhitespaceMode.IgnoreWhitespaceEol:
1278+
expectedDiffLines=commitPair.index>0?1:0;
1279+
break;
1280+
default:
1281+
thrownewException("Unexpected "+nameof(PatchWhitespaceMode));
1282+
}
1283+
Assert.Equal(expectedDiffLines,patch.LinesAdded);
1284+
}
1285+
}
1286+
}
12221287
}
12231288
}

0 commit comments

Comments
(0)