Include LineIndex and CharacterIndex when comparing SourceLocation
This commit is contained in:
parent
808f539297
commit
0e20ea5178
|
|
@ -116,9 +116,10 @@ namespace Microsoft.AspNetCore.Razor.Language
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public bool Equals(SourceLocation other)
|
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) &&
|
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)
|
public static bool operator==(SourceLocation left, SourceLocation right)
|
||||||
|
|
|
||||||
|
|
@ -40,11 +40,11 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
|
||||||
var suffixLocation1 = new SourceLocation(
|
var suffixLocation1 = new SourceLocation(
|
||||||
absoluteIndex: 8 + newlineLength + attributeNameLength,
|
absoluteIndex: 8 + newlineLength + attributeNameLength,
|
||||||
lineIndex: 1,
|
lineIndex: 1,
|
||||||
characterIndex: 5 + attributeNameLength);
|
characterIndex: 5);
|
||||||
var valueLocation1 = new SourceLocation(
|
var valueLocation1 = new SourceLocation(
|
||||||
absoluteIndex: 5 + attributeNameLength + newlineLength,
|
absoluteIndex: 5 + attributeNameLength + newlineLength,
|
||||||
lineIndex: 1,
|
lineIndex: 1,
|
||||||
characterIndex: 2 + attributeNameLength);
|
characterIndex: 2);
|
||||||
var prefixLocation2 = SourceLocationTracker.Advance(suffixLocation1, "'");
|
var prefixLocation2 = SourceLocationTracker.Advance(suffixLocation1, "'");
|
||||||
var suffixLocation2 = new SourceLocation(
|
var suffixLocation2 = new SourceLocation(
|
||||||
absoluteIndex: 15 + attributeNameLength * 2 + newlineLength * 2,
|
absoluteIndex: 15 + attributeNameLength * 2 + newlineLength * 2,
|
||||||
|
|
|
||||||
|
|
@ -61,7 +61,7 @@ namespace Microsoft.AspNetCore.Razor.Language
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void Equals_ReturnsTrue_FilePathsNullAndAbsoluteIndicesMatch()
|
public void Equals_ReturnsFalse_FilePathsNullAndAbsoluteIndicesMatch()
|
||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
var sourceLocationA = new SourceLocation(10, 3, 4);
|
var sourceLocationA = new SourceLocation(10, 3, 4);
|
||||||
|
|
@ -71,7 +71,7 @@ namespace Microsoft.AspNetCore.Razor.Language
|
||||||
var result = sourceLocationA.Equals(sourceLocationB);
|
var result = sourceLocationA.Equals(sourceLocationB);
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
Assert.True(result);
|
Assert.False(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue