From 1fbdb301866075405aa10be4659fe995352a6068 Mon Sep 17 00:00:00 2001 From: Ryan Nowak Date: Tue, 11 Apr 2017 08:03:36 -0700 Subject: [PATCH] Normalize newlines in default imports Needed for xplat --- .../CodeGenerationIntegrationTest.cs | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) 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 931f87069f..b0296f3644 100644 --- a/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Test/IntegrationTests/CodeGenerationIntegrationTest.cs +++ b/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Test/IntegrationTests/CodeGenerationIntegrationTest.cs @@ -5,6 +5,8 @@ using System.Collections.Generic; using System.IO; using System.Linq; using System.Reflection; +using System.Text; +using System.Text.RegularExpressions; using Microsoft.AspNetCore.Razor.Language; using Microsoft.AspNetCore.Razor.Language.IntegrationTests; using Microsoft.AspNetCore.Razor.TagHelpers; @@ -351,7 +353,19 @@ namespace Microsoft.AspNetCore.Mvc.Razor.Extensions.IntegrationTests protected override void OnCreatingCodeDocument(ref RazorSourceDocument source, IList imports) { - imports.Add(DefaultImports); + // It's important that we normalize the newlines in the default imports. The default imports will + // be created with Environment.NewLine, but we need to normalize to `\r\n` so that the indices + // are the same on xplat. + var buffer = new char[DefaultImports.Length]; + DefaultImports.CopyTo(0, buffer, 0, DefaultImports.Length); + + var builder = new StringBuilder(); + builder.Append(buffer); + + var text = new string(buffer); + text = Regex.Replace(text, "(? BuildDivDescriptors()