Rename LineMapping => SourceMapping.
- Also removed the == and `!=` operators for `SourceMapping`. #1510
This commit is contained in:
parent
a78202e937
commit
afa61e7080
|
|
@ -31,7 +31,7 @@ namespace Microsoft.AspNetCore.Razor.Language.CodeGeneration
|
|||
|
||||
public abstract RazorSourceDocument SourceDocument { get; }
|
||||
|
||||
public abstract void AddLineMappingFor(IntermediateNode node);
|
||||
public abstract void AddSourceMappingFor(IntermediateNode node);
|
||||
|
||||
public abstract void RenderNode(IntermediateNode node);
|
||||
|
||||
|
|
|
|||
|
|
@ -55,7 +55,7 @@ namespace Microsoft.AspNetCore.Razor.Language.CodeGeneration
|
|||
_ancestors = new Stack<IntermediateNode>();
|
||||
Diagnostics = new RazorDiagnosticCollection();
|
||||
Items = new ItemCollection();
|
||||
LineMappings = new List<LineMapping>();
|
||||
SourceMappings = new List<SourceMapping>();
|
||||
|
||||
var diagnostics = _documentNode.GetAllDiagnostics();
|
||||
for (var i = 0; i < diagnostics.Count; i++)
|
||||
|
|
@ -92,7 +92,7 @@ namespace Microsoft.AspNetCore.Razor.Language.CodeGeneration
|
|||
|
||||
public override ItemCollection Items { get; }
|
||||
|
||||
public List<LineMapping> LineMappings { get; }
|
||||
public List<SourceMapping> SourceMappings { get; }
|
||||
|
||||
public override IntermediateNodeWriter NodeWriter => Current.Writer;
|
||||
|
||||
|
|
@ -104,7 +104,7 @@ namespace Microsoft.AspNetCore.Razor.Language.CodeGeneration
|
|||
|
||||
private ScopeInternal Current => _scopes[_scopes.Count - 1];
|
||||
|
||||
public override void AddLineMappingFor(IntermediateNode node)
|
||||
public override void AddSourceMappingFor(IntermediateNode node)
|
||||
{
|
||||
if (node == null)
|
||||
{
|
||||
|
|
@ -125,9 +125,9 @@ namespace Microsoft.AspNetCore.Razor.Language.CodeGeneration
|
|||
|
||||
var source = node.Source.Value;
|
||||
var generatedLocation = new SourceSpan(CodeWriter.Location, source.Length);
|
||||
var lineMapping = new LineMapping(source, generatedLocation);
|
||||
var sourceMapping = new SourceMapping(source, generatedLocation);
|
||||
|
||||
LineMappings.Add(lineMapping);
|
||||
SourceMappings.Add(sourceMapping);
|
||||
}
|
||||
|
||||
public override void RenderChildren(IntermediateNode node)
|
||||
|
|
|
|||
|
|
@ -46,7 +46,7 @@ namespace Microsoft.AspNetCore.Razor.Language.CodeGeneration
|
|||
cSharp,
|
||||
_options,
|
||||
context.Diagnostics.ToArray(),
|
||||
context.LineMappings.ToArray());
|
||||
context.SourceMappings.ToArray());
|
||||
}
|
||||
|
||||
private class Visitor : IntermediateNodeVisitor
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@ namespace Microsoft.AspNetCore.Razor.Language.CodeGeneration
|
|||
{
|
||||
using (context.CodeWriter.BuildLinePragma(node.Source.Value))
|
||||
{
|
||||
context.AddLineMappingFor(node);
|
||||
context.AddSourceMappingFor(node);
|
||||
context.CodeWriter.WriteUsing(node.Content);
|
||||
}
|
||||
}
|
||||
|
|
@ -54,7 +54,7 @@ namespace Microsoft.AspNetCore.Razor.Language.CodeGeneration
|
|||
{
|
||||
if (node.Children[i] is IntermediateToken token && token.IsCSharp)
|
||||
{
|
||||
context.AddLineMappingFor(token);
|
||||
context.AddSourceMappingFor(token);
|
||||
context.CodeWriter.Write(token.Content);
|
||||
}
|
||||
else
|
||||
|
|
@ -119,7 +119,7 @@ namespace Microsoft.AspNetCore.Razor.Language.CodeGeneration
|
|||
{
|
||||
if (node.Children[i] is IntermediateToken token && token.IsCSharp)
|
||||
{
|
||||
context.AddLineMappingFor(token);
|
||||
context.AddSourceMappingFor(token);
|
||||
context.CodeWriter.Write(token.Content);
|
||||
}
|
||||
else
|
||||
|
|
@ -179,7 +179,7 @@ namespace Microsoft.AspNetCore.Razor.Language.CodeGeneration
|
|||
{
|
||||
if (node.Children[i] is IntermediateToken token && token.IsCSharp)
|
||||
{
|
||||
context.AddLineMappingFor(token);
|
||||
context.AddSourceMappingFor(token);
|
||||
context.CodeWriter.Write(token.Content);
|
||||
}
|
||||
else
|
||||
|
|
@ -201,7 +201,7 @@ namespace Microsoft.AspNetCore.Razor.Language.CodeGeneration
|
|||
{
|
||||
if (token.Source != null)
|
||||
{
|
||||
context.AddLineMappingFor(token);
|
||||
context.AddSourceMappingFor(token);
|
||||
}
|
||||
|
||||
context.CodeWriter.Write(token.Content);
|
||||
|
|
@ -240,7 +240,7 @@ namespace Microsoft.AspNetCore.Razor.Language.CodeGeneration
|
|||
continue;
|
||||
}
|
||||
|
||||
context.AddLineMappingFor(token);
|
||||
context.AddSourceMappingFor(token);
|
||||
context.CodeWriter.Write(token.Content);
|
||||
|
||||
if (linePragmaScope != null)
|
||||
|
|
|
|||
|
|
@ -10,14 +10,14 @@ namespace Microsoft.AspNetCore.Razor.Language
|
|||
{
|
||||
private readonly string _generatedCode;
|
||||
private readonly RazorDiagnostic[] _diagnostics;
|
||||
private readonly LineMapping[] _lineMappings;
|
||||
private readonly SourceMapping[] _sourceMappings;
|
||||
private readonly RazorCodeGenerationOptions _options;
|
||||
|
||||
public DefaultRazorCSharpDocument(
|
||||
string generatedCode,
|
||||
RazorCodeGenerationOptions options,
|
||||
RazorDiagnostic[] diagnostics,
|
||||
LineMapping[] lineMappings)
|
||||
SourceMapping[] sourceMappings)
|
||||
{
|
||||
if (generatedCode == null)
|
||||
{
|
||||
|
|
@ -33,14 +33,14 @@ namespace Microsoft.AspNetCore.Razor.Language
|
|||
_options = options;
|
||||
|
||||
_diagnostics = diagnostics ?? Array.Empty<RazorDiagnostic>();
|
||||
_lineMappings = lineMappings ?? Array.Empty<LineMapping>();
|
||||
_sourceMappings = sourceMappings ?? Array.Empty<SourceMapping>();
|
||||
}
|
||||
|
||||
public override IReadOnlyList<RazorDiagnostic> Diagnostics => _diagnostics;
|
||||
|
||||
public override string GeneratedCode => _generatedCode;
|
||||
|
||||
public override IReadOnlyList<LineMapping> LineMappings => _lineMappings;
|
||||
public override IReadOnlyList<SourceMapping> SourceMappings => _sourceMappings;
|
||||
|
||||
public override RazorCodeGenerationOptions Options => _options;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -547,7 +547,7 @@ namespace Microsoft.AspNetCore.Razor.Language.Extensions
|
|||
{
|
||||
if (DesignTime && node.Source != null)
|
||||
{
|
||||
context.AddLineMappingFor(node);
|
||||
context.AddSourceMappingFor(node);
|
||||
}
|
||||
|
||||
context.CodeWriter.Write(token.Content);
|
||||
|
|
|
|||
|
|
@ -59,7 +59,7 @@ namespace Microsoft.AspNetCore.Razor.Language.Extensions
|
|||
|
||||
// {node.Content} __typeHelper = default({node.Content});
|
||||
|
||||
context.AddLineMappingFor(node);
|
||||
context.AddSourceMappingFor(node);
|
||||
context.CodeWriter
|
||||
.Write(node.Content)
|
||||
.Write(" ")
|
||||
|
|
@ -78,7 +78,7 @@ namespace Microsoft.AspNetCore.Razor.Language.Extensions
|
|||
.Write(typeof(object).FullName)
|
||||
.Write(" ");
|
||||
|
||||
context.AddLineMappingFor(node);
|
||||
context.AddSourceMappingFor(node);
|
||||
context.CodeWriter
|
||||
.Write(node.Content)
|
||||
.WriteLine(" = null;");
|
||||
|
|
@ -96,7 +96,7 @@ namespace Microsoft.AspNetCore.Razor.Language.Extensions
|
|||
|
||||
context.CodeWriter.Write("nameof(");
|
||||
|
||||
context.AddLineMappingFor(node);
|
||||
context.AddSourceMappingFor(node);
|
||||
context.CodeWriter
|
||||
.Write(node.Content)
|
||||
.WriteLine(");");
|
||||
|
|
@ -114,13 +114,13 @@ namespace Microsoft.AspNetCore.Razor.Language.Extensions
|
|||
|
||||
if (node.Content.StartsWith("\"", StringComparison.Ordinal))
|
||||
{
|
||||
context.AddLineMappingFor(node);
|
||||
context.AddSourceMappingFor(node);
|
||||
context.CodeWriter.Write(node.Content);
|
||||
}
|
||||
else
|
||||
{
|
||||
context.CodeWriter.Write("\"");
|
||||
context.AddLineMappingFor(node);
|
||||
context.AddSourceMappingFor(node);
|
||||
context.CodeWriter
|
||||
.Write(node.Content)
|
||||
.Write("\"");
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ namespace Microsoft.AspNetCore.Razor.Language
|
|||
{
|
||||
public abstract string GeneratedCode { get; }
|
||||
|
||||
public abstract IReadOnlyList<LineMapping> LineMappings { get; }
|
||||
public abstract IReadOnlyList<SourceMapping> SourceMappings { get; }
|
||||
|
||||
public abstract IReadOnlyList<RazorDiagnostic> Diagnostics { get; }
|
||||
|
||||
|
|
@ -34,14 +34,14 @@ namespace Microsoft.AspNetCore.Razor.Language
|
|||
throw new ArgumentNullException(nameof(diagnostics));
|
||||
}
|
||||
|
||||
return new DefaultRazorCSharpDocument(generatedCode, options, diagnostics.ToArray(), lineMappings: null);
|
||||
return new DefaultRazorCSharpDocument(generatedCode, options, diagnostics.ToArray(), sourceMappings: null);
|
||||
}
|
||||
|
||||
public static RazorCSharpDocument Create(
|
||||
string generatedCode,
|
||||
RazorCodeGenerationOptions options,
|
||||
IEnumerable<RazorDiagnostic> diagnostics,
|
||||
IEnumerable<LineMapping> lineMappings)
|
||||
IEnumerable<SourceMapping> sourceMappings)
|
||||
{
|
||||
if (generatedCode == null)
|
||||
{
|
||||
|
|
@ -58,12 +58,12 @@ namespace Microsoft.AspNetCore.Razor.Language
|
|||
throw new ArgumentNullException(nameof(diagnostics));
|
||||
}
|
||||
|
||||
if (lineMappings == null)
|
||||
if (sourceMappings == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(lineMappings));
|
||||
throw new ArgumentNullException(nameof(sourceMappings));
|
||||
}
|
||||
|
||||
return new DefaultRazorCSharpDocument(generatedCode, options, diagnostics.ToArray(), lineMappings.ToArray());
|
||||
return new DefaultRazorCSharpDocument(generatedCode, options, diagnostics.ToArray(), sourceMappings.ToArray());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,9 +7,9 @@ using Microsoft.Extensions.Internal;
|
|||
|
||||
namespace Microsoft.AspNetCore.Razor.Language
|
||||
{
|
||||
public sealed class LineMapping : IEquatable<LineMapping>
|
||||
public sealed class SourceMapping : IEquatable<SourceMapping>
|
||||
{
|
||||
public LineMapping(SourceSpan originalSpan, SourceSpan generatedSpan)
|
||||
public SourceMapping(SourceSpan originalSpan, SourceSpan generatedSpan)
|
||||
{
|
||||
OriginalSpan = originalSpan;
|
||||
GeneratedSpan = generatedSpan;
|
||||
|
|
@ -21,11 +21,11 @@ namespace Microsoft.AspNetCore.Razor.Language
|
|||
|
||||
public override bool Equals(object obj)
|
||||
{
|
||||
var other = obj as LineMapping;
|
||||
var other = obj as SourceMapping;
|
||||
return Equals(other);
|
||||
}
|
||||
|
||||
public bool Equals(LineMapping other)
|
||||
public bool Equals(SourceMapping other)
|
||||
{
|
||||
if (ReferenceEquals(other, null))
|
||||
{
|
||||
|
|
@ -45,38 +45,6 @@ namespace Microsoft.AspNetCore.Razor.Language
|
|||
return hashCodeCombiner;
|
||||
}
|
||||
|
||||
public static bool operator ==(LineMapping left, LineMapping right)
|
||||
{
|
||||
if (ReferenceEquals(left, right))
|
||||
{
|
||||
// Exact equality e.g. both objects are null.
|
||||
return true;
|
||||
}
|
||||
|
||||
if (ReferenceEquals(left, null))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return left.Equals(right);
|
||||
}
|
||||
|
||||
public static bool operator !=(LineMapping left, LineMapping right)
|
||||
{
|
||||
if (ReferenceEquals(left, right))
|
||||
{
|
||||
// Exact equality e.g. both objects are null.
|
||||
return false;
|
||||
}
|
||||
|
||||
if (ReferenceEquals(left, null))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
return !left.Equals(right);
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return string.Format(CultureInfo.CurrentCulture, "{0} -> {1}", OriginalSpan, GeneratedSpan);
|
||||
|
|
@ -538,7 +538,7 @@ public class AllTagHelper : {typeof(TagHelper).FullName}
|
|||
// Assert
|
||||
AssertDocumentNodeMatchesBaseline(document.GetDocumentIntermediateNode());
|
||||
AssertCSharpDocumentMatchesBaseline(document.GetCSharpDocument());
|
||||
AssertLineMappingsMatchBaseline(document);
|
||||
AssertSourceMappingsMatchBaseline(document);
|
||||
AssertDocumentCompiles(document, compilationReferences, expectedErrors);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ using Microsoft.AspNetCore.Razor.Language;
|
|||
|
||||
namespace Microsoft.AspNetCore.Mvc.Razor.Extensions
|
||||
{
|
||||
public static class LineMappingsSerializer
|
||||
public static class SourceMappingsSerializer
|
||||
{
|
||||
public static string Serialize(RazorCSharpDocument csharpDocument, RazorSourceDocument sourceDocument)
|
||||
{
|
||||
|
|
@ -17,19 +17,19 @@ namespace Microsoft.AspNetCore.Mvc.Razor.Extensions
|
|||
sourceDocument.CopyTo(0, charBuffer, 0, sourceDocument.Length);
|
||||
var sourceContent = new string(charBuffer);
|
||||
|
||||
for (var i = 0; i < csharpDocument.LineMappings.Count; i++)
|
||||
for (var i = 0; i < csharpDocument.SourceMappings.Count; i++)
|
||||
{
|
||||
var lineMapping = csharpDocument.LineMappings[i];
|
||||
if (!string.Equals(lineMapping.OriginalSpan.FilePath, sourceFilePath, StringComparison.Ordinal))
|
||||
var sourceMapping = csharpDocument.SourceMappings[i];
|
||||
if (!string.Equals(sourceMapping.OriginalSpan.FilePath, sourceFilePath, StringComparison.Ordinal))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
builder.Append("Source Location: ");
|
||||
AppendMappingLocation(builder, lineMapping.OriginalSpan, sourceContent);
|
||||
AppendMappingLocation(builder, sourceMapping.OriginalSpan, sourceContent);
|
||||
|
||||
builder.Append("Generated Location: ");
|
||||
AppendMappingLocation(builder, lineMapping.GeneratedSpan, csharpDocument.GeneratedCode);
|
||||
AppendMappingLocation(builder, sourceMapping.GeneratedSpan, csharpDocument.GeneratedCode);
|
||||
|
||||
builder.AppendLine();
|
||||
}
|
||||
|
|
@ -44,7 +44,7 @@ namespace Microsoft.AspNetCore.Razor.Language.CodeGeneration
|
|||
|
||||
var originalSpan = new SourceSpan("test.cshtml", 0, 0, 0, 6);
|
||||
var generatedSpan = new SourceSpan(null, 21 + Environment.NewLine.Length, 1, 0, 6);
|
||||
var expectedLineMapping = new LineMapping(originalSpan, generatedSpan);
|
||||
var expectedSourceMapping = new SourceMapping(originalSpan, generatedSpan);
|
||||
var node = new UsingDirectiveIntermediateNode()
|
||||
{
|
||||
Content = "System",
|
||||
|
|
@ -55,8 +55,8 @@ namespace Microsoft.AspNetCore.Razor.Language.CodeGeneration
|
|||
writer.WriteUsingDirective(context, node);
|
||||
|
||||
// Assert
|
||||
var mapping = Assert.Single(((DefaultCodeRenderingContext)context).LineMappings);
|
||||
Assert.Equal(expectedLineMapping, mapping);
|
||||
var mapping = Assert.Single(((DefaultCodeRenderingContext)context).SourceMappings);
|
||||
Assert.Equal(expectedSourceMapping, mapping);
|
||||
var csharp = context.CodeWriter.Builder.ToString();
|
||||
Assert.Equal(
|
||||
@"#line 1 ""test.cshtml""
|
||||
|
|
|
|||
|
|
@ -903,7 +903,7 @@ namespace Microsoft.AspNetCore.Razor.Language.IntegrationTests
|
|||
// Assert
|
||||
AssertDocumentNodeMatchesBaseline(document.GetDocumentIntermediateNode());
|
||||
AssertCSharpDocumentMatchesBaseline(document.GetCSharpDocument());
|
||||
AssertLineMappingsMatchBaseline(document);
|
||||
AssertSourceMappingsMatchBaseline(document);
|
||||
}
|
||||
|
||||
private void RunTimeTest()
|
||||
|
|
@ -981,7 +981,7 @@ namespace Microsoft.AspNetCore.Razor.Language.IntegrationTests
|
|||
// Assert
|
||||
AssertDocumentNodeMatchesBaseline(document.GetDocumentIntermediateNode());
|
||||
AssertCSharpDocumentMatchesBaseline(document.GetCSharpDocument());
|
||||
AssertLineMappingsMatchBaseline(document);
|
||||
AssertSourceMappingsMatchBaseline(document);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -27,7 +27,7 @@ namespace Microsoft.AspNetCore.Razor.Language.IntegrationTests
|
|||
// Assert
|
||||
AssertDocumentNodeMatchesBaseline(document.GetDocumentIntermediateNode());
|
||||
AssertCSharpDocumentMatchesBaseline(document.GetCSharpDocument());
|
||||
AssertLineMappingsMatchBaseline(document);
|
||||
AssertSourceMappingsMatchBaseline(document);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -12,16 +12,15 @@ namespace Microsoft.AspNetCore.Razor.Language
|
|||
public void GeneratedCodeMappingsAreEqualIfDataIsEqual()
|
||||
{
|
||||
// Arrange
|
||||
var left = new LineMapping(
|
||||
var left = new SourceMapping(
|
||||
new SourceSpan(new SourceLocation(1, 2, 3), 4),
|
||||
new SourceSpan(new SourceLocation(5, 6, 7), 8));
|
||||
|
||||
var right = new LineMapping(
|
||||
var right = new SourceMapping(
|
||||
new SourceSpan(new SourceLocation(1, 2, 3), 4),
|
||||
new SourceSpan(new SourceLocation(5, 6, 7), 8));
|
||||
|
||||
// Assert
|
||||
Assert.True(left == right);
|
||||
Assert.True(left.Equals(right));
|
||||
Assert.True(right.Equals(left));
|
||||
Assert.True(Equals(left, right));
|
||||
|
|
@ -31,11 +30,11 @@ namespace Microsoft.AspNetCore.Razor.Language
|
|||
public void GeneratedCodeMappingsAreNotEqualIfCodeLengthIsNotEqual()
|
||||
{
|
||||
// Arrange
|
||||
var left = new LineMapping(
|
||||
var left = new SourceMapping(
|
||||
new SourceSpan(new SourceLocation(1, 2, 3), 4),
|
||||
new SourceSpan(new SourceLocation(5, 6, 7), 8));
|
||||
|
||||
var right = new LineMapping(
|
||||
var right = new SourceMapping(
|
||||
new SourceSpan(new SourceLocation(1, 2, 3), 5),
|
||||
new SourceSpan(new SourceLocation(5, 6, 7), 9));
|
||||
|
||||
|
|
@ -47,11 +46,11 @@ namespace Microsoft.AspNetCore.Razor.Language
|
|||
public void GeneratedCodeMappingsAreNotEqualIfStartGeneratedColumnIsNotEqual()
|
||||
{
|
||||
// Arrange
|
||||
var left = new LineMapping(
|
||||
var left = new SourceMapping(
|
||||
new SourceSpan(new SourceLocation(1, 2, 3), 4),
|
||||
new SourceSpan(new SourceLocation(5, 6, 7), 8));
|
||||
|
||||
var right = new LineMapping(
|
||||
var right = new SourceMapping(
|
||||
new SourceSpan(new SourceLocation(1, 2, 3), 4),
|
||||
new SourceSpan(new SourceLocation(5, 6, 8), 8));
|
||||
|
||||
|
|
@ -63,11 +62,11 @@ namespace Microsoft.AspNetCore.Razor.Language
|
|||
public void GeneratedCodeMappingsAreNotEqualIfStartColumnIsNotEqual()
|
||||
{
|
||||
// Arrange
|
||||
var left = new LineMapping(
|
||||
var left = new SourceMapping(
|
||||
new SourceSpan(new SourceLocation(1, 2, 3), 4),
|
||||
new SourceSpan(new SourceLocation(5, 6, 8), 8));
|
||||
|
||||
var right = new LineMapping(
|
||||
var right = new SourceMapping(
|
||||
new SourceSpan(new SourceLocation(1, 2, 3), 4),
|
||||
new SourceSpan(new SourceLocation(5, 6, 7), 8));
|
||||
|
||||
|
|
@ -79,11 +78,11 @@ namespace Microsoft.AspNetCore.Razor.Language
|
|||
public void GeneratedCodeMappingsAreNotEqualIfStartLineIsNotEqual()
|
||||
{
|
||||
// Arrange
|
||||
var left = new LineMapping(
|
||||
var left = new SourceMapping(
|
||||
new SourceSpan(new SourceLocation(1, 2, 3), 4),
|
||||
new SourceSpan(new SourceLocation(5, 5, 7), 8));
|
||||
|
||||
var right = new LineMapping(
|
||||
var right = new SourceMapping(
|
||||
new SourceSpan(new SourceLocation(1, 1, 3), 4),
|
||||
new SourceSpan(new SourceLocation(5, 6, 7), 8));
|
||||
|
||||
|
|
@ -95,11 +94,11 @@ namespace Microsoft.AspNetCore.Razor.Language
|
|||
public void GeneratedCodeMappingsAreNotEqualIfAbsoluteIndexIsNotEqual()
|
||||
{
|
||||
// Arrange
|
||||
var left = new LineMapping(
|
||||
var left = new SourceMapping(
|
||||
new SourceSpan(new SourceLocation(1, 2, 3), 4),
|
||||
new SourceSpan(new SourceLocation(4, 6, 7), 8));
|
||||
|
||||
var right = new LineMapping(
|
||||
var right = new SourceMapping(
|
||||
new SourceSpan(new SourceLocation(1, 2, 3), 4),
|
||||
new SourceSpan(new SourceLocation(5, 6, 7), 9));
|
||||
|
||||
|
|
@ -107,7 +106,7 @@ namespace Microsoft.AspNetCore.Razor.Language
|
|||
AssertNotEqual(left, right);
|
||||
}
|
||||
|
||||
private void AssertNotEqual(LineMapping left, LineMapping right)
|
||||
private void AssertNotEqual(SourceMapping left, SourceMapping right)
|
||||
{
|
||||
Assert.False(left == right);
|
||||
Assert.False(left.Equals(right));
|
||||
|
|
|
|||
|
|
@ -266,7 +266,7 @@ namespace Microsoft.AspNetCore.Razor.Language
|
|||
var document = new StringSourceDocument(content, Encoding.UTF8, filePath: null);
|
||||
|
||||
// Act
|
||||
var actual = GetAllLineMappings(document);
|
||||
var actual = GetAllSourceMappings(document);
|
||||
|
||||
// Assert
|
||||
Assert.Equal(new int[] { 16, 5, 24 }, actual);
|
||||
|
|
@ -281,7 +281,7 @@ namespace Microsoft.AspNetCore.Razor.Language
|
|||
var document = new StringSourceDocument(content, Encoding.UTF8, filePath: null);
|
||||
|
||||
// Act
|
||||
var actual = GetAllLineMappings(document);
|
||||
var actual = GetAllSourceMappings(document);
|
||||
|
||||
// Assert
|
||||
Assert.Equal(new int[] { 7, 6 }, actual);
|
||||
|
|
@ -296,7 +296,7 @@ namespace Microsoft.AspNetCore.Razor.Language
|
|||
var document = new StringSourceDocument(content, Encoding.UTF8, filePath: null);
|
||||
|
||||
// Act
|
||||
var actual = GetAllLineMappings(document);
|
||||
var actual = GetAllSourceMappings(document);
|
||||
|
||||
// Assert
|
||||
Assert.Equal(new int[] { 6, 6 }, actual);
|
||||
|
|
@ -312,7 +312,7 @@ namespace Microsoft.AspNetCore.Razor.Language
|
|||
var document = new StringSourceDocument(content, Encoding.UTF8, filePath: null);
|
||||
|
||||
// Act
|
||||
var actual = GetAllLineMappings(document);
|
||||
var actual = GetAllSourceMappings(document);
|
||||
|
||||
// Assert
|
||||
Assert.Equal(new int[] { 6, 5, 6 }, actual);
|
||||
|
|
@ -327,7 +327,7 @@ namespace Microsoft.AspNetCore.Razor.Language
|
|||
var document = new StringSourceDocument(content, Encoding.UTF8, filePath: null);
|
||||
|
||||
// Act
|
||||
var actual = GetAllLineMappings(document);
|
||||
var actual = GetAllSourceMappings(document);
|
||||
|
||||
// Assert
|
||||
Assert.Equal(new int[] { 6, 6 }, actual);
|
||||
|
|
@ -342,7 +342,7 @@ namespace Microsoft.AspNetCore.Razor.Language
|
|||
var document = new StringSourceDocument(content, Encoding.UTF8, filePath: null);
|
||||
|
||||
// Act
|
||||
var actual = GetAllLineMappings(document);
|
||||
var actual = GetAllSourceMappings(document);
|
||||
|
||||
// Assert
|
||||
Assert.Equal(new int[] { 6, 6 }, actual);
|
||||
|
|
@ -357,7 +357,7 @@ namespace Microsoft.AspNetCore.Razor.Language
|
|||
var document = new StringSourceDocument(content, Encoding.UTF8, filePath: null);
|
||||
|
||||
// Act
|
||||
var actual = GetAllLineMappings(document);
|
||||
var actual = GetAllSourceMappings(document);
|
||||
|
||||
// Assert
|
||||
Assert.Equal(new int[] { 6, 6 }, actual);
|
||||
|
|
@ -372,7 +372,7 @@ namespace Microsoft.AspNetCore.Razor.Language
|
|||
var document = new StringSourceDocument(content, Encoding.UTF8, filePath: null);
|
||||
|
||||
// Act
|
||||
var actual = GetAllLineMappings(document);
|
||||
var actual = GetAllSourceMappings(document);
|
||||
|
||||
// Assert
|
||||
Assert.Equal(new int[] { 6, 6 }, actual);
|
||||
|
|
@ -476,7 +476,7 @@ namespace Microsoft.AspNetCore.Razor.Language
|
|||
Assert.Equal(5, actual.CharacterIndex);
|
||||
}
|
||||
|
||||
private static int[] GetAllLineMappings(RazorSourceDocument source)
|
||||
private static int[] GetAllSourceMappings(RazorSourceDocument source)
|
||||
{
|
||||
var lines = new int[source.Lines.Count];
|
||||
for (var i = 0; i < lines.Length; i++)
|
||||
|
|
|
|||
|
|
@ -193,11 +193,11 @@ namespace Microsoft.AspNetCore.Razor.Language.IntegrationTests
|
|||
Assert.Equal(baselineDiagnostics, actualDiagnostics);
|
||||
}
|
||||
|
||||
protected void AssertLineMappingsMatchBaseline(RazorCodeDocument document)
|
||||
protected void AssertSourceMappingsMatchBaseline(RazorCodeDocument document)
|
||||
{
|
||||
if (FileName == null)
|
||||
{
|
||||
var message = $"{nameof(AssertLineMappingsMatchBaseline)} should only be called from an integration test ({nameof(FileName)} is null).";
|
||||
var message = $"{nameof(AssertSourceMappingsMatchBaseline)} should only be called from an integration test ({nameof(FileName)} is null).";
|
||||
throw new InvalidOperationException(message);
|
||||
}
|
||||
|
||||
|
|
@ -205,7 +205,7 @@ namespace Microsoft.AspNetCore.Razor.Language.IntegrationTests
|
|||
Assert.NotNull(csharpDocument);
|
||||
|
||||
var baselineFileName = Path.ChangeExtension(FileName, ".mappings.txt");
|
||||
var serializedMappings = LineMappingsSerializer.Serialize(csharpDocument, document.Source);
|
||||
var serializedMappings = SourceMappingsSerializer.Serialize(csharpDocument, document.Source);
|
||||
|
||||
if (GenerateBaselines)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ using Microsoft.AspNetCore.Razor.Language.Legacy;
|
|||
|
||||
namespace Microsoft.AspNetCore.Razor.Language.IntegrationTests
|
||||
{
|
||||
public static class LineMappingsSerializer
|
||||
public static class SourceMappingsSerializer
|
||||
{
|
||||
public static string Serialize(RazorCSharpDocument csharpDocument, RazorSourceDocument sourceDocument)
|
||||
{
|
||||
|
|
@ -15,15 +15,15 @@ namespace Microsoft.AspNetCore.Razor.Language.IntegrationTests
|
|||
sourceDocument.CopyTo(0, charBuffer, 0, sourceDocument.Length);
|
||||
var sourceContent = new string(charBuffer);
|
||||
|
||||
for (var i = 0; i < csharpDocument.LineMappings.Count; i++)
|
||||
for (var i = 0; i < csharpDocument.SourceMappings.Count; i++)
|
||||
{
|
||||
var lineMapping = csharpDocument.LineMappings[i];
|
||||
var sourceMapping = csharpDocument.SourceMappings[i];
|
||||
|
||||
builder.Append("Source Location: ");
|
||||
AppendMappingLocation(builder, lineMapping.OriginalSpan, sourceContent);
|
||||
AppendMappingLocation(builder, sourceMapping.OriginalSpan, sourceContent);
|
||||
|
||||
builder.Append("Generated Location: ");
|
||||
AppendMappingLocation(builder, lineMapping.GeneratedSpan, csharpDocument.GeneratedCode);
|
||||
AppendMappingLocation(builder, sourceMapping.GeneratedSpan, csharpDocument.GeneratedCode);
|
||||
|
||||
builder.AppendLine();
|
||||
}
|
||||
Loading…
Reference in New Issue