This commit is contained in:
David Wengier 2022-04-04 14:41:58 +10:00
Родитель 9c3cd70b28
Коммит f0a3f4d9fa
3 изменённых файлов: 615 добавлений и 1 удалений

Просмотреть файл

@ -1479,6 +1479,96 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer.Formatting
await RunFormattingTestAsync(input, input, fileKind: FileKinds.Component);
}
[Fact]
[WorkItem("https://github.com/dotnet/razor-tooling/issues/6158")]
public async Task Format_NestedLambdas()
{
await RunFormattingTestAsync(
input: """
@code {
protected Action Goo(string input)
{
return async () =>
{
foreach (var x in input)
{
if (true)
{
await Task.Delay(1);
if (true)
{
// do some stufff
if (true)
{
}
}
}
}
};
}
}
""",
expected: """
@code {
protected Action Goo(string input)
{
return async () =>
{
foreach (var x in input)
{
if (true)
{
await Task.Delay(1);
if (true)
{
// do some stufff
if (true)
{
}
}
}
}
};
}
}
""");
}
[Fact]
[WorkItem("https://github.com/dotnet/razor-tooling/issues/5693")]
public async Task Format_NestedLambdasWithAtIf()
{
await RunFormattingTestAsync(
input: """
@code {
public RenderFragment RenderFoo()
{
return (__builder) =>
{
@if (true) { }
};
}
}
""",
expected: """
@code {
public RenderFragment RenderFoo()
{
return (__builder) =>
{
@if (true) { }
};
}
}
""");
}
private IReadOnlyList<TagHelperDescriptor> GetComponentWithCascadingTypeParameter()
{
var input = """

Просмотреть файл

@ -624,7 +624,7 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer.Formatting
await RunOnTypeFormattingTestAsync(input, input.Replace("$$", ""), triggerCharacter: ';');
}
[Fact(Skip = "https://github.com/dotnet/razor-tooling/issues/5676")]
[Fact]
[WorkItem("https://github.com/dotnet/razor-tooling/issues/5693")]
public async Task IfStatementInsideLambda()
{
@ -661,5 +661,63 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer.Formatting
""",
triggerCharacter: '}');
}
[Fact]
[WorkItem("https://github.com/dotnet/razor-tooling/issues/6158")]
public async Task Format_NestedLambdas()
{
await RunOnTypeFormattingTestAsync(
input: """
@code {
protected Action Goo(string input)
{
return async () =>
{
foreach (var x in input)
{
if (true)
{
await Task.Delay(1);
if (true)
{
// do some stufff
if (true)
{}$$
}
}
}
};
}
}
""",
expected: """
@code {
protected Action Goo(string input)
{
return async () =>
{
foreach (var x in input)
{
if (true)
{
await Task.Delay(1);
if (true)
{
// do some stufff
if (true)
{ }
}
}
}
};
}
}
""",
triggerCharacter: '}');
}
}
}

Просмотреть файл

@ -934,6 +934,472 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer.Formatting
""");
}
[Fact]
[WorkItem("https://github.com/dotnet/razor-tooling/issues/6001")]
public async Task FormatNestedCascadingValue()
{
await RunFormattingTestAsync(
input: """
@using Microsoft.AspNetCore.Components.Forms;
@if (Object1!= null)
{
<CascadingValue Value="Variable1">
<CascadingValue Value="Variable2">
<SurveyPrompt />
@if (VarBool)
{
<div class="mb-16">
<SurveyPrompt />
<SurveyPrompt />
</div>
}
</CascadingValue>
</CascadingValue>
}
@code
{
public object Object1 {get;set;}
public object Variable1 {get;set;}
public object Variable2 {get;set;}
public bool VarBool {get;set;}
}
""",
expected: """
@using Microsoft.AspNetCore.Components.Forms;
@if (Object1 != null)
{
<CascadingValue Value="Variable1">
<CascadingValue Value="Variable2">
<SurveyPrompt />
@if (VarBool)
{
<div class="mb-16">
<SurveyPrompt />
<SurveyPrompt />
</div>
}
</CascadingValue>
</CascadingValue>
}
@code
{
public object Object1 { get; set; }
public object Variable1 { get; set; }
public object Variable2 { get; set; }
public bool VarBool { get; set; }
}
""",
fileKind: FileKinds.Component);
}
[Fact]
[WorkItem("https://github.com/dotnet/razor-tooling/issues/6001")]
public async Task FormatNestedCascadingValue2()
{
await RunFormattingTestAsync(
input: """
@using Microsoft.AspNetCore.Components.Forms;
@if (Object1!= null)
{
<CascadingValue Value="Variable1">
<SurveyPrompt />
@if (VarBool)
{
<div class="mb-16">
<SurveyPrompt />
<SurveyPrompt />
</div>
}
</CascadingValue>
}
@code
{
public object Object1 {get;set;}
public object Variable1 {get;set;}
public object Variable2 {get;set;}
public bool VarBool {get;set;}
}
""",
expected: """
@using Microsoft.AspNetCore.Components.Forms;
@if (Object1 != null)
{
<CascadingValue Value="Variable1">
<SurveyPrompt />
@if (VarBool)
{
<div class="mb-16">
<SurveyPrompt />
<SurveyPrompt />
</div>
}
</CascadingValue>
}
@code
{
public object Object1 { get; set; }
public object Variable1 { get; set; }
public object Variable2 { get; set; }
public bool VarBool { get; set; }
}
""",
fileKind: FileKinds.Component);
}
[Fact]
[WorkItem("https://github.com/dotnet/razor-tooling/issues/6001")]
public async Task FormatNestedCascadingValue3()
{
await RunFormattingTestAsync(
input: """
@using Microsoft.AspNetCore.Components.Forms;
@if (Object1!= null)
{
@if (VarBool)
{
<SurveyPrompt />
@if (VarBool)
{
<div class="mb-16">
<SurveyPrompt />
<SurveyPrompt />
</div>
}
}
}
@code
{
public object Object1 {get;set;}
public object Variable1 {get;set;}
public object Variable2 {get;set;}
public bool VarBool {get;set;}
}
""",
expected: """
@using Microsoft.AspNetCore.Components.Forms;
@if (Object1 != null)
{
@if (VarBool)
{
<SurveyPrompt />
@if (VarBool)
{
<div class="mb-16">
<SurveyPrompt />
<SurveyPrompt />
</div>
}
}
}
@code
{
public object Object1 { get; set; }
public object Variable1 { get; set; }
public object Variable2 { get; set; }
public bool VarBool { get; set; }
}
""",
fileKind: FileKinds.Component);
}
[Fact]
[WorkItem("https://github.com/dotnet/razor-tooling/issues/6001")]
public async Task FormatNestedCascadingValue4()
{
await RunFormattingTestAsync(
input: """
@using Microsoft.AspNetCore.Components.Forms;
<CascadingValue Value="Variable1">
<SurveyPrompt />
@if (VarBool)
{
<div class="mb-16">
<SurveyPrompt />
<SurveyPrompt />
</div>
}
</CascadingValue>
@code
{
public object Object1 {get;set;}
public object Variable1 {get;set;}
public object Variable2 {get;set;}
public bool VarBool {get;set;}
}
""",
expected: """
@using Microsoft.AspNetCore.Components.Forms;
<CascadingValue Value="Variable1">
<SurveyPrompt />
@if (VarBool)
{
<div class="mb-16">
<SurveyPrompt />
<SurveyPrompt />
</div>
}
</CascadingValue>
@code
{
public object Object1 { get; set; }
public object Variable1 { get; set; }
public object Variable2 { get; set; }
public bool VarBool { get; set; }
}
""",
fileKind: FileKinds.Component);
}
[Fact]
[WorkItem("https://github.com/dotnet/razor-tooling/issues/6001")]
public async Task FormatNestedCascadingValue5()
{
await RunFormattingTestAsync(
input: """
@using Microsoft.AspNetCore.Components.Forms;
@if (Object1!= null)
{
<PageTitle>
<SurveyPrompt />
@if (VarBool)
{
<div class="mb-16">
<SurveyPrompt />
<SurveyPrompt />
</div>
}
</PageTitle>
}
@code
{
public object Object1 {get;set;}
public object Variable1 {get;set;}
public object Variable2 {get;set;}
public bool VarBool {get;set;}
}
""",
expected: """
@using Microsoft.AspNetCore.Components.Forms;
@if (Object1 != null)
{
<PageTitle>
<SurveyPrompt />
@if (VarBool)
{
<div class="mb-16">
<SurveyPrompt />
<SurveyPrompt />
</div>
}
</PageTitle>
}
@code
{
public object Object1 { get; set; }
public object Variable1 { get; set; }
public object Variable2 { get; set; }
public bool VarBool { get; set; }
}
""",
fileKind: FileKinds.Component);
}
[Fact]
[WorkItem("https://github.com/dotnet/razor-tooling/issues/5676")]
public async Task FormatInputSelect()
{
await RunFormattingTestAsync(
input: """
@using Microsoft.AspNetCore.Components.Forms;
@code {
private string _id {get;set;}
}
<div>
@if (true)
{
<div>
<InputSelect @bind-Value="_id">
@if (true)
{
<option>goo</option>
}
</InputSelect>
</div>
}
</div>
""",
expected: """
@using Microsoft.AspNetCore.Components.Forms;
@code {
private string _id { get; set; }
}
<div>
@if (true)
{
<div>
<InputSelect @bind-Value="_id">
@if (true)
{
<option>goo</option>
}
</InputSelect>
</div>
}
</div>
""",
fileKind: FileKinds.Component);
}
[Fact]
[WorkItem("https://github.com/dotnet/razor-tooling/issues/5676")]
public async Task FormatInputSelect2()
{
await RunFormattingTestAsync(
input: """
@using Microsoft.AspNetCore.Components.Forms;
@code {
private string _id {get;set;}
}
<div>
<div>
<InputSelect @bind-Value="_id">
@if (true)
{
<option>goo</option>
}
</InputSelect>
</div>
</div>
""",
expected: """
@using Microsoft.AspNetCore.Components.Forms;
@code {
private string _id { get; set; }
}
<div>
<div>
<InputSelect @bind-Value="_id">
@if (true)
{
<option>goo</option>
}
</InputSelect>
</div>
</div>
""",
fileKind: FileKinds.Component);
}
[Fact]
[WorkItem("https://github.com/dotnet/razor-tooling/issues/5676")]
public async Task FormatInputSelect3()
{
await RunFormattingTestAsync(
input: """
@using Microsoft.AspNetCore.Components.Forms;
@code {
private string _id {get;set;}
}
<div>
<div>
<InputSelect @bind-Value="_id">
<option>goo</option>
</InputSelect>
</div>
</div>
""",
expected: """
@using Microsoft.AspNetCore.Components.Forms;
@code {
private string _id { get; set; }
}
<div>
<div>
<InputSelect @bind-Value="_id">
<option>goo</option>
</InputSelect>
</div>
</div>
""",
fileKind: FileKinds.Component);
}
[Fact]
[WorkItem("https://github.com/dotnet/razor-tooling/issues/5676")]
public async Task FormatInputSelect4()
{
await RunFormattingTestAsync(
input: """
@using Microsoft.AspNetCore.Components.Forms;
@code {
private string _id {get;set;}
}
<div>
@if (true)
{
<div>
<InputSelect @bind-Value="_id">
<option>goo</option>
</InputSelect>
</div>
}
</div>
""",
expected: """
@using Microsoft.AspNetCore.Components.Forms;
@code {
private string _id { get; set; }
}
<div>
@if (true)
{
<div>
<InputSelect @bind-Value="_id">
<option>goo</option>
</InputSelect>
</div>
}
</div>
""",
fileKind: FileKinds.Component);
}
[Fact]
[WorkItem("https://github.com/dotnet/razor-tooling/issues/6211")]
public async Task FormatCascadingValueWithCascadingTypeParameter()