|
4 | 4 | using System.Text;
|
5 | 5 | using LibGit2Sharp.Tests.TestHelpers;
|
6 | 6 | using Xunit;
|
7 |
| -using Xunit.Extensions; |
8 | 7 |
|
9 | 8 | namespace LibGit2Sharp.Tests
|
10 | 9 | {
|
@@ -1219,5 +1218,71 @@ public void UsingPatienceAlgorithmCompareOptionProducesPatienceDiff()
|
1219 | 1218 | Assert.Equal(diffPatience, changes);
|
1220 | 1219 | }
|
1221 | 1220 | }
|
| 1221 | + |
| 1222 | + [Fact] |
| 1223 | + public void PatchWhitespaceModeIsObeyed() |
| 1224 | + { |
| 1225 | + string repoPath = InitNewRepository(); |
| 1226 | + |
| 1227 | + var compareOptions = Enum |
| 1228 | + .GetValues(typeof(PatchWhitespaceMode)) |
| 1229 | + .Cast<PatchWhitespaceMode>() |
| 1230 | + .Select(whitespaceOption => new CompareOptions() { PatchWhitespaceMode = whitespaceOption }); |
| 1231 | + |
| 1232 | + using (var repo = new Repository(repoPath)) |
| 1233 | + { |
| 1234 | + const string fileName = "file.txt"; |
| 1235 | + var commits = new System.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 | + var commitPairs = commits |
| 1258 | + .Select((oldCommit, index) => new { oldCommit, index }) |
| 1259 | + .Zip(commits.Skip(1), (old, newCommit) => new { old.oldCommit, newCommit, old.index }); |
| 1260 | + |
| 1261 | + foreach (var commitPair in commitPairs) |
| 1262 | + foreach (var compareOption in compareOptions) |
| 1263 | + using (var patch = repo.Diff.Compare<Patch>(commitPair.oldCommit.Tree, commitPair.newCommit.Tree, compareOption)) |
| 1264 | + { |
| 1265 | + int expectedDiffLines; |
| 1266 | + switch (compareOption.PatchWhitespaceMode) |
| 1267 | + { |
| 1268 | + case PatchWhitespaceMode.DontIgnoreWhitespace: |
| 1269 | + expectedDiffLines = 1; |
| 1270 | + break; |
| 1271 | + case PatchWhitespaceMode.IgnoreAllWhitespace: |
| 1272 | + expectedDiffLines = commitPair.index > 2 ? 1 : 0; |
| 1273 | + break; |
| 1274 | + case PatchWhitespaceMode.IgnoreWhitespaceChange: |
| 1275 | + expectedDiffLines = commitPair.index > 1 ? 1 : 0; |
| 1276 | + break; |
| 1277 | + case PatchWhitespaceMode.IgnoreWhitespaceEol: |
| 1278 | + expectedDiffLines = commitPair.index > 0 ? 1 : 0; |
| 1279 | + break; |
| 1280 | + default: |
| 1281 | + throw new Exception("Unexpected " + nameof(PatchWhitespaceMode)); |
| 1282 | + } |
| 1283 | + Assert.Equal(expectedDiffLines, patch.LinesAdded); |
| 1284 | + } |
| 1285 | + } |
| 1286 | + } |
1222 | 1287 | }
|
1223 | 1288 | }
|
0 commit comments