Skip to content

Commit

Permalink
add FileLinePositionSpanConverter (#278)
Browse files Browse the repository at this point in the history
  • Loading branch information
SimonCropp authored Aug 27, 2024
1 parent 903d33b commit 4633420
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/Tests/Tests.FileLinePositionSpanConverter.verified.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
the path: (1,2)-(2,4)
4 changes: 4 additions & 0 deletions src/Tests/Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ public Task SourceTextConverter() =>
public Task LocalizableStringConverter() =>
Verify(new LocalizableStringImp());

[Fact]
public Task FileLinePositionSpanConverter() =>
Verify(new FileLinePositionSpan("the path", new(1,2), new(2,4)));

class LocalizableStringImp :
LocalizableString
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
using Microsoft.CodeAnalysis;

class FileLinePositionSpanConverter :
WriteOnlyJsonConverter<FileLinePositionSpan>
{
public override void Write(VerifyJsonWriter writer, FileLinePositionSpan value) =>
writer.WriteValue(value.ToString());
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ class LocationConverter :
WriteOnlyJsonConverter<Location>
{
public override void Write(VerifyJsonWriter writer, Location value) =>
writer.WriteValue(value.GetMappedLineSpan().ToString());
writer.WriteValue(value.GetMappedLineSpan());
}
1 change: 1 addition & 0 deletions src/Verify.SourceGenerators/VerifySourceGenerators.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public static void Initialize()
converters.Add(new LocalizableStringConverter());
converters.Add(new DiagnosticConverter());
converters.Add(new LocationConverter());
converters.Add(new FileLinePositionSpanConverter());
converters.Add(new GeneratedSourceResultConverter());
converters.Add(new DiagnosticDescriptorConverter());
converters.Add(new SourceTextConverter());
Expand Down

0 comments on commit 4633420

Please sign in to comment.