From 7b8126367c70ef9d8e63a22197cd398689229cd3 Mon Sep 17 00:00:00 2001 From: Doug Bunting Date: Tue, 13 Jan 2015 20:57:39 -0800 Subject: [PATCH] Minor: `LineMapping` and `MappingLocation` debug visualizations were types' full names - add `ToString()` overrides for these classes Nits: - improve assertion failures about code mapping mismatches - add `GENERATE_BASELINES` reminder to test project.json --- .../Generator/Compiler/LineMappings/LineMapping.cs | 7 +++++++ .../Compiler/LineMappings/MappingLocation.cs | 11 +++++++++++ .../Generator/RazorCodeGeneratorTest.cs | 14 +++++--------- test/Microsoft.AspNet.Razor.Test/project.json | 3 +++ 4 files changed, 26 insertions(+), 9 deletions(-) diff --git a/src/Microsoft.AspNet.Razor/Generator/Compiler/LineMappings/LineMapping.cs b/src/Microsoft.AspNet.Razor/Generator/Compiler/LineMappings/LineMapping.cs index 6bf06bd1ec..60778a34e6 100644 --- a/src/Microsoft.AspNet.Razor/Generator/Compiler/LineMappings/LineMapping.cs +++ b/src/Microsoft.AspNet.Razor/Generator/Compiler/LineMappings/LineMapping.cs @@ -1,6 +1,8 @@ // Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +using System.Globalization; + namespace Microsoft.AspNet.Razor.Generator.Compiler { public class LineMapping @@ -40,5 +42,10 @@ namespace Microsoft.AspNet.Razor.Generator.Compiler { return !left.Equals(right); } + + public override string ToString() + { + return string.Format(CultureInfo.CurrentUICulture, "{0} -> {1}", DocumentLocation, GeneratedLocation); + } } } diff --git a/src/Microsoft.AspNet.Razor/Generator/Compiler/LineMappings/MappingLocation.cs b/src/Microsoft.AspNet.Razor/Generator/Compiler/LineMappings/MappingLocation.cs index 53a372892e..9d3d6e2361 100644 --- a/src/Microsoft.AspNet.Razor/Generator/Compiler/LineMappings/MappingLocation.cs +++ b/src/Microsoft.AspNet.Razor/Generator/Compiler/LineMappings/MappingLocation.cs @@ -1,6 +1,7 @@ // Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +using System.Globalization; using Microsoft.AspNet.Razor.Text; namespace Microsoft.AspNet.Razor.Generator.Compiler @@ -37,6 +38,16 @@ namespace Microsoft.AspNet.Razor.Generator.Compiler return base.GetHashCode(); } + public override string ToString() + { + return string.Format( + CultureInfo.CurrentCulture, "({0}:{1},{2} [{3}])", + AbsoluteIndex, + LineIndex, + CharacterIndex, + ContentLength); + } + public static bool operator ==(MappingLocation left, MappingLocation right) { return left.Equals(right); diff --git a/test/Microsoft.AspNet.Razor.Test/Generator/RazorCodeGeneratorTest.cs b/test/Microsoft.AspNet.Razor.Test/Generator/RazorCodeGeneratorTest.cs index da41d1fd2d..c5d4ef5b45 100644 --- a/test/Microsoft.AspNet.Razor.Test/Generator/RazorCodeGeneratorTest.cs +++ b/test/Microsoft.AspNet.Razor.Test/Generator/RazorCodeGeneratorTest.cs @@ -181,17 +181,13 @@ namespace Microsoft.AspNet.Razor.Test.Generator if (expectedDesignTimePragmas != null) { - Assert.True(results.DesignTimeLineMappings != null && results.DesignTimeLineMappings.Count > 0); + Assert.True(results.DesignTimeLineMappings != null); // Guard + for (var i = 0; i < expectedDesignTimePragmas.Count && i < results.DesignTimeLineMappings.Count; i++) + { + Assert.Equal(expectedDesignTimePragmas[i], results.DesignTimeLineMappings[i]); + } Assert.Equal(expectedDesignTimePragmas.Count, results.DesignTimeLineMappings.Count); - - for (var i = 0; i < expectedDesignTimePragmas.Count; i++) - { - if (!expectedDesignTimePragmas[i].Equals(results.DesignTimeLineMappings[i])) - { - Assert.True(false, String.Format("Line mapping {0} is not equivalent.", i)); - } - } } } } diff --git a/test/Microsoft.AspNet.Razor.Test/project.json b/test/Microsoft.AspNet.Razor.Test/project.json index 14228785fb..cc96a8b09d 100644 --- a/test/Microsoft.AspNet.Razor.Test/project.json +++ b/test/Microsoft.AspNet.Razor.Test/project.json @@ -18,5 +18,8 @@ "System.Reflection.TypeExtensions": "4.0.0-beta-*" } } + }, + "compilationOptions": { + "define": [ "__RemoveThisBitTo__GENERATE_BASELINES" ] } }