Skip to content

Commit

Permalink
Replace escaped line endings in snapshot test
Browse files Browse the repository at this point in the history
  • Loading branch information
sveinungf committed Feb 18, 2024
1 parent 21fb049 commit e075615
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ private static PortableExecutableReference[] GetAssemblyReferences()
];
}

public static SettingsTask CompileAndVerify<T>(string source, bool replaceLineEndings = false, params object?[] parameters) where T : IIncrementalGenerator, new()
public static SettingsTask CompileAndVerify<T>(string source, bool replaceEscapedLineEndings = false, params object?[] parameters) where T : IIncrementalGenerator, new()
{
var syntaxTree = CSharpSyntaxTree.ParseText(source);
var references = GetAssemblyReferences();
Expand All @@ -41,8 +41,8 @@ private static PortableExecutableReference[] GetAssemblyReferences()
var settings = new VerifySettings();
settings.UseDirectory("../Snapshots");

if (replaceLineEndings)
settings.ScrubLinesWithReplace(x => x.Replace("\r\n", "\n", StringComparison.Ordinal));
if (replaceEscapedLineEndings)
settings.ScrubLinesWithReplace(x => x.Replace("\\r\\n", "\\n", StringComparison.Ordinal));

var task = Verify(target, settings);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//HintName: MyNamespace.MyGenRowContext.g.cs
//HintName: MyNamespace.MyGenRowContext.g.cs
// <auto-generated />
#nullable enable
using SpreadCheetah;
Expand Down Expand Up @@ -32,7 +32,7 @@ private static async ValueTask AddHeaderRow0Async(SpreadCheetah.Spreadsheet spre
cells[0] = new StyledCell("First name", styleId);
cells[1] = new StyledCell("", styleId);
cells[2] = new StyledCell("Nationality (escaped characters \", ', \\)", styleId);
cells[3] = new StyledCell("Address line 1 (escaped characters \r\n, \t)", styleId);
cells[3] = new StyledCell("Address line 1 (escaped characters \n, \t)", styleId);
cells[4] = new StyledCell("Address line 2 (verbatim\nstring: \", \\)", styleId);
cells[5] = new StyledCell(" Age (\n raw\n string\n literal\n )", styleId);
cells[6] = new StyledCell("Note (unicode escape sequence 🌉, 👍, ç)", styleId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,6 @@ public partial class MyGenRowContext : WorksheetRowContext;
""";

// Act & Assert
return TestHelper.CompileAndVerify<WorksheetRowGenerator>(source, replaceLineEndings: true);
return TestHelper.CompileAndVerify<WorksheetRowGenerator>(source, replaceEscapedLineEndings: true);
}
}

0 comments on commit e075615

Please sign in to comment.