From afa61e708016f22cbdad5cf539d34add137af291 Mon Sep 17 00:00:00 2001 From: "N. Taylor Mullen" Date: Thu, 6 Jul 2017 10:21:18 -0700 Subject: [PATCH] Rename LineMapping => SourceMapping. - Also removed the == and `!=` operators for `SourceMapping`. #1510 --- .../CodeGeneration/CodeRenderingContext.cs | 2 +- .../DefaultCodeRenderingContext.cs | 10 ++--- .../CodeGeneration/DefaultDocumentWriter.cs | 2 +- .../CodeGeneration/DesignTimeNodeWriter.cs | 12 +++--- .../DefaultRazorCSharpDocument.cs | 8 ++-- .../DefaultTagHelperTargetExtension.cs | 2 +- .../DesignTimeDirectiveTargetExtension.cs | 10 ++--- .../RazorCSharpDocument.cs | 12 +++--- .../{LineMapping.cs => SourceMapping.cs} | 40 ++----------------- .../CodeGenerationIntegrationTest.cs | 2 +- ...ializer.cs => SourceMappingsSerializer.cs} | 12 +++--- .../DesignTimeNodeWriterTest.cs | 6 +-- .../CodeGenerationIntegrationTest.cs | 4 +- .../ExtensibleDirectiveTest.cs | 2 +- .../SourceSpanTest.cs | 27 ++++++------- .../StringSourceDocumentTest.cs | 18 ++++----- .../IntegrationTests/IntegrationTestBase.cs | 6 +-- ...ializer.cs => SourceMappingsSerializer.cs} | 10 ++--- 18 files changed, 76 insertions(+), 109 deletions(-) rename src/Microsoft.AspNetCore.Razor.Language/{LineMapping.cs => SourceMapping.cs} (55%) rename test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Test/{LineMappingsSerializer.cs => SourceMappingsSerializer.cs} (74%) rename test/Microsoft.AspNetCore.Razor.Test.Common/Language/IntegrationTests/{LineMappingsSerializer.cs => SourceMappingsSerializer.cs} (77%) diff --git a/src/Microsoft.AspNetCore.Razor.Language/CodeGeneration/CodeRenderingContext.cs b/src/Microsoft.AspNetCore.Razor.Language/CodeGeneration/CodeRenderingContext.cs index 4765e8f062..f726e2ad4b 100644 --- a/src/Microsoft.AspNetCore.Razor.Language/CodeGeneration/CodeRenderingContext.cs +++ b/src/Microsoft.AspNetCore.Razor.Language/CodeGeneration/CodeRenderingContext.cs @@ -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); diff --git a/src/Microsoft.AspNetCore.Razor.Language/CodeGeneration/DefaultCodeRenderingContext.cs b/src/Microsoft.AspNetCore.Razor.Language/CodeGeneration/DefaultCodeRenderingContext.cs index 645ca6e0d2..848d344c3e 100644 --- a/src/Microsoft.AspNetCore.Razor.Language/CodeGeneration/DefaultCodeRenderingContext.cs +++ b/src/Microsoft.AspNetCore.Razor.Language/CodeGeneration/DefaultCodeRenderingContext.cs @@ -55,7 +55,7 @@ namespace Microsoft.AspNetCore.Razor.Language.CodeGeneration _ancestors = new Stack(); Diagnostics = new RazorDiagnosticCollection(); Items = new ItemCollection(); - LineMappings = new List(); + SourceMappings = new List(); 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 LineMappings { get; } + public List 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) diff --git a/src/Microsoft.AspNetCore.Razor.Language/CodeGeneration/DefaultDocumentWriter.cs b/src/Microsoft.AspNetCore.Razor.Language/CodeGeneration/DefaultDocumentWriter.cs index b358ee956d..d2788e8c40 100644 --- a/src/Microsoft.AspNetCore.Razor.Language/CodeGeneration/DefaultDocumentWriter.cs +++ b/src/Microsoft.AspNetCore.Razor.Language/CodeGeneration/DefaultDocumentWriter.cs @@ -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 diff --git a/src/Microsoft.AspNetCore.Razor.Language/CodeGeneration/DesignTimeNodeWriter.cs b/src/Microsoft.AspNetCore.Razor.Language/CodeGeneration/DesignTimeNodeWriter.cs index 3bd2e504f2..46837d0e23 100644 --- a/src/Microsoft.AspNetCore.Razor.Language/CodeGeneration/DesignTimeNodeWriter.cs +++ b/src/Microsoft.AspNetCore.Razor.Language/CodeGeneration/DesignTimeNodeWriter.cs @@ -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) diff --git a/src/Microsoft.AspNetCore.Razor.Language/DefaultRazorCSharpDocument.cs b/src/Microsoft.AspNetCore.Razor.Language/DefaultRazorCSharpDocument.cs index 09f6c83cbe..cae8cfb69d 100644 --- a/src/Microsoft.AspNetCore.Razor.Language/DefaultRazorCSharpDocument.cs +++ b/src/Microsoft.AspNetCore.Razor.Language/DefaultRazorCSharpDocument.cs @@ -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(); - _lineMappings = lineMappings ?? Array.Empty(); + _sourceMappings = sourceMappings ?? Array.Empty(); } public override IReadOnlyList Diagnostics => _diagnostics; public override string GeneratedCode => _generatedCode; - public override IReadOnlyList LineMappings => _lineMappings; + public override IReadOnlyList SourceMappings => _sourceMappings; public override RazorCodeGenerationOptions Options => _options; } diff --git a/src/Microsoft.AspNetCore.Razor.Language/Extensions/DefaultTagHelperTargetExtension.cs b/src/Microsoft.AspNetCore.Razor.Language/Extensions/DefaultTagHelperTargetExtension.cs index f340361731..a58199c34b 100644 --- a/src/Microsoft.AspNetCore.Razor.Language/Extensions/DefaultTagHelperTargetExtension.cs +++ b/src/Microsoft.AspNetCore.Razor.Language/Extensions/DefaultTagHelperTargetExtension.cs @@ -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); diff --git a/src/Microsoft.AspNetCore.Razor.Language/Extensions/DesignTimeDirectiveTargetExtension.cs b/src/Microsoft.AspNetCore.Razor.Language/Extensions/DesignTimeDirectiveTargetExtension.cs index cedc37fe2c..a558bbf838 100644 --- a/src/Microsoft.AspNetCore.Razor.Language/Extensions/DesignTimeDirectiveTargetExtension.cs +++ b/src/Microsoft.AspNetCore.Razor.Language/Extensions/DesignTimeDirectiveTargetExtension.cs @@ -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("\""); diff --git a/src/Microsoft.AspNetCore.Razor.Language/RazorCSharpDocument.cs b/src/Microsoft.AspNetCore.Razor.Language/RazorCSharpDocument.cs index 516cea2a4d..bfaa53b719 100644 --- a/src/Microsoft.AspNetCore.Razor.Language/RazorCSharpDocument.cs +++ b/src/Microsoft.AspNetCore.Razor.Language/RazorCSharpDocument.cs @@ -11,7 +11,7 @@ namespace Microsoft.AspNetCore.Razor.Language { public abstract string GeneratedCode { get; } - public abstract IReadOnlyList LineMappings { get; } + public abstract IReadOnlyList SourceMappings { get; } public abstract IReadOnlyList 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 diagnostics, - IEnumerable lineMappings) + IEnumerable 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()); } } } diff --git a/src/Microsoft.AspNetCore.Razor.Language/LineMapping.cs b/src/Microsoft.AspNetCore.Razor.Language/SourceMapping.cs similarity index 55% rename from src/Microsoft.AspNetCore.Razor.Language/LineMapping.cs rename to src/Microsoft.AspNetCore.Razor.Language/SourceMapping.cs index 284e3b5f70..a1ecfd1489 100644 --- a/src/Microsoft.AspNetCore.Razor.Language/LineMapping.cs +++ b/src/Microsoft.AspNetCore.Razor.Language/SourceMapping.cs @@ -7,9 +7,9 @@ using Microsoft.Extensions.Internal; namespace Microsoft.AspNetCore.Razor.Language { - public sealed class LineMapping : IEquatable + public sealed class SourceMapping : IEquatable { - 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); diff --git a/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Test/IntegrationTests/CodeGenerationIntegrationTest.cs b/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Test/IntegrationTests/CodeGenerationIntegrationTest.cs index b97de19eda..ba22e8979e 100644 --- a/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Test/IntegrationTests/CodeGenerationIntegrationTest.cs +++ b/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Test/IntegrationTests/CodeGenerationIntegrationTest.cs @@ -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); } diff --git a/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Test/LineMappingsSerializer.cs b/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Test/SourceMappingsSerializer.cs similarity index 74% rename from test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Test/LineMappingsSerializer.cs rename to test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Test/SourceMappingsSerializer.cs index 9a7cd98cd1..c2dd799b05 100644 --- a/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Test/LineMappingsSerializer.cs +++ b/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Test/SourceMappingsSerializer.cs @@ -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(); } diff --git a/test/Microsoft.AspNetCore.Razor.Language.Test/CodeGeneration/DesignTimeNodeWriterTest.cs b/test/Microsoft.AspNetCore.Razor.Language.Test/CodeGeneration/DesignTimeNodeWriterTest.cs index eeb7ef37ac..3ec12f07bf 100644 --- a/test/Microsoft.AspNetCore.Razor.Language.Test/CodeGeneration/DesignTimeNodeWriterTest.cs +++ b/test/Microsoft.AspNetCore.Razor.Language.Test/CodeGeneration/DesignTimeNodeWriterTest.cs @@ -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"" diff --git a/test/Microsoft.AspNetCore.Razor.Language.Test/IntegrationTests/CodeGenerationIntegrationTest.cs b/test/Microsoft.AspNetCore.Razor.Language.Test/IntegrationTests/CodeGenerationIntegrationTest.cs index 3d61cc376f..f8de2ce59c 100644 --- a/test/Microsoft.AspNetCore.Razor.Language.Test/IntegrationTests/CodeGenerationIntegrationTest.cs +++ b/test/Microsoft.AspNetCore.Razor.Language.Test/IntegrationTests/CodeGenerationIntegrationTest.cs @@ -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); } } } diff --git a/test/Microsoft.AspNetCore.Razor.Language.Test/IntegrationTests/ExtensibleDirectiveTest.cs b/test/Microsoft.AspNetCore.Razor.Language.Test/IntegrationTests/ExtensibleDirectiveTest.cs index 7b8d9f3c2e..3428fadde8 100644 --- a/test/Microsoft.AspNetCore.Razor.Language.Test/IntegrationTests/ExtensibleDirectiveTest.cs +++ b/test/Microsoft.AspNetCore.Razor.Language.Test/IntegrationTests/ExtensibleDirectiveTest.cs @@ -27,7 +27,7 @@ namespace Microsoft.AspNetCore.Razor.Language.IntegrationTests // Assert AssertDocumentNodeMatchesBaseline(document.GetDocumentIntermediateNode()); AssertCSharpDocumentMatchesBaseline(document.GetCSharpDocument()); - AssertLineMappingsMatchBaseline(document); + AssertSourceMappingsMatchBaseline(document); } } } diff --git a/test/Microsoft.AspNetCore.Razor.Language.Test/SourceSpanTest.cs b/test/Microsoft.AspNetCore.Razor.Language.Test/SourceSpanTest.cs index d6621c57bc..d59253c08a 100644 --- a/test/Microsoft.AspNetCore.Razor.Language.Test/SourceSpanTest.cs +++ b/test/Microsoft.AspNetCore.Razor.Language.Test/SourceSpanTest.cs @@ -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)); diff --git a/test/Microsoft.AspNetCore.Razor.Language.Test/StringSourceDocumentTest.cs b/test/Microsoft.AspNetCore.Razor.Language.Test/StringSourceDocumentTest.cs index 7fca1377e1..16acfc8be9 100644 --- a/test/Microsoft.AspNetCore.Razor.Language.Test/StringSourceDocumentTest.cs +++ b/test/Microsoft.AspNetCore.Razor.Language.Test/StringSourceDocumentTest.cs @@ -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++) diff --git a/test/Microsoft.AspNetCore.Razor.Test.Common/Language/IntegrationTests/IntegrationTestBase.cs b/test/Microsoft.AspNetCore.Razor.Test.Common/Language/IntegrationTests/IntegrationTestBase.cs index 2c76d9d289..2803102f6c 100644 --- a/test/Microsoft.AspNetCore.Razor.Test.Common/Language/IntegrationTests/IntegrationTestBase.cs +++ b/test/Microsoft.AspNetCore.Razor.Test.Common/Language/IntegrationTests/IntegrationTestBase.cs @@ -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) { diff --git a/test/Microsoft.AspNetCore.Razor.Test.Common/Language/IntegrationTests/LineMappingsSerializer.cs b/test/Microsoft.AspNetCore.Razor.Test.Common/Language/IntegrationTests/SourceMappingsSerializer.cs similarity index 77% rename from test/Microsoft.AspNetCore.Razor.Test.Common/Language/IntegrationTests/LineMappingsSerializer.cs rename to test/Microsoft.AspNetCore.Razor.Test.Common/Language/IntegrationTests/SourceMappingsSerializer.cs index a890431ca3..40d95625f4 100644 --- a/test/Microsoft.AspNetCore.Razor.Test.Common/Language/IntegrationTests/LineMappingsSerializer.cs +++ b/test/Microsoft.AspNetCore.Razor.Test.Common/Language/IntegrationTests/SourceMappingsSerializer.cs @@ -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(); }