js-beautify
Advanced tools
Comparing version 1.6.2 to 1.6.3
# Changelog | ||
## v1.6.3 | ||
### Description | ||
Bug fixes | ||
### Closed Issues | ||
* CLI broken when output path is not set ([#933](https://github.com/beautify-web/js-beautify/issues/933)) | ||
* huge memory leak ([#909](https://github.com/beautify-web/js-beautify/issues/909)) | ||
* don't print unpacking errors on stdout (python) ([#884](https://github.com/beautify-web/js-beautify/pull/884)) | ||
* Fix incomplete list of non-positionable operators (python lib) ([#878](https://github.com/beautify-web/js-beautify/pull/878)) | ||
* Fix Issue #844 ([#873](https://github.com/beautify-web/js-beautify/pull/873)) | ||
* assignment exponentiation operator ([#864](https://github.com/beautify-web/js-beautify/issues/864)) | ||
* Bug in Less mixins ([#844](https://github.com/beautify-web/js-beautify/issues/844)) | ||
* Can't Nest Conditionals ([#680](https://github.com/beautify-web/js-beautify/issues/680)) | ||
* ternary operations ([#670](https://github.com/beautify-web/js-beautify/issues/670)) | ||
* Support newline before logical or ternary operator ([#605](https://github.com/beautify-web/js-beautify/issues/605)) | ||
* Provide config files for format and linting ([#336](https://github.com/beautify-web/js-beautify/issues/336)) | ||
## v1.6.2 | ||
@@ -25,3 +44,2 @@ | ||
* Inline Format ([#572](https://github.com/beautify-web/js-beautify/issues/572)) | ||
* Add "collapse-one-line" option for braces ([#487](https://github.com/beautify-web/js-beautify/issues/487)) | ||
* Preserve attributes line break in HTML ([#455](https://github.com/beautify-web/js-beautify/issues/455)) | ||
@@ -28,0 +46,0 @@ * Multiline Array ([#406](https://github.com/beautify-web/js-beautify/issues/406)) |
@@ -19,3 +19,3 @@ /** | ||
// the default is js | ||
var beautify = function (src, config) { | ||
var beautify = function(src, config) { | ||
return js_beautify.js_beautify(src, config); | ||
@@ -25,9 +25,9 @@ }; | ||
// short aliases | ||
beautify.js = js_beautify.js_beautify; | ||
beautify.css = css_beautify.css_beautify; | ||
beautify.js = js_beautify.js_beautify; | ||
beautify.css = css_beautify.css_beautify; | ||
beautify.html = html_beautify.html_beautify; | ||
// legacy aliases | ||
beautify.js_beautify = js_beautify.js_beautify; | ||
beautify.css_beautify = css_beautify.css_beautify; | ||
beautify.js_beautify = js_beautify.js_beautify; | ||
beautify.css_beautify = css_beautify.css_beautify; | ||
beautify.html_beautify = html_beautify.html_beautify; | ||
@@ -56,3 +56,2 @@ | ||
})(module); | ||
} | ||
} |
@@ -42,9 +42,10 @@ /*jshint curly:true, eqeqeq:true, laxbreak:true, noempty:false */ | ||
The options are (default in brackets): | ||
indent_size (4) — indentation size, | ||
indent_char (space) — character to indent with, | ||
selector_separator_newline (true) - separate selectors with newline or | ||
not (e.g. "a,\nbr" or "a, br") | ||
end_with_newline (false) - end with a newline | ||
newline_between_rules (true) - add a new line after every css rule | ||
indent_size (4) — indentation size, | ||
indent_char (space) — character to indent with, | ||
selector_separator_newline (true) - separate selectors with newline or | ||
not (e.g. "a,\nbr" or "a, br") | ||
end_with_newline (false) - end with a newline | ||
newline_between_rules (true) - add a new line after every css rule | ||
space_around_selector_separator (false) - ensure space around selector separators: | ||
'>', '+', '~' (e.g. "a>b" -> "a > b") | ||
e.g | ||
@@ -57,3 +58,4 @@ | ||
'end_with_newline': false, | ||
'newline_between_rules': true | ||
'newline_between_rules': true, | ||
'space_around_selector_separator': true | ||
}); | ||
@@ -70,3 +72,3 @@ */ | ||
// HACK: newline parsing inconsistent. This brute force normalizes the input. | ||
source_text = source_text.replace(/\r\n|[\r\u2028\u2029]/g, '\n') | ||
source_text = source_text.replace(/\r\n|[\r\u2028\u2029]/g, '\n'); | ||
@@ -78,2 +80,3 @@ var indentSize = options.indent_size || 4; | ||
var newline_between_rules = (options.newline_between_rules === undefined) ? true : options.newline_between_rules; | ||
var spaceAroundSelectorSeparator = (options.space_around_selector_separator === undefined) ? false : options.space_around_selector_separator; | ||
var eol = options.eol ? options.eol : '\n'; | ||
@@ -86,3 +89,3 @@ | ||
if(options.indent_with_tabs){ | ||
if (options.indent_with_tabs) { | ||
indentCharacter = '\t'; | ||
@@ -92,3 +95,3 @@ indentSize = 1; | ||
eol = eol.replace(/\\r/, '\r').replace(/\\n/, '\n') | ||
eol = eol.replace(/\\r/, '\r').replace(/\\n/, '\n'); | ||
@@ -98,3 +101,2 @@ | ||
var whiteRe = /^\s+$/; | ||
var wordRe = /[\w$\-_]/; | ||
@@ -199,3 +201,3 @@ var pos = -1, | ||
} else if (ch === ')') { | ||
if (openParen == 0) { | ||
if (openParen === 0) { | ||
return false; | ||
@@ -306,3 +308,3 @@ } | ||
} else if (ch === '/' && peek() === '/') { // single line comment | ||
if (!isAfterNewline && last_top_ch !== '{' ) { | ||
if (!isAfterNewline && last_top_ch !== '{') { | ||
print.trim(); | ||
@@ -315,27 +317,33 @@ } | ||
print.preserveSingleSpace(); | ||
output.push(ch); | ||
// strip trailing space, if present, for hash property checks | ||
var variableOrRule = peekString(": ,;{}()[]/='\""); | ||
// deal with less propery mixins @{...} | ||
if (peek() === '{') { | ||
output.push(eatString('}')); | ||
} else { | ||
output.push(ch); | ||
if (variableOrRule.match(/[ :]$/)) { | ||
// we have a variable or pseudo-class, add it and insert one space before continuing | ||
next(); | ||
variableOrRule = eatString(": ").replace(/\s$/, ''); | ||
output.push(variableOrRule); | ||
print.singleSpace(); | ||
} | ||
// strip trailing space, if present, for hash property checks | ||
var variableOrRule = peekString(": ,;{}()[]/='\""); | ||
variableOrRule = variableOrRule.replace(/\s$/, '') | ||
if (variableOrRule.match(/[ :]$/)) { | ||
// we have a variable or pseudo-class, add it and insert one space before continuing | ||
next(); | ||
variableOrRule = eatString(": ").replace(/\s$/, ''); | ||
output.push(variableOrRule); | ||
print.singleSpace(); | ||
} | ||
// might be a nesting at-rule | ||
if (variableOrRule in css_beautify.NESTED_AT_RULE) { | ||
nestedLevel += 1; | ||
if (variableOrRule in css_beautify.CONDITIONAL_GROUP_RULE) { | ||
enteringConditionalGroup = true; | ||
variableOrRule = variableOrRule.replace(/\s$/, ''); | ||
// might be a nesting at-rule | ||
if (variableOrRule in css_beautify.NESTED_AT_RULE) { | ||
nestedLevel += 1; | ||
if (variableOrRule in css_beautify.CONDITIONAL_GROUP_RULE) { | ||
enteringConditionalGroup = true; | ||
} | ||
} | ||
} | ||
} else if (ch === '#' && peek() === '{') { | ||
print.preserveSingleSpace(); | ||
output.push(eatString('}')); | ||
print.preserveSingleSpace(); | ||
output.push(eatString('}')); | ||
} else if (ch === '{') { | ||
@@ -430,2 +438,11 @@ if (peek(true) === '}') { | ||
} | ||
} else if (ch === '>' || ch === '+' || ch === '~') { | ||
//handl selector separator spacing | ||
if (spaceAroundSelectorSeparator && !insidePropertyValue && parenLevel < 1) { | ||
print.singleSpace(); | ||
output.push(ch); | ||
print.singleSpace(); | ||
} else { | ||
output.push(ch); | ||
} | ||
} else if (ch === ']') { | ||
@@ -437,3 +454,3 @@ output.push(ch); | ||
} else if (ch === '=') { // no whitespace before or after | ||
eatWhitespace() | ||
eatWhitespace(); | ||
ch = '='; | ||
@@ -460,3 +477,3 @@ output.push(ch); | ||
if (eol != '\n') { | ||
if (eol !== '\n') { | ||
sweetCode = sweetCode.replace(/[\n]/g, eol); | ||
@@ -504,2 +521,2 @@ } | ||
}()); | ||
}()); |
@@ -75,5 +75,5 @@ /*jshint curly:true, eqeqeq:true, laxbreak:true, noempty:false */ | ||
function trim(s) { | ||
return s.replace(/^\s+|\s+$/g, ''); | ||
} | ||
// function trim(s) { | ||
// return s.replace(/^\s+|\s+$/g, ''); | ||
// } | ||
@@ -85,3 +85,3 @@ function ltrim(s) { | ||
function rtrim(s) { | ||
return s.replace(/\s+$/g,''); | ||
return s.replace(/\s+$/g, ''); | ||
} | ||
@@ -112,3 +112,3 @@ | ||
if ((options.wrap_line_length === undefined || parseInt(options.wrap_line_length, 10) === 0) && | ||
(options.max_char !== undefined && parseInt(options.max_char, 10) !== 0)) { | ||
(options.max_char !== undefined && parseInt(options.max_char, 10) !== 0)) { | ||
options.wrap_line_length = options.max_char; | ||
@@ -121,3 +121,3 @@ } | ||
brace_style = (options.brace_style === undefined) ? 'collapse' : options.brace_style; | ||
wrap_line_length = parseInt(options.wrap_line_length, 10) === 0 ? 32786 : parseInt(options.wrap_line_length || 250, 10); | ||
wrap_line_length = parseInt(options.wrap_line_length, 10) === 0 ? 32786 : parseInt(options.wrap_line_length || 250, 10); | ||
unformatted = options.unformatted || [ | ||
@@ -138,4 +138,4 @@ // https://www.w3.org/TR/html5/dom.html#phrasing-content | ||
max_preserve_newlines = preserve_newlines ? | ||
(isNaN(parseInt(options.max_preserve_newlines, 10)) ? 32786 : parseInt(options.max_preserve_newlines, 10)) | ||
: 0; | ||
(isNaN(parseInt(options.max_preserve_newlines, 10)) ? 32786 : parseInt(options.max_preserve_newlines, 10)) : | ||
0; | ||
indent_handlebars = (options.indent_handlebars === undefined) ? false : options.indent_handlebars; | ||
@@ -145,3 +145,3 @@ wrap_attributes = (options.wrap_attributes === undefined) ? 'auto' : options.wrap_attributes; | ||
end_with_newline = (options.end_with_newline === undefined) ? false : options.end_with_newline; | ||
extra_liners = (typeof options.extra_liners == 'object') && options.extra_liners ? | ||
extra_liners = (typeof options.extra_liners === 'object') && options.extra_liners ? | ||
options.extra_liners.concat() : (typeof options.extra_liners === 'string') ? | ||
@@ -151,3 +151,3 @@ options.extra_liners.split(',') : 'head,body,/html'.split(','); | ||
if(options.indent_with_tabs){ | ||
if (options.indent_with_tabs) { | ||
indent_character = '\t'; | ||
@@ -157,3 +157,3 @@ indent_size = 1; | ||
eol = eol.replace(/\\r/, '\r').replace(/\\n/, '\n') | ||
eol = eol.replace(/\\r/, '\r').replace(/\\n/, '\n'); | ||
@@ -253,4 +253,3 @@ function Parser() { | ||
var input_char = '', | ||
content = [], | ||
space = false; //if a space is needed | ||
content = []; | ||
@@ -297,3 +296,2 @@ while (this.input.charAt(this.pos) !== '<') { | ||
} | ||
var input_char = ''; | ||
var content = ''; | ||
@@ -408,3 +406,3 @@ var reg_match = new RegExp('</' + name + '\\s*>', 'igm'); | ||
space = false; | ||
if (!first_attr && wrap_attributes === 'force' && input_char !== '/') { | ||
if (!first_attr && wrap_attributes === 'force' && input_char !== '/') { | ||
this.print_newline(false, content); | ||
@@ -421,6 +419,6 @@ this.print_indentation(content); | ||
for (var i = 0; i < content.length; i++) { | ||
if (content[i] === ' ') { | ||
first_attr = false; | ||
break; | ||
} | ||
if (content[i] === ' ') { | ||
first_attr = false; | ||
break; | ||
} | ||
} | ||
@@ -515,4 +513,4 @@ } | ||
(tag_complete.search('type') === -1 || | ||
(tag_complete.search('type') > -1 && | ||
tag_complete.search(/\b(text|application)\/(x-)?(javascript|ecmascript|jscript|livescript|(ld\+)?json)/) > -1))) { | ||
(tag_complete.search('type') > -1 && | ||
tag_complete.search(/\b(text|application)\/(x-)?(javascript|ecmascript|jscript|livescript|(ld\+)?json)/) > -1))) { | ||
if (!peek) { | ||
@@ -524,3 +522,3 @@ this.record_tag(tag_check); | ||
(tag_complete.search('type') === -1 || | ||
(tag_complete.search('type') > -1 && tag_complete.search('text/css') > -1))) { | ||
(tag_complete.search('type') > -1 && tag_complete.search('text/css') > -1))) { | ||
if (!peek) { | ||
@@ -622,17 +620,17 @@ this.record_tag(tag_check); | ||
function tokenMatcher(delimiter) { | ||
var token = ''; | ||
var token = ''; | ||
var add = function (str) { | ||
var newToken = token + str.toLowerCase(); | ||
token = newToken.length <= delimiter.length ? newToken : newToken.substr(newToken.length - delimiter.length, delimiter.length); | ||
}; | ||
var add = function(str) { | ||
var newToken = token + str.toLowerCase(); | ||
token = newToken.length <= delimiter.length ? newToken : newToken.substr(newToken.length - delimiter.length, delimiter.length); | ||
}; | ||
var doesNotMatch = function () { | ||
return token.indexOf(delimiter) === -1; | ||
}; | ||
var doesNotMatch = function() { | ||
return token.indexOf(delimiter) === -1; | ||
}; | ||
return { | ||
add: add, | ||
doesNotMatch: doesNotMatch | ||
}; | ||
return { | ||
add: add, | ||
doesNotMatch: doesNotMatch | ||
}; | ||
} | ||
@@ -763,3 +761,3 @@ | ||
// HACK: newline parsing inconsistent. This brute force normalizes the input. | ||
this.input = this.input.replace(/\r\n|[\r\u2028\u2029]/g, '\n') | ||
this.input = this.input.replace(/\r\n|[\r\u2028\u2029]/g, '\n'); | ||
@@ -907,5 +905,5 @@ this.output = []; | ||
var foundIfOnCurrentLine = false; | ||
for (var lastCheckedOutput=multi_parser.output.length-1; lastCheckedOutput>=0; lastCheckedOutput--) { | ||
if (multi_parser.output[lastCheckedOutput] === '\n') { | ||
break; | ||
for (var lastCheckedOutput = multi_parser.output.length - 1; lastCheckedOutput >= 0; lastCheckedOutput--) { | ||
if (multi_parser.output[lastCheckedOutput] === '\n') { | ||
break; | ||
} else { | ||
@@ -999,3 +997,3 @@ if (multi_parser.output[lastCheckedOutput].match(/{{#if/)) { | ||
if (eol != '\n') { | ||
if (eol !== '\n') { | ||
sweet_code = sweet_code.replace(/[\n]/g, eol); | ||
@@ -1010,9 +1008,9 @@ } | ||
define(["require", "./beautify", "./beautify-css"], function(requireamd) { | ||
var js_beautify = requireamd("./beautify"); | ||
var css_beautify = requireamd("./beautify-css"); | ||
var js_beautify = requireamd("./beautify"); | ||
var css_beautify = requireamd("./beautify-css"); | ||
return { | ||
html_beautify: function(html_source, options) { | ||
return style_html(html_source, options, js_beautify.js_beautify, css_beautify.css_beautify); | ||
} | ||
html_beautify: function(html_source, options) { | ||
return style_html(html_source, options, js_beautify.js_beautify, css_beautify.css_beautify); | ||
} | ||
}; | ||
@@ -1041,2 +1039,2 @@ }); | ||
}()); | ||
}()); |
@@ -36,4 +36,4 @@ #!/usr/bin/env node | ||
var debug = process.env.DEBUG_JSBEAUTIFY || process.env.JSBEAUTIFY_DEBUG ? function() { | ||
console.error.apply(console, arguments); | ||
} : function() {}; | ||
console.error.apply(console, arguments); | ||
} : function() {}; | ||
@@ -70,5 +70,7 @@ var fs = require('fs'), | ||
"comma_first": Boolean, | ||
"operator_position": ["before-newline", "after-newline", "preserve-newline"], | ||
// CSS-only | ||
"selector_separator_newline": Boolean, | ||
"newline_between_rules": Boolean, | ||
"space_around_selector_separator": Boolean, | ||
// HTML-only | ||
@@ -102,3 +104,3 @@ "max_char": Number, // obsolete since 1.3.5 | ||
"P": ["--space_in_paren"], | ||
"E": ["--space_in_empty_paren"], | ||
"Q": ["--space_in_empty_paren"], | ||
"j": ["--jslint_happy"], | ||
@@ -114,2 +116,3 @@ "a": ["--space_after_anon_function"], | ||
"C": ["--comma_first"], | ||
"O": ["--operator_position"], | ||
// CSS-only | ||
@@ -142,3 +145,3 @@ "L": ["--selector_separator_newline"], | ||
"q": ["--quiet"] | ||
// no shorthand for "config" | ||
// no shorthand for "config" | ||
}); | ||
@@ -156,3 +159,3 @@ | ||
if (!result && (nextDir !== dir)) { | ||
result = findRecursive(nextDir, fileName); | ||
result = findRecursive(nextDir, fileName); | ||
} | ||
@@ -164,3 +167,7 @@ | ||
function getUserHome() { | ||
return process.env.USERPROFILE || process.env.HOME; | ||
var user_home = ''; | ||
try { | ||
user_home = process.env.USERPROFILE || process.env.HOME || ''; | ||
} catch (ex) {} | ||
return user_home; | ||
} | ||
@@ -264,2 +271,3 @@ | ||
msg.push(' -C, --comma-first Put commas at the beginning of new line instead of end'); | ||
msg.push(' -O, --operator-position Set operator position (before-newline|after-newline|preserve-newline) [before-newline]'); | ||
break; | ||
@@ -279,4 +287,4 @@ case "html": | ||
case "css": | ||
msg.push(' -L, --selector-separator-newline Add a newline between multiple selectors.') | ||
msg.push(' -N, --newline-between-rules Add a newline between CSS rules.') | ||
msg.push(' -L, --selector-separator-newline Add a newline between multiple selectors.'); | ||
msg.push(' -N, --newline-between-rules Add a newline between CSS rules.'); | ||
} | ||
@@ -320,4 +328,5 @@ | ||
} else { | ||
var dir = path.dirname(outfile); | ||
mkdirp.sync(dir); | ||
if (outfile) { | ||
mkdirp.sync(path.dirname(outfile)); | ||
} | ||
data = fs.readFileSync(filepath, 'utf8'); | ||
@@ -508,2 +517,2 @@ makePretty(data, config, outfile, writePretty); | ||
} | ||
} | ||
} |
@@ -14,7 +14,7 @@ // | ||
var JavascriptObfuscator = { | ||
detect: function (str) { | ||
detect: function(str) { | ||
return /^var _0x[a-f0-9]+ ?\= ?\[/.test(str); | ||
}, | ||
unpack: function (str) { | ||
unpack: function(str) { | ||
if (JavascriptObfuscator.detect(str)) { | ||
@@ -48,3 +48,3 @@ var matches = /var (_0x[a-f\d]+) ?\= ?\[(.*?)\];/.exec(str); | ||
while (pos < str.length) { | ||
if (str.charAt(pos) == '"') { | ||
if (str.charAt(pos) === '"') { | ||
// new word | ||
@@ -54,6 +54,6 @@ var word = ''; | ||
while (pos < str.length) { | ||
if (str.charAt(pos) == '"') { | ||
if (str.charAt(pos) === '"') { | ||
break; | ||
} | ||
if (str.charAt(pos) == '\\') { | ||
if (str.charAt(pos) === '\\') { | ||
word += '\\'; | ||
@@ -73,3 +73,3 @@ pos++; | ||
_unescape: function (str) { | ||
_unescape: function(str) { | ||
// inefficient if used repeatedly or on small strings, but wonderful on single large chunk of text | ||
@@ -83,3 +83,3 @@ for (var i = 32; i < 128; i++) { | ||
run_tests: function (sanity_test) { | ||
run_tests: function(sanity_test) { | ||
var t = sanity_test || new SanityTest(); | ||
@@ -108,2 +108,2 @@ | ||
}; | ||
}; |
@@ -30,3 +30,3 @@ // | ||
var MyObfuscate = { | ||
detect: function (str) { | ||
detect: function(str) { | ||
if (/^var _?[0O1lI]{3}\=('|\[).*\)\)\);/.test(str)) { | ||
@@ -41,7 +41,7 @@ return true; | ||
unpack: function (str) { | ||
unpack: function(str) { | ||
if (MyObfuscate.detect(str)) { | ||
var __eval = eval; | ||
try { | ||
eval = function (unpacked) { | ||
eval = function(unpacked) { // jshint ignore:line | ||
if (MyObfuscate.starts_with(unpacked, 'var _escape')) { | ||
@@ -60,7 +60,7 @@ // fetch the urlencoded stuff from the script, | ||
// throw to terminate the script | ||
unpacked = "// Unpacker warning: be careful when using myobfuscate.com for your projects:\n" + | ||
unpacked = "// Unpacker warning: be careful when using myobfuscate.com for your projects:\n" + | ||
"// scripts obfuscated by the free online version may call back home.\n" + | ||
"\n//\n" + unpacked; | ||
throw unpacked; | ||
}; | ||
}; // jshint ignore:line | ||
__eval(str); // should throw | ||
@@ -73,3 +73,3 @@ } catch (e) { | ||
} | ||
eval = __eval; | ||
eval = __eval; // jshint ignore:line | ||
} | ||
@@ -79,11 +79,11 @@ return str; | ||
starts_with: function (str, what) { | ||
starts_with: function(str, what) { | ||
return str.substr(0, what.length) === what; | ||
}, | ||
ends_with: function (str, what) { | ||
ends_with: function(str, what) { | ||
return str.substr(str.length - what.length, what.length) === what; | ||
}, | ||
run_tests: function (sanity_test) { | ||
run_tests: function(sanity_test) { | ||
var t = sanity_test || new SanityTest(); | ||
@@ -95,2 +95,2 @@ | ||
}; | ||
}; |
@@ -16,3 +16,3 @@ // | ||
var P_A_C_K_E_R = { | ||
detect: function (str) { | ||
detect: function(str) { | ||
return (P_A_C_K_E_R.get_chunks(str).length > 0); | ||
@@ -26,8 +26,8 @@ }, | ||
unpack: function (str) { | ||
unpack: function(str) { | ||
var chunks = P_A_C_K_E_R.get_chunks(str), | ||
chunk; | ||
for(var i = 0; i < chunks.length; i++) { | ||
for (var i = 0; i < chunks.length; i++) { | ||
chunk = chunks[i].replace(/\n$/, ''); | ||
str = str.split(chunk).join( P_A_C_K_E_R.unpack_chunk(chunk) ); | ||
str = str.split(chunk).join(P_A_C_K_E_R.unpack_chunk(chunk)); | ||
} | ||
@@ -37,3 +37,3 @@ return str; | ||
unpack_chunk: function (str) { | ||
unpack_chunk: function(str) { | ||
var unpacked_source = ''; | ||
@@ -43,5 +43,8 @@ var __eval = eval; | ||
try { | ||
eval = function (s) { unpacked_source += s; return unpacked_source; }; | ||
eval = function(s) { // jshint ignore:line | ||
unpacked_source += s; | ||
return unpacked_source; | ||
}; // jshint ignore:line | ||
__eval(str); | ||
if (typeof unpacked_source == 'string' && unpacked_source) { | ||
if (typeof unpacked_source === 'string' && unpacked_source) { | ||
str = unpacked_source; | ||
@@ -53,16 +56,16 @@ } | ||
} | ||
eval = __eval; | ||
eval = __eval; // jshint ignore:line | ||
return str; | ||
}, | ||
run_tests: function (sanity_test) { | ||
var t = sanity_test || new SanityTest(), | ||
run_tests: function(sanity_test) { | ||
var t = sanity_test || new SanityTest(); | ||
pk1 = "eval(function(p,a,c,k,e,r){e=String;if(!''.replace(/^/,String)){while(c--)r[c]=k[c]||c;k=[function(e){return r[e]}];e=function(){return'\\\\w+'};c=1};while(c--)if(k[c])p=p.replace(new RegExp('\\\\b'+e(c)+'\\\\b','g'),k[c]);return p}('0 2=1',3,3,'var||a'.split('|'),0,{}))", | ||
unpk1 = 'var a=1', | ||
pk2 = "eval(function(p,a,c,k,e,r){e=String;if(!''.replace(/^/,String)){while(c--)r[c]=k[c]||c;k=[function(e){return r[e]}];e=function(){return'\\\\w+'};c=1};while(c--)if(k[c])p=p.replace(new RegExp('\\\\b'+e(c)+'\\\\b','g'),k[c]);return p}('0 2=1',3,3,'foo||b'.split('|'),0,{}))", | ||
unpk2 = 'foo b=1', | ||
pk_broken = "eval(function(p,a,c,k,e,r){BORKBORK;if(!''.replace(/^/,String)){while(c--)r[c]=k[c]||c;k=[function(e){return r[e]}];e=function(){return'\\\\w+'};c=1};while(c--)if(k[c])p=p.replace(new RegExp('\\\\b'+e(c)+'\\\\b','g'),k[c]);return p}('0 2=1',3,3,'var||a'.split('|'),0,{}))"; | ||
pk3 = "eval(function(p,a,c,k,e,r){e=String;if(!''.replace(/^/,String)){while(c--)r[c]=k[c]||c;k=[function(e){return r[e]}];e=function(){return'\\\\w+'};c=1};while(c--)if(k[c])p=p.replace(new RegExp('\\\\b'+e(c)+'\\\\b','g'),k[c]);return p}('0 2=1{}))',3,3,'var||a'.split('|'),0,{}))", | ||
unpk3 = 'var a=1{}))', | ||
var pk1 = "eval(function(p,a,c,k,e,r){e=String;if(!''.replace(/^/,String)){while(c--)r[c]=k[c]||c;k=[function(e){return r[e]}];e=function(){return'\\\\w+'};c=1};while(c--)if(k[c])p=p.replace(new RegExp('\\\\b'+e(c)+'\\\\b','g'),k[c]);return p}('0 2=1',3,3,'var||a'.split('|'),0,{}))"; | ||
var unpk1 = 'var a=1'; | ||
var pk2 = "eval(function(p,a,c,k,e,r){e=String;if(!''.replace(/^/,String)){while(c--)r[c]=k[c]||c;k=[function(e){return r[e]}];e=function(){return'\\\\w+'};c=1};while(c--)if(k[c])p=p.replace(new RegExp('\\\\b'+e(c)+'\\\\b','g'),k[c]);return p}('0 2=1',3,3,'foo||b'.split('|'),0,{}))"; | ||
var unpk2 = 'foo b=1'; | ||
var pk_broken = "eval(function(p,a,c,k,e,r){BORKBORK;if(!''.replace(/^/,String)){while(c--)r[c]=k[c]||c;k=[function(e){return r[e]}];e=function(){return'\\\\w+'};c=1};while(c--)if(k[c])p=p.replace(new RegExp('\\\\b'+e(c)+'\\\\b','g'),k[c]);return p}('0 2=1',3,3,'var||a'.split('|'),0,{}))"; | ||
var pk3 = "eval(function(p,a,c,k,e,r){e=String;if(!''.replace(/^/,String)){while(c--)r[c]=k[c]||c;k=[function(e){return r[e]}];e=function(){return'\\\\w+'};c=1};while(c--)if(k[c])p=p.replace(new RegExp('\\\\b'+e(c)+'\\\\b','g'),k[c]);return p}('0 2=1{}))',3,3,'var||a'.split('|'),0,{}))"; | ||
var unpk3 = 'var a=1{}))'; | ||
@@ -85,2 +88,2 @@ t.test_function(P_A_C_K_E_R.detect, "P_A_C_K_E_R.detect"); | ||
}; | ||
}; |
@@ -21,7 +21,7 @@ /*global unescape */ | ||
var Urlencoded = { | ||
detect: function (str) { | ||
detect: function(str) { | ||
// the fact that script doesn't contain any space, but has %20 instead | ||
// should be sufficient check for now. | ||
if (str.indexOf(' ') == -1) { | ||
if (str.indexOf('%2') != -1) return true; | ||
if (str.indexOf(' ') === -1) { | ||
if (str.indexOf('%2') !== -1) return true; | ||
if (str.replace(/[^%]+/g, '').length > 3) return true; | ||
@@ -32,5 +32,5 @@ } | ||
unpack: function (str) { | ||
unpack: function(str) { | ||
if (Urlencoded.detect(str)) { | ||
if (str.indexOf('%2B') != -1 || str.indexOf('%2b') != -1) { | ||
if (str.indexOf('%2B') !== -1 || str.indexOf('%2b') !== -1) { | ||
// "+" escaped as "%2B" | ||
@@ -47,3 +47,3 @@ return unescape(str.replace(/\+/g, '%20')); | ||
run_tests: function (sanity_test) { | ||
run_tests: function(sanity_test) { | ||
var t = sanity_test || new SanityTest(); | ||
@@ -76,2 +76,2 @@ t.test_function(Urlencoded.detect, "Urlencoded.detect"); | ||
module.exports = Urlencoded; | ||
} | ||
} |
@@ -1,2 +0,1 @@ | ||
/*global js_beautify: true */ | ||
/*jshint node:true */ | ||
@@ -12,6 +11,6 @@ | ||
requirejs.config({ | ||
paths: { | ||
'beautify': "..", | ||
'beautify-lib': "../lib" | ||
} | ||
paths: { | ||
'beautify': "..", | ||
'beautify-lib': "../lib" | ||
} | ||
}); | ||
@@ -25,7 +24,7 @@ | ||
test_runner( | ||
results, | ||
Urlencoded, | ||
beautify.js, | ||
beautify.html, | ||
beautify.css); | ||
results, | ||
Urlencoded, | ||
beautify.js, | ||
beautify.html, | ||
beautify.css); | ||
@@ -44,7 +43,7 @@ console.log(results.results_raw()); | ||
test_runner( | ||
results, | ||
Urlencoded, | ||
js_beautify.js_beautify, | ||
html_beautify.html_beautify, | ||
css_beautify.css_beautify); | ||
results, | ||
Urlencoded, | ||
js_beautify.js_beautify, | ||
html_beautify.html_beautify, | ||
css_beautify.css_beautify); | ||
@@ -59,9 +58,9 @@ console.log(results.results_raw()); | ||
process.exit( | ||
amd_beautifier_tests('js-beautifier', run_javascript_tests).get_exitcode() + | ||
amd_beautifier_index_tests('js-beautifier', run_javascript_tests).get_exitcode() + | ||
amd_beautifier_tests('cs-beautifier', run_css_tests).get_exitcode() + | ||
amd_beautifier_index_tests('css-beautifier', run_css_tests).get_exitcode() + | ||
amd_beautifier_tests('html-beautifier', run_html_tests).get_exitcode() + | ||
amd_beautifier_index_tests('html-beautifier', run_html_tests).get_exitcode() | ||
); | ||
} | ||
amd_beautifier_tests('js-beautifier', run_javascript_tests).get_exitcode() + | ||
amd_beautifier_index_tests('js-beautifier', run_javascript_tests).get_exitcode() + | ||
amd_beautifier_tests('cs-beautifier', run_css_tests).get_exitcode() + | ||
amd_beautifier_index_tests('css-beautifier', run_css_tests).get_exitcode() + | ||
amd_beautifier_tests('html-beautifier', run_html_tests).get_exitcode() + | ||
amd_beautifier_index_tests('html-beautifier', run_html_tests).get_exitcode() | ||
); | ||
} |
@@ -7,2 +7,3 @@ /* | ||
*/ | ||
/*jshint unused:false */ | ||
@@ -31,2 +32,3 @@ function run_css_tests(test_obj, Urlencoded, js_beautify, html_beautify, css_beautify) | ||
default_opts.newline_between_rules = false; | ||
default_opts.space_around_selector_separator = false; | ||
@@ -77,3 +79,3 @@ function reset_options() | ||
function unicode_char(value) { | ||
return String.fromCharCode(value) | ||
return String.fromCharCode(value); | ||
} | ||
@@ -124,2 +126,19 @@ | ||
//============================================================ | ||
// Space Around Selector Separator - (space = " ") | ||
opts.space_around_selector_separator = true; | ||
t('a>b{}', 'a > b {}'); | ||
t('a~b{}', 'a ~ b {}'); | ||
t('a+b{}', 'a + b {}'); | ||
t('a+b>c{}', 'a + b > c {}'); | ||
// Space Around Selector Separator - (space = "") | ||
opts.space_around_selector_separator = false; | ||
t('a>b{}', 'a>b {}'); | ||
t('a~b{}', 'a~b {}'); | ||
t('a+b{}', 'a+b {}'); | ||
t('a+b>c{}', 'a+b>c {}'); | ||
reset_options(); | ||
//============================================================ | ||
// Selector Separator - (separator = " ", separator1 = " ") | ||
@@ -230,2 +249,22 @@ opts.selector_separator_newline = false; | ||
//============================================================ | ||
// Handle LESS property name interpolation | ||
t('tag {\n\t@{prop}: none;\n}'); | ||
t('tag{@{prop}:none;}', 'tag {\n\t@{prop}: none;\n}'); | ||
t('tag{ @{prop}: none;}', 'tag {\n\t@{prop}: none;\n}'); | ||
// can also be part of property name | ||
t('tag {\n\tdynamic-@{prop}: none;\n}'); | ||
t('tag{dynamic-@{prop}:none;}', 'tag {\n\tdynamic-@{prop}: none;\n}'); | ||
t('tag{ dynamic-@{prop}: none;}', 'tag {\n\tdynamic-@{prop}: none;\n}'); | ||
reset_options(); | ||
//============================================================ | ||
// Handle LESS property name interpolation, test #631 | ||
t('.generate-columns(@n, @i: 1) when (@i =< @n) {\n\t.column-@{i} {\n\t\twidth: (@i * 100% / @n);\n\t}\n\t.generate-columns(@n, (@i + 1));\n}'); | ||
t('.generate-columns(@n,@i:1) when (@i =< @n){.column-@{i}{width:(@i * 100% / @n);}.generate-columns(@n,(@i + 1));}', '.generate-columns(@n, @i: 1) when (@i =< @n) {\n\t.column-@{i} {\n\t\twidth: (@i * 100% / @n);\n\t}\n\t.generate-columns(@n, (@i + 1));\n}'); | ||
reset_options(); | ||
//============================================================ | ||
// Psuedo-classes vs Variables | ||
@@ -232,0 +271,0 @@ t('@page :first {}'); |
@@ -7,2 +7,3 @@ /* | ||
*/ | ||
/*jshint unused:false */ | ||
@@ -85,3 +86,3 @@ function run_html_tests(test_obj, Urlencoded, js_beautify, html_beautify, css_beautify) | ||
function unicode_char(value) { | ||
return String.fromCharCode(value) | ||
return String.fromCharCode(value); | ||
} | ||
@@ -88,0 +89,0 @@ |
/*global js_beautify: true */ | ||
/*jshint node:true */ | ||
/*jshint unused:false */ | ||
var fs = require('fs'), | ||
@@ -24,20 +26,19 @@ SanityTest = require('./sanitytest'), | ||
var suite = new Benchmark.Suite; | ||
var suite = new Benchmark.Suite(); | ||
suite.add("html-beautify (index.html)", function () { | ||
html_beautify(index_html, options); | ||
}) | ||
.add("html-beautify (base64 image)", function () { | ||
html_beautify(data_attr, options); | ||
}) | ||
// add listeners | ||
.on('cycle', function(event) { | ||
console.log(String(event.target)); | ||
}) | ||
.on('error', function(event) { | ||
return 1; | ||
}) | ||
.on('complete', function(event) { | ||
}) | ||
.run() | ||
suite.add("html-beautify (index.html)", function() { | ||
html_beautify(index_html, options); | ||
}) | ||
.add("html-beautify (base64 image)", function() { | ||
html_beautify(data_attr, options); | ||
}) | ||
// add listeners | ||
.on('cycle', function(event) { | ||
console.log(String(event.target)); | ||
}) | ||
.on('error', function(event) { | ||
return 1; | ||
}) | ||
.on('complete', function(event) {}) | ||
.run(); | ||
return 0; | ||
@@ -51,2 +52,2 @@ } | ||
process.exit(node_beautifier_html_tests()); | ||
} | ||
} |
/*global js_beautify: true */ | ||
/*jshint node:true */ | ||
/*jshint unused:false */ | ||
@@ -24,20 +25,19 @@ var fs = require('fs'), | ||
var suite = new Benchmark.Suite; | ||
var suite = new Benchmark.Suite(); | ||
suite.add("js-beautify (underscore)", function() { | ||
js_beautify(data, options); | ||
}) | ||
.add("js-beautify (underscore-min)", function() { | ||
js_beautify(data_min, options); | ||
}) | ||
// add listeners | ||
.on('cycle', function(event) { | ||
console.log(String(event.target)); | ||
}) | ||
.on('error', function(event) { | ||
return 1; | ||
}) | ||
.on('complete', function(event) { | ||
}) | ||
.run() | ||
js_beautify(data, options); | ||
}) | ||
.add("js-beautify (underscore-min)", function() { | ||
js_beautify(data_min, options); | ||
}) | ||
// add listeners | ||
.on('cycle', function(event) { | ||
console.log(String(event.target)); | ||
}) | ||
.on('error', function(event) { | ||
return 1; | ||
}) | ||
.on('complete', function(event) {}) | ||
.run(); | ||
return 0; | ||
@@ -51,2 +51,2 @@ } | ||
process.exit(node_beautifier_tests()); | ||
} | ||
} |
@@ -1,2 +0,1 @@ | ||
/*global js_beautify: true */ | ||
/*jshint node:true */ | ||
@@ -29,7 +28,7 @@ | ||
test_runner( | ||
results, | ||
Urlencoded, | ||
beautify.js, | ||
beautify.html, | ||
beautify.css); | ||
results, | ||
Urlencoded, | ||
beautify.js, | ||
beautify.html, | ||
beautify.css); | ||
@@ -42,7 +41,7 @@ console.log(results.results_raw()); | ||
process.exit( | ||
test_legacy_names() + | ||
node_beautifier_tests('js-beautifier', run_javascript_tests).get_exitcode() + | ||
node_beautifier_tests('cs-beautifier', run_css_tests).get_exitcode() + | ||
node_beautifier_tests('html-beautifier', run_html_tests).get_exitcode() | ||
); | ||
} | ||
test_legacy_names() + | ||
node_beautifier_tests('js-beautifier', run_javascript_tests).get_exitcode() + | ||
node_beautifier_tests('css-beautifier', run_css_tests).get_exitcode() + | ||
node_beautifier_tests('html-beautifier', run_html_tests).get_exitcode() | ||
); | ||
} |
@@ -14,5 +14,5 @@ // | ||
function SanityTest (func, name_of_test) { | ||
function SanityTest(func, name_of_test) { | ||
var test_func = func || function (x) { | ||
var test_func = func || function(x) { | ||
return x; | ||
@@ -59,3 +59,3 @@ }; | ||
} else { | ||
for (var i = 0 ; i < failures.length; i++) { | ||
for (var i = 0; i < failures.length; i++) { | ||
var f = failures[i]; | ||
@@ -83,33 +83,31 @@ if (f[0]) { | ||
var type = typeof something; | ||
switch(type.toLowerCase()) { | ||
case 'string': | ||
if (quote_strings) { | ||
return "'" + something.replace("'", "\\'") + "'"; | ||
} else { | ||
switch (type.toLowerCase()) { | ||
case 'string': | ||
if (quote_strings) { | ||
return "'" + something.replace("'", "\\'") + "'"; | ||
} | ||
return something; | ||
} | ||
case 'number': | ||
return '' + something; | ||
case 'boolean': | ||
return something ? 'true' : 'false'; | ||
case 'undefined': | ||
return 'undefined'; | ||
case 'object': | ||
if (something instanceof Array) { | ||
var x = []; | ||
var expected_index = 0; | ||
for (var k in something) { | ||
if (k === expected_index) { | ||
x.push(this.prettyprint(something[k], true)); | ||
expected_index += 1; | ||
} else { | ||
x.push('\n' + k + ': ' + this.prettyprint(something[k], true)); | ||
case 'number': | ||
return '' + something; | ||
case 'boolean': | ||
return something ? 'true' : 'false'; | ||
case 'undefined': | ||
return 'undefined'; | ||
case 'object': | ||
if (something instanceof Array) { | ||
var x = []; | ||
var expected_index = 0; | ||
for (var k in something) { | ||
if (k === expected_index) { | ||
x.push(this.prettyprint(something[k], true)); | ||
expected_index += 1; | ||
} else { | ||
x.push('\n' + k + ': ' + this.prettyprint(something[k], true)); | ||
} | ||
} | ||
return '[' + x.join(', ') + ']'; | ||
} | ||
return '[' + x.join(', ') + ']'; | ||
} else { | ||
return 'object: ' + something; | ||
} | ||
default: | ||
return type + ': ' + something; | ||
default: | ||
return type + ': ' + something; | ||
} | ||
@@ -119,3 +117,3 @@ }; | ||
this.lazy_escape = function (str) { | ||
this.lazy_escape = function(str) { | ||
return str.replace(/</g, '<').replace(/\>/g, '>').replace(/\n/g, '<br />'); | ||
@@ -125,3 +123,3 @@ }; | ||
this.log = function () { | ||
this.log = function() { | ||
if (window.console) { | ||
@@ -140,2 +138,2 @@ if (console.firebug) { | ||
module.exports = SanityTest; | ||
} | ||
} |
{ | ||
"name": "js-beautify", | ||
"version": "1.6.2", | ||
"version": "1.6.3", | ||
"description": "jsbeautifier.org for node", | ||
@@ -5,0 +5,0 @@ "main": "js/index.js", |
@@ -7,3 +7,4 @@ exports.test_data = { | ||
{ name: "end_with_newline", value: "false" }, | ||
{ name: "newline_between_rules", value: "false"}, | ||
{ name: "newline_between_rules", value: "false" }, | ||
{ name: "space_around_selector_separator", value: "false" } | ||
], | ||
@@ -13,15 +14,13 @@ groups: [{ | ||
description: "", | ||
matrix: [ | ||
{ | ||
options: [ | ||
{ name: "end_with_newline", value: "true" } | ||
], | ||
eof: '\\n' | ||
}, { | ||
options: [ | ||
{ name: "end_with_newline", value: "false" } | ||
], | ||
eof: '' | ||
} | ||
], | ||
matrix: [{ | ||
options: [ | ||
{ name: "end_with_newline", value: "true" } | ||
], | ||
eof: '\\n' | ||
}, { | ||
options: [ | ||
{ name: "end_with_newline", value: "false" } | ||
], | ||
eof: '' | ||
}], | ||
tests: [ | ||
@@ -46,50 +45,63 @@ { fragment: true, input: '', output: '{{eof}}' }, | ||
description: "", | ||
tests: [{ | ||
input: '#cboxOverlay {\n\tbackground: url(images/overlay.png) repeat 0 0;\n\topacity: 0.9;\n\tfilter: alpha(opacity = 90);\n}', | ||
output: '#cboxOverlay {\n\tbackground: url(images/overlay.png) repeat 0 0;\n\topacity: 0.9;\n\tfilter: alpha(opacity=90);\n}' | ||
}, ], | ||
}, { | ||
name: "Space Around Selector Separator", | ||
description: "", | ||
matrix: [{ | ||
options: [{ name: "space_around_selector_separator", value: "true" }], | ||
space: ' ' | ||
}, { | ||
options: [{ name: "space_around_selector_separator", value: "false" }], | ||
space: '' | ||
}], | ||
tests: [ | ||
{ | ||
input: '#cboxOverlay {\n\tbackground: url(images/overlay.png) repeat 0 0;\n\topacity: 0.9;\n\tfilter: alpha(opacity = 90);\n}', | ||
output: '#cboxOverlay {\n\tbackground: url(images/overlay.png) repeat 0 0;\n\topacity: 0.9;\n\tfilter: alpha(opacity=90);\n}' | ||
}, | ||
], | ||
{ input: 'a>b{}', output: 'a{{space}}>{{space}}b {}' }, | ||
{ input: 'a~b{}', output: 'a{{space}}~{{space}}b {}' }, | ||
{ input: 'a+b{}', output: 'a{{space}}+{{space}}b {}' }, | ||
{ input: 'a+b>c{}', output: 'a{{space}}+{{space}}b{{space}}>{{space}}c {}' } | ||
] | ||
}, { | ||
name: 'Selector Separator', | ||
description: '', | ||
matrix: [ | ||
{ | ||
options: [ | ||
{ name: 'selector_separator_newline', value: 'false' }, | ||
{ name: 'selector_separator', value: '" "' } | ||
], | ||
separator: ' ', | ||
separator1: ' ' | ||
}, { | ||
options: [ | ||
{ name: 'selector_separator_newline', value: 'false' }, | ||
{ name: 'selector_separator', value: '" "' } | ||
], | ||
// BUG: #713 | ||
separator: ' ', | ||
separator1: ' ' | ||
}, { | ||
options: [ | ||
{ name: 'selector_separator_newline', value: 'true' }, | ||
{ name: 'selector_separator', value: '" "' } | ||
], | ||
separator: '\\n', | ||
separator1: '\\n\\t' | ||
}, { | ||
options: [ | ||
{ name: 'selector_separator_newline', value: 'true' }, | ||
{ name: 'selector_separator', value: '" "' } | ||
], | ||
separator: '\\n', | ||
separator1: '\\n\\t' | ||
matrix: [{ | ||
options: [ | ||
{ name: 'selector_separator_newline', value: 'false' }, | ||
{ name: 'selector_separator', value: '" "' } | ||
], | ||
separator: ' ', | ||
separator1: ' ' | ||
}, { | ||
options: [ | ||
{ name: 'selector_separator_newline', value: 'false' }, | ||
{ name: 'selector_separator', value: '" "' } | ||
], | ||
// BUG: #713 | ||
separator: ' ', | ||
separator1: ' ' | ||
}, { | ||
options: [ | ||
{ name: 'selector_separator_newline', value: 'true' }, | ||
{ name: 'selector_separator', value: '" "' } | ||
], | ||
separator: '\\n', | ||
separator1: '\\n\\t' | ||
}, { | ||
options: [ | ||
{ name: 'selector_separator_newline', value: 'true' }, | ||
{ name: 'selector_separator', value: '" "' } | ||
], | ||
separator: '\\n', | ||
separator1: '\\n\\t' | ||
}], | ||
tests: [ | ||
{ input: '#bla, #foo{color:green}', output: '#bla,{{separator}}#foo {\n\tcolor: green\n}' }, | ||
{ input: '@media print {.tab{}}', output: '@media print {\n\t.tab {}\n}' }, | ||
{ input: '@media print {.tab,.bat{}}', output: '@media print {\n\t.tab,{{separator1}}.bat {}\n}' }, | ||
{ input: '#bla, #foo{color:black}', output: '#bla,{{separator}}#foo {\n\tcolor: black\n}' }, { | ||
input: 'a:first-child,a:first-child{color:red;div:first-child,div:hover{color:black;}}', | ||
output: 'a:first-child,{{separator}}a:first-child {\n\tcolor: red;\n\tdiv:first-child,{{separator1}}div:hover {\n\t\tcolor: black;\n\t}\n}' | ||
} | ||
], | ||
tests: [ | ||
{ input: '#bla, #foo{color:green}', output: '#bla,{{separator}}#foo {\n\tcolor: green\n}'}, | ||
{ input: '@media print {.tab{}}', output: '@media print {\n\t.tab {}\n}'}, | ||
{ input: '@media print {.tab,.bat{}}', output: '@media print {\n\t.tab,{{separator1}}.bat {}\n}'}, | ||
{ input: '#bla, #foo{color:black}', output: '#bla,{{separator}}#foo {\n\tcolor: black\n}'}, | ||
{ input: 'a:first-child,a:first-child{color:red;div:first-child,div:hover{color:black;}}', | ||
output: 'a:first-child,{{separator}}a:first-child {\n\tcolor: red;\n\tdiv:first-child,{{separator1}}div:hover {\n\t\tcolor: black;\n\t}\n}'} | ||
] | ||
@@ -99,27 +111,25 @@ }, { | ||
description: "", | ||
matrix: [ | ||
{ | ||
options: [ | ||
{ name: "newline_between_rules", value: "true" } | ||
], | ||
separator: '\\n' | ||
}, { | ||
options: [ | ||
{ name: "newline_between_rules", value: "false" } | ||
], | ||
separator: '' | ||
} | ||
], | ||
matrix: [{ | ||
options: [ | ||
{ name: "newline_between_rules", value: "true" } | ||
], | ||
separator: '\\n' | ||
}, { | ||
options: [ | ||
{ name: "newline_between_rules", value: "false" } | ||
], | ||
separator: '' | ||
}], | ||
tests: [ | ||
{ input: '.div {}\n.span {}', output: '.div {}\n{{separator}}.span {}'}, | ||
{ input: '.div{}\n \n.span{}', output: '.div {}\n{{separator}}.span {}'}, | ||
{ input: '.div {} \n \n.span { } \n', output: '.div {}\n{{separator}}.span {}'}, | ||
{ input: '.div {\n \n} \n .span {\n } ', output: '.div {}\n{{separator}}.span {}'}, | ||
{ input: '.selector1 {\n\tmargin: 0; /* This is a comment including an url http://domain.com/path/to/file.ext */\n}\n.div{height:15px;}', output: '.selector1 {\n\tmargin: 0;\n\t/* This is a comment including an url http://domain.com/path/to/file.ext */\n}\n{{separator}}.div {\n\theight: 15px;\n}'}, | ||
{ input: '.tabs{width:10px;//end of line comment\nheight:10px;//another\n}\n.div{height:15px;}', output: '.tabs {\n\twidth: 10px; //end of line comment\n\theight: 10px; //another\n}\n{{separator}}.div {\n\theight: 15px;\n}'}, | ||
{ input: '#foo {\n\tbackground-image: url(foo@2x.png);\n\t@font-face {\n\t\tfont-family: "Bitstream Vera Serif Bold";\n\t\tsrc: url("http://developer.mozilla.org/@api/deki/files/2934/=VeraSeBd.ttf");\n\t}\n}\n.div{height:15px;}', output: '#foo {\n\tbackground-image: url(foo@2x.png);\n\t@font-face {\n\t\tfont-family: "Bitstream Vera Serif Bold";\n\t\tsrc: url("http://developer.mozilla.org/@api/deki/files/2934/=VeraSeBd.ttf");\n\t}\n}\n{{separator}}.div {\n\theight: 15px;\n}'}, | ||
{ input: '@media screen {\n\t#foo:hover {\n\t\tbackground-image: url(foo@2x.png);\n\t}\n\t@font-face {\n\t\tfont-family: "Bitstream Vera Serif Bold";\n\t\tsrc: url("http://developer.mozilla.org/@api/deki/files/2934/=VeraSeBd.ttf");\n\t}\n}\n.div{height:15px;}', output: '@media screen {\n\t#foo:hover {\n\t\tbackground-image: url(foo@2x.png);\n\t}\n\t@font-face {\n\t\tfont-family: "Bitstream Vera Serif Bold";\n\t\tsrc: url("http://developer.mozilla.org/@api/deki/files/2934/=VeraSeBd.ttf");\n\t}\n}\n{{separator}}.div {\n\theight: 15px;\n}'}, | ||
{ input: '@font-face {\n\tfont-family: "Bitstream Vera Serif Bold";\n\tsrc: url("http://developer.mozilla.org/@api/deki/files/2934/=VeraSeBd.ttf");\n}\n@media screen {\n\t#foo:hover {\n\t\tbackground-image: url(foo.png);\n\t}\n\t@media screen and (min-device-pixel-ratio: 2) {\n\t\t@font-face {\n\t\t\tfont-family: "Helvetica Neue"\n\t\t}\n\t\t#foo:hover {\n\t\t\tbackground-image: url(foo@2x.png);\n\t\t}\n\t}\n}', output: '@font-face {\n\tfont-family: "Bitstream Vera Serif Bold";\n\tsrc: url("http://developer.mozilla.org/@api/deki/files/2934/=VeraSeBd.ttf");\n}\n{{separator}}@media screen {\n\t#foo:hover {\n\t\tbackground-image: url(foo.png);\n\t}\n\t@media screen and (min-device-pixel-ratio: 2) {\n\t\t@font-face {\n\t\t\tfont-family: "Helvetica Neue"\n\t\t}\n\t\t#foo:hover {\n\t\t\tbackground-image: url(foo@2x.png);\n\t\t}\n\t}\n}'}, | ||
{ input: 'a:first-child{color:red;div:first-child{color:black;}}\n.div{height:15px;}', output: 'a:first-child {\n\tcolor: red;\n\tdiv:first-child {\n\t\tcolor: black;\n\t}\n}\n{{separator}}.div {\n\theight: 15px;\n}'}, | ||
{ input: 'a:first-child{color:red;div:not(.peq){color:black;}}\n.div{height:15px;}', output: 'a:first-child {\n\tcolor: red;\n\tdiv:not(.peq) {\n\t\tcolor: black;\n\t}\n}\n{{separator}}.div {\n\theight: 15px;\n}'}, | ||
{ input: '.div {}\n.span {}', output: '.div {}\n{{separator}}.span {}' }, | ||
{ input: '.div{}\n \n.span{}', output: '.div {}\n{{separator}}.span {}' }, | ||
{ input: '.div {} \n \n.span { } \n', output: '.div {}\n{{separator}}.span {}' }, | ||
{ input: '.div {\n \n} \n .span {\n } ', output: '.div {}\n{{separator}}.span {}' }, | ||
{ input: '.selector1 {\n\tmargin: 0; /* This is a comment including an url http://domain.com/path/to/file.ext */\n}\n.div{height:15px;}', output: '.selector1 {\n\tmargin: 0;\n\t/* This is a comment including an url http://domain.com/path/to/file.ext */\n}\n{{separator}}.div {\n\theight: 15px;\n}' }, | ||
{ input: '.tabs{width:10px;//end of line comment\nheight:10px;//another\n}\n.div{height:15px;}', output: '.tabs {\n\twidth: 10px; //end of line comment\n\theight: 10px; //another\n}\n{{separator}}.div {\n\theight: 15px;\n}' }, | ||
{ input: '#foo {\n\tbackground-image: url(foo@2x.png);\n\t@font-face {\n\t\tfont-family: "Bitstream Vera Serif Bold";\n\t\tsrc: url("http://developer.mozilla.org/@api/deki/files/2934/=VeraSeBd.ttf");\n\t}\n}\n.div{height:15px;}', output: '#foo {\n\tbackground-image: url(foo@2x.png);\n\t@font-face {\n\t\tfont-family: "Bitstream Vera Serif Bold";\n\t\tsrc: url("http://developer.mozilla.org/@api/deki/files/2934/=VeraSeBd.ttf");\n\t}\n}\n{{separator}}.div {\n\theight: 15px;\n}' }, | ||
{ input: '@media screen {\n\t#foo:hover {\n\t\tbackground-image: url(foo@2x.png);\n\t}\n\t@font-face {\n\t\tfont-family: "Bitstream Vera Serif Bold";\n\t\tsrc: url("http://developer.mozilla.org/@api/deki/files/2934/=VeraSeBd.ttf");\n\t}\n}\n.div{height:15px;}', output: '@media screen {\n\t#foo:hover {\n\t\tbackground-image: url(foo@2x.png);\n\t}\n\t@font-face {\n\t\tfont-family: "Bitstream Vera Serif Bold";\n\t\tsrc: url("http://developer.mozilla.org/@api/deki/files/2934/=VeraSeBd.ttf");\n\t}\n}\n{{separator}}.div {\n\theight: 15px;\n}' }, | ||
{ input: '@font-face {\n\tfont-family: "Bitstream Vera Serif Bold";\n\tsrc: url("http://developer.mozilla.org/@api/deki/files/2934/=VeraSeBd.ttf");\n}\n@media screen {\n\t#foo:hover {\n\t\tbackground-image: url(foo.png);\n\t}\n\t@media screen and (min-device-pixel-ratio: 2) {\n\t\t@font-face {\n\t\t\tfont-family: "Helvetica Neue"\n\t\t}\n\t\t#foo:hover {\n\t\t\tbackground-image: url(foo@2x.png);\n\t\t}\n\t}\n}', output: '@font-face {\n\tfont-family: "Bitstream Vera Serif Bold";\n\tsrc: url("http://developer.mozilla.org/@api/deki/files/2934/=VeraSeBd.ttf");\n}\n{{separator}}@media screen {\n\t#foo:hover {\n\t\tbackground-image: url(foo.png);\n\t}\n\t@media screen and (min-device-pixel-ratio: 2) {\n\t\t@font-face {\n\t\t\tfont-family: "Helvetica Neue"\n\t\t}\n\t\t#foo:hover {\n\t\t\tbackground-image: url(foo@2x.png);\n\t\t}\n\t}\n}' }, | ||
{ input: 'a:first-child{color:red;div:first-child{color:black;}}\n.div{height:15px;}', output: 'a:first-child {\n\tcolor: red;\n\tdiv:first-child {\n\t\tcolor: black;\n\t}\n}\n{{separator}}.div {\n\theight: 15px;\n}' }, | ||
{ input: 'a:first-child{color:red;div:not(.peq){color:black;}}\n.div{height:15px;}', output: 'a:first-child {\n\tcolor: red;\n\tdiv:not(.peq) {\n\t\tcolor: black;\n\t}\n}\n{{separator}}.div {\n\theight: 15px;\n}' }, | ||
], | ||
@@ -149,8 +159,12 @@ }, { | ||
{ unchanged: '/* header' }, | ||
{ unchanged: '// comment' }, | ||
{ input: '.selector1 {\n\tmargin: 0; /* This is a comment including an url http://domain.com/path/to/file.ext */\n}', | ||
output: '.selector1 {\n\tmargin: 0;\n\t/* This is a comment including an url http://domain.com/path/to/file.ext */\n}'}, | ||
{ unchanged: '// comment' }, { | ||
input: '.selector1 {\n\tmargin: 0; /* This is a comment including an url http://domain.com/path/to/file.ext */\n}', | ||
output: '.selector1 {\n\tmargin: 0;\n\t/* This is a comment including an url http://domain.com/path/to/file.ext */\n}' | ||
}, | ||
{ comment: "single line comment support (less/sass)", | ||
input:'.tabs{\n// comment\nwidth:10px;\n}', output: '.tabs {\n\t// comment\n\twidth: 10px;\n}' }, | ||
{ | ||
comment: "single line comment support (less/sass)", | ||
input: '.tabs{\n// comment\nwidth:10px;\n}', | ||
output: '.tabs {\n\t// comment\n\twidth: 10px;\n}' | ||
}, | ||
{ input: '.tabs{// comment\nwidth:10px;\n}', output: '.tabs {\n\t// comment\n\twidth: 10px;\n}' }, | ||
@@ -164,9 +178,34 @@ { input: '//comment\n.tabs{width:10px;}', output: '//comment\n.tabs {\n\twidth: 10px;\n}' }, | ||
}, { | ||
name: "Handle LESS property name interpolation", | ||
description: "", | ||
tests: [ | ||
{ unchanged: 'tag {\n\t@{prop}: none;\n}' }, | ||
{ input: 'tag{@{prop}:none;}', output: 'tag {\n\t@{prop}: none;\n}' }, | ||
{ input: 'tag{ @{prop}: none;}', output: 'tag {\n\t@{prop}: none;\n}' }, | ||
{ | ||
comment: "can also be part of property name", | ||
unchanged: 'tag {\n\tdynamic-@{prop}: none;\n}' | ||
}, | ||
{ input: 'tag{dynamic-@{prop}:none;}', output: 'tag {\n\tdynamic-@{prop}: none;\n}' }, | ||
{ input: 'tag{ dynamic-@{prop}: none;}', output: 'tag {\n\tdynamic-@{prop}: none;\n}' }, | ||
], | ||
}, { | ||
name: "Handle LESS property name interpolation, test #631", | ||
description: "", | ||
tests: [ | ||
{ unchanged: '.generate-columns(@n, @i: 1) when (@i =< @n) {\n\t.column-@{i} {\n\t\twidth: (@i * 100% / @n);\n\t}\n\t.generate-columns(@n, (@i + 1));\n}' }, | ||
{ | ||
input: '.generate-columns(@n,@i:1) when (@i =< @n){.column-@{i}{width:(@i * 100% / @n);}.generate-columns(@n,(@i + 1));}', | ||
output: '.generate-columns(@n, @i: 1) when (@i =< @n) {\n\t.column-@{i} {\n\t\twidth: (@i * 100% / @n);\n\t}\n\t.generate-columns(@n, (@i + 1));\n}' | ||
} | ||
], | ||
}, { | ||
name: "Psuedo-classes vs Variables", | ||
description: "", | ||
tests: [ | ||
{ unchanged: '@page :first {}' }, | ||
{ comment: "Assume the colon goes with the @name. If we're in LESS, this is required regardless of the at-string.", | ||
input: '@page:first {}', | ||
output: '@page: first {}' }, | ||
{ unchanged: '@page :first {}' }, { | ||
comment: "Assume the colon goes with the @name. If we're in LESS, this is required regardless of the at-string.", | ||
input: '@page:first {}', | ||
output: '@page: first {}' | ||
}, | ||
{ unchanged: '@page: first {}' } | ||
@@ -177,12 +216,14 @@ ], | ||
description: "", | ||
tests: [ | ||
{ comment: "Basic Interpolation", | ||
unchanged: 'p {\n\t$font-size: 12px;\n\t$line-height: 30px;\n\tfont: #{$font-size}/#{$line-height};\n}'}, | ||
{ unchanged: 'p.#{$name} {}' }, | ||
{ unchanged: [ | ||
'@mixin itemPropertiesCoverItem($items, $margin) {', | ||
'\twidth: calc((100% - ((#{$items} - 1) * #{$margin}rem)) / #{$items});', | ||
'\tmargin: 1.6rem #{$margin}rem 1.6rem 0;', | ||
'}' | ||
]} | ||
tests: [{ | ||
comment: "Basic Interpolation", | ||
unchanged: 'p {\n\t$font-size: 12px;\n\t$line-height: 30px;\n\tfont: #{$font-size}/#{$line-height};\n}' | ||
}, | ||
{ unchanged: 'p.#{$name} {}' }, { | ||
unchanged: [ | ||
'@mixin itemPropertiesCoverItem($items, $margin) {', | ||
'\twidth: calc((100% - ((#{$items} - 1) * #{$margin}rem)) / #{$items});', | ||
'\tmargin: 1.6rem #{$margin}rem 1.6rem 0;', | ||
'}' | ||
] | ||
} | ||
], | ||
@@ -192,2 +233,2 @@ }, { | ||
}] | ||
} | ||
}; |
@@ -15,4 +15,3 @@ exports.test_data = { | ||
description: "", | ||
matrix: [ | ||
{ | ||
matrix: [{ | ||
options: [ | ||
@@ -39,4 +38,3 @@ { name: "end_with_newline", value: "true" } | ||
description: "", | ||
matrix: [ | ||
{ | ||
matrix: [{ | ||
options: [ | ||
@@ -48,14 +46,11 @@ { name: "extra_liners", value: "[]" } | ||
], | ||
tests: [ | ||
{ | ||
fragment: true, | ||
input: '<html><head><meta></head><body><div><p>x</p></div></body></html>', | ||
output: '<html>\n<head>\n <meta>\n</head>\n<body>\n <div>\n <p>x</p>\n </div>\n</body>\n</html>' | ||
} | ||
], | ||
tests: [{ | ||
fragment: true, | ||
input: '<html><head><meta></head><body><div><p>x</p></div></body></html>', | ||
output: '<html>\n<head>\n <meta>\n</head>\n<body>\n <div>\n <p>x</p>\n </div>\n</body>\n</html>' | ||
}], | ||
}, { | ||
name: "Custom Extra Liners (default)", | ||
description: "", | ||
matrix: [ | ||
{ | ||
matrix: [{ | ||
options: [ | ||
@@ -67,14 +62,11 @@ { name: "extra_liners", value: "null" } | ||
], | ||
tests: [ | ||
{ | ||
fragment: true, | ||
input: '<html><head></head><body></body></html>', | ||
output: '<html>\n\n<head></head>\n\n<body></body>\n\n</html>' | ||
} | ||
], | ||
tests: [{ | ||
fragment: true, | ||
input: '<html><head></head><body></body></html>', | ||
output: '<html>\n\n<head></head>\n\n<body></body>\n\n</html>' | ||
}], | ||
}, { | ||
name: "Custom Extra Liners (p, string)", | ||
description: "", | ||
matrix: [ | ||
{ | ||
matrix: [{ | ||
options: [ | ||
@@ -86,14 +78,11 @@ { name: "extra_liners", value: "'p,/p'" } | ||
], | ||
tests: [ | ||
{ | ||
fragment: true, | ||
input: '<html><head><meta></head><body><div><p>x</p></div></body></html>', | ||
output: '<html>\n<head>\n <meta>\n</head>\n<body>\n <div>\n\n <p>x\n\n </p>\n </div>\n</body>\n</html>' | ||
} | ||
], | ||
tests: [{ | ||
fragment: true, | ||
input: '<html><head><meta></head><body><div><p>x</p></div></body></html>', | ||
output: '<html>\n<head>\n <meta>\n</head>\n<body>\n <div>\n\n <p>x\n\n </p>\n </div>\n</body>\n</html>' | ||
}], | ||
}, { | ||
name: "Custom Extra Liners (p)", | ||
description: "", | ||
matrix: [ | ||
{ | ||
matrix: [{ | ||
options: [ | ||
@@ -105,14 +94,11 @@ { name: "extra_liners", value: "['p', '/p']" } | ||
], | ||
tests: [ | ||
{ | ||
fragment: true, | ||
input: '<html><head><meta></head><body><div><p>x</p></div></body></html>', | ||
output: '<html>\n<head>\n <meta>\n</head>\n<body>\n <div>\n\n <p>x\n\n </p>\n </div>\n</body>\n</html>' | ||
} | ||
], | ||
tests: [{ | ||
fragment: true, | ||
input: '<html><head><meta></head><body><div><p>x</p></div></body></html>', | ||
output: '<html>\n<head>\n <meta>\n</head>\n<body>\n <div>\n\n <p>x\n\n </p>\n </div>\n</body>\n</html>' | ||
}], | ||
}, { | ||
name: "Tests for script and style types (issue 453, 821", | ||
description: "Only format recognized script types", | ||
tests: [ | ||
{ | ||
tests: [{ | ||
input: '<script type="text/unknown"><div></div></script>', | ||
@@ -124,4 +110,3 @@ output: [ | ||
] | ||
}, | ||
{ | ||
}, { | ||
input: '<script type="text/javascript"><div></div></script>', | ||
@@ -133,4 +118,3 @@ output: [ | ||
] | ||
}, | ||
{ | ||
}, { | ||
input: '<script><div></div></script>', | ||
@@ -142,4 +126,3 @@ output: [ | ||
] | ||
}, | ||
{ | ||
}, { | ||
input: '<script>var foo = "bar";</script>', | ||
@@ -151,4 +134,3 @@ output: [ | ||
] | ||
}, | ||
{ | ||
}, { | ||
input: '<script type="text/javascript">var foo = "bar";</script>', | ||
@@ -160,4 +142,3 @@ output: [ | ||
] | ||
}, | ||
{ | ||
}, { | ||
input: '<script type="application/javascript">var foo = "bar";</script>', | ||
@@ -169,4 +150,3 @@ output: [ | ||
] | ||
}, | ||
{ | ||
}, { | ||
input: '<script type="application/javascript;version=1.8">var foo = "bar";</script>', | ||
@@ -178,4 +158,3 @@ output: [ | ||
] | ||
}, | ||
{ | ||
}, { | ||
input: '<script type="application/x-javascript">var foo = "bar";</script>', | ||
@@ -187,4 +166,3 @@ output: [ | ||
] | ||
}, | ||
{ | ||
}, { | ||
input: '<script type="application/ecmascript">var foo = "bar";</script>', | ||
@@ -196,4 +174,3 @@ output: [ | ||
] | ||
}, | ||
{ | ||
}, { | ||
input: '<script type="text/javascript1.5">var foo = "bar";</script>', | ||
@@ -205,4 +182,3 @@ output: [ | ||
] | ||
}, | ||
{ | ||
}, { | ||
input: '<script type="application/json">{"foo":"bar"}</script>', | ||
@@ -216,4 +192,3 @@ output: [ | ||
] | ||
}, | ||
{ | ||
}, { | ||
input: '<script type="application/ld+json">{"foo":"bar"}</script>', | ||
@@ -227,4 +202,3 @@ output: [ | ||
] | ||
}, | ||
{ | ||
}, { | ||
input: '<style type="text/unknown"><tag></tag></style>', | ||
@@ -236,4 +210,3 @@ output: [ | ||
] | ||
}, | ||
{ | ||
}, { | ||
input: '<style type="text/css"><tag></tag></style>', | ||
@@ -245,4 +218,3 @@ output: [ | ||
] | ||
}, | ||
{ | ||
}, { | ||
input: '<style><tag></tag></style>', | ||
@@ -254,4 +226,3 @@ output: [ | ||
] | ||
}, | ||
{ | ||
}, { | ||
input: '<style>.selector {font-size:12px;}</style>', | ||
@@ -265,4 +236,3 @@ output: [ | ||
] | ||
}, | ||
{ | ||
}, { | ||
input: '<style type="text/css">.selector {font-size:12px;}</style>', | ||
@@ -282,75 +252,67 @@ output: [ | ||
description: "Wraps attributes inside of html tags", | ||
matrix: [ | ||
{ | ||
options: [ | ||
{ name: "wrap_attributes", value: "'force'" } | ||
], | ||
indent_attr: '\\n ', | ||
indent_over80: '\\n ' | ||
}, { | ||
options: [ | ||
{ name: "wrap_attributes", value: "'force'" }, | ||
{ name: "wrap_line_length", value: "80" } | ||
], | ||
indent_attr: '\\n ', | ||
indent_over80: '\\n ' | ||
}, { | ||
options: [ | ||
{ name: "wrap_attributes", value: "'force'" }, | ||
{ name: "wrap_attributes_indent_size", value: "8" }, | ||
], | ||
indent_attr: '\\n ', | ||
indent_over80: '\\n ' | ||
}, { | ||
options: [ | ||
{ name: "wrap_attributes", value: "'auto'" }, | ||
{ name: "wrap_line_length", value: "80" }, | ||
{ name: "wrap_attributes_indent_size", value: "0" } | ||
], | ||
indent_attr: ' ', | ||
indent_over80: '\\n' | ||
}, { | ||
options: [ | ||
{ name: "wrap_attributes", value: "'auto'" }, | ||
{ name: "wrap_line_length", value: "80" }, | ||
{ name: "wrap_attributes_indent_size", value: "4" } | ||
], | ||
indent_attr: ' ', | ||
indent_over80: '\\n ' | ||
}, { | ||
options: [ | ||
{ name: "wrap_attributes", value: "'auto'" }, | ||
{ name: "wrap_line_length", value: "0" } | ||
], | ||
indent_attr: ' ', | ||
indent_over80: ' ' | ||
} | ||
], | ||
tests: [ | ||
{ | ||
fragment: true, | ||
input: '<div attr0 attr1="123" data-attr2="hello t here">This is some text</div>', | ||
output: '<div attr0{{indent_attr}}attr1="123"{{indent_attr}}data-attr2="hello t here">This is some text</div>' | ||
}, | ||
{ | ||
fragment: true, | ||
input: '<div lookatthissuperduperlongattributenamewhoahcrazy0="true" attr0 attr1="123" data-attr2="hello t here" heymanimreallylongtoowhocomesupwiththesenames="false">This is some text</div>', | ||
output: '<div lookatthissuperduperlongattributenamewhoahcrazy0="true"{{indent_attr}}attr0{{indent_attr}}attr1="123"{{indent_attr}}data-attr2="hello t here"{{indent_over80}}heymanimreallylongtoowhocomesupwiththesenames="false">This is some text</div>' | ||
}, | ||
{ | ||
fragment: true, | ||
input: '<img attr0 attr1="123" data-attr2="hello t here"/>', | ||
output: '<img attr0{{indent_attr}}attr1="123"{{indent_attr}}data-attr2="hello t here" />' | ||
}, | ||
{ | ||
fragment: true, | ||
input: '<?xml version="1.0" encoding="UTF-8" ?><root attr1="foo" attr2="bar"/>', | ||
output: '<?xml version="1.0" encoding="UTF-8" ?>\n<root attr1="foo"{{indent_attr}}attr2="bar" />' | ||
}, | ||
{ | ||
fragment: true, | ||
input: '<link href="//fonts.googleapis.com/css?family=Open+Sans:300italic,400italic,600italic,700italic,400,600,700,300&subset=latin" rel="stylesheet" type="text/css">', | ||
output: '<link href="//fonts.googleapis.com/css?family=Open+Sans:300italic,400italic,600italic,700italic,400,600,700,300&subset=latin"{{indent_over80}}rel="stylesheet"{{indent_attr}}type="text/css">' | ||
} | ||
] | ||
matrix: [{ | ||
options: [ | ||
{ name: "wrap_attributes", value: "'force'" } | ||
], | ||
indent_attr: '\\n ', | ||
indent_over80: '\\n ' | ||
}, { | ||
options: [ | ||
{ name: "wrap_attributes", value: "'force'" }, | ||
{ name: "wrap_line_length", value: "80" } | ||
], | ||
indent_attr: '\\n ', | ||
indent_over80: '\\n ' | ||
}, { | ||
options: [ | ||
{ name: "wrap_attributes", value: "'force'" }, | ||
{ name: "wrap_attributes_indent_size", value: "8" }, | ||
], | ||
indent_attr: '\\n ', | ||
indent_over80: '\\n ' | ||
}, { | ||
options: [ | ||
{ name: "wrap_attributes", value: "'auto'" }, | ||
{ name: "wrap_line_length", value: "80" }, | ||
{ name: "wrap_attributes_indent_size", value: "0" } | ||
], | ||
indent_attr: ' ', | ||
indent_over80: '\\n' | ||
}, { | ||
options: [ | ||
{ name: "wrap_attributes", value: "'auto'" }, | ||
{ name: "wrap_line_length", value: "80" }, | ||
{ name: "wrap_attributes_indent_size", value: "4" } | ||
], | ||
indent_attr: ' ', | ||
indent_over80: '\\n ' | ||
}, { | ||
options: [ | ||
{ name: "wrap_attributes", value: "'auto'" }, | ||
{ name: "wrap_line_length", value: "0" } | ||
], | ||
indent_attr: ' ', | ||
indent_over80: ' ' | ||
}], | ||
tests: [{ | ||
fragment: true, | ||
input: '<div attr0 attr1="123" data-attr2="hello t here">This is some text</div>', | ||
output: '<div attr0{{indent_attr}}attr1="123"{{indent_attr}}data-attr2="hello t here">This is some text</div>' | ||
}, { | ||
fragment: true, | ||
input: '<div lookatthissuperduperlongattributenamewhoahcrazy0="true" attr0 attr1="123" data-attr2="hello t here" heymanimreallylongtoowhocomesupwiththesenames="false">This is some text</div>', | ||
output: '<div lookatthissuperduperlongattributenamewhoahcrazy0="true"{{indent_attr}}attr0{{indent_attr}}attr1="123"{{indent_attr}}data-attr2="hello t here"{{indent_over80}}heymanimreallylongtoowhocomesupwiththesenames="false">This is some text</div>' | ||
}, { | ||
fragment: true, | ||
input: '<img attr0 attr1="123" data-attr2="hello t here"/>', | ||
output: '<img attr0{{indent_attr}}attr1="123"{{indent_attr}}data-attr2="hello t here" />' | ||
}, { | ||
fragment: true, | ||
input: '<?xml version="1.0" encoding="UTF-8" ?><root attr1="foo" attr2="bar"/>', | ||
output: '<?xml version="1.0" encoding="UTF-8" ?>\n<root attr1="foo"{{indent_attr}}attr2="bar" />' | ||
}, { | ||
fragment: true, | ||
input: '<link href="//fonts.googleapis.com/css?family=Open+Sans:300italic,400italic,600italic,700italic,400,600,700,300&subset=latin" rel="stylesheet" type="text/css">', | ||
output: '<link href="//fonts.googleapis.com/css?family=Open+Sans:300italic,400italic,600italic,700italic,400,600,700,300&subset=latin"{{indent_over80}}rel="stylesheet"{{indent_attr}}type="text/css">' | ||
}] | ||
}, { | ||
@@ -363,25 +325,23 @@ name: "Handlebars Indenting Off", | ||
], | ||
tests: [ | ||
{ fragment: true, | ||
input_: | ||
'{{#if 0}}\n' + | ||
' <div>\n' + | ||
' </div>\n' + | ||
'{{/if}}', | ||
output: | ||
'{{#if 0}}\n' + | ||
'<div>\n' + | ||
'</div>\n' + | ||
'{{/if}}' }, | ||
{ fragment: true, | ||
input_: | ||
'<div>\n' + | ||
'{{#each thing}}\n' + | ||
' {{name}}\n' + | ||
'{{/each}}\n' + | ||
'</div>', | ||
output: | ||
'<div>\n' + | ||
' {{#each thing}} {{name}} {{/each}}\n' + | ||
'</div>'} | ||
tests: [{ | ||
fragment: true, | ||
input_: '{{#if 0}}\n' + | ||
' <div>\n' + | ||
' </div>\n' + | ||
'{{/if}}', | ||
output: '{{#if 0}}\n' + | ||
'<div>\n' + | ||
'</div>\n' + | ||
'{{/if}}' | ||
}, { | ||
fragment: true, | ||
input_: '<div>\n' + | ||
'{{#each thing}}\n' + | ||
' {{name}}\n' + | ||
'{{/each}}\n' + | ||
'</div>', | ||
output: '<div>\n' + | ||
' {{#each thing}} {{name}} {{/each}}\n' + | ||
'</div>' | ||
} | ||
@@ -393,26 +353,23 @@ ] | ||
template: "^^^ $$$", | ||
matrix: [ | ||
{ | ||
options: [ | ||
{ name: "indent_handlebars", value: "true" } | ||
], | ||
content: '{{field}}' | ||
}, { | ||
options: [ | ||
{ name: "indent_handlebars", value: "true" } | ||
], | ||
content: '{{! comment}}' | ||
}, { | ||
options: [ | ||
{ name: "indent_handlebars", value: "true" } | ||
], | ||
content: '{pre{{field1}} {{field2}} {{field3}}post' | ||
} | ||
, { | ||
options: [ | ||
{ name: "indent_handlebars", value: "true" } | ||
], | ||
content: '{{! \\n mult-line\\ncomment \\n with spacing\\n}}' | ||
} | ||
], | ||
matrix: [{ | ||
options: [ | ||
{ name: "indent_handlebars", value: "true" } | ||
], | ||
content: '{{field}}' | ||
}, { | ||
options: [ | ||
{ name: "indent_handlebars", value: "true" } | ||
], | ||
content: '{{! comment}}' | ||
}, { | ||
options: [ | ||
{ name: "indent_handlebars", value: "true" } | ||
], | ||
content: '{pre{{field1}} {{field2}} {{field3}}post' | ||
}, { | ||
options: [ | ||
{ name: "indent_handlebars", value: "true" } | ||
], | ||
content: '{{! \\n mult-line\\ncomment \\n with spacing\\n}}' | ||
}], | ||
tests: [ | ||
@@ -422,147 +379,159 @@ { fragment: true, unchanged: '{{page-title}}' }, | ||
{ fragment: true, unchanged: '{{#if 0}}^^^content$$${{/if}}' }, | ||
{ fragment: true, unchanged: '{{#if 0}}\n{{/if}}' }, | ||
{ fragment: true, | ||
{ fragment: true, unchanged: '{{#if 0}}\n{{/if}}' }, { | ||
fragment: true, | ||
input_: '{{#if words}}{{/if}}', | ||
output: '{{#if words}}{{/if}}' }, | ||
{ fragment: true, | ||
output: '{{#if words}}{{/if}}' | ||
}, { | ||
fragment: true, | ||
input_: '{{#if words}}^^^content$$${{/if}}', | ||
output: '{{#if words}}^^^content$$${{/if}}' }, | ||
{ fragment: true, | ||
output: '{{#if words}}^^^content$$${{/if}}' | ||
}, { | ||
fragment: true, | ||
input_: '{{#if words}}^^^content$$${{/if}}', | ||
output: '{{#if words}}^^^content$$${{/if}}' }, | ||
{ fragment: true, | ||
unchanged: | ||
'{{#if 1}}\n' + | ||
' <div>\n' + | ||
' </div>\n' + | ||
'{{/if}}' }, | ||
{ fragment: true, | ||
input_: | ||
'{{#if 1}}\n' + | ||
'<div>\n' + | ||
'</div>\n' + | ||
'{{/if}}', | ||
output: | ||
'{{#if 1}}\n' + | ||
' <div>\n' + | ||
' </div>\n' + | ||
'{{/if}}' }, | ||
{ fragment: true, | ||
unchanged: | ||
'<div>\n' + | ||
' {{#if 1}}\n' + | ||
' {{/if}}\n' + | ||
'</div>' }, | ||
{ fragment: true, | ||
input_: | ||
'<div>\n' + | ||
'{{#if 1}}\n' + | ||
'{{/if}}\n' + | ||
'</div>', | ||
output: | ||
'<div>\n' + | ||
' {{#if 1}}\n' + | ||
' {{/if}}\n' + | ||
'</div>' }, | ||
{ fragment: true, | ||
input_: | ||
'{{#if}}\n' + | ||
'{{#each}}\n' + | ||
'{{#if}}\n' + | ||
'^^^content$$$\n' + | ||
'{{/if}}\n' + | ||
'{{#if}}\n' + | ||
'^^^content$$$\n' + | ||
'{{/if}}\n' + | ||
'{{/each}}\n' + | ||
'{{/if}}', | ||
output: | ||
'{{#if}}\n' + | ||
' {{#each}}\n' + | ||
' {{#if}}\n' + | ||
' ^^^content$$$\n' + | ||
' {{/if}}\n' + | ||
' {{#if}}\n' + | ||
' ^^^content$$$\n' + | ||
' {{/if}}\n' + | ||
' {{/each}}\n' + | ||
'{{/if}}' }, | ||
{ fragment: true, unchanged: '{{#if 1}}\n' + | ||
' <div>\n' + | ||
' </div>\n' + | ||
'{{/if}}' }, | ||
output: '{{#if words}}^^^content$$${{/if}}' | ||
}, { | ||
fragment: true, | ||
unchanged: '{{#if 1}}\n' + | ||
' <div>\n' + | ||
' </div>\n' + | ||
'{{/if}}' | ||
}, { | ||
fragment: true, | ||
input_: '{{#if 1}}\n' + | ||
'<div>\n' + | ||
'</div>\n' + | ||
'{{/if}}', | ||
output: '{{#if 1}}\n' + | ||
' <div>\n' + | ||
' </div>\n' + | ||
'{{/if}}' | ||
}, { | ||
fragment: true, | ||
unchanged: '<div>\n' + | ||
' {{#if 1}}\n' + | ||
' {{/if}}\n' + | ||
'</div>' | ||
}, { | ||
fragment: true, | ||
input_: '<div>\n' + | ||
'{{#if 1}}\n' + | ||
'{{/if}}\n' + | ||
'</div>', | ||
output: '<div>\n' + | ||
' {{#if 1}}\n' + | ||
' {{/if}}\n' + | ||
'</div>' | ||
}, { | ||
fragment: true, | ||
input_: '{{#if}}\n' + | ||
'{{#each}}\n' + | ||
'{{#if}}\n' + | ||
'^^^content$$$\n' + | ||
'{{/if}}\n' + | ||
'{{#if}}\n' + | ||
'^^^content$$$\n' + | ||
'{{/if}}\n' + | ||
'{{/each}}\n' + | ||
'{{/if}}', | ||
output: '{{#if}}\n' + | ||
' {{#each}}\n' + | ||
' {{#if}}\n' + | ||
' ^^^content$$$\n' + | ||
' {{/if}}\n' + | ||
' {{#if}}\n' + | ||
' ^^^content$$$\n' + | ||
' {{/if}}\n' + | ||
' {{/each}}\n' + | ||
'{{/if}}' | ||
}, { | ||
fragment: true, | ||
unchanged: '{{#if 1}}\n' + | ||
' <div>\n' + | ||
' </div>\n' + | ||
'{{/if}}' | ||
}, | ||
// Test {{else}} aligned with {{#if}} and {{/if}} | ||
{ fragment: true, | ||
input_: | ||
'{{#if 1}}\n' + | ||
' ^^^content$$$\n' + | ||
' {{else}}\n' + | ||
' ^^^content$$$\n' + | ||
'{{/if}}', | ||
output: | ||
'{{#if 1}}\n' + | ||
' ^^^content$$$\n' + | ||
'{{else}}\n' + | ||
' ^^^content$$$\n' + | ||
'{{/if}}' }, | ||
{ fragment: true, | ||
input_: | ||
'{{#if 1}}\n' + | ||
' {{else}}\n' + | ||
' {{/if}}', | ||
output: | ||
'{{#if 1}}\n' + | ||
'{{else}}\n' + | ||
'{{/if}}' }, | ||
{ fragment: true, | ||
input_: | ||
'{{#if thing}}\n' + | ||
'{{#if otherthing}}\n' + | ||
' ^^^content$$$\n' + | ||
' {{else}}\n' + | ||
'^^^content$$$\n' + | ||
' {{/if}}\n' + | ||
' {{else}}\n'+ | ||
'^^^content$$$\n' + | ||
'{{/if}}', | ||
output: | ||
'{{#if thing}}\n' + | ||
' {{#if otherthing}}\n' + | ||
' ^^^content$$$\n' + | ||
' {{else}}\n' + | ||
' ^^^content$$$\n' + | ||
' {{/if}}\n' + | ||
'{{else}}\n'+ | ||
' ^^^content$$$\n' + | ||
'{{/if}}' }, | ||
// Test {{}} inside of <> tags, which should be separated by spaces | ||
// for readability, unless they are inside a string. | ||
{ fragment: true, | ||
{ | ||
fragment: true, | ||
input_: '{{#if 1}}\n' + | ||
' ^^^content$$$\n' + | ||
' {{else}}\n' + | ||
' ^^^content$$$\n' + | ||
'{{/if}}', | ||
output: '{{#if 1}}\n' + | ||
' ^^^content$$$\n' + | ||
'{{else}}\n' + | ||
' ^^^content$$$\n' + | ||
'{{/if}}' | ||
}, { | ||
fragment: true, | ||
input_: '{{#if 1}}\n' + | ||
' {{else}}\n' + | ||
' {{/if}}', | ||
output: '{{#if 1}}\n' + | ||
'{{else}}\n' + | ||
'{{/if}}' | ||
}, { | ||
fragment: true, | ||
input_: '{{#if thing}}\n' + | ||
'{{#if otherthing}}\n' + | ||
' ^^^content$$$\n' + | ||
' {{else}}\n' + | ||
'^^^content$$$\n' + | ||
' {{/if}}\n' + | ||
' {{else}}\n' + | ||
'^^^content$$$\n' + | ||
'{{/if}}', | ||
output: '{{#if thing}}\n' + | ||
' {{#if otherthing}}\n' + | ||
' ^^^content$$$\n' + | ||
' {{else}}\n' + | ||
' ^^^content$$$\n' + | ||
' {{/if}}\n' + | ||
'{{else}}\n' + | ||
' ^^^content$$$\n' + | ||
'{{/if}}' | ||
}, | ||
// Test {{}} inside of <> tags, which should be separated by spaces | ||
// for readability, unless they are inside a string. | ||
{ | ||
fragment: true, | ||
input_: '<div{{somestyle}}></div>', | ||
output: '<div {{somestyle}}></div>' }, | ||
{ fragment: true, | ||
output: '<div {{somestyle}}></div>' | ||
}, { | ||
fragment: true, | ||
input_: '<div{{#if test}}class="foo"{{/if}}>^^^content$$$</div>', | ||
output: '<div {{#if test}} class="foo" {{/if}}>^^^content$$$</div>' }, | ||
{ fragment: true, | ||
output: '<div {{#if test}} class="foo" {{/if}}>^^^content$$$</div>' | ||
}, { | ||
fragment: true, | ||
input_: '<div{{#if thing}}{{somestyle}}class="{{class}}"{{else}}class="{{class2}}"{{/if}}>^^^content$$$</div>', | ||
output: '<div {{#if thing}} {{somestyle}} class="{{class}}" {{else}} class="{{class2}}" {{/if}}>^^^content$$$</div>' }, | ||
{ fragment: true, | ||
output: '<div {{#if thing}} {{somestyle}} class="{{class}}" {{else}} class="{{class2}}" {{/if}}>^^^content$$$</div>' | ||
}, { | ||
fragment: true, | ||
input_: '<span{{#if condition}}class="foo"{{/if}}>^^^content$$$</span>', | ||
output: '<span {{#if condition}} class="foo" {{/if}}>^^^content$$$</span>' }, | ||
{ fragment: true, | ||
unchanged: '<div unformatted="{{#if}}^^^content$$${{/if}}">^^^content$$$</div>' }, | ||
{ fragment: true, | ||
unchanged: '<div unformatted="{{#if }} ^^^content$$${{/if}}">^^^content$$$</div>' }, | ||
output: '<span {{#if condition}} class="foo" {{/if}}>^^^content$$$</span>' | ||
}, { | ||
fragment: true, | ||
unchanged: '<div unformatted="{{#if}}^^^content$$${{/if}}">^^^content$$$</div>' | ||
}, { | ||
fragment: true, | ||
unchanged: '<div unformatted="{{#if }} ^^^content$$${{/if}}">^^^content$$$</div>' | ||
}, | ||
// Quotes found inside of Handlebars expressions inside of quoted | ||
// strings themselves should not be considered string delimiters. | ||
{ fragment: true, | ||
unchanged: '<div class="{{#if thingIs "value"}}^^^content$$${{/if}}"></div>' }, | ||
{ fragment: true, | ||
unchanged: '<div class="{{#if thingIs \\\'value\\\'}}^^^content$$${{/if}}"></div>' }, | ||
{ fragment: true, | ||
unchanged: '<div class=\\\'{{#if thingIs "value"}}^^^content$$${{/if}}\\\'></div>' }, | ||
{ fragment: true, | ||
unchanged: '<div class=\\\'{{#if thingIs \\\'value\\\'}}^^^content$$${{/if}}\\\'></div>' } | ||
{ | ||
fragment: true, | ||
unchanged: '<div class="{{#if thingIs "value"}}^^^content$$${{/if}}"></div>' | ||
}, { | ||
fragment: true, | ||
unchanged: '<div class="{{#if thingIs \\\'value\\\'}}^^^content$$${{/if}}"></div>' | ||
}, { | ||
fragment: true, | ||
unchanged: '<div class=\\\'{{#if thingIs "value"}}^^^content$$${{/if}}\\\'></div>' | ||
}, { | ||
fragment: true, | ||
unchanged: '<div class=\\\'{{#if thingIs \\\'value\\\'}}^^^content$$${{/if}}\\\'></div>' | ||
} | ||
], | ||
@@ -572,20 +541,18 @@ }, { | ||
description: "Handlebar Else tags should be newlined after formatted tags", | ||
template: "^^^ $$$", | ||
template: "^^^ $$$", | ||
options: [ | ||
{name: "indent_handlebars", value: "true"} | ||
], | ||
tests: [ | ||
{ fragment: true, | ||
input_: | ||
'{{#if test}}<div></div>{{else}}<div></div>{{/if}}', | ||
output: | ||
'{{#if test}}\n' + | ||
' <div></div>\n' + | ||
'{{else}}\n' + | ||
' <div></div>\n' + | ||
'{{/if}}' }, | ||
{ fragment: true, | ||
unchanged: | ||
'{{#if test}}<span></span>{{else}}<span></span>{{/if}}' } | ||
] | ||
{ name: "indent_handlebars", value: "true" } | ||
], | ||
tests: [{ | ||
fragment: true, | ||
input_: '{{#if test}}<div></div>{{else}}<div></div>{{/if}}', | ||
output: '{{#if test}}\n' + | ||
' <div></div>\n' + | ||
'{{else}}\n' + | ||
' <div></div>\n' + | ||
'{{/if}}' | ||
}, { | ||
fragment: true, | ||
unchanged: '{{#if test}}<span></span>{{else}}<span></span>{{/if}}' | ||
}] | ||
}, { | ||
@@ -619,5 +586,5 @@ name: "Unclosed html elements", | ||
tests: [ | ||
{ fragment: true, unchanged: '<h1 class="content-page-header"><?=$view["name"]; ?></h1>' }, | ||
{ fragment: true, unchanged: | ||
[ | ||
{ fragment: true, unchanged: '<h1 class="content-page-header"><?=$view["name"]; ?></h1>' }, { | ||
fragment: true, | ||
unchanged: [ | ||
'<?php', | ||
@@ -630,4 +597,5 @@ 'for($i = 1; $i <= 100; $i++;) {', | ||
] | ||
}, { fragment: true, unchanged: | ||
[ | ||
}, { | ||
fragment: true, | ||
unchanged: [ | ||
'<?php ?>', | ||
@@ -650,13 +618,12 @@ '<!DOCTYPE html>', | ||
options: [], | ||
tests: [ | ||
{ fragment: true, unchanged: | ||
[ | ||
'<div class="col-sm-9">', | ||
' <textarea id="notes" class="form-control" rows="3">', | ||
' <%= notes %>', | ||
' </textarea>', | ||
'</div>' | ||
] | ||
}, | ||
] | ||
tests: [{ | ||
fragment: true, | ||
unchanged: [ | ||
'<div class="col-sm-9">', | ||
' <textarea id="notes" class="form-control" rows="3">', | ||
' <%= notes %>', | ||
' </textarea>', | ||
'</div>' | ||
] | ||
}, ] | ||
}, { | ||
@@ -669,15 +636,13 @@ name: "Indent with tabs", | ||
], | ||
tests: [ | ||
{ fragment: true, | ||
input_: | ||
tests: [{ | ||
fragment: true, | ||
input_: '<div>\n' + | ||
'<div>\n' + | ||
'<div>\n' + | ||
'</div>\n' + | ||
'</div>', | ||
output: | ||
'<div>\n' + | ||
output: '<div>\n' + | ||
'\t<div>\n' + | ||
'\t</div>\n' + | ||
'</div>' } | ||
] | ||
'</div>' | ||
}] | ||
}, { | ||
@@ -690,18 +655,16 @@ name: "Indent without tabs", | ||
], | ||
tests: [ | ||
{ fragment: true, | ||
input_: | ||
tests: [{ | ||
fragment: true, | ||
input_: '<div>\n' + | ||
'<div>\n' + | ||
'<div>\n' + | ||
'</div>\n' + | ||
'</div>', | ||
output: | ||
'<div>\n' + | ||
output: '<div>\n' + | ||
' <div>\n' + | ||
' </div>\n' + | ||
'</div>' } | ||
] | ||
}, { | ||
name: "New Test Suite" | ||
}], | ||
}; | ||
'</div>' | ||
}] | ||
}, { | ||
name: "New Test Suite" | ||
}], | ||
}; |
#!/usr/bin/env node | ||
var fs = require('fs'); | ||
@@ -7,9 +8,7 @@ var mustache = require('mustache'); | ||
function generate_tests() { | ||
var test_data, template; | ||
// javascript | ||
generate_test_files('javascript', 'bt', 'js/test/generated/beautify-javascript-tests.js', 'python/jsbeautifier/tests/generated/tests.py' ); | ||
generate_test_files('javascript', 'bt', 'js/test/generated/beautify-javascript-tests.js', 'python/jsbeautifier/tests/generated/tests.py'); | ||
// css | ||
generate_test_files('css', 't', 'js/test/generated/beautify-css-tests.js', 'python/cssbeautifier/tests/generated/tests.py' ); | ||
generate_test_files('css', 't', 'js/test/generated/beautify-css-tests.js', 'python/cssbeautifier/tests/generated/tests.py'); | ||
@@ -30,19 +29,19 @@ // html | ||
template_file_path = path.resolve(input_path, 'node.mustache'); | ||
template = fs.readFileSync(template_file_path, {encoding: 'utf-8'}); | ||
set_formatters(test_data, test_method, '// ') | ||
template = fs.readFileSync(template_file_path, { encoding: 'utf-8' }); | ||
set_formatters(test_data, test_method, '// '); | ||
set_generated_header(test_data, data_file_path, template_file_path); | ||
fs.writeFileSync(path.resolve(__dirname, '..', node_output), | ||
mustache.render(template, test_data), {encoding: 'utf-8'}); | ||
mustache.render(template, test_data), { encoding: 'utf-8' }); | ||
if (python_output) { | ||
template_file_path = path.resolve(input_path, 'python.mustache'); | ||
template = fs.readFileSync(template_file_path, {encoding: 'utf-8'}); | ||
set_formatters(test_data, test_method, '# ') | ||
template = fs.readFileSync(template_file_path, { encoding: 'utf-8' }); | ||
set_formatters(test_data, test_method, '# '); | ||
set_generated_header(test_data, data_file_path, template_file_path); | ||
fs.writeFileSync(path.resolve(__dirname, '..', python_output), | ||
mustache.render(template, test_data), {encoding: 'utf-8'}); | ||
mustache.render(template, test_data), { encoding: 'utf-8' }); | ||
} | ||
} | ||
function set_generated_header (data, data_file_path, template_file_path) { | ||
function set_generated_header(data, data_file_path, template_file_path) { | ||
var relative_script_path = path.relative(process.cwd(), __filename).split(path.sep).join('/'); | ||
@@ -66,5 +65,5 @@ var relative_data_file_path = path.relative(process.cwd(), data_file_path).split(path.sep).join('/'); | ||
if (typeof val === 'string') { | ||
return "'" + val.replace(/\n/g,'\\n').replace(/\t/g,'\\t') + "'"; | ||
return "'" + val.replace(/\n/g, '\\n').replace(/\t/g, '\\t') + "'"; | ||
} else if (val instanceof Array) { | ||
return "'" + val.join("\\n' +\n '").replace(/\t/g,'\\t') + "'"; | ||
return "'" + val.join("\\n' +\n '").replace(/\t/g, '\\t') + "'"; | ||
} else { | ||
@@ -75,3 +74,3 @@ return null; | ||
function set_formatters (data, test_method, comment_mark) { | ||
function set_formatters(data, test_method, comment_mark) { | ||
@@ -94,3 +93,3 @@ // utility mustache functions | ||
return render(outputs.join(', ')); | ||
} | ||
}; | ||
}; | ||
@@ -138,3 +137,3 @@ | ||
set_input(this.unchanged); | ||
if(isStringOrArray(this.unchanged) && isStringOrArray(this.output)) { | ||
if (isStringOrArray(this.unchanged) && isStringOrArray(this.output)) { | ||
throw "Cannot specify 'output' with 'unchanged' test input: " + input; | ||
@@ -162,3 +161,3 @@ } | ||
if(output && output.indexOf('<%') !== -1) { | ||
if (output && output.indexOf('<%') !== -1) { | ||
mustache.tags = ['<%', '%>']; | ||
@@ -168,3 +167,3 @@ } | ||
output = render(output); | ||
if(output && output.indexOf('<%') !== -1) { | ||
if (output && output.indexOf('<%') !== -1) { | ||
mustache.tags = ['{{', '}}']; | ||
@@ -177,25 +176,25 @@ } | ||
} | ||
return comment + before_input + input + before_output + output + ')'; | ||
} | ||
return comment + before_input + input + before_output + output + ')'; | ||
}; | ||
}; | ||
data.set_mustache_tags = function() { | ||
return function(text, render) { | ||
if(this.template) { | ||
return function( /* text, render */ ) { | ||
if (this.template) { | ||
mustache.tags = this.template.split(' '); | ||
} | ||
return ''; | ||
} | ||
}; | ||
}; | ||
data.unset_mustache_tags = function() { | ||
return function(text, render) { | ||
if(this.template) { | ||
return function( /* text , render */ ) { | ||
if (this.template) { | ||
mustache.tags = ['{{', '}}']; | ||
} | ||
return ''; | ||
} | ||
}; | ||
}; | ||
} | ||
generate_tests(); | ||
generate_tests(); |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
1078533
59
13590