Skip to content

Commit 85b9676

Browse files
committed
test(theme-common): Add tests for getLineNumbersStart
1 parent abeae04 commit 85b9676

File tree

2 files changed

+142
-0
lines changed

2 files changed

+142
-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
@@ -1,5 +1,29 @@
11
// Jest Snapshot v1, https://goo.gl/fbAQLP
22

3+
exports[`getLineNumbersStart handles metadata combined with other options set as flag 1`] = `1`;
4+
5+
exports[`getLineNumbersStart handles metadata combined with other options set with number 1`] = `10`;
6+
7+
exports[`getLineNumbersStart handles metadata standalone set as flag 1`] = `1`;
8+
9+
exports[`getLineNumbersStart handles metadata standalone set with number 1`] = `10`;
10+
11+
exports[`getLineNumbersStart handles prop combined with metastring combined with metastring set to false 1`] = `undefined`;
12+
13+
exports[`getLineNumbersStart handles prop combined with metastring combined with metastring set to number 1`] = `10`;
14+
15+
exports[`getLineNumbersStart handles prop combined with metastring combined with metastring set to true 1`] = `1`;
16+
17+
exports[`getLineNumbersStart handles prop combined with metastring standalone set to false 1`] = `undefined`;
18+
19+
exports[`getLineNumbersStart handles prop combined with metastring standalone set to number 1`] = `10`;
20+
21+
exports[`getLineNumbersStart handles prop combined with metastring standalone set to true 1`] = `1`;
22+
23+
exports[`getLineNumbersStart with nothing set 1`] = `undefined`;
24+
25+
exports[`getLineNumbersStart with nothing set 2`] = `undefined`;
26+
327
exports[`parseLines does not parse content with metastring 1`] = `
428
{
529
"code": "aaaaa

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

Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
*/
77

88
import {
9+
getLineNumbersStart,
910
type MagicCommentConfig,
1011
parseCodeBlockTitle,
1112
parseLanguage,
@@ -360,3 +361,120 @@ line
360361
).toMatchSnapshot();
361362
});
362363
});
364+
365+
describe('getLineNumbersStart', () => {
366+
it('with nothing set', () => {
367+
expect(
368+
getLineNumbersStart({
369+
showLineNumbers: undefined,
370+
metastring: undefined,
371+
}),
372+
).toMatchSnapshot();
373+
expect(
374+
getLineNumbersStart({
375+
showLineNumbers: undefined,
376+
metastring: '',
377+
}),
378+
).toMatchSnapshot();
379+
});
380+
381+
describe('handles prop combined with metastring', () => {
382+
describe('combined with metastring', () => {
383+
it('set to true', () => {
384+
expect(
385+
getLineNumbersStart({
386+
showLineNumbers: true,
387+
metastring: 'showLineNumbers=2',
388+
}),
389+
).toMatchSnapshot();
390+
});
391+
392+
it('set to false', () => {
393+
expect(
394+
getLineNumbersStart({
395+
showLineNumbers: false,
396+
metastring: 'showLineNumbers=2',
397+
}),
398+
).toMatchSnapshot();
399+
});
400+
401+
it('set to number', () => {
402+
expect(
403+
getLineNumbersStart({
404+
showLineNumbers: 10,
405+
metastring: 'showLineNumbers=2',
406+
}),
407+
).toMatchSnapshot();
408+
});
409+
});
410+
411+
describe('standalone', () => {
412+
it('set to true', () => {
413+
expect(
414+
getLineNumbersStart({
415+
showLineNumbers: true,
416+
metastring: undefined,
417+
}),
418+
).toMatchSnapshot();
419+
});
420+
421+
it('set to false', () => {
422+
expect(
423+
getLineNumbersStart({
424+
showLineNumbers: false,
425+
metastring: undefined,
426+
}),
427+
).toMatchSnapshot();
428+
});
429+
430+
it('set to number', () => {
431+
expect(
432+
getLineNumbersStart({
433+
showLineNumbers: 10,
434+
metastring: undefined,
435+
}),
436+
).toMatchSnapshot();
437+
});
438+
});
439+
});
440+
441+
describe('handles metadata', () => {
442+
describe('standalone', () => {
443+
it('set as flag', () => {
444+
expect(
445+
getLineNumbersStart({
446+
showLineNumbers: undefined,
447+
metastring: 'showLineNumbers',
448+
}),
449+
).toMatchSnapshot();
450+
});
451+
it('set with number', () => {
452+
expect(
453+
getLineNumbersStart({
454+
showLineNumbers: undefined,
455+
metastring: 'showLineNumbers=10',
456+
}),
457+
).toMatchSnapshot();
458+
});
459+
});
460+
461+
describe('combined with other options', () => {
462+
it('set as flag', () => {
463+
expect(
464+
getLineNumbersStart({
465+
showLineNumbers: undefined,
466+
metastring: '{1,2-3} title="file.txt" showLineNumbers noInline',
467+
}),
468+
).toMatchSnapshot();
469+
});
470+
it('set with number', () => {
471+
expect(
472+
getLineNumbersStart({
473+
showLineNumbers: undefined,
474+
metastring: '{1,2-3} title="file.txt" showLineNumbers=10 noInline',
475+
}),
476+
).toMatchSnapshot();
477+
});
478+
});
479+
});
480+
});

0 commit comments

Comments
 (0)