Fixed mixed line breaks in saved code files and tests failing on Windows (#1149)

This commit is contained in:
Paul Koudelka authored and GitHub committed 2026-11-03 14:43:26 +01:00
1 parent 770c16e20a
commit f864359290
4 files changed
+39 -4

No files matched your search

@@ -117,7 +117,8 @@ public sealed class SwotCategoryAnalysisResponseTests
public void TheSystemPromptAssignsExactlyOneCategory(string categoryName, string expectedDescription)
{
var category = Enum.Parse<SwotAnalysisCategory>(categoryName);
var prompt = SwotCategoryAnalysis.BuildSystemPrompt(category, "Answer in German.");
// The prompt takes the line breaks of its source file, which depend on the checkout:
var prompt = SwotCategoryAnalysis.BuildSystemPrompt(category, "Answer in German.").ReplaceLineEndings("\n");
using (Assert.EnterMultipleScope())
{
+29
View File
@@ -251,6 +251,35 @@ public sealed class IContentExtensionsTests
Assert.That(TextWith(string.Empty).ToExportContent(file), Is.EqualTo("print(42)\n"));
}
[TestCase("import sys\r\nprint(sys.argv)")]
[TestCase("import sys\r\nprint(sys.argv)\r\n")]
[TestCase("import sys\rprint(sys.argv)")]
public void CodeNeverMixesLineEndings(string code)
{
var file = new MessageFile(1, Position: 0, string.Empty, FileExportFormat.SOURCE_CODE, SourceCodeLanguages.FromCodeFenceLanguage("python"), code);
Assert.That(TextWith(string.Empty).ToExportContent(file), Is.EqualTo("import sys\nprint(sys.argv)\n"), "Every line ends with LF, whatever line breaks the code came with.");
}
[TestCase("@echo off\necho done")]
[TestCase("@echo off\r\necho done\r\n")]
[TestCase("@echo off\recho done")]
public void ABatchFileNeverMixesLineEndings(string code)
{
var file = new MessageFile(1, Position: 0, string.Empty, FileExportFormat.SOURCE_CODE, SourceCodeLanguages.FromCodeFenceLanguage("bat"), code);
Assert.That(TextWith(string.Empty).ToExportContent(file), Is.EqualTo("@echo off\r\necho done\r\n"), "Every line ends with CR LF, whatever line breaks the code came with.");
}
[TestCase("python", "print('a\fb\u2028c')", "print('a\fb\u2028c')\n")]
[TestCase("bat", "echo a\fb\u2028c", "echo a\fb\u2028c\r\n")]
public void AFormFeedOrALineSeparatorStaysInItsLine(string language, string code, string expected)
{
var file = new MessageFile(1, Position: 0, string.Empty, FileExportFormat.SOURCE_CODE, SourceCodeLanguages.FromCodeFenceLanguage(language), code);
Assert.That(TextWith(string.Empty).ToExportContent(file), Is.EqualTo(expected), "Markdown breaks lines only at LF and CR, and so does the file.");
}
[Test]
public void ABatchFileEndsItsLinesTheWindowsWay()
{