From f0a3f4d9faf4c21135aef5378db42cf847b0dc28 Mon Sep 17 00:00:00 2001 From: David Wengier Date: Mon, 4 Apr 2022 14:41:58 +1000 Subject: [PATCH] Add tests --- .../Formatting/CodeDirectiveFormattingTest.cs | 90 ++++ .../CodeDirectiveOnTypeFormattingTest.cs | 60 ++- .../Formatting/HtmlFormattingTest.cs | 466 ++++++++++++++++++ 3 files changed, 615 insertions(+), 1 deletion(-) diff --git a/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/Formatting/CodeDirectiveFormattingTest.cs b/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/Formatting/CodeDirectiveFormattingTest.cs index c8e40bb1f0..70a7c8aaff 100644 --- a/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/Formatting/CodeDirectiveFormattingTest.cs +++ b/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/Formatting/CodeDirectiveFormattingTest.cs @@ -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 GetComponentWithCascadingTypeParameter() { var input = """ diff --git a/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/Formatting/CodeDirectiveOnTypeFormattingTest.cs b/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/Formatting/CodeDirectiveOnTypeFormattingTest.cs index 436afe6c98..f7b0b94400 100644 --- a/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/Formatting/CodeDirectiveOnTypeFormattingTest.cs +++ b/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/Formatting/CodeDirectiveOnTypeFormattingTest.cs @@ -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: '}'); + } } } diff --git a/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/Formatting/HtmlFormattingTest.cs b/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/Formatting/HtmlFormattingTest.cs index a668c17604..ebc4167537 100644 --- a/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/Formatting/HtmlFormattingTest.cs +++ b/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/Formatting/HtmlFormattingTest.cs @@ -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) + { + + + + @if (VarBool) + { +
+ + +
+ } +
+
+ } + + @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) + { +
+ + +
+ } +
+
+ } + + @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) + { + + + @if (VarBool) + { +
+ + +
+ } +
+ } + + @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) + { +
+ + +
+ } +
+ } + + @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) + { + + @if (VarBool) + { +
+ + +
+ } + } + } + + @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) + { + + @if (VarBool) + { +
+ + +
+ } + } + } + + @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; + + + + @if (VarBool) + { +
+ + +
+ } +
+ + @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 (VarBool) + { +
+ + +
+ } +
+ + @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) + { + + + @if (VarBool) + { +
+ + +
+ } +
+ } + + @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) + { +
+ + +
+ } +
+ } + + @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;} + } + +
+ @if (true) + { +
+ + @if (true) + { + + } + +
+ } +
+ """, + expected: """ + @using Microsoft.AspNetCore.Components.Forms; + + @code { + private string _id { get; set; } + } + +
+ @if (true) + { +
+ + @if (true) + { + + } + +
+ } +
+ """, + 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;} + } + +
+
+ + @if (true) + { + + } + +
+
+ """, + expected: """ + @using Microsoft.AspNetCore.Components.Forms; + + @code { + private string _id { get; set; } + } + +
+
+ + @if (true) + { + + } + +
+
+ """, + 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;} + } + +
+
+ + + +
+
+ """, + expected: """ + @using Microsoft.AspNetCore.Components.Forms; + + @code { + private string _id { get; set; } + } + +
+
+ + + +
+
+ """, + 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;} + } + +
+ @if (true) + { +
+ + + +
+ } +
+ """, + expected: """ + @using Microsoft.AspNetCore.Components.Forms; + + @code { + private string _id { get; set; } + } + +
+ @if (true) + { +
+ + + +
+ } +
+ """, + fileKind: FileKinds.Component); + } + [Fact] [WorkItem("https://github.com/dotnet/razor-tooling/issues/6211")] public async Task FormatCascadingValueWithCascadingTypeParameter()