import { expect } from 'chai';
import { DOMParserImpl } from '../../src/parser/dom-parser';
describe('Locator parse tests', () => {
function assertPosition(n: Node, line: number, col: number, info: string) {
expect(n.lineNumber).to.eq(line, 'lineNumber:' + n.lineNumber + '/' + line + '\n@' + info);
expect(n.columnNumber).to.eq(col, 'columnNumber:' + n.columnNumber + '/' + col + '\n@' + info);
}
it.skip('empty line number', () => {
const xml = [
'',
'',
' ',
'',
' ',
' ',
' ',
'',
' ',
].join('\n');
const parser = new DOMParserImpl({ locator: {} });
const doc = parser.parseFromString(xml, 'text/xml');
const trans = doc.getElementsByTagName('transition')[0];
expect(trans.lineNumber).to.eq(10);
});
it.skip('node positions', () => {
const parser = new DOMParserImpl({ locator: {} });
const doc = parser.parseFromString(
'\n' + '\n' + ' something\nx',
'text/xml',
);
const test = doc.documentElement;
const a = test.firstChild!.nextSibling!;
assertPosition(doc.firstChild!, 1, 1, 'first child');
assertPosition(doc.firstChild!.nextSibling!, 1, 1 + ''.length, 'first child nextSibling');
assertPosition(test, 2, 1, 'document element' + test);
assertPosition(a, 3, 3, 'documentElement firstchild nextSibling' + a);
assertPosition(a.firstChild!, 3, 19, 'a.firstchild');
assertPosition(a.firstChild!.nextSibling!, 3, 19 + ''.length, 'a.firstchild.nextsibling');
assertPosition(test.lastChild!, 4, 5, 'test.lastChild');
});
it('error positions', () => {
const error: string[] = [];
const parser = new DOMParserImpl({
locator: { systemId: 'c:/test/1.xml' },
errorHandler: {
error: function(msg) {
error.push(msg);
},
},
});
const xml = '