@kademi/keditor
Version:
KEditor is a jQuery plugin which provides a content editor with drag n drop, configurable contents
1,459 lines (1,376 loc) • 212 kB
JavaScript
/*
AUTO-GENERATED. DO NOT MODIFY.
Script: test/generate-tests.js
Template: test/data/javascript/node.mustache
Data: test/data/javascript/tests.js
The MIT License (MIT)
Copyright (c) 2007-2017 Einar Lielmanis, Liam Newman, and contributors.
Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation files
(the "Software"), to deal in the Software without restriction,
including without limitation the rights to use, copy, modify, merge,
publish, distribute, sublicense, and/or sell copies of the Software,
and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
/*jshint unused:false */
function run_javascript_tests(test_obj, Urlencoded, js_beautify, html_beautify, css_beautify)
{
var default_opts = {
indent_size: 4,
indent_char: ' ',
preserve_newlines: true,
jslint_happy: false,
keep_array_indentation: false,
brace_style: 'collapse',
space_before_conditional: true,
break_chained_methods: false,
selector_separator: '\n',
end_with_newline: false
};
var opts;
default_opts.indent_size = 4;
default_opts.indent_char = ' ';
default_opts.preserve_newlines = true;
default_opts.jslint_happy = false;
default_opts.keep_array_indentation = false;
default_opts.brace_style = 'collapse';
default_opts.operator_position = 'before-newline';
function reset_options()
{
opts = JSON.parse(JSON.stringify(default_opts));
}
function test_js_beautifier(input)
{
return js_beautify(input, opts);
}
var sanitytest;
// test the input on beautifier with the current flag settings
// does not check the indentation / surroundings as bt() does
function test_fragment(input, expected)
{
expected = expected || expected === '' ? expected : input;
sanitytest.expect(input, expected);
// if the expected is different from input, run it again
// expected output should be unchanged when run twice.
if (expected !== input) {
sanitytest.expect(expected, expected);
}
// Everywhere we do newlines, they should be replaced with opts.eol
opts.eol = '\r\\n';
expected = expected.replace(/[\n]/g, '\r\n');
sanitytest.expect(input, expected);
if (input.indexOf('\n') !== -1) {
input = input.replace(/[\n]/g, '\r\n');
sanitytest.expect(input, expected);
// Ensure support for auto eol detection
opts.eol = 'auto';
sanitytest.expect(input, expected);
}
opts.eol = '\n';
}
// test the input on beautifier with the current flag settings
// test both the input as well as { input } wrapping
function bt(input, expectation)
{
var wrapped_input, wrapped_expectation;
expectation = expectation || expectation === '' ? expectation : input;
sanitytest.test_function(test_js_beautifier, 'js_beautify');
test_fragment(input, expectation);
// If we set raw, input should be unchanged
opts.test_output_raw = true;
if (!opts.end_with_newline) {
test_fragment(input, input);
}
opts.test_output_raw = false;
// test also the returned indentation
// e.g if input = "asdf();"
// then test that this remains properly formatted as well:
// {
// asdf();
// indent;
// }
var current_indent_size = opts.js ? opts.js.indent_size : null;
current_indent_size = current_indent_size ? current_indent_size : opts.indent_size;
if (current_indent_size === 4 && input) {
wrapped_input = '{\n' + input.replace(/^(.+)$/mg, ' $1') + '\n foo = bar;\n}';
wrapped_expectation = '{\n' + expectation.replace(/^(.+)$/mg, ' $1') + '\n foo = bar;\n}';
test_fragment(wrapped_input, wrapped_expectation);
// If we set raw, input should be unchanged
opts.test_output_raw = true;
if (!opts.end_with_newline) {
test_fragment(wrapped_input, wrapped_input);
}
opts.test_output_raw = false;
}
}
// run all tests for the given brace style ("collapse", "expand", "end-expand", or "none").
// uses various whitespace combinations before and after opening and closing braces,
// respectively, for most of the tests' inputs.
function beautify_brace_tests(brace_style) {
var indent_on_wrap_str = ' '; // could use Array(opts.indent_size + 1).join(' '); if we wanted to replace _all_ of the hardcoded 4-space in the test and expectation strings
function permute_brace_tests(expect_open_white, expect_close_white) {
// run the tests that need permutation against a specific combination of
// pre-opening-brace and pre-closing-brace whitespace
function run_brace_permutation(test_open_white, test_close_white) {
var to = test_open_white,
tc = test_close_white,
eo = expect_open_white ? expect_open_white : to === '' ? ' ' : to,
ec = expect_close_white ? expect_close_white : tc === '' ? ' ' : tc,
i = eo === '\n' ? indent_on_wrap_str: '';
bt( '//case 1\nif (a == 1)' + to + '{}\n//case 2\nelse if (a == 2)' + to + '{}',
'//case 1\nif (a == 1)' + eo + '{}\n//case 2\nelse if (a == 2)' + eo + '{}');
bt( 'if(1)' + to + '{2}' + tc + 'else' + to + '{3}',
'if (1)' + eo + '{\n 2\n}' + ec + 'else' + eo + '{\n 3\n}');
bt( 'try' + to + '{a();}' + tc +
'catch(b)' + to + '{c();}' + tc +
'catch(d)' + to + '{}' + tc +
'finally' + to + '{e();}',
// expected
'try' + eo + '{\n a();\n}' + ec +
'catch (b)' + eo + '{\n c();\n}' + ec +
'catch (d)' + eo + '{}' + ec +
'finally' + eo + '{\n e();\n}');
bt( 'if(a)' + to + '{b();}' + tc + 'else if(c) foo();',
'if (a)' + eo + '{\n b();\n}' + ec + 'else if (c) foo();');
// if/else statement with empty body
bt( 'if (a)' + to + '{\n// comment\n}' + tc + 'else' + to + '{\n// comment\n}',
'if (a)' + eo + '{\n // comment\n}' + ec + 'else' + eo + '{\n // comment\n}');
bt( 'if (x)' + to + '{y}' + tc + 'else' + to + '{ if (x)' + to + '{y}}',
'if (x)' + eo + '{\n y\n}' + ec + 'else' + eo + '{\n if (x)' + eo + i + '{\n y\n }\n}');
bt( 'if (a)' + to + '{\nb;\n}' + tc + 'else' + to + '{\nc;\n}',
'if (a)' + eo + '{\n b;\n}' + ec + 'else' + eo + '{\n c;\n}');
test_fragment(' /*\n* xx\n*/\n// xx\nif (foo)' + to + '{\n bar();\n}',
' /*\n * xx\n */\n // xx\n if (foo)' + eo + i + '{\n bar();\n }');
bt( 'if (foo)' + to + '{}' + tc + 'else /regex/.test();',
'if (foo)' + eo + '{}' + ec + 'else /regex/.test();');
test_fragment('if (foo)' + to + '{', 'if (foo)' + eo + '{');
test_fragment('foo' + to + '{', 'foo' + eo + '{');
test_fragment('return;' + to + '{', 'return;' + eo + '{');
bt( 'function x()' + to + '{\n foo();\n}zzz', 'function x()' + eo +'{\n foo();\n}\nzzz');
bt( 'var a = new function a()' + to + '{};', 'var a = new function a()' + eo + '{};');
bt( 'var a = new function a()' + to + ' {},\n b = new function b()' + to + ' {};',
'var a = new function a()' + eo + i + '{},\n b = new function b()' + eo + i + '{};');
bt("foo(" + to + "{\n 'a': 1\n},\n10);",
"foo(" + (eo === ' ' ? '' : eo) + i + "{\n 'a': 1\n },\n 10);"); // "foo( {..." is a weird case
bt('(["foo","bar"]).each(function(i)' + to + '{return i;});',
'(["foo", "bar"]).each(function(i)' + eo + '{\n return i;\n});');
bt('(function(i)' + to + '{return i;})();', '(function(i)' + eo + '{\n return i;\n})();');
bt( "test( /*Argument 1*/" + to + "{\n" +
" 'Value1': '1'\n" +
"}, /*Argument 2\n" +
" */ {\n" +
" 'Value2': '2'\n" +
"});",
// expected
"test( /*Argument 1*/" + eo + i + "{\n" +
" 'Value1': '1'\n" +
" },\n" +
" /*Argument 2\n" +
" */\n" +
" {\n" +
" 'Value2': '2'\n" +
" });");
bt( "test( /*Argument 1*/" + to + "{\n" +
" 'Value1': '1'\n" +
"}, /*Argument 2\n" +
" */\n" +
"{\n" +
" 'Value2': '2'\n" +
"});",
// expected
"test( /*Argument 1*/" + eo + i + "{\n" +
" 'Value1': '1'\n" +
" },\n" +
" /*Argument 2\n" +
" */\n" +
" {\n" +
" 'Value2': '2'\n" +
" });");
}
run_brace_permutation('\n', '\n');
run_brace_permutation('\n', ' ');
run_brace_permutation(' ', ' ');
run_brace_permutation(' ', '\n');
run_brace_permutation('','');
// brace tests that don't make sense to permutate
test_fragment('return {'); // return needs the brace.
test_fragment('return /* inline */ {');
bt('throw {}');
bt('throw {\n foo;\n}');
bt( 'var foo = {}');
test_fragment('a: do {} while (); xxx', 'a: do {} while ();\nxxx');
bt( '{a: do {} while (); xxx}', '{\n a: do {} while ();xxx\n}');
bt( 'var a = new function() {};');
bt( 'var a = new function()\n{};', 'var a = new function() {};');
bt( "test(\n" +
"/*Argument 1*/ {\n" +
" 'Value1': '1'\n" +
"},\n" +
"/*Argument 2\n" +
" */ {\n" +
" 'Value2': '2'\n" +
"});",
// expected
"test(\n" +
" /*Argument 1*/\n" +
" {\n" +
" 'Value1': '1'\n" +
" },\n" +
" /*Argument 2\n" +
" */\n" +
" {\n" +
" 'Value2': '2'\n" +
" });");
}
reset_options();
opts.brace_style = brace_style;
switch(opts.brace_style) {
case 'collapse':
permute_brace_tests(' ', ' ');
break;
case 'expand':
permute_brace_tests('\n', '\n');
break;
case 'end-expand':
permute_brace_tests(' ', '\n');
break;
case 'none':
permute_brace_tests();
break;
}
}
function unicode_char(value) {
return String.fromCharCode(value);
}
function beautifier_tests()
{
sanitytest = test_obj;
//============================================================
// Unicode Support
reset_options();
bt('var ' + unicode_char(3232) + '_' + unicode_char(3232) + ' = "hi";');
bt(
'var ' + unicode_char(228) + 'x = {\n' +
' ' + unicode_char(228) + 'rgerlich: true\n' +
'};');
//============================================================
// Test template and continuation strings
reset_options();
bt('`This is a ${template} string.`');
bt(
'`This\n' +
' is\n' +
' a\n' +
' ${template}\n' +
' string.`');
bt(
'a = `This is a continuation\\\n' +
'string.`');
bt(
'a = "This is a continuation\\\n' +
'string."');
bt(
'`SELECT\n' +
' nextval(\'${this.options.schema ? `${this.options.schema}.` : \'\'}"${this.tableName}_${this.autoIncrementField}_seq"\'::regclass\n' +
' ) nextval;`');
// Tests for #1030
bt(
'const composeUrl = (host) => {\n' +
' return `${host `test`}`;\n' +
'};');
bt(
'const composeUrl = (host, api, key, data) => {\n' +
' switch (api) {\n' +
' case "Init":\n' +
' return `${host}/vwapi/Init?VWID=${key}&DATA=${encodeURIComponent(\n' +
' Object.keys(data).map((k) => `${k}=${ data[k]}` ).join(";")\n' +
' )}`;\n' +
' case "Pay":\n' +
' return `${host}/vwapi/Pay?SessionId=${par}`;\n' +
' };\n' +
'};');
//============================================================
// ES7 Decorators
reset_options();
bt('@foo');
bt('@foo(bar)');
bt(
'@foo(function(k, v) {\n' +
' implementation();\n' +
'})');
//============================================================
// ES7 exponential
reset_options();
bt('x ** 2');
bt('x ** -2');
//============================================================
// Spread operator
reset_options();
opts.brace_style = "collapse,preserve-inline";
bt('const m = { ...item, c: 3 };');
bt(
'const m = {\n' +
' ...item,\n' +
' c: 3\n' +
'};');
bt('const m = { c: 3, ...item };');
bt('const m = [...item, 3];');
bt('const m = [3, ...item];');
//============================================================
// Object literal shorthand functions
reset_options();
bt(
'return {\n' +
' foo() {\n' +
' return 42;\n' +
' }\n' +
'}');
bt(
'var foo = {\n' +
' * bar() {\n' +
' yield 42;\n' +
' }\n' +
'};');
bt(
'var foo = {bar(){return 42;},*barGen(){yield 42;}};',
// -- output --
'var foo = {\n' +
' bar() {\n' +
' return 42;\n' +
' },\n' +
' * barGen() {\n' +
' yield 42;\n' +
' }\n' +
'};');
// also handle generator shorthand in class - #1013
bt(
'class A {\n' +
' fn() {\n' +
' return true;\n' +
' }\n' +
'\n' +
' * gen() {\n' +
' return true;\n' +
' }\n' +
'}');
bt(
'class A {\n' +
' * gen() {\n' +
' return true;\n' +
' }\n' +
'\n' +
' fn() {\n' +
' return true;\n' +
' }\n' +
'}');
//============================================================
// End With Newline - (eof = "\n")
reset_options();
opts.end_with_newline = true;
test_fragment('', '\n');
test_fragment(' return .5', ' return .5\n');
test_fragment(
' \n' +
'\n' +
'return .5\n' +
'\n' +
'\n' +
'\n',
// -- output --
' return .5\n');
test_fragment('\n');
// End With Newline - (eof = "")
reset_options();
opts.end_with_newline = false;
test_fragment('');
test_fragment(' return .5');
test_fragment(
' \n' +
'\n' +
'return .5\n' +
'\n' +
'\n' +
'\n',
// -- output --
' return .5');
test_fragment('\n', '');
//============================================================
// Support simple language specific option inheritance/overriding - (j = " ")
reset_options();
opts.js = { 'indent_size': 3 };
opts.css = { 'indent_size': 5 };
bt(
'if (a == b) {\n' +
' test();\n' +
'}');
// Support simple language specific option inheritance/overriding - (j = " ")
reset_options();
opts.html = { 'js': { 'indent_size': 3 }, 'css': { 'indent_size': 5 } };
bt(
'if (a == b) {\n' +
' test();\n' +
'}');
// Support simple language specific option inheritance/overriding - (j = " ")
reset_options();
opts.indent_size = 9;
opts.html = { 'js': { 'indent_size': 3 }, 'css': { 'indent_size': 5 }, 'indent_size': 2};
opts.js = { 'indent_size': 4 };
opts.css = { 'indent_size': 3 };
bt(
'if (a == b) {\n' +
' test();\n' +
'}');
//============================================================
// Brace style permutations - (ibo = "", iao = "", ibc = "", iac = "", obo = " ", oao = " ", obc = " ", oac = " ")
reset_options();
opts.brace_style = 'collapse,preserve-inline';
bt(
'var a ={a: 2};\n' +
'var a ={a: 2};',
// -- output --
'var a = { a: 2 };\n' +
'var a = { a: 2 };');
bt(
'//case 1\n' +
'if (a == 1){}\n' +
'//case 2\n' +
'else if (a == 2){}',
// -- output --
'//case 1\n' +
'if (a == 1) {}\n' +
'//case 2\n' +
'else if (a == 2) {}');
bt('if(1){2}else{3}', 'if (1) { 2 } else { 3 }');
bt('try{a();}catch(b){c();}catch(d){}finally{e();}', 'try { a(); } catch (b) { c(); } catch (d) {} finally { e(); }');
// Brace style permutations - (ibo = "\n", iao = "\n", ibc = "\n", iac = "\n", obo = " ", oao = "\n ", obc = "\n", oac = " ")
reset_options();
opts.brace_style = 'collapse,preserve-inline';
bt(
'var a =\n' +
'{\n' +
'a: 2\n' +
'}\n' +
';\n' +
'var a =\n' +
'{\n' +
'a: 2\n' +
'}\n' +
';',
// -- output --
'var a = {\n' +
' a: 2\n' +
'};\n' +
'var a = {\n' +
' a: 2\n' +
'};');
bt(
'//case 1\n' +
'if (a == 1)\n' +
'{}\n' +
'//case 2\n' +
'else if (a == 2)\n' +
'{}',
// -- output --
'//case 1\n' +
'if (a == 1) {}\n' +
'//case 2\n' +
'else if (a == 2) {}');
bt(
'if(1)\n' +
'{\n' +
'2\n' +
'}\n' +
'else\n' +
'{\n' +
'3\n' +
'}',
// -- output --
'if (1) {\n' +
' 2\n' +
'} else {\n' +
' 3\n' +
'}');
bt(
'try\n' +
'{\n' +
'a();\n' +
'}\n' +
'catch(b)\n' +
'{\n' +
'c();\n' +
'}\n' +
'catch(d)\n' +
'{}\n' +
'finally\n' +
'{\n' +
'e();\n' +
'}',
// -- output --
'try {\n' +
' a();\n' +
'} catch (b) {\n' +
' c();\n' +
'} catch (d) {} finally {\n' +
' e();\n' +
'}');
// Brace style permutations - (ibo = "", iao = "", ibc = "", iac = "", obo = " ", oao = "\n ", obc = "\n", oac = " ")
reset_options();
opts.brace_style = 'collapse';
bt(
'var a ={a: 2};\n' +
'var a ={a: 2};',
// -- output --
'var a = {\n' +
' a: 2\n' +
'};\n' +
'var a = {\n' +
' a: 2\n' +
'};');
bt(
'//case 1\n' +
'if (a == 1){}\n' +
'//case 2\n' +
'else if (a == 2){}',
// -- output --
'//case 1\n' +
'if (a == 1) {}\n' +
'//case 2\n' +
'else if (a == 2) {}');
bt(
'if(1){2}else{3}',
// -- output --
'if (1) {\n' +
' 2\n' +
'} else {\n' +
' 3\n' +
'}');
bt(
'try{a();}catch(b){c();}catch(d){}finally{e();}',
// -- output --
'try {\n' +
' a();\n' +
'} catch (b) {\n' +
' c();\n' +
'} catch (d) {} finally {\n' +
' e();\n' +
'}');
// Brace style permutations - (ibo = "\n", iao = "\n", ibc = "\n", iac = "\n", obo = " ", oao = "\n ", obc = "\n", oac = " ")
reset_options();
opts.brace_style = 'collapse';
bt(
'var a =\n' +
'{\n' +
'a: 2\n' +
'}\n' +
';\n' +
'var a =\n' +
'{\n' +
'a: 2\n' +
'}\n' +
';',
// -- output --
'var a = {\n' +
' a: 2\n' +
'};\n' +
'var a = {\n' +
' a: 2\n' +
'};');
bt(
'//case 1\n' +
'if (a == 1)\n' +
'{}\n' +
'//case 2\n' +
'else if (a == 2)\n' +
'{}',
// -- output --
'//case 1\n' +
'if (a == 1) {}\n' +
'//case 2\n' +
'else if (a == 2) {}');
bt(
'if(1)\n' +
'{\n' +
'2\n' +
'}\n' +
'else\n' +
'{\n' +
'3\n' +
'}',
// -- output --
'if (1) {\n' +
' 2\n' +
'} else {\n' +
' 3\n' +
'}');
bt(
'try\n' +
'{\n' +
'a();\n' +
'}\n' +
'catch(b)\n' +
'{\n' +
'c();\n' +
'}\n' +
'catch(d)\n' +
'{}\n' +
'finally\n' +
'{\n' +
'e();\n' +
'}',
// -- output --
'try {\n' +
' a();\n' +
'} catch (b) {\n' +
' c();\n' +
'} catch (d) {} finally {\n' +
' e();\n' +
'}');
//============================================================
// Comma-first option - (c0 = ",\n", c1 = ",\n ", c2 = ",\n ", c3 = ",\n ", f1 = " ,\n ")
reset_options();
opts.comma_first = false;
bt(
'{a:1, b:2}',
// -- output --
'{\n' +
' a: 1,\n' +
' b: 2\n' +
'}');
bt(
'var a=1, b=c[d], e=6;',
// -- output --
'var a = 1,\n' +
' b = c[d],\n' +
' e = 6;');
bt(
'for(var a=1,b=2,c=3;d<3;d++)\n' +
'e',
// -- output --
'for (var a = 1, b = 2, c = 3; d < 3; d++)\n' +
' e');
bt(
'for(var a=1,b=2,\n' +
'c=3;d<3;d++)\n' +
'e',
// -- output --
'for (var a = 1, b = 2,\n' +
' c = 3; d < 3; d++)\n' +
' e');
bt(
'function foo() {\n' +
' return [\n' +
' "one",\n' +
' "two"\n' +
' ];\n' +
'}');
bt(
'a=[[1,2],[4,5],[7,8]]',
// -- output --
'a = [\n' +
' [1, 2],\n' +
' [4, 5],\n' +
' [7, 8]\n' +
']');
bt(
'a=[[1,2],[4,5],[7,8],]',
// -- output --
'a = [\n' +
' [1, 2],\n' +
' [4, 5],\n' +
' [7, 8],\n' +
']');
bt(
'a=[[1,2],[4,5],function(){},[7,8]]',
// -- output --
'a = [\n' +
' [1, 2],\n' +
' [4, 5],\n' +
' function() {},\n' +
' [7, 8]\n' +
']');
bt(
'a=[[1,2],[4,5],function(){},function(){},[7,8]]',
// -- output --
'a = [\n' +
' [1, 2],\n' +
' [4, 5],\n' +
' function() {},\n' +
' function() {},\n' +
' [7, 8]\n' +
']');
bt(
'a=[[1,2],[4,5],function(){},[7,8]]',
// -- output --
'a = [\n' +
' [1, 2],\n' +
' [4, 5],\n' +
' function() {},\n' +
' [7, 8]\n' +
']');
bt('a=[b,c,function(){},function(){},d]', 'a = [b, c, function() {}, function() {}, d]');
bt(
'a=[b,c,\n' +
'function(){},function(){},d]',
// -- output --
'a = [b, c,\n' +
' function() {},\n' +
' function() {},\n' +
' d\n' +
']');
bt('a=[a[1],b[4],c[d[7]]]', 'a = [a[1], b[4], c[d[7]]]');
bt('[1,2,[3,4,[5,6],7],8]', '[1, 2, [3, 4, [5, 6], 7], 8]');
bt(
'[[["1","2"],["3","4"]],[["5","6","7"],["8","9","0"]],[["1","2","3"],["4","5","6","7"],["8","9","0"]]]',
// -- output --
'[\n' +
' [\n' +
' ["1", "2"],\n' +
' ["3", "4"]\n' +
' ],\n' +
' [\n' +
' ["5", "6", "7"],\n' +
' ["8", "9", "0"]\n' +
' ],\n' +
' [\n' +
' ["1", "2", "3"],\n' +
' ["4", "5", "6", "7"],\n' +
' ["8", "9", "0"]\n' +
' ]\n' +
']');
bt(
'changeCollection.add({\n' +
' name: "Jonathan" // New line inserted after this line on every save\n' +
' , age: 25\n' +
'});',
// -- output --
'changeCollection.add({\n' +
' name: "Jonathan" // New line inserted after this line on every save\n' +
' ,\n' +
' age: 25\n' +
'});');
bt(
'changeCollection.add(\n' +
' function() {\n' +
' return true;\n' +
' },\n' +
' function() {\n' +
' return true;\n' +
' }\n' +
');');
// Comma-first option - (c0 = "\n, ", c1 = "\n , ", c2 = "\n , ", c3 = "\n , ", f1 = ", ")
reset_options();
opts.comma_first = true;
bt(
'{a:1, b:2}',
// -- output --
'{\n' +
' a: 1\n' +
' , b: 2\n' +
'}');
bt(
'var a=1, b=c[d], e=6;',
// -- output --
'var a = 1\n' +
' , b = c[d]\n' +
' , e = 6;');
bt(
'for(var a=1,b=2,c=3;d<3;d++)\n' +
'e',
// -- output --
'for (var a = 1, b = 2, c = 3; d < 3; d++)\n' +
' e');
bt(
'for(var a=1,b=2,\n' +
'c=3;d<3;d++)\n' +
'e',
// -- output --
'for (var a = 1, b = 2\n' +
' , c = 3; d < 3; d++)\n' +
' e');
bt(
'function foo() {\n' +
' return [\n' +
' "one"\n' +
' , "two"\n' +
' ];\n' +
'}');
bt(
'a=[[1,2],[4,5],[7,8]]',
// -- output --
'a = [\n' +
' [1, 2]\n' +
' , [4, 5]\n' +
' , [7, 8]\n' +
']');
bt(
'a=[[1,2],[4,5],[7,8],]',
// -- output --
'a = [\n' +
' [1, 2]\n' +
' , [4, 5]\n' +
' , [7, 8]\n' +
', ]');
bt(
'a=[[1,2],[4,5],function(){},[7,8]]',
// -- output --
'a = [\n' +
' [1, 2]\n' +
' , [4, 5]\n' +
' , function() {}\n' +
' , [7, 8]\n' +
']');
bt(
'a=[[1,2],[4,5],function(){},function(){},[7,8]]',
// -- output --
'a = [\n' +
' [1, 2]\n' +
' , [4, 5]\n' +
' , function() {}\n' +
' , function() {}\n' +
' , [7, 8]\n' +
']');
bt(
'a=[[1,2],[4,5],function(){},[7,8]]',
// -- output --
'a = [\n' +
' [1, 2]\n' +
' , [4, 5]\n' +
' , function() {}\n' +
' , [7, 8]\n' +
']');
bt('a=[b,c,function(){},function(){},d]', 'a = [b, c, function() {}, function() {}, d]');
bt(
'a=[b,c,\n' +
'function(){},function(){},d]',
// -- output --
'a = [b, c\n' +
' , function() {}\n' +
' , function() {}\n' +
' , d\n' +
']');
bt('a=[a[1],b[4],c[d[7]]]', 'a = [a[1], b[4], c[d[7]]]');
bt('[1,2,[3,4,[5,6],7],8]', '[1, 2, [3, 4, [5, 6], 7], 8]');
bt(
'[[["1","2"],["3","4"]],[["5","6","7"],["8","9","0"]],[["1","2","3"],["4","5","6","7"],["8","9","0"]]]',
// -- output --
'[\n' +
' [\n' +
' ["1", "2"]\n' +
' , ["3", "4"]\n' +
' ]\n' +
' , [\n' +
' ["5", "6", "7"]\n' +
' , ["8", "9", "0"]\n' +
' ]\n' +
' , [\n' +
' ["1", "2", "3"]\n' +
' , ["4", "5", "6", "7"]\n' +
' , ["8", "9", "0"]\n' +
' ]\n' +
']');
bt(
'changeCollection.add({\n' +
' name: "Jonathan" // New line inserted after this line on every save\n' +
' , age: 25\n' +
'});');
bt(
'changeCollection.add(\n' +
' function() {\n' +
' return true;\n' +
' },\n' +
' function() {\n' +
' return true;\n' +
' }\n' +
');',
// -- output --
'changeCollection.add(\n' +
' function() {\n' +
' return true;\n' +
' }\n' +
' , function() {\n' +
' return true;\n' +
' }\n' +
');');
//============================================================
// Unindent chained functions - ()
reset_options();
opts.unindent_chained_methods = true;
bt(
'f().f().f()\n' +
' .f().f();',
// -- output --
'f().f().f()\n' +
'.f().f();');
bt(
'f()\n' +
' .f()\n' +
' .f();',
// -- output --
'f()\n' +
'.f()\n' +
'.f();');
bt(
'f(function() {\n' +
' f()\n' +
' .f()\n' +
' .f();\n' +
'});',
// -- output --
'f(function() {\n' +
' f()\n' +
' .f()\n' +
' .f();\n' +
'});');
//============================================================
// Space in parens tests - (s = "", e = "")
reset_options();
opts.space_in_paren = false;
opts.space_in_empty_paren = false;
bt('if(p) foo(a,b);', 'if (p) foo(a, b);');
bt(
'try{while(true){willThrow()}}catch(result)switch(result){case 1:++result }',
// -- output --
'try {\n' +
' while (true) {\n' +
' willThrow()\n' +
' }\n' +
'} catch (result) switch (result) {\n' +
' case 1:\n' +
' ++result\n' +
'}');
bt('((e/((a+(b)*c)-d))^2)*5;', '((e / ((a + (b) * c) - d)) ^ 2) * 5;');
bt(
'function f(a,b) {if(a) b()}function g(a,b) {if(!a) b()}',
// -- output --
'function f(a, b) {\n' +
' if (a) b()\n' +
'}\n' +
'\n' +
'function g(a, b) {\n' +
' if (!a) b()\n' +
'}');
bt('a=[];', 'a = [];');
bt('a=[b,c,d];', 'a = [b, c, d];');
bt('a= f[b];', 'a = f[b];');
bt(
'{\n' +
' files: [ {\n' +
' expand: true,\n' +
' cwd: "www/gui/",\n' +
' src: [ "im/design_standards/*.*" ],\n' +
' dest: "www/gui/build"\n' +
' } ]\n' +
'}',
// -- output --
'{\n' +
' files: [{\n' +
' expand: true,\n' +
' cwd: "www/gui/",\n' +
' src: ["im/design_standards/*.*"],\n' +
' dest: "www/gui/build"\n' +
' }]\n' +
'}');
// Space in parens tests - (s = "", e = "")
reset_options();
opts.space_in_paren = false;
opts.space_in_empty_paren = true;
bt('if(p) foo(a,b);', 'if (p) foo(a, b);');
bt(
'try{while(true){willThrow()}}catch(result)switch(result){case 1:++result }',
// -- output --
'try {\n' +
' while (true) {\n' +
' willThrow()\n' +
' }\n' +
'} catch (result) switch (result) {\n' +
' case 1:\n' +
' ++result\n' +
'}');
bt('((e/((a+(b)*c)-d))^2)*5;', '((e / ((a + (b) * c) - d)) ^ 2) * 5;');
bt(
'function f(a,b) {if(a) b()}function g(a,b) {if(!a) b()}',
// -- output --
'function f(a, b) {\n' +
' if (a) b()\n' +
'}\n' +
'\n' +
'function g(a, b) {\n' +
' if (!a) b()\n' +
'}');
bt('a=[];', 'a = [];');
bt('a=[b,c,d];', 'a = [b, c, d];');
bt('a= f[b];', 'a = f[b];');
bt(
'{\n' +
' files: [ {\n' +
' expand: true,\n' +
' cwd: "www/gui/",\n' +
' src: [ "im/design_standards/*.*" ],\n' +
' dest: "www/gui/build"\n' +
' } ]\n' +
'}',
// -- output --
'{\n' +
' files: [{\n' +
' expand: true,\n' +
' cwd: "www/gui/",\n' +
' src: ["im/design_standards/*.*"],\n' +
' dest: "www/gui/build"\n' +
' }]\n' +
'}');
// Space in parens tests - (s = " ", e = "")
reset_options();
opts.space_in_paren = true;
opts.space_in_empty_paren = false;
bt('if(p) foo(a,b);', 'if ( p ) foo( a, b );');
bt(
'try{while(true){willThrow()}}catch(result)switch(result){case 1:++result }',
// -- output --
'try {\n' +
' while ( true ) {\n' +
' willThrow()\n' +
' }\n' +
'} catch ( result ) switch ( result ) {\n' +
' case 1:\n' +
' ++result\n' +
'}');
bt('((e/((a+(b)*c)-d))^2)*5;', '( ( e / ( ( a + ( b ) * c ) - d ) ) ^ 2 ) * 5;');
bt(
'function f(a,b) {if(a) b()}function g(a,b) {if(!a) b()}',
// -- output --
'function f( a, b ) {\n' +
' if ( a ) b()\n' +
'}\n' +
'\n' +
'function g( a, b ) {\n' +
' if ( !a ) b()\n' +
'}');
bt('a=[];', 'a = [];');
bt('a=[b,c,d];', 'a = [ b, c, d ];');
bt('a= f[b];', 'a = f[ b ];');
bt(
'{\n' +
' files: [ {\n' +
' expand: true,\n' +
' cwd: "www/gui/",\n' +
' src: [ "im/design_standards/*.*" ],\n' +
' dest: "www/gui/build"\n' +
' } ]\n' +
'}');
// Space in parens tests - (s = " ", e = " ")
reset_options();
opts.space_in_paren = true;
opts.space_in_empty_paren = true;
bt('if(p) foo(a,b);', 'if ( p ) foo( a, b );');
bt(
'try{while(true){willThrow()}}catch(result)switch(result){case 1:++result }',
// -- output --
'try {\n' +
' while ( true ) {\n' +
' willThrow( )\n' +
' }\n' +
'} catch ( result ) switch ( result ) {\n' +
' case 1:\n' +
' ++result\n' +
'}');
bt('((e/((a+(b)*c)-d))^2)*5;', '( ( e / ( ( a + ( b ) * c ) - d ) ) ^ 2 ) * 5;');
bt(
'function f(a,b) {if(a) b()}function g(a,b) {if(!a) b()}',
// -- output --
'function f( a, b ) {\n' +
' if ( a ) b( )\n' +
'}\n' +
'\n' +
'function g( a, b ) {\n' +
' if ( !a ) b( )\n' +
'}');
bt('a=[];', 'a = [ ];');
bt('a=[b,c,d];', 'a = [ b, c, d ];');
bt('a= f[b];', 'a = f[ b ];');
bt(
'{\n' +
' files: [ {\n' +
' expand: true,\n' +
' cwd: "www/gui/",\n' +
' src: [ "im/design_standards/*.*" ],\n' +
' dest: "www/gui/build"\n' +
' } ]\n' +
'}');
//============================================================
// operator_position option - ensure no neswlines if preserve_newlines is false - ()
reset_options();
opts.operator_position = 'before-newline';
opts.preserve_newlines = false;
bt(
'var res = a + b - c / d * e % f;\n' +
'var res = g & h | i ^ j;\n' +
'var res = (k && l || m) ? n : o;\n' +
'var res = p >> q << r >>> s;\n' +
'var res = t === u !== v != w == x >= y <= z > aa < ab;\n' +
'ac + -ad');
bt(
'var res = a + b\n' +
'- c /\n' +
'd * e\n' +
'%\n' +
'f;\n' +
' var res = g & h\n' +
'| i ^\n' +
'j;\n' +
'var res = (k &&\n' +
'l\n' +
'|| m) ?\n' +
'n\n' +
': o\n' +
';\n' +
'var res = p\n' +
'>> q <<\n' +
'r\n' +
'>>> s;\n' +
'var res\n' +
' = t\n' +
'\n' +
' === u !== v\n' +
' !=\n' +
'w\n' +
'== x >=\n' +
'y <= z > aa <\n' +
'ab;\n' +
'ac +\n' +
'-ad',
// -- output --
'var res = a + b - c / d * e % f;\n' +
'var res = g & h | i ^ j;\n' +
'var res = (k && l || m) ? n : o;\n' +
'var res = p >> q << r >>> s;\n' +
'var res = t === u !== v != w == x >= y <= z > aa < ab;\n' +
'ac + -ad');
// operator_position option - ensure no neswlines if preserve_newlines is false - ()
reset_options();
opts.operator_position = 'after-newline';
opts.preserve_newlines = false;
bt(
'var res = a + b - c / d * e % f;\n' +
'var res = g & h | i ^ j;\n' +
'var res = (k && l || m) ? n : o;\n' +
'var res = p >> q << r >>> s;\n' +
'var res = t === u !== v != w == x >= y <= z > aa < ab;\n' +
'ac + -ad');
bt(
'var res = a + b\n' +
'- c /\n' +
'd * e\n' +
'%\n' +
'f;\n' +
' var res = g & h\n' +
'| i ^\n' +
'j;\n' +
'var res = (k &&\n' +
'l\n' +
'|| m) ?\n' +
'n\n' +
': o\n' +
';\n' +
'var res = p\n' +
'>> q <<\n' +
'r\n' +
'>>> s;\n' +
'var res\n' +
' = t\n' +
'\n' +
' === u !== v\n' +
' !=\n' +
'w\n' +
'== x >=\n' +
'y <= z > aa <\n' +
'ab;\n' +
'ac +\n' +
'-ad',
// -- output --
'var res = a + b - c / d * e % f;\n' +
'var res = g & h | i ^ j;\n' +
'var res = (k && l || m) ? n : o;\n' +
'var res = p >> q << r >>> s;\n' +
'var res = t === u !== v != w == x >= y <= z > aa < ab;\n' +
'ac + -ad');
// operator_position option - ensure no neswlines if preserve_newlines is false - ()
reset_options();
opts.operator_position = 'preserve-newline';
opts.preserve_newlines = false;
bt(
'var res = a + b - c / d * e % f;\n' +
'var res = g & h | i ^ j;\n' +
'var res = (k && l || m) ? n : o;\n' +
'var res = p >> q << r >>> s;\n' +
'var res = t === u !== v != w == x >= y <= z > aa < ab;\n' +
'ac + -ad');
bt(
'var res = a + b\n' +
'- c /\n' +
'd * e\n' +
'%\n' +
'f;\n' +
' var res = g & h\n' +
'| i ^\n' +
'j;\n' +
'var res = (k &&\n' +
'l\n' +
'|| m) ?\n' +
'n\n' +
': o\n' +
';\n' +
'var res = p\n' +
'>> q <<\n' +
'r\n' +
'>>> s;\n' +
'var res\n' +
' = t\n' +
'\n' +
' === u !== v\n' +
' !=\n' +
'w\n' +
'== x >=\n' +
'y <= z > aa <\n' +
'ab;\n' +
'ac +\n' +
'-ad',
// -- output --
'var res = a + b - c / d * e % f;\n' +
'var res = g & h | i ^ j;\n' +
'var res = (k && l || m) ? n : o;\n' +
'var res = p >> q << r >>> s;\n' +
'var res = t === u !== v != w == x >= y <= z > aa < ab;\n' +
'ac + -ad');
//============================================================
// operator_position option - set to 'before-newline' (default value)
reset_options();
// comprehensive, various newlines
bt(
'var res = a + b\n' +
'- c /\n' +
'd * e\n' +
'%\n' +
'f;\n' +
' var res = g & h\n' +
'| i ^\n' +
'j;\n' +
'var res = (k &&\n' +
'l\n' +
'|| m) ?\n' +
'n\n' +
': o\n' +
';\n' +
'var res = p\n' +
'>> q <<\n' +
'r\n' +
'>>> s;\n' +
'var res\n' +
' = t\n' +
'\n' +
' === u !== v\n' +
' !=\n' +
'w\n' +
'== x >=\n' +
'y <= z > aa <\n' +
'ab;\n' +
'ac +\n' +
'-ad',
// -- output --
'var res = a + b -\n' +
' c /\n' +
' d * e %\n' +
' f;\n' +
'var res = g & h |\n' +
' i ^\n' +
' j;\n' +
'var res = (k &&\n' +
' l ||\n' +
' m) ?\n' +
' n :\n' +
' o;\n' +
'var res = p >>\n' +
' q <<\n' +
' r >>>\n' +
' s;\n' +
'var res = t\n' +
'\n' +
' ===\n' +
' u !== v !=\n' +
' w ==\n' +
' x >=\n' +
' y <= z > aa <\n' +
' ab;\n' +
'ac +\n' +
' -ad');
// colon special case
bt(
'var a = {\n' +
' b\n' +
': bval,\n' +
' c:\n' +
'cval\n' +
' ,d: dval\n' +
'};\n' +
'var e = f ? g\n' +
': h;\n' +
'var i = j ? k :\n' +
'l;',
// -- output --
'var a = {\n' +
' b: bval,\n' +
' c: cval,\n' +
' d: dval\n' +
'};\n' +
'var e = f ? g :\n' +
' h;\n' +
'var i = j ? k :\n' +
' l;');
// catch-all, includes brackets and other various code
bt(
'var d = 1;\n' +
'if (a === b\n' +
' && c) {\n' +
' d = (c * everything\n' +
' / something_else) %\n' +
' b;\n' +
' e\n' +
' += d;\n' +
'\n' +
'} else if (!(complex && simple) ||\n' +
' (emotion && emotion.name === "happy")) {\n' +
' cryTearsOfJoy(many ||\n' +
' anOcean\n' +
' || aRiver);\n' +
'}',
// -- output --
'var d = 1;\n' +
'if (a === b &&\n' +
' c) {\n' +
' d = (c * everything /\n' +
' something_else) %\n' +
' b;\n' +
' e\n' +
' += d;\n' +
'\n' +
'} else if (!(complex && simple) ||\n' +
' (emotion && emotion.name === "happy")) {\n' +
' cryTearsOfJoy(many ||\n' +
' anOcean ||\n' +
' aRiver);\n' +
'}');
//============================================================
// operator_position option - set to 'after_newline'
reset_options();
opts.operator_position = 'after-newline';
// c