/* * Copyright (c) 2013 - present Adobe Systems Incorporated. All rights reserved. * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * DEALINGS IN THE SOFTWARE. * */ /*global describe, it, expect, jasmine */ /*unittests: HTML SimpleDOM*/ define(function (require, exports, module) { "use strict"; var HTMLSimpleDOM = require("language/HTMLSimpleDOM"), FileUtils = require("file/FileUtils"), WellFormedDoc = require("text!spec/HTMLInstrumentation-test-files/wellformed.html"), MurmurHash3 = require("thirdparty/murmurhash3_gc"); // We test for character document positions here, so LF vs. CRLF line endings make a difference. // Normalize to LF. WellFormedDoc = FileUtils.translateLineEndings(WellFormedDoc, FileUtils.LINE_ENDINGS_LF); function _build(text, startOffset, startOffsetPos, strict, expectedErrors) { var builder = new HTMLSimpleDOM.Builder(text), root = builder.build(strict), errors = builder.errors; if (expectedErrors) { expect(root).toBeNull(); } else { expect(root).toBeTruthy(); } expect(errors).toEqual(expectedErrors); return root; } function build(text, strict, expectedErrors) { return _build(text, undefined, undefined, strict, expectedErrors); } describe("HTML SimpleDOM", function () { describe("Strict HTML parsing", function () { it("should parse a document with balanced, void and self-closing tags", function () { var root = build("
someawesome text
and another
para
unclosed para
unclosed para
hello", true); expect(result).toBeTruthy(); expect(result.tag).toBe("body"); expect(result.children[0].tag).toBe("p"); expect(result.children[0].children[0].content).toBe("hello"); }); it("should return null for an unclosed non-void/non-implied-close tag", function () { var errors = [{ token : { type : 'closetag', contents : 'p', start : 37, end : 38, startPos : { line : 0, ch : 37 }, endPos : { line : 0, ch : 38 } }, startPos : { line : 0, ch : 37 }, endPos : { line : 0, ch : 38 } }]; build("
this has an unclosed bold tag
", true, errors); }); it("should adjust for offsets when logging errors", function () { var errors = [{ token : { type : 'closetag', contents : 'p', start : 38, end : 39, startPos : { line : 1, ch : 22 }, endPos : { line : 1, ch : 23 } }, startPos : { line : 1, ch : 22 }, endPos : { line : 1, ch : 23 } }]; _build("this has an \nunclosed bold tag
", 16, {line: 1, ch: 0}, true, errors); }); it("should return null for an extra close tag", function () { var errors = [{ token : { type : 'closetag', contents : 'b', start : 30, end : 31, startPos : { line : 0, ch : 30 }, endPos : { line : 0, ch : 31 } }, startPos : { line : 0, ch : 30 }, endPos : { line : 0, ch : 31 } }]; build("this has an unopened bold tag
", true, errors); }); it("should return null if there are unclosed tags at the end of the document", function () { var errors = [{ token : null, startPos : { line : 0, ch : 0 }, endPos : { line : 0, ch : 0 } }]; build("