Skip to content

Commit 78ce9f5

Browse files
author
Alessio Michelini
committed
test: add unit test for handling mixed line endings in MarkdownParser
1 parent 785ff7f commit 78ce9f5

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

test/line-endings.test.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import { MarkdownParser } from '../src/classes/markdown';
2+
import { promises as fs } from 'fs';
3+
import * as path from 'path';
4+
import { fileURLToPath } from 'url';
5+
6+
const __filename = fileURLToPath(import.meta.url);
7+
const __dirname = path.dirname(__filename);
8+
9+
describe('Line Endings', () => {
10+
const mixedLineEndingsContent = '# Test\n\n## Heading 1\r\n### Heading 2\r';
11+
const expectedLinks = [
12+
'- [Heading 1](#heading-1)',
13+
' - [Heading 2](#heading-2)',
14+
];
15+
16+
it('should handle mixed line endings', async () => {
17+
const tempDir = await fs.mkdtemp(path.join(__dirname, 'temp-'));
18+
const tempFile = path.join(tempDir, 'test.md');
19+
await fs.writeFile(tempFile, mixedLineEndingsContent);
20+
const parser = new MarkdownParser(tempFile);
21+
const links = await parser.parse();
22+
expect(links).toEqual(expectedLinks);
23+
await fs.rm(tempDir, { recursive: true, force: true });
24+
});
25+
});

0 commit comments

Comments
 (0)