Skip to content

Commit 17d38d5

Browse files
committed
Add unit tests
1 parent 2dfb12f commit 17d38d5

File tree

2 files changed

+47
-0
lines changed

2 files changed

+47
-0
lines changed

packages/docusaurus-theme-common/src/utils/__tests__/__snapshots__/codeBlockUtils.test.ts.snap

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,30 @@ bbbbb",
7070
}
7171
`;
7272

73+
exports[`parseLines handles CRLF line breaks with highlight comments correctly 1`] = `
74+
{
75+
"code": "aaaaa
76+
bbbbb",
77+
"lineClassNames": {
78+
"1": [
79+
"theme-code-block-highlighted-line",
80+
],
81+
},
82+
}
83+
`;
84+
85+
exports[`parseLines handles CRLF line breaks with highlight metastring 1`] = `
86+
{
87+
"code": "aaaaa
88+
bbbbb",
89+
"lineClassNames": {
90+
"1": [
91+
"theme-code-block-highlighted-line",
92+
],
93+
},
94+
}
95+
`;
96+
7397
exports[`parseLines handles one line with multiple class names 1`] = `
7498
{
7599
"code": "

packages/docusaurus-theme-common/src/utils/__tests__/codeBlockUtils.test.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -360,6 +360,29 @@ line
360360
),
361361
).toMatchSnapshot();
362362
});
363+
364+
it('handles CRLF line breaks with highlight comments correctly', () => {
365+
expect(
366+
parseLines(
367+
`aaaaa\r\n// highlight-start\r\nbbbbb\r\n// highlight-end\r\n`,
368+
{
369+
metastring: '',
370+
language: 'js',
371+
magicComments: defaultMagicComments,
372+
},
373+
),
374+
).toMatchSnapshot();
375+
});
376+
377+
it('handles CRLF line breaks with highlight metastring', () => {
378+
expect(
379+
parseLines(`aaaaa\r\nbbbbb\r\n`, {
380+
metastring: '{2}',
381+
language: 'js',
382+
magicComments: defaultMagicComments,
383+
}),
384+
).toMatchSnapshot();
385+
});
363386
});
364387

365388
describe('getLineNumbersStart', () => {

0 commit comments

Comments
 (0)