import * as assert from 'assert'; import { extractJspSections } from '../src/jsp/jsp-extractor'; suite('JspExtractor Tests', () => { test('extracts script block as javascript', () => { const content = '\n\n'; 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 = ''; 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 = '

hi

\n<% int x = 1; %>\n

end

'; 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('

hello

'), []); }); test('collects script, style and scriptlet sections', () => { const content = '<% int a = 1; %>'; const sections = extractJspSections(content); assert.deepStrictEqual(sections.map(s => s.language), ['javascript', 'css', 'java']); assert.strictEqual(sections[2].scriptletKind, 'statement'); }); });