Preserve whitespace trivia when applying code fix

This commit is contained in:
Patrik Svensson
2021-06-23 23:42:05 +02:00
committed by Phil Scott
parent 6b5b31957c
commit a186fd94ac
2 changed files with 43 additions and 2 deletions

View File

@ -47,6 +47,46 @@ class TestClass
.ConfigureAwait(false);
}
[Fact]
public async Task Static_call_replaced_with_field_call_Should_Preserve_Trivia()
{
const string Source = @"
using Spectre.Console;
class TestClass
{
IAnsiConsole _ansiConsole = AnsiConsole.Console;
void TestMethod()
{
var foo = 1;
AnsiConsole.Write(""this is fine"");
_ansiConsole.Write(""Hello, World"");
}
}";
const string FixedSource = @"
using Spectre.Console;
class TestClass
{
IAnsiConsole _ansiConsole = AnsiConsole.Console;
void TestMethod()
{
var foo = 1;
_ansiConsole.Write(""this is fine"");
_ansiConsole.Write(""Hello, World"");
}
}";
await SpectreAnalyzerVerifier<FavorInstanceAnsiConsoleOverStaticAnalyzer>
.VerifyCodeFixAsync(Source, _expectedDiagnostic.WithLocation(12, 9), FixedSource)
.ConfigureAwait(false);
}
[Fact]
public async Task Static_call_replaced_with_parameter_call()
{