Skip to content

Commit

Permalink
Do not show the line as modified if all tokens in a line is skipped f…
Browse files Browse the repository at this point in the history
…rom diff
  • Loading branch information
praveenkuttappan committed Jan 22, 2025
1 parent 5d39a1d commit ab3ec0c
Show file tree
Hide file tree
Showing 7 changed files with 29,692 additions and 8 deletions.
6 changes: 6 additions & 0 deletions src/dotnet/APIView/APIView/Model/V2/ReviewLine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -153,5 +153,11 @@ private static string CreateHashFromString(string inputString)
int hash = inputString.GetHashCode();
return "nId" + hash.ToString();
}

public bool IsSkippedFromDiff()
{
return Tokens.All(t => t.SkipDiff == true);
}

}
}
9 changes: 9 additions & 0 deletions src/dotnet/APIView/APIViewUnitTests/APIViewUnitTests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,15 @@
</ItemGroup>

<ItemGroup>
<None Update="SampleTestFiles\app-conf-change-in-skipped-diff.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="SampleTestFiles\app-conf.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="SampleTestFiles\app-conf_without_skip_diff.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="SampleTestFiles\azure-core-1.47.0-sources4.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
Expand Down
63 changes: 63 additions & 0 deletions src/dotnet/APIView/APIViewUnitTests/CodeFileTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
using Xunit;
using Xunit.Abstractions;
using APIViewWeb.Helpers;
using APIView.Model.V2;
using APIView.TreeToken;

namespace APIViewUnitTests
{
Expand Down Expand Up @@ -122,5 +124,66 @@ public async Task TestCodeFileConversion()
bool result = CodeFileHelpers.AreCodeFilesSame(codeFileA, codeFileB);
Assert.True(result);
}

[Fact]
public async Task TestCodeFileComparisonWithSkippedLines()
{
var codeFileA = new CodeFile();
var codeFileB = new CodeFile();
var filePath = Path.Combine("SampleTestFiles", "app-conf.json");
var fileInfo = new FileInfo(filePath);
var fileStream = fileInfo.Open(FileMode.Open, FileAccess.Read, FileShare.Read);
codeFileA = await CodeFile.DeserializeAsync(fileStream);

filePath = Path.Combine("SampleTestFiles", "app-conf_without_skip_diff.json");
fileInfo = new FileInfo(filePath);
fileStream = fileInfo.Open(FileMode.Open, FileAccess.Read, FileShare.Read);
codeFileB = await CodeFile.DeserializeAsync(fileStream);

bool isSame = CodeFileHelpers.AreCodeFilesSame(codeFileA, codeFileB);
Assert.True(isSame);

var diff = CodeFileHelpers.FindDiff(codeFileA.ReviewLines, codeFileB.ReviewLines);
Assert.False(FindAnyDiffLine(diff));
}

private bool FindAnyDiffLine(List<ReviewLine> lines)
{
if(lines == null || lines.Count == 0)
{
return false;
}

foreach (var line in lines)
{
if (line.DiffKind != DiffKind.NoneDiff || FindAnyDiffLine(line.Children))
{
return true;
}
}
return false;
}

[Fact]
public async Task TestCodeFileComparisonWithChangeInSkippedLines()
{
var codeFileA = new CodeFile();
var codeFileB = new CodeFile();
var filePath = Path.Combine("SampleTestFiles", "app-conf.json");
var fileInfo = new FileInfo(filePath);
var fileStream = fileInfo.Open(FileMode.Open, FileAccess.Read, FileShare.Read);
codeFileA = await CodeFile.DeserializeAsync(fileStream);

filePath = Path.Combine("SampleTestFiles", "app-conf-change-in-skipped-diff.json");
fileInfo = new FileInfo(filePath);
fileStream = fileInfo.Open(FileMode.Open, FileAccess.Read, FileShare.Read);
codeFileB = await CodeFile.DeserializeAsync(fileStream);

bool isSame = CodeFileHelpers.AreCodeFilesSame(codeFileA, codeFileB);
Assert.True(isSame);

var diff = CodeFileHelpers.FindDiff(codeFileA.ReviewLines, codeFileB.ReviewLines);
Assert.False(FindAnyDiffLine(diff));
}
}
}
Loading

0 comments on commit ab3ec0c

Please sign in to comment.