Skip to content

Commit

Permalink
Add test for cascading type parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
davidwengier committed Oct 25, 2021
1 parent da8752a commit 29149b1
Showing 1 changed file with 83 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the MIT license. See License.txt in the project root for license information.

using System.Collections.Generic;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Razor.Language;
using Microsoft.AspNetCore.Razor.Test.Common;
Expand All @@ -11,6 +12,10 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer.Formatting
{
public class CodeDirectiveFormattingTest : FormattingTestBase
{
internal override bool UseTwoPhaseCompilation => true;

internal override bool DesignTime => true;

public CodeDirectiveFormattingTest(ITestOutputHelper output)
: base(output)
{
Expand Down Expand Up @@ -866,5 +871,83 @@ await RunFormattingTestAsync(useSourceTextDiffer: useSourceTextDiffer,
</div>
");
}

[Theory]
[CombinatorialData]
[WorkItem("https://github.com/dotnet/razor-tooling/issues/5648")]
public async Task GenericComponentWithCascadingTypeParameter(bool useSourceTextDiffer)
{
await RunFormattingTestAsync(useSourceTextDiffer: useSourceTextDiffer,
input: @"
@page ""/counter""
@if(true)
{
// indented
}
<TestGeneric Items=""_items"">
@foreach (var v in System.Linq.Enumerable.Range(1, 10))
{
<div></div>
}
</TestGeneric>
@if(true)
{
// indented
}
@code
{
private IEnumerable<int> _items = new[] { 1, 2, 3, 4, 5 };
}",
expected: @"@page ""/counter""
@if (true)
{
// indented
}
<TestGeneric Items=""_items"">
@foreach (var v in System.Linq.Enumerable.Range(1, 10))
{
<div></div>
}
</TestGeneric>
@if (true)
{
// indented
}
@code
{
private IEnumerable<int> _items = new[] { 1, 2, 3, 4, 5 };
}",
tagHelpers: GetComponentWithCascadingTypeParameter());
}

private IReadOnlyList<TagHelperDescriptor> GetComponentWithCascadingTypeParameter()
{
var input = @"
@using System.Collections.Generic
@using Microsoft.AspNetCore.Components
@typeparam TItem
@attribute [CascadingTypeParameter(nameof(TItem))]
<h3>TestGeneric</h3>
@code
{
[Parameter] public IEnumerable<TItem> Items { get; set; }
[Parameter] public RenderFragment ChildContent { get; set; }
}
";

var generated = CompileToCSharp("TestGeneric.razor", input, throwOnFailure: true, fileKind: FileKinds.Component);
var tagHelpers = generated.CodeDocument.GetTagHelperContext().TagHelpers;
return tagHelpers;
}
}
}

0 comments on commit 29149b1

Please sign in to comment.