diff --git a/Frontmatter.Test/LineEndingTests.cs b/Frontmatter.Test/LineEndingTests.cs
new file mode 100644
index 0000000..8f6f77c
--- /dev/null
+++ b/Frontmatter.Test/LineEndingTests.cs
@@ -0,0 +1,86 @@
+// Copyright (c) 2023-2026 ktsu-dev contributors
+
+namespace ktsu.Frontmatter.Test;
+
+using Microsoft.VisualStudio.TestTools.UnitTesting;
+
+///
+/// Tests that every writer emits the input document's line ending, whatever the host's is.
+///
+[TestClass]
+public class LineEndingTests
+{
+ private static string Lines(string newLine, params string[] lines) => string.Join(newLine, lines) + newLine;
+
+ private static void AssertOnlyLineEnding(string newLine, string text)
+ {
+ string withoutLineEndings = text.Replace(newLine, string.Empty, StringComparison.Ordinal);
+ Assert.DoesNotContain("\r", withoutLineEndings);
+ Assert.DoesNotContain("\n", withoutLineEndings);
+ }
+
+ [TestMethod]
+ [DataRow("\r\n", DisplayName = "CRLF")]
+ [DataRow("\n", DisplayName = "LF")]
+ public void CombineFrontmatter_KeepsTheInputLineEnding(string nl)
+ {
+ string input = Lines(nl, "---", "title: A", "---", "---", "author: B", "---", "line1", "line2");
+
+ string result = Frontmatter.CombineFrontmatter(input, FrontmatterNaming.AsIs, FrontmatterOrder.AsIs, FrontmatterMergeStrategy.None);
+
+ Assert.AreEqual(Lines(nl, "---", "title: A", "author: B", "---", "line1", "line2"), result);
+ AssertOnlyLineEnding(nl, result);
+ }
+
+ [TestMethod]
+ [DataRow("\r\n", DisplayName = "CRLF")]
+ [DataRow("\n", DisplayName = "LF")]
+ public void AddFrontmatter_DocumentWithoutHeader_KeepsTheInputLineEnding(string nl)
+ {
+ string input = Lines(nl, "line1", "line2");
+
+ string result = Frontmatter.AddFrontmatter(input, new Dictionary { ["title"] = "T", ["author"] = "B" });
+
+ Assert.AreEqual(Lines(nl, "---", "title: T", "author: B", "---", "line1", "line2"), result);
+ AssertOnlyLineEnding(nl, result);
+ }
+
+ [TestMethod]
+ [DataRow("\r\n", DisplayName = "CRLF")]
+ [DataRow("\n", DisplayName = "LF")]
+ public void AddFrontmatter_DocumentWithHeader_KeepsTheInputLineEnding(string nl)
+ {
+ string input = Lines(nl, "---", "title: A", "---", "line1", "line2");
+
+ string result = Frontmatter.AddFrontmatter(input, new Dictionary { ["author"] = "B" });
+
+ Assert.AreEqual(Lines(nl, "---", "title: A", "author: B", "---", "line1", "line2"), result);
+ AssertOnlyLineEnding(nl, result);
+ }
+
+ [TestMethod]
+ [DataRow("\r\n", DisplayName = "CRLF")]
+ [DataRow("\n", DisplayName = "LF")]
+ public void ReplaceFrontmatter_KeepsTheInputLineEnding(string nl)
+ {
+ string input = Lines(nl, "---", "title: A", "---", "line1", "line2");
+
+ string result = Frontmatter.ReplaceFrontmatter(input, new Dictionary { ["title"] = "B", ["tags"] = new List