• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1import * as assert from 'node:assert';
2import { generateLocationInfoParserTests } from 'parse5-test-utils/utils/generate-location-info-parser-tests.js';
3import { generateTestsForEachTreeAdapter } from 'parse5-test-utils/utils/common.js';
4import { parseChunked } from './utils/parse-chunked.js';
5
6generateLocationInfoParserTests('location-info', (input, opts) =>
7    // NOTE: because of performance use bigger chunks here
8    parseChunked({ input }, opts, 100, 400)
9);
10
11generateTestsForEachTreeAdapter('location-info', (treeAdapter) => {
12    test('Regression - location info for the implicitly generated <body>, <html> and <head> (GH-44)', () => {
13        const html = '</head><div class="test"></div></body></html>';
14
15        const opts = {
16            treeAdapter,
17            sourceCodeLocationInfo: true,
18        };
19
20        const document = parseChunked({ input: html }, opts).node;
21        const htmlEl = treeAdapter.getChildNodes(document)[0];
22        const headEl = treeAdapter.getChildNodes(htmlEl)[0];
23        const bodyEl = treeAdapter.getChildNodes(htmlEl)[1];
24
25        assert.strictEqual(treeAdapter.getNodeSourceCodeLocation(htmlEl), null);
26        assert.strictEqual(treeAdapter.getNodeSourceCodeLocation(headEl), null);
27        assert.strictEqual(treeAdapter.getNodeSourceCodeLocation(bodyEl), null);
28    });
29});
30