Skip to content

Commit bc90bbc

Browse files
committed
Use real types in the formatting log tests
1 parent 02e693d commit bc90bbc

File tree

1 file changed

+4
-68
lines changed
  • src/Razor/test/Microsoft.VisualStudio.LanguageServices.Razor.Test/Cohost/Formatting

1 file changed

+4
-68
lines changed

src/Razor/test/Microsoft.VisualStudio.LanguageServices.Razor.Test/Cohost/Formatting/FormattingLogTest.cs

Lines changed: 4 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33

44
using System.Linq;
55
using System.Runtime.CompilerServices;
6-
using System.Runtime.Serialization;
76
using System.Text.Json;
87
using System.Threading.Tasks;
98
using Microsoft.AspNetCore.Razor;
@@ -35,7 +34,7 @@ public async Task UnexpectedFalseInIndentBlockOperation()
3534
var document = CreateProjectAndRazorDocument(contents);
3635

3736
var optionsFile = GetResource("Options.json");
38-
var options = (TempRazorFormattingOptions)JsonSerializer.Deserialize(optionsFile, typeof(TempRazorFormattingOptions), JsonHelpers.JsonSerializerOptions).AssumeNotNull();
37+
var options = (RazorFormattingOptions)JsonSerializer.Deserialize(optionsFile, typeof(RazorFormattingOptions), JsonHelpers.JsonSerializerOptions).AssumeNotNull();
3938

4039
var formattingService = (RazorFormattingService)OOPExportProvider.GetExportedValue<IRazorFormattingService>();
4140
formattingService.GetTestAccessor().SetFormattingLoggerFactory(new TestFormattingLoggerFactory(TestOutputHelper));
@@ -45,7 +44,7 @@ public async Task UnexpectedFalseInIndentBlockOperation()
4544
var sourceText = await document.GetTextAsync();
4645
var htmlEdits = htmlChanges.Select(c => sourceText.GetTextEdit(c.ToTextChange())).ToArray();
4746

48-
await GetFormattingEditsAsync(document, htmlEdits, span: default, options.CodeBlockBraceOnNextLine, options.InsertSpaces, options.TabSize, options.ToRazorFormattingOptions().CSharpSyntaxFormattingOptions.AssumeNotNull());
47+
await GetFormattingEditsAsync(document, htmlEdits, span: default, options.CodeBlockBraceOnNextLine, options.InsertSpaces, options.TabSize, options.CSharpSyntaxFormattingOptions.AssumeNotNull());
4948
}
5049

5150
[Fact]
@@ -72,7 +71,7 @@ private async Task VerifyMixedIndentationAsync(string contents, string htmlChang
7271
{
7372
var document = CreateProjectAndRazorDocument(contents);
7473

75-
var options = new TempRazorFormattingOptions();
74+
var options = new RazorFormattingOptions();
7675

7776
var formattingService = (RazorFormattingService)OOPExportProvider.GetExportedValue<IRazorFormattingService>();
7877
formattingService.GetTestAccessor().SetFormattingLoggerFactory(new TestFormattingLoggerFactory(TestOutputHelper));
@@ -81,7 +80,7 @@ private async Task VerifyMixedIndentationAsync(string contents, string htmlChang
8180
var sourceText = await document.GetTextAsync();
8281
var htmlEdits = htmlChanges.Select(c => sourceText.GetTextEdit(c.ToTextChange())).ToArray();
8382

84-
await GetFormattingEditsAsync(document, htmlEdits, span: default, options.CodeBlockBraceOnNextLine, options.InsertSpaces, options.TabSize, options.ToRazorFormattingOptions().CSharpSyntaxFormattingOptions.AssumeNotNull());
83+
await GetFormattingEditsAsync(document, htmlEdits, span: default, options.CodeBlockBraceOnNextLine, options.InsertSpaces, options.TabSize, RazorCSharpSyntaxFormattingOptions.Default);
8584
}
8685

8786
private string GetResource(string name, [CallerMemberName] string? testName = null)
@@ -93,67 +92,4 @@ private string GetResource(string name, [CallerMemberName] string? testName = nu
9392

9493
return testFile.ReadAllText();
9594
}
96-
97-
// HACK: Temporary types for deserializing because RazorCSharpSyntaxFormattingOptions doesn't have a parameterless constructor.
98-
internal class TempRazorFormattingOptions()
99-
{
100-
[DataMember(Order = 0)]
101-
public bool InsertSpaces { get; init; } = true;
102-
[DataMember(Order = 1)]
103-
public int TabSize { get; init; } = 4;
104-
[DataMember(Order = 2)]
105-
public bool CodeBlockBraceOnNextLine { get; init; } = false;
106-
[DataMember(Order = 3)]
107-
public TempRazorCSharpSyntaxFormattingOptions? CSharpSyntaxFormattingOptions { get; init; }
108-
109-
public RazorFormattingOptions ToRazorFormattingOptions()
110-
=> new()
111-
{
112-
InsertSpaces = InsertSpaces,
113-
TabSize = TabSize,
114-
CodeBlockBraceOnNextLine = CodeBlockBraceOnNextLine,
115-
CSharpSyntaxFormattingOptions = CSharpSyntaxFormattingOptions is not null
116-
? new RazorCSharpSyntaxFormattingOptions(
117-
CSharpSyntaxFormattingOptions.Spacing,
118-
CSharpSyntaxFormattingOptions.SpacingAroundBinaryOperator,
119-
CSharpSyntaxFormattingOptions.NewLines,
120-
CSharpSyntaxFormattingOptions.LabelPositioning,
121-
CSharpSyntaxFormattingOptions.Indentation,
122-
CSharpSyntaxFormattingOptions.WrappingKeepStatementsOnSingleLine,
123-
CSharpSyntaxFormattingOptions.WrappingPreserveSingleLine,
124-
CSharpSyntaxFormattingOptions.NamespaceDeclarations,
125-
CSharpSyntaxFormattingOptions.PreferTopLevelStatements,
126-
CSharpSyntaxFormattingOptions.CollectionExpressionWrappingLength)
127-
: RazorCSharpSyntaxFormattingOptions.Default
128-
};
129-
}
130-
131-
[DataContract]
132-
internal sealed record class TempRazorCSharpSyntaxFormattingOptions(
133-
[property: DataMember] RazorSpacePlacement Spacing,
134-
[property: DataMember] RazorBinaryOperatorSpacingOptions SpacingAroundBinaryOperator,
135-
[property: DataMember] RazorNewLinePlacement NewLines,
136-
[property: DataMember] RazorLabelPositionOptions LabelPositioning,
137-
[property: DataMember] RazorIndentationPlacement Indentation,
138-
[property: DataMember] bool WrappingKeepStatementsOnSingleLine,
139-
[property: DataMember] bool WrappingPreserveSingleLine,
140-
[property: DataMember] RazorNamespaceDeclarationPreference NamespaceDeclarations,
141-
[property: DataMember] bool PreferTopLevelStatements,
142-
[property: DataMember] int CollectionExpressionWrappingLength)
143-
{
144-
public TempRazorCSharpSyntaxFormattingOptions()
145-
: this(
146-
default,
147-
default,
148-
default,
149-
default,
150-
default,
151-
default,
152-
default,
153-
default,
154-
true,
155-
default)
156-
{
157-
}
158-
}
15995
}

0 commit comments

Comments
 (0)