|
4 | 4 | usingSystem.Text; |
5 | 5 | usingLibGit2Sharp.Tests.TestHelpers; |
6 | 6 | usingXunit; |
7 | | -usingXunit.Extensions; |
8 | 7 |
|
9 | 8 | namespaceLibGit2Sharp.Tests |
10 | 9 | { |
@@ -1219,5 +1218,71 @@ public void UsingPatienceAlgorithmCompareOptionProducesPatienceDiff() |
1219 | 1218 | Assert.Equal(diffPatience,changes); |
1220 | 1219 | } |
1221 | 1220 | } |
| 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 | +} |
1222 | 1287 | } |
1223 | 1288 | } |
0 commit comments