Change ~index - 1 > 0 to ~index-1 >=0 to allow for the case where ~index is equal to 1.
Add unit test to cover the cross line number case to GetMappingEntryForGeneratedSourcePosition.
This commit is contained in:
Родитель
788a2b99e7
Коммит
28ac8dfc08
|
@ -60,9 +60,9 @@ namespace SourcemapToolkit.SourcemapParser
|
|||
{
|
||||
// The BinarySearch method returns the bitwise complement of the nearest element that is larger than the desired element when there isn't a match.
|
||||
// Based on tests with source maps generated with the Closure Compiler, we should consider the closest source position that is smaller than the target value when we don't have a match.
|
||||
if ((~index) - 1 > 0 && ParsedMappings[(~index) - 1].GeneratedSourcePosition.IsEqualish(generatedSourcePosition))
|
||||
if (~index - 1 >= 0 && ParsedMappings[~index - 1].GeneratedSourcePosition.IsEqualish(generatedSourcePosition))
|
||||
{
|
||||
index = (~index) - 1;
|
||||
index = ~index - 1;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -68,7 +68,7 @@ namespace SourcemapToolkit.SourcemapParser.UnitTests
|
|||
}
|
||||
|
||||
[TestMethod]
|
||||
public void GetMappingEntryForGeneratedSourcePosition_NoExactMatchHasSimilar_ReturnSimilarEntry()
|
||||
public void GetMappingEntryForGeneratedSourcePosition_NoExactMatchHasSimilarOnSameLine_ReturnSimilarEntry()
|
||||
{
|
||||
// Arrange
|
||||
SourceMap sourceMap = new SourceMap();
|
||||
|
@ -92,5 +92,31 @@ namespace SourcemapToolkit.SourcemapParser.UnitTests
|
|||
// Asset
|
||||
Assert.AreEqual(matchingMappingEntry, result);
|
||||
}
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void GetMappingEntryForGeneratedSourcePosition_NoExactMatchHasSimilarOnDifferentLinesLine_ReturnSimilarEntry()
|
||||
{
|
||||
// Arrange
|
||||
SourceMap sourceMap = new SourceMap();
|
||||
MappingEntry matchingMappingEntry = new MappingEntry
|
||||
{
|
||||
GeneratedSourcePosition = new SourcePosition { ZeroBasedLineNumber = 23, ZeroBasedColumnNumber = 15 }
|
||||
};
|
||||
sourceMap.ParsedMappings = new List<MappingEntry>
|
||||
{
|
||||
new MappingEntry
|
||||
{
|
||||
GeneratedSourcePosition = new SourcePosition {ZeroBasedLineNumber = 0, ZeroBasedColumnNumber = 0}
|
||||
},
|
||||
matchingMappingEntry
|
||||
};
|
||||
SourcePosition sourcePosition = new SourcePosition { ZeroBasedLineNumber = 24, ZeroBasedColumnNumber = 0 };
|
||||
|
||||
// Act
|
||||
MappingEntry result = sourceMap.GetMappingEntryForGeneratedSourcePosition(sourcePosition);
|
||||
|
||||
// Asset
|
||||
Assert.AreEqual(matchingMappingEntry, result);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче