Skip to content

Commit b7e598f

Browse files
committed
test(theme-common): Extend tests for new parsing
1 parent 56c3cbc commit b7e598f

File tree

2 files changed

+156
-2
lines changed

2 files changed

+156
-2
lines changed

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

+80
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,86 @@ exports[`getLineNumbersStart with parsed metaoption with nothing set 1`] = `unde
6464

6565
exports[`getLineNumbersStart with parsed metaoption with nothing set 2`] = `undefined`;
6666

67+
exports[`parseCodeBlockMetaOptions any option double quotes as string 1`] = `
68+
{
69+
"PascalCase": "Hello'Docusaurus Options",
70+
"UPPER_CASE": "Hello'Docusaurus Options",
71+
"camelCase": "Hello'Docusaurus Options",
72+
"kebab-case": "Hello'Docusaurus Options",
73+
"lowercase": "Hello'Docusaurus Options",
74+
}
75+
`;
76+
77+
exports[`parseCodeBlockMetaOptions any option false 1`] = `
78+
{
79+
"PascalCase": false,
80+
"UPPER_CASE": false,
81+
"camelCase": false,
82+
"kebab-case": false,
83+
"lowercase": false,
84+
}
85+
`;
86+
87+
exports[`parseCodeBlockMetaOptions any option flag as true 1`] = `
88+
{
89+
"PascalCase": true,
90+
"UPPER_CASE": true,
91+
"camelCase": true,
92+
"kebab-case": true,
93+
"lowercase": true,
94+
}
95+
`;
96+
97+
exports[`parseCodeBlockMetaOptions any option float numbers 1`] = `
98+
{
99+
"PascalCase": 3.3,
100+
"UPPER_CASE": 4.4,
101+
"camelCase": 2.2,
102+
"kebab-case": 5.5,
103+
"lowercase": 1.1,
104+
}
105+
`;
106+
107+
exports[`parseCodeBlockMetaOptions any option integer numbers 1`] = `
108+
{
109+
"PascalCase": 3,
110+
"UPPER_CASE": 4,
111+
"camelCase": 2,
112+
"kebab-case": 5,
113+
"lowercase": 1,
114+
}
115+
`;
116+
117+
exports[`parseCodeBlockMetaOptions any option non quoted value as string 1`] = `
118+
{
119+
"PascalCase": "simple",
120+
"UPPER_CASE": "simple",
121+
"camelCase": "simple",
122+
"kebab-case": "simple",
123+
"lowercase": "simple",
124+
}
125+
`;
126+
127+
exports[`parseCodeBlockMetaOptions any option single quotes as string 1`] = `
128+
{
129+
"PascalCase": "Hello"Docusaurus Options",
130+
"UPPER_CASE": "Hello"Docusaurus Options",
131+
"camelCase": "Hello"Docusaurus Options",
132+
"kebab-case": "Hello"Docusaurus Options",
133+
"lowercase": "Hello"Docusaurus Options",
134+
}
135+
`;
136+
137+
exports[`parseCodeBlockMetaOptions any option true 1`] = `
138+
{
139+
"PascalCase": true,
140+
"UPPER_CASE": true,
141+
"camelCase": true,
142+
"kebab-case": true,
143+
"lowercase": true,
144+
}
145+
`;
146+
67147
exports[`parseLines does not parse content with metastring 1`] = `
68148
{
69149
"code": "aaaaa

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

+76-2
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,10 @@ describe('parseCodeBlockMetaOptions', () => {
3636
).toBe(`index.js`);
3737
});
3838

39-
it('does not parse mismatched quote delimiters', () => {
39+
it('parses mismatched quote delimiters as literal', () => {
4040
expect(
4141
parseCodeBlockMetaOptions(`title="index.js'`, undefined).title,
42-
).toBeUndefined();
42+
).toBe(`"index.js'`);
4343
});
4444

4545
it('parses undefined metastring', () => {
@@ -116,6 +116,80 @@ describe('parseCodeBlockMetaOptions', () => {
116116
).toBeUndefined();
117117
});
118118
});
119+
120+
describe('any option', () => {
121+
it('flag as true', () => {
122+
expect(
123+
parseCodeBlockMetaOptions(
124+
`lowercase camelCase PascalCase UPPER_CASE kebab-case`,
125+
undefined,
126+
),
127+
).toMatchSnapshot();
128+
});
129+
130+
it('single quotes as string', () => {
131+
expect(
132+
parseCodeBlockMetaOptions(
133+
`lowercase='Hello"Docusaurus Options' camelCase='Hello"Docusaurus Options' PascalCase='Hello"Docusaurus Options' UPPER_CASE='Hello"Docusaurus Options' kebab-case='Hello"Docusaurus Options'`,
134+
undefined,
135+
),
136+
).toMatchSnapshot();
137+
});
138+
139+
it('double quotes as string', () => {
140+
expect(
141+
parseCodeBlockMetaOptions(
142+
`lowercase="Hello'Docusaurus Options" camelCase="Hello'Docusaurus Options" PascalCase="Hello'Docusaurus Options" UPPER_CASE="Hello'Docusaurus Options" kebab-case="Hello'Docusaurus Options"`,
143+
undefined,
144+
),
145+
).toMatchSnapshot();
146+
});
147+
148+
it('true', () => {
149+
expect(
150+
parseCodeBlockMetaOptions(
151+
`lowercase=true camelCase=true PascalCase=true UPPER_CASE=true kebab-case=true`,
152+
undefined,
153+
),
154+
).toMatchSnapshot();
155+
});
156+
157+
it('false', () => {
158+
expect(
159+
parseCodeBlockMetaOptions(
160+
`lowercase=false camelCase=false PascalCase=false UPPER_CASE=false kebab-case=false`,
161+
undefined,
162+
),
163+
).toMatchSnapshot();
164+
});
165+
166+
it('integer numbers', () => {
167+
expect(
168+
parseCodeBlockMetaOptions(
169+
`lowercase=1 camelCase=2 PascalCase=3 UPPER_CASE=4 kebab-case=5`,
170+
undefined,
171+
),
172+
).toMatchSnapshot();
173+
});
174+
175+
it('float numbers', () => {
176+
expect(
177+
parseCodeBlockMetaOptions(
178+
`lowercase=1.1 camelCase=2.2 PascalCase=3.3 UPPER_CASE=4.4 kebab-case=5.5`,
179+
undefined,
180+
),
181+
).toMatchSnapshot();
182+
});
183+
184+
it('non quoted value as string', () => {
185+
expect(
186+
parseCodeBlockMetaOptions(
187+
`lowercase=simple camelCase=simple PascalCase=simple UPPER_CASE=simple kebab-case=simple`,
188+
undefined,
189+
),
190+
).toMatchSnapshot();
191+
});
192+
});
119193
});
120194

121195
describe('parseLanguage', () => {

0 commit comments

Comments
 (0)