Skip to content

Commit fb4733d

Browse files
committed
Don't use test hook to override formatting options in tests
And rename the parameter to match
1 parent 69b5815 commit fb4733d

File tree

6 files changed

+89
-83
lines changed

6 files changed

+89
-83
lines changed

src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/Formatting_NetFx/DocumentFormattingTest.cs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
// Licensed to the .NET Foundation under one or more agreements.
22
// The .NET Foundation licenses this file to you under the MIT license.
33

4-
using System;
54
using System.Threading.Tasks;
65
using Microsoft.AspNetCore.Razor.Language;
76
using Microsoft.AspNetCore.Razor.Test.Common;
@@ -66,7 +65,7 @@ public void Bar() {
6665
}
6766
}
6867
""",
69-
formattingOptionsOverride: RazorCSharpSyntaxFormattingOptions.Default with
68+
csharpSyntaxFormattingOptions: RazorCSharpSyntaxFormattingOptions.Default with
7069
{
7170
NewLines = RazorNewLinePlacement.None
7271
});
@@ -106,7 +105,7 @@ public void Bar() {
106105
}
107106
}
108107
""",
109-
formattingOptionsOverride: RazorCSharpSyntaxFormattingOptions.Default with
108+
csharpSyntaxFormattingOptions: RazorCSharpSyntaxFormattingOptions.Default with
110109
{
111110
NewLines = RazorNewLinePlacement.None
112111
});
@@ -134,7 +133,7 @@ protected void ToggleIconMenu(bool iconMenuActive)
134133
}
135134
}
136135
""",
137-
formattingOptionsOverride: RazorCSharpSyntaxFormattingOptions.Default with
136+
csharpSyntaxFormattingOptions: RazorCSharpSyntaxFormattingOptions.Default with
138137
{
139138
NewLines = RazorNewLinePlacement.BeforeOpenBraceInMethods
140139
});
@@ -164,7 +163,7 @@ protected void ToggleIconMenu(bool iconMenuActive)
164163
}
165164
}
166165
""",
167-
formattingOptionsOverride: RazorCSharpSyntaxFormattingOptions.Default with
166+
csharpSyntaxFormattingOptions: RazorCSharpSyntaxFormattingOptions.Default with
168167
{
169168
NewLines = RazorNewLinePlacement.BeforeOpenBraceInMethods
170169
});
@@ -194,7 +193,7 @@ protected void ToggleIconMenu(bool iconMenuActive)
194193
}
195194
}
196195
""",
197-
formattingOptionsOverride: RazorCSharpSyntaxFormattingOptions.Default with
196+
csharpSyntaxFormattingOptions: RazorCSharpSyntaxFormattingOptions.Default with
198197
{
199198
NewLines = RazorNewLinePlacement.BeforeOpenBraceInMethods
200199
});
@@ -228,7 +227,7 @@ protected void ToggleIconMenu(bool iconMenuActive)
228227
}
229228
</div>
230229
""",
231-
formattingOptionsOverride: RazorCSharpSyntaxFormattingOptions.Default with
230+
csharpSyntaxFormattingOptions: RazorCSharpSyntaxFormattingOptions.Default with
232231
{
233232
NewLines = RazorNewLinePlacement.BeforeOpenBraceInMethods
234233
});
@@ -255,7 +254,7 @@ public string Name {
255254
}
256255
}
257256
""",
258-
formattingOptionsOverride: RazorCSharpSyntaxFormattingOptions.Default with
257+
csharpSyntaxFormattingOptions: RazorCSharpSyntaxFormattingOptions.Default with
259258
{
260259
NewLines = RazorNewLinePlacement.None
261260
});

src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/Formatting_NetFx/FormattingTestBase.cs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -66,13 +66,15 @@ private protected async Task RunFormattingTestAsync(
6666
bool codeBlockBraceOnNextLine = false,
6767
bool inGlobalNamespace = false,
6868
bool debugAssertsEnabled = true,
69-
RazorCSharpSyntaxFormattingOptions? formattingOptionsOverride = null)
69+
RazorCSharpSyntaxFormattingOptions? csharpSyntaxFormattingOptions = null)
7070
{
7171
(input, expected) = ProcessFormattingContext(input, expected);
7272

7373
var razorLSPOptions = RazorLSPOptions.Default with { CodeBlockBraceOnNextLine = codeBlockBraceOnNextLine };
7474

75-
await RunFormattingTestInternalAsync(input, expected, tabSize, insertSpaces, fileKind, tagHelpers, allowDiagnostics, razorLSPOptions, inGlobalNamespace, debugAssertsEnabled, formattingOptionsOverride);
75+
csharpSyntaxFormattingOptions ??= RazorCSharpSyntaxFormattingOptions.Default;
76+
77+
await RunFormattingTestInternalAsync(input, expected, tabSize, insertSpaces, fileKind, tagHelpers, allowDiagnostics, razorLSPOptions, inGlobalNamespace, debugAssertsEnabled, csharpSyntaxFormattingOptions);
7678
}
7779

7880
private async Task RunFormattingTestInternalAsync(
@@ -86,7 +88,7 @@ private async Task RunFormattingTestInternalAsync(
8688
RazorLSPOptions? razorLSPOptions,
8789
bool inGlobalNamespace,
8890
bool debugAssertsEnabled,
89-
RazorCSharpSyntaxFormattingOptions? formattingOptionsOverride)
91+
RazorCSharpSyntaxFormattingOptions csharpSyntaxFormattingOptions)
9092
{
9193
// Arrange
9294
var fileKindValue = fileKind ?? RazorFileKind.Component;
@@ -109,11 +111,11 @@ private async Task RunFormattingTestInternalAsync(
109111
TabSize = tabSize,
110112
InsertSpaces = insertSpaces,
111113
};
112-
var razorOptions = RazorFormattingOptions.From(options, codeBlockBraceOnNextLine: razorLSPOptions?.CodeBlockBraceOnNextLine ?? false);
114+
var razorOptions = RazorFormattingOptions.From(options, codeBlockBraceOnNextLine: razorLSPOptions?.CodeBlockBraceOnNextLine ?? false, csharpSyntaxFormattingOptions);
113115

114116
var languageServerFeatureOptions = new TestLanguageServerFeatureOptions(useNewFormattingEngine: _context.UseNewFormattingEngine);
115117

116-
var formattingService = await TestRazorFormattingService.CreateWithFullSupportAsync(LoggerFactory, codeDocument, razorLSPOptions, languageServerFeatureOptions, debugAssertsEnabled, formattingOptionsOverride);
118+
var formattingService = await TestRazorFormattingService.CreateWithFullSupportAsync(LoggerFactory, codeDocument, razorLSPOptions, languageServerFeatureOptions, debugAssertsEnabled);
117119
var documentContext = new DocumentContext(uri, documentSnapshot, projectContext: null);
118120

119121
var client = new FormattingLanguageServerClient(_htmlFormattingService, LoggerFactory);

src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/Formatting_NetFx/TestRazorFormattingService.cs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
using Microsoft.AspNetCore.Razor.LanguageServer.Hosting;
99
using Microsoft.AspNetCore.Razor.Test.Common.LanguageServer;
1010
using Microsoft.AspNetCore.Razor.Test.Common.Workspaces;
11-
using Microsoft.CodeAnalysis.ExternalAccess.Razor.Features;
1211
using Microsoft.CodeAnalysis.Razor.Formatting;
1312
using Microsoft.CodeAnalysis.Razor.Logging;
1413
using Microsoft.CodeAnalysis.Razor.Workspaces;
@@ -23,8 +22,7 @@ public static async Task<IRazorFormattingService> CreateWithFullSupportAsync(
2322
RazorCodeDocument? codeDocument = null,
2423
RazorLSPOptions? razorLSPOptions = null,
2524
LanguageServerFeatureOptions? languageServerFeatureOptions = null,
26-
bool debugAssertsEnabled = false,
27-
RazorCSharpSyntaxFormattingOptions? formattingOptionsOverride = null)
25+
bool debugAssertsEnabled = false)
2826
{
2927
codeDocument ??= TestRazorCodeDocument.CreateEmpty();
3028

@@ -50,7 +48,6 @@ public static async Task<IRazorFormattingService> CreateWithFullSupportAsync(
5048
var service = new RazorFormattingService(mappingService, hostServicesProvider, languageServerFeatureOptions, loggerFactory);
5149
var accessor = service.GetTestAccessor();
5250
accessor.SetDebugAssertsEnabled(debugAssertsEnabled);
53-
accessor.SetCSharpSyntaxFormattingOptionsOverride(formattingOptionsOverride);
5451

5552
return service;
5653
}

0 commit comments

Comments
 (0)