Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Licensed to the .NET Foundation under one or more agreements.
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

#nullable disable
Expand Down Expand Up @@ -34,21 +34,6 @@ public CodeGenerationIntegrationTest()

protected override RazorConfiguration Configuration => _configuration;

protected override void ConfigureProjectEngine(RazorProjectEngineBuilder builder)
{
base.ConfigureProjectEngine(builder);

// Register the UTF-8 WriteLiteral feature with a pre-computed support map.
var supportMap = new DefaultUtf8WriteLiteralFeature.Utf8SupportMap(
ImmutableSortedDictionary<string, string>.Empty,
ImmutableSortedDictionary.CreateRange(StringComparer.Ordinal, new[]
{
new KeyValuePair<string, bool>("MyUtf8PageBase", true),
new KeyValuePair<string, bool>("MyPageBase", false),
}));
builder.Features.Add(new DefaultUtf8WriteLiteralFeature { SupportMap = supportMap });
}

#region Runtime

[ConditionalFact(typeof(IsEnglishLocal))]
Expand Down Expand Up @@ -961,82 +946,6 @@ public void InvalidCode_EmptyImplicitExpression()
CompileToAssembly(generated, throwOnFailure: false, ignoreRazorDiagnostics: true);
}

[Fact, WorkItem("https://github.com/dotnet/razor/issues/8429")]
public void Utf8HtmlLiterals_AutoDetectedFromInherits()
{
// Arrange
_configuration = new(RazorLanguageVersion.Preview, "MVC-3.0", Extensions: []);

AddCSharpSyntaxTree("""

using System;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc.Razor;

public abstract class MyUtf8PageBase : RazorPage
{
public void WriteLiteral(ReadOnlySpan<byte> value)
{
WriteLiteral(System.Text.Encoding.UTF8.GetString(value));
}
}

""");

// Act
var generated = CompileToCSharp("""
@inherits MyUtf8PageBase

<html>
<body>
<h1>Hello World</h1>
<p>This is UTF-8 encoded HTML content.</p>
</body>
</html>
""");

// Assert
CompileToAssembly(generated);

var generatedCode = generated.CodeDocument.GetImplCSharpDocument().Text.ToString();
Assert.Contains("u8)", generatedCode);
}

[Fact, WorkItem("https://github.com/dotnet/razor/issues/8429")]
public void Utf8HtmlLiterals_WithoutOverload_UsesStringLiterals()
{
// Arrange
_configuration = new(RazorLanguageVersion.Preview, "MVC-3.0", Extensions: []);

AddCSharpSyntaxTree("""

using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc.Razor;

public abstract class MyPageBase : RazorPage
{
}

""");

// Act
var generated = CompileToCSharp("""
@inherits MyPageBase

<html>
<body>
<h1>Hello World</h1>
</body>
</html>
""");

// Assert
CompileToAssembly(generated);

var generatedCode = generated.CodeDocument.GetImplCSharpDocument().Text.ToString();
Assert.DoesNotContain("u8)", generatedCode);
}

#endregion

[Theory, CombinatorialData, WorkItem("https://github.com/dotnet/razor/issues/7286")]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ private static void AssertDefaultPhases(RazorProjectEngine engine)
phase => Assert.IsType<DefaultTagHelperResolutionPhase>(phase),
phase => Assert.IsType<DefaultRazorTagHelperRewritePhase>(phase),
phase => Assert.IsType<DefaultRazorOptimizationPhase>(phase),
phase => Assert.IsType<Utf8WriteLiteralPhase>(phase),
phase => Assert.IsType<DefaultRazorCSharpLoweringPhase>(phase));
}

Expand Down Expand Up @@ -94,7 +95,6 @@ private static void AssertDefaultFeatures(RazorProjectEngine engine)
feature => Assert.IsType<MetadataAttributePass>(feature),
feature => Assert.IsType<PreallocatedTagHelperAttributeOptimizationPass>(feature),
feature => Assert.IsType<TagHelperDiscoveryService>(feature),
feature => Assert.IsType<Utf8WriteLiteralDetectionPass>(feature),
feature => Assert.IsType<ViewCssScopePass>(feature));
}

Expand Down
Loading