Files
范智鹏 e469554691 test: 新增 8 个测试文件 63 用例 + 覆盖率设施,行覆盖 42.58%→48.24%
- 新增 jsp-extractor/report/method-extractor/fix-prompt/registry/provider-chat/import-service/yaml-parser 测试
- .vscode-test.mjs 加 srcDir+coverage,package.json 加 test:coverage,产出 tests/coverage/(html)
- 修复 method-extractor java fallback 取错捕获组、mockDocument.getText 忽略 range
- 更新 tests/test-cases.md(24 文件 179 条)与 test-execution-log.md(覆盖率记录)
2026-08-27 22:54:00 +08:00

76 lines
3.1 KiB
TypeScript

import * as assert from 'assert';
import { extractJspSections } from '../src/jsp/jsp-extractor';
suite('JspExtractor Tests', () => {
test('extracts script block as javascript', () => {
const content = '<html>\n<script type="text/javascript">\nvar a = 1;\n</script>\n</html>';
const sections = extractJspSections(content);
assert.strictEqual(sections.length, 1);
assert.strictEqual(sections[0].language, 'javascript');
assert.strictEqual(sections[0].code, '\nvar a = 1;\n');
assert.strictEqual(sections[0].lineOffset, 1);
});
test('extracts style block as css', () => {
const content = '<style>\nbody { color: red; }\n</style>';
const sections = extractJspSections(content);
assert.strictEqual(sections.length, 1);
assert.strictEqual(sections[0].language, 'css');
assert.strictEqual(sections[0].code, '\nbody { color: red; }\n');
});
test('extracts statement scriptlet with line offset', () => {
const content = '<p>hi</p>\n<% int x = 1; %>\n<p>end</p>';
const sections = extractJspSections(content);
assert.strictEqual(sections.length, 1);
assert.strictEqual(sections[0].language, 'java');
assert.strictEqual(sections[0].scriptletKind, 'statement');
assert.strictEqual(sections[0].code, ' int x = 1; ');
assert.strictEqual(sections[0].lineOffset, 1);
});
test('extracts declaration scriptlet', () => {
const content = '<%! private int count = 0; %>';
const sections = extractJspSections(content);
assert.strictEqual(sections.length, 1);
assert.strictEqual(sections[0].scriptletKind, 'declaration');
assert.strictEqual(sections[0].code, ' private int count = 0; ');
});
test('extracts expression scriptlet', () => {
const content = '<%= user.name %>';
const sections = extractJspSections(content);
assert.strictEqual(sections.length, 1);
assert.strictEqual(sections[0].scriptletKind, 'expression');
assert.strictEqual(sections[0].code, ' user.name ');
});
test('skips directives and comments', () => {
const content = '<%@ page import="java.util.*" %>\n<%-- comment --%>\n<% int y = 2; %>';
const sections = extractJspSections(content);
assert.strictEqual(sections.length, 1);
assert.strictEqual(sections[0].scriptletKind, 'statement');
assert.strictEqual(sections[0].code, ' int y = 2; ');
});
test('reports sourceStart/sourceEnd positions', () => {
const content = 'a\n<% x(); %>';
const sections = extractJspSections(content);
assert.strictEqual(sections.length, 1);
const slice = content.slice(sections[0].sourceStart, sections[0].sourceEnd);
assert.strictEqual(slice, '<% x(); %>');
assert.strictEqual(sections[0].lineOffset, 1);
});
test('returns empty array for plain html', () => {
assert.deepStrictEqual(extractJspSections('<p>hello</p>'), []);
});
test('collects script, style and scriptlet sections', () => {
const content = '<script>var s=1;</script><% int a = 1; %><style>.c{}</style>';
const sections = extractJspSections(content);
assert.deepStrictEqual(sections.map(s => s.language), ['javascript', 'css', 'java']);
assert.strictEqual(sections[2].scriptletKind, 'statement');
});
});