import { describe, it, expect } from 'vitest'; import { parseProblemPage } from './problem-page'; const MOCK_PROBLEM_HTML = `
Time Limit: 2 sec / Memory Limit: 1024 MB
1 2 3
6
10 20 30
60
1 2 3
6
Given $N$ integers $A_1, A_2, \\dots, A_N$.
Find $$ \\sum_{i=1}^N A_i $$.
Constraints: $1 \\le N \\le 100$ and $A_i \\le 1000$ with some _underscores_ outside and grid cell # symbols.
Given \\(T_i\\) for all \\(i\\).
Find \\[ \\sum_{i=1}^N T_i \\].
Constraints: \\(1 \\le N,Q \\le 1000\\).
Let N be the number of elements.
Constraints:
blocks containing math or var tags as LaTeX array block', () => {
const htmlWithPre = `
Input
N M
A_1 A_2 ... A_N
:
query_Q
`;
// Add tag to trigger math conversion
const htmlWithPreVar = htmlWithPre.replace('N M', 'N M');
const details = parseProblemPage(htmlWithPreVar);
expect(details.problemStatementMd).toContain('\\begin{array}{l}');
expect(details.problemStatementMd).toContain('N\\ M');
expect(details.problemStatementMd).toContain('A_1');
expect(details.problemStatementMd).toContain('\\ldots');
expect(details.problemStatementMd).toContain('\\vdots');
expect(details.problemStatementMd).toContain('query_Q');
expect(details.problemStatementMd).toContain('\\end{array}');
});
it('should keep standard pre blocks (sample cases) as markdown code blocks', () => {
const htmlWithStandardPre = `
Sample Input 1
3 125 175
200 300 400
`;
const details = parseProblemPage(htmlWithStandardPre);
expect(details.problemStatementMd).toContain('\`\`\`\n3 125 175\n200 300 400\n\`\`\`');
});
it('should format pre blocks that already contain LaTeX \\text{} commands correctly', () => {
const htmlWithPreLaTeX = `
Input
Q
\\text{query}_1
\\text{query}_2
:
\\text{query}_Q
`;
// Add tag to trigger math conversion
const htmlWithPreVar = htmlWithPreLaTeX.replace('Q', 'Q');
const details = parseProblemPage(htmlWithPreVar);
expect(details.problemStatementMd).toContain('\\begin{array}{l}');
expect(details.problemStatementMd).toContain('Q');
expect(details.problemStatementMd).toContain('\\text{query}_1');
expect(details.problemStatementMd).toContain('\\text{query}_2');
expect(details.problemStatementMd).toContain('\\vdots');
expect(details.problemStatementMd).toContain('\\text{query}_Q');
expect(details.problemStatementMd).toContain('\\end{array}');
expect(details.problemStatementMd).not.toContain('\\text\\text');
});
it('should format pre blocks with adjacent subscripted variables like s_1s_2s_3 correctly', () => {
const htmlWithPreAdjacent = `
Input
s_1s_2s_3
`;
// Add tag to trigger math conversion
const htmlWithPreVar = htmlWithPreAdjacent.replace('s_1s_2s_3', 's_1s_2s_3');
const details = parseProblemPage(htmlWithPreVar);
expect(details.problemStatementMd).toContain('s_1s_2s_3');
});
});