/script-kiddie/002_script_kiddie/script-kiddie/node_modules/js-beautify/test/data/html/tests.js |
@@ -0,0 +1,1105 @@ |
/* |
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. |
*/ |
|
exports.test_data = { |
default_options: [ |
{ name: "indent_size", value: "4" }, |
{ name: "indent_char", value: "' '" }, |
{ name: "indent_with_tabs", value: "false" }, |
{ name: "preserve_newlines", value: "true" }, |
{ name: "jslint_happy", value: "false" }, |
{ name: "keep_array_indentation", value: "false" }, |
{ name: "brace_style", value: "'collapse'" }, |
{ name: "extra_liners", value: "['html', 'head', '/html']" } |
], |
groups: [{ |
name: "Handle inline and block elements differently", |
description: "", |
matrix: [{}], |
tests: [{ |
fragment: true, |
input: '<body><h1>Block</h1></body>', |
output: [ |
'<body>', |
' <h1>Block</h1>', |
'</body>' |
] |
}, { |
fragment: true, |
unchanged: '<body><i>Inline</i></body>' |
}] |
}, { |
name: "End With Newline", |
description: "", |
matrix: [{ |
options: [ |
{ name: "end_with_newline", value: "true" } |
], |
eof: '\n' |
}, { |
options: [ |
{ name: "end_with_newline", value: "false" } |
], |
eof: '' |
} |
|
], |
tests: [ |
{ fragment: true, input: '', output: '{{eof}}' }, |
{ fragment: true, input: '<div></div>', output: '<div></div>{{eof}}' }, |
// { fragment: true, input: ' \n\n<div></div>\n\n\n\n', output: ' <div></div>{{eof}}' }, |
{ fragment: true, input: '\n', output: '{{eof}}' } |
], |
}, { |
name: "Custom Extra Liners (empty)", |
description: "", |
matrix: [{ |
options: [ |
{ 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>' |
}], |
}, { |
name: "Custom Extra Liners (default)", |
description: "", |
matrix: [{ |
options: [ |
{ 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>' |
}], |
}, { |
name: "Custom Extra Liners (p, string)", |
description: "", |
matrix: [{ |
options: [ |
{ 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>' |
}], |
}, { |
name: "Custom Extra Liners (p)", |
description: "", |
matrix: [{ |
options: [ |
{ 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>' |
}], |
}, { |
name: "Tests for script and style types (issue 453, 821)", |
description: "Only format recognized script types", |
tests: [{ |
input: '<script type="text/unknown"><div></div></script>', |
output: [ |
'<script type="text/unknown">', |
' <div></div>', |
'</script>' |
] |
}, { |
input: '<script type="text/javascript"><div></div></script>', |
output: [ |
'<script type="text/javascript">', |
' < div > < /div>', |
'</script>' |
] |
}, { |
input: '<script><div></div></script>', |
output: [ |
'<script>', |
' < div > < /div>', |
'</script>' |
] |
}, { |
input: '<script>var foo = "bar";</script>', |
output: [ |
'<script>', |
' var foo = "bar";', |
'</script>' |
] |
}, { |
input: '<script type="text/javascript">var foo = "bar";</script>', |
output: [ |
'<script type="text/javascript">', |
' var foo = "bar";', |
'</script>' |
] |
}, { |
input: '<script type="application/javascript">var foo = "bar";</script>', |
output: [ |
'<script type="application/javascript">', |
' var foo = "bar";', |
'</script>' |
] |
}, { |
input: '<script type="application/javascript;version=1.8">var foo = "bar";</script>', |
output: [ |
'<script type="application/javascript;version=1.8">', |
' var foo = "bar";', |
'</script>' |
] |
}, { |
input: '<script type="application/x-javascript">var foo = "bar";</script>', |
output: [ |
'<script type="application/x-javascript">', |
' var foo = "bar";', |
'</script>' |
] |
}, { |
input: '<script type="application/ecmascript">var foo = "bar";</script>', |
output: [ |
'<script type="application/ecmascript">', |
' var foo = "bar";', |
'</script>' |
] |
}, { |
input: '<script type="dojo/aspect">this.domNode.style.display="none";</script>', |
output: [ |
'<script type="dojo/aspect">', |
' this.domNode.style.display = "none";', |
'</script>' |
] |
}, { |
input: '<script type="dojo/method">this.domNode.style.display="none";</script>', |
output: [ |
'<script type="dojo/method">', |
' this.domNode.style.display = "none";', |
'</script>' |
] |
}, { |
input: '<script type="text/javascript1.5">var foo = "bar";</script>', |
output: [ |
'<script type="text/javascript1.5">', |
' var foo = "bar";', |
'</script>' |
] |
}, { |
input: '<script type="application/json">{"foo":"bar"}</script>', |
output: [ |
'<script type="application/json">', |
' {', |
' "foo": "bar"', |
' }', |
'</script>' |
] |
}, { |
input: '<script type="application/ld+json">{"foo":"bar"}</script>', |
output: [ |
'<script type="application/ld+json">', |
' {', |
' "foo": "bar"', |
' }', |
'</script>' |
] |
}, { |
input: '<style type="text/unknown"><tag></tag></style>', |
output: [ |
'<style type="text/unknown">', |
' <tag></tag>', |
'</style>' |
] |
}, { |
input: '<style type="text/css"><tag></tag></style>', |
output: [ |
'<style type="text/css">', |
' <tag></tag>', |
'</style>' |
] |
}, { |
input: '<style><tag></tag></style>', |
output: [ |
'<style>', |
' <tag></tag>', |
'</style>' |
] |
}, { |
input: '<style>.selector {font-size:12px;}</style>', |
output: [ |
'<style>', |
' .selector {', |
' font-size: 12px;', |
' }', |
'</style>' |
] |
}, { |
input: '<style type="text/css">.selector {font-size:12px;}</style>', |
output: [ |
'<style type="text/css">', |
' .selector {', |
' font-size: 12px;', |
' }', |
'</style>' |
] |
}, |
|
], |
}, { |
name: "Attribute Wrap alignment with spaces", |
description: "Ensure attributes are internally aligned with spaces when the indent_character is set to tab", |
matrix: [{ |
options: [ |
{ name: "wrap_attributes", value: "'force-aligned'" }, |
{ name: "indent_with_tabs", value: "true" } |
] |
}], |
tests: [{ |
fragment: true, |
input: '<div><div a="1" b="2"><div>test</div></div></div>', |
output: '<div>\n\t<div a="1"\n\t b="2">\n\t\t<div>test</div>\n\t</div>\n</div>' |
}] |
}, { |
name: "Attribute Wrap de-indent", |
description: "Tags de-indent when attributes are wrapped", |
matrix: [{ |
options: [ |
{ name: "wrap_attributes", value: "'force-aligned'" }, |
{ name: "indent_with_tabs", value: "false" } |
] |
}], |
tests: [{ |
fragment: true, |
input: '<div a="1" b="2"><div>test</div></div>', |
output: '<div a="1"\n b="2">\n <div>test</div>\n</div>' |
}, |
{ |
fragment: true, |
input: '<p>\n <a href="/test/" target="_blank"><img src="test.jpg" /></a><a href="/test/" target="_blank"><img src="test.jpg" /></a>\n</p>', |
output: '<p>\n <a href="/test/"\n target="_blank"><img src="test.jpg" /></a><a href="/test/"\n target="_blank"><img src="test.jpg" /></a>\n</p>' |
}, |
{ |
fragment: true, |
input: '<p>\n <span data-not-a-href="/test/" data-totally-not-a-target="_blank"><img src="test.jpg" /></span><span data-not-a-href="/test/" data-totally-not-a-target="_blank"><img src="test.jpg" /></span>\n</p>', |
output: '<p>\n <span data-not-a-href="/test/"\n data-totally-not-a-target="_blank"><img src="test.jpg" /></span><span data-not-a-href="/test/"\n data-totally-not-a-target="_blank"><img src="test.jpg" /></span>\n</p>' |
} |
] |
}, { |
name: "Attribute Wrap", |
description: "Wraps attributes inside of html tags", |
matrix: [{ |
options: [ |
{ name: "wrap_attributes", value: "'force'" } |
], |
indent_attr: '\n ', |
indent_attr_first: ' ', |
indent_end: '', |
indent_end_selfclosing: ' ', |
indent_over80: '\n ' |
}, { |
options: [ |
{ name: "wrap_attributes", value: "'force'" }, |
{ name: "wrap_line_length", value: "80" } |
], |
indent_attr: '\n ', |
indent_attr_first: ' ', |
indent_end: '', |
indent_end_selfclosing: ' ', |
indent_over80: '\n ' |
}, { |
options: [ |
{ name: "wrap_attributes", value: "'force'" }, |
{ name: "wrap_attributes_indent_size", value: "8" } |
], |
indent_attr: '\n ', |
indent_attr_first: ' ', |
indent_end: '', |
indent_end_selfclosing: ' ', |
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_attr_first: ' ', |
indent_end: '', |
indent_end_selfclosing: ' ', |
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_attr_first: ' ', |
indent_end: '', |
indent_end_selfclosing: ' ', |
indent_over80: '\n ' |
}, { |
options: [ |
{ name: "wrap_attributes", value: "'auto'" }, |
{ name: "wrap_line_length", value: "0" } |
], |
indent_attr: ' ', |
indent_attr_first: ' ', |
indent_end: '', |
indent_end_selfclosing: ' ', |
indent_over80: ' ' |
}, { |
options: [ |
{ name: "wrap_attributes", value: "'force-aligned'" } |
], |
indent_attr: '\n ', |
indent_attr_faligned: ' ', |
indent_attr_first: ' ', |
indent_end: '', |
indent_end_selfclosing: ' ', |
indent_over80: '\n ' |
}, { |
options: [ |
{ name: "wrap_attributes", value: "'force-aligned'" }, |
{ name: "wrap_line_length", value: "80" } |
], |
indent_attr: '\n ', |
indent_attr_faligned: ' ', |
indent_attr_first: ' ', |
indent_end: '', |
indent_end_selfclosing: ' ', |
indent_over80: '\n ' |
}, { |
options: [ |
{ name: "wrap_attributes", value: "'force-aligned'" }, |
{ name: "wrap_attributes_indent_size", value: "8" } |
], |
indent_attr: '\n ', |
indent_attr_faligned: ' ', |
indent_attr_first: ' ', |
indent_end: '', |
indent_end_selfclosing: ' ', |
indent_over80: '\n ' |
}, { |
options: [ |
{ name: "wrap_attributes", value: "'force-expand-multiline'" }, |
{ name: "wrap_attributes_indent_size", value: "4" } |
], |
indent_attr: '\n ', |
indent_attr_first: '\n ', |
indent_end: '\n', |
indent_end_selfclosing: '\n', |
indent_over80: '\n ' |
}, { |
options: [ |
{ name: "wrap_attributes", value: "'force-expand-multiline'" }, |
{ name: "wrap_attributes_indent_size", value: "4" }, |
{ name: "wrap_line_length", value: "80" } |
], |
indent_attr: '\n ', |
indent_attr_first: '\n ', |
indent_end: '\n', |
indent_end_selfclosing: '\n', |
indent_over80: '\n ' |
}, { |
options: [ |
{ name: "wrap_attributes", value: "'force-expand-multiline'" }, |
{ name: "wrap_attributes_indent_size", value: "8" } |
], |
indent_attr: '\n ', |
indent_attr_first: '\n ', |
indent_end: '\n', |
indent_end_selfclosing: '\n', |
indent_over80: '\n ' |
}], |
tests: [{ |
fragment: true, |
input: '<div >This is some text</div>', |
output: '<div>This is some text</div>' |
}, { |
fragment: true, |
input: '<div attr="123" >This is some text</div>', |
output: '<div attr="123">This is some text</div>' |
}, { |
fragment: true, |
input: '<div attr0 attr1="123" data-attr2="hello t here">This is some text</div>', |
output: '<div{{indent_attr_first}}attr0{{indent_attr}}attr1="123"{{indent_attr}}data-attr2="hello t here"{{indent_end}}>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{{indent_attr_first}}lookatthissuperduperlongattributenamewhoahcrazy0="true"{{indent_attr}}attr0{{indent_attr}}attr1="123"{{indent_attr}}data-attr2="hello t here"{{indent_over80}}heymanimreallylongtoowhocomesupwiththesenames="false"{{indent_end}}>This is some text</div>' |
}, { |
fragment: true, |
input: '<img attr0 attr1="123" data-attr2="hello t here"/>', |
output: '<img{{indent_attr_first}}attr0{{indent_attr}}attr1="123"{{indent_attr}}data-attr2="hello t here"{{indent_end_selfclosing}}/>' |
}, { |
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{{indent_attr_first}}attr1="foo"{{indent_attr}}{{indent_attr_faligned}}attr2="bar"{{indent_end_selfclosing}}/>' |
}, { |
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{{indent_attr_first}}href="//fonts.googleapis.com/css?family=Open+Sans:300italic,400italic,600italic,700italic,400,600,700,300&subset=latin"{{indent_over80}}{{indent_attr_faligned}}rel="stylesheet"{{indent_attr}}{{indent_attr_faligned}}type="text/css"{{indent_end}}>' |
}] |
}, { |
name: "Handlebars Indenting Off", |
description: "Test handlebar behavior when indenting is off", |
template: "^^^ $$$", |
options: [ |
{ name: "indent_handlebars", value: "false" } |
], |
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>' |
} |
|
] |
}, { |
name: "Handlebars Indenting On", |
description: "Test handlebar formatting", |
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: '{{!-- 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}}' |
}, { |
options: [ |
{ name: "indent_handlebars", value: "true" } |
], |
content: '{{!-- \n mult-line\ncomment \n with spacing\n--}}' |
}, { |
options: [ |
{ name: "indent_handlebars", value: "true" } |
], |
content: '{{!-- \n mult-line\ncomment \n{{#> component}}\n mult-line\ncomment \n with spacing\n {{/ component}}--}}' |
}, { |
options: [ |
{ name: "indent_handlebars", value: "true" }, |
{ name: "wrap_line_length", value: "80" } |
], |
content: 'content' |
}], |
tests: [ |
{ fragment: true, unchanged: '{{page-title}}' }, |
{ fragment: true, unchanged: '{{#if 0}}{{/if}}' }, |
{ fragment: true, unchanged: '{{#if 0}}^^^&content$$${{/if}}' }, |
{ fragment: true, unchanged: '{{#if 0}}\n{{/if}}' }, { |
fragment: true, |
input_: '{{#if words}}{{/if}}', |
output: '{{#if words}}{{/if}}' |
}, { |
fragment: true, |
input_: '{{#if words}}^^^&content$$${{/if}}', |
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}}' |
}, |
|
// 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, |
input_: '<div{{somestyle}}></div>', |
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, |
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, |
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>' |
}, |
|
// 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: '<span>{{condition < 0 ? "result1" : "result2"}}</span>' |
}, { |
fragment: true, |
unchanged: '<span>{{condition1 && condition2 && condition3 && condition4 < 0 ? "resForTrue" : "resForFalse"}}</span>' |
} |
], |
}, { |
name: "Handlebars Else tag indenting", |
description: "Handlebar Else tags should be newlined after formatted tags", |
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: "Unclosed html elements", |
description: "Unclosed elements should not indent", |
options: [], |
tests: [ |
{ fragment: true, unchanged: '<source>\n<source>' }, |
{ fragment: true, unchanged: '<br>\n<br>' }, |
{ fragment: true, unchanged: '<input>\n<input>' }, |
{ fragment: true, unchanged: '<meta>\n<meta>' }, |
{ fragment: true, unchanged: '<link>\n<link>' }, |
{ fragment: true, unchanged: '<colgroup>\n <col>\n <col>\n</colgroup>' } |
] |
}, { |
name: "Unformatted tags", |
description: "Unformatted tag behavior", |
options: [], |
tests: [{ |
fragment: true, |
input: '<ol>\n <li>b<pre>c</pre></li>\n</ol>', |
output: [ |
'<ol>', |
' <li>b', |
' <pre>c</pre>', |
' </li>', |
'</ol>' |
] |
}, |
{ fragment: true, unchanged: '<ol>\n <li>b<code>c</code></li>\n</ol>' }, |
{ fragment: true, unchanged: '<ul>\n <li>\n <span class="octicon octicon-person"></span>\n <a href="/contact/">Kontakt</a>\n </li>\n</ul>' }, |
{ fragment: true, unchanged: '<div class="searchform"><input type="text" value="" name="s" id="s" /><input type="submit" id="searchsubmit" value="Search" /></div>' }, |
{ fragment: true, unchanged: '<div class="searchform"><input type="text" value="" name="s" id="s"><input type="submit" id="searchsubmit" value="Search"></div>' }, |
{ fragment: true, unchanged: '<p>\n <a href="/test/"><img src="test.jpg" /></a>\n</p>' }, |
{ fragment: true, unchanged: '<p>\n <a href="/test/"><img src="test.jpg" /></a><a href="/test/"><img src="test.jpg" /></a>\n</p>' }, |
{ fragment: true, unchanged: '<p>\n <a href="/test/"><img src="test.jpg" /></a><a href="/test/"><img src="test.jpg" /></a><a href="/test/"><img src="test.jpg" /></a><a href="/test/"><img src="test.jpg" /></a>\n</p>' }, |
{ fragment: true, unchanged: '<p>\n <span>image: <img src="test.jpg" /></span><span>image: <img src="test.jpg" /></span>\n</p>' }, |
{ fragment: true, unchanged: '<p>\n <strong>image: <img src="test.jpg" /></strong><strong>image: <img src="test.jpg" /></strong>\n</p>' }, |
] |
}, { |
name: "File starting with comment", |
description: "Unformatted tag behavior", |
options: [], |
tests: [{ |
fragment: true, |
unchanged: [ |
'<!--sample comment -->', |
'', |
'<html>', |
'<body>', |
' <span>a span</span>', |
'</body>', |
'', |
'</html>' |
] |
}, ] |
}, { |
name: "Php formatting", |
description: "Php (<?php ... ?>) treated as comments.", |
options: [], |
tests: [{ |
fragment: true, |
input: '<h1 class="content-page-header"><?=$view["name"]; ?></h1>', |
output: '<h1 class="content-page-header">\n <?=$view["name"]; ?>\n</h1>', |
}, { |
fragment: true, |
unchanged: [ |
'<?php', |
'for($i = 1; $i <= 100; $i++;) {', |
' #count to 100!', |
' echo($i . "</br>");', |
'}', |
'?>' |
] |
}, { |
fragment: true, |
unchanged: [ |
'<?php ?>', |
'<!DOCTYPE html>', |
'', |
'<html>', |
'', |
'<head></head>', |
'', |
'<body></body>', |
'', |
'</html>' |
] |
}] |
}, { |
name: "Support simple language specific option inheritance/overriding", |
description: "Support simple language specific option inheritance/overriding", |
matrix: [{ |
options: [ |
{ name: "js", value: "{ 'indent_size': 3 }" }, |
{ name: "css", value: "{ 'indent_size': 5 }" } |
], |
h: ' ', |
c: ' ', |
j: ' ' |
}, |
{ |
options: [ |
{ name: "html", value: "{ 'js': { 'indent_size': 3 }, 'css': { 'indent_size': 5 } }" } |
], |
h: ' ', |
c: ' ', |
j: ' ' |
}, |
{ |
options: [ |
{ name: "indent_size", value: "9" }, |
{ name: "html", value: "{ 'js': { 'indent_size': 3 }, 'css': { 'indent_size': 5 }, 'indent_size': 2}" }, |
{ name: "js", value: "{ 'indent_size': 5 }" }, |
{ name: "css", value: "{ 'indent_size': 3 }" } |
], |
h: ' ', |
c: ' ', |
j: ' ' |
} |
], |
tests: [{ |
fragment: true, |
unchanged: [ |
'<head>', |
'{{h}}<script>', |
'{{h}}{{h}}if (a == b) {', |
'{{h}}{{h}}{{j}}test();', |
'{{h}}{{h}}}', |
'{{h}}</script>', |
'{{h}}<style>', |
'{{h}}{{h}}.selector {', |
'{{h}}{{h}}{{c}}font-size: 12px;', |
'{{h}}{{h}}}', |
'{{h}}</style>', |
'</head>', |
] |
}, ] |
}, { |
name: "underscore.js formatting", |
description: "underscore.js templates (<% ... %>) treated as comments.", |
options: [], |
tests: [{ |
fragment: true, |
unchanged: [ |
'<div class="col-sm-9">', |
' <textarea id="notes" class="form-control" rows="3">', |
' <%= notes %>', |
' </textarea>', |
'</div>' |
] |
}, ] |
}, { |
name: "Indent with tabs", |
description: "Use one tab instead of several spaces for indentation", |
template: "^^^ $$$", |
options: [ |
{ name: "indent_with_tabs", value: "true" } |
], |
tests: [{ |
fragment: true, |
input_: '<div>\n' + |
'<div>\n' + |
'</div>\n' + |
'</div>', |
output: '<div>\n' + |
'\t<div>\n' + |
'\t</div>\n' + |
'</div>' |
}] |
}, { |
name: "Indent without tabs", |
description: "Use several spaces for indentation", |
template: "^^^ $$$", |
options: [ |
{ name: "indent_with_tabs", value: "false" } |
], |
tests: [{ |
fragment: true, |
input_: '<div>\n' + |
'<div>\n' + |
'</div>\n' + |
'</div>', |
output: '<div>\n' + |
' <div>\n' + |
' </div>\n' + |
'</div>' |
}] |
}, { |
name: "Indent body inner html by default", |
description: "", |
tests: [{ |
fragment: true, |
input: '<html>\n<body>\n<div></div>\n</body>\n\n</html>', |
output: '<html>\n<body>\n <div></div>\n</body>\n\n</html>' |
}] |
}, { |
name: "indent_body_inner_html set to false prevents indent of body inner html", |
description: "", |
options: [ |
{ name: 'indent_body_inner_html', value: "false" } |
], |
tests: [{ |
fragment: true, |
unchanged: '<html>\n<body>\n<div></div>\n</body>\n\n</html>' |
}] |
}, { |
name: "Indent head inner html by default", |
description: "", |
tests: [{ |
fragment: true, |
input: '<html>\n\n<head>\n<meta>\n</head>\n\n</html>', |
output: '<html>\n\n<head>\n <meta>\n</head>\n\n</html>' |
}] |
}, { |
name: "indent_head_inner_html set to false prevents indent of head inner html", |
description: "", |
options: [ |
{ name: 'indent_head_inner_html', value: "false" } |
], |
tests: [{ |
fragment: true, |
unchanged: '<html>\n\n<head>\n<meta>\n</head>\n\n</html>' |
}] |
}, { |
name: "content_unformatted to prevent formatting content", |
description: "", |
options: [ |
{ name: 'content_unformatted', value: "['script', 'style', 'p', 'span', 'br']" } |
], |
tests: [{ |
fragment: true, |
input: '<html><body><h1>A</h1><script>if(1){f();}</script><style>.a{display:none;}</style></body></html>', |
output: [ |
'<html>', |
'<body>', |
' <h1>A</h1>', |
' <script>if(1){f();}</script>', |
' <style>.a{display:none;}</style>', |
'</body>', |
'', |
'</html>' |
] |
}, { |
fragment: true, |
input: '<div><p>Beautify me</p></div><p><p>But not me</p></p>', |
output: [ |
'<div>', |
' <p>Beautify me</p>', |
'</div>', |
'<p><p>But not me</p></p>' |
] |
}, { |
fragment: true, |
input: '<div><p\n class="beauty-me"\n>Beautify me</p></div><p><p\n class="iamalreadybeauty"\n>But not me</p></p>', |
output: [ |
'<div>', |
' <p class="beauty-me">Beautify me</p>', |
'</div>', |
'<p><p', |
' class="iamalreadybeauty"', |
'>But not me</p></p>' |
] |
}, { |
fragment: true, |
unchanged: '<div><span>blabla<div>something here</div></span></div>' |
}, { |
fragment: true, |
unchanged: '<div><br /></div>' |
}, { |
fragment: true, |
input: '<div><pre>var a=1;\nvar b=a;</pre></div>', |
output: [ |
'<div>', |
' <pre>var a=1; var b=a;</pre>', |
'</div>' |
] |
}, { |
fragment: true, |
input: '<div><pre>\nvar a=1;\nvar b=a;\n</pre></div>', |
output: [ |
'<div>', |
' <pre>', |
' var a=1; var b=a;', |
' </pre>', |
'</div>' |
] |
}] |
}, { |
name: "default content_unformatted", |
description: "", |
options: [], |
tests: [{ |
fragment: true, |
input: '<html><body><h1>A</h1><script>if(1){f();}</script><style>.a{display:none;}</style></body></html>', |
output: [ |
'<html>', |
'<body>', |
' <h1>A</h1>', |
' <script>', |
' if (1) {', |
' f();', |
' }', |
' </script>', |
' <style>', |
' .a {', |
' display: none;', |
' }', |
' </style>', |
'</body>', |
'', |
'</html>' |
] |
}, { |
fragment: true, |
input: '<div><p>Beautify me</p></div><p><p>But not me</p></p>', |
output: [ |
'<div>', |
' <p>Beautify me</p>', |
'</div>', |
'<p>', |
' <p>But not me</p>', |
'</p>', |
] |
}, { |
fragment: true, |
input: '<div><p\n class="beauty-me"\n>Beautify me</p></div><p><p\n class="iamalreadybeauty"\n>But not me</p></p>', |
output: [ |
'<div>', |
' <p class="beauty-me">Beautify me</p>', |
'</div>', |
'<p>', |
' <p class="iamalreadybeauty">But not me</p>', |
'</p>' |
] |
}, { |
fragment: true, |
unchanged: '<div><span>blabla<div>something here</div></span></div>' |
}, { |
fragment: true, |
unchanged: '<div><br /></div>' |
}, { |
fragment: true, |
input: '<div><pre>var a=1;\nvar b=a;</pre></div>', |
output: [ |
'<div>', |
' <pre>var a=1;', |
'var b=a;</pre>', |
'</div>' |
] |
}, { |
fragment: true, |
input: '<div><pre>\nvar a=1;\nvar b=a;\n</pre></div>', |
output: [ |
'<div>', |
' <pre>', |
'var a=1;', |
'var b=a;', |
'</pre>', |
'</div>' |
] |
}] |
}, { |
name: "New Test Suite" |
}], |
}; |
/script-kiddie/002_script_kiddie/script-kiddie/node_modules/js-beautify/test/data/javascript/node.mustache |
@@ -0,0 +1,1114 @@ |
/* |
{{&header_text}} |
|
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_options}} default_opts.{{name}} = {{&value}}; |
{{/default_options}} |
|
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; |
|
{{#groups}}{{#set_mustache_tags}}.{{/set_mustache_tags}} |
//============================================================ |
{{^matrix}} |
// {{&name}} |
reset_options(); |
{{#options}} |
opts.{{name}} = {{&value}}; |
{{/options}} |
{{#tests}} |
{{#test_line}}.{{/test_line}}; |
{{/tests}} |
|
{{/matrix}} |
{{#matrix}} |
// {{&name}} - ({{#matrix_context_string}}.{{/matrix_context_string}}) |
reset_options(); |
{{#options}} |
opts.{{name}} = {{&value}}; |
{{/options}} |
{{#tests}} |
{{#test_line}}.{{/test_line}}; |
{{/tests}} |
|
{{/matrix}} |
{{#unset_mustache_tags}}.{{/unset_mustache_tags}}{{/groups}} |
} |
|
function beautifier_unconverted_tests() |
{ |
sanitytest = test_obj; |
|
reset_options(); |
//============================================================ |
opts.indent_size = 1; |
opts.indent_char = ' '; |
bt('{ one_char() }', "{\n one_char()\n}"); |
|
bt('var a,b=1,c=2', 'var a, b = 1,\n c = 2'); |
|
opts.indent_size = 4; |
opts.indent_char = ' '; |
bt('{ one_char() }', "{\n one_char()\n}"); |
|
opts.indent_size = 1; |
opts.indent_char = "\t"; |
bt('{ one_char() }', "{\n\tone_char()\n}"); |
bt('x = a ? b : c; x;', 'x = a ? b : c;\nx;'); |
|
//set to something else than it should change to, but with tabs on, should override |
opts.indent_size = 5; |
opts.indent_char = ' '; |
opts.indent_with_tabs = true; |
|
bt('{ one_char() }', "{\n\tone_char()\n}"); |
bt('x = a ? b : c; x;', 'x = a ? b : c;\nx;'); |
|
opts.indent_size = 4; |
opts.indent_char = ' '; |
opts.indent_with_tabs = false; |
|
reset_options(); |
//============================================================ |
opts.preserve_newlines = false; |
|
bt('var\na=dont_preserve_newlines;', 'var a = dont_preserve_newlines;'); |
|
// make sure the blank line between function definitions stays |
// even when preserve_newlines = false |
bt('function foo() {\n return 1;\n}\n\nfunction foo() {\n return 1;\n}'); |
bt('function foo() {\n return 1;\n}\nfunction foo() {\n return 1;\n}', |
'function foo() {\n return 1;\n}\n\nfunction foo() {\n return 1;\n}' |
); |
bt('function foo() {\n return 1;\n}\n\n\nfunction foo() {\n return 1;\n}', |
'function foo() {\n return 1;\n}\n\nfunction foo() {\n return 1;\n}' |
); |
|
opts.preserve_newlines = true; |
bt('var\na=do_preserve_newlines;', 'var\n a = do_preserve_newlines;'); |
bt('if (foo) // comment\n{\n bar();\n}'); |
|
|
reset_options(); |
//============================================================ |
opts.keep_array_indentation = false; |
bt("a = ['a', 'b', 'c',\n 'd', 'e', 'f']", |
"a = ['a', 'b', 'c',\n 'd', 'e', 'f'\n]"); |
bt("a = ['a', 'b', 'c',\n 'd', 'e', 'f',\n 'g', 'h', 'i']", |
"a = ['a', 'b', 'c',\n 'd', 'e', 'f',\n 'g', 'h', 'i'\n]"); |
bt("a = ['a', 'b', 'c',\n 'd', 'e', 'f',\n 'g', 'h', 'i']", |
"a = ['a', 'b', 'c',\n 'd', 'e', 'f',\n 'g', 'h', 'i'\n]"); |
bt('var x = [{}\n]', 'var x = [{}]'); |
bt('var x = [{foo:bar}\n]', 'var x = [{\n foo: bar\n}]'); |
bt("a = ['something',\n 'completely',\n 'different'];\nif (x);", |
"a = ['something',\n 'completely',\n 'different'\n];\nif (x);"); |
bt("a = ['a','b','c']", "a = ['a', 'b', 'c']"); |
|
bt("a = ['a', 'b','c']", "a = ['a', 'b', 'c']"); |
bt("x = [{'a':0}]", |
"x = [{\n 'a': 0\n}]"); |
bt('{a([[a1]], {b;});}', |
'{\n a([\n [a1]\n ], {\n b;\n });\n}'); |
bt("a();\n [\n ['sdfsdfsd'],\n ['sdfsdfsdf']\n ].toString();", |
"a();\n[\n ['sdfsdfsd'],\n ['sdfsdfsdf']\n].toString();"); |
bt("a();\na = [\n ['sdfsdfsd'],\n ['sdfsdfsdf']\n ].toString();", |
"a();\na = [\n ['sdfsdfsd'],\n ['sdfsdfsdf']\n].toString();"); |
bt("function() {\n Foo([\n ['sdfsdfsd'],\n ['sdfsdfsdf']\n ]);\n}", |
"function() {\n Foo([\n ['sdfsdfsd'],\n ['sdfsdfsdf']\n ]);\n}"); |
bt('function foo() {\n return [\n "one",\n "two"\n ];\n}'); |
// 4 spaces per indent input, processed with 4-spaces per indent |
bt( "function foo() {\n" + |
" return [\n" + |
" {\n" + |
" one: 'x',\n" + |
" two: [\n" + |
" {\n" + |
" id: 'a',\n" + |
" name: 'apple'\n" + |
" }, {\n" + |
" id: 'b',\n" + |
" name: 'banana'\n" + |
" }\n" + |
" ]\n" + |
" }\n" + |
" ];\n" + |
"}", |
"function foo() {\n" + |
" return [{\n" + |
" one: 'x',\n" + |
" two: [{\n" + |
" id: 'a',\n" + |
" name: 'apple'\n" + |
" }, {\n" + |
" id: 'b',\n" + |
" name: 'banana'\n" + |
" }]\n" + |
" }];\n" + |
"}"); |
// 3 spaces per indent input, processed with 4-spaces per indent |
bt( "function foo() {\n" + |
" return [\n" + |
" {\n" + |
" one: 'x',\n" + |
" two: [\n" + |
" {\n" + |
" id: 'a',\n" + |
" name: 'apple'\n" + |
" }, {\n" + |
" id: 'b',\n" + |
" name: 'banana'\n" + |
" }\n" + |
" ]\n" + |
" }\n" + |
" ];\n" + |
"}", |
"function foo() {\n" + |
" return [{\n" + |
" one: 'x',\n" + |
" two: [{\n" + |
" id: 'a',\n" + |
" name: 'apple'\n" + |
" }, {\n" + |
" id: 'b',\n" + |
" name: 'banana'\n" + |
" }]\n" + |
" }];\n" + |
"}"); |
|
opts.keep_array_indentation = true; |
bt("a = ['a', 'b', 'c',\n 'd', 'e', 'f']"); |
bt("a = ['a', 'b', 'c',\n 'd', 'e', 'f',\n 'g', 'h', 'i']"); |
bt("a = ['a', 'b', 'c',\n 'd', 'e', 'f',\n 'g', 'h', 'i']"); |
bt('var x = [{}\n]', 'var x = [{}\n]'); |
bt('var x = [{foo:bar}\n]', 'var x = [{\n foo: bar\n }\n]'); |
bt("a = ['something',\n 'completely',\n 'different'];\nif (x);"); |
bt("a = ['a','b','c']", "a = ['a', 'b', 'c']"); |
bt("a = ['a', 'b','c']", "a = ['a', 'b', 'c']"); |
bt("x = [{'a':0}]", |
"x = [{\n 'a': 0\n}]"); |
bt('{a([[a1]], {b;});}', |
'{\n a([[a1]], {\n b;\n });\n}'); |
bt("a();\n [\n ['sdfsdfsd'],\n ['sdfsdfsdf']\n ].toString();", |
"a();\n [\n ['sdfsdfsd'],\n ['sdfsdfsdf']\n ].toString();"); |
bt("a();\na = [\n ['sdfsdfsd'],\n ['sdfsdfsdf']\n ].toString();", |
"a();\na = [\n ['sdfsdfsd'],\n ['sdfsdfsdf']\n ].toString();"); |
bt("function() {\n Foo([\n ['sdfsdfsd'],\n ['sdfsdfsdf']\n ]);\n}", |
"function() {\n Foo([\n ['sdfsdfsd'],\n ['sdfsdfsdf']\n ]);\n}"); |
bt('function foo() {\n return [\n "one",\n "two"\n ];\n}'); |
// 4 spaces per indent input, processed with 4-spaces per indent |
bt( "function foo() {\n" + |
" return [\n" + |
" {\n" + |
" one: 'x',\n" + |
" two: [\n" + |
" {\n" + |
" id: 'a',\n" + |
" name: 'apple'\n" + |
" }, {\n" + |
" id: 'b',\n" + |
" name: 'banana'\n" + |
" }\n" + |
" ]\n" + |
" }\n" + |
" ];\n" + |
"}"); |
// 3 spaces per indent input, processed with 4-spaces per indent |
// Should be unchanged, but is not - #445 |
// bt( "function foo() {\n" + |
// " return [\n" + |
// " {\n" + |
// " one: 'x',\n" + |
// " two: [\n" + |
// " {\n" + |
// " id: 'a',\n" + |
// " name: 'apple'\n" + |
// " }, {\n" + |
// " id: 'b',\n" + |
// " name: 'banana'\n" + |
// " }\n" + |
// " ]\n" + |
// " }\n" + |
// " ];\n" + |
// "}"); |
|
|
reset_options(); |
//============================================================ |
bt('a = //comment\n /regex/;'); |
|
bt('if (a)\n{\nb;\n}\nelse\n{\nc;\n}', 'if (a) {\n b;\n} else {\n c;\n}'); |
|
// tests for brace positioning |
beautify_brace_tests('expand'); |
beautify_brace_tests('collapse'); |
beautify_brace_tests('end-expand'); |
beautify_brace_tests('none'); |
|
test_fragment('roo = {\n /*\n ****\n FOO\n ****\n */\n BAR: 0\n};'); |
|
bt('"foo""bar""baz"', '"foo"\n"bar"\n"baz"'); |
bt("'foo''bar''baz'", "'foo'\n'bar'\n'baz'"); |
|
|
test_fragment("if (zz) {\n // ....\n}\n(function"); |
|
bt("{\n get foo() {}\n}"); |
bt("{\n var a = get\n foo();\n}"); |
bt("{\n set foo() {}\n}"); |
bt("{\n var a = set\n foo();\n}"); |
bt("var x = {\n get function()\n}"); |
bt("var x = {\n set function()\n}"); |
|
// According to my current research get/set have no special meaning outside of an object literal |
bt("var x = set\n\na() {}", "var x = set\n\na() {}"); |
bt("var x = set\n\nfunction() {}", "var x = set\n\nfunction() {}"); |
|
bt('<!-- foo\nbar();\n-->'); |
bt('<!-- dont crash'); // --> |
bt('for () /abc/.test()'); |
bt('if (k) /aaa/m.test(v) && l();'); |
bt('switch (true) {\n case /swf/i.test(foo):\n bar();\n}'); |
bt('createdAt = {\n type: Date,\n default: Date.now\n}'); |
bt('switch (createdAt) {\n case a:\n Date,\n default:\n Date.now\n}'); |
|
reset_options(); |
//============================================================ |
opts.space_before_conditional = false; |
bt('if(a) b()'); |
|
|
reset_options(); |
//============================================================ |
opts.preserve_newlines = true; |
bt('var a = 42; // foo\n\nvar b;'); |
bt('var a = 42; // foo\n\n\nvar b;'); |
bt("var a = 'foo' +\n 'bar';"); |
bt("var a = \"foo\" +\n \"bar\";"); |
bt('this.oa = new OAuth(\n' + |
' _requestToken,\n' + |
' _accessToken,\n' + |
' consumer_key\n' + |
');'); |
|
|
reset_options(); |
//============================================================ |
opts.unescape_strings = false; |
bt('"\\\\s"'); // == "\\s" in the js source |
bt("'\\\\s'"); // == '\\s' in the js source |
bt("'\\\\\\s'"); // == '\\\s' in the js source |
bt("'\\s'"); // == '\s' in the js source |
bt('"•"'); |
bt('"—"'); |
bt('"\\x41\\x42\\x43\\x01"', '"\\x41\\x42\\x43\\x01"'); |
bt('"\\u2022"', '"\\u2022"'); |
bt('a = /\s+/'); |
// bt('a = /\\x41/','a = /A/'); |
bt('"\\u2022";a = /\s+/;"\\x41\\x42\\x43\\x01".match(/\\x41/);','"\\u2022";\na = /\s+/;\n"\\x41\\x42\\x43\\x01".match(/\\x41/);'); |
test_fragment('"\\x22\\x27",\'\\x22\\x27\',"\\x5c",\'\\x5c\',"\\xff and \\xzz","unicode \\u0000 \\u0022 \\u0027 \\u005c \\uffff \\uzzzz"', '"\\x22\\x27", \'\\x22\\x27\', "\\x5c", \'\\x5c\', "\\xff and \\xzz", "unicode \\u0000 \\u0022 \\u0027 \\u005c \\uffff \\uzzzz"'); |
|
opts.unescape_strings = true; |
test_fragment('"\\x20\\x40\\x4a"', '" @J"'); |
test_fragment('"\\xff\\x40\\x4a"'); |
test_fragment('"\\u0072\\u016B\\u0137\\u012B\\u0074\\u0069\\u0073"', '"\u0072\u016B\u0137\u012B\u0074\u0069\u0073"'); |
test_fragment('"Google Chrome est\\u00E1 actualizado."', '"Google Chrome está actualizado."'); |
test_fragment('"\\x22\\x27",\'\\x22\\x27\',"\\x5c",\'\\x5c\',"\\xff and \\xzz","unicode \\u0000 \\u0022 \\u0027 \\u005c \\uffff"', |
'"\\"\\\'", \'\\"\\\'\', "\\\\", \'\\\\\', "\\xff and \\xzz", "unicode \\u0000 \\" \\\' \\\\ ' + unicode_char(0xffff) + '"'); |
|
// For error case, return the string unchanged |
test_fragment('"\\x22\\x27",\'\\x22\\x27\',"\\x5c",\'\\x5c\',"\\xff and \\xzz","unicode \\u0000 \\u0022 \\u0027 \\u005c \\uffff \\uzzzz"', |
'"\\"\\\'", \'\\"\\\'\', "\\\\", \'\\\\\', "\\xff and \\xzz", "unicode \\u0000 \\u0022 \\u0027 \\u005c \\uffff \\uzzzz"'); |
|
reset_options(); |
//============================================================ |
bt('return function();'); |
bt('var a = function();'); |
bt('var a = 5 + function();'); |
|
bt('import foo.*;', 'import foo.*;'); // actionscript's import |
test_fragment('function f(a: a, b: b)'); // actionscript |
|
bt('{\n foo // something\n ,\n bar // something\n baz\n}'); |
bt('function a(a) {} function b(b) {} function c(c) {}', 'function a(a) {}\n\nfunction b(b) {}\n\nfunction c(c) {}'); |
bt('foo(a, function() {})'); |
|
bt('foo(a, /regex/)'); |
|
bt('/* foo */\n"x"'); |
|
reset_options(); |
//============================================================ |
opts.break_chained_methods = false; |
opts.preserve_newlines = false; |
bt('foo\n.bar()\n.baz().cucumber(fat)', 'foo.bar().baz().cucumber(fat)'); |
bt('foo\n.bar()\n.baz().cucumber(fat); foo.bar().baz().cucumber(fat)', 'foo.bar().baz().cucumber(fat);\nfoo.bar().baz().cucumber(fat)'); |
bt('foo\n.bar()\n.baz().cucumber(fat)\n foo.bar().baz().cucumber(fat)', 'foo.bar().baz().cucumber(fat)\nfoo.bar().baz().cucumber(fat)'); |
bt('this\n.something = foo.bar()\n.baz().cucumber(fat)', 'this.something = foo.bar().baz().cucumber(fat)'); |
bt('this.something.xxx = foo.moo.bar()'); |
bt('this\n.something\n.xxx = foo.moo\n.bar()', 'this.something.xxx = foo.moo.bar()'); |
|
opts.break_chained_methods = false; |
opts.preserve_newlines = true; |
bt('foo\n.bar()\n.baz().cucumber(fat)', 'foo\n .bar()\n .baz().cucumber(fat)'); |
bt('foo\n.bar()\n.baz().cucumber(fat); foo.bar().baz().cucumber(fat)', 'foo\n .bar()\n .baz().cucumber(fat);\nfoo.bar().baz().cucumber(fat)'); |
bt('foo\n.bar()\n.baz().cucumber(fat)\n foo.bar().baz().cucumber(fat)', 'foo\n .bar()\n .baz().cucumber(fat)\nfoo.bar().baz().cucumber(fat)'); |
bt('this\n.something = foo.bar()\n.baz().cucumber(fat)', 'this\n .something = foo.bar()\n .baz().cucumber(fat)'); |
bt('this.something.xxx = foo.moo.bar()'); |
bt('this\n.something\n.xxx = foo.moo\n.bar()', 'this\n .something\n .xxx = foo.moo\n .bar()'); |
|
opts.break_chained_methods = true; |
opts.preserve_newlines = false; |
bt('foo\n.bar()\n.baz().cucumber(fat)', 'foo.bar()\n .baz()\n .cucumber(fat)'); |
bt('foo\n.bar()\n.baz().cucumber(fat); foo.bar().baz().cucumber(fat)', 'foo.bar()\n .baz()\n .cucumber(fat);\nfoo.bar()\n .baz()\n .cucumber(fat)'); |
bt('foo\n.bar()\n.baz().cucumber(fat)\n foo.bar().baz().cucumber(fat)', 'foo.bar()\n .baz()\n .cucumber(fat)\nfoo.bar()\n .baz()\n .cucumber(fat)'); |
bt('this\n.something = foo.bar()\n.baz().cucumber(fat)', 'this.something = foo.bar()\n .baz()\n .cucumber(fat)'); |
bt('this.something.xxx = foo.moo.bar()'); |
bt('this\n.something\n.xxx = foo.moo\n.bar()', 'this.something.xxx = foo.moo.bar()'); |
|
opts.break_chained_methods = true; |
opts.preserve_newlines = true; |
bt('foo\n.bar()\n.baz().cucumber(fat)', 'foo\n .bar()\n .baz()\n .cucumber(fat)'); |
bt('foo\n.bar()\n.baz().cucumber(fat); foo.bar().baz().cucumber(fat)', 'foo\n .bar()\n .baz()\n .cucumber(fat);\nfoo.bar()\n .baz()\n .cucumber(fat)'); |
bt('foo\n.bar()\n.baz().cucumber(fat)\n foo.bar().baz().cucumber(fat)', 'foo\n .bar()\n .baz()\n .cucumber(fat)\nfoo.bar()\n .baz()\n .cucumber(fat)'); |
bt('this\n.something = foo.bar()\n.baz().cucumber(fat)', 'this\n .something = foo.bar()\n .baz()\n .cucumber(fat)'); |
bt('this.something.xxx = foo.moo.bar()'); |
bt('this\n.something\n.xxx = foo.moo\n.bar()', 'this\n .something\n .xxx = foo.moo\n .bar()'); |
|
reset_options(); |
//============================================================ |
// Line wrap test intputs |
//.............---------1---------2---------3---------4---------5---------6---------7 |
//.............1234567890123456789012345678901234567890123456789012345678901234567890 |
wrap_input_1=('foo.bar().baz().cucumber((fat && "sassy") || (leans && mean));\n' + |
'Test_very_long_variable_name_this_should_never_wrap\n.but_this_can\n' + |
'return between_return_and_expression_should_never_wrap.but_this_can\n' + |
'throw between_throw_and_expression_should_never_wrap.but_this_can\n' + |
'if (wraps_can_occur && inside_an_if_block) that_is_\n.okay();\n' + |
'object_literal = {\n' + |
' propertx: first_token + 12345678.99999E-6,\n' + |
' property: first_token_should_never_wrap + but_this_can,\n' + |
' propertz: first_token_should_never_wrap + !but_this_can,\n' + |
' proper: "first_token_should_never_wrap" + "but_this_can"\n' + |
'}'); |
|
//.............---------1---------2---------3---------4---------5---------6---------7 |
//.............1234567890123456789012345678901234567890123456789012345678901234567890 |
wrap_input_2=('{\n' + |
' foo.bar().baz().cucumber((fat && "sassy") || (leans && mean));\n' + |
' Test_very_long_variable_name_this_should_never_wrap\n.but_this_can\n' + |
' return between_return_and_expression_should_never_wrap.but_this_can\n' + |
' throw between_throw_and_expression_should_never_wrap.but_this_can\n' + |
' if (wraps_can_occur && inside_an_if_block) that_is_\n.okay();\n' + |
' object_literal = {\n' + |
' propertx: first_token + 12345678.99999E-6,\n' + |
' property: first_token_should_never_wrap + but_this_can,\n' + |
' propertz: first_token_should_never_wrap + !but_this_can,\n' + |
' proper: "first_token_should_never_wrap" + "but_this_can"\n' + |
' }' + |
'}'); |
|
opts.preserve_newlines = false; |
opts.wrap_line_length = 0; |
//.............---------1---------2---------3---------4---------5---------6---------7 |
//.............1234567890123456789012345678901234567890123456789012345678901234567890 |
test_fragment(wrap_input_1, |
/* expected */ |
'foo.bar().baz().cucumber((fat && "sassy") || (leans && mean));\n' + |
'Test_very_long_variable_name_this_should_never_wrap.but_this_can\n' + |
'return between_return_and_expression_should_never_wrap.but_this_can\n' + |
'throw between_throw_and_expression_should_never_wrap.but_this_can\n' + |
'if (wraps_can_occur && inside_an_if_block) that_is_.okay();\n' + |
'object_literal = {\n' + |
' propertx: first_token + 12345678.99999E-6,\n' + |
' property: first_token_should_never_wrap + but_this_can,\n' + |
' propertz: first_token_should_never_wrap + !but_this_can,\n' + |
' proper: "first_token_should_never_wrap" + "but_this_can"\n' + |
'}'); |
|
opts.wrap_line_length = 70; |
//.............---------1---------2---------3---------4---------5---------6---------7 |
//.............1234567890123456789012345678901234567890123456789012345678901234567890 |
test_fragment(wrap_input_1, |
/* expected */ |
'foo.bar().baz().cucumber((fat && "sassy") || (leans && mean));\n' + |
'Test_very_long_variable_name_this_should_never_wrap.but_this_can\n' + |
'return between_return_and_expression_should_never_wrap.but_this_can\n' + |
'throw between_throw_and_expression_should_never_wrap.but_this_can\n' + |
'if (wraps_can_occur && inside_an_if_block) that_is_.okay();\n' + |
'object_literal = {\n' + |
' propertx: first_token + 12345678.99999E-6,\n' + |
' property: first_token_should_never_wrap + but_this_can,\n' + |
' propertz: first_token_should_never_wrap + !but_this_can,\n' + |
' proper: "first_token_should_never_wrap" + "but_this_can"\n' + |
'}'); |
|
opts.wrap_line_length = 40; |
//.............---------1---------2---------3---------4---------5---------6---------7 |
//.............1234567890123456789012345678901234567890123456789012345678901234567890 |
test_fragment(wrap_input_1, |
/* expected */ |
'foo.bar().baz().cucumber((fat &&\n' + |
' "sassy") || (leans && mean));\n' + |
'Test_very_long_variable_name_this_should_never_wrap\n' + |
' .but_this_can\n' + |
'return between_return_and_expression_should_never_wrap\n' + |
' .but_this_can\n' + |
'throw between_throw_and_expression_should_never_wrap\n' + |
' .but_this_can\n' + |
'if (wraps_can_occur &&\n' + |
' inside_an_if_block) that_is_.okay();\n' + |
'object_literal = {\n' + |
' propertx: first_token +\n' + |
' 12345678.99999E-6,\n' + |
' property: first_token_should_never_wrap +\n' + |
' but_this_can,\n' + |
' propertz: first_token_should_never_wrap +\n' + |
' !but_this_can,\n' + |
' proper: "first_token_should_never_wrap" +\n' + |
' "but_this_can"\n' + |
'}'); |
|
opts.wrap_line_length = 41; |
// NOTE: wrap is only best effort - line continues until next wrap point is found. |
//.............---------1---------2---------3---------4---------5---------6---------7 |
//.............1234567890123456789012345678901234567890123456789012345678901234567890 |
test_fragment(wrap_input_1, |
/* expected */ |
'foo.bar().baz().cucumber((fat && "sassy") ||\n' + |
' (leans && mean));\n' + |
'Test_very_long_variable_name_this_should_never_wrap\n' + |
' .but_this_can\n' + |
'return between_return_and_expression_should_never_wrap\n' + |
' .but_this_can\n' + |
'throw between_throw_and_expression_should_never_wrap\n' + |
' .but_this_can\n' + |
'if (wraps_can_occur &&\n' + |
' inside_an_if_block) that_is_.okay();\n' + |
'object_literal = {\n' + |
' propertx: first_token +\n' + |
' 12345678.99999E-6,\n' + |
' property: first_token_should_never_wrap +\n' + |
' but_this_can,\n' + |
' propertz: first_token_should_never_wrap +\n' + |
' !but_this_can,\n' + |
' proper: "first_token_should_never_wrap" +\n' + |
' "but_this_can"\n' + |
'}'); |
|
opts.wrap_line_length = 45; |
// NOTE: wrap is only best effort - line continues until next wrap point is found. |
//.............---------1---------2---------3---------4---------5---------6---------7 |
//.............1234567890123456789012345678901234567890123456789012345678901234567890 |
test_fragment(wrap_input_2, |
/* expected */ |
'{\n' + |
' foo.bar().baz().cucumber((fat && "sassy") ||\n' + |
' (leans && mean));\n' + |
' Test_very_long_variable_name_this_should_never_wrap\n' + |
' .but_this_can\n' + |
' return between_return_and_expression_should_never_wrap\n' + |
' .but_this_can\n' + |
' throw between_throw_and_expression_should_never_wrap\n' + |
' .but_this_can\n' + |
' if (wraps_can_occur &&\n' + |
' inside_an_if_block) that_is_.okay();\n' + |
' object_literal = {\n' + |
' propertx: first_token +\n' + |
' 12345678.99999E-6,\n' + |
' property: first_token_should_never_wrap +\n' + |
' but_this_can,\n' + |
' propertz: first_token_should_never_wrap +\n' + |
' !but_this_can,\n' + |
' proper: "first_token_should_never_wrap" +\n' + |
' "but_this_can"\n' + |
' }\n'+ |
'}'); |
|
opts.preserve_newlines = true; |
opts.wrap_line_length = 0; |
//.............---------1---------2---------3---------4---------5---------6---------7 |
//.............1234567890123456789012345678901234567890123456789012345678901234567890 |
test_fragment(wrap_input_1, |
/* expected */ |
'foo.bar().baz().cucumber((fat && "sassy") || (leans && mean));\n' + |
'Test_very_long_variable_name_this_should_never_wrap\n' + |
' .but_this_can\n' + |
'return between_return_and_expression_should_never_wrap.but_this_can\n' + |
'throw between_throw_and_expression_should_never_wrap.but_this_can\n' + |
'if (wraps_can_occur && inside_an_if_block) that_is_\n' + |
' .okay();\n' + |
'object_literal = {\n' + |
' propertx: first_token + 12345678.99999E-6,\n' + |
' property: first_token_should_never_wrap + but_this_can,\n' + |
' propertz: first_token_should_never_wrap + !but_this_can,\n' + |
' proper: "first_token_should_never_wrap" + "but_this_can"\n' + |
'}'); |
|
opts.wrap_line_length = 70; |
//.............---------1---------2---------3---------4---------5---------6---------7 |
//.............1234567890123456789012345678901234567890123456789012345678901234567890 |
test_fragment(wrap_input_1, |
/* expected */ |
'foo.bar().baz().cucumber((fat && "sassy") || (leans && mean));\n' + |
'Test_very_long_variable_name_this_should_never_wrap\n' + |
' .but_this_can\n' + |
'return between_return_and_expression_should_never_wrap.but_this_can\n' + |
'throw between_throw_and_expression_should_never_wrap.but_this_can\n' + |
'if (wraps_can_occur && inside_an_if_block) that_is_\n' + |
' .okay();\n' + |
'object_literal = {\n' + |
' propertx: first_token + 12345678.99999E-6,\n' + |
' property: first_token_should_never_wrap + but_this_can,\n' + |
' propertz: first_token_should_never_wrap + !but_this_can,\n' + |
' proper: "first_token_should_never_wrap" + "but_this_can"\n' + |
'}'); |
|
|
opts.wrap_line_length = 40; |
//.............---------1---------2---------3---------4---------5---------6---------7 |
//.............1234567890123456789012345678901234567890123456789012345678901234567890 |
test_fragment(wrap_input_1, |
/* expected */ |
'foo.bar().baz().cucumber((fat &&\n' + |
' "sassy") || (leans && mean));\n' + |
'Test_very_long_variable_name_this_should_never_wrap\n' + |
' .but_this_can\n' + |
'return between_return_and_expression_should_never_wrap\n' + |
' .but_this_can\n' + |
'throw between_throw_and_expression_should_never_wrap\n' + |
' .but_this_can\n' + |
'if (wraps_can_occur &&\n' + |
' inside_an_if_block) that_is_\n' + |
' .okay();\n' + |
'object_literal = {\n' + |
' propertx: first_token +\n' + |
' 12345678.99999E-6,\n' + |
' property: first_token_should_never_wrap +\n' + |
' but_this_can,\n' + |
' propertz: first_token_should_never_wrap +\n' + |
' !but_this_can,\n' + |
' proper: "first_token_should_never_wrap" +\n' + |
' "but_this_can"\n' + |
'}'); |
|
opts.wrap_line_length = 41; |
// NOTE: wrap is only best effort - line continues until next wrap point is found. |
//.............---------1---------2---------3---------4---------5---------6---------7 |
//.............1234567890123456789012345678901234567890123456789012345678901234567890 |
test_fragment(wrap_input_1, |
/* expected */ |
'foo.bar().baz().cucumber((fat && "sassy") ||\n' + |
' (leans && mean));\n' + |
'Test_very_long_variable_name_this_should_never_wrap\n' + |
' .but_this_can\n' + |
'return between_return_and_expression_should_never_wrap\n' + |
' .but_this_can\n' + |
'throw between_throw_and_expression_should_never_wrap\n' + |
' .but_this_can\n' + |
'if (wraps_can_occur &&\n' + |
' inside_an_if_block) that_is_\n' + |
' .okay();\n' + |
'object_literal = {\n' + |
' propertx: first_token +\n' + |
' 12345678.99999E-6,\n' + |
' property: first_token_should_never_wrap +\n' + |
' but_this_can,\n' + |
' propertz: first_token_should_never_wrap +\n' + |
' !but_this_can,\n' + |
' proper: "first_token_should_never_wrap" +\n' + |
' "but_this_can"\n' + |
'}'); |
|
opts.wrap_line_length = 45; |
// NOTE: wrap is only best effort - line continues until next wrap point is found. |
//.............---------1---------2---------3---------4---------5---------6---------7 |
//.............1234567890123456789012345678901234567890123456789012345678901234567890 |
test_fragment(wrap_input_2, |
/* expected */ |
'{\n' + |
' foo.bar().baz().cucumber((fat && "sassy") ||\n' + |
' (leans && mean));\n' + |
' Test_very_long_variable_name_this_should_never_wrap\n' + |
' .but_this_can\n' + |
' return between_return_and_expression_should_never_wrap\n' + |
' .but_this_can\n' + |
' throw between_throw_and_expression_should_never_wrap\n' + |
' .but_this_can\n' + |
' if (wraps_can_occur &&\n' + |
' inside_an_if_block) that_is_\n' + |
' .okay();\n' + |
' object_literal = {\n' + |
' propertx: first_token +\n' + |
' 12345678.99999E-6,\n' + |
' property: first_token_should_never_wrap +\n' + |
' but_this_can,\n' + |
' propertz: first_token_should_never_wrap +\n' + |
' !but_this_can,\n' + |
' proper: "first_token_should_never_wrap" +\n' + |
' "but_this_can"\n' + |
' }\n'+ |
'}'); |
|
reset_options(); |
//============================================================ |
opts.preserve_newlines = false; |
bt('if (foo) // comment\n bar();'); |
bt('if (foo) // comment\n (bar());'); |
bt('if (foo) // comment\n (bar());'); |
bt('if (foo) // comment\n /asdf/;'); |
bt('this.oa = new OAuth(\n' + |
' _requestToken,\n' + |
' _accessToken,\n' + |
' consumer_key\n' + |
');', |
'this.oa = new OAuth(_requestToken, _accessToken, consumer_key);'); |
bt('foo = {\n x: y, // #44\n w: z // #44\n}'); |
bt('switch (x) {\n case "a":\n // comment on newline\n break;\n case "b": // comment on same line\n break;\n}'); |
bt('this.type =\n this.options =\n // comment\n this.enabled null;', |
'this.type = this.options =\n // comment\n this.enabled null;'); |
bt('someObj\n .someFunc1()\n // This comment should not break the indent\n .someFunc2();', |
'someObj.someFunc1()\n // This comment should not break the indent\n .someFunc2();'); |
|
bt('if (true ||\n!true) return;', 'if (true || !true) return;'); |
|
// these aren't ready yet. |
//bt('if (foo) // comment\n bar() /*i*/ + baz() /*j\n*/ + asdf();'); |
bt('if\n(foo)\nif\n(bar)\nif\n(baz)\nwhee();\na();', |
'if (foo)\n if (bar)\n if (baz) whee();\na();'); |
bt('if\n(foo)\nif\n(bar)\nif\n(baz)\nwhee();\nelse\na();', |
'if (foo)\n if (bar)\n if (baz) whee();\n else a();'); |
bt('if (foo)\nbar();\nelse\ncar();', |
'if (foo) bar();\nelse car();'); |
|
bt('if (foo) if (bar) if (baz);\na();', |
'if (foo)\n if (bar)\n if (baz);\na();'); |
bt('if (foo) if (bar) if (baz) whee();\na();', |
'if (foo)\n if (bar)\n if (baz) whee();\na();'); |
bt('if (foo) a()\nif (bar) if (baz) whee();\na();', |
'if (foo) a()\nif (bar)\n if (baz) whee();\na();'); |
bt('if (foo);\nif (bar) if (baz) whee();\na();', |
'if (foo);\nif (bar)\n if (baz) whee();\na();'); |
bt('if (options)\n' + |
' for (var p in options)\n' + |
' this[p] = options[p];', |
'if (options)\n'+ |
' for (var p in options) this[p] = options[p];'); |
bt('if (options) for (var p in options) this[p] = options[p];', |
'if (options)\n for (var p in options) this[p] = options[p];'); |
|
bt('if (options) do q(); while (b());', |
'if (options)\n do q(); while (b());'); |
bt('if (options) while (b()) q();', |
'if (options)\n while (b()) q();'); |
bt('if (options) do while (b()) q(); while (a());', |
'if (options)\n do\n while (b()) q(); while (a());'); |
|
bt('function f(a, b, c,\nd, e) {}', |
'function f(a, b, c, d, e) {}'); |
|
bt('function f(a,b) {if(a) b()}function g(a,b) {if(!a) b()}', |
'function f(a, b) {\n if (a) b()\n}\n\nfunction g(a, b) {\n if (!a) b()\n}'); |
bt('function f(a,b) {if(a) b()}\n\n\n\nfunction g(a,b) {if(!a) b()}', |
'function f(a, b) {\n if (a) b()\n}\n\nfunction g(a, b) {\n if (!a) b()\n}'); |
|
// This is not valid syntax, but still want to behave reasonably and not side-effect |
bt('(if(a) b())(if(a) b())', |
'(\n if (a) b())(\n if (a) b())'); |
bt('(if(a) b())\n\n\n(if(a) b())', |
'(\n if (a) b())\n(\n if (a) b())'); |
|
|
|
bt("if\n(a)\nb();", "if (a) b();"); |
bt('var a =\nfoo', 'var a = foo'); |
bt('var a = {\n"a":1,\n"b":2}', "var a = {\n \"a\": 1,\n \"b\": 2\n}"); |
bt("var a = {\n'a':1,\n'b':2}", "var a = {\n 'a': 1,\n 'b': 2\n}"); |
bt('var a = /*i*/ "b";'); |
bt('var a = /*i*/\n"b";', 'var a = /*i*/ "b";'); |
bt('var a = /*i*/\nb;', 'var a = /*i*/ b;'); |
bt('{\n\n\n"x"\n}', '{\n "x"\n}'); |
bt('if(a &&\nb\n||\nc\n||d\n&&\ne) e = f', 'if (a && b || c || d && e) e = f'); |
bt('if(a &&\n(b\n||\nc\n||d)\n&&\ne) e = f', 'if (a && (b || c || d) && e) e = f'); |
test_fragment('\n\n"x"', '"x"'); |
bt('a = 1;\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\nb = 2;', |
'a = 1;\nb = 2;'); |
|
opts.preserve_newlines = true; |
bt('if (foo) // comment\n bar();'); |
bt('if (foo) // comment\n (bar());'); |
bt('if (foo) // comment\n (bar());'); |
bt('if (foo) // comment\n /asdf/;'); |
bt('foo = {\n x: y, // #44\n w: z // #44\n}'); |
bt('switch (x) {\n case "a":\n // comment on newline\n break;\n case "b": // comment on same line\n break;\n}'); |
bt('this.type =\n this.options =\n // comment\n this.enabled null;'); |
bt('someObj\n .someFunc1()\n // This comment should not break the indent\n .someFunc2();'); |
|
bt('if (true ||\n!true) return;', 'if (true ||\n !true) return;'); |
|
// these aren't ready yet. |
// bt('if (foo) // comment\n bar() /*i*/ + baz() /*j\n*/ + asdf();'); |
bt('if\n(foo)\nif\n(bar)\nif\n(baz)\nwhee();\na();', |
'if (foo)\n if (bar)\n if (baz)\n whee();\na();'); |
bt('if\n(foo)\nif\n(bar)\nif\n(baz)\nwhee();\nelse\na();', |
'if (foo)\n if (bar)\n if (baz)\n whee();\n else\n a();'); |
bt('if (foo)\nbar();\nelse\ncar();', |
'if (foo)\n bar();\nelse\n car();'); |
bt('if (foo) bar();\nelse\ncar();', |
'if (foo) bar();\nelse\n car();'); |
|
bt('if (foo) if (bar) if (baz);\na();', |
'if (foo)\n if (bar)\n if (baz);\na();'); |
bt('if (foo) if (bar) if (baz) whee();\na();', |
'if (foo)\n if (bar)\n if (baz) whee();\na();'); |
bt('if (foo) a()\nif (bar) if (baz) whee();\na();', |
'if (foo) a()\nif (bar)\n if (baz) whee();\na();'); |
bt('if (foo);\nif (bar) if (baz) whee();\na();', |
'if (foo);\nif (bar)\n if (baz) whee();\na();'); |
bt('if (options)\n' + |
' for (var p in options)\n' + |
' this[p] = options[p];'); |
bt('if (options) for (var p in options) this[p] = options[p];', |
'if (options)\n for (var p in options) this[p] = options[p];'); |
|
bt('if (options) do q(); while (b());', |
'if (options)\n do q(); while (b());'); |
bt('if (options) do; while (b());', |
'if (options)\n do; while (b());'); |
bt('if (options) while (b()) q();', |
'if (options)\n while (b()) q();'); |
bt('if (options) do while (b()) q(); while (a());', |
'if (options)\n do\n while (b()) q(); while (a());'); |
|
bt('function f(a, b, c,\nd, e) {}', |
'function f(a, b, c,\n d, e) {}'); |
|
bt('function f(a,b) {if(a) b()}function g(a,b) {if(!a) b()}', |
'function f(a, b) {\n if (a) b()\n}\n\nfunction g(a, b) {\n if (!a) b()\n}'); |
bt('function f(a,b) {if(a) b()}\n\n\n\nfunction g(a,b) {if(!a) b()}', |
'function f(a, b) {\n if (a) b()\n}\n\n\n\nfunction g(a, b) {\n if (!a) b()\n}'); |
// This is not valid syntax, but still want to behave reasonably and not side-effect |
bt('(if(a) b())(if(a) b())', |
'(\n if (a) b())(\n if (a) b())'); |
bt('(if(a) b())\n\n\n(if(a) b())', |
'(\n if (a) b())\n\n\n(\n if (a) b())'); |
|
// space between functions |
bt('/*\n * foo\n */\nfunction foo() {}'); |
bt('// a nice function\nfunction foo() {}'); |
bt('function foo() {}\nfunction foo() {}', |
'function foo() {}\n\nfunction foo() {}' |
); |
|
bt('[\n function() {}\n]'); |
|
|
|
bt("if\n(a)\nb();", "if (a)\n b();"); |
bt('var a =\nfoo', 'var a =\n foo'); |
bt('var a = {\n"a":1,\n"b":2}', "var a = {\n \"a\": 1,\n \"b\": 2\n}"); |
bt("var a = {\n'a':1,\n'b':2}", "var a = {\n 'a': 1,\n 'b': 2\n}"); |
bt('var a = /*i*/ "b";'); |
bt('var a = /*i*/\n"b";', 'var a = /*i*/\n "b";'); |
bt('var a = /*i*/\nb;', 'var a = /*i*/\n b;'); |
bt('{\n\n\n"x"\n}', '{\n\n\n "x"\n}'); |
bt('if(a &&\nb\n||\nc\n||d\n&&\ne) e = f', 'if (a &&\n b ||\n c ||\n d &&\n e) e = f'); |
bt('if(a &&\n(b\n||\nc\n||d)\n&&\ne) e = f', 'if (a &&\n (b ||\n c ||\n d) &&\n e) e = f'); |
test_fragment('\n\n"x"', '"x"'); |
|
// this beavior differs between js and python, defaults to unlimited in js, 10 in python |
bt('a = 1;\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\nb = 2;', |
'a = 1;\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\nb = 2;'); |
opts.max_preserve_newlines = 8; |
bt('a = 1;\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\nb = 2;', |
'a = 1;\n\n\n\n\n\n\n\nb = 2;'); |
|
reset_options(); |
//============================================================ |
|
|
Urlencoded.run_tests(sanitytest); |
} |
|
beautifier_tests(); |
beautifier_unconverted_tests(); |
} |
|
if (typeof exports !== "undefined") { |
exports.run_javascript_tests = run_javascript_tests; |
} |
/script-kiddie/002_script_kiddie/script-kiddie/node_modules/js-beautify/test/data/javascript/python.mustache |
@@ -0,0 +1,1322 @@ |
#!/usr/bin/env python |
# -*- coding: utf-8 -*- |
|
''' |
{{&header_text}} |
|
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. |
''' |
|
import re |
import unittest |
import jsbeautifier |
import six |
import copy |
|
class TestJSBeautifier(unittest.TestCase): |
options = None |
|
@classmethod |
def setUpClass(cls): |
true = True |
false = False |
|
default_options = jsbeautifier.default_options() |
default_options.indent_size = 4 |
default_options.indent_char = ' ' |
default_options.preserve_newlines = True |
default_options.jslint_happy = False |
default_options.keep_array_indentation = False |
default_options.brace_style = 'collapse' |
default_options.indent_level = 0 |
default_options.break_chained_methods = False |
default_options.eol = '\n' |
|
{{#default_options}} default_options.{{name}} = {{&value}} |
{{/default_options}} |
|
cls.default_options = default_options |
cls.wrapregex = re.compile('^(.+)$', re.MULTILINE) |
|
def reset_options(self): |
self.options = copy.copy(self.default_options) |
|
def test_unescape(self): |
# Test cases contributed by <chrisjshull on GitHub.com> |
test_fragment = self.decodesto |
self.reset_options() |
bt = self.bt |
|
def unicode_char(value): |
return six.unichr(value) |
|
bt('"\\\\s"') # == "\\s" in the js source |
bt("'\\\\s'") # == '\\s' in the js source |
bt("'\\\\\\s'") # == '\\\s' in the js source |
bt("'\\s'") # == '\s' in the js source |
bt('"•"') |
bt('"—"') |
bt('"\\x41\\x42\\x43\\x01"', '"\\x41\\x42\\x43\\x01"') |
bt('"\\u2022"', '"\\u2022"') |
bt('a = /\s+/') |
#bt('a = /\\x41/','a = /A/') |
bt('"\\u2022";a = /\s+/;"\\x41\\x42\\x43\\x01".match(/\\x41/);','"\\u2022";\na = /\s+/;\n"\\x41\\x42\\x43\\x01".match(/\\x41/);') |
test_fragment('"\\x22\\x27",\'\\x22\\x27\',"\\x5c",\'\\x5c\',"\\xff and \\xzz","unicode \\u0000 \\u0022 \\u0027 \\u005c \\uffff \\uzzzz"', '"\\x22\\x27", \'\\x22\\x27\', "\\x5c", \'\\x5c\', "\\xff and \\xzz", "unicode \\u0000 \\u0022 \\u0027 \\u005c \\uffff \\uzzzz"') |
|
self.options.unescape_strings = True |
|
bt('"\\x41\\x42\\x43\\x01"', '"ABC\\x01"') |
test_fragment('"\\x20\\x40\\x4a"', '" @J"'); |
test_fragment('"\\xff\\x40\\x4a"'); |
test_fragment('"\\u0072\\u016B\\u0137\\u012B\\u0074\\u0069\\u0073"', six.u('"\u0072\u016B\u0137\u012B\u0074\u0069\u0073"')); |
|
bt('a = /\s+/') |
test_fragment('"\\x22\\x27",\'\\x22\\x27\',"\\x5c",\'\\x5c\',"\\xff","unicode \\u0000 \\u0022 \\u0027 \\u005c \\uffff"', |
'"\\"\\\'", \'\\"\\\'\', "\\\\", \'\\\\\', "\\xff", "unicode \\u0000 \\" \\\' \\\\ ' + unicode_char(0xffff) + '"'); |
|
# For error case, return the string unchanged |
test_fragment('"\\x22\\x27",\'\\x22\\x27\',"\\x5c",\'\\x5c\',"\\xff and \\xzz","unicode \\u0000 \\u0022 \\u0027 \\u005c \\uffff \\uzzzz"', |
'"\\"\\\'", \'\\"\\\'\', "\\\\", \'\\\\\', "\\xff and \\xzz", "unicode \\u0000 \\u0022 \\u0027 \\u005c \\uffff \\uzzzz"'); |
|
self.options.unescape_strings = False |
|
def test_beautifier(self): |
test_fragment = self.decodesto |
bt = self.bt |
|
true = True |
false = False |
|
def unicode_char(value): |
return six.unichr(value) |
|
{{#groups}}{{#set_mustache_tags}}.{{/set_mustache_tags}} |
#============================================================ |
{{^matrix}} |
# {{&name}} |
self.reset_options(); |
{{#options}} |
self.options.{{name}} = {{&value}} |
{{/options}} |
{{#tests}} |
{{#test_line}}.{{/test_line}} |
{{/tests}} |
|
{{/matrix}} |
{{#matrix}} |
# {{&name}} - ({{#matrix_context_string}}.{{/matrix_context_string}}) |
self.reset_options(); |
{{#options}} |
self.options.{{name}} = {{&value}} |
{{/options}} |
{{#tests}} |
{{#test_line}}.{{/test_line}} |
{{/tests}} |
|
{{/matrix}} |
{{#unset_mustache_tags}}.{{/unset_mustache_tags}}{{/groups}} |
|
def test_beautifier_unconverted(self): |
test_fragment = self.decodesto |
bt = self.bt |
|
self.reset_options(); |
#============================================================ |
self.options.indent_size = 1; |
self.options.indent_char = ' '; |
bt('{ one_char() }', "{\n one_char()\n}") |
|
bt('var a,b=1,c=2', 'var a, b = 1,\n c = 2') |
|
self.options.indent_size = 4; |
self.options.indent_char = ' '; |
bt('{ one_char() }', "{\n one_char()\n}") |
|
self.options.indent_size = 1; |
self.options.indent_char = "\t"; |
bt('{ one_char() }', "{\n\tone_char()\n}") |
bt('x = a ? b : c; x;', 'x = a ? b : c;\nx;') |
|
#set to something else than it should change to, but with tabs on, should override |
self.options.indent_size = 5; |
self.options.indent_char = ' '; |
self.options.indent_with_tabs = True; |
|
bt('{ one_char() }', "{\n\tone_char()\n}") |
bt('x = a ? b : c; x;', 'x = a ? b : c;\nx;') |
|
|
self.reset_options(); |
#============================================================ |
self.options.preserve_newlines = False; |
bt('var\na=dont_preserve_newlines;', 'var a = dont_preserve_newlines;') |
|
# make sure the blank line between function definitions stays |
# even when preserve_newlines = False |
bt('function foo() {\n return 1;\n}\n\nfunction foo() {\n return 1;\n}') |
bt('function foo() {\n return 1;\n}\nfunction foo() {\n return 1;\n}', |
'function foo() {\n return 1;\n}\n\nfunction foo() {\n return 1;\n}' |
) |
bt('function foo() {\n return 1;\n}\n\n\nfunction foo() {\n return 1;\n}', |
'function foo() {\n return 1;\n}\n\nfunction foo() {\n return 1;\n}' |
) |
|
|
self.options.preserve_newlines = True; |
bt('var\na=do_preserve_newlines;', 'var\n a = do_preserve_newlines;') |
bt('if (foo) // comment\n{\n bar();\n}') |
|
|
self.reset_options(); |
#============================================================ |
self.options.keep_array_indentation = False; |
bt("a = ['a', 'b', 'c',\n 'd', 'e', 'f']", |
"a = ['a', 'b', 'c',\n 'd', 'e', 'f'\n]") |
bt("a = ['a', 'b', 'c',\n 'd', 'e', 'f',\n 'g', 'h', 'i']", |
"a = ['a', 'b', 'c',\n 'd', 'e', 'f',\n 'g', 'h', 'i'\n]") |
bt("a = ['a', 'b', 'c',\n 'd', 'e', 'f',\n 'g', 'h', 'i']", |
"a = ['a', 'b', 'c',\n 'd', 'e', 'f',\n 'g', 'h', 'i'\n]") |
bt('var x = [{}\n]', 'var x = [{}]') |
bt('var x = [{foo:bar}\n]', 'var x = [{\n foo: bar\n}]') |
bt("a = ['something',\n 'completely',\n 'different'];\nif (x);", |
"a = ['something',\n 'completely',\n 'different'\n];\nif (x);") |
bt("a = ['a','b','c']", "a = ['a', 'b', 'c']") |
bt("a = ['a', 'b','c']", "a = ['a', 'b', 'c']") |
bt("x = [{'a':0}]", |
"x = [{\n 'a': 0\n}]") |
bt('{a([[a1]], {b;});}', |
'{\n a([\n [a1]\n ], {\n b;\n });\n}') |
bt("a();\n [\n ['sdfsdfsd'],\n ['sdfsdfsdf']\n ].toString();", |
"a();\n[\n ['sdfsdfsd'],\n ['sdfsdfsdf']\n].toString();") |
bt("a();\na = [\n ['sdfsdfsd'],\n ['sdfsdfsdf']\n ].toString();", |
"a();\na = [\n ['sdfsdfsd'],\n ['sdfsdfsdf']\n].toString();") |
bt("function() {\n Foo([\n ['sdfsdfsd'],\n ['sdfsdfsdf']\n ]);\n}", |
"function() {\n Foo([\n ['sdfsdfsd'],\n ['sdfsdfsdf']\n ]);\n}") |
bt('function foo() {\n return [\n "one",\n "two"\n ];\n}') |
# 4 spaces per indent input, processed with 4-spaces per indent |
bt( "function foo() {\n" + |
" return [\n" + |
" {\n" + |
" one: 'x',\n" + |
" two: [\n" + |
" {\n" + |
" id: 'a',\n" + |
" name: 'apple'\n" + |
" }, {\n" + |
" id: 'b',\n" + |
" name: 'banana'\n" + |
" }\n" + |
" ]\n" + |
" }\n" + |
" ];\n" + |
"}", |
"function foo() {\n" + |
" return [{\n" + |
" one: 'x',\n" + |
" two: [{\n" + |
" id: 'a',\n" + |
" name: 'apple'\n" + |
" }, {\n" + |
" id: 'b',\n" + |
" name: 'banana'\n" + |
" }]\n" + |
" }];\n" + |
"}") |
# 3 spaces per indent input, processed with 4-spaces per indent |
bt( "function foo() {\n" + |
" return [\n" + |
" {\n" + |
" one: 'x',\n" + |
" two: [\n" + |
" {\n" + |
" id: 'a',\n" + |
" name: 'apple'\n" + |
" }, {\n" + |
" id: 'b',\n" + |
" name: 'banana'\n" + |
" }\n" + |
" ]\n" + |
" }\n" + |
" ];\n" + |
"}", |
"function foo() {\n" + |
" return [{\n" + |
" one: 'x',\n" + |
" two: [{\n" + |
" id: 'a',\n" + |
" name: 'apple'\n" + |
" }, {\n" + |
" id: 'b',\n" + |
" name: 'banana'\n" + |
" }]\n" + |
" }];\n" + |
"}") |
|
self.options.keep_array_indentation = True; |
bt("a = ['a', 'b', 'c',\n 'd', 'e', 'f']") |
bt("a = ['a', 'b', 'c',\n 'd', 'e', 'f',\n 'g', 'h', 'i']") |
bt("a = ['a', 'b', 'c',\n 'd', 'e', 'f',\n 'g', 'h', 'i']") |
bt('var x = [{}\n]', 'var x = [{}\n]') |
bt('var x = [{foo:bar}\n]', 'var x = [{\n foo: bar\n }\n]') |
bt("a = ['something',\n 'completely',\n 'different'];\nif (x);") |
bt("a = ['a','b','c']", "a = ['a', 'b', 'c']") |
bt("a = ['a', 'b','c']", "a = ['a', 'b', 'c']") |
bt("x = [{'a':0}]", |
"x = [{\n 'a': 0\n}]") |
bt('{a([[a1]], {b;});}', |
'{\n a([[a1]], {\n b;\n });\n}') |
bt("a();\n [\n ['sdfsdfsd'],\n ['sdfsdfsdf']\n ].toString();", |
"a();\n [\n ['sdfsdfsd'],\n ['sdfsdfsdf']\n ].toString();") |
bt("a();\na = [\n ['sdfsdfsd'],\n ['sdfsdfsdf']\n ].toString();", |
"a();\na = [\n ['sdfsdfsd'],\n ['sdfsdfsdf']\n ].toString();") |
bt("function() {\n Foo([\n ['sdfsdfsd'],\n ['sdfsdfsdf']\n ]);\n}", |
"function() {\n Foo([\n ['sdfsdfsd'],\n ['sdfsdfsdf']\n ]);\n}") |
bt('function foo() {\n return [\n "one",\n "two"\n ];\n}') |
# 4 spaces per indent input, processed with 4-spaces per indent |
bt( "function foo() {\n" + |
" return [\n" + |
" {\n" + |
" one: 'x',\n" + |
" two: [\n" + |
" {\n" + |
" id: 'a',\n" + |
" name: 'apple'\n" + |
" }, {\n" + |
" id: 'b',\n" + |
" name: 'banana'\n" + |
" }\n" + |
" ]\n" + |
" }\n" + |
" ];\n" + |
"}") |
# 3 spaces per indent input, processed with 4-spaces per indent |
# Should be unchanged, but is not - #445 |
# bt( "function foo() {\n" + |
# " return [\n" + |
# " {\n" + |
# " one: 'x',\n" + |
# " two: [\n" + |
# " {\n" + |
# " id: 'a',\n" + |
# " name: 'apple'\n" + |
# " }, {\n" + |
# " id: 'b',\n" + |
# " name: 'banana'\n" + |
# " }\n" + |
# " ]\n" + |
# " }\n" + |
# " ];\n" + |
# "}") |
|
self.reset_options(); |
#============================================================ |
bt('a = //comment\n /regex/;') |
|
bt('if (a)\n{\nb;\n}\nelse\n{\nc;\n}', 'if (a) {\n b;\n} else {\n c;\n}') |
|
bt('var a = new function();') |
test_fragment('new function') |
|
self.reset_options(); |
#============================================================ |
# START tests for brace positioning |
|
# If this is ever supported, update tests for each brace style. |
# test_fragment('return\n{', 'return\n{') # can't support this?, but that's an improbable and extreme case anyway. |
|
self.options.brace_style = 'expand'; |
|
bt('//case 1\nif (a == 1)\n{}\n//case 2\nelse if (a == 2)\n{}') |
bt('if(1){2}else{3}', "if (1)\n{\n 2\n}\nelse\n{\n 3\n}") |
bt('try{a();}catch(b){c();}catch(d){}finally{e();}', |
"try\n{\n a();\n}\ncatch (b)\n{\n c();\n}\ncatch (d)\n{}\nfinally\n{\n e();\n}") |
bt('if(a){b();}else if(c) foo();', |
"if (a)\n{\n b();\n}\nelse if (c) foo();") |
bt("if (a) {\n// comment\n}else{\n// comment\n}", |
"if (a)\n{\n // comment\n}\nelse\n{\n // comment\n}") # if/else statement with empty body |
bt('if (x) {y} else { if (x) {y}}', |
'if (x)\n{\n y\n}\nelse\n{\n if (x)\n {\n y\n }\n}') |
bt('if (a)\n{\nb;\n}\nelse\n{\nc;\n}', |
'if (a)\n{\n b;\n}\nelse\n{\n c;\n}') |
test_fragment(' /*\n* xx\n*/\n// xx\nif (foo) {\n bar();\n}', |
' /*\n * xx\n */\n // xx\n if (foo)\n {\n bar();\n }') |
bt('if (foo)\n{}\nelse /regex/.test();') |
test_fragment('if (foo) {', 'if (foo)\n{') |
test_fragment('foo {', 'foo\n{') |
test_fragment('return {', 'return {') # return needs the brace. |
test_fragment('return /* inline */ {', 'return /* inline */ {') |
test_fragment('return;\n{', 'return;\n{') |
bt("throw {}") |
bt("throw {\n foo;\n}") |
bt('var foo = {}') |
bt('function x() {\n foo();\n}zzz', 'function x()\n{\n foo();\n}\nzzz') |
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 a() {};', 'var a = new function a()\n{};') |
bt('var a = new function()\n{};', 'var a = new function() {};') |
bt('var a = new function a()\n{};') |
bt('var a = new function a()\n {},\n b = new function b()\n {};') |
bt("foo({\n 'a': 1\n},\n10);", |
"foo(\n {\n 'a': 1\n },\n 10);") |
bt('(["foo","bar"]).each(function(i) {return i;});', |
'(["foo", "bar"]).each(function(i)\n{\n return i;\n});') |
bt('(function(i) {return i;})();', |
'(function(i)\n{\n return i;\n})();') |
bt( "test( /*Argument 1*/ {\n" + |
" 'Value1': '1'\n" + |
"}, /*Argument 2\n" + |
" */ {\n" + |
" 'Value2': '2'\n" + |
"});", |
# expected |
"test( /*Argument 1*/\n" + |
" {\n" + |
" 'Value1': '1'\n" + |
" },\n" + |
" /*Argument 2\n" + |
" */\n" + |
" {\n" + |
" 'Value2': '2'\n" + |
" });") |
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" + |
" });") |
bt( "test( /*Argument 1*/\n" + |
"{\n" + |
" 'Value1': '1'\n" + |
"}, /*Argument 2\n" + |
" */\n" + |
"{\n" + |
" 'Value2': '2'\n" + |
"});", |
# expected |
"test( /*Argument 1*/\n" + |
" {\n" + |
" 'Value1': '1'\n" + |
" },\n" + |
" /*Argument 2\n" + |
" */\n" + |
" {\n" + |
" 'Value2': '2'\n" + |
" });") |
|
self.options.brace_style = 'collapse'; |
|
bt('//case 1\nif (a == 1) {}\n//case 2\nelse if (a == 2) {}') |
bt('if(1){2}else{3}', "if (1) {\n 2\n} else {\n 3\n}") |
bt('try{a();}catch(b){c();}catch(d){}finally{e();}', |
"try {\n a();\n} catch (b) {\n c();\n} catch (d) {} finally {\n e();\n}") |
bt('if(a){b();}else if(c) foo();', |
"if (a) {\n b();\n} else if (c) foo();") |
bt("if (a) {\n// comment\n}else{\n// comment\n}", |
"if (a) {\n // comment\n} else {\n // comment\n}") # if/else statement with empty body |
bt('if (x) {y} else { if (x) {y}}', |
'if (x) {\n y\n} else {\n if (x) {\n y\n }\n}') |
bt('if (a)\n{\nb;\n}\nelse\n{\nc;\n}', |
'if (a) {\n b;\n} else {\n c;\n}') |
test_fragment(' /*\n* xx\n*/\n// xx\nif (foo) {\n bar();\n}', |
' /*\n * xx\n */\n // xx\n if (foo) {\n bar();\n }') |
bt('if (foo) {} else /regex/.test();') |
test_fragment('if (foo) {', 'if (foo) {') |
test_fragment('foo {', 'foo {') |
test_fragment('return {', 'return {') # return needs the brace. |
test_fragment('return /* inline */ {', 'return /* inline */ {') |
test_fragment('return;\n{', 'return; {') |
bt("throw {}") |
bt("throw {\n foo;\n}") |
bt('var foo = {}') |
bt('function x() {\n foo();\n}zzz', 'function x() {\n foo();\n}\nzzz') |
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 a() {};') |
bt('var a = new function()\n{};', 'var a = new function() {};') |
bt('var a = new function a()\n{};', 'var a = new function a() {};') |
bt('var a = new function a()\n {},\n b = new function b()\n {};', 'var a = new function a() {},\n b = new function b() {};') |
bt("foo({\n 'a': 1\n},\n10);", |
"foo({\n 'a': 1\n },\n 10);") |
bt('(["foo","bar"]).each(function(i) {return i;});', |
'(["foo", "bar"]).each(function(i) {\n return i;\n});') |
bt('(function(i) {return i;})();', |
'(function(i) {\n return i;\n})();') |
bt( "test( /*Argument 1*/ {\n" + |
" 'Value1': '1'\n" + |
"}, /*Argument 2\n" + |
" */ {\n" + |
" 'Value2': '2'\n" + |
"});", |
# expected |
"test( /*Argument 1*/ {\n" + |
" 'Value1': '1'\n" + |
" },\n" + |
" /*Argument 2\n" + |
" */\n" + |
" {\n" + |
" 'Value2': '2'\n" + |
" });") |
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" + |
" });") |
bt( "test( /*Argument 1*/\n" + |
"{\n" + |
" 'Value1': '1'\n" + |
"}, /*Argument 2\n" + |
" */\n" + |
"{\n" + |
" 'Value2': '2'\n" + |
"});", |
# expected |
"test( /*Argument 1*/ {\n" + |
" 'Value1': '1'\n" + |
" },\n" + |
" /*Argument 2\n" + |
" */\n" + |
" {\n" + |
" 'Value2': '2'\n" + |
" });") |
|
self.options.brace_style = "end-expand"; |
|
bt('//case 1\nif (a == 1) {}\n//case 2\nelse if (a == 2) {}') |
bt('if(1){2}else{3}', "if (1) {\n 2\n}\nelse {\n 3\n}") |
bt('try{a();}catch(b){c();}catch(d){}finally{e();}', |
"try {\n a();\n}\ncatch (b) {\n c();\n}\ncatch (d) {}\nfinally {\n e();\n}") |
bt('if(a){b();}else if(c) foo();', |
"if (a) {\n b();\n}\nelse if (c) foo();") |
bt("if (a) {\n// comment\n}else{\n// comment\n}", |
"if (a) {\n // comment\n}\nelse {\n // comment\n}") # if/else statement with empty body |
bt('if (x) {y} else { if (x) {y}}', |
'if (x) {\n y\n}\nelse {\n if (x) {\n y\n }\n}') |
bt('if (a)\n{\nb;\n}\nelse\n{\nc;\n}', |
'if (a) {\n b;\n}\nelse {\n c;\n}') |
test_fragment(' /*\n* xx\n*/\n// xx\nif (foo) {\n bar();\n}', |
' /*\n * xx\n */\n // xx\n if (foo) {\n bar();\n }') |
bt('if (foo) {}\nelse /regex/.test();') |
test_fragment('if (foo) {', 'if (foo) {') |
test_fragment('foo {', 'foo {') |
test_fragment('return {', 'return {') # return needs the brace. |
test_fragment('return /* inline */ {', 'return /* inline */ {') |
test_fragment('return;\n{', 'return; {') |
bt("throw {}") |
bt("throw {\n foo;\n}") |
bt('var foo = {}') |
bt('function x() {\n foo();\n}zzz', 'function x() {\n foo();\n}\nzzz') |
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 a() {};') |
bt('var a = new function()\n{};', 'var a = new function() {};') |
bt('var a = new function a()\n{};', 'var a = new function a() {};') |
bt('var a = new function a()\n {},\n b = new function b()\n {};', 'var a = new function a() {},\n b = new function b() {};') |
bt("foo({\n 'a': 1\n},\n10);", |
"foo({\n 'a': 1\n },\n 10);") |
bt('(["foo","bar"]).each(function(i) {return i;});', |
'(["foo", "bar"]).each(function(i) {\n return i;\n});') |
bt('(function(i) {return i;})();', |
'(function(i) {\n return i;\n})();') |
bt( "test( /*Argument 1*/ {\n" + |
" 'Value1': '1'\n" + |
"}, /*Argument 2\n" + |
" */ {\n" + |
" 'Value2': '2'\n" + |
"});", |
# expected |
"test( /*Argument 1*/ {\n" + |
" 'Value1': '1'\n" + |
" },\n" + |
" /*Argument 2\n" + |
" */\n" + |
" {\n" + |
" 'Value2': '2'\n" + |
" });") |
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" + |
" });") |
bt( "test( /*Argument 1*/\n" + |
"{\n" + |
" 'Value1': '1'\n" + |
"}, /*Argument 2\n" + |
" */\n" + |
"{\n" + |
" 'Value2': '2'\n" + |
"});", |
# expected |
"test( /*Argument 1*/ {\n" + |
" 'Value1': '1'\n" + |
" },\n" + |
" /*Argument 2\n" + |
" */\n" + |
" {\n" + |
" 'Value2': '2'\n" + |
" });") |
|
self.options.brace_style = 'none'; |
|
bt('//case 1\nif (a == 1)\n{}\n//case 2\nelse if (a == 2)\n{}') |
bt('if(1){2}else{3}', "if (1) {\n 2\n} else {\n 3\n}") |
bt('try{a();}catch(b){c();}catch(d){}finally{e();}', |
"try {\n a();\n} catch (b) {\n c();\n} catch (d) {} finally {\n e();\n}") |
bt('if(a){b();}else if(c) foo();', |
"if (a) {\n b();\n} else if (c) foo();") |
bt("if (a) {\n// comment\n}else{\n// comment\n}", |
"if (a) {\n // comment\n} else {\n // comment\n}") # if/else statement with empty body |
bt('if (x) {y} else { if (x) {y}}', |
'if (x) {\n y\n} else {\n if (x) {\n y\n }\n}') |
bt('if (a)\n{\nb;\n}\nelse\n{\nc;\n}', |
'if (a)\n{\n b;\n}\nelse\n{\n c;\n}') |
test_fragment(' /*\n* xx\n*/\n// xx\nif (foo) {\n bar();\n}', |
' /*\n * xx\n */\n // xx\n if (foo) {\n bar();\n }') |
bt('if (foo)\n{}\nelse /regex/.test();') |
test_fragment('if (foo) {') |
test_fragment('foo {') |
test_fragment('return {') # return needs the brace. |
test_fragment('return /* inline */ {') |
test_fragment('return;\n{') |
bt("throw {}") |
bt("throw {\n foo;\n}") |
bt('var foo = {}') |
bt('function x() {\n foo();\n}zzz', 'function x() {\n foo();\n}\nzzz') |
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 a() {};') |
bt('var a = new function()\n{};', 'var a = new function() {};') |
bt('var a = new function a()\n{};') |
bt('var a = new function a()\n {},\n b = new function b()\n {};') |
bt("foo({\n 'a': 1\n},\n10);", |
"foo({\n 'a': 1\n },\n 10);") |
bt('(["foo","bar"]).each(function(i) {return i;});', |
'(["foo", "bar"]).each(function(i) {\n return i;\n});') |
bt('(function(i) {return i;})();', |
'(function(i) {\n return i;\n})();') |
bt( "test( /*Argument 1*/ {\n" + |
" 'Value1': '1'\n" + |
"}, /*Argument 2\n" + |
" */ {\n" + |
" 'Value2': '2'\n" + |
"});", |
# expected |
"test( /*Argument 1*/ {\n" + |
" 'Value1': '1'\n" + |
" },\n" + |
" /*Argument 2\n" + |
" */\n" + |
" {\n" + |
" 'Value2': '2'\n" + |
" });") |
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" + |
" });") |
bt( "test( /*Argument 1*/\n" + |
"{\n" + |
" 'Value1': '1'\n" + |
"}, /*Argument 2\n" + |
" */\n" + |
"{\n" + |
" 'Value2': '2'\n" + |
"});", |
# expected |
"test( /*Argument 1*/\n" + |
" {\n" + |
" 'Value1': '1'\n" + |
" },\n" + |
" /*Argument 2\n" + |
" */\n" + |
" {\n" + |
" 'Value2': '2'\n" + |
" });") |
# END tests for brace position |
|
self.reset_options(); |
#============================================================ |
test_fragment('roo = {\n /*\n ****\n FOO\n ****\n */\n BAR: 0\n};') |
test_fragment("if (zz) {\n // ....\n}\n(function") |
|
self.reset_options(); |
#============================================================ |
self.options.preserve_newlines = True; |
bt('var a = 42; // foo\n\nvar b;') |
bt('var a = 42; // foo\n\n\nvar b;') |
bt("var a = 'foo' +\n 'bar';") |
bt("var a = \"foo\" +\n \"bar\";") |
|
bt('"foo""bar""baz"', '"foo"\n"bar"\n"baz"') |
bt("'foo''bar''baz'", "'foo'\n'bar'\n'baz'") |
bt("{\n get foo() {}\n}") |
bt("{\n var a = get\n foo();\n}") |
bt("{\n set foo() {}\n}") |
bt("{\n var a = set\n foo();\n}") |
bt("var x = {\n get function()\n}") |
bt("var x = {\n set function()\n}") |
|
# According to my current research get/set have no special meaning outside of an object literal |
bt("var x = set\n\na() {}", "var x = set\n\na() {}") |
bt("var x = set\n\nfunction() {}", "var x = set\n\nfunction() {}") |
|
bt('<!-- foo\nbar();\n-->') |
bt('<!-- dont crash') # --> |
bt('for () /abc/.test()') |
bt('if (k) /aaa/m.test(v) && l();') |
bt('switch (true) {\n case /swf/i.test(foo):\n bar();\n}') |
bt('createdAt = {\n type: Date,\n default: Date.now\n}') |
bt('switch (createdAt) {\n case a:\n Date,\n default:\n Date.now\n}') |
|
bt('return function();') |
bt('var a = function();') |
bt('var a = 5 + function();') |
|
bt('{\n foo // something\n ,\n bar // something\n baz\n}') |
bt('function a(a) {} function b(b) {} function c(c) {}', 'function a(a) {}\n\nfunction b(b) {}\n\nfunction c(c) {}') |
|
|
bt('import foo.*;', 'import foo.*;') # actionscript's import |
test_fragment('function f(a: a, b: b)') # actionscript |
bt('foo(a, function() {})') |
bt('foo(a, /regex/)') |
|
bt('/* foo */\n"x"') |
|
self.reset_options(); |
#============================================================ |
self.options.break_chained_methods = False |
self.options.preserve_newlines = False |
bt('foo\n.bar()\n.baz().cucumber(fat)', 'foo.bar().baz().cucumber(fat)') |
bt('foo\n.bar()\n.baz().cucumber(fat); foo.bar().baz().cucumber(fat)', 'foo.bar().baz().cucumber(fat);\nfoo.bar().baz().cucumber(fat)') |
bt('foo\n.bar()\n.baz().cucumber(fat)\n foo.bar().baz().cucumber(fat)', 'foo.bar().baz().cucumber(fat)\nfoo.bar().baz().cucumber(fat)') |
bt('this\n.something = foo.bar()\n.baz().cucumber(fat)', 'this.something = foo.bar().baz().cucumber(fat)') |
bt('this.something.xxx = foo.moo.bar()') |
bt('this\n.something\n.xxx = foo.moo\n.bar()', 'this.something.xxx = foo.moo.bar()') |
|
self.options.break_chained_methods = False |
self.options.preserve_newlines = True |
bt('foo\n.bar()\n.baz().cucumber(fat)', 'foo\n .bar()\n .baz().cucumber(fat)') |
bt('foo\n.bar()\n.baz().cucumber(fat); foo.bar().baz().cucumber(fat)', 'foo\n .bar()\n .baz().cucumber(fat);\nfoo.bar().baz().cucumber(fat)') |
bt('foo\n.bar()\n.baz().cucumber(fat)\n foo.bar().baz().cucumber(fat)', 'foo\n .bar()\n .baz().cucumber(fat)\nfoo.bar().baz().cucumber(fat)') |
bt('this\n.something = foo.bar()\n.baz().cucumber(fat)', 'this\n .something = foo.bar()\n .baz().cucumber(fat)') |
bt('this.something.xxx = foo.moo.bar()') |
bt('this\n.something\n.xxx = foo.moo\n.bar()', 'this\n .something\n .xxx = foo.moo\n .bar()') |
|
self.options.break_chained_methods = True |
self.options.preserve_newlines = False |
bt('foo\n.bar()\n.baz().cucumber(fat)', 'foo.bar()\n .baz()\n .cucumber(fat)') |
bt('foo\n.bar()\n.baz().cucumber(fat); foo.bar().baz().cucumber(fat)', 'foo.bar()\n .baz()\n .cucumber(fat);\nfoo.bar()\n .baz()\n .cucumber(fat)') |
bt('foo\n.bar()\n.baz().cucumber(fat)\n foo.bar().baz().cucumber(fat)', 'foo.bar()\n .baz()\n .cucumber(fat)\nfoo.bar()\n .baz()\n .cucumber(fat)') |
bt('this\n.something = foo.bar()\n.baz().cucumber(fat)', 'this.something = foo.bar()\n .baz()\n .cucumber(fat)') |
bt('this.something.xxx = foo.moo.bar()') |
bt('this\n.something\n.xxx = foo.moo\n.bar()', 'this.something.xxx = foo.moo.bar()') |
|
self.options.break_chained_methods = True |
self.options.preserve_newlines = True |
bt('foo\n.bar()\n.baz().cucumber(fat)', 'foo\n .bar()\n .baz()\n .cucumber(fat)') |
bt('foo\n.bar()\n.baz().cucumber(fat); foo.bar().baz().cucumber(fat)', 'foo\n .bar()\n .baz()\n .cucumber(fat);\nfoo.bar()\n .baz()\n .cucumber(fat)') |
bt('foo\n.bar()\n.baz().cucumber(fat)\n foo.bar().baz().cucumber(fat)', 'foo\n .bar()\n .baz()\n .cucumber(fat)\nfoo.bar()\n .baz()\n .cucumber(fat)') |
bt('this\n.something = foo.bar()\n.baz().cucumber(fat)', 'this\n .something = foo.bar()\n .baz()\n .cucumber(fat)') |
bt('this.something.xxx = foo.moo.bar()') |
bt('this\n.something\n.xxx = foo.moo\n.bar()', 'this\n .something\n .xxx = foo.moo\n .bar()') |
|
self.reset_options(); |
#============================================================ |
# Line wrap test intputs |
#..............---------1---------2---------3---------4---------5---------6---------7 |
#..............1234567890123456789012345678901234567890123456789012345678901234567890 |
wrap_input_1=('foo.bar().baz().cucumber((fat && "sassy") || (leans && mean));\n' + |
'Test_very_long_variable_name_this_should_never_wrap\n.but_this_can\n' + |
'return between_return_and_expression_should_never_wrap.but_this_can\n' + |
'throw between_throw_and_expression_should_never_wrap.but_this_can\n' + |
'if (wraps_can_occur && inside_an_if_block) that_is_\n.okay();\n' + |
'object_literal = {\n' + |
' propertx: first_token + 12345678.99999E-6,\n' + |
' property: first_token_should_never_wrap + but_this_can,\n' + |
' propertz: first_token_should_never_wrap + !but_this_can,\n' + |
' proper: "first_token_should_never_wrap" + "but_this_can"\n' + |
'}') |
|
#..............---------1---------2---------3---------4---------5---------6---------7 |
#..............1234567890123456789012345678901234567890123456789012345678901234567890 |
wrap_input_2=('{\n' + |
' foo.bar().baz().cucumber((fat && "sassy") || (leans && mean));\n' + |
' Test_very_long_variable_name_this_should_never_wrap\n.but_this_can\n' + |
' return between_return_and_expression_should_never_wrap.but_this_can\n' + |
' throw between_throw_and_expression_should_never_wrap.but_this_can\n' + |
' if (wraps_can_occur && inside_an_if_block) that_is_\n.okay();\n' + |
' object_literal = {\n' + |
' propertx: first_token + 12345678.99999E-6,\n' + |
' property: first_token_should_never_wrap + but_this_can,\n' + |
' propertz: first_token_should_never_wrap + !but_this_can,\n' + |
' proper: "first_token_should_never_wrap" + "but_this_can"\n' + |
' }' + |
'}') |
|
self.options.preserve_newlines = False |
self.options.wrap_line_length = 0 |
#..............---------1---------2---------3---------4---------5---------6---------7 |
#..............1234567890123456789012345678901234567890123456789012345678901234567890 |
test_fragment(wrap_input_1, |
# expected # |
'foo.bar().baz().cucumber((fat && "sassy") || (leans && mean));\n' + |
'Test_very_long_variable_name_this_should_never_wrap.but_this_can\n' + |
'return between_return_and_expression_should_never_wrap.but_this_can\n' + |
'throw between_throw_and_expression_should_never_wrap.but_this_can\n' + |
'if (wraps_can_occur && inside_an_if_block) that_is_.okay();\n' + |
'object_literal = {\n' + |
' propertx: first_token + 12345678.99999E-6,\n' + |
' property: first_token_should_never_wrap + but_this_can,\n' + |
' propertz: first_token_should_never_wrap + !but_this_can,\n' + |
' proper: "first_token_should_never_wrap" + "but_this_can"\n' + |
'}') |
|
self.options.wrap_line_length = 70 |
#..............---------1---------2---------3---------4---------5---------6---------7 |
#..............1234567890123456789012345678901234567890123456789012345678901234567890 |
test_fragment(wrap_input_1, |
# expected # |
'foo.bar().baz().cucumber((fat && "sassy") || (leans && mean));\n' + |
'Test_very_long_variable_name_this_should_never_wrap.but_this_can\n' + |
'return between_return_and_expression_should_never_wrap.but_this_can\n' + |
'throw between_throw_and_expression_should_never_wrap.but_this_can\n' + |
'if (wraps_can_occur && inside_an_if_block) that_is_.okay();\n' + |
'object_literal = {\n' + |
' propertx: first_token + 12345678.99999E-6,\n' + |
' property: first_token_should_never_wrap + but_this_can,\n' + |
' propertz: first_token_should_never_wrap + !but_this_can,\n' + |
' proper: "first_token_should_never_wrap" + "but_this_can"\n' + |
'}') |
|
self.options.wrap_line_length = 40 |
#..............---------1---------2---------3---------4---------5---------6---------7 |
#..............1234567890123456789012345678901234567890123456789012345678901234567890 |
test_fragment(wrap_input_1, |
# expected # |
'foo.bar().baz().cucumber((fat &&\n' + |
' "sassy") || (leans && mean));\n' + |
'Test_very_long_variable_name_this_should_never_wrap\n' + |
' .but_this_can\n' + |
'return between_return_and_expression_should_never_wrap\n' + |
' .but_this_can\n' + |
'throw between_throw_and_expression_should_never_wrap\n' + |
' .but_this_can\n' + |
'if (wraps_can_occur &&\n' + |
' inside_an_if_block) that_is_.okay();\n' + |
'object_literal = {\n' + |
' propertx: first_token +\n' + |
' 12345678.99999E-6,\n' + |
' property: first_token_should_never_wrap +\n' + |
' but_this_can,\n' + |
' propertz: first_token_should_never_wrap +\n' + |
' !but_this_can,\n' + |
' proper: "first_token_should_never_wrap" +\n' + |
' "but_this_can"\n' + |
'}') |
|
self.options.wrap_line_length = 41 |
# NOTE: wrap is only best effort - line continues until next wrap point is found. |
#..............---------1---------2---------3---------4---------5---------6---------7 |
#..............1234567890123456789012345678901234567890123456789012345678901234567890 |
test_fragment(wrap_input_1, |
# expected # |
'foo.bar().baz().cucumber((fat && "sassy") ||\n' + |
' (leans && mean));\n' + |
'Test_very_long_variable_name_this_should_never_wrap\n' + |
' .but_this_can\n' + |
'return between_return_and_expression_should_never_wrap\n' + |
' .but_this_can\n' + |
'throw between_throw_and_expression_should_never_wrap\n' + |
' .but_this_can\n' + |
'if (wraps_can_occur &&\n' + |
' inside_an_if_block) that_is_.okay();\n' + |
'object_literal = {\n' + |
' propertx: first_token +\n' + |
' 12345678.99999E-6,\n' + |
' property: first_token_should_never_wrap +\n' + |
' but_this_can,\n' + |
' propertz: first_token_should_never_wrap +\n' + |
' !but_this_can,\n' + |
' proper: "first_token_should_never_wrap" +\n' + |
' "but_this_can"\n' + |
'}') |
|
|
self.options.wrap_line_length = 45 |
# NOTE: wrap is only best effort - line continues until next wrap point is found. |
#..............---------1---------2---------3---------4---------5---------6---------7 |
#..............1234567890123456789012345678901234567890123456789012345678901234567890 |
test_fragment(wrap_input_2, |
# expected # |
'{\n' + |
' foo.bar().baz().cucumber((fat && "sassy") ||\n' + |
' (leans && mean));\n' + |
' Test_very_long_variable_name_this_should_never_wrap\n' + |
' .but_this_can\n' + |
' return between_return_and_expression_should_never_wrap\n' + |
' .but_this_can\n' + |
' throw between_throw_and_expression_should_never_wrap\n' + |
' .but_this_can\n' + |
' if (wraps_can_occur &&\n' + |
' inside_an_if_block) that_is_.okay();\n' + |
' object_literal = {\n' + |
' propertx: first_token +\n' + |
' 12345678.99999E-6,\n' + |
' property: first_token_should_never_wrap +\n' + |
' but_this_can,\n' + |
' propertz: first_token_should_never_wrap +\n' + |
' !but_this_can,\n' + |
' proper: "first_token_should_never_wrap" +\n' + |
' "but_this_can"\n' + |
' }\n'+ |
'}') |
|
self.options.preserve_newlines = True |
self.options.wrap_line_length = 0 |
#..............---------1---------2---------3---------4---------5---------6---------7 |
#..............1234567890123456789012345678901234567890123456789012345678901234567890 |
test_fragment(wrap_input_1, |
# expected # |
'foo.bar().baz().cucumber((fat && "sassy") || (leans && mean));\n' + |
'Test_very_long_variable_name_this_should_never_wrap\n' + |
' .but_this_can\n' + |
'return between_return_and_expression_should_never_wrap.but_this_can\n' + |
'throw between_throw_and_expression_should_never_wrap.but_this_can\n' + |
'if (wraps_can_occur && inside_an_if_block) that_is_\n' + |
' .okay();\n' + |
'object_literal = {\n' + |
' propertx: first_token + 12345678.99999E-6,\n' + |
' property: first_token_should_never_wrap + but_this_can,\n' + |
' propertz: first_token_should_never_wrap + !but_this_can,\n' + |
' proper: "first_token_should_never_wrap" + "but_this_can"\n' + |
'}') |
|
|
self.options.wrap_line_length = 70 |
#..............---------1---------2---------3---------4---------5---------6---------7 |
#..............1234567890123456789012345678901234567890123456789012345678901234567890 |
test_fragment(wrap_input_1, |
# expected # |
'foo.bar().baz().cucumber((fat && "sassy") || (leans && mean));\n' + |
'Test_very_long_variable_name_this_should_never_wrap\n' + |
' .but_this_can\n' + |
'return between_return_and_expression_should_never_wrap.but_this_can\n' + |
'throw between_throw_and_expression_should_never_wrap.but_this_can\n' + |
'if (wraps_can_occur && inside_an_if_block) that_is_\n' + |
' .okay();\n' + |
'object_literal = {\n' + |
' propertx: first_token + 12345678.99999E-6,\n' + |
' property: first_token_should_never_wrap + but_this_can,\n' + |
' propertz: first_token_should_never_wrap + !but_this_can,\n' + |
' proper: "first_token_should_never_wrap" + "but_this_can"\n' + |
'}') |
|
|
self.options.wrap_line_length = 40 |
#..............---------1---------2---------3---------4---------5---------6---------7 |
#..............1234567890123456789012345678901234567890123456789012345678901234567890 |
test_fragment(wrap_input_1, |
# expected # |
'foo.bar().baz().cucumber((fat &&\n' + |
' "sassy") || (leans && mean));\n' + |
'Test_very_long_variable_name_this_should_never_wrap\n' + |
' .but_this_can\n' + |
'return between_return_and_expression_should_never_wrap\n' + |
' .but_this_can\n' + |
'throw between_throw_and_expression_should_never_wrap\n' + |
' .but_this_can\n' + |
'if (wraps_can_occur &&\n' + |
' inside_an_if_block) that_is_\n' + |
' .okay();\n' + |
'object_literal = {\n' + |
' propertx: first_token +\n' + |
' 12345678.99999E-6,\n' + |
' property: first_token_should_never_wrap +\n' + |
' but_this_can,\n' + |
' propertz: first_token_should_never_wrap +\n' + |
' !but_this_can,\n' + |
' proper: "first_token_should_never_wrap" +\n' + |
' "but_this_can"\n' + |
'}') |
|
self.options.wrap_line_length = 41 |
# NOTE: wrap is only best effort - line continues until next wrap point is found. |
#..............---------1---------2---------3---------4---------5---------6---------7 |
#..............1234567890123456789012345678901234567890123456789012345678901234567890 |
test_fragment(wrap_input_1, |
# expected # |
'foo.bar().baz().cucumber((fat && "sassy") ||\n' + |
' (leans && mean));\n' + |
'Test_very_long_variable_name_this_should_never_wrap\n' + |
' .but_this_can\n' + |
'return between_return_and_expression_should_never_wrap\n' + |
' .but_this_can\n' + |
'throw between_throw_and_expression_should_never_wrap\n' + |
' .but_this_can\n' + |
'if (wraps_can_occur &&\n' + |
' inside_an_if_block) that_is_\n' + |
' .okay();\n' + |
'object_literal = {\n' + |
' propertx: first_token +\n' + |
' 12345678.99999E-6,\n' + |
' property: first_token_should_never_wrap +\n' + |
' but_this_can,\n' + |
' propertz: first_token_should_never_wrap +\n' + |
' !but_this_can,\n' + |
' proper: "first_token_should_never_wrap" +\n' + |
' "but_this_can"\n' + |
'}') |
|
self.options.wrap_line_length = 45 |
# NOTE: wrap is only best effort - line continues until next wrap point is found. |
#..............---------1---------2---------3---------4---------5---------6---------7 |
#..............1234567890123456789012345678901234567890123456789012345678901234567890 |
test_fragment(wrap_input_2, |
# expected # |
'{\n' + |
' foo.bar().baz().cucumber((fat && "sassy") ||\n' + |
' (leans && mean));\n' + |
' Test_very_long_variable_name_this_should_never_wrap\n' + |
' .but_this_can\n' + |
' return between_return_and_expression_should_never_wrap\n' + |
' .but_this_can\n' + |
' throw between_throw_and_expression_should_never_wrap\n' + |
' .but_this_can\n' + |
' if (wraps_can_occur &&\n' + |
' inside_an_if_block) that_is_\n' + |
' .okay();\n' + |
' object_literal = {\n' + |
' propertx: first_token +\n' + |
' 12345678.99999E-6,\n' + |
' property: first_token_should_never_wrap +\n' + |
' but_this_can,\n' + |
' propertz: first_token_should_never_wrap +\n' + |
' !but_this_can,\n' + |
' proper: "first_token_should_never_wrap" +\n' + |
' "but_this_can"\n' + |
' }\n'+ |
'}') |
|
self.reset_options(); |
#============================================================ |
self.options.preserve_newlines = False |
bt('if (foo) // comment\n bar();') |
bt('if (foo) // comment\n (bar());') |
bt('if (foo) // comment\n (bar());') |
bt('if (foo) // comment\n /asdf/;') |
bt('this.oa = new OAuth(\n' + |
' _requestToken,\n' + |
' _accessToken,\n' + |
' consumer_key\n' + |
');', |
'this.oa = new OAuth(_requestToken, _accessToken, consumer_key);') |
bt('foo = {\n x: y, // #44\n w: z // #44\n}') |
bt('switch (x) {\n case "a":\n // comment on newline\n break;\n case "b": // comment on same line\n break;\n}') |
bt('this.type =\n this.options =\n // comment\n this.enabled null;', |
'this.type = this.options =\n // comment\n this.enabled null;') |
bt('someObj\n .someFunc1()\n // This comment should not break the indent\n .someFunc2();', |
'someObj.someFunc1()\n // This comment should not break the indent\n .someFunc2();') |
|
bt('if (true ||\n!true) return;', 'if (true || !true) return;') |
|
# these aren't ready yet. |
#bt('if (foo) // comment\n bar() /*i*/ + baz() /*j\n*/ + asdf();') |
bt('if\n(foo)\nif\n(bar)\nif\n(baz)\nwhee();\na();', |
'if (foo)\n if (bar)\n if (baz) whee();\na();') |
bt('if\n(foo)\nif\n(bar)\nif\n(baz)\nwhee();\nelse\na();', |
'if (foo)\n if (bar)\n if (baz) whee();\n else a();') |
bt('if (foo)\nbar();\nelse\ncar();', |
'if (foo) bar();\nelse car();') |
|
bt('if (foo) if (bar) if (baz);\na();', |
'if (foo)\n if (bar)\n if (baz);\na();') |
bt('if (foo) if (bar) if (baz) whee();\na();', |
'if (foo)\n if (bar)\n if (baz) whee();\na();') |
bt('if (foo) a()\nif (bar) if (baz) whee();\na();', |
'if (foo) a()\nif (bar)\n if (baz) whee();\na();') |
bt('if (foo);\nif (bar) if (baz) whee();\na();', |
'if (foo);\nif (bar)\n if (baz) whee();\na();') |
bt('if (options)\n' + |
' for (var p in options)\n' + |
' this[p] = options[p];', |
'if (options)\n'+ |
' for (var p in options) this[p] = options[p];') |
bt('if (options) for (var p in options) this[p] = options[p];', |
'if (options)\n for (var p in options) this[p] = options[p];') |
|
bt('if (options) do q(); while (b());', |
'if (options)\n do q(); while (b());') |
bt('if (options) while (b()) q();', |
'if (options)\n while (b()) q();') |
bt('if (options) do while (b()) q(); while (a());', |
'if (options)\n do\n while (b()) q(); while (a());') |
|
bt('function f(a, b, c,\nd, e) {}', |
'function f(a, b, c, d, e) {}') |
|
bt('function f(a,b) {if(a) b()}function g(a,b) {if(!a) b()}', |
'function f(a, b) {\n if (a) b()\n}\n\nfunction g(a, b) {\n if (!a) b()\n}') |
bt('function f(a,b) {if(a) b()}\n\n\n\nfunction g(a,b) {if(!a) b()}', |
'function f(a, b) {\n if (a) b()\n}\n\nfunction g(a, b) {\n if (!a) b()\n}') |
# This is not valid syntax, but still want to behave reasonably and not side-effect |
bt('(if(a) b())(if(a) b())', |
'(\n if (a) b())(\n if (a) b())') |
bt('(if(a) b())\n\n\n(if(a) b())', |
'(\n if (a) b())\n(\n if (a) b())') |
|
# space between functions |
bt('/*\n * foo\n */\nfunction foo() {}') |
bt('// a nice function\nfunction foo() {}') |
bt('function foo() {}\nfunction foo() {}', |
'function foo() {}\n\nfunction foo() {}' |
) |
|
bt('[\n function() {}\n]') |
|
|
bt("if\n(a)\nb();", "if (a) b();") |
bt('var a =\nfoo', 'var a = foo') |
bt('var a = {\n"a":1,\n"b":2}', "var a = {\n \"a\": 1,\n \"b\": 2\n}") |
bt("var a = {\n'a':1,\n'b':2}", "var a = {\n 'a': 1,\n 'b': 2\n}") |
bt('var a = /*i*/ "b";') |
bt('var a = /*i*/\n"b";', 'var a = /*i*/ "b";') |
bt('var a = /*i*/\nb;', 'var a = /*i*/ b;') |
bt('{\n\n\n"x"\n}', '{\n "x"\n}') |
bt('if(a &&\nb\n||\nc\n||d\n&&\ne) e = f', 'if (a && b || c || d && e) e = f') |
bt('if(a &&\n(b\n||\nc\n||d)\n&&\ne) e = f', 'if (a && (b || c || d) && e) e = f') |
test_fragment('\n\n"x"', '"x"') |
bt('a = 1;\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\nb = 2;', |
'a = 1;\nb = 2;') |
|
|
self.options.preserve_newlines = True |
bt('if (foo) // comment\n bar();') |
bt('if (foo) // comment\n (bar());') |
bt('if (foo) // comment\n (bar());') |
bt('if (foo) // comment\n /asdf/;') |
bt('this.oa = new OAuth(\n' + |
' _requestToken,\n' + |
' _accessToken,\n' + |
' consumer_key\n' + |
');') |
bt('foo = {\n x: y, // #44\n w: z // #44\n}') |
bt('switch (x) {\n case "a":\n // comment on newline\n break;\n case "b": // comment on same line\n break;\n}') |
bt('this.type =\n this.options =\n // comment\n this.enabled null;') |
bt('someObj\n .someFunc1()\n // This comment should not break the indent\n .someFunc2();') |
|
bt('if (true ||\n!true) return;', 'if (true ||\n !true) return;') |
|
# these aren't ready yet. |
# bt('if (foo) // comment\n bar() /*i*/ + baz() /*j\n*/ + asdf();') |
bt('if\n(foo)\nif\n(bar)\nif\n(baz)\nwhee();\na();', |
'if (foo)\n if (bar)\n if (baz)\n whee();\na();') |
bt('if\n(foo)\nif\n(bar)\nif\n(baz)\nwhee();\nelse\na();', |
'if (foo)\n if (bar)\n if (baz)\n whee();\n else\n a();') |
bt('if (foo)\nbar();\nelse\ncar();', |
'if (foo)\n bar();\nelse\n car();') |
bt('if (foo) bar();\nelse\ncar();', |
'if (foo) bar();\nelse\n car();') |
|
bt('if (foo) if (bar) if (baz);\na();', |
'if (foo)\n if (bar)\n if (baz);\na();') |
bt('if (foo) if (bar) if (baz) whee();\na();', |
'if (foo)\n if (bar)\n if (baz) whee();\na();') |
bt('if (foo) a()\nif (bar) if (baz) whee();\na();', |
'if (foo) a()\nif (bar)\n if (baz) whee();\na();') |
bt('if (foo);\nif (bar) if (baz) whee();\na();', |
'if (foo);\nif (bar)\n if (baz) whee();\na();') |
bt('if (options)\n' + |
' for (var p in options)\n' + |
' this[p] = options[p];') |
bt('if (options) for (var p in options) this[p] = options[p];', |
'if (options)\n for (var p in options) this[p] = options[p];') |
|
bt('if (options) do q(); while (b());', |
'if (options)\n do q(); while (b());') |
bt('if (options) do; while (b());', |
'if (options)\n do; while (b());') |
bt('if (options) while (b()) q();', |
'if (options)\n while (b()) q();') |
bt('if (options) do while (b()) q(); while (a());', |
'if (options)\n do\n while (b()) q(); while (a());') |
|
bt('function f(a, b, c,\nd, e) {}', |
'function f(a, b, c,\n d, e) {}') |
|
bt('function f(a,b) {if(a) b()}function g(a,b) {if(!a) b()}', |
'function f(a, b) {\n if (a) b()\n}\n\nfunction g(a, b) {\n if (!a) b()\n}') |
bt('function f(a,b) {if(a) b()}\n\n\n\nfunction g(a,b) {if(!a) b()}', |
'function f(a, b) {\n if (a) b()\n}\n\n\n\nfunction g(a, b) {\n if (!a) b()\n}') |
# This is not valid syntax, but still want to behave reasonably and not side-effect |
bt('(if(a) b())(if(a) b())', |
'(\n if (a) b())(\n if (a) b())') |
bt('(if(a) b())\n\n\n(if(a) b())', |
'(\n if (a) b())\n\n\n(\n if (a) b())') |
|
|
bt("if\n(a)\nb();", "if (a)\n b();") |
bt('var a =\nfoo', 'var a =\n foo') |
bt('var a = {\n"a":1,\n"b":2}', "var a = {\n \"a\": 1,\n \"b\": 2\n}") |
bt("var a = {\n'a':1,\n'b':2}", "var a = {\n 'a': 1,\n 'b': 2\n}") |
bt('var a = /*i*/ "b";') |
bt('var a = /*i*/\n"b";', 'var a = /*i*/\n "b";') |
bt('var a = /*i*/\nb;', 'var a = /*i*/\n b;') |
bt('{\n\n\n"x"\n}', '{\n\n\n "x"\n}') |
bt('if(a &&\nb\n||\nc\n||d\n&&\ne) e = f', 'if (a &&\n b ||\n c ||\n d &&\n e) e = f') |
bt('if(a &&\n(b\n||\nc\n||d)\n&&\ne) e = f', 'if (a &&\n (b ||\n c ||\n d) &&\n e) e = f') |
test_fragment('\n\n"x"', '"x"') |
# this beavior differs between js and python, defaults to unlimited in js, 10 in python |
bt('a = 1;\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\nb = 2;', |
'a = 1;\n\n\n\n\n\n\n\n\n\nb = 2;') |
self.options.max_preserve_newlines = 8; |
bt('a = 1;\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\nb = 2;', |
'a = 1;\n\n\n\n\n\n\n\nb = 2;') |
|
self.reset_options(); |
#============================================================ |
|
|
def decodesto(self, input, expectation=None): |
if expectation == None: |
expectation = input |
|
self.assertMultiLineEqual( |
jsbeautifier.beautify(input, self.options), expectation) |
|
# if the expected is different from input, run it again |
# expected output should be unchanged when run twice. |
if not expectation == None: |
self.assertMultiLineEqual( |
jsbeautifier.beautify(expectation, self.options), expectation) |
|
# Everywhere we do newlines, they should be replaced with opts.eol |
self.options.eol = '\r\\n'; |
expectation = expectation.replace('\n', '\r\n') |
self.assertMultiLineEqual( |
jsbeautifier.beautify(input, self.options), expectation) |
if input.find('\n') != -1: |
input = input.replace('\n', '\r\n') |
self.assertMultiLineEqual( |
jsbeautifier.beautify(input, self.options), expectation) |
# Ensure support for auto eol detection |
self.options.eol = 'auto' |
self.assertMultiLineEqual( |
jsbeautifier.beautify(input, self.options), expectation) |
self.options.eol = '\n' |
|
def wrap(self, text): |
return self.wrapregex.sub(' \\1', text) |
|
def bt(self, input, expectation=None): |
if expectation == None: |
expectation = input |
|
self.decodesto(input, expectation) |
# If we set raw, input should be unchanged |
self.options.test_output_raw = True |
if self.options.end_with_newline: |
elf.decodesto(input, input) |
self.options.test_output_raw = False |
|
current_indent_size = None |
if self.options.js and self.options.js['indent_size']: |
current_indent_size = self.options.js['indent_size'] |
|
if not current_indent_size: |
current_indent_size = self.options.indent_size |
|
if current_indent_size == 4 and input: |
wrapped_input = '{\n%s\n foo = bar;\n}' % self.wrap(input) |
wrapped_expect = '{\n%s\n foo = bar;\n}' % self.wrap(expectation) |
self.decodesto(wrapped_input, wrapped_expect) |
|
# If we set raw, input should be unchanged |
self.options.test_output_raw = True |
if self.options.end_with_newline: |
elf.decodesto(wrapped_input, wrapped_input) |
self.options.test_output_raw = False |
|
|
if __name__ == '__main__': |
unittest.main() |
/script-kiddie/002_script_kiddie/script-kiddie/node_modules/js-beautify/test/data/javascript/tests.js |
@@ -0,0 +1,3083 @@ |
/* |
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. |
*/ |
|
var inputlib = require('./inputlib'); |
|
exports.test_data = { |
default_options: [ |
{ name: "indent_size", value: "4" }, |
{ name: "indent_char", value: "' '" }, |
{ name: "preserve_newlines", value: "true" }, |
{ name: "jslint_happy", value: "false" }, |
{ name: "keep_array_indentation", value: "false" }, |
{ name: "brace_style", value: "'collapse'" }, |
{ name: "operator_position", value: "'before-newline'" } |
], |
groups: [{ |
name: "Unicode Support", |
description: "", |
tests: [{ |
unchanged: "var ' + unicode_char(3232) + '_' + unicode_char(3232) + ' = \"hi\";" |
}, { |
unchanged: [ |
"var ' + unicode_char(228) + 'x = {", |
" ' + unicode_char(228) + 'rgerlich: true", |
"};" |
] |
}] |
}, { |
name: "Test template and continuation strings", |
description: "", |
tests: [ |
{ unchanged: '`This is a ${template} string.`' }, |
{ unchanged: '`This\n is\n a\n ${template}\n string.`' }, |
{ unchanged: 'a = `This is a continuation\\\\\nstring.`' }, |
{ unchanged: 'a = "This is a continuation\\\\\nstring."' }, |
{ unchanged: '`SELECT\n nextval(\\\'${this.options.schema ? `${this.options.schema}.` : \\\'\\\'}"${this.tableName}_${this.autoIncrementField}_seq"\\\'::regclass\n ) nextval;`' }, |
{ |
comment: 'Tests for #1030', |
unchanged: [ |
'const composeUrl = (host) => {', |
' return `${host `test`}`;', |
'};' |
] |
}, { |
unchanged: [ |
'const composeUrl = (host, api, key, data) => {', |
' switch (api) {', |
' case "Init":', |
' return `${host}/vwapi/Init?VWID=${key}&DATA=${encodeURIComponent(', |
' Object.keys(data).map((k) => `${k}=${ data[k]}` ).join(";")', |
' )}`;', |
' case "Pay":', |
' return `${host}/vwapi/Pay?SessionId=${par}`;', |
' };', |
'};' |
] |
} |
] |
}, { |
name: "ES7 Decorators", |
description: "Permit ES7 decorators, which are invoked with a leading \"@\".", |
tests: [ |
{ unchanged: '@foo' }, |
{ unchanged: '@foo(bar)' }, |
{ |
unchanged: [ |
'@foo(function(k, v) {', |
' implementation();', |
'})' |
] |
} |
] |
}, { |
name: "ES7 exponential", |
description: "ES7 exponential", |
tests: [ |
{ unchanged: 'x ** 2' }, |
{ unchanged: 'x ** -2' } |
] |
}, { |
name: "Spread operator", |
description: "Spread operator", |
options: [ |
{ name: 'brace_style', value: '"collapse,preserve-inline"' } |
], |
tests: [ |
{ unchanged: 'const m = { ...item, c: 3 };' }, |
{ unchanged: 'const m = {\n ...item,\n c: 3\n};' }, |
{ unchanged: 'const m = { c: 3, ...item };' }, |
{ unchanged: 'const m = [...item, 3];' }, |
{ unchanged: 'const m = [3, ...item];' } |
] |
}, { |
name: "Object literal shorthand functions", |
description: "Object literal shorthand functions", |
tests: [ |
{ unchanged: 'return {\n foo() {\n return 42;\n }\n}' }, |
{ |
unchanged: [ |
'var foo = {', |
' * bar() {', |
' yield 42;', |
' }', |
'};' |
] |
}, |
{ |
input: 'var foo = {bar(){return 42;},*barGen(){yield 42;}};', |
output: ['var foo = {', |
' bar() {', |
' return 42;', |
' },', |
' * barGen() {', |
' yield 42;', |
' }', |
'};' |
] |
}, { |
comment: 'also handle generator shorthand in class - #1013', |
unchanged: [ |
'class A {', |
' fn() {', |
' return true;', |
' }', |
'', |
' * gen() {', |
' return true;', |
' }', |
'}' |
] |
}, { |
unchanged: [ |
'class A {', |
' * gen() {', |
' return true;', |
' }', |
'', |
' fn() {', |
' return true;', |
' }', |
'}' |
] |
} |
] |
}, { |
name: "End With Newline", |
description: "", |
matrix: [{ |
options: [ |
{ name: "end_with_newline", value: "true" } |
], |
eof: '\n' |
}, { |
options: [ |
{ name: "end_with_newline", value: "false" } |
], |
eof: '' |
} |
|
], |
tests: [ |
{ fragment: true, input: '', output: '{{eof}}' }, |
{ fragment: true, input: ' return .5', output: ' return .5{{eof}}' }, |
{ fragment: true, input: ' \n\nreturn .5\n\n\n\n', output: ' return .5{{eof}}' }, |
{ fragment: true, input: '\n', output: '{{eof}}' } |
], |
}, { |
name: "Support simple language specific option inheritance/overriding", |
description: "Support simple language specific option inheritance/overriding", |
matrix: [{ |
options: [ |
{ name: "js", value: "{ 'indent_size': 3 }" }, |
{ name: "css", value: "{ 'indent_size': 5 }" } |
], |
j: ' ' |
}, |
{ |
options: [ |
{ name: "html", value: "{ 'js': { 'indent_size': 3 }, 'css': { 'indent_size': 5 } }" } |
], |
j: ' ' |
}, |
{ |
options: [ |
{ name: "indent_size", value: "9" }, |
{ name: "html", value: "{ 'js': { 'indent_size': 3 }, 'css': { 'indent_size': 5 }, 'indent_size': 2}" }, |
{ name: "js", value: "{ 'indent_size': 4 }" }, |
{ name: "css", value: "{ 'indent_size': 3 }" } |
], |
j: ' ' |
} |
], |
tests: [{ |
unchanged: [ |
'if (a == b) {', |
'{{j}}test();', |
'}' |
] |
}, ] |
}, { |
name: "Brace style permutations", |
description: "", |
template: "< >", |
matrix: [ |
// brace_style collapse,preserve-inline - Should preserve if no newlines |
{ |
options: [ |
{ name: "brace_style", value: "'collapse,preserve-inline'" } |
], |
ibo: '', |
iao: '', |
ibc: '', |
iac: '', |
obo: ' ', |
oao: ' ', |
obc: ' ', |
oac: ' ' |
}, |
{ |
options: [ |
{ name: "brace_style", value: "'collapse,preserve-inline'" } |
], |
ibo: '\n', |
iao: '\n', |
ibc: '\n', |
iac: '\n', |
obo: ' ', |
oao: '\n ', |
obc: '\n', |
oac: ' ' |
}, |
|
// brace_style collapse - Shouldn't preserve if no newlines (uses collapse styling) |
{ |
options: [ |
{ name: "brace_style", value: "'collapse'" } |
], |
ibo: '', |
iao: '', |
ibc: '', |
iac: '', |
obo: ' ', |
oao: '\n ', |
obc: '\n', |
oac: ' ' |
}, |
{ |
options: [ |
{ name: "brace_style", value: "'collapse'" } |
], |
ibo: '\n', |
iao: '\n', |
ibc: '\n', |
iac: '\n', |
obo: ' ', |
oao: '\n ', |
obc: '\n', |
oac: ' ' |
}, |
], |
tests: [{ |
input: 'var a =<ibo>{<iao>a: 2<ibc>}<iac>;\nvar a =<ibo>{<iao>a: 2<ibc>}<iac>;', |
output: 'var a =<obo>{<oao>a: 2<obc>};\nvar a =<obo>{<oao>a: 2<obc>};' |
}, |
// { |
// input: 'var a =<ibo>{<iao>a:<ibo>{<iao>a:<ibo>{<iao>a:2<ibc>}<iac><ibc>}<iac>}<iac>;\nvar a =<ibo>{<iao>a:<ibo>{<iao>a:<ibo>{<iao>a:2<ibc>}<iac><ibc>}<iac>}<iac>;', |
// output: 'var a =<obo>{<oao>a:<obo>{<oao>a:<obo>{<oao>a: 2<obc>}<oac><obc>}<oac><obc>};\nvar a =<obo>{<oao>a:<obo>{<oao>a:<obo>{<oao>a: 2<obc>}<oac><obc>}<oac><obc>};' |
// }, |
{ |
input: '//case 1\nif (a == 1)<ibo>{}\n//case 2\nelse if (a == 2)<ibo>{}', |
output: '//case 1\nif (a == 1)<obo>{}\n//case 2\nelse if (a == 2)<obo>{}' |
}, |
{ |
input: 'if(1)<ibo>{<iao>2<ibc>}<iac>else<ibo>{<iao>3<ibc>}', |
output: 'if (1)<obo>{<oao>2<obc>}<oac>else<obo>{<oao>3<obc>}' |
}, |
{ |
input: 'try<ibo>{<iao>a();<ibc>}<iac>' + |
'catch(b)<ibo>{<iao>c();<ibc>}<iac>' + |
'catch(d)<ibo>{}<iac>' + |
'finally<ibo>{<iao>e();<ibc>}', |
output: |
// expected |
'try<obo>{<oao>a();<obc>}<oac>' + |
'catch (b)<obo>{<oao>c();<obc>}<oac>' + |
'catch (d)<obo>{}<oac>' + |
'finally<obo>{<oao>e();<obc>}' |
} |
], |
}, { |
name: "Comma-first option", |
description: "Put commas at the start of lines instead of the end", |
matrix: [{ |
options: [ |
{ name: "comma_first", value: "false" } |
], |
c0: ',\n', |
c1: ',\n ', |
c2: ',\n ', |
c3: ',\n ', |
// edge cases where engine bails |
f1: ' ,\n ' |
}, { |
options: [ |
{ name: "comma_first", value: "true" } |
], |
c0: '\n, ', |
c1: '\n , ', |
c2: '\n , ', |
c3: '\n , ', |
// edge cases where engine bails |
f1: ', ' |
}], |
tests: [ |
{ input: '{a:1, b:2}', output: "{\n a: 1{{c1}}b: 2\n}" }, |
{ input: 'var a=1, b=c[d], e=6;', output: 'var a = 1{{c1}}b = c[d]{{c1}}e = 6;' }, |
{ input: "for(var a=1,b=2,c=3;d<3;d++)\ne", output: "for (var a = 1, b = 2, c = 3; d < 3; d++)\n e" }, |
{ input: "for(var a=1,b=2,\nc=3;d<3;d++)\ne", output: "for (var a = 1, b = 2{{c2}}c = 3; d < 3; d++)\n e" }, |
{ unchanged: 'function foo() {\n return [\n "one"{{c2}}"two"\n ];\n}' }, |
{ input: 'a=[[1,2],[4,5],[7,8]]', output: "a = [\n [1, 2]{{c1}}[4, 5]{{c1}}[7, 8]\n]" }, |
{ input: 'a=[[1,2],[4,5],[7,8],]', output: "a = [\n [1, 2]{{c1}}[4, 5]{{c1}}[7, 8]{{c0}}]" }, |
{ |
input: 'a=[[1,2],[4,5],function(){},[7,8]]', |
output: "a = [\n [1, 2]{{c1}}[4, 5]{{c1}}function() {}{{c1}}[7, 8]\n]" |
}, |
{ |
input: 'a=[[1,2],[4,5],function(){},function(){},[7,8]]', |
output: "a = [\n [1, 2]{{c1}}[4, 5]{{c1}}function() {}{{c1}}function() {}{{c1}}[7, 8]\n]" |
}, |
{ |
input: 'a=[[1,2],[4,5],function(){},[7,8]]', |
output: "a = [\n [1, 2]{{c1}}[4, 5]{{c1}}function() {}{{c1}}[7, 8]\n]" |
}, |
{ |
input: 'a=[b,c,function(){},function(){},d]', |
output: "a = [b, c, function() {}, function() {}, d]" |
}, |
{ |
input: 'a=[b,c,\nfunction(){},function(){},d]', |
output: "a = [b, c{{c1}}function() {}{{c1}}function() {}{{c1}}d\n]" |
}, |
{ input: 'a=[a[1],b[4],c[d[7]]]', output: "a = [a[1], b[4], c[d[7]]]" }, |
{ input: '[1,2,[3,4,[5,6],7],8]', output: "[1, 2, [3, 4, [5, 6], 7], 8]" }, |
|
{ |
input: '[[["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"]{{c2}}["3", "4"]\n ]{{c1}}[\n ["5", "6", "7"]{{c2}}["8", "9", "0"]\n ]{{c1}}[\n ["1", "2", "3"]{{c2}}["4", "5", "6", "7"]{{c2}}["8", "9", "0"]\n ]\n]' |
}, |
{ |
input: [ |
'changeCollection.add({', |
' name: "Jonathan" // New line inserted after this line on every save', |
' , age: 25', |
'});' |
], |
output: [ |
'changeCollection.add({', |
' name: "Jonathan" // New line inserted after this line on every save', |
' {{f1}}age: 25', |
'});' |
] |
}, |
{ |
input: [ |
'changeCollection.add(', |
' function() {', |
' return true;', |
' },', |
' function() {', |
' return true;', |
' }', |
');' |
], |
output: [ |
'changeCollection.add(', |
' function() {', |
' return true;', |
' }{{c1}}function() {', |
' return true;', |
' }', |
');' |
] |
}, |
], |
}, { |
name: "Space in parens tests", |
description: "put space inside parens", |
matrix: [{ |
options: [ |
{ name: "space_in_paren", value: "false" }, |
{ name: "space_in_empty_paren", value: "false" }, |
], |
s: '', |
e: '', |
}, { |
options: [ |
{ name: "space_in_paren", value: "false" }, |
{ name: "space_in_empty_paren", value: "true" }, |
], |
s: '', |
e: '', |
}, { |
options: [ |
{ name: "space_in_paren", value: "true" }, |
{ name: "space_in_empty_paren", value: "false" }, |
], |
s: ' ', |
e: '', |
}, { |
options: [ |
{ name: "space_in_paren", value: "true" }, |
{ name: "space_in_empty_paren", value: "true" }, |
], |
s: ' ', |
e: ' ', |
}], |
tests: [{ |
input: 'if(p) foo(a,b);', |
output: 'if ({{s}}p{{s}}) foo({{s}}a, b{{s}});' |
}, |
{ |
input: 'try{while(true){willThrow()}}catch(result)switch(result){case 1:++result }', |
output: 'try {\n while ({{s}}true{{s}}) {\n willThrow({{e}})\n }\n} catch ({{s}}result{{s}}) switch ({{s}}result{{s}}) {\n case 1:\n ++result\n}' |
}, |
{ |
input: '((e/((a+(b)*c)-d))^2)*5;', |
output: '({{s}}({{s}}e / ({{s}}({{s}}a + ({{s}}b{{s}}) * c{{s}}) - d{{s}}){{s}}) ^ 2{{s}}) * 5;' |
}, |
{ |
input: 'function f(a,b) {if(a) b()}function g(a,b) {if(!a) b()}', |
output: 'function f({{s}}a, b{{s}}) {\n if ({{s}}a{{s}}) b({{e}})\n}\n\nfunction g({{s}}a, b{{s}}) {\n if ({{s}}!a{{s}}) b({{e}})\n}' |
}, |
{ |
input: 'a=[];', |
output: 'a = [{{e}}];' |
}, |
{ |
input: 'a=[b,c,d];', |
output: 'a = [{{s}}b, c, d{{s}}];' |
}, |
{ |
input: 'a= f[b];', |
output: 'a = f[{{s}}b{{s}}];' |
}, |
{ |
input: [ |
'{', |
' files: [ {', |
' expand: true,', |
' cwd: "www/gui/",', |
' src: [ "im/design_standards/*.*" ],', |
' dest: "www/gui/build"', |
' } ]', |
'}' |
], |
output: [ |
'{', |
' files: [{{s}}{', |
' expand: true,', |
' cwd: "www/gui/",', |
' src: [{{s}}"im/design_standards/*.*"{{s}}],', |
' dest: "www/gui/build"', |
' }{{s}}]', |
'}' |
], |
}, |
], |
}, { |
name: "operator_position option - ensure no neswlines if preserve_newlines is false", |
matrix: [{ |
options: [ |
{ name: "operator_position", value: "'before-newline'" }, |
{ name: "preserve_newlines", value: "false" } |
] |
}, { |
options: [ |
{ name: "operator_position", value: "'after-newline'" }, |
{ name: "preserve_newlines", value: "false" } |
] |
}, { |
options: [ |
{ name: "operator_position", value: "'preserve-newline'" }, |
{ name: "preserve_newlines", value: "false" } |
] |
}], |
tests: [{ |
unchanged: inputlib.operator_position.sanity |
}, { |
input: inputlib.operator_position.comprehensive, |
output: inputlib.operator_position.sanity, |
}] |
}, { |
name: "operator_position option - set to 'before-newline' (default value)", |
tests: [{ |
comment: 'comprehensive, various newlines', |
input: inputlib.operator_position.comprehensive, |
output: [ |
'var res = a + b -', |
' c /', |
' d * e %', |
' f;', |
'var res = g & h |', |
' i ^', |
' j;', |
'var res = (k &&', |
' l ||', |
' m) ?', |
' n :', |
' o;', |
'var res = p >>', |
' q <<', |
' r >>>', |
' s;', |
'var res = t', |
'', |
' ===', |
' u !== v !=', |
' w ==', |
' x >=', |
' y <= z > aa <', |
' ab;', |
'ac +', |
' -ad' |
] |
}, { |
comment: 'colon special case', |
input: inputlib.operator_position.colon_special_case, |
output: [ |
'var a = {', |
' b: bval,', |
' c: cval,', |
' d: dval', |
'};', |
'var e = f ? g :', |
' h;', |
'var i = j ? k :', |
' l;' |
] |
}, { |
comment: 'catch-all, includes brackets and other various code', |
input: inputlib.operator_position.catch_all, |
output: [ |
'var d = 1;', |
'if (a === b &&', |
' c) {', |
' d = (c * everything /', |
' something_else) %', |
' b;', |
' e', |
' += d;', |
'', |
'} else if (!(complex && simple) ||', |
' (emotion && emotion.name === "happy")) {', |
' cryTearsOfJoy(many ||', |
' anOcean ||', |
' aRiver);', |
'}' |
] |
}] |
}, { |
name: "operator_position option - set to 'after_newline'", |
options: [{ |
name: "operator_position", |
value: "'after-newline'" |
}], |
tests: [{ |
comment: 'comprehensive, various newlines', |
input: inputlib.operator_position.comprehensive, |
output: [ |
'var res = a + b', |
' - c', |
' / d * e', |
' % f;', |
'var res = g & h', |
' | i', |
' ^ j;', |
'var res = (k', |
' && l', |
' || m)', |
' ? n', |
' : o;', |
'var res = p', |
' >> q', |
' << r', |
' >>> s;', |
'var res = t', |
'', |
' === u !== v', |
' != w', |
' == x', |
' >= y <= z > aa', |
' < ab;', |
'ac', |
' + -ad' |
] |
}, { |
comment: 'colon special case', |
input: inputlib.operator_position.colon_special_case, |
output: [ |
'var a = {', |
' b: bval,', |
' c: cval,', |
' d: dval', |
'};', |
'var e = f ? g', |
' : h;', |
'var i = j ? k', |
' : l;' |
] |
}, { |
comment: 'catch-all, includes brackets and other various code', |
input: inputlib.operator_position.catch_all, |
output: [ |
'var d = 1;', |
'if (a === b', |
' && c) {', |
' d = (c * everything', |
' / something_else)', |
' % b;', |
' e', |
' += d;', |
'', |
'} else if (!(complex && simple)', |
' || (emotion && emotion.name === "happy")) {', |
' cryTearsOfJoy(many', |
' || anOcean', |
' || aRiver);', |
'}' |
] |
}] |
}, { |
name: "operator_position option - set to 'preserve-newline'", |
options: [{ |
name: "operator_position", |
value: "'preserve-newline'" |
}], |
tests: [{ |
comment: 'comprehensive, various newlines', |
input: inputlib.operator_position.comprehensive, |
output: [ |
'var res = a + b', |
' - c /', |
' d * e', |
' %', |
' f;', |
'var res = g & h', |
' | i ^', |
' j;', |
'var res = (k &&', |
' l', |
' || m) ?', |
' n', |
' : o;', |
'var res = p', |
' >> q <<', |
' r', |
' >>> s;', |
'var res = t', |
'', |
' === u !== v', |
' !=', |
' w', |
' == x >=', |
' y <= z > aa <', |
' ab;', |
'ac +', |
' -ad' |
] |
}, { |
comment: 'colon special case', |
input: inputlib.operator_position.colon_special_case, |
output: [ |
'var a = {', |
' b: bval,', |
' c: cval,', |
' d: dval', |
'};', |
'var e = f ? g', |
' : h;', |
'var i = j ? k :', |
' l;' |
] |
}, { |
comment: 'catch-all, includes brackets and other various code', |
unchanged: inputlib.operator_position.catch_all |
}] |
}, { |
name: "Yield tests", |
description: "ES6 yield tests", |
tests: [ |
{ unchanged: 'yield /foo\\\\//;' }, |
{ unchanged: 'result = yield pgClient.query_(queryString);' }, |
{ unchanged: 'yield [1, 2]' }, |
{ unchanged: "yield* bar();" }, |
{ |
comment: "yield should have no space between yield and star", |
input: "yield * bar();", |
output: "yield* bar();" |
}, |
{ |
comment: "yield should have space between star and generator", |
input: "yield *bar();", |
output: "yield* bar();" |
} |
] |
}, { |
name: "Async / await tests", |
description: "ES7 async / await tests", |
tests: [ |
{ unchanged: "async function foo() {}" }, |
{ unchanged: "let w = async function foo() {}" }, |
{ unchanged: "async function foo() {}\nvar x = await foo();" }, |
{ |
comment: "async function as an input to another function", |
unchanged: "wrapper(async function foo() {})" |
}, |
{ |
comment: "await on inline anonymous function. should have a space after await", |
input_: "async function() {\n var w = await(async function() {\n return await foo();\n })();\n}", |
output: "async function() {\n var w = await (async function() {\n return await foo();\n })();\n}" |
}, |
{ |
comment: "ensure that this doesn't break anyone with the async library", |
unchanged: "async.map(function(t) {})" |
} |
] |
}, { |
name: "e4x - Test that e4x literals passed through when e4x-option is enabled", |
description: "", |
options: [ |
{ name: 'e4x', value: true } |
], |
tests: [ |
{ input: 'xml=<a b="c"><d/><e>\n foo</e>x</a>;', output: 'xml = <a b="c"><d/><e>\n foo</e>x</a>;' }, |
{ unchanged: '<a b=\\\'This is a quoted "c".\\\'/>' }, |
{ unchanged: '<a b="This is a quoted \\\'c\\\'."/>' }, |
{ unchanged: '<a b="A quote \\\' inside string."/>' }, |
{ unchanged: '<a b=\\\'A quote " inside string.\\\'/>' }, |
{ unchanged: '<a b=\\\'Some """ quotes "" inside string.\\\'/>' }, |
|
{ |
comment: 'Handles inline expressions', |
input: 'xml=<{a} b="c"><d/><e v={z}>\n foo</e>x</{a}>;', |
output: 'xml = <{a} b="c"><d/><e v={z}>\n foo</e>x</{a}>;' |
}, |
{ |
input: 'xml=<{a} b="c">\n <e v={z}>\n foo</e>x</{a}>;', |
output: 'xml = <{a} b="c">\n <e v={z}>\n foo</e>x</{a}>;' |
}, |
{ |
comment: 'xml literals with special characters in elem names - see http://www.w3.org/TR/REC-xml/#NT-NameChar', |
unchanged: 'xml = <_:.valid.xml- _:.valid.xml-="123"/>;' |
}, |
{ |
comment: 'xml literals with attributes without equal sign', |
unchanged: 'xml = <elem someAttr/>;' |
}, |
|
{ |
comment: 'Handles CDATA', |
input: 'xml=<![CDATA[ b="c"><d/><e v={z}>\n foo</e>x/]]>;', |
output: 'xml = <![CDATA[ b="c"><d/><e v={z}>\n foo</e>x/]]>;' |
}, |
{ input: 'xml=<![CDATA[]]>;', output: 'xml = <![CDATA[]]>;' }, |
{ input: 'xml=<a b="c"><![CDATA[d/></a></{}]]></a>;', output: 'xml = <a b="c"><![CDATA[d/></a></{}]]></a>;' }, |
|
{ |
comment: 'JSX - working jsx from http://prettydiff.com/unit_tests/beautification_javascript_jsx.txt', |
unchanged: [ |
'var ListItem = React.createClass({', |
' render: function() {', |
' return (', |
' <li className="ListItem">', |
' <a href={ "/items/" + this.props.item.id }>', |
' this.props.item.name', |
' </a>', |
' </li>', |
' );', |
' }', |
'});' |
] |
}, |
{ |
unchanged: [ |
'var List = React.createClass({', |
' renderList: function() {', |
' return this.props.items.map(function(item) {', |
' return <ListItem item={item} key={item.id} />;', |
' });', |
' },', |
'', |
' render: function() {', |
' return <ul className="List">', |
' this.renderList()', |
' </ul>', |
' }', |
'});' |
] |
}, |
{ |
unchanged: [ |
'var Mist = React.createClass({', |
' renderList: function() {', |
' return this.props.items.map(function(item) {', |
' return <ListItem item={return <tag>{item}</tag>} key={item.id} />;', |
' });', |
' }', |
'});', |
] |
}, |
{ |
unchanged: [ |
'// JSX', |
'var box = <Box>', |
' {shouldShowAnswer(user) ?', |
' <Answer value={false}>no</Answer> : <Box.Comment>', |
' Text Content', |
' </Box.Comment>}', |
' </Box>;', |
'var a = function() {', |
' return <tsdf>asdf</tsdf>;', |
'};', |
'', |
'var HelloMessage = React.createClass({', |
' render: function() {', |
' return <div {someAttr}>Hello {this.props.name}</div>;', |
' }', |
'});', |
'React.render(<HelloMessage name="John" />, mountNode);', |
] |
}, |
{ |
unchanged: [ |
'var Timer = React.createClass({', |
' getInitialState: function() {', |
' return {', |
' secondsElapsed: 0', |
' };', |
' },', |
' tick: function() {', |
' this.setState({', |
' secondsElapsed: this.state.secondsElapsed + 1', |
' });', |
' },', |
' componentDidMount: function() {', |
' this.interval = setInterval(this.tick, 1000);', |
' },', |
' componentWillUnmount: function() {', |
' clearInterval(this.interval);', |
' },', |
' render: function() {', |
' return (', |
' <div>Seconds Elapsed: {this.state.secondsElapsed}</div>', |
' );', |
' }', |
'});', |
'React.render(<Timer />, mountNode);' |
] |
}, |
{ |
unchanged: [ |
'var TodoList = React.createClass({', |
' render: function() {', |
' var createItem = function(itemText) {', |
' return <li>{itemText}</li>;', |
' };', |
' return <ul>{this.props.items.map(createItem)}</ul>;', |
' }', |
'});' |
] |
}, |
{ |
unchanged: [ |
'var TodoApp = React.createClass({', |
' getInitialState: function() {', |
' return {', |
' items: [],', |
' text: \\\'\\\'', |
' };', |
' },', |
' onChange: function(e) {', |
' this.setState({', |
' text: e.target.value', |
' });', |
' },', |
' handleSubmit: function(e) {', |
' e.preventDefault();', |
' var nextItems = this.state.items.concat([this.state.text]);', |
' var nextText = \\\'\\\';', |
' this.setState({', |
' items: nextItems,', |
' text: nextText', |
' });', |
' },', |
' render: function() {', |
' return (', |
' <div>', |
' <h3 {someAttr}>TODO</h3>', |
' <TodoList items={this.state.items} />', |
' <form onSubmit={this.handleSubmit}>', |
' <input onChange={this.onChange} value={this.state.text} />', |
' <button>{\\\'Add #\\\' + (this.state.items.length + 1)}</button>', |
' </form>', |
' </div>', |
' );', |
' }', |
'});', |
'React.render(<TodoApp />, mountNode);' |
] |
}, |
{ |
input: [ |
'var converter = new Showdown.converter();', |
'var MarkdownEditor = React.createClass({', |
' getInitialState: function() {', |
' return {value: \\\'Type some *markdown* here!\\\'};', |
' },', |
' handleChange: function() {', |
' this.setState({value: this.refs.textarea.getDOMNode().value});', |
' },', |
' render: function() {', |
' return (', |
' <div className="MarkdownEditor">', |
' <h3>Input</h3>', |
' <textarea', |
' onChange={this.handleChange}', |
' ref="textarea"', |
' defaultValue={this.state.value} />', |
' <h3>Output</h3>', |
' <div', |
' className="content"', |
' dangerouslySetInnerHTML={{', |
' __html: converter.makeHtml(this.state.value)', |
' }}', |
' />', |
' </div>', |
' );', |
' }', |
'});', |
'React.render(<MarkdownEditor />, mountNode);' |
|
], |
output: [ |
'var converter = new Showdown.converter();', |
'var MarkdownEditor = React.createClass({', |
' getInitialState: function() {', |
' return {', |
' value: \\\'Type some *markdown* here!\\\'', |
' };', |
' },', |
' handleChange: function() {', |
' this.setState({', |
' value: this.refs.textarea.getDOMNode().value', |
' });', |
' },', |
' render: function() {', |
' return (', |
' <div className="MarkdownEditor">', |
' <h3>Input</h3>', |
' <textarea', |
' onChange={this.handleChange}', |
' ref="textarea"', |
' defaultValue={this.state.value} />', |
' <h3>Output</h3>', |
' <div', |
' className="content"', |
' dangerouslySetInnerHTML={{', |
' __html: converter.makeHtml(this.state.value)', |
' }}', |
' />', |
' </div>', |
' );', |
' }', |
'});', |
'React.render(<MarkdownEditor />, mountNode);' |
] |
}, |
{ |
comment: 'JSX - Not quite correct jsx formatting that still works', |
input: [ |
'var content = (', |
' <Nav>', |
' {/* child comment, put {} around */}', |
' <Person', |
' /* multi', |
' line', |
' comment */', |
' //attr="test"', |
' name={window.isLoggedIn ? window.name : \\\'\\\'} // end of line comment', |
' />', |
' </Nav>', |
' );', |
'var qwer = <DropDown> A dropdown list <Menu> <MenuItem>Do Something</MenuItem> <MenuItem>Do Something Fun!</MenuItem> <MenuItem>Do Something Else</MenuItem> </Menu> </DropDown>;', |
'render(dropdown);', |
], |
output: [ |
'var content = (', |
' <Nav>', |
' {/* child comment, put {} around */}', |
' <Person', |
' /* multi', |
' line', |
' comment */', |
' //attr="test"', |
' name={window.isLoggedIn ? window.name : \\\'\\\'} // end of line comment', |
' />', |
' </Nav>', |
');', |
'var qwer = <DropDown> A dropdown list <Menu> <MenuItem>Do Something</MenuItem> <MenuItem>Do Something Fun!</MenuItem> <MenuItem>Do Something Else</MenuItem> </Menu> </DropDown>;', |
'render(dropdown);', |
] |
}, |
{ |
comment: [ |
"Handles messed up tags, as long as it isn't the same name", |
"as the root tag. Also handles tags of same name as root tag", |
"as long as nesting matches." |
], |
input_: 'xml=<a x="jn"><c></b></f><a><d jnj="jnn"><f></a ></nj></a>;', |
output: 'xml = <a x="jn"><c></b></f><a><d jnj="jnn"><f></a ></nj></a>;' |
}, |
|
{ |
comment: [ |
"If xml is not terminated, the remainder of the file is treated", |
"as part of the xml-literal (passed through unaltered)" |
], |
fragment: true, |
input_: 'xml=<a></b>\nc<b;', |
output: 'xml = <a></b>\nc<b;' |
}, |
{ |
comment: 'Issue #646 = whitespace is allowed in attribute declarations', |
unchanged: [ |
'let a = React.createClass({', |
' render() {', |
' return (', |
' <p className=\\\'a\\\'>', |
' <span>c</span>', |
' </p>', |
' );', |
' }', |
'});' |
] |
}, |
{ |
unchanged: [ |
'let a = React.createClass({', |
' render() {', |
' return (', |
' <p className = \\\'b\\\'>', |
' <span>c</span>', |
' </p>', |
' );', |
' }', |
'});' |
] |
}, |
{ |
unchanged: [ |
'let a = React.createClass({', |
' render() {', |
' return (', |
' <p className = "c">', |
' <span>c</span>', |
' </p>', |
' );', |
' }', |
'});' |
] |
}, |
{ |
unchanged: [ |
'let a = React.createClass({', |
' render() {', |
' return (', |
' <{e} className = {d}>', |
' <span>c</span>', |
' </{e}>', |
' );', |
' }', |
'});' |
] |
}, |
{ |
comment: 'Issue #914 - Multiline attribute in root tag', |
unchanged: [ |
'return (', |
' <a href="#"', |
' onClick={e => {', |
' e.preventDefault()', |
' onClick()', |
' }}>', |
' {children}', |
' </a>', |
');' |
] |
}, |
{ |
unchanged: [ |
'return (', |
' <{', |
' a + b', |
' } href="#"', |
' onClick={e => {', |
' e.preventDefault()', |
' onClick()', |
' }}>', |
' {children}', |
' </{', |
' a + b', |
' }>', |
');' |
] |
}, |
{ |
input: [ |
'return (', |
' <{', |
' a + b', |
' } href="#"', |
' onClick={e => {', |
' e.preventDefault()', |
' onClick()', |
' }}>', |
' {children}', |
' </{a + b}>', |
' );' |
], |
output: [ |
'return (', |
' <{', |
' a + b', |
' } href="#"', |
' onClick={e => {', |
' e.preventDefault()', |
' onClick()', |
' }}>', |
' {children}', |
' </{a + b}>', |
');' |
] |
} |
] |
}, { |
name: "e4x disabled", |
description: "", |
options: [ |
{ name: 'e4x', value: false } |
], |
tests: [{ |
input_: 'xml=<a b="c"><d/><e>\n foo</e>x</a>;', |
output: 'xml = < a b = "c" > < d / > < e >\n foo < /e>x</a > ;' |
}] |
}, { |
name: "Multiple braces", |
description: "", |
template: "^^^ $$$", |
options: [], |
tests: [ |
{ input: '{{}/z/}', output: '{\n {}\n /z/\n}' } |
] |
}, { |
name: "Beautify preserve formatting", |
description: "Allow beautifier to preserve sections", |
tests: [ |
{ unchanged: "/* beautify preserve:start */\n/* beautify preserve:end */" }, |
{ unchanged: "/* beautify preserve:start */\n var a = 1;\n/* beautify preserve:end */" }, |
{ unchanged: "var a = 1;\n/* beautify preserve:start */\n var a = 1;\n/* beautify preserve:end */" }, |
{ unchanged: "/* beautify preserve:start */ {asdklgh;y;;{}dd2d}/* beautify preserve:end */" }, |
{ |
input_: "var a = 1;\n/* beautify preserve:start */\n var a = 1;\n/* beautify preserve:end */", |
output: "var a = 1;\n/* beautify preserve:start */\n var a = 1;\n/* beautify preserve:end */" |
}, |
{ |
input_: "var a = 1;\n /* beautify preserve:start */\n var a = 1;\n/* beautify preserve:end */", |
output: "var a = 1;\n/* beautify preserve:start */\n var a = 1;\n/* beautify preserve:end */" |
}, |
{ |
unchanged: [ |
'var a = {', |
' /* beautify preserve:start */', |
' one : 1', |
' two : 2,', |
' three : 3,', |
' ten : 10', |
' /* beautify preserve:end */', |
'};' |
] |
}, |
{ |
input: [ |
'var a = {', |
'/* beautify preserve:start */', |
' one : 1,', |
' two : 2,', |
' three : 3,', |
' ten : 10', |
'/* beautify preserve:end */', |
'};' |
], |
output: [ |
'var a = {', |
' /* beautify preserve:start */', |
' one : 1,', |
' two : 2,', |
' three : 3,', |
' ten : 10', |
'/* beautify preserve:end */', |
'};' |
] |
}, |
{ |
comment: 'one space before and after required, only single spaces inside.', |
input: [ |
'var a = {', |
'/* beautify preserve:start */', |
' one : 1,', |
' two : 2,', |
' three : 3,', |
' ten : 10', |
'};' |
], |
output: [ |
'var a = {', |
' /* beautify preserve:start */', |
' one: 1,', |
' two: 2,', |
' three: 3,', |
' ten: 10', |
'};' |
] |
}, |
{ |
input: [ |
'var a = {', |
'/*beautify preserve:start*/', |
' one : 1,', |
' two : 2,', |
' three : 3,', |
' ten : 10', |
'};' |
], |
output: [ |
'var a = {', |
' /*beautify preserve:start*/', |
' one: 1,', |
' two: 2,', |
' three: 3,', |
' ten: 10', |
'};' |
] |
}, |
{ |
input: [ |
'var a = {', |
'/*beautify preserve:start*/', |
' one : 1,', |
' two : 2,', |
' three : 3,', |
' ten : 10', |
'};' |
], |
output: [ |
'var a = {', |
' /*beautify preserve:start*/', |
' one: 1,', |
' two: 2,', |
' three: 3,', |
' ten: 10', |
'};' |
] |
}, |
|
{ |
comment: 'Directive: ignore', |
unchanged: "/* beautify ignore:start */\n/* beautify ignore:end */" |
}, |
{ unchanged: "/* beautify ignore:start */\n var a,,,{ 1;\n/* beautify ignore:end */" }, |
{ unchanged: "var a = 1;\n/* beautify ignore:start */\n var a = 1;\n/* beautify ignore:end */" }, |
{ unchanged: "/* beautify ignore:start */ {asdklgh;y;+++;dd2d}/* beautify ignore:end */" }, |
{ |
input_: "var a = 1;\n/* beautify ignore:start */\n var a,,,{ 1;\n/* beautify ignore:end */", |
output: "var a = 1;\n/* beautify ignore:start */\n var a,,,{ 1;\n/* beautify ignore:end */" |
}, |
{ |
input_: "var a = 1;\n /* beautify ignore:start */\n var a,,,{ 1;\n/* beautify ignore:end */", |
output: "var a = 1;\n/* beautify ignore:start */\n var a,,,{ 1;\n/* beautify ignore:end */" |
}, |
{ |
unchanged: [ |
'var a = {', |
' /* beautify ignore:start */', |
' one : 1', |
' two : 2,', |
' three : {', |
' ten : 10', |
' /* beautify ignore:end */', |
'};' |
] |
}, |
{ |
input: [ |
'var a = {', |
'/* beautify ignore:start */', |
' one : 1', |
' two : 2,', |
' three : {', |
' ten : 10', |
'/* beautify ignore:end */', |
'};' |
], |
output: [ |
'var a = {', |
' /* beautify ignore:start */', |
' one : 1', |
' two : 2,', |
' three : {', |
' ten : 10', |
'/* beautify ignore:end */', |
'};' |
] |
}, |
{ |
comment: 'Directives - multiple and interacting', |
input: [ |
'var a = {', |
'/* beautify preserve:start */', |
'/* beautify preserve:start */', |
' one : 1,', |
' /* beautify preserve:end */', |
' two : 2,', |
' three : 3,', |
'/* beautify preserve:start */', |
' ten : 10', |
'/* beautify preserve:end */', |
'};' |
], |
output: [ |
'var a = {', |
' /* beautify preserve:start */', |
'/* beautify preserve:start */', |
' one : 1,', |
' /* beautify preserve:end */', |
' two: 2,', |
' three: 3,', |
' /* beautify preserve:start */', |
' ten : 10', |
'/* beautify preserve:end */', |
'};' |
] |
}, |
{ |
input: [ |
'var a = {', |
'/* beautify ignore:start */', |
' one : 1', |
' /* beautify ignore:end */', |
' two : 2,', |
'/* beautify ignore:start */', |
' three : {', |
' ten : 10', |
'/* beautify ignore:end */', |
'};' |
], |
output: [ |
'var a = {', |
' /* beautify ignore:start */', |
' one : 1', |
' /* beautify ignore:end */', |
' two: 2,', |
' /* beautify ignore:start */', |
' three : {', |
' ten : 10', |
'/* beautify ignore:end */', |
'};' |
] |
}, |
{ |
comment: 'Starts can occur together, ignore:end must occur alone.', |
input: [ |
'var a = {', |
'/* beautify ignore:start */', |
' one : 1', |
' NOTE: ignore end block does not support starting other directives', |
' This does not match the ending the ignore...', |
' /* beautify ignore:end preserve:start */', |
' two : 2,', |
'/* beautify ignore:start */', |
' three : {', |
' ten : 10', |
' ==The next comment ends the starting ignore==', |
'/* beautify ignore:end */', |
'};' |
], |
output: [ |
'var a = {', |
' /* beautify ignore:start */', |
' one : 1', |
' NOTE: ignore end block does not support starting other directives', |
' This does not match the ending the ignore...', |
' /* beautify ignore:end preserve:start */', |
' two : 2,', |
'/* beautify ignore:start */', |
' three : {', |
' ten : 10', |
' ==The next comment ends the starting ignore==', |
'/* beautify ignore:end */', |
'};' |
] |
}, |
{ |
input: [ |
'var a = {', |
'/* beautify ignore:start preserve:start */', |
' one : {', |
' /* beautify ignore:end */', |
' two : 2,', |
' /* beautify ignore:start */', |
' three : {', |
'/* beautify ignore:end */', |
' ten : 10', |
' // This is all preserved', |
'};' |
], |
output: [ |
'var a = {', |
' /* beautify ignore:start preserve:start */', |
' one : {', |
' /* beautify ignore:end */', |
' two : 2,', |
' /* beautify ignore:start */', |
' three : {', |
'/* beautify ignore:end */', |
' ten : 10', |
' // This is all preserved', |
'};' |
] |
}, |
{ |
input: [ |
'var a = {', |
'/* beautify ignore:start preserve:start */', |
' one : {', |
' /* beautify ignore:end */', |
' two : 2,', |
' /* beautify ignore:start */', |
' three : {', |
'/* beautify ignore:end */', |
' ten : 10,', |
'/* beautify preserve:end */', |
' eleven: 11', |
'};' |
], |
output: [ |
'var a = {', |
' /* beautify ignore:start preserve:start */', |
' one : {', |
' /* beautify ignore:end */', |
' two : 2,', |
' /* beautify ignore:start */', |
' three : {', |
'/* beautify ignore:end */', |
' ten : 10,', |
'/* beautify preserve:end */', |
' eleven: 11', |
'};' |
] |
}, |
] |
}, { |
name: "Comments and tests", |
description: "Comments should be in the right indent and not side-ffect.", |
options: [], |
tests: [{ |
comment: '#913', |
|
unchanged: [ |
'class test {', |
' method1() {', |
' let resp = null;', |
' }', |
' /**', |
' * @param {String} id', |
' */', |
' method2(id) {', |
' let resp2 = null;', |
' }', |
'}' |
] |
}, |
{ |
comment: '#1090', |
unchanged: [ |
'for (var i = 0; i < 20; ++i) // loop', |
' if (i % 3) {', |
' console.log(i);', |
' }', |
'console.log("done");', |
] |
}, |
{ |
comment: '#1043', |
unchanged: [ |
'var o = {', |
' k: 0', |
'}', |
'// ...', |
'foo(o)', |
] |
}, |
{ |
comment: '#713 and #964', |
unchanged: [ |
'Meteor.call("foo", bar, function(err, result) {', |
' Session.set("baz", result.lorem)', |
'})', |
'//blah blah', |
] |
}, |
{ |
comment: '#815', |
unchanged: [ |
'foo()', |
'// this is a comment', |
'bar()', |
'', |
'const foo = 5', |
'// comment', |
'bar()', |
] |
}, |
{ |
comment: 'This shows current behavior. Note #1069 is not addressed yet.', |
unchanged: [ |
'if (modulus === 2) {', |
' // i might be odd here', |
' i += (i & 1);', |
' // now i is guaranteed to be even', |
' // this block is obviously about the statement above', |
'', |
' // #1069 This should attach to the block below', |
' // this comment is about the block after it.', |
'} else {', |
' // rounding up using integer arithmetic only', |
' if (i % modulus)', |
' i += modulus - (i % modulus);', |
' // now i is divisible by modulus', |
' // behavior of comments should be different for single statements vs block statements/expressions', |
'}', |
'', |
'if (modulus === 2)', |
' // i might be odd here', |
' i += (i & 1);', |
'// now i is guaranteed to be even', |
'// non-braced comments unindent immediately', |
'', |
'// this comment is about the block after it.', |
'else', |
' // rounding up using integer arithmetic only', |
' if (i % modulus)', |
' i += modulus - (i % modulus);', |
'// behavior of comments should be different for single statements vs block statements/expressions', |
] |
}, |
|
] |
}, { |
name: "Template Formatting", |
description: "Php (<?php ... ?>) and underscore.js templating treated as strings.", |
options: [], |
tests: [ |
{ unchanged: '<?=$view["name"]; ?>' }, |
{ unchanged: 'a = <?= external() ?>;' }, |
{ |
unchanged: [ |
'<?php', |
'for($i = 1; $i <= 100; $i++;) {', |
' #count to 100!', |
' echo($i . "</br>");', |
'}', |
'?>' |
] |
}, |
{ unchanged: 'a = <%= external() %>;' } |
] |
}, { |
name: "jslint and space after anon function", |
description: "jslint_happy and space_after_anon_function tests", |
matrix: [{ |
options: [ |
{ name: "jslint_happy", value: "true" }, |
{ name: "space_after_anon_function", value: "true" } |
], |
f: ' ', |
c: '' |
}, { |
options: [ |
{ name: "jslint_happy", value: "true" }, |
{ name: "space_after_anon_function", value: "false" } |
], |
f: ' ', |
c: '' |
}, { |
options: [ |
{ name: "jslint_happy", value: "false" }, |
{ name: "space_after_anon_function", value: "true" } |
], |
f: ' ', |
c: ' ' |
}, { |
options: [ |
{ name: "jslint_happy", value: "false" }, |
{ name: "space_after_anon_function", value: "false" } |
], |
f: '', |
c: ' ' |
} |
|
|
], |
tests: [{ |
input_: 'a=typeof(x)', |
output: 'a = typeof{{f}}(x)' |
}, |
{ |
input_: 'x();\n\nfunction(){}', |
output: 'x();\n\nfunction{{f}}() {}' |
}, |
{ |
input_: 'x();\n\nvar x = {\nx: function(){}\n}', |
output: 'x();\n\nvar x = {\n x: function{{f}}() {}\n}' |
}, |
{ |
input_: 'function () {\n var a, b, c, d, e = [],\n f;\n}', |
output: 'function{{f}}() {\n var a, b, c, d, e = [],\n f;\n}' |
}, |
|
{ |
input_: 'switch(x) {case 0: case 1: a(); break; default: break}', |
output: 'switch (x) {\n{{c}}case 0:\n{{c}}case 1:\n{{c}} a();\n{{c}} break;\n{{c}}default:\n{{c}} break\n}' |
}, |
{ |
input: 'switch(x){case -1:break;case !y:break;}', |
output: 'switch (x) {\n{{c}}case -1:\n{{c}} break;\n{{c}}case !y:\n{{c}} break;\n}' |
}, |
{ |
comment: 'typical greasemonkey start', |
fragment: true, |
unchanged: '// comment 2\n(function{{f}}()' |
}, |
|
{ |
input_: 'var a2, b2, c2, d2 = 0, c = function() {}, d = \\\'\\\';', |
output: 'var a2, b2, c2, d2 = 0,\n c = function{{f}}() {},\n d = \\\'\\\';' |
}, |
{ |
input_: 'var a2, b2, c2, d2 = 0, c = function() {},\nd = \\\'\\\';', |
output: 'var a2, b2, c2, d2 = 0,\n c = function{{f}}() {},\n d = \\\'\\\';' |
}, |
{ |
input_: 'var o2=$.extend(a);function(){alert(x);}', |
output: 'var o2 = $.extend(a);\n\nfunction{{f}}() {\n alert(x);\n}' |
}, |
{ input: 'function*() {\n yield 1;\n}', output: 'function*{{f}}() {\n yield 1;\n}' }, |
{ unchanged: 'function* x() {\n yield 1;\n}' }, |
] |
}, { |
name: "Regression tests", |
description: "Ensure specific bugs do not recur", |
options: [], |
tests: [{ |
comment: "Issue 241", |
unchanged: [ |
'obj', |
' .last({', |
' foo: 1,', |
' bar: 2', |
' });', |
'var test = 1;' |
] |
}, |
{ |
unchanged: [ |
'obj', |
' .last(a, function() {', |
' var test;', |
' });', |
'var test = 1;' |
] |
}, |
{ |
unchanged: [ |
'obj.first()', |
' .second()', |
' .last(function(err, response) {', |
' console.log(err);', |
' });' |
] |
}, |
{ |
comment: "Issue 268 and 275", |
unchanged: [ |
'obj.last(a, function() {', |
' var test;', |
'});', |
'var test = 1;' |
] |
}, |
{ |
unchanged: [ |
'obj.last(a,', |
' function() {', |
' var test;', |
' });', |
'var test = 1;' |
] |
}, |
{ |
input: '(function() {if (!window.FOO) window.FOO || (window.FOO = function() {var b = {bar: "zort"};});})();', |
output: [ |
'(function() {', |
' if (!window.FOO) window.FOO || (window.FOO = function() {', |
' var b = {', |
' bar: "zort"', |
' };', |
' });', |
'})();' |
] |
}, |
{ |
comment: "Issue 281", |
unchanged: [ |
'define(["dojo/_base/declare", "my/Employee", "dijit/form/Button",', |
' "dojo/_base/lang", "dojo/Deferred"', |
'], function(declare, Employee, Button, lang, Deferred) {', |
' return declare(Employee, {', |
' constructor: function() {', |
' new Button({', |
' onClick: lang.hitch(this, function() {', |
' new Deferred().then(lang.hitch(this, function() {', |
' this.salary * 0.25;', |
' }));', |
' })', |
' });', |
' }', |
' });', |
'});' |
] |
}, |
{ |
unchanged: [ |
'define(["dojo/_base/declare", "my/Employee", "dijit/form/Button",', |
' "dojo/_base/lang", "dojo/Deferred"', |
' ],', |
' function(declare, Employee, Button, lang, Deferred) {', |
' return declare(Employee, {', |
' constructor: function() {', |
' new Button({', |
' onClick: lang.hitch(this, function() {', |
' new Deferred().then(lang.hitch(this, function() {', |
' this.salary * 0.25;', |
' }));', |
' })', |
' });', |
' }', |
' });', |
' });' |
] |
}, |
{ |
comment: "Issue 459", |
unchanged: [ |
'(function() {', |
' return {', |
' foo: function() {', |
' return "bar";', |
' },', |
' bar: ["bar"]', |
' };', |
'}());' |
] |
}, |
{ |
comment: "Issue 505 - strings should end at newline unless continued by backslash", |
unchanged: [ |
'var name = "a;', |
'name = "b";' |
] |
}, |
{ |
unchanged: [ |
'var name = "a;\\\\', |
' name = b";' |
] |
}, |
{ |
comment: "Issue 514 - some operators require spaces to distinguish them", |
unchanged: 'var c = "_ACTION_TO_NATIVEAPI_" + ++g++ + +new Date;' |
}, |
{ |
unchanged: 'var c = "_ACTION_TO_NATIVEAPI_" - --g-- - -new Date;' |
}, |
{ |
comment: "Issue 440 - reserved words can be used as object property names", |
unchanged: [ |
'a = {', |
' function: {},', |
' "function": {},', |
' throw: {},', |
' "throw": {},', |
' var: {},', |
' "var": {},', |
' set: {},', |
' "set": {},', |
' get: {},', |
' "get": {},', |
' if: {},', |
' "if": {},', |
' then: {},', |
' "then": {},', |
' else: {},', |
' "else": {},', |
' yay: {}', |
'};' |
] |
}, |
{ |
comment: "Issue 331 - if-else with braces edge case", |
input: 'if(x){a();}else{b();}if(y){c();}', |
output: [ |
'if (x) {', |
' a();', |
'} else {', |
' b();', |
'}', |
'if (y) {', |
' c();', |
'}' |
] |
}, |
{ |
comment: "Issue 485 - ensure function declarations behave the same in arrays as elsewhere", |
unchanged: [ |
'var v = ["a",', |
' function() {', |
' return;', |
' }, {', |
' id: 1', |
' }', |
'];' |
] |
}, |
{ |
unchanged: [ |
'var v = ["a", function() {', |
' return;', |
'}, {', |
' id: 1', |
'}];' |
] |
}, |
{ |
comment: "Issue 382 - initial totally cursory support for es6 module export", |
unchanged: [ |
'module "Even" {', |
' import odd from "Odd";', |
' export function sum(x, y) {', |
' return x + y;', |
' }', |
' export var pi = 3.141593;', |
' export default moduleName;', |
'}' |
] |
}, |
{ |
unchanged: [ |
'module "Even" {', |
' export default function div(x, y) {}', |
'}' |
] |
}, |
{ |
comment: 'Issue 889 - export default { ... }', |
unchanged: [ |
'export default {', |
' func1() {},', |
' func2() {}', |
' func3() {}', |
'}' |
] |
}, |
{ |
unchanged: [ |
'export default {', |
' a() {', |
' return 1;', |
' },', |
' b() {', |
' return 2;', |
' },', |
' c() {', |
' return 3;', |
' }', |
'}' |
] |
}, |
{ |
comment: "Issue 508", |
unchanged: 'set["name"]' |
}, |
{ |
unchanged: 'get["name"]' |
}, |
{ |
fragmeent: true, |
unchanged: [ |
'a = {', |
' set b(x) {},', |
' c: 1,', |
' d: function() {}', |
'};' |
] |
}, |
{ |
fragmeent: true, |
unchanged: [ |
'a = {', |
' get b() {', |
' retun 0;', |
' },', |
' c: 1,', |
' d: function() {}', |
'};' |
] |
}, |
{ |
comment: "Issue 298 - do not under indent if/while/for condtionals experesions", |
unchanged: [ |
'\\\'use strict\\\';', |
'if ([].some(function() {', |
' return false;', |
' })) {', |
' console.log("hello");', |
'}' |
] |
}, |
{ |
comment: "Issue 298 - do not under indent if/while/for condtionals experesions", |
unchanged: [ |
'\\\'use strict\\\';', |
'if ([].some(function() {', |
' return false;', |
' })) {', |
' console.log("hello");', |
'}' |
] |
}, |
{ |
comment: "Issue 552 - Typescript? Okay... we didn't break it before, so try not to break it now.", |
unchanged: [ |
'class Test {', |
' blah: string[];', |
' foo(): number {', |
' return 0;', |
' }', |
' bar(): number {', |
' return 0;', |
' }', |
'}' |
] |
}, |
{ |
unchanged: [ |
'interface Test {', |
' blah: string[];', |
' foo(): number {', |
' return 0;', |
' }', |
' bar(): number {', |
' return 0;', |
' }', |
'}' |
] |
}, |
{ |
comment: "Issue 583 - Functions with comments after them should still indent correctly.", |
unchanged: [ |
'function exit(code) {', |
' setTimeout(function() {', |
' phantom.exit(code);', |
' }, 0);', |
' phantom.onError = function() {};', |
'}', |
'// Comment' |
] |
}, |
{ |
comment: "Issue 806 - newline arrow functions", |
unchanged: [ |
'a.b("c",', |
' () => d.e', |
')' |
] |
}, |
{ |
comment: "Issue 810 - es6 object literal detection", |
unchanged: [ |
'function badFormatting() {', |
' return {', |
' a,', |
' b: c,', |
' d: e,', |
' f: g,', |
' h,', |
' i,', |
' j: k', |
' }', |
'}', |
'', |
'function goodFormatting() {', |
' return {', |
' a: b,', |
' c,', |
' d: e,', |
' f: g,', |
' h,', |
' i,', |
' j: k', |
' }', |
'}' |
] |
}, |
{ |
comment: "Issue 602 - ES6 object literal shorthand functions", |
unchanged: [ |
'return {', |
' fn1() {},', |
' fn2() {}', |
'}' |
] |
}, { |
unchanged: [ |
'throw {', |
' fn1() {},', |
' fn2() {}', |
'}' |
] |
}, { |
unchanged: [ |
'foo({', |
' fn1(a) {}', |
' fn2(a) {}', |
'})' |
] |
}, { |
unchanged: [ |
'foo("text", {', |
' fn1(a) {}', |
' fn2(a) {}', |
'})' |
] |
}, { |
unchanged: [ |
'oneArg = {', |
' fn1(a) {', |
' do();', |
' },', |
' fn2() {}', |
'}' |
] |
}, { |
unchanged: [ |
'multiArg = {', |
' fn1(a, b, c) {', |
' do();', |
' },', |
' fn2() {}', |
'}' |
] |
}, { |
unchanged: [ |
'noArgs = {', |
' fn1() {', |
' do();', |
' },', |
' fn2() {}', |
'}' |
] |
}, { |
unchanged: [ |
'emptyFn = {', |
' fn1() {},', |
' fn2() {}', |
'}' |
] |
}, { |
unchanged: [ |
'nested = {', |
' fns: {', |
' fn1() {},', |
' fn2() {}', |
' }', |
'}' |
] |
}, { |
unchanged: [ |
'array = [{', |
' fn1() {},', |
' prop: val,', |
' fn2() {}', |
'}]' |
] |
}, { |
unchanged: [ |
'expr = expr ? expr : {', |
' fn1() {},', |
' fn2() {}', |
'}' |
] |
}, { |
unchanged: [ |
'strange = valid + {', |
' fn1() {},', |
' fn2() {', |
' return 1;', |
' }', |
'}.fn2()' |
] |
}, |
{ |
comment: "Issue 854 - Arrow function with statement block", |
unchanged: [ |
'test(() => {', |
' var a = {}', |
'', |
' a.what = () => true ? 1 : 2', |
'', |
' a.thing = () => {', |
' b();', |
' }', |
'})' |
] |
}, |
{ |
comment: "Issue 406 - Multiline array", |
unchanged: [ |
'var tempName = [', |
' "temp",', |
' process.pid,', |
' (Math.random() * 0x1000000000).toString(36),', |
' new Date().getTime()', |
'].join("-");' |
] |
}, |
{ |
comment: "Issue #996 - Input ends with backslash throws exception", |
fragment: true, |
unchanged: [ |
'sd = 1;', |
'/' |
] |
}, |
{ |
comment: "Issue #1079 - unbraced if with comments should still look right", |
unchanged: [ |
'if (console.log)', |
' for (var i = 0; i < 20; ++i)', |
' if (i % 3)', |
' console.log(i);', |
'// all done', |
'console.log("done");' |
] |
}, |
{ |
comment: "Issue #1085 - function should not have blank line in a number of cases", |
unchanged: [ |
'var transformer =', |
' options.transformer ||', |
' globalSettings.transformer ||', |
' function(x) {', |
' return x;', |
' };' |
] |
}, |
{ |
comment: "Issue #569 - function should not have blank line in a number of cases", |
unchanged: [ |
'(function(global) {', |
' "use strict";', |
'', |
' /* jshint ignore:start */', |
' include "somefile.js"', |
' /* jshint ignore:end */', |
'}(this));' |
] |
}, |
{ |
unchanged: [ |
'function bindAuthEvent(eventName) {', |
' self.auth.on(eventName, function(event, meta) {', |
' self.emit(eventName, event, meta);', |
' });', |
'}', |
'["logged_in", "logged_out", "signed_up", "updated_user"].forEach(bindAuthEvent);', |
'', |
'function bindBrowserEvent(eventName) {', |
' browser.on(eventName, function(event, meta) {', |
' self.emit(eventName, event, meta);', |
' });', |
'}', |
'["navigating"].forEach(bindBrowserEvent);' |
] |
}, |
{ |
comment: "Issue #892 - new line between chained methods ", |
unchanged: [ |
'foo', |
' .who()', |
'', |
' .knows()', |
' // comment', |
' .nothing() // comment', |
'', |
' .more()' |
] |
} |
] |
}, { |
name: "Test non-positionable-ops", |
description: "Ensure specific bugs do not recur", |
tests: [ |
{ unchanged: 'a += 2;' }, |
{ unchanged: 'a -= 2;' }, |
{ unchanged: 'a *= 2;' }, |
{ unchanged: 'a /= 2;' }, |
{ unchanged: 'a %= 2;' }, |
{ unchanged: 'a &= 2;' }, |
{ unchanged: 'a ^= 2;' }, |
{ unchanged: 'a |= 2;' }, |
{ unchanged: 'a **= 2;' }, |
{ unchanged: 'a <<= 2;' }, |
{ unchanged: 'a >>= 2;' }, |
] |
}, { |
//Relies on the tab being four spaces as default for the tests |
name: "brace_style ,preserve-inline tests", |
description: "brace_style *,preserve-inline varying different brace_styles", |
template: "< >", |
matrix: [ |
//test for all options of brace_style |
{ |
options: [ |
{ name: "brace_style", value: "'collapse,preserve-inline'" } |
], |
obo: ' ', |
obot: '', //Output Before Open curlybrace & Tab character |
oao: '\n', |
oaot: ' ', //Output After Open curlybrace & corresponding Tab |
obc: '\n', //Output Before Close curlybrace |
oac: ' ', |
oact: '' //Output After Close curlybrace & corresponding Tab character |
}, |
{ |
options: [ |
{ name: "brace_style", value: "'expand,preserve-inline'" } |
], |
obo: '\n', |
obot: ' ', |
oao: '\n', |
oaot: ' ', |
obc: '\n', |
oac: '\n', |
oact: ' ' |
}, |
{ |
options: [ |
{ name: "brace_style", value: "'end-expand,preserve-inline'" } |
], |
obo: ' ', |
obot: '', |
oao: '\n', |
oaot: ' ', |
obc: '\n', |
oac: '\n', |
oact: ' ' |
}, |
{ |
//None tries not to touch brace style so all the tests in this |
//matrix were formatted as if they were collapse |
options: [ |
{ name: "brace_style", value: "'none,preserve-inline'" } |
], |
obo: ' ', |
obot: '', |
oao: '\n', |
oaot: ' ', |
obc: '\n', |
oac: ' ', |
oact: '' |
}, |
//Test for backward compatibility |
{ |
options: [ |
{ name: "brace_style", value: "'collapse-preserve-inline'" } |
], |
//Equivalent to the output of the first test |
obo: ' ', |
obot: '', |
oao: '\n', |
oaot: ' ', |
obc: '\n', |
oac: ' ', |
oact: '' |
} |
], |
tests: [ |
//Test single inline blocks |
{ |
unchanged: 'import { asdf } from "asdf";' |
}, |
{ |
unchanged: 'import { get } from "asdf";' |
}, |
{ |
unchanged: 'function inLine() { console.log("oh em gee"); }' |
}, |
{ |
unchanged: 'if (cancer) { console.log("Im sorry but you only have so long to live..."); }' |
}, |
//Test more complex inliners |
{ |
input: 'if (ding) { console.log("dong"); } else { console.log("dang"); }', |
output: 'if (ding) { console.log("dong"); }<oac>else { console.log("dang"); }' |
}, |
//Test complex mixes of the two |
{ |
//The outer function and the third object (obj3) should not |
//be preserved. All other objects should be |
input: [ |
'function kindaComplex() {', |
' var a = 2;', |
' var obj = {};', |
' var obj2 = { a: "a", b: "b" };', |
' var obj3 = {', |
' c: "c",', |
' d: "d",', |
' e: "e"', |
' };', |
'}' |
], |
output: [ |
'function kindaComplex()<obo>{<oao>' + //NL in templates |
'<oaot>var a = 2;', |
' var obj = {};', |
' var obj2 = { a: "a", b: "b" };', |
' var obj3 = {<oao>' + //NL in templates, Expand doesnt affect js objects |
'<oaot><oaot>c: "c",', |
' d: "d",', |
' e: "e"' + //NL in templates |
'<obc> };' + //NL in templates |
'<obc>}' |
] |
}, |
{ |
//All inlines should be preserved, all non-inlines (specifically |
//complex(), obj, and obj.b should not be preserved (and hence |
//have the template spacing defined in output) |
input: [ |
'function complex() {', |
' console.log("wowe");', |
' (function() { var a = 2; var b = 3; })();', |
' $.each(arr, function(el, idx) { return el; });', |
' var obj = {', |
' a: function() { console.log("test"); },', |
' b() {', |
' console.log("test2");', |
' }', |
' };', |
'}' |
|
], |
output: [ |
'function complex()<obo>{<oao>' + //NL in templates |
'<oaot>console.log("wowe");', |
' (function() { var a = 2; var b = 3; })();', |
' $.each(arr, function(el, idx) { return el; });', |
' var obj = {<oao>' + //NL in templates |
'<oaot><oaot>a: function() { console.log("test"); },', |
' b()<obo><obot><obot>{<oao>' + //NL in templates |
'<oaot><oaot><oaot>console.log("test2");' + |
'<obc> }' + //NL in templates |
'<obc> };' + //NL in templates |
'<obc>}' |
] |
} |
] |
}, { |
name: "Destructured and related", |
description: "Ensure specific bugs do not recur", |
options: [ |
{ name: "brace_style", value: "'collapse,preserve-inline'" } |
], //Issue 1052, now collapse,preserve-inline instead of collapse-preserve-inline |
tests: [{ |
comment: "Issue 382 - import destructured ", |
unchanged: [ |
'module "Even" {', |
' import { odd, oddly } from "Odd";', |
'}' |
] |
}, |
{ |
unchanged: [ |
'import defaultMember from "module-name";', |
'import * as name from "module-name";', |
'import { member } from "module-name";', |
'import { member as alias } from "module-name";', |
'import { member1, member2 } from "module-name";', |
'import { member1, member2 as alias2 } from "module-name";', |
'import defaultMember, { member, member2 } from "module-name";', |
'import defaultMember, * as name from "module-name";', |
'import "module-name";' |
] |
}, |
{ |
comment: "Issue 858 - from is a keyword only after import", |
unchanged: [ |
'if (from < to) {', |
' from++;', |
'} else {', |
' from--;', |
'}' |
] |
}, |
{ |
comment: "Issue 511 - destrutured", |
unchanged: [ |
'var { b, c } = require("../stores");', |
'var { ProjectStore } = require("../stores");', |
'', |
'function takeThing({ prop }) {', |
' console.log("inner prop", prop)', |
'}' |
] |
}, |
{ |
comment: "Issue 315 - Short objects", |
unchanged: [ |
'var a = { b: { c: { d: e } } };' |
] |
}, |
{ |
unchanged: [ |
'var a = {', |
' b: {', |
' c: { d: e }', |
' c3: { d: e }', |
' },', |
' b2: { c: { d: e } }', |
'};' |
] |
}, |
{ |
comment: "Issue 370 - Short objects in array", |
unchanged: [ |
'var methods = [', |
' { name: "to" },', |
' { name: "step" },', |
' { name: "move" },', |
' { name: "min" },', |
' { name: "max" }', |
'];' |
] |
}, |
{ |
comment: "Issue 838 - Short objects in array", |
unchanged: [ |
'function(url, callback) {', |
' var script = document.createElement("script")', |
' if (true) script.onreadystatechange = function() {', |
' foo();', |
' }', |
' else script.onload = callback;', |
'}' |
] |
}, |
{ |
comment: "Issue 578 - Odd indenting after function", |
unchanged: [ |
'function bindAuthEvent(eventName) {', |
' self.auth.on(eventName, function(event, meta) {', |
' self.emit(eventName, event, meta);', |
' });', |
'}', |
'["logged_in", "logged_out", "signed_up", "updated_user"].forEach(bindAuthEvent);', |
] |
}, |
{ |
comment: "Issue #487 - some short expressions examples", |
unchanged: [ |
'if (a == 1) { a++; }', |
'a = { a: a };', |
'UserDB.findOne({ username: "xyz" }, function(err, user) {});', |
'import { fs } from "fs";' |
] |
}, |
{ |
comment: "Issue #982 - Fixed return expression collapse-preserve-inline", |
unchanged: [ |
'function foo(arg) {', |
' if (!arg) { a(); }', |
' if (!arg) { return false; }', |
' if (!arg) { throw "inline"; }', |
' return true;', |
'}' |
] |
}, |
{ |
comment: "Issue #338 - Short expressions ", |
unchanged: [ |
'if (someCondition) { return something; }', |
'if (someCondition) {', |
' return something;', |
'}', |
'if (someCondition) { break; }', |
'if (someCondition) {', |
' return something;', |
'}' |
] |
} |
] |
}, { |
// ======================================================= |
// New tests groups should be added above this line. |
// Everything below is a work in progress - converting |
// old test to generated form. |
// ======================================================= |
name: "Old tests", |
description: "Largely unorganized pile of tests", |
options: [], |
tests: [ |
{ unchanged: '' }, |
{ fragment: true, unchanged: ' return .5' }, |
{ fragment: true, unchanged: ' return .5;\n a();' }, |
{ fragment: true, unchanged: ' return .5;\n a();' }, |
{ fragment: true, unchanged: ' return .5;\n a();' }, |
{ fragment: true, unchanged: ' < div' }, |
{ input: 'a = 1', output: 'a = 1' }, |
{ input: 'a=1', output: 'a = 1' }, |
{ unchanged: '(3) / 2' }, |
{ unchanged: '["a", "b"].join("")' }, |
{ unchanged: 'a();\n\nb();' }, |
{ input: 'var a = 1 var b = 2', output: 'var a = 1\nvar b = 2' }, |
{ input: 'var a=1, b=c[d], e=6;', output: 'var a = 1,\n b = c[d],\n e = 6;' }, |
{ unchanged: 'var a,\n b,\n c;' }, |
{ input: 'let a = 1 let b = 2', output: 'let a = 1\nlet b = 2' }, |
{ input: 'let a=1, b=c[d], e=6;', output: 'let a = 1,\n b = c[d],\n e = 6;' }, |
{ unchanged: 'let a,\n b,\n c;' }, |
{ input: 'const a = 1 const b = 2', output: 'const a = 1\nconst b = 2' }, |
{ input: 'const a=1, b=c[d], e=6;', output: 'const a = 1,\n b = c[d],\n e = 6;' }, |
{ unchanged: 'const a,\n b,\n c;' }, |
{ unchanged: 'a = " 12345 "' }, |
{ unchanged: "a = \\' 12345 \\'" }, |
{ unchanged: 'if (a == 1) b = 2;' }, |
{ input: 'if(1){2}else{3}', output: 'if (1) {\n 2\n} else {\n 3\n}' }, |
{ input: 'if(1||2);', output: 'if (1 || 2);' }, |
{ input: '(a==1)||(b==2)', output: '(a == 1) || (b == 2)' }, |
{ input: 'var a = 1 if (2) 3;', output: 'var a = 1\nif (2) 3;' }, |
{ unchanged: 'a = a + 1' }, |
{ unchanged: 'a = a == 1' }, |
{ unchanged: '/12345[^678]*9+/.match(a)' }, |
{ unchanged: 'a /= 5' }, |
{ unchanged: 'a = 0.5 * 3' }, |
{ unchanged: 'a *= 10.55' }, |
{ unchanged: 'a < .5' }, |
{ unchanged: 'a <= .5' }, |
{ input: 'a<.5', output: 'a < .5' }, |
{ input: 'a<=.5', output: 'a <= .5' }, |
|
{ |
comment: 'exponent literals', |
unchanged: 'a = 1e10' |
}, |
{ unchanged: 'a = 1.3e10' }, |
{ unchanged: 'a = 1.3e-10' }, |
{ unchanged: 'a = -12345.3e-10' }, |
{ unchanged: 'a = .12345e-10' }, |
{ unchanged: 'a = 06789e-10' }, |
{ unchanged: 'a = e - 10' }, |
{ unchanged: 'a = 1.3e+10' }, |
{ unchanged: 'a = 1.e-7' }, |
{ unchanged: 'a = -12345.3e+10' }, |
{ unchanged: 'a = .12345e+10' }, |
{ unchanged: 'a = 06789e+10' }, |
{ unchanged: 'a = e + 10' }, |
{ input: 'a=0e-12345.3e-10', output: 'a = 0e-12345 .3e-10' }, |
{ input: 'a=0.e-12345.3e-10', output: 'a = 0.e-12345 .3e-10' }, |
{ input: 'a=0x.e-12345.3e-10', output: 'a = 0x.e - 12345.3e-10' }, |
{ input: 'a=0x0.e-12345.3e-10', output: 'a = 0x0.e - 12345.3e-10' }, |
{ input: 'a=0x0.0e-12345.3e-10', output: 'a = 0x0 .0e-12345 .3e-10' }, |
{ input: 'a=0g-12345.3e-10', output: 'a = 0 g - 12345.3e-10' }, |
{ input: 'a=0.g-12345.3e-10', output: 'a = 0. g - 12345.3e-10' }, |
{ input: 'a=0x.g-12345.3e-10', output: 'a = 0x.g - 12345.3e-10' }, |
{ input: 'a=0x0.g-12345.3e-10', output: 'a = 0x0.g - 12345.3e-10' }, |
{ input: 'a=0x0.0g-12345.3e-10', output: 'a = 0x0 .0 g - 12345.3e-10' }, |
|
{ |
comment: 'Decimal literals', |
unchanged: 'a = 0123456789;' |
}, |
{ unchanged: 'a = 9876543210;' }, |
{ unchanged: 'a = 5647308291;' }, |
{ input: 'a=030e-5', output: 'a = 030e-5' }, |
{ input: 'a=00+4', output: 'a = 00 + 4' }, |
{ input: 'a=32+4', output: 'a = 32 + 4' }, |
{ input: 'a=0.6g+4', output: 'a = 0.6 g + 4' }, |
{ input: 'a=01.10', output: 'a = 01.10' }, |
{ input: 'a=a.10', output: 'a = a .10' }, |
{ input: 'a=00B0x0', output: 'a = 00 B0x0' }, |
{ input: 'a=00B0xb0', output: 'a = 00 B0xb0' }, |
{ input: 'a=00B0x0b0', output: 'a = 00 B0x0b0' }, |
{ input: 'a=0090x0', output: 'a = 0090 x0' }, |
{ input: 'a=0g0b0o0', output: 'a = 0 g0b0o0' }, |
|
{ |
comment: 'Hexadecimal literals', |
unchanged: 'a = 0x0123456789abcdef;' |
}, |
{ unchanged: 'a = 0X0123456789ABCDEF;' }, |
{ unchanged: 'a = 0xFeDcBa9876543210;' }, |
{ input: 'a=0x30e-5', output: 'a = 0x30e - 5' }, |
{ input: 'a=0xF0+4', output: 'a = 0xF0 + 4' }, |
{ input: 'a=0Xff+4', output: 'a = 0Xff + 4' }, |
{ input: 'a=0Xffg+4', output: 'a = 0Xff g + 4' }, |
{ input: 'a=0x01.10', output: 'a = 0x01 .10' }, |
{ unchanged: 'a = 0xb0ce;' }, |
{ unchanged: 'a = 0x0b0;' }, |
{ input: 'a=0x0B0x0', output: 'a = 0x0B0 x0' }, |
{ input: 'a=0x0B0xb0', output: 'a = 0x0B0 xb0' }, |
{ input: 'a=0x0B0x0b0', output: 'a = 0x0B0 x0b0' }, |
{ input: 'a=0X090x0', output: 'a = 0X090 x0' }, |
{ input: 'a=0Xg0b0o0', output: 'a = 0X g0b0o0' }, |
|
{ |
comment: 'Octal literals', |
unchanged: 'a = 0o01234567;' |
}, |
{ unchanged: 'a = 0O01234567;' }, |
{ unchanged: 'a = 0o34120675;' }, |
{ input: 'a=0o30e-5', output: 'a = 0o30 e - 5' }, |
{ input: 'a=0o70+4', output: 'a = 0o70 + 4' }, |
{ input: 'a=0O77+4', output: 'a = 0O77 + 4' }, |
{ input: 'a=0O778+4', output: 'a = 0O77 8 + 4' }, |
{ input: 'a=0O77a+4', output: 'a = 0O77 a + 4' }, |
{ input: 'a=0o01.10', output: 'a = 0o01 .10' }, |
{ input: 'a=0o0B0x0', output: 'a = 0o0 B0x0' }, |
{ input: 'a=0o0B0xb0', output: 'a = 0o0 B0xb0' }, |
{ input: 'a=0o0B0x0b0', output: 'a = 0o0 B0x0b0' }, |
{ input: 'a=0O090x0', output: 'a = 0O0 90 x0' }, |
{ input: 'a=0Og0b0o0', output: 'a = 0O g0b0o0' }, |
|
{ |
comment: 'Binary literals', |
unchanged: 'a = 0b010011;' |
}, |
{ unchanged: 'a = 0B010011;' }, |
{ unchanged: 'a = 0b01001100001111;' }, |
{ input: 'a=0b10e-5', output: 'a = 0b10 e - 5' }, |
{ input: 'a=0b10+4', output: 'a = 0b10 + 4' }, |
{ input: 'a=0B11+4', output: 'a = 0B11 + 4' }, |
{ input: 'a=0B112+4', output: 'a = 0B11 2 + 4' }, |
{ input: 'a=0B11a+4', output: 'a = 0B11 a + 4' }, |
{ input: 'a=0b01.10', output: 'a = 0b01 .10' }, |
{ input: 'a=0b0B0x0', output: 'a = 0b0 B0x0' }, |
{ input: 'a=0b0B0xb0', output: 'a = 0b0 B0xb0' }, |
{ input: 'a=0b0B0x0b0', output: 'a = 0b0 B0x0b0' }, |
{ input: 'a=0B090x0', output: 'a = 0B0 90 x0' }, |
{ input: 'a=0Bg0b0o0', output: 'a = 0B g0b0o0' }, |
{ unchanged: 'a = [1, 2, 3, 4]' }, |
{ input: 'F*(g/=f)*g+b', output: 'F * (g /= f) * g + b' }, |
{ input: 'a.b({c:d})', output: 'a.b({\n c: d\n})' }, |
{ input: 'a.b\n(\n{\nc:\nd\n}\n)', output: 'a.b({\n c: d\n})' }, |
{ input: 'a.b({c:"d"})', output: 'a.b({\n c: "d"\n})' }, |
{ input: 'a.b\n(\n{\nc:\n"d"\n}\n)', output: 'a.b({\n c: "d"\n})' }, |
{ input: 'a=!b', output: 'a = !b' }, |
{ input: 'a=!!b', output: 'a = !!b' }, |
{ input: 'a?b:c', output: 'a ? b : c' }, |
{ input: 'a?1:2', output: 'a ? 1 : 2' }, |
{ input: 'a?(b):c', output: 'a ? (b) : c' }, |
{ input: 'x={a:1,b:w=="foo"?x:y,c:z}', output: 'x = {\n a: 1,\n b: w == "foo" ? x : y,\n c: z\n}' }, |
{ input: 'x=a?b?c?d:e:f:g;', output: 'x = a ? b ? c ? d : e : f : g;' }, |
{ input: 'x=a?b?c?d:{e1:1,e2:2}:f:g;', output: 'x = a ? b ? c ? d : {\n e1: 1,\n e2: 2\n} : f : g;' }, |
{ unchanged: 'function void(void) {}' }, |
{ input: 'if(!a)foo();', output: 'if (!a) foo();' }, |
{ input: 'a=~a', output: 'a = ~a' }, |
{ input: 'a;/*comment*/b;', output: "a; /*comment*/\nb;" }, |
{ input: 'a;/* comment */b;', output: "a; /* comment */\nb;" }, |
{ fragment: true, input: 'a;/*\ncomment\n*/b;', output: "a;\n/*\ncomment\n*/\nb;", comment: "simple comments don't get touched at all" }, |
{ input: 'a;/**\n* javadoc\n*/b;', output: "a;\n/**\n * javadoc\n */\nb;" }, |
{ fragment: true, input: 'a;/**\n\nno javadoc\n*/b;', output: "a;\n/**\n\nno javadoc\n*/\nb;" }, |
{ input: 'a;/*\n* javadoc\n*/b;', output: "a;\n/*\n * javadoc\n */\nb;", comment: 'comment blocks detected and reindented even w/o javadoc starter' }, |
{ input: 'if(a)break;', output: "if (a) break;" }, |
{ input: 'if(a){break}', output: "if (a) {\n break\n}" }, |
{ input: 'if((a))foo();', output: 'if ((a)) foo();' }, |
{ input: 'for(var i=0;;) a', output: 'for (var i = 0;;) a' }, |
{ input: 'for(var i=0;;)\na', output: 'for (var i = 0;;)\n a' }, |
{ unchanged: 'a++;' }, |
{ input: 'for(;;i++)a()', output: 'for (;; i++) a()' }, |
{ input: 'for(;;i++)\na()', output: 'for (;; i++)\n a()' }, |
{ input: 'for(;;++i)a', output: 'for (;; ++i) a' }, |
{ input: 'return(1)', output: 'return (1)' }, |
{ input: 'try{a();}catch(b){c();}finally{d();}', output: "try {\n a();\n} catch (b) {\n c();\n} finally {\n d();\n}" }, |
{ unchanged: '(xx)()', comment: ' magic function call' }, |
{ unchanged: 'a[1]()', comment: 'another magic function call' }, |
{ input: 'if(a){b();}else if(c) foo();', output: "if (a) {\n b();\n} else if (c) foo();" }, |
{ input: 'switch(x) {case 0: case 1: a(); break; default: break}', output: "switch (x) {\n case 0:\n case 1:\n a();\n break;\n default:\n break\n}" }, |
{ input: 'switch(x){case -1:break;case !y:break;}', output: 'switch (x) {\n case -1:\n break;\n case !y:\n break;\n}' }, |
{ unchanged: 'a !== b' }, |
{ input: 'if (a) b(); else c();', output: "if (a) b();\nelse c();" }, |
{ unchanged: "// comment\n(function something() {})", comment: 'typical greasemonkey start' }, |
{ unchanged: "{\n\n x();\n\n}", comment: 'duplicating newlines' }, |
{ unchanged: 'if (a in b) foo();' }, |
{ unchanged: 'if (a of b) foo();' }, |
{ unchanged: 'if (a of [1, 2, 3]) foo();' }, |
{ |
input: 'if(X)if(Y)a();else b();else c();', |
output: "if (X)\n if (Y) a();\n else b();\nelse c();" |
}, |
{ unchanged: 'if (foo) bar();\nelse break' }, |
{ unchanged: 'var a, b;' }, |
{ unchanged: 'var a = new function();' }, |
{ fragment: true, unchanged: 'new function' }, |
{ unchanged: 'var a, b' }, |
{ input: '{a:1, b:2}', output: "{\n a: 1,\n b: 2\n}" }, |
{ input: 'a={1:[-1],2:[+1]}', output: 'a = {\n 1: [-1],\n 2: [+1]\n}' }, |
{ input: "var l = {\\'a\\':\\'1\\', \\'b\\':\\'2\\'}", output: "var l = {\n \\'a\\': \\'1\\',\n \\'b\\': \\'2\\'\n}" }, |
{ unchanged: 'if (template.user[n] in bk) foo();' }, |
{ unchanged: 'return 45' }, |
{ unchanged: 'return this.prevObject ||\n\n this.constructor(null);' }, |
{ unchanged: 'If[1]' }, |
{ unchanged: 'Then[1]' }, |
{ input: "a = 1;// comment", output: "a = 1; // comment" }, |
{ unchanged: "a = 1; // comment" }, |
{ input: "a = 1;\n // comment", output: "a = 1;\n// comment" }, |
{ unchanged: 'a = [-1, -1, -1]' }, |
|
// These must work as non-fragments. |
{ unchanged: ['// a', '// b', '', '', '', '// c', '// d'] }, |
{ unchanged: ['// func-comment', '', 'function foo() {}', '', '// end-func-comment'] }, |
|
{ |
comment: 'The exact formatting these should have is open for discussion, but they are at least reasonable', |
unchanged: 'a = [ // comment\n -1, -1, -1\n]' |
}, |
{ unchanged: 'var a = [ // comment\n -1, -1, -1\n]' }, |
{ unchanged: 'a = [ // comment\n -1, // comment\n -1, -1\n]' }, |
{ unchanged: 'var a = [ // comment\n -1, // comment\n -1, -1\n]' }, |
|
{ input: 'o = [{a:b},{c:d}]', output: 'o = [{\n a: b\n}, {\n c: d\n}]' }, |
|
{ |
comment: 'was: extra space appended', |
unchanged: "if (a) {\n do();\n}" |
}, |
|
{ |
comment: 'if/else statement with empty body', |
input: "if (a) {\n// comment\n}else{\n// comment\n}", |
output: "if (a) {\n // comment\n} else {\n // comment\n}" |
}, |
{ comment: 'multiple comments indentation', input: "if (a) {\n// comment\n// comment\n}", output: "if (a) {\n // comment\n // comment\n}" }, |
{ input: "if (a) b() else c();", output: "if (a) b()\nelse c();" }, |
{ input: "if (a) b() else if c() d();", output: "if (a) b()\nelse if c() d();" }, |
|
{ unchanged: "{}" }, |
{ unchanged: "{\n\n}" }, |
{ input: "do { a(); } while ( 1 );", output: "do {\n a();\n} while (1);" }, |
{ unchanged: "do {} while (1);" }, |
{ input: "do {\n} while (1);", output: "do {} while (1);" }, |
{ unchanged: "do {\n\n} while (1);" }, |
{ unchanged: "var a = x(a, b, c)" }, |
{ input: "delete x if (a) b();", output: "delete x\nif (a) b();" }, |
{ input: "delete x[x] if (a) b();", output: "delete x[x]\nif (a) b();" }, |
{ input: "for(var a=1,b=2)d", output: "for (var a = 1, b = 2) d" }, |
{ input: "for(var a=1,b=2,c=3) d", output: "for (var a = 1, b = 2, c = 3) d" }, |
{ input: "for(var a=1,b=2,c=3;d<3;d++)\ne", output: "for (var a = 1, b = 2, c = 3; d < 3; d++)\n e" }, |
{ input: "function x(){(a||b).c()}", output: "function x() {\n (a || b).c()\n}" }, |
{ input: "function x(){return - 1}", output: "function x() {\n return -1\n}" }, |
{ input: "function x(){return ! a}", output: "function x() {\n return !a\n}" }, |
{ unchanged: "x => x" }, |
{ unchanged: "(x) => x" }, |
{ input: "x => { x }", output: "x => {\n x\n}" }, |
{ input: "(x) => { x }", output: "(x) => {\n x\n}" }, |
|
{ |
comment: 'a common snippet in jQuery plugins', |
input_: "settings = $.extend({},defaults,settings);", |
output: "settings = $.extend({}, defaults, settings);" |
}, |
|
// reserved words used as property names |
{ unchanged: "$http().then().finally().default()" }, |
{ input: "$http()\n.then()\n.finally()\n.default()", output: "$http()\n .then()\n .finally()\n .default()" }, |
{ unchanged: "$http().when.in.new.catch().throw()" }, |
{ input: "$http()\n.when\n.in\n.new\n.catch()\n.throw()", output: "$http()\n .when\n .in\n .new\n .catch()\n .throw()" }, |
|
{ input: '{xxx;}()', output: '{\n xxx;\n}()' }, |
|
{ unchanged: "a = \\'a\\'\nb = \\'b\\'" }, |
{ unchanged: "a = /reg/exp" }, |
{ unchanged: "a = /reg/" }, |
{ unchanged: '/abc/.test()' }, |
{ unchanged: '/abc/i.test()' }, |
{ input: "{/abc/i.test()}", output: "{\n /abc/i.test()\n}" }, |
{ input: 'var x=(a)/a;', output: 'var x = (a) / a;' }, |
|
{ unchanged: 'x != -1' }, |
|
{ input: 'for (; s-->0;)t', output: 'for (; s-- > 0;) t' }, |
{ input: 'for (; s++>0;)u', output: 'for (; s++ > 0;) u' }, |
{ input: 'a = s++>s--;', output: 'a = s++ > s--;' }, |
{ input: 'a = s++>--s;', output: 'a = s++ > --s;' }, |
|
{ input: '{x=#1=[]}', output: '{\n x = #1=[]\n}' }, |
{ input: '{a:#1={}}', output: '{\n a: #1={}\n}' }, |
{ input: '{a:#1#}', output: '{\n a: #1#\n}' }, |
|
{ fragment: true, unchanged: '"incomplete-string' }, |
{ fragment: true, unchanged: "\\'incomplete-string" }, |
{ fragment: true, unchanged: '/incomplete-regex' }, |
{ fragment: true, unchanged: '`incomplete-template-string' }, |
|
{ fragment: true, input: '{a:1},{a:2}', output: '{\n a: 1\n}, {\n a: 2\n}' }, |
{ fragment: true, input: 'var ary=[{a:1}, {a:2}];', output: 'var ary = [{\n a: 1\n}, {\n a: 2\n}];' }, |
|
{ comment: 'incomplete', fragment: true, input: '{a:#1', output: '{\n a: #1' }, |
{ comment: 'incomplete', fragment: true, input: '{a:#', output: '{\n a: #' }, |
|
{ comment: 'incomplete', fragment: true, input: '}}}', output: '}\n}\n}' }, |
|
{ fragment: true, unchanged: '<!--\nvoid();\n// -->' }, |
|
{ comment: 'incomplete regexp', fragment: true, input: 'a=/regexp', output: 'a = /regexp' }, |
|
{ input: '{a:#1=[],b:#1#,c:#999999#}', output: '{\n a: #1=[],\n b: #1#,\n c: #999999#\n}' }, |
|
{ input: "do{x()}while(a>1)", output: "do {\n x()\n} while (a > 1)" }, |
|
{ input: "x(); /reg/exp.match(something)", output: "x();\n/reg/exp.match(something)" }, |
|
{ fragment: true, input: "something();(", output: "something();\n(" }, |
{ fragment: true, input: "#!she/bangs, she bangs\nf=1", output: "#!she/bangs, she bangs\n\nf = 1" }, |
{ fragment: true, input: "#!she/bangs, she bangs\n\nf=1", output: "#!she/bangs, she bangs\n\nf = 1" }, |
{ fragment: true, unchanged: "#!she/bangs, she bangs\n\n/* comment */" }, |
{ fragment: true, unchanged: "#!she/bangs, she bangs\n\n\n/* comment */" }, |
{ fragment: true, unchanged: "#" }, |
{ fragment: true, unchanged: "#!" }, |
|
{ unchanged: "function namespace::something()" }, |
|
{ fragment: true, unchanged: "<!--\nsomething();\n-->" }, |
{ fragment: true, input: "<!--\nif(i<0){bla();}\n-->", output: "<!--\nif (i < 0) {\n bla();\n}\n-->" }, |
|
{ input: '{foo();--bar;}', output: '{\n foo();\n --bar;\n}' }, |
{ input: '{foo();++bar;}', output: '{\n foo();\n ++bar;\n}' }, |
{ input: '{--bar;}', output: '{\n --bar;\n}' }, |
{ input: '{++bar;}', output: '{\n ++bar;\n}' }, |
{ input: 'if(true)++a;', output: 'if (true) ++a;' }, |
{ input: 'if(true)\n++a;', output: 'if (true)\n ++a;' }, |
{ input: 'if(true)--a;', output: 'if (true) --a;' }, |
{ input: 'if(true)\n--a;', output: 'if (true)\n --a;' }, |
{ unchanged: 'elem[array]++;' }, |
{ unchanged: 'elem++ * elem[array]++;' }, |
{ unchanged: 'elem-- * -elem[array]++;' }, |
{ unchanged: 'elem-- + elem[array]++;' }, |
{ unchanged: 'elem-- - elem[array]++;' }, |
{ unchanged: 'elem-- - -elem[array]++;' }, |
{ unchanged: 'elem-- - +elem[array]++;' }, |
|
|
{ |
comment: 'Handling of newlines around unary ++ and -- operators', |
input: '{foo\n++bar;}', |
output: '{\n foo\n ++bar;\n}' |
}, |
{ input: '{foo++\nbar;}', output: '{\n foo++\n bar;\n}' }, |
|
{ |
comment: 'This is invalid, but harder to guard against. Issue #203.', |
input: '{foo\n++\nbar;}', |
output: '{\n foo\n ++\n bar;\n}' |
}, |
|
{ |
comment: 'regexps', |
input: 'a(/abc\\\\/\\\\/def/);b()', |
output: "a(/abc\\\\/\\\\/def/);\nb()" |
}, |
{ input: 'a(/a[b\\\\[\\\\]c]d/);b()', output: "a(/a[b\\\\[\\\\]c]d/);\nb()" }, |
{ comment: 'incomplete char class', fragment: true, unchanged: 'a(/a[b\\\\[' }, |
|
{ |
comment: 'allow unescaped / in char classes', |
input: 'a(/[a/b]/);b()', |
output: "a(/[a/b]/);\nb()" |
}, |
{ unchanged: 'typeof /foo\\\\//;' }, |
{ unchanged: 'throw /foo\\\\//;' }, |
{ unchanged: 'do /foo\\\\//;' }, |
{ unchanged: 'return /foo\\\\//;' }, |
{ unchanged: 'switch (a) {\n case /foo\\\\//:\n b\n}' }, |
{ unchanged: 'if (a) /foo\\\\//\nelse /foo\\\\//;' }, |
|
{ unchanged: 'if (foo) /regex/.test();' }, |
{ unchanged: "for (index in [1, 2, 3]) /^test$/i.test(s)" }, |
|
{ unchanged: 'function foo() {\n return [\n "one",\n "two"\n ];\n}' }, |
{ input: 'a=[[1,2],[4,5],[7,8]]', output: "a = [\n [1, 2],\n [4, 5],\n [7, 8]\n]" }, |
{ |
input: 'a=[[1,2],[4,5],function(){},[7,8]]', |
output: "a = [\n [1, 2],\n [4, 5],\n function() {},\n [7, 8]\n]" |
}, |
{ |
input: '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]" |
}, |
{ |
input: 'a=[[1,2],[4,5],function(){},[7,8]]', |
output: "a = [\n [1, 2],\n [4, 5],\n function() {},\n [7, 8]\n]" |
}, |
{ |
input: 'a=[b,c,function(){},function(){},d]', |
output: "a = [b, c, function() {}, function() {}, d]" |
}, |
{ |
input: 'a=[b,c,\nfunction(){},function(){},d]', |
output: "a = [b, c,\n function() {},\n function() {},\n d\n]" |
}, |
{ input: 'a=[a[1],b[4],c[d[7]]]', output: "a = [a[1], b[4], c[d[7]]]" }, |
{ input: '[1,2,[3,4,[5,6],7],8]', output: "[1, 2, [3, 4, [5, 6], 7], 8]" }, |
|
{ |
input: '[[["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]' |
}, |
|
{ input: '{[x()[0]];indent;}', output: '{\n [x()[0]];\n indent;\n}' }, |
{ unchanged: '/*\n foo trailing space \n * bar trailing space \n**/' }, |
{ unchanged: '{\n /*\n foo \n * bar \n */\n}' }, |
|
{ unchanged: 'return ++i' }, |
{ unchanged: 'return !!x' }, |
{ unchanged: 'return !x' }, |
{ input: 'return [1,2]', output: 'return [1, 2]' }, |
{ unchanged: 'return;' }, |
{ unchanged: 'return\nfunc' }, |
{ input: 'catch(e)', output: 'catch (e)' }, |
|
{ |
input: 'var a=1,b={foo:2,bar:3},{baz:4,wham:5},c=4;', |
output: 'var a = 1,\n b = {\n foo: 2,\n bar: 3\n },\n {\n baz: 4,\n wham: 5\n }, c = 4;' |
}, |
{ |
input: 'var a=1,b={foo:2,bar:3},{baz:4,wham:5},\nc=4;', |
output: 'var a = 1,\n b = {\n foo: 2,\n bar: 3\n },\n {\n baz: 4,\n wham: 5\n },\n c = 4;' |
}, |
|
{ |
comment: 'inline comment', |
input_: 'function x(/*int*/ start, /*string*/ foo)', |
output: 'function x( /*int*/ start, /*string*/ foo)' |
}, |
|
{ |
comment: 'javadoc comment', |
input: '/**\n* foo\n*/', |
output: '/**\n * foo\n */' |
}, |
{ input: '{\n/**\n* foo\n*/\n}', output: '{\n /**\n * foo\n */\n}' }, |
|
{ |
comment: 'starless block comment', |
unchanged: '/**\nfoo\n*/' |
}, |
{ unchanged: '/**\nfoo\n**/' }, |
{ unchanged: '/**\nfoo\nbar\n**/' }, |
{ unchanged: '/**\nfoo\n\nbar\n**/' }, |
{ unchanged: '/**\nfoo\n bar\n**/' }, |
{ input: '{\n/**\nfoo\n*/\n}', output: '{\n /**\n foo\n */\n}' }, |
{ input: '{\n/**\nfoo\n**/\n}', output: '{\n /**\n foo\n **/\n}' }, |
{ input: '{\n/**\nfoo\nbar\n**/\n}', output: '{\n /**\n foo\n bar\n **/\n}' }, |
{ input: '{\n/**\nfoo\n\nbar\n**/\n}', output: '{\n /**\n foo\n\n bar\n **/\n}' }, |
{ input: '{\n/**\nfoo\n bar\n**/\n}', output: '{\n /**\n foo\n bar\n **/\n}' }, |
{ unchanged: '{\n /**\n foo\nbar\n **/\n}' }, |
|
{ input: 'var a,b,c=1,d,e,f=2;', output: 'var a, b, c = 1,\n d, e, f = 2;' }, |
{ input: 'var a,b,c=[],d,e,f=2;', output: 'var a, b, c = [],\n d, e, f = 2;' }, |
{ unchanged: 'function() {\n var a, b, c, d, e = [],\n f;\n}' }, |
|
{ input: 'do/regexp/;\nwhile(1);', output: 'do /regexp/;\nwhile (1);' }, |
{ input: 'var a = a,\na;\nb = {\nb\n}', output: 'var a = a,\n a;\nb = {\n b\n}' }, |
|
{ unchanged: 'var a = a,\n /* c */\n b;' }, |
{ unchanged: 'var a = a,\n // c\n b;' }, |
|
{ |
comment: 'weird element referencing', |
unchanged: 'foo.("bar");' |
}, |
|
|
{ unchanged: 'if (a) a()\nelse b()\nnewline()' }, |
{ unchanged: 'if (a) a()\nnewline()' }, |
{ input: 'a=typeof(x)', output: 'a = typeof(x)' }, |
|
{ unchanged: 'var a = function() {\n return null;\n },\n b = false;' }, |
|
{ unchanged: 'var a = function() {\n func1()\n}' }, |
{ unchanged: 'var a = function() {\n func1()\n}\nvar b = function() {\n func2()\n}' }, |
|
{ |
comment: 'code with and without semicolons', |
input_: 'var whatever = require("whatever");\nfunction() {\n a = 6;\n}', |
output: 'var whatever = require("whatever");\n\nfunction() {\n a = 6;\n}' |
}, |
{ |
input: 'var whatever = require("whatever")\nfunction() {\n a = 6\n}', |
output: 'var whatever = require("whatever")\n\nfunction() {\n a = 6\n}' |
}, |
|
{ input: '{"x":[{"a":1,"b":3},\n7,8,8,8,8,{"b":99},{"a":11}]}', output: '{\n "x": [{\n "a": 1,\n "b": 3\n },\n 7, 8, 8, 8, 8, {\n "b": 99\n }, {\n "a": 11\n }\n ]\n}' }, |
{ input: '{"x":[{"a":1,"b":3},7,8,8,8,8,{"b":99},{"a":11}]}', output: '{\n "x": [{\n "a": 1,\n "b": 3\n }, 7, 8, 8, 8, 8, {\n "b": 99\n }, {\n "a": 11\n }]\n}' }, |
|
{ input: '{"1":{"1a":"1b"},"2"}', output: '{\n "1": {\n "1a": "1b"\n },\n "2"\n}' }, |
{ input: '{a:{a:b},c}', output: '{\n a: {\n a: b\n },\n c\n}' }, |
|
{ input: '{[y[a]];keep_indent;}', output: '{\n [y[a]];\n keep_indent;\n}' }, |
|
{ input: 'if (x) {y} else { if (x) {y}}', output: 'if (x) {\n y\n} else {\n if (x) {\n y\n }\n}' }, |
|
{ unchanged: 'if (foo) one()\ntwo()\nthree()' }, |
{ unchanged: 'if (1 + foo() && bar(baz()) / 2) one()\ntwo()\nthree()' }, |
{ unchanged: 'if (1 + foo() && bar(baz()) / 2) one();\ntwo();\nthree();' }, |
|
{ input: 'var a=1,b={bang:2},c=3;', output: 'var a = 1,\n b = {\n bang: 2\n },\n c = 3;' }, |
{ input: 'var a={bing:1},b=2,c=3;', output: 'var a = {\n bing: 1\n },\n b = 2,\n c = 3;' }, |
|
], |
}], |
examples: [{ |
// Example |
group_name: "one", |
description: "", |
options: [], |
values: [{ |
source: "", //string or array of lines |
output: "" //string or array of lines |
}] |
}] |
}; |