/*--------------------------------------------------------------------------------------------- * Copyright (c) Microsoft Corporation. All rights reserved. * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ 'use strict'; import * as assert from 'assert'; import {Node, HTMLDocument, parse} from '../parser/htmlParser'; suite('HTML Parser', () => { function toJSON(node: Node): any { return { tag: node.tag, start: node.start, end: node.end, children: node.children.map(toJSON) }; } function assertDocument(input: string, expected: any) { let document = parse(input); assert.deepEqual(document.roots.map(toJSON), expected); } function assertNodeBefore(input: string, offset: number, expectedTag: string) { let document = parse(input); let node = document.findNodeBefore(offset); assert.equal(node ? node.tag : '', expectedTag); } test('Simple', () => { assertDocument('', [ { tag: 'html', start: 0, end: 13, children: []}] ); assertDocument('
', [ { tag: 'html', start: 0, end: 26, children: [ { tag: 'body', start: 6, end: 19, children: [] }]}] ); assertDocument('', [ { tag: 'html', start: 0, end: 39, children: [ { tag: 'head', start: 6, end: 19, children: [] }, { tag: 'body', start: 19, end: 32, children: [] }]}] ); }); test('SelfClose', () => { assertDocument('