diff --git a/package.json b/package.json index 7f96a40..7ac313a 100644 --- a/package.json +++ b/package.json @@ -8,8 +8,8 @@ }, "scripts": { "build": "browserify ./src/index.js -o slowparse.js --standalone Slowparse", - "test": "node test.js", - "dev": "npm run build && npm run test" + "debug": "npm run build && node inspect test.js", + "test": "npm run build && node test.js" }, "repository": { "type": "git", diff --git a/slowparse.js b/slowparse.js index 56b109a..2499e34 100644 --- a/slowparse.js +++ b/slowparse.js @@ -972,9 +972,21 @@ module.exports = (function(){ start: token.interval.start }; var openTagName = this.domBuilder.currentNode.nodeName.toLowerCase(); - if (closeTagName != openTagName) - throw new ParseError("MISMATCHED_CLOSE_TAG", this, openTagName, - closeTagName, token); + if (closeTagName != openTagName) { + // Are we dealing with a rogue 0) { console.log(failureCount + " tests failed."); } + +var testRunner = require("./test/test-slowparse.js"); +var failureCount = testRunner(Slowparse, window, document, validators); + +if (failureCount > 0) { + console.log(`${failureCount} test${failureCount>1 ? 's' : ''} failed.`); +} process.exit(failureCount); diff --git a/test/test-slowparse.js b/test/test-slowparse.js index 29733c4..a5d5401 100644 --- a/test/test-slowparse.js +++ b/test/test-slowparse.js @@ -809,6 +809,38 @@ module.exports = function(Slowparse, window, document, validators) { }); + test("correctly flag the opening tag for an auto-closed closing tag", function () { + var html = '

test

'; + var result = parse(html); + equal(result.error, { + type: 'MISMATCHED_CLOSE_TAG_DUE_TO_EARLIER_AUTO_CLOSING', + openTag: { name: 'p', start: 6, end: 9 }, + closeTag: { name: 'p', start: 37, end: 40 }, + cursor: 37 + }); + }); + + test("correctly flag the opening tag in the source for a block closer with auto-closed flow element", function () { + var html = '

lol

'; + var result = parse(html); + equal(result.error, { + type: 'MISMATCHED_CLOSE_TAG_DUE_TO_EARLIER_AUTO_CLOSING', + openTag: { name: 'p', start: 6, end: 9 }, + closeTag: { name: 'h2', start: 21, end: 25 }, + cursor: 21 + }); + }); + + test("testing

lol

'; + var result = parse(html); + equal(result.error, { + type: 'MISSING_CLOSING_TAG_NAME', + openTag: { name: 'p', start: 11, end: 14 }, + cursor: 26 + }); + }); + // specifically CSS testing test("parsing empty CSS document", function() {