diff --git a/README.md b/README.md index 826b6997..b820b415 100644 --- a/README.md +++ b/README.md @@ -58,8 +58,8 @@ Most of the options are disabled by default. | `includeAutoGeneratedTags` | Insert tags generated by HTML parser | `true` | | `keepClosingSlash` | Keep the trailing slash on singleton elements | `false` | | `maxLineLength` | Specify a maximum line length. Compressed output will be split by newlines at valid HTML split-points | -| `minifyCSS` | Minify CSS in style elements and style attributes (uses [clean-css](https://github.com/jakubpawlowicz/clean-css)) | `false` (could be `true`, `Object`, `Function(text, type)`) | -| `minifyJS` | Minify JavaScript in script elements and event attributes (uses [UglifyJS](https://github.com/mishoo/UglifyJS2)) | `false` (could be `true`, `Object`, `Function(text, inline)`) | +| `minifyCSS` | Minify CSS in style elements and style attributes (uses [clean-css](https://github.com/jakubpawlowicz/clean-css)) | `false` (could be `true`, `Object`, `Function(text, type[, cb])`) | +| `minifyJS` | Minify JavaScript in script elements and event attributes (uses [UglifyJS](https://github.com/mishoo/UglifyJS2)) | `false` (could be `true`, `Object`, `Function(text, inline[, cb])`) | | `minifyURLs` | Minify URLs in various attributes (uses [relateurl](https://github.com/stevenvachon/relateurl)) | `false` (could be `String`, `Object`, `Function(text)`) | | `preserveLineBreaks` | Always collapse to 1 line break (never remove it entirely) when whitespace between tags include a line break. Must be used in conjunction with `collapseWhitespace=true` | `false` | | `preventAttributesEscaping` | Prevents the escaping of the values of attributes | `false` | @@ -142,6 +142,8 @@ For command line usage please see `html-minifier --help` ### Node.js +#### Synchronous Usage + ```js var minify = require('html-minifier').minify; var result = minify('

foo

', { @@ -150,6 +152,62 @@ var result = minify('

foo

', { result; // '

foo

' ``` +#### Asynchronous Usage + +`minify` can take an optional callback function that will be invoked once the +minification is complete (or an error occurs). + +This allows for the following functions to complete asynchronously: + +* minifyCSS +* minifyJS + +```js +var minify = require('html-minifier').minify; + +minify( + '', + { + minifyCSS: function(css, cb) { + doSomethingAsync(css, function(updatedCss) { + cb(updatedCss); + }); + }, + }, + function(error, result) { + if (error) { + // Handle error. + } else { + // Do something with the result. + } + } +); +``` + +##### Promisify + +`minify` is compatable with NodeJS's [`util.promisify`](https://nodejs.org/dist/latest-v8.x/docs/api/util.html#util_util_promisify_original) +function added in v8.0.0 + +```js +const util = require('util'); +const minify = util.promisify(require('html-minifier').minify); + +minify('', { + minifyCSS: (css, cb) => { + doSomethingAsync(css, updatedCss => { + cb(updatedCss); + }); + } +}) + .then(result => { + // Do something with the result. + }) + .catch(error => { + // Handle error. + }); +``` + ## Running benchmarks Benchmarks for minified HTML: diff --git a/src/htmlminifier.js b/src/htmlminifier.js index e3824342..f9df2ee7 100644 --- a/src/htmlminifier.js +++ b/src/htmlminifier.js @@ -8,6 +8,17 @@ var TokenChain = require('./tokenchain'); var UglifyJS = require('uglify-js'); var utils = require('./utils'); +/** + * A callback that takes an error and a string result. + * @typedef {function(?Error, string):void} ResultCallback + * + * A callback that takes an error and an update buffer. + * @typedef {function(?Error, Buffer):void} BufferCallback + * + * A buffer of strings. + * @typedef {string[]} Buffer + */ + function trimWhitespace(str) { if (typeof str !== 'string') { return str; @@ -257,10 +268,16 @@ function isSrcset(attrName, tag) { return attrName === 'srcset' && srcsetTags(tag); } -function cleanAttributeValue(tag, attrName, attrValue, options, attrs) { +function cleanAttributeValue(tag, attrName, attrValue, options, attrs, cb) { if (attrValue && isEventAttribute(attrName, options)) { attrValue = trimWhitespace(attrValue).replace(/^javascript:\s*/i, ''); - return options.minifyJS(attrValue, true); + attrValue = options.minifyJS(attrValue, true, function(result) { + cb(null, result); + }); + if (typeof attrValue !== 'undefined') { + return cb(null, attrValue); + } + return; } else if (attrName === 'class') { attrValue = trimWhitespace(attrValue); @@ -270,14 +287,14 @@ function cleanAttributeValue(tag, attrName, attrValue, options, attrs) { else { attrValue = collapseWhitespaceAll(attrValue); } - return attrValue; + return cb(null, attrValue); } else if (isUriTypeAttribute(attrName, tag)) { attrValue = trimWhitespace(attrValue); - return isLinkType(tag, attrs, 'canonical') ? attrValue : options.minifyURLs(attrValue); + return cb(null, isLinkType(tag, attrs, 'canonical') ? attrValue : options.minifyURLs(attrValue)); } else if (isNumberTypeAttribute(attrName, tag)) { - return trimWhitespace(attrValue); + return cb(null, trimWhitespace(attrValue)); } else if (attrName === 'style') { attrValue = trimWhitespace(attrValue); @@ -285,9 +302,15 @@ function cleanAttributeValue(tag, attrName, attrValue, options, attrs) { if (/;$/.test(attrValue) && !/&#?[0-9a-zA-Z]+;$/.test(attrValue)) { attrValue = attrValue.replace(/\s*;$/, ';'); } - attrValue = options.minifyCSS(attrValue, 'inline'); + attrValue = options.minifyCSS(attrValue, 'inline', function(result) { + cb(null, result); + }); + if (typeof attrValue !== 'undefined') { + return cb(null, attrValue); + } + return; } - return attrValue; + return cb(null, attrValue); } else if (isSrcset(attrName, tag)) { // https://html.spec.whatwg.org/multipage/embedded-content.html#attr-img-srcset @@ -322,9 +345,15 @@ function cleanAttributeValue(tag, attrName, attrValue, options, attrs) { } else if (isMediaQuery(tag, attrs, attrName)) { attrValue = trimWhitespace(attrValue); - return options.minifyCSS(attrValue, 'media'); + attrValue = options.minifyCSS(attrValue, 'media', function(result) { + cb(null, result); + }); + if (typeof attrValue !== 'undefined') { + return cb(null, attrValue); + } + return; } - return attrValue; + return cb(null, attrValue); } function isMetaViewport(tag, attrs) { @@ -358,20 +387,26 @@ function unwrapMediaQuery(text) { return matches ? matches[1] : text; } -function cleanConditionalComment(comment, options) { - return options.processConditionalComments ? comment.replace(/^(\[if\s[^\]]+]>)([\s\S]*?)()([\s\S]*?)( -1) { - return minify(text, options); + return minify(text, options, false, cb); } } - return text; + return cb(null, text); } // Tag omission rules from https://html.spec.whatwg.org/multipage/syntax.html#optional-tags @@ -521,7 +556,7 @@ function canTrimWhitespace(tag) { return !/^(?:pre|textarea)$/.test(tag); } -function normalizeAttr(attr, attrs, tag, options) { +function normalizeAttr(attr, attrs, tag, options, cb) { var attrName = options.caseSensitive ? attr.name : attr.name.toLowerCase(), attrValue = attr.value; @@ -535,25 +570,29 @@ function normalizeAttr(attr, attrs, tag, options) { attrName === 'type' && isScriptTypeAttribute(attrValue) || options.removeStyleLinkTypeAttributes && (tag === 'style' || tag === 'link') && attrName === 'type' && isStyleLinkTypeAttribute(attrValue)) { - return; + return cb(); } - attrValue = cleanAttributeValue(tag, attrName, attrValue, options, attrs); + cleanAttributeValue(tag, attrName, attrValue, options, attrs, function(error, attrValue) { + if (error) { + return cb(error); + } - if (options.removeEmptyAttributes && + if (options.removeEmptyAttributes && canDeleteEmptyAttribute(tag, attrName, attrValue, options)) { - return; - } + return cb(); + } - if (options.decodeEntities && attrValue) { - attrValue = attrValue.replace(/&(#?[0-9a-zA-Z]+;)/g, '&$1'); - } + if (options.decodeEntities && attrValue) { + attrValue = attrValue.replace(/&(#?[0-9a-zA-Z]+;)/g, '&$1'); + } - return { - attr: attr, - name: attrName, - value: attrValue - }; + return cb(null, { + attr: attr, + name: attrName, + value: attrValue + }); + }); } function buildAttr(normalized, hasUnarySlash, options, isLast, uidAttr) { @@ -613,10 +652,11 @@ function identity(value) { return value; } -function processOptions(values) { +function processOptions(values, ensureSynchronicity) { var options = { canCollapseWhitespace: canCollapseWhitespace, canTrimWhitespace: canTrimWhitespace, + ensureSynchronicity: ensureSynchronicity, html5: true, ignoreCustomComments: [/^!/], ignoreCustomFragments: [ @@ -726,7 +766,7 @@ function uniqueId(value) { var specialContentTags = createMapFromString('script,style'); -function createSortFns(value, options, uidIgnore, uidAttr) { +function createSortFns(value, options, uidIgnore, uidAttr, cb) { var attrChains = options.sortAttributes && Object.create(null); var classChain = options.sortClassName && new TokenChain(); @@ -781,42 +821,164 @@ function createSortFns(value, options, uidIgnore, uidAttr) { options.log = identity; options.sortAttributes = false; options.sortClassName = false; - scan(minify(value, options)); - options.log = log; - if (attrChains) { - var attrSorters = Object.create(null); - for (var tag in attrChains) { - attrSorters[tag] = attrChains[tag].createSorter(); + minify(value, options, false, function(error, result) { + if (error) { + return cb(error); } - options.sortAttributes = function(tag, attrs) { - var sorter = attrSorters[tag]; - if (sorter) { - var attrMap = Object.create(null); - var names = attrNames(attrs); - names.forEach(function(name, index) { - (attrMap[name] || (attrMap[name] = [])).push(attrs[index]); - }); - sorter.sort(names).forEach(function(name, index) { - attrs[index] = attrMap[name].shift(); - }); + + scan(result); + options.log = log; + if (attrChains) { + var attrSorters = Object.create(null); + for (var tag in attrChains) { + attrSorters[tag] = attrChains[tag].createSorter(); } - }; - } - if (classChain) { - var sorter = classChain.createSorter(); - options.sortClassName = function(value) { - return sorter.sort(value.split(/[ \n\f\r]+/)).join(' '); - }; - } + options.sortAttributes = function(tag, attrs) { + var sorter = attrSorters[tag]; + if (sorter) { + var attrMap = Object.create(null); + var names = attrNames(attrs); + names.forEach(function(name, index) { + (attrMap[name] || (attrMap[name] = [])).push(attrs[index]); + }); + sorter.sort(names).forEach(function(name, index) { + attrs[index] = attrMap[name].shift(); + }); + } + }; + } + if (classChain) { + var sorter = classChain.createSorter(); + options.sortClassName = function(value) { + return sorter.sort(value.split(/[ \n\f\r]+/)).join(' '); + }; + } + + return cb(); + }); } -function minify(value, options, partialMarkup) { +/** + * A task that operates on the a buffer. + * + * The task will not be executed until explicitly told to. + * + * @class + */ +var Task = (function() { + /** + * @constructor + * @param {function(Buffer, BufferCallback)} task + */ + function Task(task) { + this.task = task; + } + + /** + * Execute this task. + * + * @param {Buffer} buffer + * @param {BufferCallback} cb + */ + Task.prototype.exec = function(buffer, cb) { + this.task(buffer, cb); + }; + + return Task; +})(); + +/** + * A group of Tasks and or other TaskGroups to execute in series. + * + * The tasks will not be executed until explicitly told to. + * Additional tasks can be added to the group by pushing to the `tasks` array + * property. Do not modify this property once execution was begun. + * + * @class + */ +var TaskGroup = (function() { + /** + * @constructor + * @param {Array} [tasks] + */ + function TaskGroup(tasks) { + this.tasks = tasks ? tasks : []; + } + + /** + * Run all tasks in this group in series. + * + * @param {Buffer} buffer + * @param {BufferCallback} cb + */ + TaskGroup.prototype.exec = function(buffer, cb) { + /** + * Run the task at the given index, giving it a callback to run the next + * task the same way. + * + * @param {number} index + */ + (function implementation(buffer, index) { + if (index < this.tasks.length) { + try { + this.tasks[index].exec(buffer.slice(0), function(error, buffer) { + if (error) { + return cb(error); + } + return implementation.call(this, buffer, index + 1); + }.bind(this)); + } + catch (error) { + // Recover from `Maximum call stack size exceeded`. + if (error.message === 'Maximum call stack size exceeded') { + // Wait for stack to clear, then try again. + setTimeout(function() { + implementation.call(this, buffer, index); + }.bind(this), 0); + } + else { + cb(error); + } + } + } + else { + cb(null, buffer); + } + }.bind(this))(buffer, 0); + }; + return TaskGroup; +})(); + +/** + * Minify HTML. + * + * @param {string} value + * @param {Object} options + * @param {boolean} partialMarkup + * @param {ResultCallback} cb + */ +function minify(value, options, partialMarkup, cb) { + /** + * Calls the `topLevelCb` if there is an error; otherwise does nothing. + * + * @param {Error} [error] + */ + function errorCallback(error) { + if (error) { + return cb(error); + } + } + if (options.collapseWhitespace) { value = collapseWhitespace(value, options, true, true); } - var buffer = [], - charsPrevTag, + /** + * @type {Buffer} + */ + var buffer = []; + + var charsPrevTag, currentChars = '', hasChars, currentTag = '', @@ -831,6 +993,20 @@ function minify(value, options, partialMarkup) { uidAttr, uidPattern; + /** + * Set of tasks to perform. + * + * @type {Array} + */ + var tasks = []; + + /** + * The next task to perform. + * + * @type {Task} + */ + var nextTask; + // temporarily replace ignored chunks with comments, // so that we don't have to worry what's there. // for all we care there might be @@ -853,11 +1029,11 @@ function minify(value, options, partialMarkup) { }); function escapeFragments(fn) { - return function(text, type) { + return function(text, type, cb) { return fn(text.replace(uidPattern, function(match, prefix, index) { var chunks = ignoredCustomMarkupChunks[+index]; return chunks[1] + uidAttr + index + chunks[2]; - }), type); + }), type, cb); }; } @@ -886,7 +1062,17 @@ function minify(value, options, partialMarkup) { if (options.sortAttributes && typeof options.sortAttributes !== 'function' || options.sortClassName && typeof options.sortClassName !== 'function') { - createSortFns(value, options, uidIgnore, uidAttr); + nextTask = new Task(function(buffer, cb) { + createSortFns(value, options, uidIgnore, uidAttr, function(error) { + cb(error, buffer); + }); + }); + if (options.ensureSynchronicity) { + nextTask.exec(buffer, errorCallback); + } + else { + tasks.push(nextTask); + } } function _canCollapseWhitespace(tag, attrs) { @@ -897,7 +1083,7 @@ function minify(value, options, partialMarkup) { return options.canTrimWhitespace(tag, attrs, canTrimWhitespace); } - function removeStartTag() { + function removeStartTag(buffer) { var index = buffer.length - 1; while (index > 0 && !/^<[^/!]/.test(buffer[index])) { index--; @@ -905,7 +1091,7 @@ function minify(value, options, partialMarkup) { buffer.length = Math.max(0, index); } - function removeEndTag() { + function removeEndTag(buffer) { var index = buffer.length - 1; while (index > 0 && !/^<\//.test(buffer[index])) { index--; @@ -914,7 +1100,7 @@ function minify(value, options, partialMarkup) { } // look for trailing whitespaces, bypass any inline tags - function trimTrailingWhitespace(index, nextTag) { + function trimTrailingWhitespace(buffer, index, nextTag) { for (var endTag = null; index >= 0 && _canTrimWhitespace(endTag); index--) { var str = buffer[index]; var match = str.match(/^<\/([\w:-]+)>$/); @@ -930,7 +1116,7 @@ function minify(value, options, partialMarkup) { // look for trailing whitespaces from previously processed text // which may not be trimmed due to a following comment or an empty // element which has now been removed - function squashTrailingWhitespace(nextTag) { + function squashTrailingWhitespace(buffer, nextTag) { var charsIndex = buffer.length - 1; if (buffer.length > 1) { var item = buffer[buffer.length - 1]; @@ -938,333 +1124,546 @@ function minify(value, options, partialMarkup) { charsIndex--; } } - trimTrailingWhitespace(charsIndex, nextTag); + trimTrailingWhitespace(buffer, charsIndex, nextTag); } - new HTMLParser(value, { - partialMarkup: partialMarkup, - html5: options.html5, + nextTask = new Task(function(buffer, cb) { + try { + var subtasks = []; - start: function(tag, attrs, unary, unarySlash, autoGenerated) { - var lowerTag = tag.toLowerCase(); + new HTMLParser(value, { + partialMarkup: partialMarkup, + html5: options.html5, - if (lowerTag === 'svg') { - options = Object.create(options); - options.keepClosingSlash = true; - options.caseSensitive = true; - } + start: function(tag, attrs, unary, unarySlash, autoGenerated) { + nextTask = new Task(function(buffer, cb) { + var lowerTag = tag.toLowerCase(); - tag = options.caseSensitive ? tag : lowerTag; + if (lowerTag === 'svg') { + options = Object.create(options); + options.keepClosingSlash = true; + options.caseSensitive = true; + } - currentTag = tag; - charsPrevTag = tag; - if (!inlineTextTags(tag)) { - currentChars = ''; - } - hasChars = false; - currentAttrs = attrs; - - var optional = options.removeOptionalTags; - if (optional) { - var htmlTag = htmlTags(tag); - // may be omitted if first thing inside is not comment - // may be omitted if first thing inside is an element - // may be omitted if first thing inside is not space, comment, , , '), ''); - assert.equal(minify(''), ''); - assert.equal(minify(''), ''); + test_minify(assert, '', ''); + test_minify(assert, '', ''); + test_minify(assert, '', ''); - assert.equal(minify('foo'), 'foo'); - assert.equal(minify('

x'), '

x

'); - assert.equal(minify('

x

'), '

x

', 'trailing quote should be ignored'); - assert.equal(minify('

Click me

'), '

Click me

'); - assert.equal(minify(''), ''); - assert.equal(minify('
[fallback image]
'), - '
[fallback image]
' - ); + test_minify(assert, 'foo', 'foo'); + test_minify(assert, '

x', '

x

'); + test_minify(assert, '

x

', '

x

', null, 'trailing quote should be ignored'); + test_minify(assert, '

Click me

', '

Click me

'); + test_minify(assert, '', ''); + test_minify(assert, '
[fallback image]
', '
[fallback image]
'); - assert.equal(minify(''), ''); - assert.equal(minify(''), ''); - assert.equal(minify('
'), - '
' - ); + test_minify(assert, '', ''); + test_minify(assert, '', ''); + test_minify(assert, '
', '
'); // will cause test to time-out if fail input = '

For more information, read this Stack Overflow answer.

'; output = '

For more information, read this Stack Overflow answer.

'; - assert.equal(minify(input), output); + test_minify(assert, input, output); input = ''; - assert.equal(minify(input), input); + test_minify(assert, input, input); input = ''; - assert.equal(minify(input), input); + test_minify(assert, input, input); input = '<$unicorn>'; - assert.throws(function() { - minify(input); - }, 'Invalid tag name'); + test_minify_error(assert, input, null, null, 'Invalid tag name'); input = ''; - assert.equal(minify(input), input); + test_minify(assert, input, input); // https://github.com/kangax/html-minifier/issues/41 - assert.equal(minify(''), - '' - ); + test_minify(assert, '', ''); // https://github.com/kangax/html-minifier/issues/40 - assert.equal(minify('[\']["]'), '[\']["]'); + test_minify(assert, '[\']["]', '[\']["]'); // https://github.com/kangax/html-minifier/issues/21 - assert.equal(minify('
hey
'), '
hey
'); + test_minify(assert, '
hey
', '
hey
'); // https://github.com/kangax/html-minifier/issues/17 - assert.equal(minify(':) link'), ':) link'); + test_minify(assert, ':) link', ':) link'); // https://github.com/kangax/html-minifier/issues/169 - assert.equal(minify('ok'), 'ok'); + test_minify(assert, 'ok', 'ok'); - assert.equal(minify(''), ''); + test_minify(assert, '', ''); // https://github.com/kangax/html-minifier/issues/229 - assert.equal(minify('
Hello :)
'), '
Hello :)
'); + test_minify(assert, '
Hello :)
', '
Hello :)
'); // https://github.com/kangax/html-minifier/issues/507 input = ''; - assert.equal(minify(input), input); - assert.throws(function() { - minify(''); - }, 'invalid attribute name'); + test_minify(assert, input, input); + test_minify_error(assert, '', null, null, 'invalid attribute name'); // https://github.com/kangax/html-minifier/issues/512 input = ''; - assert.equal(minify(input), input); - assert.throws(function() { - minify( - '' + ' placeholder="YYYY-MM-DD"' + ' date-range-picker' + ' data-ng-model="vm.value"' + ' data-ng-model-options="{ debounce: 1000 }"' + ' data-ng-pattern="vm.options.format"' + - ' data-options="vm.datepickerOptions">' - ); - }, 'HTML comment inside tag'); + ' data-options="vm.datepickerOptions">', null, null, 'HTML comment inside tag'); input = '
'; output = '
'; - assert.equal(minify(input), output); + test_minify(assert, input, output); output = '
'; - assert.equal(minify(input, { + test_minify(assert, input, output, { decodeEntities: true, removeTagWhitespace: true, - }), output); + }); output = '
'; - assert.equal(minify(input, { + test_minify(assert, input, output, { decodeEntities: true, removeAttributeQuotes: true - }), output); - assert.equal(minify(input, { + }); + test_minify(assert, input, output, { decodeEntities: true, removeAttributeQuotes: true, removeTagWhitespace: true, - }), output); + }); }); QUnit.test('options', function(assert) { var input = '

blahblah 2blah 3

'; - assert.equal(minify(input), input); - assert.equal(minify(input, {}), input); + test_minify(assert, input, input); + test_minify(assert, input, input, {}); }); QUnit.test('case normalization', function(assert) { - assert.equal(minify('

foo

'), '

foo

'); - assert.equal(minify('
boo
'), '
boo
'); - assert.equal(minify('
boo
'), '
boo
'); - assert.equal(minify('
boo
'), '
boo
'); - assert.equal(minify('
boo
'), '
boo
'); - assert.equal(minify('
boo
'), '
boo
'); + test_minify(assert, '

foo

', '

foo

'); + test_minify(assert, '
boo
', '
boo
'); + test_minify(assert, '
boo
', '
boo
'); + test_minify(assert, '
boo
', '
boo
'); + test_minify(assert, '
boo
', '
boo
'); + test_minify(assert, '
boo
', '
boo
'); }); QUnit.test('space normalization between attributes', function(assert) { - assert.equal(minify('

foo

'), '

foo

'); - assert.equal(minify(''), ''); - assert.equal(minify('

foo

'), '

foo

'); - assert.equal(minify('

foo

'), '

foo

'); - assert.equal(minify(''), ''); - assert.equal(minify(''), ''); + test_minify(assert, '

foo

', '

foo

'); + test_minify(assert, '', ''); + test_minify(assert, '

foo

', '

foo

'); + test_minify(assert, '

foo

', '

foo

'); + test_minify(assert, '', ''); + test_minify(assert, '', ''); }); QUnit.test('space normalization around text', function(assert) { var input, output; input = '

blah

\n\n\n '; - assert.equal(minify(input), input); + test_minify(assert, input, input); output = '

blah

'; - assert.equal(minify(input, { collapseWhitespace: true }), output); + test_minify(assert, input, output, { collapseWhitespace: true }); output = '

blah

'; - assert.equal(minify(input, { + test_minify(assert, input, output, { collapseWhitespace: true, conservativeCollapse: true - }), output); + }); output = '

blah

\n'; - assert.equal(minify(input, { + test_minify(assert, input, output, { collapseWhitespace: true, preserveLineBreaks: true - }), output); + }); output = '

blah

\n'; - assert.equal(minify(input, { + test_minify(assert, input, output, { collapseWhitespace: true, conservativeCollapse: true, preserveLineBreaks: true - }), output); + }); [ 'a', 'abbr', 'acronym', 'b', 'big', 'del', 'em', 'font', 'i', 'ins', 'kbd', 'mark', 's', 'samp', 'small', 'span', 'strike', 'strong', 'sub', 'sup', 'time', 'tt', 'u', 'var' ].forEach(function(el) { - assert.equal(minify('foo <' + el + '>baz bar', { collapseWhitespace: true }), 'foo <' + el + '>baz bar'); - assert.equal(minify('foo<' + el + '>bazbar', { collapseWhitespace: true }), 'foo<' + el + '>bazbar'); - assert.equal(minify('foo <' + el + '>bazbar', { collapseWhitespace: true }), 'foo <' + el + '>bazbar'); - assert.equal(minify('foo<' + el + '>baz bar', { collapseWhitespace: true }), 'foo<' + el + '>baz bar'); - assert.equal(minify('foo <' + el + '> baz bar', { collapseWhitespace: true }), 'foo <' + el + '>baz bar'); - assert.equal(minify('foo<' + el + '> baz bar', { collapseWhitespace: true }), 'foo<' + el + '> baz bar'); - assert.equal(minify('foo <' + el + '> baz bar', { collapseWhitespace: true }), 'foo <' + el + '>baz bar'); - assert.equal(minify('foo<' + el + '> baz bar', { collapseWhitespace: true }), 'foo<' + el + '> baz bar'); - assert.equal(minify('
foo <' + el + '>baz bar
', { collapseWhitespace: true }), '
foo <' + el + '>baz bar
'); - assert.equal(minify('
foo<' + el + '>bazbar
', { collapseWhitespace: true }), '
foo<' + el + '>bazbar
'); - assert.equal(minify('
foo <' + el + '>bazbar
', { collapseWhitespace: true }), '
foo <' + el + '>bazbar
'); - assert.equal(minify('
foo<' + el + '>baz bar
', { collapseWhitespace: true }), '
foo<' + el + '>baz bar
'); - assert.equal(minify('
foo <' + el + '> baz bar
', { collapseWhitespace: true }), '
foo <' + el + '>baz bar
'); - assert.equal(minify('
foo<' + el + '> baz bar
', { collapseWhitespace: true }), '
foo<' + el + '> baz bar
'); - assert.equal(minify('
foo <' + el + '> baz bar
', { collapseWhitespace: true }), '
foo <' + el + '>baz bar
'); - assert.equal(minify('
foo<' + el + '> baz bar
', { collapseWhitespace: true }), '
foo<' + el + '> baz bar
'); + test_minify(assert, 'foo <' + el + '>baz bar', 'foo <' + el + '>baz bar', { collapseWhitespace: true }); + test_minify(assert, 'foo<' + el + '>bazbar', 'foo<' + el + '>bazbar', { collapseWhitespace: true }); + test_minify(assert, 'foo <' + el + '>bazbar', 'foo <' + el + '>bazbar', { collapseWhitespace: true }); + test_minify(assert, 'foo<' + el + '>baz bar', 'foo<' + el + '>baz bar', { collapseWhitespace: true }); + test_minify(assert, 'foo <' + el + '> baz bar', 'foo <' + el + '>baz bar', { collapseWhitespace: true }); + test_minify(assert, 'foo<' + el + '> baz bar', 'foo<' + el + '> baz bar', { collapseWhitespace: true }); + test_minify(assert, 'foo <' + el + '> baz bar', 'foo <' + el + '>baz bar', { collapseWhitespace: true }); + test_minify(assert, 'foo<' + el + '> baz bar', 'foo<' + el + '> baz bar', { collapseWhitespace: true }); + test_minify(assert, '
foo <' + el + '>baz bar
', '
foo <' + el + '>baz bar
', { collapseWhitespace: true }); + test_minify(assert, '
foo<' + el + '>bazbar
', '
foo<' + el + '>bazbar
', { collapseWhitespace: true }); + test_minify(assert, '
foo <' + el + '>bazbar
', '
foo <' + el + '>bazbar
', { collapseWhitespace: true }); + test_minify(assert, '
foo<' + el + '>baz bar
', '
foo<' + el + '>baz bar
', { collapseWhitespace: true }); + test_minify(assert, '
foo <' + el + '> baz bar
', '
foo <' + el + '>baz bar
', { collapseWhitespace: true }); + test_minify(assert, '
foo<' + el + '> baz bar
', '
foo<' + el + '> baz bar
', { collapseWhitespace: true }); + test_minify(assert, '
foo <' + el + '> baz bar
', '
foo <' + el + '>baz bar
', { collapseWhitespace: true }); + test_minify(assert, '
foo<' + el + '> baz bar
', '
foo<' + el + '> baz bar
', { collapseWhitespace: true }); }); // Don't trim whitespace around element, but do trim within [ 'bdi', 'bdo', 'button', 'cite', 'code', 'dfn', 'math', 'q', 'rt', 'rtc', 'ruby', 'svg' ].forEach(function(el) { - assert.equal(minify('foo <' + el + '>baz bar', { collapseWhitespace: true }), 'foo <' + el + '>baz bar'); - assert.equal(minify('foo<' + el + '>bazbar', { collapseWhitespace: true }), 'foo<' + el + '>bazbar'); - assert.equal(minify('foo <' + el + '>bazbar', { collapseWhitespace: true }), 'foo <' + el + '>bazbar'); - assert.equal(minify('foo<' + el + '>baz bar', { collapseWhitespace: true }), 'foo<' + el + '>baz bar'); - assert.equal(minify('foo <' + el + '> baz bar', { collapseWhitespace: true }), 'foo <' + el + '>baz bar'); - assert.equal(minify('foo<' + el + '> baz bar', { collapseWhitespace: true }), 'foo<' + el + '>bazbar'); - assert.equal(minify('foo <' + el + '> baz bar', { collapseWhitespace: true }), 'foo <' + el + '>bazbar'); - assert.equal(minify('foo<' + el + '> baz bar', { collapseWhitespace: true }), 'foo<' + el + '>baz bar'); - assert.equal(minify('
foo <' + el + '>baz bar
', { collapseWhitespace: true }), '
foo <' + el + '>baz bar
'); - assert.equal(minify('
foo<' + el + '>bazbar
', { collapseWhitespace: true }), '
foo<' + el + '>bazbar
'); - assert.equal(minify('
foo <' + el + '>bazbar
', { collapseWhitespace: true }), '
foo <' + el + '>bazbar
'); - assert.equal(minify('
foo<' + el + '>baz bar
', { collapseWhitespace: true }), '
foo<' + el + '>baz bar
'); - assert.equal(minify('
foo <' + el + '> baz bar
', { collapseWhitespace: true }), '
foo <' + el + '>baz bar
'); - assert.equal(minify('
foo<' + el + '> baz bar
', { collapseWhitespace: true }), '
foo<' + el + '>bazbar
'); - assert.equal(minify('
foo <' + el + '> baz bar
', { collapseWhitespace: true }), '
foo <' + el + '>bazbar
'); - assert.equal(minify('
foo<' + el + '> baz bar
', { collapseWhitespace: true }), '
foo<' + el + '>baz bar
'); + test_minify(assert, 'foo <' + el + '>baz bar', 'foo <' + el + '>baz bar', { collapseWhitespace: true }); + test_minify(assert, 'foo<' + el + '>bazbar', 'foo<' + el + '>bazbar', { collapseWhitespace: true }); + test_minify(assert, 'foo <' + el + '>bazbar', 'foo <' + el + '>bazbar', { collapseWhitespace: true }); + test_minify(assert, 'foo<' + el + '>baz bar', 'foo<' + el + '>baz bar', { collapseWhitespace: true }); + test_minify(assert, 'foo <' + el + '> baz bar', 'foo <' + el + '>baz bar', { collapseWhitespace: true }); + test_minify(assert, 'foo<' + el + '> baz bar', 'foo<' + el + '>bazbar', { collapseWhitespace: true }); + test_minify(assert, 'foo <' + el + '> baz bar', 'foo <' + el + '>bazbar', { collapseWhitespace: true }); + test_minify(assert, 'foo<' + el + '> baz bar', 'foo<' + el + '>baz bar', { collapseWhitespace: true }); + test_minify(assert, '
foo <' + el + '>baz bar
', '
foo <' + el + '>baz bar
', { collapseWhitespace: true }); + test_minify(assert, '
foo<' + el + '>bazbar
', '
foo<' + el + '>bazbar
', { collapseWhitespace: true }); + test_minify(assert, '
foo <' + el + '>bazbar
', '
foo <' + el + '>bazbar
', { collapseWhitespace: true }); + test_minify(assert, '
foo<' + el + '>baz bar
', '
foo<' + el + '>baz bar
', { collapseWhitespace: true }); + test_minify(assert, '
foo <' + el + '> baz bar
', '
foo <' + el + '>baz bar
', { collapseWhitespace: true }); + test_minify(assert, '
foo<' + el + '> baz bar
', '
foo<' + el + '>bazbar
', { collapseWhitespace: true }); + test_minify(assert, '
foo <' + el + '> baz bar
', '
foo <' + el + '>bazbar
', { collapseWhitespace: true }); + test_minify(assert, '
foo<' + el + '> baz bar
', '
foo<' + el + '>baz bar
', { collapseWhitespace: true }); }); [ [' foo ', 'foo'], @@ -252,39 +378,39 @@ QUnit.test('space normalization around text', function(assert) { ['a b c', 'a b c'], ['a b c', 'a b c'] ].forEach(function(inputs) { - assert.equal(minify(inputs[0], { + test_minify(assert, inputs[0], inputs[0], { collapseWhitespace: true, conservativeCollapse: true - }), inputs[0], inputs[0]); - assert.equal(minify(inputs[0], { collapseWhitespace: true }), inputs[1], inputs[0]); + }, inputs[0]); + test_minify(assert, inputs[0], inputs[1], { collapseWhitespace: true }, inputs[0]); var input = '
' + inputs[0] + '
'; - assert.equal(minify(input, { + test_minify(assert, input, input, { collapseWhitespace: true, conservativeCollapse: true - }), input, input); + }, input); var output = '
' + inputs[1] + '
'; - assert.equal(minify(input, { collapseWhitespace: true }), output, input); - }); - assert.equal(minify('

foo bar

', { collapseWhitespace: true }), '

foo bar

'); - assert.equal(minify('

foobar

', { collapseWhitespace: true }), '

foobar

'); - assert.equal(minify('

foo bar

', { collapseWhitespace: true }), '

foo bar

'); - assert.equal(minify('

foo bar

', { collapseWhitespace: true }), '

foo bar

'); - assert.equal(minify('

foo bar

', { collapseWhitespace: true }), '

foo bar

'); - assert.equal(minify('

foobar

', { collapseWhitespace: true }), '

foobar

'); - assert.equal(minify('

foo bar

', { collapseWhitespace: true }), '

foo bar

'); - assert.equal(minify('

foo bar

', { collapseWhitespace: true }), '

foo bar

'); - assert.equal(minify('

foo bar

', { collapseWhitespace: true }), '

foo bar

'); - assert.equal(minify('

foobar

', { collapseWhitespace: true }), '

foobar

'); - assert.equal(minify('

foo bar

', { collapseWhitespace: true }), '

foo bar

'); - assert.equal(minify('

foo bar

', { collapseWhitespace: true }), '

foo bar

'); - assert.equal(minify('

foo bar

', { collapseWhitespace: true }), '

foo bar

'); - assert.equal(minify('

foo bar

', { collapseWhitespace: true }), '

foo bar

'); - assert.equal(minify('

foo bar

', { collapseWhitespace: true }), '

foo bar

'); - assert.equal(minify('
Empty not
', { collapseWhitespace: true }), '
Empty not
'); - assert.equal(minify('
a c
', { + test_minify(assert, input, output, { collapseWhitespace: true }, input); + }); + test_minify(assert, '

foo bar

', '

foo bar

', { collapseWhitespace: true }); + test_minify(assert, '

foobar

', '

foobar

', { collapseWhitespace: true }); + test_minify(assert, '

foo bar

', '

foo bar

', { collapseWhitespace: true }); + test_minify(assert, '

foo bar

', '

foo bar

', { collapseWhitespace: true }); + test_minify(assert, '

foo bar

', '

foo bar

', { collapseWhitespace: true }); + test_minify(assert, '

foobar

', '

foobar

', { collapseWhitespace: true }); + test_minify(assert, '

foo bar

', '

foo bar

', { collapseWhitespace: true }); + test_minify(assert, '

foo bar

', '

foo bar

', { collapseWhitespace: true }); + test_minify(assert, '

foo bar

', '

foo bar

', { collapseWhitespace: true }); + test_minify(assert, '

foobar

', '

foobar

', { collapseWhitespace: true }); + test_minify(assert, '

foo bar

', '

foo bar

', { collapseWhitespace: true }); + test_minify(assert, '

foo bar

', '

foo bar

', { collapseWhitespace: true }); + test_minify(assert, '

foo bar

', '

foo bar

', { collapseWhitespace: true }); + test_minify(assert, '

foo bar

', '

foo bar

', { collapseWhitespace: true }); + test_minify(assert, '

foo bar

', '

foo bar

', { collapseWhitespace: true }); + test_minify(assert, '
Empty not
', '
Empty not
', { collapseWhitespace: true }); + test_minify(assert, '
a c
', '
a c
', { collapseWhitespace: true, removeComments: true - }), '
a c
'); + }); [ ' a c ', ' a c ', @@ -296,64 +422,64 @@ QUnit.test('space normalization around text', function(assert) { ' a c ', ' a c ' ].forEach(function(input) { - assert.equal(minify(input, { + test_minify(assert, input, input, { collapseWhitespace: true, conservativeCollapse: true - }), input, input); - assert.equal(minify(input, { + }, input); + test_minify(assert, input, 'a c', { collapseWhitespace: true, removeComments: true - }), 'a c', input); - assert.equal(minify(input, { + }, input); + test_minify(assert, input, ' a c ', { collapseWhitespace: true, conservativeCollapse: true, removeComments: true - }), ' a c ', input); + }, input); input = '

' + input + '

'; - assert.equal(minify(input, { + test_minify(assert, input, input, { collapseWhitespace: true, conservativeCollapse: true - }), input, input); - assert.equal(minify(input, { + }, input); + test_minify(assert, input, '

a c

', { collapseWhitespace: true, removeComments: true - }), '

a c

', input); - assert.equal(minify(input, { + }, input); + test_minify(assert, input, '

a c

', { collapseWhitespace: true, conservativeCollapse: true, removeComments: true - }), '

a c

', input); + }, input); }); input = '
  • foo
  • '; output = '
  • foo
  • '; - assert.equal(minify(input, { collapseWhitespace: true }), output); + test_minify(assert, input, output, { collapseWhitespace: true }); input = '
  • foo
  • '; - assert.equal(minify(input, { collapseWhitespace: true }), output); + test_minify(assert, input, output, { collapseWhitespace: true }); input = '
  • foo
  • '; - assert.equal(minify(input, { collapseWhitespace: true }), output); + test_minify(assert, input, output, { collapseWhitespace: true }); input = '
  • foo
  • '; - assert.equal(minify(input, { collapseWhitespace: true }), output); + test_minify(assert, input, output, { collapseWhitespace: true }); input = '
  • foo
  • '; - assert.equal(minify(input, { collapseWhitespace: true }), output); + test_minify(assert, input, output, { collapseWhitespace: true }); input = '
    foo bar
    '; output = '
    foo bar
    '; - assert.equal(minify(input, { collapseWhitespace: true }), output); + test_minify(assert, input, output, { collapseWhitespace: true }); input = ' '; output = ''; - assert.equal(minify(input, { collapseWhitespace: true }), output); + test_minify(assert, input, output, { collapseWhitespace: true }); input = ' '; output = ''; - assert.equal(minify(input, { collapseWhitespace: true }), output); + test_minify(assert, input, output, { collapseWhitespace: true }); input = '

    foo\u00A0bar\nbaz \u00A0\nmoo\t

    '; output = '

    foo\u00A0bar baz \u00A0 moo

    '; - assert.equal(minify(input, { collapseWhitespace: true }), output); + test_minify(assert, input, output, { collapseWhitespace: true }); input = '\n' + '\n' + ' bar \n' + '\n' + '\n'; output = ' bar '; - assert.equal(minify(input, { collapseWhitespace: true }), output); + test_minify(assert, input, output, { collapseWhitespace: true }); input = '
    \n' +
               'foo\n' +
               '
    \n' + @@ -361,130 +487,130 @@ QUnit.test('space normalization around text', function(assert) { '
    \n' + 'baz\n'; output = '
    \nfoo\n
    \nbar\n
    baz'; - assert.equal(minify(input, { collapseWhitespace: true }), output); + test_minify(assert, input, output, { collapseWhitespace: true }); }); QUnit.test('types of whitespace that should always be preserved', function(assert) { // Hair space: var input = '
    \u200afo\u200ao\u200a
    '; - assert.equal(minify(input, { collapseWhitespace: true }), input); + test_minify(assert, input, input, { collapseWhitespace: true }); // Hair space passed as HTML entity: var inputWithEntities = '
     fo o 
    '; - assert.equal(minify(inputWithEntities, { collapseWhitespace: true }), inputWithEntities); + test_minify(assert, inputWithEntities, inputWithEntities, { collapseWhitespace: true }); // Hair space passed as HTML entity, in decodeEntities:true mode: - assert.equal(minify(inputWithEntities, { collapseWhitespace: true, decodeEntities: true }), input); + test_minify(assert, inputWithEntities, input, { collapseWhitespace: true, decodeEntities: true }); // Non-breaking space: input = '
    \xa0fo\xa0o\xa0
    '; - assert.equal(minify(input, { collapseWhitespace: true }), input); + test_minify(assert, input, input, { collapseWhitespace: true }); // Non-breaking space passed as HTML entity: inputWithEntities = '
     fo o 
    '; - assert.equal(minify(inputWithEntities, { collapseWhitespace: true }), inputWithEntities); + test_minify(assert, inputWithEntities, inputWithEntities, { collapseWhitespace: true }); // Non-breaking space passed as HTML entity, in decodeEntities:true mode: - assert.equal(minify(inputWithEntities, { collapseWhitespace: true, decodeEntities: true }), input); + test_minify(assert, inputWithEntities, input, { collapseWhitespace: true, decodeEntities: true }); // Do not remove hair space when preserving line breaks between tags: input = '

    \u200a\n

    \n'; - assert.equal(minify(input, { collapseWhitespace: true, preserveLineBreaks: true }), input); + test_minify(assert, input, input, { collapseWhitespace: true, preserveLineBreaks: true }); // Preserve hair space in attributes: input = '

    '; - assert.equal(minify(input, { collapseWhitespace: true }), input); + test_minify(assert, input, input, { collapseWhitespace: true }); // Preserve hair space in class names when deduplicating and reordering: input = ''; - assert.equal(minify(input, { sortClassName: false }), input); - assert.equal(minify(input, { sortClassName: true }), input); + test_minify(assert, input, input, { sortClassName: false }); + test_minify(assert, input, input, { sortClassName: true }); }); QUnit.test('doctype normalization', function(assert) { var input; input = ''; - assert.equal(minify(input, { useShortDoctype: true }), ''); + test_minify(assert, input, '', { useShortDoctype: true }); input = ''; - assert.equal(minify(input, { useShortDoctype: true }), input); + test_minify(assert, input, input, { useShortDoctype: true }); input = ''; - assert.equal(minify(input, { useShortDoctype: false }), input); + test_minify(assert, input, input, { useShortDoctype: false }); }); QUnit.test('removing comments', function(assert) { var input; input = ''; - assert.equal(minify(input, { removeComments: true }), ''); + test_minify(assert, input, '', { removeComments: true }); input = '
    baz
    '; - assert.equal(minify(input, { removeComments: true }), '
    baz
    '); - assert.equal(minify(input, { removeComments: false }), input); + test_minify(assert, input, '
    baz
    ', { removeComments: true }); + test_minify(assert, input, input, { removeComments: false }); input = '

    foo

    '; - assert.equal(minify(input, { removeComments: true }), input); + test_minify(assert, input, input, { removeComments: true }); input = ''; - assert.equal(minify(input, { removeComments: true }), input); + test_minify(assert, input, input, { removeComments: true }); input = ''; - assert.equal(minify(input, { removeComments: true }), ''); + test_minify(assert, input, '', { removeComments: true }); }); QUnit.test('ignoring comments', function(assert) { var input, output; input = ''; - assert.equal(minify(input, { removeComments: true }), input); - assert.equal(minify(input, { removeComments: false }), input); + test_minify(assert, input, input, { removeComments: true }); + test_minify(assert, input, input, { removeComments: false }); input = '
    baz
    '; - assert.equal(minify(input, { removeComments: true }), input); - assert.equal(minify(input, { removeComments: false }), input); + test_minify(assert, input, input, { removeComments: true }); + test_minify(assert, input, input, { removeComments: false }); input = '
    baz
    '; - assert.equal(minify(input, { removeComments: true }), '
    baz
    '); - assert.equal(minify(input, { removeComments: false }), input); + test_minify(assert, input, '
    baz
    ', { removeComments: true }); + test_minify(assert, input, input, { removeComments: false }); input = ''; - assert.equal(minify(input, { removeComments: true }), ''); - assert.equal(minify(input, { removeComments: false }), input); + test_minify(assert, input, '', { removeComments: true }); + test_minify(assert, input, input, { removeComments: false }); input = '
    \n\n \t
    \n\n

    \n\n \n\n

    \n\n
    '; output = '

    '; - assert.equal(minify(input, { removeComments: true }), input); - assert.equal(minify(input, { removeComments: true, collapseWhitespace: true }), output); - assert.equal(minify(input, { removeComments: false }), input); - assert.equal(minify(input, { removeComments: false, collapseWhitespace: true }), output); + test_minify(assert, input, input, { removeComments: true }); + test_minify(assert, input, output, { removeComments: true, collapseWhitespace: true }); + test_minify(assert, input, input, { removeComments: false }); + test_minify(assert, input, output, { removeComments: false, collapseWhitespace: true }); input = '

    foo

    '; - assert.equal(minify(input, { removeComments: true }), input); + test_minify(assert, input, input, { removeComments: true }); }); QUnit.test('conditional comments', function(assert) { var input, output; input = 'test'; - assert.equal(minify(input, { removeComments: true }), input); + test_minify(assert, input, input, { removeComments: true }); input = ''; - assert.equal(minify(input, { removeComments: true }), input); + test_minify(assert, input, input, { removeComments: true }); input = 'test'; - assert.equal(minify(input, { removeComments: true }), input); + test_minify(assert, input, input, { removeComments: true }); input = 'test'; - assert.equal(minify(input, { removeComments: true }), input); + test_minify(assert, input, input, { removeComments: true }); input = ''; - assert.equal(minify(input, { removeComments: true }), input); + test_minify(assert, input, input, { removeComments: true }); input = ''; - assert.equal(minify(input, { removeComments: true }), input); + test_minify(assert, input, input, { removeComments: true }); input = '\n' + ' \n' + @@ -502,22 +628,22 @@ QUnit.test('conditional comments', function(assert) { ' alert("ie8!");\n' + ' \n' + ' '; - assert.equal(minify(input, { + test_minify(assert, input, output, { minifyJS: true, removeComments: true, collapseWhitespace: true, removeOptionalTags: true, removeScriptTypeAttributes: true - }), output); + }); output = ''; - assert.equal(minify(input, { + test_minify(assert, input, output, { minifyJS: true, removeComments: true, collapseWhitespace: true, removeOptionalTags: true, removeScriptTypeAttributes: true, processConditionalComments: true - }), output); + }); input = '\n' + '\n' + @@ -545,15 +671,15 @@ QUnit.test('conditional comments', function(assert) { '' + '' + 'Document'; - assert.equal(minify(input, { + test_minify(assert, input, output, { removeComments: true, collapseWhitespace: true - }), output); - assert.equal(minify(input, { + }); + test_minify(assert, input, output, { removeComments: true, collapseWhitespace: true, processConditionalComments: true - }), output); + }); }); QUnit.test('collapsing space in conditional comments', function(assert) { @@ -562,215 +688,215 @@ QUnit.test('collapsing space in conditional comments', function(assert) { input = ''; - assert.equal(minify(input, { removeComments: true }), input); - assert.equal(minify(input, { removeComments: true, collapseWhitespace: true }), input); + test_minify(assert, input, input, { removeComments: true }); + test_minify(assert, input, input, { removeComments: true, collapseWhitespace: true }); output = ''; - assert.equal(minify(input, { removeComments: true, processConditionalComments: true }), output); + test_minify(assert, input, output, { removeComments: true, processConditionalComments: true }); output = ''; - assert.equal(minify(input, { + test_minify(assert, input, output, { removeComments: true, collapseWhitespace: true, processConditionalComments: true - }), output); + }); input = ''; - assert.equal(minify(input, { removeComments: true }), input); - assert.equal(minify(input, { removeComments: true, collapseWhitespace: true }), input); + test_minify(assert, input, input, { removeComments: true }); + test_minify(assert, input, input, { removeComments: true, collapseWhitespace: true }); output = ''; - assert.equal(minify(input, { + test_minify(assert, input, output, { removeComments: true, collapseWhitespace: true, processConditionalComments: true - }), output); + }); }); QUnit.test('remove comments from scripts', function(assert) { var input, output; input = ''; - assert.equal(minify(input), input); + test_minify(assert, input, input); output = ''; - assert.equal(minify(input, { minifyJS: true }), output); + test_minify(assert, input, output, { minifyJS: true }); input = ''; - assert.equal(minify(input), input); + test_minify(assert, input, input); output = ''; - assert.equal(minify(input, { minifyJS: true }), output); + test_minify(assert, input, output, { minifyJS: true }); input = ''; - assert.equal(minify(input), input); + test_minify(assert, input, input); output = ''; - assert.equal(minify(input, { minifyJS: true }), output); + test_minify(assert, input, output, { minifyJS: true }); input = ''; - assert.equal(minify(input), input); - assert.equal(minify(input, { minifyJS: true }), input); + test_minify(assert, input, input); + test_minify(assert, input, input, { minifyJS: true }); input = ''; - assert.equal(minify(input), input); - assert.equal(minify(input, { minifyJS: true }), input); + test_minify(assert, input, input); + test_minify(assert, input, input, { minifyJS: true }); input = ''; - assert.equal(minify(input), input); + test_minify(assert, input, input); output = ''; - assert.equal(minify(input, { minifyJS: true }), output); + test_minify(assert, input, output, { minifyJS: true }); input = ''; - assert.equal(minify(input), input); - assert.equal(minify(input, { minifyJS: true }), input); + test_minify(assert, input, input); + test_minify(assert, input, input, { minifyJS: true }); input = ''; - assert.equal(minify(input), input); + test_minify(assert, input, input); output = ''; - assert.equal(minify(input, { minifyJS: true }), output); + test_minify(assert, input, output, { minifyJS: true }); input = ''; - assert.equal(minify(input), input); + test_minify(assert, input, input); output = ''; - assert.equal(minify(input, { minifyJS: true }), output); + test_minify(assert, input, output, { minifyJS: true }); input = ''; - assert.equal(minify(input), input); - assert.equal(minify(input, { minifyJS: true }), input); + test_minify(assert, input, input); + test_minify(assert, input, input, { minifyJS: true }); }); QUnit.test('remove comments from styles', function(assert) { var input, output; input = ''; - assert.equal(minify(input), input); + test_minify(assert, input, input); output = ''; - assert.equal(minify(input, { minifyCSS: true }), output); + test_minify(assert, input, output, { minifyCSS: true }); input = ''; - assert.equal(minify(input), input); + test_minify(assert, input, input); output = ''; - assert.equal(minify(input, { minifyCSS: true }), output); + test_minify(assert, input, output, { minifyCSS: true }); input = ''; - assert.equal(minify(input), input); + test_minify(assert, input, input); output = ''; - assert.equal(minify(input, { minifyCSS: true }), output); + test_minify(assert, input, output, { minifyCSS: true }); input = ''; - assert.equal(minify(input), input); + test_minify(assert, input, input); output = ''; - assert.equal(minify(input, { minifyCSS: true }), output); + test_minify(assert, input, output, { minifyCSS: true }); input = ''; - assert.equal(minify(input), input); + test_minify(assert, input, input); output = ''; - assert.equal(minify(input, { minifyCSS: true }), output); + test_minify(assert, input, output, { minifyCSS: true }); input = ''; - assert.equal(minify(input), input); + test_minify(assert, input, input); output = ''; - assert.equal(minify(input, { minifyCSS: true }), output); + test_minify(assert, input, output, { minifyCSS: true }); input = ''; - assert.equal(minify(input), input); + test_minify(assert, input, input); output = ''; - assert.equal(minify(input, { minifyCSS: true }), output); + test_minify(assert, input, output, { minifyCSS: true }); input = ''; - assert.equal(minify(input), input); + test_minify(assert, input, input); output = ''; - assert.equal(minify(input, { minifyCSS: true }), output); + test_minify(assert, input, output, { minifyCSS: true }); input = ''; - assert.equal(minify(input), input); - assert.equal(minify(input, { minifyCSS: true }), input); + test_minify(assert, input, input); + test_minify(assert, input, input, { minifyCSS: true }); }); QUnit.test('remove CDATA sections from scripts/styles', function(assert) { var input, output; input = ''; - assert.equal(minify(input), input); - assert.equal(minify(input, { minifyJS: true }), input); + test_minify(assert, input, input); + test_minify(assert, input, input, { minifyJS: true }); input = ''; - assert.equal(minify(input), input); - assert.equal(minify(input, { minifyJS: true }), input); + test_minify(assert, input, input); + test_minify(assert, input, input, { minifyJS: true }); input = ''; - assert.equal(minify(input), input); - assert.equal(minify(input, { minifyJS: true }), input); + test_minify(assert, input, input); + test_minify(assert, input, input, { minifyJS: true }); input = ''; - assert.equal(minify(input), input); - assert.equal(minify(input, { minifyJS: true }), input); + test_minify(assert, input, input); + test_minify(assert, input, input, { minifyJS: true }); input = ''; - assert.equal(minify(input), input); - assert.equal(minify(input, { minifyJS: true }), input); + test_minify(assert, input, input); + test_minify(assert, input, input, { minifyJS: true }); input = ''; - assert.equal(minify(input), input); + test_minify(assert, input, input); output = ''; - assert.equal(minify(input, { minifyJS: true }), output); + test_minify(assert, input, output, { minifyJS: true }); input = ''; - assert.equal(minify(input), input); + test_minify(assert, input, input); output = ''; - assert.equal(minify(input, { minifyJS: true }), output); + test_minify(assert, input, output, { minifyJS: true }); input = ''; - assert.equal(minify(input), input); + test_minify(assert, input, input); output = ''; - assert.equal(minify(input, { minifyJS: true }), output); + test_minify(assert, input, output, { minifyJS: true }); input = ''; - assert.equal(minify(input), input); + test_minify(assert, input, input); output = ''; - assert.equal(minify(input, { minifyJS: true }), output); + test_minify(assert, input, output, { minifyJS: true }); input = ''; - assert.equal(minify(input), input); + test_minify(assert, input, input); output = ''; - assert.equal(minify(input, { minifyCSS: true }), output); + test_minify(assert, input, output, { minifyCSS: true }); input = ''; - assert.equal(minify(input), input); + test_minify(assert, input, input); output = ''; - assert.equal(minify(input, { minifyCSS: true }), output); + test_minify(assert, input, output, { minifyCSS: true }); input = ''; - assert.equal(minify(input), input); + test_minify(assert, input, input); output = ''; - assert.equal(minify(input, { minifyCSS: true }), output); + test_minify(assert, input, output, { minifyCSS: true }); input = ''; - assert.equal(minify(input), input); + test_minify(assert, input, input); output = ''; - assert.equal(minify(input, { minifyCSS: true }), output); + test_minify(assert, input, output, { minifyCSS: true }); input = ''; - assert.equal(minify(input), input); + test_minify(assert, input, input); output = ''; - assert.equal(minify(input, { minifyCSS: true }), output); + test_minify(assert, input, output, { minifyCSS: true }); input = ''; - assert.equal(minify(input), input); + test_minify(assert, input, input); output = ''; - assert.equal(minify(input, { minifyCSS: true }), output); + test_minify(assert, input, output, { minifyCSS: true }); input = ''; - assert.equal(minify(input), input); + test_minify(assert, input, input); output = ''; - assert.equal(minify(input, { minifyCSS: true }), output); + test_minify(assert, input, output, { minifyCSS: true }); input = ''; - assert.equal(minify(input), input); - assert.equal(minify(input, { minifyCSS: true }), input); + test_minify(assert, input, input); + test_minify(assert, input, input, { minifyCSS: true }); }); QUnit.test('custom processors', function(assert) { @@ -781,125 +907,125 @@ QUnit.test('custom processors', function(assert) { } input = ''; - assert.equal(minify(input), input); - assert.equal(minify(input, { minifyCSS: null }), input); - assert.equal(minify(input, { minifyCSS: false }), input); + test_minify(assert, input, input); + test_minify(assert, input, input, { minifyCSS: null }); + test_minify(assert, input, input, { minifyCSS: false }); output = ''; - assert.equal(minify(input, { minifyCSS: css }), output); + test_minify(assert, input, output, { minifyCSS: css }); input = '

    '; - assert.equal(minify(input), input); - assert.equal(minify(input, { minifyCSS: null }), input); - assert.equal(minify(input, { minifyCSS: false }), input); + test_minify(assert, input, input); + test_minify(assert, input, input, { minifyCSS: null }); + test_minify(assert, input, input, { minifyCSS: false }); output = '

    '; - assert.equal(minify(input, { minifyCSS: css }), output); + test_minify(assert, input, output, { minifyCSS: css }); input = ''; - assert.equal(minify(input), input); - assert.equal(minify(input, { minifyCSS: null }), input); - assert.equal(minify(input, { minifyCSS: false }), input); + test_minify(assert, input, input); + test_minify(assert, input, input, { minifyCSS: null }); + test_minify(assert, input, input, { minifyCSS: false }); output = ''; - assert.equal(minify(input, { minifyCSS: css }), output); + test_minify(assert, input, output, { minifyCSS: css }); input = ''; - assert.equal(minify(input), input); - assert.equal(minify(input, { minifyCSS: null }), input); - assert.equal(minify(input, { minifyCSS: false }), input); + test_minify(assert, input, input); + test_minify(assert, input, input, { minifyCSS: null }); + test_minify(assert, input, input, { minifyCSS: false }); output = ''; - assert.equal(minify(input, { minifyCSS: css }), output); + test_minify(assert, input, output, { minifyCSS: css }); function js(text, inline) { return inline ? 'Inline JS' : 'Normal JS'; } input = ''; - assert.equal(minify(input), input); - assert.equal(minify(input, { minifyJS: null }), input); - assert.equal(minify(input, { minifyJS: false }), input); + test_minify(assert, input, input); + test_minify(assert, input, input, { minifyJS: null }); + test_minify(assert, input, input, { minifyJS: false }); output = ''; - assert.equal(minify(input, { minifyJS: js }), output); + test_minify(assert, input, output, { minifyJS: js }); input = '

    '; - assert.equal(minify(input), input); - assert.equal(minify(input, { minifyJS: null }), input); - assert.equal(minify(input, { minifyJS: false }), input); + test_minify(assert, input, input); + test_minify(assert, input, input, { minifyJS: null }); + test_minify(assert, input, input, { minifyJS: false }); output = '

    '; - assert.equal(minify(input, { minifyJS: js }), output); + test_minify(assert, input, output, { minifyJS: js }); function url() { return 'URL'; } input = 'bar'; - assert.equal(minify(input), input); - assert.equal(minify(input, { minifyURLs: null }), input); - assert.equal(minify(input, { minifyURLs: false }), input); + test_minify(assert, input, input); + test_minify(assert, input, input, { minifyURLs: null }); + test_minify(assert, input, input, { minifyURLs: false }); output = 'bar'; - assert.equal(minify(input, { minifyURLs: url }), output); + test_minify(assert, input, output, { minifyURLs: url }); input = ''; - assert.equal(minify(input), input); - assert.equal(minify(input, { minifyURLs: null }), input); - assert.equal(minify(input, { minifyURLs: false }), input); - assert.equal(minify(input, { minifyURLs: url }), input); + test_minify(assert, input, input); + test_minify(assert, input, input, { minifyURLs: null }); + test_minify(assert, input, input, { minifyURLs: false }); + test_minify(assert, input, input, { minifyURLs: url }); output = ''; - assert.equal(minify(input, { minifyCSS: true, minifyURLs: url }), output); + test_minify(assert, input, output, { minifyCSS: true, minifyURLs: url }); }); QUnit.test('empty attributes', function(assert) { var input; input = '

    x

    '; - assert.equal(minify(input, { removeEmptyAttributes: true }), '

    x

    '); + test_minify(assert, input, '

    x

    ', { removeEmptyAttributes: true }); input = '

    x

    '; - assert.equal(minify(input, { removeEmptyAttributes: true }), '

    x

    '); + test_minify(assert, input, '

    x

    ', { removeEmptyAttributes: true }); input = ''; - assert.equal(minify(input, { removeEmptyAttributes: true }), ''); + test_minify(assert, input, '', { removeEmptyAttributes: true }); input = ''; - assert.equal(minify(input, { removeEmptyAttributes: true }), ''); + test_minify(assert, input, '', { removeEmptyAttributes: true }); input = ''; - assert.equal(minify(input, { removeEmptyAttributes: true }), ''); + test_minify(assert, input, '', { removeEmptyAttributes: true }); // preserve unrecognized attribute // remove recognized attrs with unspecified values input = '
    '; - assert.equal(minify(input, { removeEmptyAttributes: true }), '
    '); + test_minify(assert, input, '
    ', { removeEmptyAttributes: true }); // additional remove attributes input = ''; - assert.equal(minify(input, { removeEmptyAttributes: function(attrName, tag) { return tag === 'img' && attrName === 'src'; } }), ''); + test_minify(assert, input, '', { removeEmptyAttributes: function(attrName, tag) { return tag === 'img' && attrName === 'src'; } }); }); QUnit.test('cleaning class/style attributes', function(assert) { var input, output; input = '

    foo bar baz

    '; - assert.equal(minify(input), '

    foo bar baz

    '); + test_minify(assert, input, '

    foo bar baz

    '); input = '

    foo bar baz

    '; - assert.equal(minify(input), '

    foo bar baz

    '); - assert.equal(minify(input, { removeAttributeQuotes: true }), '

    foo bar baz

    '); + test_minify(assert, input, '

    foo bar baz

    '); + test_minify(assert, input, '

    foo bar baz

    ', { removeAttributeQuotes: true }); input = '

    foo bar baz

    '; output = '

    foo bar baz

    '; - assert.equal(minify(input), output); + test_minify(assert, input, output); input = '

    foo bar baz

    '; output = '

    foo bar baz

    '; - assert.equal(minify(input), output); + test_minify(assert, input, output); input = '

    '; output = '

    '; - assert.equal(minify(input), output); + test_minify(assert, input, output); input = '

    '; output = '

    '; - assert.equal(minify(input), output); + test_minify(assert, input, output); }); QUnit.test('cleaning URI-based attributes', function(assert) { @@ -907,41 +1033,41 @@ QUnit.test('cleaning URI-based attributes', function(assert) { input = 'x'; output = 'x'; - assert.equal(minify(input), output); + test_minify(assert, input, output); input = 'x'; output = 'x'; - assert.equal(minify(input), output); + test_minify(assert, input, output); input = ''; output = ''; - assert.equal(minify(input), output); + test_minify(assert, input, output); input = ''; output = ''; - assert.equal(minify(input), output); + test_minify(assert, input, output); input = '
    '; output = '
    '; - assert.equal(minify(input), output); + test_minify(assert, input, output); input = '

    foobar

    '; output = '

    foobar

    '; - assert.equal(minify(input), output); + test_minify(assert, input, output); input = ''; output = ''; - assert.equal(minify(input), output); + test_minify(assert, input, output); input = ''; output = ''; - assert.equal(minify(input), output); + test_minify(assert, input, output); input = 'foo'; - assert.equal(minify(input), input); + test_minify(assert, input, input); input = '
    blah
    '; - assert.equal(minify(input), input); + test_minify(assert, input, input); }); QUnit.test('cleaning Number-based attributes', function(assert) { @@ -949,27 +1075,27 @@ QUnit.test('cleaning Number-based attributes', function(assert) { input = 'x'; output = 'x'; - assert.equal(minify(input), output); + test_minify(assert, input, output); input = ''; output = ''; - assert.equal(minify(input), output); + test_minify(assert, input, output); input = ''; output = ''; - assert.equal(minify(input), output); + test_minify(assert, input, output); input = ''; output = ''; - assert.equal(minify(input), output); + test_minify(assert, input, output); input = ''; output = ''; - assert.equal(minify(input), output); + test_minify(assert, input, output); input = 'x'; output = 'x'; - assert.equal(minify(input), output); + test_minify(assert, input, output); }); QUnit.test('cleaning other attributes', function(assert) { @@ -977,50 +1103,50 @@ QUnit.test('cleaning other attributes', function(assert) { input = 'blah'; output = 'blah'; - assert.equal(minify(input), output); + test_minify(assert, input, output); input = '

    x'; output = '

    x

    '; - assert.equal(minify(input), output); + test_minify(assert, input, output); }); QUnit.test('removing redundant attributes (<form method="get" ...>)', function(assert) { var input; input = '
    hello world
    '; - assert.equal(minify(input, { removeRedundantAttributes: true }), '
    hello world
    '); + test_minify(assert, input, '
    hello world
    ', { removeRedundantAttributes: true }); input = '
    hello world
    '; - assert.equal(minify(input, { removeRedundantAttributes: true }), '
    hello world
    '); + test_minify(assert, input, '
    hello world
    ', { removeRedundantAttributes: true }); }); QUnit.test('removing redundant attributes (<input type="text" ...>)', function(assert) { var input; input = ''; - assert.equal(minify(input, { removeRedundantAttributes: true }), ''); + test_minify(assert, input, '', { removeRedundantAttributes: true }); input = ''; - assert.equal(minify(input, { removeRedundantAttributes: true }), ''); + test_minify(assert, input, '', { removeRedundantAttributes: true }); input = ''; - assert.equal(minify(input, { removeRedundantAttributes: true }), ''); + test_minify(assert, input, '', { removeRedundantAttributes: true }); }); QUnit.test('removing redundant attributes (<a name="..." id="..." ...>)', function(assert) { var input; input = 'blah'; - assert.equal(minify(input, { removeRedundantAttributes: true }), 'blah'); + test_minify(assert, input, 'blah', { removeRedundantAttributes: true }); input = ''; - assert.equal(minify(input, { removeRedundantAttributes: true }), input); + test_minify(assert, input, input, { removeRedundantAttributes: true }); input = 'blah'; - assert.equal(minify(input, { removeRedundantAttributes: true }), input); + test_minify(assert, input, input, { removeRedundantAttributes: true }); input = 'blah'; - assert.equal(minify(input, { removeRedundantAttributes: true }), 'blah'); + test_minify(assert, input, 'blah', { removeRedundantAttributes: true }); }); QUnit.test('removing redundant attributes (<script src="..." charset="...">)', function(assert) { @@ -1028,125 +1154,125 @@ QUnit.test('removing redundant attributes (<script src="..." charset="...">)' input = ''; output = ''; - assert.equal(minify(input, { removeRedundantAttributes: true }), output); + test_minify(assert, input, output, { removeRedundantAttributes: true }); input = ''; - assert.equal(minify(input, { removeRedundantAttributes: true }), input); + test_minify(assert, input, input, { removeRedundantAttributes: true }); input = ''; output = ''; - assert.equal(minify(input, { removeRedundantAttributes: true }), output); + test_minify(assert, input, output, { removeRedundantAttributes: true }); }); QUnit.test('removing redundant attributes (<... language="javascript" ...>)', function(assert) { var input; input = ''; - assert.equal(minify(input, { removeRedundantAttributes: true }), ''); + test_minify(assert, input, '', { removeRedundantAttributes: true }); input = ''; - assert.equal(minify(input, { removeRedundantAttributes: true }), ''); + test_minify(assert, input, '', { removeRedundantAttributes: true }); }); QUnit.test('removing redundant attributes (<area shape="rect" ...>)', function(assert) { var input = ''; var output = ''; - assert.equal(minify(input, { removeRedundantAttributes: true }), output); + test_minify(assert, input, output, { removeRedundantAttributes: true }); }); QUnit.test('removing redundant attributes (<... = "javascript: ..." ...>)', function(assert) { var input; input = '

    x

    '; - assert.equal(minify(input), '

    x

    '); + test_minify(assert, input, '

    x

    '); input = '

    x

    '; - assert.equal(minify(input, { removeAttributeQuotes: true }), '

    x

    '); + test_minify(assert, input, '

    x

    ', { removeAttributeQuotes: true }); input = '

    x

    '; - assert.equal(minify(input), '

    x

    '); + test_minify(assert, input, '

    x

    '); input = '

    x

    '; - assert.equal(minify(input), input); + test_minify(assert, input, input); }); QUnit.test('removing javascript type attributes', function(assert) { var input, output; input = ''; - assert.equal(minify(input, { removeScriptTypeAttributes: false }), input); + test_minify(assert, input, input, { removeScriptTypeAttributes: false }); output = ''; - assert.equal(minify(input, { removeScriptTypeAttributes: true }), output); + test_minify(assert, input, output, { removeScriptTypeAttributes: true }); input = ''; - assert.equal(minify(input, { removeScriptTypeAttributes: false }), input); + test_minify(assert, input, input, { removeScriptTypeAttributes: false }); output = ''; - assert.equal(minify(input, { removeScriptTypeAttributes: true }), output); + test_minify(assert, input, output, { removeScriptTypeAttributes: true }); input = ''; output = ''; - assert.equal(minify(input, { removeScriptTypeAttributes: true }), output); + test_minify(assert, input, output, { removeScriptTypeAttributes: true }); input = ''; output = ''; - assert.equal(minify(input, { removeScriptTypeAttributes: true }), output); + test_minify(assert, input, output, { removeScriptTypeAttributes: true }); input = ''; output = ''; - assert.equal(minify(input, { removeScriptTypeAttributes: true }), output); + test_minify(assert, input, output, { removeScriptTypeAttributes: true }); }); QUnit.test('removing type="text/css" attributes', function(assert) { var input, output; input = ''; - assert.equal(minify(input, { removeStyleLinkTypeAttributes: false }), input); + test_minify(assert, input, input, { removeStyleLinkTypeAttributes: false }); output = ''; - assert.equal(minify(input, { removeStyleLinkTypeAttributes: true }), output); + test_minify(assert, input, output, { removeStyleLinkTypeAttributes: true }); input = ''; - assert.equal(minify(input, { removeStyleLinkTypeAttributes: false }), input); + test_minify(assert, input, input, { removeStyleLinkTypeAttributes: false }); output = ''; - assert.equal(minify(input, { removeStyleLinkTypeAttributes: true }), output); + test_minify(assert, input, output, { removeStyleLinkTypeAttributes: true }); input = ''; output = ''; - assert.equal(minify(input, { removeStyleLinkTypeAttributes: true }), output); + test_minify(assert, input, output, { removeStyleLinkTypeAttributes: true }); input = ''; - assert.equal(minify(input, { removeStyleLinkTypeAttributes: true }), input); + test_minify(assert, input, input, { removeStyleLinkTypeAttributes: true }); input = ''; output = ''; - assert.equal(minify(input, { removeStyleLinkTypeAttributes: true }), output); + test_minify(assert, input, output, { removeStyleLinkTypeAttributes: true }); input = ''; - assert.equal(minify(input, { removeStyleLinkTypeAttributes: true }), input); + test_minify(assert, input, input, { removeStyleLinkTypeAttributes: true }); }); QUnit.test('removing attribute quotes', function(assert) { var input; input = '

    foo

    '; - assert.equal(minify(input, { removeAttributeQuotes: true }), '

    foo

    '); + test_minify(assert, input, '

    foo

    ', { removeAttributeQuotes: true }); input = ''; - assert.equal(minify(input, { removeAttributeQuotes: true }), ''); + test_minify(assert, input, '', { removeAttributeQuotes: true }); input = 'x'; - assert.equal(minify(input, { removeAttributeQuotes: true }), 'x'); + test_minify(assert, input, 'x', { removeAttributeQuotes: true }); input = '\nfoo\n\n'; - assert.equal(minify(input, { removeAttributeQuotes: true }), '\nfoo\n\n'); + test_minify(assert, input, '\nfoo\n\n', { removeAttributeQuotes: true }); input = '\nfoo\n\n'; - assert.equal(minify(input, { removeAttributeQuotes: true }), '\nfoo\n\n'); + test_minify(assert, input, '\nfoo\n\n', { removeAttributeQuotes: true }); input = '\nfoo\n\n'; - assert.equal(minify(input, { removeAttributeQuotes: true, removeEmptyAttributes: true }), '\nfoo\n\n'); + test_minify(assert, input, '\nfoo\n\n', { removeAttributeQuotes: true, removeEmptyAttributes: true }); input = '

    '; - assert.equal(minify(input, { removeAttributeQuotes: true }), '

    '); + test_minify(assert, input, '

    ', { removeAttributeQuotes: true }); }); QUnit.test('preserving custom attribute-wrapping markup', function(assert) { @@ -1158,10 +1284,10 @@ QUnit.test('preserving custom attribute-wrapping markup', function(assert) { }; input = ''; - assert.equal(minify(input, customAttrOptions), input); + test_minify(assert, input, input, customAttrOptions); input = ''; - assert.equal(minify(input, customAttrOptions), input); + test_minify(assert, input, input, customAttrOptions); // With multiple rules customAttrOptions = { @@ -1172,16 +1298,16 @@ QUnit.test('preserving custom attribute-wrapping markup', function(assert) { }; input = ''; - assert.equal(minify(input, customAttrOptions), input); + test_minify(assert, input, input, customAttrOptions); input = ''; - assert.equal(minify(input, customAttrOptions), input); + test_minify(assert, input, input, customAttrOptions); input = ''; - assert.equal(minify(input, customAttrOptions), input); + test_minify(assert, input, input, customAttrOptions); input = ''; - assert.equal(minify(input, customAttrOptions), input); + test_minify(assert, input, input, customAttrOptions); // With multiple rules and richer options customAttrOptions = { @@ -1194,13 +1320,13 @@ QUnit.test('preserving custom attribute-wrapping markup', function(assert) { }; input = ''; - assert.equal(minify(input, customAttrOptions), ''); + test_minify(assert, input, '', customAttrOptions); input = ''; - assert.equal(minify(input, customAttrOptions), ''); + test_minify(assert, input, '', customAttrOptions); customAttrOptions.keepClosingSlash = true; - assert.equal(minify(input, customAttrOptions), ''); + test_minify(assert, input, '', customAttrOptions); }); QUnit.test('preserving custom attribute-joining markup', function(assert) { @@ -1210,9 +1336,9 @@ QUnit.test('preserving custom attribute-joining markup', function(assert) { customAttrAssign: [polymerConditionalAttributeJoin] }; input = '
    '; - assert.equal(minify(input, customAttrOptions), input); + test_minify(assert, input, input, customAttrOptions); input = '
    '; - assert.equal(minify(input, customAttrOptions), input); + test_minify(assert, input, input, customAttrOptions); }); QUnit.test('collapsing whitespace', function(assert) { @@ -1220,37 +1346,37 @@ QUnit.test('collapsing whitespace', function(assert) { input = ''; output = ''; - assert.equal(minify(input, { collapseWhitespace: true }), output); + test_minify(assert, input, output, { collapseWhitespace: true }); input = '

    foo

    bar

    \n\n \n\t\t
    baz
    '; output = '

    foo

    bar

    baz
    '; - assert.equal(minify(input, { collapseWhitespace: true }), output); + test_minify(assert, input, output, { collapseWhitespace: true }); input = '

    foo bar

    '; output = '

    foo bar

    '; - assert.equal(minify(input, { collapseWhitespace: true }), output); + test_minify(assert, input, output, { collapseWhitespace: true }); input = '

    foo\nbar

    '; output = '

    foo bar

    '; - assert.equal(minify(input, { collapseWhitespace: true }), output); + test_minify(assert, input, output, { collapseWhitespace: true }); input = '

    foo blah 22 bar

    '; output = '

    foo blah 22 bar

    '; - assert.equal(minify(input, { collapseWhitespace: true }), output); + test_minify(assert, input, output, { collapseWhitespace: true }); input = ''; output = ''; - assert.equal(minify(input, { collapseWhitespace: true }), output); + test_minify(assert, input, output, { collapseWhitespace: true }); input = '
    '; output = '
    '; - assert.equal(minify(input, { collapseWhitespace: true }), output); + test_minify(assert, input, output, { collapseWhitespace: true }); input = '
     $foo = "baz"; 
    '; output = '
     $foo = "baz"; 
    '; - assert.equal(minify(input, { collapseWhitespace: true }), output); + test_minify(assert, input, output, { collapseWhitespace: true }); output = '
    $foo = "baz";
    '; - assert.equal(minify(input, { collapseWhitespace: true, caseSensitive: true }), output); + test_minify(assert, input, output, { collapseWhitespace: true, caseSensitive: true }); input = '\r\n\r\n\r\n' + '\r\n\r\n\r\n' + @@ -1268,153 +1394,153 @@ QUnit.test('collapsing whitespace', function(assert) { '' + '
           \r\nxxxx
    x Hello billy ' + '
    ';
    -  assert.equal(minify(input, { collapseWhitespace: true }), output);
    +  test_minify(assert, input, output, { collapseWhitespace: true });
     
       input = '
       hello     world 
    '; output = '
       hello     world 
    '; - assert.equal(minify(input, { collapseWhitespace: true }), output); + test_minify(assert, input, output, { collapseWhitespace: true }); input = '
       hello     world 
    '; output = '
       hello     world 
    '; - assert.equal(minify(input, { collapseWhitespace: true }), output); + test_minify(assert, input, output, { collapseWhitespace: true }); input = ''; output = ''; - assert.equal(minify(input, { collapseWhitespace: true }), output); + test_minify(assert, input, output, { collapseWhitespace: true }); input = ''; output = ''; - assert.equal(minify(input, { collapseWhitespace: true }), output); + test_minify(assert, input, output, { collapseWhitespace: true }); }); QUnit.test('removing empty elements', function(assert) { var input, output; - assert.equal(minify('

    x

    ', { removeEmptyElements: true }), '

    x

    '); - assert.equal(minify('

    ', { removeEmptyElements: true }), ''); + test_minify(assert, '

    x

    ', '

    x

    ', { removeEmptyElements: true }); + test_minify(assert, '

    ', '', { removeEmptyElements: true }); input = '

    foobar

    '; output = '

    foobar

    '; - assert.equal(minify(input, { removeEmptyElements: true }), output); + test_minify(assert, input, output, { removeEmptyElements: true }); input = ''; output = ''; - assert.equal(minify(input, { removeEmptyElements: true }), output); + test_minify(assert, input, output, { removeEmptyElements: true }); input = ''; output = ''; - assert.equal(minify(input, { removeEmptyElements: true }), output); + test_minify(assert, input, output, { removeEmptyElements: true }); input = ''; - assert.equal(minify(input, { removeEmptyElements: true }), input); + test_minify(assert, input, input, { removeEmptyElements: true }); input = ''; - assert.equal(minify(input, { removeEmptyElements: true }), input); + test_minify(assert, input, input, { removeEmptyElements: true }); input = ''; output = ''; - assert.equal(minify(input, { removeEmptyElements: true }), output); + test_minify(assert, input, output, { removeEmptyElements: true }); input = ''; - assert.equal(minify(input, { removeEmptyElements: true }), input); + test_minify(assert, input, input, { removeEmptyElements: true }); input = ''; output = ''; - assert.equal(minify(input, { removeEmptyElements: true }), output); + test_minify(assert, input, output, { removeEmptyElements: true }); input = ''; - assert.equal(minify(input, { removeEmptyElements: true }), input); + test_minify(assert, input, input, { removeEmptyElements: true }); input = ''; output = ''; - assert.equal(minify(input, { removeEmptyElements: true }), output); + test_minify(assert, input, output, { removeEmptyElements: true }); input = ''; - assert.equal(minify(input, { removeEmptyElements: true }), input); + test_minify(assert, input, input, { removeEmptyElements: true }); input = ''; output = ''; - assert.equal(minify(input, { removeEmptyElements: true }), output); + test_minify(assert, input, output, { removeEmptyElements: true }); input = ''; - assert.equal(minify(input, { removeEmptyElements: true }), input); + test_minify(assert, input, input, { removeEmptyElements: true }); input = ''; - assert.equal(minify(input, { removeEmptyElements: true }), input); + test_minify(assert, input, input, { removeEmptyElements: true }); input = '
    helloworld
    '; - assert.equal(minify(input, { removeEmptyElements: true }), input); + test_minify(assert, input, input, { removeEmptyElements: true }); input = '

    x

    '; output = '

    x

    '; - assert.equal(minify(input, { removeEmptyElements: true }), output); + test_minify(assert, input, output, { removeEmptyElements: true }); input = '
    x
    y
    blah
    foo
    z
    '; output = '
    x
    y
    blah
    foo
    z
    '; - assert.equal(minify(input, { removeEmptyElements: true }), output); + test_minify(assert, input, output, { removeEmptyElements: true }); input = ''; - assert.equal(minify(input, { removeEmptyElements: true }), input); + test_minify(assert, input, input, { removeEmptyElements: true }); input = '

    '; output = ''; - assert.equal(minify(input, { removeEmptyElements: true }), output); + test_minify(assert, input, output, { removeEmptyElements: true }); input = ''; - assert.equal(minify(input, { removeEmptyElements: true }), input); + test_minify(assert, input, input, { removeEmptyElements: true }); input = ''; - assert.equal(minify(input, { removeEmptyElements: true }), ''); + test_minify(assert, input, '', { removeEmptyElements: true }); input = '
    after
    '; output = '
    after
    '; - assert.equal(minify(input, { removeEmptyElements: true }), output); + test_minify(assert, input, output, { removeEmptyElements: true }); output = '
    after
    '; - assert.equal(minify(input, { collapseWhitespace: true, removeEmptyElements: true }), output); + test_minify(assert, input, output, { collapseWhitespace: true, removeEmptyElements: true }); input = '
    before
    '; output = '
    before
    '; - assert.equal(minify(input, { removeEmptyElements: true }), output); + test_minify(assert, input, output, { removeEmptyElements: true }); output = '
    before
    '; - assert.equal(minify(input, { collapseWhitespace: true, removeEmptyElements: true }), output); + test_minify(assert, input, output, { collapseWhitespace: true, removeEmptyElements: true }); input = '
    both
    '; output = '
    both
    '; - assert.equal(minify(input, { removeEmptyElements: true }), output); + test_minify(assert, input, output, { removeEmptyElements: true }); output = '
    both
    '; - assert.equal(minify(input, { collapseWhitespace: true, removeEmptyElements: true }), output); + test_minify(assert, input, output, { collapseWhitespace: true, removeEmptyElements: true }); input = '
    unary
    '; output = '
    unary
    '; - assert.equal(minify(input, { removeEmptyElements: true }), output); + test_minify(assert, input, output, { removeEmptyElements: true }); output = '
    unary
    '; - assert.equal(minify(input, { collapseWhitespace: true, removeEmptyElements: true }), output); + test_minify(assert, input, output, { collapseWhitespace: true, removeEmptyElements: true }); input = '
    Empty
    '; - assert.equal(minify(input, { removeEmptyElements: true }), input); + test_minify(assert, input, input, { removeEmptyElements: true }); output = '
    Empty
    '; - assert.equal(minify(input, { collapseWhitespace: true, removeEmptyElements: true }), output); + test_minify(assert, input, output, { collapseWhitespace: true, removeEmptyElements: true }); }); QUnit.test('collapsing boolean attributes', function(assert) { var input, output; input = ''; - assert.equal(minify(input, { collapseBooleanAttributes: true }), ''); + test_minify(assert, input, '', { collapseBooleanAttributes: true }); input = ''; - assert.equal(minify(input, { collapseBooleanAttributes: true }), ''); + test_minify(assert, input, '', { collapseBooleanAttributes: true }); input = ''; - assert.equal(minify(input, { collapseBooleanAttributes: true }), ''); + test_minify(assert, input, '', { collapseBooleanAttributes: true }); input = ''; - assert.equal(minify(input, { collapseBooleanAttributes: true }), ''); + test_minify(assert, input, '', { collapseBooleanAttributes: true }); input = ''; - assert.equal(minify(input, { collapseBooleanAttributes: true }), ''); + test_minify(assert, input, '', { collapseBooleanAttributes: true }); input = ''; - assert.equal(minify(input, { collapseBooleanAttributes: true }), ''); + test_minify(assert, input, '', { collapseBooleanAttributes: true }); input = ''; - assert.equal(minify(input, { collapseBooleanAttributes: true }), output); + test_minify(assert, input, output, { collapseBooleanAttributes: true }); output = ''; - assert.equal(minify(input, { collapseBooleanAttributes: true, caseSensitive: true }), output); + test_minify(assert, input, output, { collapseBooleanAttributes: true, caseSensitive: true }); }); QUnit.test('collapsing enumerated attributes', function(assert) { - assert.equal(minify('
    ', { collapseBooleanAttributes: true }), '
    '); - assert.equal(minify('
    ', { collapseBooleanAttributes: true }), '
    '); - assert.equal(minify('
    ', { collapseBooleanAttributes: true }), '
    '); - assert.equal(minify('
    ', { collapseBooleanAttributes: true }), '
    '); - assert.equal(minify('
    ', { collapseBooleanAttributes: true }), '
    '); - assert.equal(minify('
    ', { collapseBooleanAttributes: true }), '
    '); - assert.equal(minify('
    ', { collapseBooleanAttributes: true }), '
    '); - assert.equal(minify('
    ', { collapseBooleanAttributes: true }), '
    '); - assert.equal(minify('
    ', { collapseBooleanAttributes: true }), '
    '); - assert.equal(minify('
    ', { collapseBooleanAttributes: true }), '
    '); - assert.equal(minify('
    ', { collapseBooleanAttributes: true }), '
    '); + test_minify(assert, '
    ', '
    ', { collapseBooleanAttributes: true }); + test_minify(assert, '
    ', '
    ', { collapseBooleanAttributes: true }); + test_minify(assert, '
    ', '
    ', { collapseBooleanAttributes: true }); + test_minify(assert, '
    ', '
    ', { collapseBooleanAttributes: true }); + test_minify(assert, '
    ', '
    ', { collapseBooleanAttributes: true }); + test_minify(assert, '
    ', '
    ', { collapseBooleanAttributes: true }); + test_minify(assert, '
    ', '
    ', { collapseBooleanAttributes: true }); + test_minify(assert, '
    ', '
    ', { collapseBooleanAttributes: true }); + test_minify(assert, '
    ', '
    ', { collapseBooleanAttributes: true }); + test_minify(assert, '
    ', '
    ', { collapseBooleanAttributes: true }); + test_minify(assert, '
    ', '
    ', { collapseBooleanAttributes: true }); }); QUnit.test('keeping trailing slashes in tags', function(assert) { - assert.equal(minify('', { keepClosingSlash: true }), ''); + test_minify(assert, '', '', { keepClosingSlash: true }); // https://github.com/kangax/html-minifier/issues/233 - assert.equal(minify('', { keepClosingSlash: true, removeAttributeQuotes: true }), ''); - assert.equal(minify('', { keepClosingSlash: true, removeAttributeQuotes: true, removeEmptyAttributes: true }), ''); - assert.equal(minify('', { keepClosingSlash: true, removeAttributeQuotes: true }), ''); + test_minify(assert, '', '', { keepClosingSlash: true, removeAttributeQuotes: true }); + test_minify(assert, '', '', { keepClosingSlash: true, removeAttributeQuotes: true, removeEmptyAttributes: true }); + test_minify(assert, '', '', { keepClosingSlash: true, removeAttributeQuotes: true }); }); QUnit.test('removing optional tags', function(assert) { var input, output; input = '

    foo'; - assert.equal(minify(input, { removeOptionalTags: true }), input); + test_minify(assert, input, input, { removeOptionalTags: true }); input = '

    '; output = '

    '; - assert.equal(minify(input, { removeOptionalTags: true }), output); + test_minify(assert, input, output, { removeOptionalTags: true }); input = ''; output = ''; - assert.equal(minify(input, { removeOptionalTags: true }), output); - assert.equal(minify(input, { removeOptionalTags: true, removeEmptyElements: true }), output); + test_minify(assert, input, output, { removeOptionalTags: true }); + test_minify(assert, input, output, { removeOptionalTags: true, removeEmptyElements: true }); input = ''; output = ''; - assert.equal(minify(input, { removeOptionalTags: true }), output); - assert.equal(minify(input, { removeOptionalTags: true, removeEmptyElements: true }), output); + test_minify(assert, input, output, { removeOptionalTags: true }); + test_minify(assert, input, output, { removeOptionalTags: true, removeEmptyElements: true }); input = ' '; output = ' '; - assert.equal(minify(input, { removeOptionalTags: true }), output); + test_minify(assert, input, output, { removeOptionalTags: true }); output = ''; - assert.equal(minify(input, { collapseWhitespace: true, removeOptionalTags: true }), output); + test_minify(assert, input, output, { collapseWhitespace: true, removeOptionalTags: true }); input = ' '; output = ' '; - assert.equal(minify(input, { removeOptionalTags: true }), output); + test_minify(assert, input, output, { removeOptionalTags: true }); output = ''; - assert.equal(minify(input, { collapseWhitespace: true, removeOptionalTags: true }), output); + test_minify(assert, input, output, { collapseWhitespace: true, removeOptionalTags: true }); input = ' '; output = ' '; - assert.equal(minify(input, { removeOptionalTags: true }), output); + test_minify(assert, input, output, { removeOptionalTags: true }); output = ''; - assert.equal(minify(input, { collapseWhitespace: true, removeOptionalTags: true }), output); + test_minify(assert, input, output, { collapseWhitespace: true, removeOptionalTags: true }); input = ' '; output = ' '; - assert.equal(minify(input, { removeOptionalTags: true }), output); + test_minify(assert, input, output, { removeOptionalTags: true }); output = ''; - assert.equal(minify(input, { collapseWhitespace: true, removeOptionalTags: true }), output); + test_minify(assert, input, output, { collapseWhitespace: true, removeOptionalTags: true }); input = ' '; output = ' '; - assert.equal(minify(input, { removeOptionalTags: true }), output); + test_minify(assert, input, output, { removeOptionalTags: true }); output = ''; - assert.equal(minify(input, { collapseWhitespace: true, removeOptionalTags: true }), output); + test_minify(assert, input, output, { collapseWhitespace: true, removeOptionalTags: true }); input = ' '; output = ' '; - assert.equal(minify(input, { removeOptionalTags: true }), output); + test_minify(assert, input, output, { removeOptionalTags: true }); output = ''; - assert.equal(minify(input, { collapseWhitespace: true, removeOptionalTags: true }), output); + test_minify(assert, input, output, { collapseWhitespace: true, removeOptionalTags: true }); input = ' '; output = ' '; - assert.equal(minify(input, { removeOptionalTags: true }), output); + test_minify(assert, input, output, { removeOptionalTags: true }); output = ''; - assert.equal(minify(input, { collapseWhitespace: true, removeOptionalTags: true }), output); + test_minify(assert, input, output, { collapseWhitespace: true, removeOptionalTags: true }); input = ' '; output = ' '; - assert.equal(minify(input, { removeOptionalTags: true }), output); + test_minify(assert, input, output, { removeOptionalTags: true }); output = ''; - assert.equal(minify(input, { collapseWhitespace: true, removeOptionalTags: true }), output); + test_minify(assert, input, output, { collapseWhitespace: true, removeOptionalTags: true }); input = 'hello

    foobar

    '; - assert.equal(minify(input), input); + test_minify(assert, input, input); output = 'hello

    foobar'; - assert.equal(minify(input, { removeOptionalTags: true }), output); + test_minify(assert, input, output, { removeOptionalTags: true }); input = 'hello

    foobar

    '; output = 'hello

    foobar'; - assert.equal(minify(input, { removeOptionalTags: true }), output); + test_minify(assert, input, output, { removeOptionalTags: true }); output = 'hello

    foobar'; - assert.equal(minify(input, { removeOptionalTags: true, removeEmptyAttributes: true }), output); + test_minify(assert, input, output, { removeOptionalTags: true, removeEmptyAttributes: true }); input = 'a

    '; output = 'a
    '; - assert.equal(minify(input, { removeOptionalTags: true }), output); + test_minify(assert, input, output, { removeOptionalTags: true }); input = 'Blah

    This is some text in a div

    Followed by some details

    This is some more text in a div

    '; output = 'Blah

    This is some text in a div

    Followed by some details

    This is some more text in a div

    '; - assert.equal(minify(input, { removeOptionalTags: true }), output); + test_minify(assert, input, output, { removeOptionalTags: true }); input = 'Blah'; output = 'Blah'; - assert.equal(minify(input, { removeOptionalTags: true }), output); + test_minify(assert, input, output, { removeOptionalTags: true }); input = '

    Configure

    '; - assert.equal(minify(input, { removeOptionalTags: true }), input); + test_minify(assert, input, input, { removeOptionalTags: true }); }); QUnit.test('removing optional tags in tables', function(assert) { @@ -1559,22 +1685,22 @@ QUnit.test('removing optional tags in tables', function(assert) { 'boomooloo ' + 'baz quxboo' + ''; - assert.equal(minify(input), input); + test_minify(assert, input, input); output = '' + ' ' + ' ' + '
    foobar baz
    boomooloo
    baz quxboo' + '
    '; - assert.equal(minify(input, { removeOptionalTags: true }), output); + test_minify(assert, input, output, { removeOptionalTags: true }); output = '' + '
    foobarbaz' + '
    boomooloo' + '
    bazquxboo' + '
    '; - assert.equal(minify(input, { collapseWhitespace: true, removeOptionalTags: true }), output); - assert.equal(minify(output, { collapseWhitespace: true, removeOptionalTags: true }), output); + test_minify(assert, input, output, { collapseWhitespace: true, removeOptionalTags: true }); + test_minify(assert, output, output, { collapseWhitespace: true, removeOptionalTags: true }); input = '' + '' + @@ -1583,7 +1709,7 @@ QUnit.test('removing optional tags in tables', function(assert) { '' + '' + '
    foo
    barbazqux
    '; - assert.equal(minify(input), input); + test_minify(assert, input, input); output = '' + '' + @@ -1592,23 +1718,23 @@ QUnit.test('removing optional tags in tables', function(assert) { '' + '
    foo
    barbazqux' + '
    '; - assert.equal(minify(input, { removeOptionalTags: true }), output); - assert.equal(minify(output, { removeOptionalTags: true }), output); + test_minify(assert, input, output, { removeOptionalTags: true }); + test_minify(assert, output, output, { removeOptionalTags: true }); output = '' + '' + '
    foo' + '
    barbazqux' + '
    '; - assert.equal(minify(input, { removeComments: true, removeOptionalTags: true }), output); + test_minify(assert, input, output, { removeComments: true, removeOptionalTags: true }); input = '' + '' + '
    '; - assert.equal(minify(input), input); + test_minify(assert, input, input); output = '
    '; - assert.equal(minify(input, { removeOptionalTags: true }), output); + test_minify(assert, input, output, { removeOptionalTags: true }); }); QUnit.test('removing optional tags in options', function(assert) { @@ -1616,17 +1742,17 @@ QUnit.test('removing optional tags in options', function(assert) { input = ''; output = ''; - assert.equal(minify(input, { removeOptionalTags: true }), output); + test_minify(assert, input, output, { removeOptionalTags: true }); input = ''; - assert.equal(minify(input, { removeOptionalTags: true }), input); + test_minify(assert, input, input, { removeOptionalTags: true }); output = ''; - assert.equal(minify(input, { removeOptionalTags: true, collapseWhitespace: true }), output); + test_minify(assert, input, output, { removeOptionalTags: true, collapseWhitespace: true }); output = ''; - assert.equal(minify(input, { removeOptionalTags: true, collapseWhitespace: true, conservativeCollapse: true }), output); + test_minify(assert, input, output, { removeOptionalTags: true, collapseWhitespace: true, conservativeCollapse: true }); // example from htmldog.com input = ''; - assert.equal(minify(input, { removeOptionalTags: true }), output); + test_minify(assert, input, output, { removeOptionalTags: true }); }); QUnit.test('custom components', function(assert) { var input = 'Oh, my.'; var output = 'Oh, my.'; - assert.equal(minify(input), output); + test_minify(assert, input, output); }); QUnit.test('HTML4: anchor with inline elements', function(assert) { var input = 'Well, look at me! I\'m a span!'; - assert.equal(minify(input, { html5: false }), input); + test_minify(assert, input, input, { html5: false }); }); QUnit.test('HTML5: anchor with inline elements', function(assert) { var input = 'Well, look at me! I\'m a span!'; - assert.equal(minify(input, { html5: true }), input); + test_minify(assert, input, input, { html5: true }); }); QUnit.test('HTML4: anchor with block elements', function(assert) { var input = '
    Well, look at me! I\'m a div!
    '; var output = '
    Well, look at me! I\'m a div!
    '; - assert.equal(minify(input, { html5: false }), output); + test_minify(assert, input, output, { html5: false }); }); QUnit.test('HTML5: anchor with block elements', function(assert) { var input = '
    Well, look at me! I\'m a div!
    '; var output = '
    Well, look at me! I\'m a div!
    '; - assert.equal(minify(input, { html5: true }), output); + test_minify(assert, input, output, { html5: true }); }); QUnit.test('HTML5: enabled by default', function(assert) { var input = '
    Well, look at me! I\'m a div!
    '; - assert.equal(minify(input, { html5: true }), minify(input)); + test_minify(assert, input, minify(input), { html5: true }); }); QUnit.test('phrasing content', function(assert) { @@ -1686,12 +1812,12 @@ QUnit.test('phrasing content', function(assert) { input = '

    a

    b
    '; output = '

    a

    b
    '; - assert.equal(minify(input, { html5: true }), output); + test_minify(assert, input, output, { html5: true }); output = '

    a

    b

    '; - assert.equal(minify(input, { html5: false }), output); + test_minify(assert, input, output, { html5: false }); input = ''; - assert.equal(minify(input, { html5: true }), input); + test_minify(assert, input, input, { html5: true }); }); // https://github.com/kangax/html-minifier/issues/888 @@ -1700,29 +1826,29 @@ QUnit.test('ul/ol should be phrasing content', function(assert) { input = '

    a

    '; output = '

    a

    '; - assert.equal(minify(input, { html5: true }), output); + test_minify(assert, input, output, { html5: true }); output = '

    a

    '; - assert.equal(minify(input, { html5: true, removeOptionalTags: true }), output); + test_minify(assert, input, output, { html5: true, removeOptionalTags: true }); output = '

    a

    '; - assert.equal(minify(input, { html5: false }), output); + test_minify(assert, input, output, { html5: false }); input = '

    a

    1. item

    '; output = '

    a

    1. item

    '; - assert.equal(minify(input, { html5: true }), output); + test_minify(assert, input, output, { html5: true }); output = '

    a

    1. item

    '; - assert.equal(minify(input, { html5: true, removeOptionalTags: true }), output); + test_minify(assert, input, output, { html5: true, removeOptionalTags: true }); output = '

    a

    1. item
    '; - assert.equal(minify(input, { html5: true, removeEmptyElements: true }), output); + test_minify(assert, input, output, { html5: true, removeEmptyElements: true }); }); QUnit.test('phrasing content with Web Components', function(assert) { var input = ''; var output = ''; - assert.equal(minify(input, { html5: true }), output); + test_minify(assert, input, output, { html5: true }); }); // https://github.com/kangax/html-minifier/issues/10 @@ -1732,52 +1858,52 @@ QUnit.test('Ignore custom fragments', function(assert) { input = 'This is the start. <% ... %>\r\n<%= ... %>\r\n\r\n\r\nNo comment, but middle.\r\n{{ ... }}\r\n\r\n\r\nHello, this is the end!'; output = 'This is the start. <% ... %> <%= ... %> No comment, but middle. {{ ... }} Hello, this is the end!'; - assert.equal(minify(input, {}), input); - assert.equal(minify(input, { removeComments: true, collapseWhitespace: true }), output); - assert.equal(minify(input, { + test_minify(assert, input, input, {}); + test_minify(assert, input, output, { removeComments: true, collapseWhitespace: true }); + test_minify(assert, input, output, { removeComments: true, collapseWhitespace: true, ignoreCustomFragments: reFragments - }), output); + }); output = 'This is the start. <% ... %>\n<%= ... %>\n\nNo comment, but middle. {{ ... }}\n\n\nHello, this is the end!'; - assert.equal(minify(input, { + test_minify(assert, input, output, { removeComments: true, collapseWhitespace: true, preserveLineBreaks: true - }), output); + }); output = 'This is the start. <% ... %>\n<%= ... %>\n\nNo comment, but middle.\n{{ ... }}\n\n\nHello, this is the end!'; - assert.equal(minify(input, { + test_minify(assert, input, output, { removeComments: true, collapseWhitespace: true, preserveLineBreaks: true, ignoreCustomFragments: reFragments - }), output); + }); input = '{{ if foo? }}\r\n
    \r\n ...\r\n
    \r\n{{ end \n}}'; output = '{{ if foo? }}
    ...
    {{ end }}'; - assert.equal(minify(input, {}), input); - assert.equal(minify(input, { collapseWhitespace: true }), output); - assert.equal(minify(input, { collapseWhitespace: true, ignoreCustomFragments: [] }), output); + test_minify(assert, input, input, {}); + test_minify(assert, input, output, { collapseWhitespace: true }); + test_minify(assert, input, output, { collapseWhitespace: true, ignoreCustomFragments: [] }); output = '{{ if foo? }}
    ...
    {{ end \n}}'; - assert.equal(minify(input, { collapseWhitespace: true, ignoreCustomFragments: reFragments }), output); + test_minify(assert, input, output, { collapseWhitespace: true, ignoreCustomFragments: reFragments }); output = '{{ if foo? }}\n
    \n...\n
    \n{{ end \n}}'; - assert.equal(minify(input, { + test_minify(assert, input, output, { collapseWhitespace: true, preserveLineBreaks: true, ignoreCustomFragments: reFragments - }), output); + }); input = ''; - assert.equal(minify(input, {}), input); - assert.equal(minify(input, { ignoreCustomFragments: reFragments }), input); + test_minify(assert, input, input, {}); + test_minify(assert, input, input, { ignoreCustomFragments: reFragments }); input = ''; output = ''; - assert.equal(minify(input, { ignoreCustomFragments: [/\{%[^%]*?%\}/g] }), output); + test_minify(assert, input, output, { ignoreCustomFragments: [/\{%[^%]*?%\}/g] }); input = '' + '{{ form.name.label_tag }}' + @@ -1789,13 +1915,13 @@ QUnit.test('Ignore custom fragments', function(assert) { '{% endfor %}' + '{% endif %}' + '

    '; - assert.equal(minify(input, { + test_minify(assert, input, input, { ignoreCustomFragments: [ /\{%[\s\S]*?%\}/g, /\{\{[\s\S]*?\}\}/g ], quoteCharacter: '\'' - }), input); + }); output = '

    ' + '{{ form.name.label_tag }}' + '{{ form.name }}' + @@ -1806,151 +1932,151 @@ QUnit.test('Ignore custom fragments', function(assert) { '{% endfor %}' + '{% endif %}' + '

    '; - assert.equal(minify(input, { + test_minify(assert, input, output, { ignoreCustomFragments: [ /\{%[\s\S]*?%\}/g, /\{\{[\s\S]*?\}\}/g ], quoteCharacter: '\'', collapseWhitespace: true - }), output); + }); input = '>Legal Notices'; - assert.equal(minify(input, { + test_minify(assert, input, input, { ignoreCustomFragments: [ /<\?php[\s\S]*?\?>/g ] - }), input); + }); input = '>'; - assert.equal(minify(input, { + test_minify(assert, input, input, { ignoreCustomFragments: [ /<%=[\s\S]*?%>/g ] - }), input); + }); input = ''; - assert.equal(minify(input, { + test_minify(assert, input, input, { ignoreCustomFragments: [ /\{\{[\s\S]*?\}\}/g ], caseSensitive: true - }), input); + }); input = ''; - assert.equal(minify(input, { + test_minify(assert, input, input, { ignoreCustomFragments: [ /\{%[^%]*?%\}/g ] - }), input); + }); // trimCustomFragments withOUT collapseWhitespace, does // not break the "{% foo %} {% bar %}" test - assert.equal(minify(input, { + test_minify(assert, input, input, { ignoreCustomFragments: [ /\{%[^%]*?%\}/g ], trimCustomFragments: true - }), input); + }); // trimCustomFragments WITH collapseWhitespace, changes output output = ''; - assert.equal(minify(input, { + test_minify(assert, input, output, { ignoreCustomFragments: [ /\{%[^%]*?%\}/g ], collapseWhitespace: true, trimCustomFragments: true - }), output); + }); input = ''; - assert.equal(minify(input), input); - assert.equal(minify(input, { + test_minify(assert, input, input); + test_minify(assert, input, input, { collapseWhitespace: true - }), input); + }); input = '
    '; - assert.equal(minify(input), input); - assert.equal(minify(input, { + test_minify(assert, input, input); + test_minify(assert, input, input, { collapseWhitespace: true - }), input); + }); input = '{{if a}}
    b
    {{/if}}'; - assert.equal(minify(input), input); + test_minify(assert, input, input); output = '{{if a}}
    b
    {{/if}}'; - assert.equal(minify(input, { + test_minify(assert, input, output, { removeComments: true, ignoreCustomFragments: [ /\{\{.*?\}\}/g ] - }), output); + }); // https://github.com/kangax/html-minifier/issues/722 input = ' bar'; - assert.equal(minify(input), input); - assert.equal(minify(input, { + test_minify(assert, input, input); + test_minify(assert, input, input, { collapseWhitespace: true - }), input); + }); output = 'bar'; - assert.equal(minify(input, { + test_minify(assert, input, output, { collapseWhitespace: true, trimCustomFragments: true - }), output); + }); input = ' bar'; - assert.equal(minify(input), input); + test_minify(assert, input, input); output = ' bar'; - assert.equal(minify(input, { + test_minify(assert, input, output, { collapseWhitespace: true - }), output); + }); output = 'bar'; - assert.equal(minify(input, { + test_minify(assert, input, output, { collapseWhitespace: true, trimCustomFragments: true - }), output); + }); input = 'foo baz'; - assert.equal(minify(input), input); - assert.equal(minify(input, { + test_minify(assert, input, input); + test_minify(assert, input, input, { collapseWhitespace: true - }), input); + }); output = 'foobaz'; - assert.equal(minify(input, { + test_minify(assert, input, output, { collapseWhitespace: true, trimCustomFragments: true - }), output); + }); input = 'foo foo'; - assert.equal(minify(input), input); - assert.equal(minify(input, { + test_minify(assert, input, input); + test_minify(assert, input, input, { collapseWhitespace: true - }), input); + }); output = 'foofoo'; - assert.equal(minify(input, { + test_minify(assert, input, output, { collapseWhitespace: true, trimCustomFragments: true - }), output); + }); input = 'foo baz moo loo'; - assert.equal(minify(input, { + test_minify(assert, input, input, { collapseWhitespace: true, ignoreCustomFragments: [ /<(WC@[\s\S]*?)>(.*?)<\/\1>/ ] - }), input); + }); output = 'foobaz mooloo'; - assert.equal(minify(input, { + test_minify(assert, input, output, { collapseWhitespace: true - }), output); + }); input = ''; - assert.equal(minify(input), input); - assert.equal(minify(input, { removeAttributeQuotes: true }), input); + test_minify(assert, input, input); + test_minify(assert, input, input, { removeAttributeQuotes: true }); input = '
    \nfoo\n\nbaz\n
    '; - assert.equal(minify(input), input); - assert.equal(minify(input, { collapseWhitespace: true }), input); + test_minify(assert, input, input); + test_minify(assert, input, input, { collapseWhitespace: true }); }); QUnit.test('bootstrap\'s span > button > span', function(assert) { @@ -1960,15 +2086,15 @@ QUnit.test('bootstrap\'s span > button > span', function(assert) { '\n ' + ''; var output = ''; - assert.equal(minify(input, { collapseWhitespace: true, removeAttributeQuotes: true }), output); + test_minify(assert, input, output, { collapseWhitespace: true, removeAttributeQuotes: true }); }); QUnit.test('caseSensitive', function(assert) { var input = '
    '; var caseSensitiveOutput = '
    '; var caseInSensitiveOutput = '
    '; - assert.equal(minify(input), caseInSensitiveOutput); - assert.equal(minify(input, { caseSensitive: true }), caseSensitiveOutput); + test_minify(assert, input, caseInSensitiveOutput); + test_minify(assert, input, caseSensitiveOutput, { caseSensitive: true }); }); QUnit.test('source & track', function(assert) { @@ -1978,8 +2104,8 @@ QUnit.test('source & track', function(assert) { '' + '' + ''; - assert.equal(minify(input), input); - assert.equal(minify(input, { removeOptionalTags: true }), input); + test_minify(assert, input, input); + test_minify(assert, input, input, { removeOptionalTags: true }); }); QUnit.test('mixed html and svg', function(assert) { @@ -2004,18 +2130,18 @@ QUnit.test('mixed html and svg', function(assert) { '' + ''; // Should preserve case-sensitivity and closing slashes within svg tags - assert.equal(minify(input, { collapseWhitespace: true }), output); + test_minify(assert, input, output, { collapseWhitespace: true }); }); QUnit.test('nested quotes', function(assert) { var input, output; input = '
    '; - assert.equal(minify(input), input); - assert.equal(minify(input, { quoteCharacter: '\'' }), input); + test_minify(assert, input, input); + test_minify(assert, input, input, { quoteCharacter: '\'' }); output = '
    '; - assert.equal(minify(input, { quoteCharacter: '"' }), output); + test_minify(assert, input, output, { quoteCharacter: '"' }); }); QUnit.test('script minification', function(assert) { @@ -2023,32 +2149,32 @@ QUnit.test('script minification', function(assert) { input = '(function(){ var foo = 1; var bar = 2; alert(foo + " " + bar); })()'; - assert.equal(minify(input, { minifyJS: true }), input); + test_minify(assert, input, input, { minifyJS: true }); input = ''; output = ''; - assert.equal(minify(input, { minifyJS: true }), output); + test_minify(assert, input, output, { minifyJS: true }); input = ''; output = ''; - assert.equal(minify(input, { minifyJS: true }), output); + test_minify(assert, input, output, { minifyJS: true }); input = ''; output = ''; - assert.equal(minify(input, { minifyJS: true }), output); + test_minify(assert, input, output, { minifyJS: true }); input = ''; output = ''; - assert.equal(minify(input, { minifyJS: true }), output); + test_minify(assert, input, output, { minifyJS: true }); input = ''; output = ''; - assert.equal(minify(input, { minifyJS: { mangle: false } }), output); + test_minify(assert, input, output, { minifyJS: { mangle: false } }); input = ''; output = ''; - assert.equal(minify(input, { minifyJS: true }), output); + test_minify(assert, input, output, { minifyJS: true }); }); QUnit.test('minification of scripts with different mimetypes', function(assert) { @@ -2069,268 +2195,268 @@ QUnit.test('minification of scripts with different mimetypes', function(assert) input = ''; output = ''; - assert.equal(minify(input, { minifyJS: true }), output); + test_minify(assert, input, output, { minifyJS: true }); input = ''; output = ''; - assert.equal(minify(input, { minifyJS: true }), output); + test_minify(assert, input, output, { minifyJS: true }); input = ''; output = ''; - assert.equal(minify(input, { minifyJS: true }), output); + test_minify(assert, input, output, { minifyJS: true }); input = ''; output = ''; - assert.equal(minify(input, { minifyJS: true }), output); + test_minify(assert, input, output, { minifyJS: true }); input = ''; output = ''; - assert.equal(minify(input, { minifyJS: true }), output); + test_minify(assert, input, output, { minifyJS: true }); input = ''; - assert.equal(minify(input, { minifyJS: true }), input); + test_minify(assert, input, input, { minifyJS: true }); input = ''; - assert.equal(minify(input, { minifyJS: true }), input); + test_minify(assert, input, input, { minifyJS: true }); }); QUnit.test('minification of scripts with custom fragments', function(assert) { var input, output; input = ''; - assert.equal(minify(input, { minifyJS: true }), input); - assert.equal(minify(input, { collapseWhitespace: true, minifyJS: true }), input); - assert.equal(minify(input, { + test_minify(assert, input, input, { minifyJS: true }); + test_minify(assert, input, input, { collapseWhitespace: true, minifyJS: true }); + test_minify(assert, input, input, { collapseWhitespace: true, minifyJS: true, preserveLineBreaks: true - }), input); + }); input = ''; - assert.equal(minify(input, { minifyJS: true }), input); + test_minify(assert, input, input, { minifyJS: true }); output = ''; - assert.equal(minify(input, { collapseWhitespace: true, minifyJS: true }), output); - assert.equal(minify(input, { + test_minify(assert, input, output, { collapseWhitespace: true, minifyJS: true }); + test_minify(assert, input, input, { collapseWhitespace: true, minifyJS: true, preserveLineBreaks: true - }), input); + }); input = ''; - assert.equal(minify(input, { minifyJS: true }), input); + test_minify(assert, input, input, { minifyJS: true }); output = ''; - assert.equal(minify(input, { collapseWhitespace: true, minifyJS: true }), output); - assert.equal(minify(input, { + test_minify(assert, input, output, { collapseWhitespace: true, minifyJS: true }); + test_minify(assert, input, input, { collapseWhitespace: true, minifyJS: true, preserveLineBreaks: true - }), input); + }); input = ''; - assert.equal(minify(input, { minifyJS: true }), input); + test_minify(assert, input, input, { minifyJS: true }); output = ''; - assert.equal(minify(input, { collapseWhitespace: true, minifyJS: true }), output); - assert.equal(minify(input, { + test_minify(assert, input, output, { collapseWhitespace: true, minifyJS: true }); + test_minify(assert, input, input, { collapseWhitespace: true, minifyJS: true, preserveLineBreaks: true - }), input); + }); input = ''; output = ''; - assert.equal(minify(input, { minifyJS: true }), output); - assert.equal(minify(input, { collapseWhitespace: true, minifyJS: true }), output); - assert.equal(minify(input, { + test_minify(assert, input, output, { minifyJS: true }); + test_minify(assert, input, output, { collapseWhitespace: true, minifyJS: true }); + test_minify(assert, input, output, { collapseWhitespace: true, minifyJS: true, preserveLineBreaks: true - }), output); + }); input = ''; output = ''; - assert.equal(minify(input, { minifyJS: true }), output); + test_minify(assert, input, output, { minifyJS: true }); output = ''; - assert.equal(minify(input, { collapseWhitespace: true, minifyJS: true }), output); + test_minify(assert, input, output, { collapseWhitespace: true, minifyJS: true }); output = ''; - assert.equal(minify(input, { + test_minify(assert, input, output, { collapseWhitespace: true, minifyJS: true, preserveLineBreaks: true - }), output); + }); input = ''; output = ''; - assert.equal(minify(input, { minifyJS: true }), output); - assert.equal(minify(input, { collapseWhitespace: true, minifyJS: true }), output); - assert.equal(minify(input, { + test_minify(assert, input, output, { minifyJS: true }); + test_minify(assert, input, output, { collapseWhitespace: true, minifyJS: true }); + test_minify(assert, input, output, { collapseWhitespace: true, minifyJS: true, preserveLineBreaks: true - }), output); + }); input = ''; output = ''; - assert.equal(minify(input, { minifyJS: true }), output); + test_minify(assert, input, output, { minifyJS: true }); output = ''; - assert.equal(minify(input, { collapseWhitespace: true, minifyJS: true }), output); + test_minify(assert, input, output, { collapseWhitespace: true, minifyJS: true }); output = ''; - assert.equal(minify(input, { + test_minify(assert, input, output, { collapseWhitespace: true, minifyJS: true, preserveLineBreaks: true - }), output); + }); input = ''; output = ''; - assert.equal(minify(input, { minifyJS: true }), output); + test_minify(assert, input, output, { minifyJS: true }); output = ''; - assert.equal(minify(input, { collapseWhitespace: true, minifyJS: true }), output); + test_minify(assert, input, output, { collapseWhitespace: true, minifyJS: true }); input = ''; output = ''; - assert.equal(minify(input, { minifyJS: true }), output); - assert.equal(minify(input, { collapseWhitespace: true, minifyJS: true }), output); + test_minify(assert, input, output, { minifyJS: true }); + test_minify(assert, input, output, { collapseWhitespace: true, minifyJS: true }); }); QUnit.test('event minification', function(assert) { var input, output; input = '
    '; - assert.equal(minify(input, { minifyJS: true }), input); + test_minify(assert, input, input, { minifyJS: true }); input = '
    '; output = '
    '; - assert.equal(minify(input, { minifyJS: true }), output); + test_minify(assert, input, output, { minifyJS: true }); input = 'test'; output = 'test'; - assert.equal(minify(input, { minifyJS: true }), output); + test_minify(assert, input, output, { minifyJS: true }); input = ' foobar'; output = ' foobar'; - assert.equal(minify(input, { minifyJS: { mangle: false } }), output); - assert.equal(minify(input, { minifyJS: { mangle: false }, quoteCharacter: '\'' }), output); + test_minify(assert, input, output, { minifyJS: { mangle: false } }); + test_minify(assert, input, output, { minifyJS: { mangle: false }, quoteCharacter: '\'' }); input = ' foobar'; output = ' foobar'; - assert.equal(minify(input, { minifyJS: { mangle: false }, quoteCharacter: '"' }), output); + test_minify(assert, input, output, { minifyJS: { mangle: false }, quoteCharacter: '"' }); input = ''; output = ''; - assert.equal(minify(input, { minifyJS: true }), output); - assert.equal(minify(input, { minifyJS: true, quoteCharacter: '\'' }), output); + test_minify(assert, input, output, { minifyJS: true }); + test_minify(assert, input, output, { minifyJS: true, quoteCharacter: '\'' }); input = ''; output = ''; - assert.equal(minify(input, { minifyJS: true, quoteCharacter: '"' }), output); + test_minify(assert, input, output, { minifyJS: true, quoteCharacter: '"' }); input = ''; output = ''; - assert.equal(minify(input, { minifyJS: true }), output); + test_minify(assert, input, output, { minifyJS: true }); input = ''; output = ''; - assert.equal(minify(input, { minifyJS: true }), output); - assert.equal(minify(input, { minifyJS: true, customEventAttributes: [] }), input); + test_minify(assert, input, output, { minifyJS: true }); + test_minify(assert, input, input, { minifyJS: true, customEventAttributes: [] }); output = ''; - assert.equal(minify(input, { minifyJS: true, customEventAttributes: [/^ng-/] }), output); + test_minify(assert, input, output, { minifyJS: true, customEventAttributes: [/^ng-/] }); output = ''; - assert.equal(minify(input, { minifyJS: true, customEventAttributes: [/^on/, /^ng-/] }), output); + test_minify(assert, input, output, { minifyJS: true, customEventAttributes: [/^on/, /^ng-/] }); input = '
    '; - assert.equal(minify(input, { minifyJS: true }), input); + test_minify(assert, input, input, { minifyJS: true }); input = '
    '; output = '
    '; - assert.equal(minify(input, { minifyJS: true }), output); + test_minify(assert, input, output, { minifyJS: true }); input = '
    '; output = '
    ")\'>
    '; - assert.equal(minify(input, { minifyJS: true }), output); + test_minify(assert, input, output, { minifyJS: true }); }); QUnit.test('escaping closing script tag', function(assert) { var input = ''; var output = ''; - assert.equal(minify(input, { minifyJS: true }), output); + test_minify(assert, input, output, { minifyJS: true }); }); QUnit.test('style minification', function(assert) { var input, output; input = 'div#foo { background-color: red; color: white }'; - assert.equal(minify(input, { minifyCSS: true }), input); + test_minify(assert, input, input, { minifyCSS: true }); input = ''; output = ''; - assert.equal(minify(input), input); - assert.equal(minify(input, { minifyCSS: true }), output); + test_minify(assert, input, input); + test_minify(assert, input, output, { minifyCSS: true }); input = ''; output = ''; - assert.equal(minify(input, { minifyCSS: true }), output); + test_minify(assert, input, output, { minifyCSS: true }); input = '
    '; - assert.equal(minify(input), input); + test_minify(assert, input, input); output = '
    '; - assert.equal(minify(input, { minifyCSS: true }), output); - assert.equal(minify(input, { + test_minify(assert, input, output, { minifyCSS: true }); + test_minify(assert, input, output, { collapseWhitespace: true, minifyCSS: true - }), output); + }); input = '
    '; - assert.equal(minify(input), input); + test_minify(assert, input, input); output = '
    '; - assert.equal(minify(input, { minifyCSS: true }), output); - assert.equal(minify(input, { + test_minify(assert, input, output, { minifyCSS: true }); + test_minify(assert, input, output, { collapseWhitespace: true, minifyCSS: true - }), output); + }); input = ''; - assert.equal(minify(input), input); + test_minify(assert, input, input); output = ''; - assert.equal(minify(input, { minifyCSS: true }), output); - assert.equal(minify(input, { + test_minify(assert, input, output, { minifyCSS: true }); + test_minify(assert, input, output, { collapseWhitespace: true, minifyCSS: true - }), output); + }); input = ''; - assert.equal(minify(input), input); + test_minify(assert, input, input); output = ''; - assert.equal(minify(input, { minifyCSS: true }), output); - assert.equal(minify(input, { + test_minify(assert, input, output, { minifyCSS: true }); + test_minify(assert, input, output, { collapseWhitespace: true, minifyCSS: true - }), output); + }); input = ''; - assert.equal(minify(input), input); + test_minify(assert, input, input); output = ''; - assert.equal(minify(input, { minifyCSS: true }), output); + test_minify(assert, input, output, { minifyCSS: true }); output = ''; - assert.equal(minify(input, { + test_minify(assert, input, output, { minifyCSS: true, removeAttributeQuotes: true - }), output); + }); input = ''; - assert.equal(minify(input), input); + test_minify(assert, input, input); output = ''; - assert.equal(minify(input, { minifyCSS: true }), output); + test_minify(assert, input, output, { minifyCSS: true }); output = ''; - assert.equal(minify(input, { + test_minify(assert, input, output, { minifyCSS: true, removeAttributeQuotes: true - }), output); + }); }); QUnit.test('style attribute minification', function(assert) { var input = '
    '; var output = '
    '; - assert.equal(minify(input, { minifyCSS: true }), output); + test_minify(assert, input, output, { minifyCSS: true }); }); QUnit.test('url attribute minification', function(assert) { @@ -2338,61 +2464,61 @@ QUnit.test('url attribute minification', function(assert) { input = '
    link
    '; output = '
    link
    '; - assert.equal(minify(input, { minifyURLs: 'http://website.com/folder/' }), output); - assert.equal(minify(input, { minifyURLs: { site: 'http://website.com/folder/' } }), output); + test_minify(assert, input, output, { minifyURLs: 'http://website.com/folder/' }); + test_minify(assert, input, output, { minifyURLs: { site: 'http://website.com/folder/' } }); input = ''; - assert.equal(minify(input, { minifyURLs: 'http://website.com/' }), input); - assert.equal(minify(input, { minifyURLs: { site: 'http://website.com/' } }), input); + test_minify(assert, input, input, { minifyURLs: 'http://website.com/' }); + test_minify(assert, input, input, { minifyURLs: { site: 'http://website.com/' } }); input = ''; - assert.equal(minify(input, { minifyURLs: 'http://website.com/' }), input); - assert.equal(minify(input, { minifyURLs: { site: 'http://website.com/' } }), input); + test_minify(assert, input, input, { minifyURLs: 'http://website.com/' }); + test_minify(assert, input, input, { minifyURLs: { site: 'http://website.com/' } }); output = ''; - assert.equal(minify(input, { minifyCSS: true }), output); + test_minify(assert, input, output, { minifyCSS: true }); output = ''; - assert.equal(minify(input, { + test_minify(assert, input, output, { minifyCSS: true, minifyURLs: 'http://website.com/' - }), output); - assert.equal(minify(input, { + }); + test_minify(assert, input, output, { minifyCSS: true, minifyURLs: { site: 'http://website.com/' } - }), output); + }); input = ''; - assert.equal(minify(input, { minifyURLs: { site: 'http://website.com/foo bar/' } }), input); + test_minify(assert, input, input, { minifyURLs: { site: 'http://website.com/foo bar/' } }); output = ''; - assert.equal(minify(input, { minifyCSS: true }), output); + test_minify(assert, input, output, { minifyCSS: true }); output = ''; - assert.equal(minify(input, { + test_minify(assert, input, output, { minifyCSS: true, minifyURLs: { site: 'http://website.com/foo bar/' } - }), output); + }); input = ''; - assert.equal(minify(input, { minifyURLs: { site: 'http://website.com/' } }), input); - assert.equal(minify(input, { minifyURLs: { site: 'http://website.com/foo%20bar/' } }), input); - assert.equal(minify(input, { minifyURLs: { site: 'http://website.com/foo%20bar/(baz)/' } }), input); + test_minify(assert, input, input, { minifyURLs: { site: 'http://website.com/' } }); + test_minify(assert, input, input, { minifyURLs: { site: 'http://website.com/foo%20bar/' } }); + test_minify(assert, input, input, { minifyURLs: { site: 'http://website.com/foo%20bar/(baz)/' } }); output = ''; - assert.equal(minify(input, { + test_minify(assert, input, output, { minifyCSS: true, minifyURLs: { site: 'http://website.com/' } - }), output); + }); output = ''; - assert.equal(minify(input, { + test_minify(assert, input, output, { minifyCSS: true, minifyURLs: { site: 'http://website.com/foo%20bar/' } - }), output); + }); output = ''; - assert.equal(minify(input, { + test_minify(assert, input, output, { minifyCSS: true, minifyURLs: { site: 'http://website.com/foo%20bar/(baz)/' } - }), output); + }); input = ''; output = ''; - assert.equal(minify(input, { minifyURLs: { site: 'http://site.com/' } }), output); + test_minify(assert, input, output, { minifyURLs: { site: 'http://site.com/' } }); }); QUnit.test('srcset attribute minification', function(assert) { @@ -2400,20 +2526,20 @@ QUnit.test('srcset attribute minification', function(assert) { input = ''; output = ''; - assert.equal(minify(input), output); + test_minify(assert, input, output); output = ''; - assert.equal(minify(input, { minifyURLs: { site: 'http://site.com/' } }), output); + test_minify(assert, input, output, { minifyURLs: { site: 'http://site.com/' } }); }); QUnit.test('valueless attributes', function(assert) { var input = '
    '; - assert.equal(minify(input), input); + test_minify(assert, input, input); }); QUnit.test('newlines becoming whitespaces', function(assert) { var input = 'test\n\n\n\ntest'; var output = 'test test'; - assert.equal(minify(input, { collapseWhitespace: true }), output); + test_minify(assert, input, output, { collapseWhitespace: true }); }); QUnit.test('conservative collapse', function(assert) { @@ -2421,115 +2547,115 @@ QUnit.test('conservative collapse', function(assert) { input = ' foo \n\n'; output = ' foo '; - assert.equal(minify(input, { + test_minify(assert, input, output, { collapseWhitespace: true, conservativeCollapse: true - }), output); + }); input = '\n\n\n\n'; output = ' '; - assert.equal(minify(input, { + test_minify(assert, input, output, { removeComments: true, collapseWhitespace: true, conservativeCollapse: true - }), output); + }); input = '

    \u00A0

    '; - assert.equal(minify(input, { collapseWhitespace: true }), input); - assert.equal(minify(input, { + test_minify(assert, input, input, { collapseWhitespace: true }); + test_minify(assert, input, input, { collapseWhitespace: true, conservativeCollapse: true - }), input); + }); input = '

    \u00A0

    '; output = '

    \u00A0

    '; - assert.equal(minify(input, { collapseWhitespace: true }), output); - assert.equal(minify(input, { + test_minify(assert, input, output, { collapseWhitespace: true }); + test_minify(assert, input, output, { collapseWhitespace: true, conservativeCollapse: true - }), output); + }); input = '

    \u00A0

    '; output = '

    \u00A0

    '; - assert.equal(minify(input, { collapseWhitespace: true }), output); - assert.equal(minify(input, { + test_minify(assert, input, output, { collapseWhitespace: true }); + test_minify(assert, input, output, { collapseWhitespace: true, conservativeCollapse: true - }), output); + }); input = '

    \u00A0

    '; output = '

    \u00A0

    '; - assert.equal(minify(input, { collapseWhitespace: true }), output); - assert.equal(minify(input, { + test_minify(assert, input, output, { collapseWhitespace: true }); + test_minify(assert, input, output, { collapseWhitespace: true, conservativeCollapse: true - }), output); + }); input = '

    \u00A0\u00A0 \u00A0

    '; output = '

    \u00A0\u00A0 \u00A0

    '; - assert.equal(minify(input, { collapseWhitespace: true }), output); - assert.equal(minify(input, { + test_minify(assert, input, output, { collapseWhitespace: true }); + test_minify(assert, input, output, { collapseWhitespace: true, conservativeCollapse: true - }), output); + }); input = '

    foo \u00A0\u00A0 \u00A0

    '; output = '

    foo \u00A0\u00A0 \u00A0

    '; - assert.equal(minify(input, { collapseWhitespace: true }), output); - assert.equal(minify(input, { + test_minify(assert, input, output, { collapseWhitespace: true }); + test_minify(assert, input, output, { collapseWhitespace: true, conservativeCollapse: true - }), output); + }); input = '

    \u00A0\u00A0 \u00A0 bar

    '; output = '

    \u00A0\u00A0 \u00A0 bar

    '; - assert.equal(minify(input, { collapseWhitespace: true }), output); - assert.equal(minify(input, { + test_minify(assert, input, output, { collapseWhitespace: true }); + test_minify(assert, input, output, { collapseWhitespace: true, conservativeCollapse: true - }), output); + }); input = '

    foo \u00A0\u00A0 \u00A0 bar

    '; output = '

    foo \u00A0\u00A0 \u00A0 bar

    '; - assert.equal(minify(input, { collapseWhitespace: true }), output); - assert.equal(minify(input, { + test_minify(assert, input, output, { collapseWhitespace: true }); + test_minify(assert, input, output, { collapseWhitespace: true, conservativeCollapse: true - }), output); + }); input = '

    \u00A0foo\u00A0\t

    '; output = '

    \u00A0foo\u00A0

    '; - assert.equal(minify(input, { collapseWhitespace: true }), output); - assert.equal(minify(input, { + test_minify(assert, input, output, { collapseWhitespace: true }); + test_minify(assert, input, output, { collapseWhitespace: true, conservativeCollapse: true - }), output); + }); input = '

    \u00A0\nfoo\u00A0\t

    '; output = '

    \u00A0 foo\u00A0

    '; - assert.equal(minify(input, { collapseWhitespace: true }), output); - assert.equal(minify(input, { + test_minify(assert, input, output, { collapseWhitespace: true }); + test_minify(assert, input, output, { collapseWhitespace: true, conservativeCollapse: true - }), output); + }); input = '

    \u00A0foo \u00A0\t

    '; output = '

    \u00A0foo \u00A0

    '; - assert.equal(minify(input, { collapseWhitespace: true }), output); - assert.equal(minify(input, { + test_minify(assert, input, output, { collapseWhitespace: true }); + test_minify(assert, input, output, { collapseWhitespace: true, conservativeCollapse: true - }), output); + }); input = '

    \u00A0\nfoo \u00A0\t

    '; output = '

    \u00A0 foo \u00A0

    '; - assert.equal(minify(input, { collapseWhitespace: true }), output); - assert.equal(minify(input, { + test_minify(assert, input, output, { collapseWhitespace: true }); + test_minify(assert, input, output, { collapseWhitespace: true, conservativeCollapse: true - }), output); + }); }); QUnit.test('collapse preseving a line break', function(assert) { @@ -2559,15 +2685,15 @@ QUnit.test('collapse preseving a line break', function(assert) { '\n' + '\n' + '\n\n

    \ntest test test\n

    \n'; - assert.equal(minify(input, { + test_minify(assert, input, output, { collapseWhitespace: true, preserveLineBreaks: true - }), output); - assert.equal(minify(input, { + }); + test_minify(assert, input, output, { collapseWhitespace: true, conservativeCollapse: true, preserveLineBreaks: true - }), output); + }); output = '\n\n\n' + '\n\n\n' + 'Carbon\n\n' + @@ -2579,140 +2705,140 @@ QUnit.test('collapse preseving a line break', function(assert) { '\n' + '\n' + '\n\n

    \ntest test test\n

    \n'; - assert.equal(minify(input, { + test_minify(assert, input, output, { collapseWhitespace: true, conservativeCollapse: true, preserveLineBreaks: true, removeComments: true - }), output); + }); input = '
    text \n text \n
    '; output = '
    text \ntext\n
    '; - assert.equal(minify(input, { + test_minify(assert, input, output, { collapseWhitespace: true, preserveLineBreaks: true - }), output); + }); input = '
    text \n
    '; output = '
    text\n
    '; - assert.equal(minify(input, { + test_minify(assert, input, output, { collapseWhitespace: true, preserveLineBreaks: true - }), output); + }); output = '
    text\n
    '; - assert.equal(minify(input, { + test_minify(assert, input, output, { collapseWhitespace: true, conservativeCollapse: true, preserveLineBreaks: true - }), output); + }); input = '
    \ntext
    '; output = '
    \ntext
    '; - assert.equal(minify(input, { + test_minify(assert, input, output, { collapseWhitespace: true, preserveLineBreaks: true - }), output); + }); output = '
    \ntext
    '; - assert.equal(minify(input, { + test_minify(assert, input, output, { collapseWhitespace: true, conservativeCollapse: true, preserveLineBreaks: true - }), output); + }); input = 'This is the start. <% ... %>\r\n<%= ... %>\r\n\r\n\r\nNo comment, but middle.\r\n\r\n\r\n\r\nHello, this is the end!'; output = 'This is the start. <% ... %>\n<%= ... %>\n\nNo comment, but middle.\n\n\n\nHello, this is the end!'; - assert.equal(minify(input, { + test_minify(assert, input, output, { removeComments: true, collapseWhitespace: true, preserveLineBreaks: true - }), output); + }); }); QUnit.test('collapse inline tag whitespace', function(assert) { var input, output; input = ' '; - assert.equal(minify(input, { + test_minify(assert, input, input, { collapseWhitespace: true - }), input); + }); output = ''; - assert.equal(minify(input, { + test_minify(assert, input, output, { collapseWhitespace: true, collapseInlineTagWhitespace: true - }), output); + }); input = '

    where R is the Rici tensor.

    '; output = '

    where R is the Rici tensor.

    '; - assert.equal(minify(input, { + test_minify(assert, input, output, { collapseWhitespace: true - }), output); + }); output = '

    whereRis the Rici tensor.

    '; - assert.equal(minify(input, { + test_minify(assert, input, output, { collapseWhitespace: true, collapseInlineTagWhitespace: true - }), output); + }); }); QUnit.test('ignore custom comments', function(assert) { var input, output; input = ''; - assert.equal(minify(input), input); - assert.equal(minify(input, { removeComments: true }), input); - assert.equal(minify(input, { ignoreCustomComments: false }), input); - assert.equal(minify(input, { + test_minify(assert, input, input); + test_minify(assert, input, input, { removeComments: true }); + test_minify(assert, input, input, { ignoreCustomComments: false }); + test_minify(assert, input, '', { removeComments: true, ignoreCustomComments: [] - }), ''); - assert.equal(minify(input, { + }); + test_minify(assert, input, '', { removeComments: true, ignoreCustomComments: false - }), ''); + }); input = 'test'; output = 'test'; - assert.equal(minify(input), output); - assert.equal(minify(input, { removeComments: true }), output); - assert.equal(minify(input, { ignoreCustomComments: false }), output); - assert.equal(minify(input, { + test_minify(assert, input, output); + test_minify(assert, input, output, { removeComments: true }); + test_minify(assert, input, output, { ignoreCustomComments: false }); + test_minify(assert, input, output, { removeComments: true, ignoreCustomComments: [] - }), output); - assert.equal(minify(input, { + }); + test_minify(assert, input, output, { removeComments: true, ignoreCustomComments: false - }), output); + }); input = '
  • test
  • '; - assert.equal(minify(input, { + test_minify(assert, input, input, { removeComments: true, // ignore knockout comments ignoreCustomComments: [ /^\s+ko/, /\/ko\s+$/ ] - }), input); + }); input = ''; - assert.equal(minify(input, { + test_minify(assert, input, input, { removeComments: true, // ignore Apache SSI includes ignoreCustomComments: [ /^\s*#/ ] - }), input); + }); }); QUnit.test('processScripts', function(assert) { var input = ''; var output = ''; - assert.equal(minify(input, { + test_minify(assert, input, output, { collapseWhitespace: true, removeComments: true, processScripts: ['text/ng-template'] - }), output); + }); }); QUnit.test('ignore', function(assert) { @@ -2722,10 +2848,10 @@ QUnit.test('ignore', function(assert) { '
    \n test foo \n\n
    '; output = '
    \n test foo \n\n
    ' + '
    test foo
    '; - assert.equal(minify(input, { collapseWhitespace: true }), output); + test_minify(assert, input, output, { collapseWhitespace: true }); input = ''; - assert.equal(minify(input), ''); + test_minify(assert, input, ''); input = '

    .....

    ' + '@for( $i = 0 ; $i < $criterions->count() ; $i++ )' + @@ -2737,23 +2863,23 @@ QUnit.test('ignore', function(assert) { '

    {{ $criterions[$i]->value }}

    ' + '@endfor' + '

    ....

    '; - assert.equal(minify(input, { removeComments: true }), output); + test_minify(assert, input, output, { removeComments: true }); input = '

    bar

    '; output = '

    bar

    '; - assert.equal(minify(input), output); + test_minify(assert, input, output); input = '>'; output = '>'; - assert.equal(minify(input, { ignoreCustomFragments: [/<\?php[\s\S]*?\?>/] }), output); + test_minify(assert, input, output, { ignoreCustomFragments: [/<\?php[\s\S]*?\?>/] }); input = 'a\nb'; output = 'a b'; - assert.equal(minify(input, { collapseWhitespace: true }), output); + test_minify(assert, input, output, { collapseWhitespace: true }); input = '

    foo \n\tbar\n.

    '; output = '

    foo \n\tbar\n.

    '; - assert.equal(minify(input, { collapseWhitespace: true }), output); + test_minify(assert, input, output, { collapseWhitespace: true }); }); QUnit.test('meta viewport', function(assert) { @@ -2761,37 +2887,36 @@ QUnit.test('meta viewport', function(assert) { input = ''; output = ''; - assert.equal(minify(input), output); + test_minify(assert, input, output); input = ''; output = ''; - assert.equal(minify(input), output); + test_minify(assert, input, output); input = ''; output = ''; - assert.equal(minify(input), output); + test_minify(assert, input, output); input = ''; output = ''; - assert.equal(minify(input), output); + test_minify(assert, input, output); }); QUnit.test('downlevel-revealed conditional comments', function(assert) { var input = ''; - assert.equal(minify(input), input); - assert.equal(minify(input, { removeComments: true }), input); + test_minify(assert, input, input); + test_minify(assert, input, input, { removeComments: true }); }); QUnit.test('noscript', function(assert) { var input; input = ''; - assert.equal(minify(input), ''); + test_minify(assert, input, ''); input = ''; - assert.equal(minify(input, { removeComments: true, collapseWhitespace: true, removeEmptyAttributes: true }), - ''); + test_minify(assert, input, '', { removeComments: true, collapseWhitespace: true, removeEmptyAttributes: true }); }); QUnit.test('max line length', function(assert) { @@ -2799,57 +2924,51 @@ QUnit.test('max line length', function(assert) { var options = { maxLineLength: 25 }; input = '123456789012345678901234567890'; - assert.equal(minify(input, options), input); + test_minify(assert, input, input, options); input = '
    '; - assert.equal(minify(input, options), '
    \n
    '); + test_minify(assert, input, '
    \n
    ', options); input = ' hello world \n world hello '; - assert.equal(minify(input, options), '\n hello world \n world hello \n'); + test_minify(assert, input, '\n hello world \n world hello \n', options); - assert.equal(minify('

    x

    '), '

    x

    '); - assert.equal(minify('

    x

    '), '

    x

    '); - assert.equal(minify('

    x

    '), '

    x

    '); - assert.equal(minify('

    xxx

    '), '

    xxx

    '); - assert.equal(minify('

    xxx

    '), '

    xxx

    '); + test_minify(assert, '

    x

    ', '

    x

    '); + test_minify(assert, '

    x

    ', '

    x

    '); + test_minify(assert, '

    x

    ', '

    x

    '); + test_minify(assert, '

    xxx

    ', '

    xxx

    '); + test_minify(assert, '

    xxx

    ', '

    xxx

    '); input = '
    ' + 'i\'m 10 levels deep' + '
    '; - assert.equal(minify(input), input); + test_minify(assert, input, input); - assert.equal(minify('', options), ''); + test_minify(assert, '', '', options); input = ''; - assert.equal(minify('', options), input); - assert.equal(minify(input, options), input); - assert.equal(minify('', options), ''); - - assert.equal(minify('foo', options), 'foo\n'); - assert.equal(minify('

    x', options), '

    x

    '); - assert.equal(minify('

    x

    ', options), '

    x

    ', 'trailing quote should be ignored'); - assert.equal(minify('

    Click me

    ', options), '

    Click me\n

    '); + test_minify(assert, '', input, options); + test_minify(assert, input, input, options); + test_minify(assert, '', '', options); + + test_minify(assert, 'foo', 'foo\n', options); + test_minify(assert, '

    x', '

    x

    ', options); + test_minify(assert, '

    x

    ', '

    x

    ', options, 'trailing quote should be ignored'); + test_minify(assert, '

    Click me

    ', '

    Click me\n

    ', options); input = ''; - assert.equal(minify('', options), input); - assert.equal(minify(input, options), input); - assert.equal(minify('
    [fallback image]
    ', options), - '
    \n[fallback image]
    \n
    ' - ); + test_minify(assert, '', input, options); + test_minify(assert, input, input, options); + test_minify(assert, '
    [fallback image]
    ', '
    \n[fallback image]
    \n
    ', options); - assert.equal(minify('', options), '\n'); - assert.equal(minify('', options), '\n'); - assert.equal(minify('
    ', options), - '\n
    ' - ); - assert.equal(minify('', options), - '\n\n\n' - ); - assert.equal(minify('[\']["]', options), '[\']["]'); - assert.equal(minify('
    hey
    ', options), '\n
    hey
    '); - assert.equal(minify(':) link', options), ':) \nlink'); - assert.equal(minify(':) \nlink', options), ':) \nlink'); - assert.equal(minify(':) \n\nlink', options), ':) \n\nlink'); + test_minify(assert, '', '\n', options); + test_minify(assert, '', '\n', options); + test_minify(assert, '
    ', '\n
    ', options); + test_minify(assert, '', '\n\n\n', options); + test_minify(assert, '[\']["]', '[\']["]', options); + test_minify(assert, '
    hey
    ', '\n
    hey
    ', options); + test_minify(assert, ':) link', ':) \nlink', options); + test_minify(assert, ':) \nlink', ':) \nlink', options); + test_minify(assert, ':) \n\nlink', ':) \n\nlink', options); - assert.equal(minify('ok', options), 'ok'); + test_minify(assert, 'ok', 'ok', options); }); QUnit.test('custom attribute collapse', function(assert) { @@ -2866,15 +2985,15 @@ QUnit.test('custom attribute collapse', function(assert) { '">foo'; output = '
    foo
    '; - assert.equal(minify(input), input); - assert.equal(minify(input, { customAttrCollapse: /data-bind/ }), output); + test_minify(assert, input, input); + test_minify(assert, input, output, { customAttrCollapse: /data-bind/ }); input = '
    bar
    '; output = '
    bar
    '; - assert.equal(minify(input, { customAttrCollapse: /style/ }), output); + test_minify(assert, input, output, { customAttrCollapse: /style/ }); input = '
    ' + '
    '; output = '
    '; - assert.equal(minify(input, { customAttrCollapse: /ng-class/ }), output); + test_minify(assert, input, output, { customAttrCollapse: /ng-class/ }); }); QUnit.test('custom attribute collapse with empty attribute value', function(assert) { var input = '
    '; var output = '
    '; - assert.equal(minify(input, { customAttrCollapse: /.+/ }), output); + test_minify(assert, input, output, { customAttrCollapse: /.+/ }); }); QUnit.test('custom attribute collapse with newlines, whitespace, and carriage returns', function(assert) { @@ -2901,7 +3020,7 @@ QUnit.test('custom attribute collapse with newlines, whitespace, and carriage re ' value2:false \n\r' + ' }">'; var output = '
    '; - assert.equal(minify(input, { customAttrCollapse: /ng-class/ }), output); + test_minify(assert, input, output, { customAttrCollapse: /ng-class/ }); }); QUnit.test('do not escape attribute value', function(assert) { @@ -2910,23 +3029,23 @@ QUnit.test('do not escape attribute value', function(assert) { input = '
    \n"' + '}\'>'; - assert.equal(minify(input), input); - assert.equal(minify(input, { preventAttributesEscaping: true }), input); + test_minify(assert, input, input); + test_minify(assert, input, input, { preventAttributesEscaping: true }); input = '
    '; - assert.equal(minify(input, { preventAttributesEscaping: true }), input); + test_minify(assert, input, input, { preventAttributesEscaping: true }); output = '
    '; - assert.equal(minify(input), output); + test_minify(assert, input, output); }); QUnit.test('quoteCharacter is single quote', function(assert) { - assert.equal(minify('
    foo
    ', { quoteCharacter: '\'' }), '
    foo
    '); - assert.equal(minify('
    foo
    ', { quoteCharacter: '\'' }), '
    foo
    '); + test_minify(assert, '
    foo
    ', '
    foo
    ', { quoteCharacter: '\'' }); + test_minify(assert, '
    foo
    ', '
    foo
    ', { quoteCharacter: '\'' }); }); QUnit.test('quoteCharacter is not single quote or double quote', function(assert) { - assert.equal(minify('
    foo
    ', { quoteCharacter: 'm' }), '
    foo
    '); - assert.equal(minify('
    foo
    ', { quoteCharacter: 'm' }), '
    foo
    '); + test_minify(assert, '
    foo
    ', '
    foo
    ', { quoteCharacter: 'm' }); + test_minify(assert, '
    foo
    ', '
    foo
    ', { quoteCharacter: 'm' }); }); QUnit.test('remove space between attributes', function(assert) { @@ -2940,27 +3059,27 @@ QUnit.test('remove space between attributes', function(assert) { input = ''; output = ''; - assert.equal(minify(input, options), output); + test_minify(assert, input, output, options); input = ''; output = ''; - assert.equal(minify(input, options), output); + test_minify(assert, input, output, options); input = ''; output = ''; - assert.equal(minify(input, options), output); + test_minify(assert, input, output, options); input = ''; output = ''; - assert.equal(minify(input, options), output); + test_minify(assert, input, output, options); input = ''; output = ''; - assert.equal(minify(input, options), output); + test_minify(assert, input, output, options); input = ''; output = ''; - assert.equal(minify(input, options), output); + test_minify(assert, input, output, options); }); QUnit.test('markups from Angular 2', function(assert) { @@ -2986,7 +3105,7 @@ QUnit.test('markups from Angular 2', function(assert) { ' \n' + ' \n' + ''; - assert.equal(minify(input, { caseSensitive: true }), output); + test_minify(assert, input, output, { caseSensitive: true }); output = '' + @@ -2997,7 +3116,7 @@ QUnit.test('markups from Angular 2', function(assert) { '' + '' + ''; - assert.equal(minify(input, { + test_minify(assert, input, output, { caseSensitive: true, collapseBooleanAttributes: true, collapseWhitespace: true, @@ -3010,58 +3129,58 @@ QUnit.test('markups from Angular 2', function(assert) { removeStyleLinkTypeAttributes: true, removeTagWhitespace: true, useShortDoctype: true - }), output); + }); }); QUnit.test('auto-generated tags', function(assert) { var input, output; input = '

    '; - assert.equal(minify(input, { includeAutoGeneratedTags: false }), input); + test_minify(assert, input, input, { includeAutoGeneratedTags: false }); input = '

    x'; output = '

    x'; - assert.equal(minify(input, { includeAutoGeneratedTags: false }), output); + test_minify(assert, input, output, { includeAutoGeneratedTags: false }); output = '

    x

    '; - assert.equal(minify(input), output); - assert.equal(minify(input, { includeAutoGeneratedTags: true }), output); + test_minify(assert, input, output); + test_minify(assert, input, output, { includeAutoGeneratedTags: true }); input = '

    x'; output = '

    x'; - assert.equal(minify(input, { includeAutoGeneratedTags: false }), output); + test_minify(assert, input, output, { includeAutoGeneratedTags: false }); input = '

    Well, look at me! I\'m a div!
    '; output = '
    Well, look at me! I\'m a div!
    '; - assert.equal(minify(input, { html5: false, includeAutoGeneratedTags: false }), output); - assert.equal(minify('

    x', { + test_minify(assert, input, output, { html5: false, includeAutoGeneratedTags: false }); + test_minify(assert, '

    x', '

    x', { maxLineLength: 25, includeAutoGeneratedTags: false - }), '

    x'); + }); input = '

    foo'; - assert.equal(minify(input, { includeAutoGeneratedTags: false }), input); - assert.equal(minify(input, { + test_minify(assert, input, input, { includeAutoGeneratedTags: false }); + test_minify(assert, input, input, { includeAutoGeneratedTags: false, removeOptionalTags: true - }), input); + }); input = '

    '; - assert.equal(minify(input, { includeAutoGeneratedTags: false }), input); + test_minify(assert, input, input, { includeAutoGeneratedTags: false }); output = ''; - assert.equal(minify(input, { + test_minify(assert, input, output, { includeAutoGeneratedTags: false, removeOptionalTags: true - }), output); + }); input = ''; - assert.equal(minify(input, { includeAutoGeneratedTags: false }), input); + test_minify(assert, input, input, { includeAutoGeneratedTags: false }); output = ''; - assert.equal(minify(input, { includeAutoGeneratedTags: true }), output); + test_minify(assert, input, output, { includeAutoGeneratedTags: true }); input = ''; - assert.equal(minify(input, { includeAutoGeneratedTags: false }), input); + test_minify(assert, input, input, { includeAutoGeneratedTags: false }); output = ''; - assert.equal(minify(input, { includeAutoGeneratedTags: true }), output); + test_minify(assert, input, output, { includeAutoGeneratedTags: true }); }); QUnit.test('sort attributes', function(assert) { @@ -3070,31 +3189,31 @@ QUnit.test('sort attributes', function(assert) { input = '' + '' + ''; - assert.equal(minify(input), input); - assert.equal(minify(input, { sortAttributes: false }), input); + test_minify(assert, input, input); + test_minify(assert, input, input, { sortAttributes: false }); output = '' + '' + ''; - assert.equal(minify(input, { sortAttributes: true }), output); + test_minify(assert, input, output, { sortAttributes: true }); input = '' + '' + ''; - assert.equal(minify(input), input); - assert.equal(minify(input, { sortAttributes: false }), input); + test_minify(assert, input, input); + test_minify(assert, input, input, { sortAttributes: false }); output = '' + '' + ''; - assert.equal(minify(input, { sortAttributes: true }), output); + test_minify(assert, input, output, { sortAttributes: true }); output = '' + '' + ''; - assert.equal(minify(input, { + test_minify(assert, input, output, { processScripts: [ 'text/html' ], sortAttributes: true - }), output); + }); input = '' + '' + @@ -3102,45 +3221,45 @@ QUnit.test('sort attributes', function(assert) { output = '' + '' + ''; - assert.equal(minify(input, { sortAttributes: true }), output); + test_minify(assert, input, output, { sortAttributes: true }); output = '' + '' + ''; - assert.equal(minify(input, { + test_minify(assert, input, output, { removeStyleLinkTypeAttributes: true, sortAttributes: true - }), output); + }); input = '
    ' + '' + '' + '' + ''; - assert.equal(minify(input), input); - assert.equal(minify(input, { sortAttributes: false }), input); + test_minify(assert, input, input); + test_minify(assert, input, input, { sortAttributes: false }); output = '' + '' + '' + '' + ''; - assert.equal(minify(input, { sortAttributes: true }), output); + test_minify(assert, input, output, { sortAttributes: true }); input = ' foo_bar>'; - assert.equal(minify(input, { + test_minify(assert, input, input, { ignoreCustomFragments: [/<#[\s\S]*?#>/] - }), input); - assert.equal(minify(input, { + }); + test_minify(assert, input, input, { ignoreCustomFragments: [/<#[\s\S]*?#>/], sortAttributes: false - }), input); + }); output = ' >'; - assert.equal(minify(input, { + test_minify(assert, input, output, { ignoreCustomFragments: [/<#[\s\S]*?#>/], sortAttributes: true - }), output); + }); input = ''; - assert.equal(minify(input, { sortAttributes: true }), input); + test_minify(assert, input, input, { sortAttributes: true }); }); QUnit.test('sort style classes', function(assert) { @@ -3151,125 +3270,125 @@ QUnit.test('sort style classes', function(assert) { '' + '' + ''; - assert.equal(minify(input), input); - assert.equal(minify(input, { sortClassName: false }), input); + test_minify(assert, input, input); + test_minify(assert, input, input, { sortClassName: false }); output = '' + '' + '' + '' + ''; - assert.equal(minify(input, { sortClassName: true }), output); + test_minify(assert, input, output, { sortClassName: true }); input = ''; output = ''; - assert.equal(minify(input), output); - assert.equal(minify(input, { sortClassName: false }), output); + test_minify(assert, input, output); + test_minify(assert, input, output, { sortClassName: false }); output = ''; - assert.equal(minify(input, { sortClassName: true }), output); + test_minify(assert, input, output, { sortClassName: true }); input = ''; - assert.equal(minify(input, { + test_minify(assert, input, input, { ignoreCustomFragments: [/<#[\s\S]*?#>/] - }), input); - assert.equal(minify(input, { + }); + test_minify(assert, input, input, { ignoreCustomFragments: [/<#[\s\S]*?#>/], sortClassName: false - }), input); - assert.equal(minify(input, { + }); + test_minify(assert, input, input, { ignoreCustomFragments: [/<#[\s\S]*?#>/], sortClassName: true - }), input); + }); input = ''; - assert.equal(minify(input, { sortClassName: false }), input); - assert.equal(minify(input, { sortClassName: true }), input); + test_minify(assert, input, input, { sortClassName: false }); + test_minify(assert, input, input, { sortClassName: true }); input = ''; - assert.equal(minify(input, { sortClassName: false }), input); + test_minify(assert, input, input, { sortClassName: false }); output = ''; - assert.equal(minify(input, { sortClassName: true }), output); + test_minify(assert, input, output, { sortClassName: true }); input = ''; - assert.equal(minify(input, { + test_minify(assert, input, input, { collapseWhitespace: true, ignoreCustomFragments: [/{{.*?}}/], removeAttributeQuotes: true, sortClassName: true - }), input); + }); input = ''; - assert.equal(minify(input, { + test_minify(assert, input, input, { collapseWhitespace: true, ignoreCustomFragments: [/{{.*?}}/], removeAttributeQuotes: true, sortClassName: true - }), input); + }); input = ''; - assert.equal(minify(input, { + test_minify(assert, input, input, { collapseWhitespace: true, ignoreCustomFragments: [/{{.*?}}/], removeAttributeQuotes: true, sortClassName: true - }), input); + }); input = ''; - assert.equal(minify(input, { + test_minify(assert, input, input, { collapseWhitespace: true, ignoreCustomFragments: [/{{.*?}}/], removeAttributeQuotes: true, sortClassName: true - }), input); + }); input = ''; output = ''; - assert.equal(minify(input, { + test_minify(assert, input, output, { collapseWhitespace: true, ignoreCustomFragments: [/{{.*?}}/], removeAttributeQuotes: true, sortClassName: true - }), output); + }); }); QUnit.test('decode entity characters', function(assert) { var input, output; input = ''; - assert.equal(minify(input), input); - assert.equal(minify(input, { decodeEntities: false }), input); - assert.equal(minify(input, { decodeEntities: true }), input); + test_minify(assert, input, input); + test_minify(assert, input, input, { decodeEntities: false }); + test_minify(assert, input, input, { decodeEntities: true }); input = ''; - assert.equal(minify(input), input); - assert.equal(minify(input, { decodeEntities: false }), input); - assert.equal(minify(input, { decodeEntities: true }), input); + test_minify(assert, input, input); + test_minify(assert, input, input, { decodeEntities: false }); + test_minify(assert, input, input, { decodeEntities: true }); output = ''; - assert.equal(minify(input, { decodeEntities: true, processScripts: ['text/html'] }), output); + test_minify(assert, input, output, { decodeEntities: true, processScripts: ['text/html'] }); input = '
    foo$
    '; - assert.equal(minify(input), input); - assert.equal(minify(input, { decodeEntities: false }), input); + test_minify(assert, input, input); + test_minify(assert, input, input, { decodeEntities: false }); output = '
    foo$
    '; - assert.equal(minify(input, { decodeEntities: true }), output); + test_minify(assert, input, output, { decodeEntities: true }); output = '
    foo$
    '; - assert.equal(minify(input, { minifyCSS: true }), output); - assert.equal(minify(input, { decodeEntities: false, minifyCSS: true }), output); + test_minify(assert, input, output, { minifyCSS: true }); + test_minify(assert, input, output, { decodeEntities: false, minifyCSS: true }); output = '
    foo$
    '; - assert.equal(minify(input, { decodeEntities: true, minifyCSS: true }), output); + test_minify(assert, input, output, { decodeEntities: true, minifyCSS: true }); input = 'baz<moo>©'; - assert.equal(minify(input), input); - assert.equal(minify(input, { decodeEntities: false }), input); + test_minify(assert, input, input); + test_minify(assert, input, input, { decodeEntities: false }); output = 'baz<moo>\u00a9'; - assert.equal(minify(input, { decodeEntities: true }), output); + test_minify(assert, input, output, { decodeEntities: true }); input = '&
    &
    '; - assert.equal(minify(input), input); - assert.equal(minify(input, { collapseWhitespace: false, decodeEntities: false }), input); - assert.equal(minify(input, { collapseWhitespace: true, decodeEntities: false }), input); + test_minify(assert, input, input); + test_minify(assert, input, input, { collapseWhitespace: false, decodeEntities: false }); + test_minify(assert, input, input, { collapseWhitespace: true, decodeEntities: false }); output = '&
    &
    '; - assert.equal(minify(input, { collapseWhitespace: false, decodeEntities: true }), output); - assert.equal(minify(input, { collapseWhitespace: true, decodeEntities: true }), output); + test_minify(assert, input, output, { collapseWhitespace: false, decodeEntities: true }); + test_minify(assert, input, output, { collapseWhitespace: true, decodeEntities: true }); }); QUnit.test('tests from PHPTAL', function(assert) { @@ -3351,7 +3470,7 @@ QUnit.test('tests from PHPTAL', function(assert) { 'foo ' ]*/ ].forEach(function(tokens) { - assert.equal(minify(tokens[1], { + test_minify(assert, tokens[1], tokens[0], { collapseBooleanAttributes: true, collapseWhitespace: true, removeAttributeQuotes: true, @@ -3364,7 +3483,7 @@ QUnit.test('tests from PHPTAL', function(assert) { removeTagWhitespace: true, sortAttributes: true, useShortDoctype: true - }), tokens[0]); + }); }); }); @@ -3379,31 +3498,119 @@ QUnit.test('canCollapseWhitespace and canTrimWhitespace hooks', function(assert) var input = '
    foo bar
    '; var output = '
    foo bar
    '; - assert.equal(minify(input, { + test_minify(assert, input, output, { collapseWhitespace: true, canTrimWhitespace: canCollapseAndTrimWhitespace, canCollapseWhitespace: canCollapseAndTrimWhitespace - }), output); + }); // Regression test: Previously the first would clear the internal // stackNo{Collapse,Trim}Whitespace, so that ' foo bar' turned into ' foo bar' input = '
    foo bar
    '; output = '
    foo bar
    '; - assert.equal(minify(input, { + test_minify(assert, input, output, { collapseWhitespace: true, canTrimWhitespace: canCollapseAndTrimWhitespace, canCollapseWhitespace: canCollapseAndTrimWhitespace - }), output); + }); // Make sure that the stack does get reset when leaving the element for which // the hooks returned false: input = '
    foo bar
    '; output = '
    foo bar
    '; - assert.equal(minify(input, { + test_minify(assert, input, output, { collapseWhitespace: true, canTrimWhitespace: canCollapseAndTrimWhitespace, canCollapseWhitespace: canCollapseAndTrimWhitespace - }), output); + }); +}); + +QUnit.test('minify error with callback', function(assert) { + var input = '<$unicorn>'; + + var done = assert.async(); + assert.timeout(100); + + try { + assert.notOk(minify(input, null, function(error, result) { + assert.ok(error, 'An error should have occurred.'); + assert.ok(error instanceof Error, '"' + error + '" was returned as an error.'); + assert.throws(function() { throw error; }, null, 'An error should have been thrown'); + assert.notOk(result); + done(); + })); + } + catch (error) { + // An error shouldn't be thrown - fail the test. + if (error && error instanceof Error) { + assert.ok(false, test.descriptionPrefix + 'threw an error - stack trace:\n' + error.stack); + } + else { + assert.ok(false, test.descriptionPrefix + 'threw an error - "' + error + '"'); + } + done(); + } +}); + +QUnit.test('error in callback', function(assert) { + var input = ''; + var cssError = new Error(); + + function css() { + throw cssError; + } + + var done = assert.async(); + assert.timeout(100); + + try { + assert.notOk(minify(input, { minifyCSS: css }, function(error, result) { + assert.ok(error, 'An error should have occurred.'); + assert.ok(error instanceof Error, '"' + error + '" was returned as an error.'); + assert.throws(function() { throw error; }, cssError, cssError + ' should have been thrown'); + assert.notOk(result); + done(); + })); + } + catch (error) { + // An error shouldn't be thrown - fail the test. + if (error && error instanceof Error) { + assert.ok(false, test.descriptionPrefix + 'threw an error - stack trace:\n' + error.stack); + } + else { + assert.ok(false, test.descriptionPrefix + 'threw an error - "' + error + '"'); + } + done(); + } +}); + +QUnit.test('callback called multiple times', function(assert) { + var input, done; + + function bad(_, __, cb) { + try { + cb(''); + cb(''); + assert.ok(false, 'An error should be thrown.'); + } + catch (error) { + assert.equal(error.message, 'Async completion has already occurred.'); + } + finally { + done(); + } + } + + input = ''; + + done = assert.async(); + minify(input, { minifyCSS: bad }); + + done = assert.async(); + minify(input, { minifyJS: bad }); + + done = assert.async(2); + minify(input, { minifyCSS: bad, minifyJS: bad }); });