|
6 | 6 |
|
7 | 7 | import { unitTest } from "../../../test.ts"; |
8 | 8 | import { assertEquals } from "testing/asserts"; |
9 | | -import { getEndingNewlineCount } from "../../../../src/core/lib/text.ts"; |
| 9 | +import { getEndingNewlineCount, lines } from "../../../../src/core/lib/text.ts"; |
10 | 10 |
|
11 | 11 | unitTest("core/lib/text.ts - getEndingNewlineCount", async () => { |
12 | 12 | // Test case 1: No trailing newlines |
@@ -64,3 +64,34 @@ unitTest("core/lib/text.ts - getEndingNewlineCount", async () => { |
64 | 64 | 3, |
65 | 65 | ); |
66 | 66 | }); |
| 67 | + |
| 68 | +// Test for lines() function with different line endings |
| 69 | +// See: https://github.com/quarto-dev/quarto-cli/issues/13998 |
| 70 | +unitTest("core/lib/text.ts - lines() with different line endings", async () => { |
| 71 | + // LF (Unix/Linux) |
| 72 | + assertEquals(lines("a\nb\nc"), ["a", "b", "c"]); |
| 73 | + |
| 74 | + // CRLF (Windows) |
| 75 | + assertEquals(lines("a\r\nb\r\nc"), ["a", "b", "c"]); |
| 76 | + |
| 77 | + // CR-only (old Mac) - the fix for #13998 |
| 78 | + assertEquals(lines("a\rb\rc"), ["a", "b", "c"]); |
| 79 | + |
| 80 | + // Mixed endings |
| 81 | + assertEquals(lines("a\rb\nc\r\nd"), ["a", "b", "c", "d"]); |
| 82 | + |
| 83 | + // YAML front matter with CR-only |
| 84 | + const yaml = "---\rtitle: \"Test\"\r---"; |
| 85 | + assertEquals(lines(yaml), ["---", "title: \"Test\"", "---"]); |
| 86 | + |
| 87 | + // Empty string |
| 88 | + assertEquals(lines(""), [""]); |
| 89 | + |
| 90 | + // Single line without newline |
| 91 | + assertEquals(lines("single"), ["single"]); |
| 92 | + |
| 93 | + // Trailing newlines |
| 94 | + assertEquals(lines("a\n"), ["a", ""]); |
| 95 | + assertEquals(lines("a\r"), ["a", ""]); |
| 96 | + assertEquals(lines("a\r\n"), ["a", ""]); |
| 97 | +}); |
0 commit comments