Include LineIndex and CharacterIndex when comparing SourceLocation

This commit is contained in:
Ajay Bhargav Baaskaran 2017-12-19 15:38:57 -08:00
parent 808f539297
commit 0e20ea5178
3 changed files with 7 additions and 6 deletions

View File

@ -116,9 +116,10 @@ namespace Microsoft.AspNetCore.Razor.Language
/// <inheritdoc />
public bool Equals(SourceLocation other)
{
// LineIndex and CharacterIndex can be calculated from AbsoluteIndex and the document content.
return string.Equals(FilePath, other.FilePath, StringComparison.Ordinal) &&
AbsoluteIndex == other.AbsoluteIndex;
AbsoluteIndex == other.AbsoluteIndex &&
LineIndex == other.LineIndex &&
CharacterIndex == other.CharacterIndex;
}
public static bool operator==(SourceLocation left, SourceLocation right)

View File

@ -40,11 +40,11 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
var suffixLocation1 = new SourceLocation(
absoluteIndex: 8 + newlineLength + attributeNameLength,
lineIndex: 1,
characterIndex: 5 + attributeNameLength);
characterIndex: 5);
var valueLocation1 = new SourceLocation(
absoluteIndex: 5 + attributeNameLength + newlineLength,
lineIndex: 1,
characterIndex: 2 + attributeNameLength);
characterIndex: 2);
var prefixLocation2 = SourceLocationTracker.Advance(suffixLocation1, "'");
var suffixLocation2 = new SourceLocation(
absoluteIndex: 15 + attributeNameLength * 2 + newlineLength * 2,

View File

@ -61,7 +61,7 @@ namespace Microsoft.AspNetCore.Razor.Language
}
[Fact]
public void Equals_ReturnsTrue_FilePathsNullAndAbsoluteIndicesMatch()
public void Equals_ReturnsFalse_FilePathsNullAndAbsoluteIndicesMatch()
{
// Arrange
var sourceLocationA = new SourceLocation(10, 3, 4);
@ -71,7 +71,7 @@ namespace Microsoft.AspNetCore.Razor.Language
var result = sourceLocationA.Equals(sourceLocationB);
// Assert
Assert.True(result);
Assert.False(result);
}
[Fact]