How to use test_fragment method in wpt

Best JavaScript code snippet using wpt

beautify-html-tests.js

Source:beautify-html-tests.js Github

copy

Full Screen

...57 }58 var sanitytest;59 // test the input on beautifier with the current flag settings60 // does not check the indentation / surroundings as bt() does61 function test_fragment(input, expected)62 {63 expected = expected || expected === '' ? expected : input;64 sanitytest.expect(input, expected);65 // if the expected is different from input, run it again66 // expected output should be unchanged when run twice.67 if (expected !== input) {68 sanitytest.expect(expected, expected);69 }70 // Everywhere we do newlines, they should be replaced with opts.eol71 opts.eol = '\r\n';72 expected = expected.replace(/[\n]/g, '\r\n');73 sanitytest.expect(input, expected);74 if (input.indexOf('\n') !== -1) {75 input = input.replace(/[\n]/g, '\r\n');76 sanitytest.expect(input, expected);77 // Ensure support for auto eol detection78 opts.eol = 'auto';79 sanitytest.expect(input, expected);80 }81 opts.eol = '\n';82 }83 // test html84 function bth(input, expectation)85 {86 var wrapped_input, wrapped_expectation, field_input, field_expectation;87 expectation = expectation || expectation === '' ? expectation : input;88 sanitytest.test_function(test_html_beautifier, 'html_beautify');89 test_fragment(input, expectation);90 if (opts.indent_size === 4 && input) {91 wrapped_input = '<div>\n' + input.replace(/^(.+)$/mg, ' $1') + '\n <span>inline</span>\n</div>';92 wrapped_expectation = '<div>\n' + expectation.replace(/^(.+)$/mg, ' $1') + '\n <span>inline</span>\n</div>';93 test_fragment(wrapped_input, wrapped_expectation);94 }95 }96 function unicode_char(value) {97 return String.fromCharCode(value);98 }99 function beautifier_tests()100 {101 sanitytest = test_obj;102 reset_options();103 //============================================================104 bth('');105 //============================================================106 // Handle inline and block elements differently - ()107 reset_options();108 test_fragment(109 '<body><h1>Block</h1></body>',110 // -- output --111 '<body>\n' +112 ' <h1>Block</h1>\n' +113 '</body>');114 test_fragment('<body><i>Inline</i></body>');115 //============================================================116 // End With Newline - (eof = "\n")117 reset_options();118 opts.end_with_newline = true;119 test_fragment('', '\n');120 test_fragment('<div></div>', '<div></div>\n');121 test_fragment('\n');122 // End With Newline - (eof = "")123 reset_options();124 opts.end_with_newline = false;125 test_fragment('');126 test_fragment('<div></div>');127 test_fragment('\n', '');128 //============================================================129 // Custom Extra Liners (empty) - ()130 reset_options();131 opts.extra_liners = [];132 test_fragment(133 '<html><head><meta></head><body><div><p>x</p></div></body></html>',134 // -- output --135 '<html>\n' +136 '<head>\n' +137 ' <meta>\n' +138 '</head>\n' +139 '<body>\n' +140 ' <div>\n' +141 ' <p>x</p>\n' +142 ' </div>\n' +143 '</body>\n' +144 '</html>');145 //============================================================146 // Custom Extra Liners (default) - ()147 reset_options();148 opts.extra_liners = null;149 test_fragment(150 '<html><head></head><body></body></html>',151 // -- output --152 '<html>\n' +153 '\n' +154 '<head></head>\n' +155 '\n' +156 '<body></body>\n' +157 '\n' +158 '</html>');159 //============================================================160 // Custom Extra Liners (p, string) - ()161 reset_options();162 opts.extra_liners = 'p,/p';163 test_fragment(164 '<html><head><meta></head><body><div><p>x</p></div></body></html>',165 // -- output --166 '<html>\n' +167 '<head>\n' +168 ' <meta>\n' +169 '</head>\n' +170 '<body>\n' +171 ' <div>\n' +172 '\n' +173 ' <p>x\n' +174 '\n' +175 ' </p>\n' +176 ' </div>\n' +177 '</body>\n' +178 '</html>');179 //============================================================180 // Custom Extra Liners (p) - ()181 reset_options();182 opts.extra_liners = ['p', '/p'];183 test_fragment(184 '<html><head><meta></head><body><div><p>x</p></div></body></html>',185 // -- output --186 '<html>\n' +187 '<head>\n' +188 ' <meta>\n' +189 '</head>\n' +190 '<body>\n' +191 ' <div>\n' +192 '\n' +193 ' <p>x\n' +194 '\n' +195 ' </p>\n' +196 ' </div>\n' +197 '</body>\n' +198 '</html>');199 //============================================================200 // Tests for script and style types (issue 453, 821)201 reset_options();202 bth(203 '<script type="text/unknown"><div></div></script>',204 // -- output --205 '<script type="text/unknown">\n' +206 ' <div></div>\n' +207 '</script>');208 bth(209 '<script type="text/javascript"><div></div></script>',210 // -- output --211 '<script type="text/javascript">\n' +212 ' < div > < /div>\n' +213 '</script>');214 bth(215 '<script><div></div></script>',216 // -- output --217 '<script>\n' +218 ' < div > < /div>\n' +219 '</script>');220 bth(221 '<script>var foo = "bar";</script>',222 // -- output --223 '<script>\n' +224 ' var foo = "bar";\n' +225 '</script>');226 bth(227 '<script type="text/javascript">var foo = "bar";</script>',228 // -- output --229 '<script type="text/javascript">\n' +230 ' var foo = "bar";\n' +231 '</script>');232 bth(233 '<script type="application/javascript">var foo = "bar";</script>',234 // -- output --235 '<script type="application/javascript">\n' +236 ' var foo = "bar";\n' +237 '</script>');238 bth(239 '<script type="application/javascript;version=1.8">var foo = "bar";</script>',240 // -- output --241 '<script type="application/javascript;version=1.8">\n' +242 ' var foo = "bar";\n' +243 '</script>');244 bth(245 '<script type="application/x-javascript">var foo = "bar";</script>',246 // -- output --247 '<script type="application/x-javascript">\n' +248 ' var foo = "bar";\n' +249 '</script>');250 bth(251 '<script type="application/ecmascript">var foo = "bar";</script>',252 // -- output --253 '<script type="application/ecmascript">\n' +254 ' var foo = "bar";\n' +255 '</script>');256 bth(257 '<script type="dojo/aspect">this.domNode.style.display="none";</script>',258 // -- output --259 '<script type="dojo/aspect">\n' +260 ' this.domNode.style.display = "none";\n' +261 '</script>');262 bth(263 '<script type="dojo/method">this.domNode.style.display="none";</script>',264 // -- output --265 '<script type="dojo/method">\n' +266 ' this.domNode.style.display = "none";\n' +267 '</script>');268 bth(269 '<script type="text/javascript1.5">var foo = "bar";</script>',270 // -- output --271 '<script type="text/javascript1.5">\n' +272 ' var foo = "bar";\n' +273 '</script>');274 bth(275 '<script type="application/json">{"foo":"bar"}</script>',276 // -- output --277 '<script type="application/json">\n' +278 ' {\n' +279 ' "foo": "bar"\n' +280 ' }\n' +281 '</script>');282 bth(283 '<script type="application/ld+json">{"foo":"bar"}</script>',284 // -- output --285 '<script type="application/ld+json">\n' +286 ' {\n' +287 ' "foo": "bar"\n' +288 ' }\n' +289 '</script>');290 bth(291 '<style type="text/unknown"><tag></tag></style>',292 // -- output --293 '<style type="text/unknown">\n' +294 ' <tag></tag>\n' +295 '</style>');296 bth(297 '<style type="text/css"><tag></tag></style>',298 // -- output --299 '<style type="text/css">\n' +300 ' <tag></tag>\n' +301 '</style>');302 bth(303 '<style><tag></tag></style>',304 // -- output --305 '<style>\n' +306 ' <tag></tag>\n' +307 '</style>');308 bth(309 '<style>.selector {font-size:12px;}</style>',310 // -- output --311 '<style>\n' +312 ' .selector {\n' +313 ' font-size: 12px;\n' +314 ' }\n' +315 '</style>');316 bth(317 '<style type="text/css">.selector {font-size:12px;}</style>',318 // -- output --319 '<style type="text/css">\n' +320 ' .selector {\n' +321 ' font-size: 12px;\n' +322 ' }\n' +323 '</style>');324 //============================================================325 // Attribute Wrap alignment with spaces - ()326 reset_options();327 opts.wrap_attributes = 'force-aligned';328 opts.indent_with_tabs = true;329 test_fragment(330 '<div><div a="1" b="2"><div>test</div></div></div>',331 // -- output --332 '<div>\n' +333 '\t<div a="1"\n' +334 '\t b="2">\n' +335 '\t\t<div>test</div>\n' +336 '\t</div>\n' +337 '</div>');338 //============================================================339 // Attribute Wrap de-indent - ()340 reset_options();341 opts.wrap_attributes = 'force-aligned';342 opts.indent_with_tabs = false;343 test_fragment(344 '<div a="1" b="2"><div>test</div></div>',345 // -- output --346 '<div a="1"\n' +347 ' b="2">\n' +348 ' <div>test</div>\n' +349 '</div>');350 test_fragment(351 '<p>\n' +352 ' <a href="/test/" target="_blank"><img src="test.jpg" /></a><a href="/test/" target="_blank"><img src="test.jpg" /></a>\n' +353 '</p>',354 // -- output --355 '<p>\n' +356 ' <a href="/test/"\n' +357 ' target="_blank"><img src="test.jpg" /></a><a href="/test/"\n' +358 ' target="_blank"><img src="test.jpg" /></a>\n' +359 '</p>');360 test_fragment(361 '<p>\n' +362 ' <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' +363 '</p>',364 // -- output --365 '<p>\n' +366 ' <span data-not-a-href="/test/"\n' +367 ' data-totally-not-a-target="_blank"><img src="test.jpg" /></span><span data-not-a-href="/test/"\n' +368 ' data-totally-not-a-target="_blank"><img src="test.jpg" /></span>\n' +369 '</p>');370 //============================================================371 // Attribute Wrap - (indent_attr = "\n ", indent_attr_first = " ", indent_end = "", indent_end_selfclosing = " ", indent_over80 = "\n ")372 reset_options();373 opts.wrap_attributes = 'force';374 test_fragment('<div >This is some text</div>', '<div>This is some text</div>');375 test_fragment('<div attr="123" >This is some text</div>', '<div attr="123">This is some text</div>');376 test_fragment(377 '<div attr0 attr1="123" data-attr2="hello t here">This is some text</div>',378 // -- output --379 '<div attr0\n' +380 ' attr1="123"\n' +381 ' data-attr2="hello t here">This is some text</div>');382 test_fragment(383 '<div lookatthissuperduperlongattributenamewhoahcrazy0="true" attr0 attr1="123" data-attr2="hello t here" heymanimreallylongtoowhocomesupwiththesenames="false">This is some text</div>',384 // -- output --385 '<div lookatthissuperduperlongattributenamewhoahcrazy0="true"\n' +386 ' attr0\n' +387 ' attr1="123"\n' +388 ' data-attr2="hello t here"\n' +389 ' heymanimreallylongtoowhocomesupwiththesenames="false">This is some text</div>');390 test_fragment(391 '<img attr0 attr1="123" data-attr2="hello t here"/>',392 // -- output --393 '<img attr0\n' +394 ' attr1="123"\n' +395 ' data-attr2="hello t here" />');396 test_fragment(397 '<?xml version="1.0" encoding="UTF-8" ?><root attr1="foo" attr2="bar"/>',398 // -- output --399 '<?xml version="1.0" encoding="UTF-8" ?>\n' +400 '<root attr1="foo"\n' +401 ' attr2="bar" />');402 test_fragment(403 '<link href="//fonts.googleapis.com/css?family=Open+Sans:300italic,400italic,600italic,700italic,400,600,700,300&amp;subset=latin" rel="stylesheet" type="text/css">',404 // -- output --405 '<link href="//fonts.googleapis.com/css?family=Open+Sans:300italic,400italic,600italic,700italic,400,600,700,300&amp;subset=latin"\n' +406 ' rel="stylesheet"\n' +407 ' type="text/css">');408 // Attribute Wrap - (indent_attr = "\n ", indent_attr_first = " ", indent_end = "", indent_end_selfclosing = " ", indent_over80 = "\n ")409 reset_options();410 opts.wrap_attributes = 'force';411 opts.wrap_line_length = 80;412 test_fragment('<div >This is some text</div>', '<div>This is some text</div>');413 test_fragment('<div attr="123" >This is some text</div>', '<div attr="123">This is some text</div>');414 test_fragment(415 '<div attr0 attr1="123" data-attr2="hello t here">This is some text</div>',416 // -- output --417 '<div attr0\n' +418 ' attr1="123"\n' +419 ' data-attr2="hello t here">This is some text</div>');420 test_fragment(421 '<div lookatthissuperduperlongattributenamewhoahcrazy0="true" attr0 attr1="123" data-attr2="hello t here" heymanimreallylongtoowhocomesupwiththesenames="false">This is some text</div>',422 // -- output --423 '<div lookatthissuperduperlongattributenamewhoahcrazy0="true"\n' +424 ' attr0\n' +425 ' attr1="123"\n' +426 ' data-attr2="hello t here"\n' +427 ' heymanimreallylongtoowhocomesupwiththesenames="false">This is some text</div>');428 test_fragment(429 '<img attr0 attr1="123" data-attr2="hello t here"/>',430 // -- output --431 '<img attr0\n' +432 ' attr1="123"\n' +433 ' data-attr2="hello t here" />');434 test_fragment(435 '<?xml version="1.0" encoding="UTF-8" ?><root attr1="foo" attr2="bar"/>',436 // -- output --437 '<?xml version="1.0" encoding="UTF-8" ?>\n' +438 '<root attr1="foo"\n' +439 ' attr2="bar" />');440 test_fragment(441 '<link href="//fonts.googleapis.com/css?family=Open+Sans:300italic,400italic,600italic,700italic,400,600,700,300&amp;subset=latin" rel="stylesheet" type="text/css">',442 // -- output --443 '<link href="//fonts.googleapis.com/css?family=Open+Sans:300italic,400italic,600italic,700italic,400,600,700,300&amp;subset=latin"\n' +444 ' rel="stylesheet"\n' +445 ' type="text/css">');446 // Attribute Wrap - (indent_attr = "\n ", indent_attr_first = " ", indent_end = "", indent_end_selfclosing = " ", indent_over80 = "\n ")447 reset_options();448 opts.wrap_attributes = 'force';449 opts.wrap_attributes_indent_size = 8;450 test_fragment('<div >This is some text</div>', '<div>This is some text</div>');451 test_fragment('<div attr="123" >This is some text</div>', '<div attr="123">This is some text</div>');452 test_fragment(453 '<div attr0 attr1="123" data-attr2="hello t here">This is some text</div>',454 // -- output --455 '<div attr0\n' +456 ' attr1="123"\n' +457 ' data-attr2="hello t here">This is some text</div>');458 test_fragment(459 '<div lookatthissuperduperlongattributenamewhoahcrazy0="true" attr0 attr1="123" data-attr2="hello t here" heymanimreallylongtoowhocomesupwiththesenames="false">This is some text</div>',460 // -- output --461 '<div lookatthissuperduperlongattributenamewhoahcrazy0="true"\n' +462 ' attr0\n' +463 ' attr1="123"\n' +464 ' data-attr2="hello t here"\n' +465 ' heymanimreallylongtoowhocomesupwiththesenames="false">This is some text</div>');466 test_fragment(467 '<img attr0 attr1="123" data-attr2="hello t here"/>',468 // -- output --469 '<img attr0\n' +470 ' attr1="123"\n' +471 ' data-attr2="hello t here" />');472 test_fragment(473 '<?xml version="1.0" encoding="UTF-8" ?><root attr1="foo" attr2="bar"/>',474 // -- output --475 '<?xml version="1.0" encoding="UTF-8" ?>\n' +476 '<root attr1="foo"\n' +477 ' attr2="bar" />');478 test_fragment(479 '<link href="//fonts.googleapis.com/css?family=Open+Sans:300italic,400italic,600italic,700italic,400,600,700,300&amp;subset=latin" rel="stylesheet" type="text/css">',480 // -- output --481 '<link href="//fonts.googleapis.com/css?family=Open+Sans:300italic,400italic,600italic,700italic,400,600,700,300&amp;subset=latin"\n' +482 ' rel="stylesheet"\n' +483 ' type="text/css">');484 // Attribute Wrap - (indent_attr = " ", indent_attr_first = " ", indent_end = "", indent_end_selfclosing = " ", indent_over80 = "\n")485 reset_options();486 opts.wrap_attributes = 'auto';487 opts.wrap_line_length = 80;488 opts.wrap_attributes_indent_size = 0;489 test_fragment('<div >This is some text</div>', '<div>This is some text</div>');490 test_fragment('<div attr="123" >This is some text</div>', '<div attr="123">This is some text</div>');491 test_fragment('<div attr0 attr1="123" data-attr2="hello t here">This is some text</div>');492 test_fragment(493 '<div lookatthissuperduperlongattributenamewhoahcrazy0="true" attr0 attr1="123" data-attr2="hello t here" heymanimreallylongtoowhocomesupwiththesenames="false">This is some text</div>',494 // -- output --495 '<div lookatthissuperduperlongattributenamewhoahcrazy0="true" attr0 attr1="123" data-attr2="hello t here"\n' +496 'heymanimreallylongtoowhocomesupwiththesenames="false">This is some text</div>');497 test_fragment('<img attr0 attr1="123" data-attr2="hello t here"/>', '<img attr0 attr1="123" data-attr2="hello t here" />');498 test_fragment(499 '<?xml version="1.0" encoding="UTF-8" ?><root attr1="foo" attr2="bar"/>',500 // -- output --501 '<?xml version="1.0" encoding="UTF-8" ?>\n' +502 '<root attr1="foo" attr2="bar" />');503 test_fragment(504 '<link href="//fonts.googleapis.com/css?family=Open+Sans:300italic,400italic,600italic,700italic,400,600,700,300&amp;subset=latin" rel="stylesheet" type="text/css">',505 // -- output --506 '<link href="//fonts.googleapis.com/css?family=Open+Sans:300italic,400italic,600italic,700italic,400,600,700,300&amp;subset=latin"\n' +507 'rel="stylesheet" type="text/css">');508 // Attribute Wrap - (indent_attr = " ", indent_attr_first = " ", indent_end = "", indent_end_selfclosing = " ", indent_over80 = "\n ")509 reset_options();510 opts.wrap_attributes = 'auto';511 opts.wrap_line_length = 80;512 opts.wrap_attributes_indent_size = 4;513 test_fragment('<div >This is some text</div>', '<div>This is some text</div>');514 test_fragment('<div attr="123" >This is some text</div>', '<div attr="123">This is some text</div>');515 test_fragment('<div attr0 attr1="123" data-attr2="hello t here">This is some text</div>');516 test_fragment(517 '<div lookatthissuperduperlongattributenamewhoahcrazy0="true" attr0 attr1="123" data-attr2="hello t here" heymanimreallylongtoowhocomesupwiththesenames="false">This is some text</div>',518 // -- output --519 '<div lookatthissuperduperlongattributenamewhoahcrazy0="true" attr0 attr1="123" data-attr2="hello t here"\n' +520 ' heymanimreallylongtoowhocomesupwiththesenames="false">This is some text</div>');521 test_fragment('<img attr0 attr1="123" data-attr2="hello t here"/>', '<img attr0 attr1="123" data-attr2="hello t here" />');522 test_fragment(523 '<?xml version="1.0" encoding="UTF-8" ?><root attr1="foo" attr2="bar"/>',524 // -- output --525 '<?xml version="1.0" encoding="UTF-8" ?>\n' +526 '<root attr1="foo" attr2="bar" />');527 test_fragment(528 '<link href="//fonts.googleapis.com/css?family=Open+Sans:300italic,400italic,600italic,700italic,400,600,700,300&amp;subset=latin" rel="stylesheet" type="text/css">',529 // -- output --530 '<link href="//fonts.googleapis.com/css?family=Open+Sans:300italic,400italic,600italic,700italic,400,600,700,300&amp;subset=latin"\n' +531 ' rel="stylesheet" type="text/css">');532 // Attribute Wrap - (indent_attr = " ", indent_attr_first = " ", indent_end = "", indent_end_selfclosing = " ", indent_over80 = " ")533 reset_options();534 opts.wrap_attributes = 'auto';535 opts.wrap_line_length = 0;536 test_fragment('<div >This is some text</div>', '<div>This is some text</div>');537 test_fragment('<div attr="123" >This is some text</div>', '<div attr="123">This is some text</div>');538 test_fragment('<div attr0 attr1="123" data-attr2="hello t here">This is some text</div>');539 test_fragment('<div lookatthissuperduperlongattributenamewhoahcrazy0="true" attr0 attr1="123" data-attr2="hello t here" heymanimreallylongtoowhocomesupwiththesenames="false">This is some text</div>');540 test_fragment('<img attr0 attr1="123" data-attr2="hello t here"/>', '<img attr0 attr1="123" data-attr2="hello t here" />');541 test_fragment(542 '<?xml version="1.0" encoding="UTF-8" ?><root attr1="foo" attr2="bar"/>',543 // -- output --544 '<?xml version="1.0" encoding="UTF-8" ?>\n' +545 '<root attr1="foo" attr2="bar" />');546 test_fragment('<link href="//fonts.googleapis.com/css?family=Open+Sans:300italic,400italic,600italic,700italic,400,600,700,300&amp;subset=latin" rel="stylesheet" type="text/css">');547 // Attribute Wrap - (indent_attr = "\n ", indent_attr_faligned = " ", indent_attr_first = " ", indent_end = "", indent_end_selfclosing = " ", indent_over80 = "\n ")548 reset_options();549 opts.wrap_attributes = 'force-aligned';550 test_fragment('<div >This is some text</div>', '<div>This is some text</div>');551 test_fragment('<div attr="123" >This is some text</div>', '<div attr="123">This is some text</div>');552 test_fragment(553 '<div attr0 attr1="123" data-attr2="hello t here">This is some text</div>',554 // -- output --555 '<div attr0\n' +556 ' attr1="123"\n' +557 ' data-attr2="hello t here">This is some text</div>');558 test_fragment(559 '<div lookatthissuperduperlongattributenamewhoahcrazy0="true" attr0 attr1="123" data-attr2="hello t here" heymanimreallylongtoowhocomesupwiththesenames="false">This is some text</div>',560 // -- output --561 '<div lookatthissuperduperlongattributenamewhoahcrazy0="true"\n' +562 ' attr0\n' +563 ' attr1="123"\n' +564 ' data-attr2="hello t here"\n' +565 ' heymanimreallylongtoowhocomesupwiththesenames="false">This is some text</div>');566 test_fragment(567 '<img attr0 attr1="123" data-attr2="hello t here"/>',568 // -- output --569 '<img attr0\n' +570 ' attr1="123"\n' +571 ' data-attr2="hello t here" />');572 test_fragment(573 '<?xml version="1.0" encoding="UTF-8" ?><root attr1="foo" attr2="bar"/>',574 // -- output --575 '<?xml version="1.0" encoding="UTF-8" ?>\n' +576 '<root attr1="foo"\n' +577 ' attr2="bar" />');578 test_fragment(579 '<link href="//fonts.googleapis.com/css?family=Open+Sans:300italic,400italic,600italic,700italic,400,600,700,300&amp;subset=latin" rel="stylesheet" type="text/css">',580 // -- output --581 '<link href="//fonts.googleapis.com/css?family=Open+Sans:300italic,400italic,600italic,700italic,400,600,700,300&amp;subset=latin"\n' +582 ' rel="stylesheet"\n' +583 ' type="text/css">');584 // Attribute Wrap - (indent_attr = "\n ", indent_attr_faligned = " ", indent_attr_first = " ", indent_end = "", indent_end_selfclosing = " ", indent_over80 = "\n ")585 reset_options();586 opts.wrap_attributes = 'force-aligned';587 opts.wrap_line_length = 80;588 test_fragment('<div >This is some text</div>', '<div>This is some text</div>');589 test_fragment('<div attr="123" >This is some text</div>', '<div attr="123">This is some text</div>');590 test_fragment(591 '<div attr0 attr1="123" data-attr2="hello t here">This is some text</div>',592 // -- output --593 '<div attr0\n' +594 ' attr1="123"\n' +595 ' data-attr2="hello t here">This is some text</div>');596 test_fragment(597 '<div lookatthissuperduperlongattributenamewhoahcrazy0="true" attr0 attr1="123" data-attr2="hello t here" heymanimreallylongtoowhocomesupwiththesenames="false">This is some text</div>',598 // -- output --599 '<div lookatthissuperduperlongattributenamewhoahcrazy0="true"\n' +600 ' attr0\n' +601 ' attr1="123"\n' +602 ' data-attr2="hello t here"\n' +603 ' heymanimreallylongtoowhocomesupwiththesenames="false">This is some text</div>');604 test_fragment(605 '<img attr0 attr1="123" data-attr2="hello t here"/>',606 // -- output --607 '<img attr0\n' +608 ' attr1="123"\n' +609 ' data-attr2="hello t here" />');610 test_fragment(611 '<?xml version="1.0" encoding="UTF-8" ?><root attr1="foo" attr2="bar"/>',612 // -- output --613 '<?xml version="1.0" encoding="UTF-8" ?>\n' +614 '<root attr1="foo"\n' +615 ' attr2="bar" />');616 test_fragment(617 '<link href="//fonts.googleapis.com/css?family=Open+Sans:300italic,400italic,600italic,700italic,400,600,700,300&amp;subset=latin" rel="stylesheet" type="text/css">',618 // -- output --619 '<link href="//fonts.googleapis.com/css?family=Open+Sans:300italic,400italic,600italic,700italic,400,600,700,300&amp;subset=latin"\n' +620 ' rel="stylesheet"\n' +621 ' type="text/css">');622 // Attribute Wrap - (indent_attr = "\n ", indent_attr_faligned = " ", indent_attr_first = " ", indent_end = "", indent_end_selfclosing = " ", indent_over80 = "\n ")623 reset_options();624 opts.wrap_attributes = 'force-aligned';625 opts.wrap_attributes_indent_size = 8;626 test_fragment('<div >This is some text</div>', '<div>This is some text</div>');627 test_fragment('<div attr="123" >This is some text</div>', '<div attr="123">This is some text</div>');628 test_fragment(629 '<div attr0 attr1="123" data-attr2="hello t here">This is some text</div>',630 // -- output --631 '<div attr0\n' +632 ' attr1="123"\n' +633 ' data-attr2="hello t here">This is some text</div>');634 test_fragment(635 '<div lookatthissuperduperlongattributenamewhoahcrazy0="true" attr0 attr1="123" data-attr2="hello t here" heymanimreallylongtoowhocomesupwiththesenames="false">This is some text</div>',636 // -- output --637 '<div lookatthissuperduperlongattributenamewhoahcrazy0="true"\n' +638 ' attr0\n' +639 ' attr1="123"\n' +640 ' data-attr2="hello t here"\n' +641 ' heymanimreallylongtoowhocomesupwiththesenames="false">This is some text</div>');642 test_fragment(643 '<img attr0 attr1="123" data-attr2="hello t here"/>',644 // -- output --645 '<img attr0\n' +646 ' attr1="123"\n' +647 ' data-attr2="hello t here" />');648 test_fragment(649 '<?xml version="1.0" encoding="UTF-8" ?><root attr1="foo" attr2="bar"/>',650 // -- output --651 '<?xml version="1.0" encoding="UTF-8" ?>\n' +652 '<root attr1="foo"\n' +653 ' attr2="bar" />');654 test_fragment(655 '<link href="//fonts.googleapis.com/css?family=Open+Sans:300italic,400italic,600italic,700italic,400,600,700,300&amp;subset=latin" rel="stylesheet" type="text/css">',656 // -- output --657 '<link href="//fonts.googleapis.com/css?family=Open+Sans:300italic,400italic,600italic,700italic,400,600,700,300&amp;subset=latin"\n' +658 ' rel="stylesheet"\n' +659 ' type="text/css">');660 // Attribute Wrap - (indent_attr = "\n ", indent_attr_first = "\n ", indent_end = "\n", indent_end_selfclosing = "\n", indent_over80 = "\n ")661 reset_options();662 opts.wrap_attributes = 'force-expand-multiline';663 opts.wrap_attributes_indent_size = 4;664 test_fragment('<div >This is some text</div>', '<div>This is some text</div>');665 test_fragment('<div attr="123" >This is some text</div>', '<div attr="123">This is some text</div>');666 test_fragment(667 '<div attr0 attr1="123" data-attr2="hello t here">This is some text</div>',668 // -- output --669 '<div\n' +670 ' attr0\n' +671 ' attr1="123"\n' +672 ' data-attr2="hello t here"\n' +673 '>This is some text</div>');674 test_fragment(675 '<div lookatthissuperduperlongattributenamewhoahcrazy0="true" attr0 attr1="123" data-attr2="hello t here" heymanimreallylongtoowhocomesupwiththesenames="false">This is some text</div>',676 // -- output --677 '<div\n' +678 ' lookatthissuperduperlongattributenamewhoahcrazy0="true"\n' +679 ' attr0\n' +680 ' attr1="123"\n' +681 ' data-attr2="hello t here"\n' +682 ' heymanimreallylongtoowhocomesupwiththesenames="false"\n' +683 '>This is some text</div>');684 test_fragment(685 '<img attr0 attr1="123" data-attr2="hello t here"/>',686 // -- output --687 '<img\n' +688 ' attr0\n' +689 ' attr1="123"\n' +690 ' data-attr2="hello t here"\n' +691 '/>');692 test_fragment(693 '<?xml version="1.0" encoding="UTF-8" ?><root attr1="foo" attr2="bar"/>',694 // -- output --695 '<?xml version="1.0" encoding="UTF-8" ?>\n' +696 '<root\n' +697 ' attr1="foo"\n' +698 ' attr2="bar"\n' +699 '/>');700 test_fragment(701 '<link href="//fonts.googleapis.com/css?family=Open+Sans:300italic,400italic,600italic,700italic,400,600,700,300&amp;subset=latin" rel="stylesheet" type="text/css">',702 // -- output --703 '<link\n' +704 ' href="//fonts.googleapis.com/css?family=Open+Sans:300italic,400italic,600italic,700italic,400,600,700,300&amp;subset=latin"\n' +705 ' rel="stylesheet"\n' +706 ' type="text/css"\n' +707 '>');708 // Attribute Wrap - (indent_attr = "\n ", indent_attr_first = "\n ", indent_end = "\n", indent_end_selfclosing = "\n", indent_over80 = "\n ")709 reset_options();710 opts.wrap_attributes = 'force-expand-multiline';711 opts.wrap_attributes_indent_size = 4;712 opts.wrap_line_length = 80;713 test_fragment('<div >This is some text</div>', '<div>This is some text</div>');714 test_fragment('<div attr="123" >This is some text</div>', '<div attr="123">This is some text</div>');715 test_fragment(716 '<div attr0 attr1="123" data-attr2="hello t here">This is some text</div>',717 // -- output --718 '<div\n' +719 ' attr0\n' +720 ' attr1="123"\n' +721 ' data-attr2="hello t here"\n' +722 '>This is some text</div>');723 test_fragment(724 '<div lookatthissuperduperlongattributenamewhoahcrazy0="true" attr0 attr1="123" data-attr2="hello t here" heymanimreallylongtoowhocomesupwiththesenames="false">This is some text</div>',725 // -- output --726 '<div\n' +727 ' lookatthissuperduperlongattributenamewhoahcrazy0="true"\n' +728 ' attr0\n' +729 ' attr1="123"\n' +730 ' data-attr2="hello t here"\n' +731 ' heymanimreallylongtoowhocomesupwiththesenames="false"\n' +732 '>This is some text</div>');733 test_fragment(734 '<img attr0 attr1="123" data-attr2="hello t here"/>',735 // -- output --736 '<img\n' +737 ' attr0\n' +738 ' attr1="123"\n' +739 ' data-attr2="hello t here"\n' +740 '/>');741 test_fragment(742 '<?xml version="1.0" encoding="UTF-8" ?><root attr1="foo" attr2="bar"/>',743 // -- output --744 '<?xml version="1.0" encoding="UTF-8" ?>\n' +745 '<root\n' +746 ' attr1="foo"\n' +747 ' attr2="bar"\n' +748 '/>');749 test_fragment(750 '<link href="//fonts.googleapis.com/css?family=Open+Sans:300italic,400italic,600italic,700italic,400,600,700,300&amp;subset=latin" rel="stylesheet" type="text/css">',751 // -- output --752 '<link\n' +753 ' href="//fonts.googleapis.com/css?family=Open+Sans:300italic,400italic,600italic,700italic,400,600,700,300&amp;subset=latin"\n' +754 ' rel="stylesheet"\n' +755 ' type="text/css"\n' +756 '>');757 // Attribute Wrap - (indent_attr = "\n ", indent_attr_first = "\n ", indent_end = "\n", indent_end_selfclosing = "\n", indent_over80 = "\n ")758 reset_options();759 opts.wrap_attributes = 'force-expand-multiline';760 opts.wrap_attributes_indent_size = 8;761 test_fragment('<div >This is some text</div>', '<div>This is some text</div>');762 test_fragment('<div attr="123" >This is some text</div>', '<div attr="123">This is some text</div>');763 test_fragment(764 '<div attr0 attr1="123" data-attr2="hello t here">This is some text</div>',765 // -- output --766 '<div\n' +767 ' attr0\n' +768 ' attr1="123"\n' +769 ' data-attr2="hello t here"\n' +770 '>This is some text</div>');771 test_fragment(772 '<div lookatthissuperduperlongattributenamewhoahcrazy0="true" attr0 attr1="123" data-attr2="hello t here" heymanimreallylongtoowhocomesupwiththesenames="false">This is some text</div>',773 // -- output --774 '<div\n' +775 ' lookatthissuperduperlongattributenamewhoahcrazy0="true"\n' +776 ' attr0\n' +777 ' attr1="123"\n' +778 ' data-attr2="hello t here"\n' +779 ' heymanimreallylongtoowhocomesupwiththesenames="false"\n' +780 '>This is some text</div>');781 test_fragment(782 '<img attr0 attr1="123" data-attr2="hello t here"/>',783 // -- output --784 '<img\n' +785 ' attr0\n' +786 ' attr1="123"\n' +787 ' data-attr2="hello t here"\n' +788 '/>');789 test_fragment(790 '<?xml version="1.0" encoding="UTF-8" ?><root attr1="foo" attr2="bar"/>',791 // -- output --792 '<?xml version="1.0" encoding="UTF-8" ?>\n' +793 '<root\n' +794 ' attr1="foo"\n' +795 ' attr2="bar"\n' +796 '/>');797 test_fragment(798 '<link href="//fonts.googleapis.com/css?family=Open+Sans:300italic,400italic,600italic,700italic,400,600,700,300&amp;subset=latin" rel="stylesheet" type="text/css">',799 // -- output --800 '<link\n' +801 ' href="//fonts.googleapis.com/css?family=Open+Sans:300italic,400italic,600italic,700italic,400,600,700,300&amp;subset=latin"\n' +802 ' rel="stylesheet"\n' +803 ' type="text/css"\n' +804 '>');805 //============================================================806 // Handlebars Indenting Off807 reset_options();808 opts.indent_handlebars = false;809 test_fragment(810 '{{#if 0}}\n' +811 ' <div>\n' +812 ' </div>\n' +813 '{{/if}}',814 // -- output --815 '{{#if 0}}\n' +816 '<div>\n' +817 '</div>\n' +818 '{{/if}}');819 test_fragment(820 '<div>\n' +821 '{{#each thing}}\n' +822 ' {{name}}\n' +823 '{{/each}}\n' +824 '</div>',825 // -- output --826 '<div>\n' +827 ' {{#each thing}} {{name}} {{/each}}\n' +828 '</div>');829 //============================================================830 // Handlebars Indenting On - (content = "{{field}}")831 reset_options();832 opts.indent_handlebars = true;833 test_fragment('{{page-title}}');834 test_fragment('{{#if 0}}{{/if}}');835 test_fragment('{{#if 0}}{{field}}{{/if}}');836 test_fragment(837 '{{#if 0}}\n' +838 '{{/if}}');839 test_fragment(840 '{{#if words}}{{/if}}',841 // -- output --842 '{{#if words}}{{/if}}');843 test_fragment(844 '{{#if words}}{{field}}{{/if}}',845 // -- output --846 '{{#if words}}{{field}}{{/if}}');847 test_fragment(848 '{{#if words}}{{field}}{{/if}}',849 // -- output --850 '{{#if words}}{{field}}{{/if}}');851 test_fragment(852 '{{#if 1}}\n' +853 ' <div>\n' +854 ' </div>\n' +855 '{{/if}}');856 test_fragment(857 '{{#if 1}}\n' +858 '<div>\n' +859 '</div>\n' +860 '{{/if}}',861 // -- output --862 '{{#if 1}}\n' +863 ' <div>\n' +864 ' </div>\n' +865 '{{/if}}');866 test_fragment(867 '<div>\n' +868 ' {{#if 1}}\n' +869 ' {{/if}}\n' +870 '</div>');871 test_fragment(872 '<div>\n' +873 '{{#if 1}}\n' +874 '{{/if}}\n' +875 '</div>',876 // -- output --877 '<div>\n' +878 ' {{#if 1}}\n' +879 ' {{/if}}\n' +880 '</div>');881 test_fragment(882 '{{#if}}\n' +883 '{{#each}}\n' +884 '{{#if}}\n' +885 '{{field}}\n' +886 '{{/if}}\n' +887 '{{#if}}\n' +888 '{{field}}\n' +889 '{{/if}}\n' +890 '{{/each}}\n' +891 '{{/if}}',892 // -- output --893 '{{#if}}\n' +894 ' {{#each}}\n' +895 ' {{#if}}\n' +896 ' {{field}}\n' +897 ' {{/if}}\n' +898 ' {{#if}}\n' +899 ' {{field}}\n' +900 ' {{/if}}\n' +901 ' {{/each}}\n' +902 '{{/if}}');903 test_fragment(904 '{{#if 1}}\n' +905 ' <div>\n' +906 ' </div>\n' +907 '{{/if}}');908 test_fragment(909 '{{#if 1}}\n' +910 ' {{field}}\n' +911 ' {{else}}\n' +912 ' {{field}}\n' +913 '{{/if}}',914 // -- output --915 '{{#if 1}}\n' +916 ' {{field}}\n' +917 '{{else}}\n' +918 ' {{field}}\n' +919 '{{/if}}');920 test_fragment(921 '{{#if 1}}\n' +922 ' {{else}}\n' +923 ' {{/if}}',924 // -- output --925 '{{#if 1}}\n' +926 '{{else}}\n' +927 '{{/if}}');928 test_fragment(929 '{{#if thing}}\n' +930 '{{#if otherthing}}\n' +931 ' {{field}}\n' +932 ' {{else}}\n' +933 '{{field}}\n' +934 ' {{/if}}\n' +935 ' {{else}}\n' +936 '{{field}}\n' +937 '{{/if}}',938 // -- output --939 '{{#if thing}}\n' +940 ' {{#if otherthing}}\n' +941 ' {{field}}\n' +942 ' {{else}}\n' +943 ' {{field}}\n' +944 ' {{/if}}\n' +945 '{{else}}\n' +946 ' {{field}}\n' +947 '{{/if}}');948 test_fragment(949 '<div{{somestyle}}></div>',950 // -- output --951 '<div {{somestyle}}></div>');952 test_fragment(953 '<div{{#if test}}class="foo"{{/if}}>{{field}}</div>',954 // -- output --955 '<div {{#if test}} class="foo" {{/if}}>{{field}}</div>');956 test_fragment(957 '<div{{#if thing}}{{somestyle}}class="{{class}}"{{else}}class="{{class2}}"{{/if}}>{{field}}</div>',958 // -- output --959 '<div {{#if thing}} {{somestyle}} class="{{class}}" {{else}} class="{{class2}}" {{/if}}>{{field}}</div>');960 test_fragment(961 '<span{{#if condition}}class="foo"{{/if}}>{{field}}</span>',962 // -- output --963 '<span {{#if condition}} class="foo" {{/if}}>{{field}}</span>');964 test_fragment('<div unformatted="{{#if}}{{field}}{{/if}}">{{field}}</div>');965 test_fragment('<div unformatted="{{#if }} {{field}}{{/if}}">{{field}}</div>');966 test_fragment('<div class="{{#if thingIs "value"}}{{field}}{{/if}}"></div>');967 test_fragment('<div class="{{#if thingIs \'value\'}}{{field}}{{/if}}"></div>');968 test_fragment('<div class=\'{{#if thingIs "value"}}{{field}}{{/if}}\'></div>');969 test_fragment('<div class=\'{{#if thingIs \'value\'}}{{field}}{{/if}}\'></div>');970 test_fragment('<span>{{condition < 0 ? "result1" : "result2"}}</span>');971 test_fragment('<span>{{condition1 && condition2 && condition3 && condition4 < 0 ? "resForTrue" : "resForFalse"}}</span>');972 // Handlebars Indenting On - (content = "{{! comment}}")973 reset_options();974 opts.indent_handlebars = true;975 test_fragment('{{page-title}}');976 test_fragment('{{#if 0}}{{/if}}');977 test_fragment('{{#if 0}}{{! comment}}{{/if}}');978 test_fragment(979 '{{#if 0}}\n' +980 '{{/if}}');981 test_fragment(982 '{{#if words}}{{/if}}',983 // -- output --984 '{{#if words}}{{/if}}');985 test_fragment(986 '{{#if words}}{{! comment}}{{/if}}',987 // -- output --988 '{{#if words}}{{! comment}}{{/if}}');989 test_fragment(990 '{{#if words}}{{! comment}}{{/if}}',991 // -- output --992 '{{#if words}}{{! comment}}{{/if}}');993 test_fragment(994 '{{#if 1}}\n' +995 ' <div>\n' +996 ' </div>\n' +997 '{{/if}}');998 test_fragment(999 '{{#if 1}}\n' +1000 '<div>\n' +1001 '</div>\n' +1002 '{{/if}}',1003 // -- output --1004 '{{#if 1}}\n' +1005 ' <div>\n' +1006 ' </div>\n' +1007 '{{/if}}');1008 test_fragment(1009 '<div>\n' +1010 ' {{#if 1}}\n' +1011 ' {{/if}}\n' +1012 '</div>');1013 test_fragment(1014 '<div>\n' +1015 '{{#if 1}}\n' +1016 '{{/if}}\n' +1017 '</div>',1018 // -- output --1019 '<div>\n' +1020 ' {{#if 1}}\n' +1021 ' {{/if}}\n' +1022 '</div>');1023 test_fragment(1024 '{{#if}}\n' +1025 '{{#each}}\n' +1026 '{{#if}}\n' +1027 '{{! comment}}\n' +1028 '{{/if}}\n' +1029 '{{#if}}\n' +1030 '{{! comment}}\n' +1031 '{{/if}}\n' +1032 '{{/each}}\n' +1033 '{{/if}}',1034 // -- output --1035 '{{#if}}\n' +1036 ' {{#each}}\n' +1037 ' {{#if}}\n' +1038 ' {{! comment}}\n' +1039 ' {{/if}}\n' +1040 ' {{#if}}\n' +1041 ' {{! comment}}\n' +1042 ' {{/if}}\n' +1043 ' {{/each}}\n' +1044 '{{/if}}');1045 test_fragment(1046 '{{#if 1}}\n' +1047 ' <div>\n' +1048 ' </div>\n' +1049 '{{/if}}');1050 test_fragment(1051 '{{#if 1}}\n' +1052 ' {{! comment}}\n' +1053 ' {{else}}\n' +1054 ' {{! comment}}\n' +1055 '{{/if}}',1056 // -- output --1057 '{{#if 1}}\n' +1058 ' {{! comment}}\n' +1059 '{{else}}\n' +1060 ' {{! comment}}\n' +1061 '{{/if}}');1062 test_fragment(1063 '{{#if 1}}\n' +1064 ' {{else}}\n' +1065 ' {{/if}}',1066 // -- output --1067 '{{#if 1}}\n' +1068 '{{else}}\n' +1069 '{{/if}}');1070 test_fragment(1071 '{{#if thing}}\n' +1072 '{{#if otherthing}}\n' +1073 ' {{! comment}}\n' +1074 ' {{else}}\n' +1075 '{{! comment}}\n' +1076 ' {{/if}}\n' +1077 ' {{else}}\n' +1078 '{{! comment}}\n' +1079 '{{/if}}',1080 // -- output --1081 '{{#if thing}}\n' +1082 ' {{#if otherthing}}\n' +1083 ' {{! comment}}\n' +1084 ' {{else}}\n' +1085 ' {{! comment}}\n' +1086 ' {{/if}}\n' +1087 '{{else}}\n' +1088 ' {{! comment}}\n' +1089 '{{/if}}');1090 test_fragment(1091 '<div{{somestyle}}></div>',1092 // -- output --1093 '<div {{somestyle}}></div>');1094 test_fragment(1095 '<div{{#if test}}class="foo"{{/if}}>{{! comment}}</div>',1096 // -- output --1097 '<div {{#if test}} class="foo" {{/if}}>{{! comment}}</div>');1098 test_fragment(1099 '<div{{#if thing}}{{somestyle}}class="{{class}}"{{else}}class="{{class2}}"{{/if}}>{{! comment}}</div>',1100 // -- output --1101 '<div {{#if thing}} {{somestyle}} class="{{class}}" {{else}} class="{{class2}}" {{/if}}>{{! comment}}</div>');1102 test_fragment(1103 '<span{{#if condition}}class="foo"{{/if}}>{{! comment}}</span>',1104 // -- output --1105 '<span {{#if condition}} class="foo" {{/if}}>{{! comment}}</span>');1106 test_fragment('<div unformatted="{{#if}}{{! comment}}{{/if}}">{{! comment}}</div>');1107 test_fragment('<div unformatted="{{#if }} {{! comment}}{{/if}}">{{! comment}}</div>');1108 test_fragment('<div class="{{#if thingIs "value"}}{{! comment}}{{/if}}"></div>');1109 test_fragment('<div class="{{#if thingIs \'value\'}}{{! comment}}{{/if}}"></div>');1110 test_fragment('<div class=\'{{#if thingIs "value"}}{{! comment}}{{/if}}\'></div>');1111 test_fragment('<div class=\'{{#if thingIs \'value\'}}{{! comment}}{{/if}}\'></div>');1112 test_fragment('<span>{{condition < 0 ? "result1" : "result2"}}</span>');1113 test_fragment('<span>{{condition1 && condition2 && condition3 && condition4 < 0 ? "resForTrue" : "resForFalse"}}</span>');1114 // Handlebars Indenting On - (content = "{{!-- comment--}}")1115 reset_options();1116 opts.indent_handlebars = true;1117 test_fragment('{{page-title}}');1118 test_fragment('{{#if 0}}{{/if}}');1119 test_fragment('{{#if 0}}{{!-- comment--}}{{/if}}');1120 test_fragment(1121 '{{#if 0}}\n' +1122 '{{/if}}');1123 test_fragment(1124 '{{#if words}}{{/if}}',1125 // -- output --1126 '{{#if words}}{{/if}}');1127 test_fragment(1128 '{{#if words}}{{!-- comment--}}{{/if}}',1129 // -- output --1130 '{{#if words}}{{!-- comment--}}{{/if}}');1131 test_fragment(1132 '{{#if words}}{{!-- comment--}}{{/if}}',1133 // -- output --1134 '{{#if words}}{{!-- comment--}}{{/if}}');1135 test_fragment(1136 '{{#if 1}}\n' +1137 ' <div>\n' +1138 ' </div>\n' +1139 '{{/if}}');1140 test_fragment(1141 '{{#if 1}}\n' +1142 '<div>\n' +1143 '</div>\n' +1144 '{{/if}}',1145 // -- output --1146 '{{#if 1}}\n' +1147 ' <div>\n' +1148 ' </div>\n' +1149 '{{/if}}');1150 test_fragment(1151 '<div>\n' +1152 ' {{#if 1}}\n' +1153 ' {{/if}}\n' +1154 '</div>');1155 test_fragment(1156 '<div>\n' +1157 '{{#if 1}}\n' +1158 '{{/if}}\n' +1159 '</div>',1160 // -- output --1161 '<div>\n' +1162 ' {{#if 1}}\n' +1163 ' {{/if}}\n' +1164 '</div>');1165 test_fragment(1166 '{{#if}}\n' +1167 '{{#each}}\n' +1168 '{{#if}}\n' +1169 '{{!-- comment--}}\n' +1170 '{{/if}}\n' +1171 '{{#if}}\n' +1172 '{{!-- comment--}}\n' +1173 '{{/if}}\n' +1174 '{{/each}}\n' +1175 '{{/if}}',1176 // -- output --1177 '{{#if}}\n' +1178 ' {{#each}}\n' +1179 ' {{#if}}\n' +1180 ' {{!-- comment--}}\n' +1181 ' {{/if}}\n' +1182 ' {{#if}}\n' +1183 ' {{!-- comment--}}\n' +1184 ' {{/if}}\n' +1185 ' {{/each}}\n' +1186 '{{/if}}');1187 test_fragment(1188 '{{#if 1}}\n' +1189 ' <div>\n' +1190 ' </div>\n' +1191 '{{/if}}');1192 test_fragment(1193 '{{#if 1}}\n' +1194 ' {{!-- comment--}}\n' +1195 ' {{else}}\n' +1196 ' {{!-- comment--}}\n' +1197 '{{/if}}',1198 // -- output --1199 '{{#if 1}}\n' +1200 ' {{!-- comment--}}\n' +1201 '{{else}}\n' +1202 ' {{!-- comment--}}\n' +1203 '{{/if}}');1204 test_fragment(1205 '{{#if 1}}\n' +1206 ' {{else}}\n' +1207 ' {{/if}}',1208 // -- output --1209 '{{#if 1}}\n' +1210 '{{else}}\n' +1211 '{{/if}}');1212 test_fragment(1213 '{{#if thing}}\n' +1214 '{{#if otherthing}}\n' +1215 ' {{!-- comment--}}\n' +1216 ' {{else}}\n' +1217 '{{!-- comment--}}\n' +1218 ' {{/if}}\n' +1219 ' {{else}}\n' +1220 '{{!-- comment--}}\n' +1221 '{{/if}}',1222 // -- output --1223 '{{#if thing}}\n' +1224 ' {{#if otherthing}}\n' +1225 ' {{!-- comment--}}\n' +1226 ' {{else}}\n' +1227 ' {{!-- comment--}}\n' +1228 ' {{/if}}\n' +1229 '{{else}}\n' +1230 ' {{!-- comment--}}\n' +1231 '{{/if}}');1232 test_fragment(1233 '<div{{somestyle}}></div>',1234 // -- output --1235 '<div {{somestyle}}></div>');1236 test_fragment(1237 '<div{{#if test}}class="foo"{{/if}}>{{!-- comment--}}</div>',1238 // -- output --1239 '<div {{#if test}} class="foo" {{/if}}>{{!-- comment--}}</div>');1240 test_fragment(1241 '<div{{#if thing}}{{somestyle}}class="{{class}}"{{else}}class="{{class2}}"{{/if}}>{{!-- comment--}}</div>',1242 // -- output --1243 '<div {{#if thing}} {{somestyle}} class="{{class}}" {{else}} class="{{class2}}" {{/if}}>{{!-- comment--}}</div>');1244 test_fragment(1245 '<span{{#if condition}}class="foo"{{/if}}>{{!-- comment--}}</span>',1246 // -- output --1247 '<span {{#if condition}} class="foo" {{/if}}>{{!-- comment--}}</span>');1248 test_fragment('<div unformatted="{{#if}}{{!-- comment--}}{{/if}}">{{!-- comment--}}</div>');1249 test_fragment('<div unformatted="{{#if }} {{!-- comment--}}{{/if}}">{{!-- comment--}}</div>');1250 test_fragment('<div class="{{#if thingIs "value"}}{{!-- comment--}}{{/if}}"></div>');1251 test_fragment('<div class="{{#if thingIs \'value\'}}{{!-- comment--}}{{/if}}"></div>');1252 test_fragment('<div class=\'{{#if thingIs "value"}}{{!-- comment--}}{{/if}}\'></div>');1253 test_fragment('<div class=\'{{#if thingIs \'value\'}}{{!-- comment--}}{{/if}}\'></div>');1254 test_fragment('<span>{{condition < 0 ? "result1" : "result2"}}</span>');1255 test_fragment('<span>{{condition1 && condition2 && condition3 && condition4 < 0 ? "resForTrue" : "resForFalse"}}</span>');1256 // Handlebars Indenting On - (content = "{pre{{field1}} {{field2}} {{field3}}post")1257 reset_options();1258 opts.indent_handlebars = true;1259 test_fragment('{{page-title}}');1260 test_fragment('{{#if 0}}{{/if}}');1261 test_fragment('{{#if 0}}{pre{{field1}} {{field2}} {{field3}}post{{/if}}');1262 test_fragment(1263 '{{#if 0}}\n' +1264 '{{/if}}');1265 test_fragment(1266 '{{#if words}}{{/if}}',1267 // -- output --1268 '{{#if words}}{{/if}}');1269 test_fragment(1270 '{{#if words}}{pre{{field1}} {{field2}} {{field3}}post{{/if}}',1271 // -- output --1272 '{{#if words}}{pre{{field1}} {{field2}} {{field3}}post{{/if}}');1273 test_fragment(1274 '{{#if words}}{pre{{field1}} {{field2}} {{field3}}post{{/if}}',1275 // -- output --1276 '{{#if words}}{pre{{field1}} {{field2}} {{field3}}post{{/if}}');1277 test_fragment(1278 '{{#if 1}}\n' +1279 ' <div>\n' +1280 ' </div>\n' +1281 '{{/if}}');1282 test_fragment(1283 '{{#if 1}}\n' +1284 '<div>\n' +1285 '</div>\n' +1286 '{{/if}}',1287 // -- output --1288 '{{#if 1}}\n' +1289 ' <div>\n' +1290 ' </div>\n' +1291 '{{/if}}');1292 test_fragment(1293 '<div>\n' +1294 ' {{#if 1}}\n' +1295 ' {{/if}}\n' +1296 '</div>');1297 test_fragment(1298 '<div>\n' +1299 '{{#if 1}}\n' +1300 '{{/if}}\n' +1301 '</div>',1302 // -- output --1303 '<div>\n' +1304 ' {{#if 1}}\n' +1305 ' {{/if}}\n' +1306 '</div>');1307 test_fragment(1308 '{{#if}}\n' +1309 '{{#each}}\n' +1310 '{{#if}}\n' +1311 '{pre{{field1}} {{field2}} {{field3}}post\n' +1312 '{{/if}}\n' +1313 '{{#if}}\n' +1314 '{pre{{field1}} {{field2}} {{field3}}post\n' +1315 '{{/if}}\n' +1316 '{{/each}}\n' +1317 '{{/if}}',1318 // -- output --1319 '{{#if}}\n' +1320 ' {{#each}}\n' +1321 ' {{#if}}\n' +1322 ' {pre{{field1}} {{field2}} {{field3}}post\n' +1323 ' {{/if}}\n' +1324 ' {{#if}}\n' +1325 ' {pre{{field1}} {{field2}} {{field3}}post\n' +1326 ' {{/if}}\n' +1327 ' {{/each}}\n' +1328 '{{/if}}');1329 test_fragment(1330 '{{#if 1}}\n' +1331 ' <div>\n' +1332 ' </div>\n' +1333 '{{/if}}');1334 test_fragment(1335 '{{#if 1}}\n' +1336 ' {pre{{field1}} {{field2}} {{field3}}post\n' +1337 ' {{else}}\n' +1338 ' {pre{{field1}} {{field2}} {{field3}}post\n' +1339 '{{/if}}',1340 // -- output --1341 '{{#if 1}}\n' +1342 ' {pre{{field1}} {{field2}} {{field3}}post\n' +1343 '{{else}}\n' +1344 ' {pre{{field1}} {{field2}} {{field3}}post\n' +1345 '{{/if}}');1346 test_fragment(1347 '{{#if 1}}\n' +1348 ' {{else}}\n' +1349 ' {{/if}}',1350 // -- output --1351 '{{#if 1}}\n' +1352 '{{else}}\n' +1353 '{{/if}}');1354 test_fragment(1355 '{{#if thing}}\n' +1356 '{{#if otherthing}}\n' +1357 ' {pre{{field1}} {{field2}} {{field3}}post\n' +1358 ' {{else}}\n' +1359 '{pre{{field1}} {{field2}} {{field3}}post\n' +1360 ' {{/if}}\n' +1361 ' {{else}}\n' +1362 '{pre{{field1}} {{field2}} {{field3}}post\n' +1363 '{{/if}}',1364 // -- output --1365 '{{#if thing}}\n' +1366 ' {{#if otherthing}}\n' +1367 ' {pre{{field1}} {{field2}} {{field3}}post\n' +1368 ' {{else}}\n' +1369 ' {pre{{field1}} {{field2}} {{field3}}post\n' +1370 ' {{/if}}\n' +1371 '{{else}}\n' +1372 ' {pre{{field1}} {{field2}} {{field3}}post\n' +1373 '{{/if}}');1374 test_fragment(1375 '<div{{somestyle}}></div>',1376 // -- output --1377 '<div {{somestyle}}></div>');1378 test_fragment(1379 '<div{{#if test}}class="foo"{{/if}}>{pre{{field1}} {{field2}} {{field3}}post</div>',1380 // -- output --1381 '<div {{#if test}} class="foo" {{/if}}>{pre{{field1}} {{field2}} {{field3}}post</div>');1382 test_fragment(1383 '<div{{#if thing}}{{somestyle}}class="{{class}}"{{else}}class="{{class2}}"{{/if}}>{pre{{field1}} {{field2}} {{field3}}post</div>',1384 // -- output --1385 '<div {{#if thing}} {{somestyle}} class="{{class}}" {{else}} class="{{class2}}" {{/if}}>{pre{{field1}} {{field2}} {{field3}}post</div>');1386 test_fragment(1387 '<span{{#if condition}}class="foo"{{/if}}>{pre{{field1}} {{field2}} {{field3}}post</span>',1388 // -- output --1389 '<span {{#if condition}} class="foo" {{/if}}>{pre{{field1}} {{field2}} {{field3}}post</span>');1390 test_fragment('<div unformatted="{{#if}}{pre{{field1}} {{field2}} {{field3}}post{{/if}}">{pre{{field1}} {{field2}} {{field3}}post</div>');1391 test_fragment('<div unformatted="{{#if }} {pre{{field1}} {{field2}} {{field3}}post{{/if}}">{pre{{field1}} {{field2}} {{field3}}post</div>');1392 test_fragment('<div class="{{#if thingIs "value"}}{pre{{field1}} {{field2}} {{field3}}post{{/if}}"></div>');1393 test_fragment('<div class="{{#if thingIs \'value\'}}{pre{{field1}} {{field2}} {{field3}}post{{/if}}"></div>');1394 test_fragment('<div class=\'{{#if thingIs "value"}}{pre{{field1}} {{field2}} {{field3}}post{{/if}}\'></div>');1395 test_fragment('<div class=\'{{#if thingIs \'value\'}}{pre{{field1}} {{field2}} {{field3}}post{{/if}}\'></div>');1396 test_fragment('<span>{{condition < 0 ? "result1" : "result2"}}</span>');1397 test_fragment('<span>{{condition1 && condition2 && condition3 && condition4 < 0 ? "resForTrue" : "resForFalse"}}</span>');1398 // Handlebars Indenting On - (content = "{{! \n mult-line\ncomment \n with spacing\n}}")1399 reset_options();1400 opts.indent_handlebars = true;1401 test_fragment('{{page-title}}');1402 test_fragment('{{#if 0}}{{/if}}');1403 test_fragment(1404 '{{#if 0}}{{! \n' +1405 ' mult-line\n' +1406 'comment \n' +1407 ' with spacing\n' +1408 '}}{{/if}}');1409 test_fragment(1410 '{{#if 0}}\n' +1411 '{{/if}}');1412 test_fragment(1413 '{{#if words}}{{/if}}',1414 // -- output --1415 '{{#if words}}{{/if}}');1416 test_fragment(1417 '{{#if words}}{{! \n' +1418 ' mult-line\n' +1419 'comment \n' +1420 ' with spacing\n' +1421 '}}{{/if}}',1422 // -- output --1423 '{{#if words}}{{! \n' +1424 ' mult-line\n' +1425 'comment \n' +1426 ' with spacing\n' +1427 '}}{{/if}}');1428 test_fragment(1429 '{{#if words}}{{! \n' +1430 ' mult-line\n' +1431 'comment \n' +1432 ' with spacing\n' +1433 '}}{{/if}}',1434 // -- output --1435 '{{#if words}}{{! \n' +1436 ' mult-line\n' +1437 'comment \n' +1438 ' with spacing\n' +1439 '}}{{/if}}');1440 test_fragment(1441 '{{#if 1}}\n' +1442 ' <div>\n' +1443 ' </div>\n' +1444 '{{/if}}');1445 test_fragment(1446 '{{#if 1}}\n' +1447 '<div>\n' +1448 '</div>\n' +1449 '{{/if}}',1450 // -- output --1451 '{{#if 1}}\n' +1452 ' <div>\n' +1453 ' </div>\n' +1454 '{{/if}}');1455 test_fragment(1456 '<div>\n' +1457 ' {{#if 1}}\n' +1458 ' {{/if}}\n' +1459 '</div>');1460 test_fragment(1461 '<div>\n' +1462 '{{#if 1}}\n' +1463 '{{/if}}\n' +1464 '</div>',1465 // -- output --1466 '<div>\n' +1467 ' {{#if 1}}\n' +1468 ' {{/if}}\n' +1469 '</div>');1470 test_fragment(1471 '{{#if}}\n' +1472 '{{#each}}\n' +1473 '{{#if}}\n' +1474 '{{! \n' +1475 ' mult-line\n' +1476 'comment \n' +1477 ' with spacing\n' +1478 '}}\n' +1479 '{{/if}}\n' +1480 '{{#if}}\n' +1481 '{{! \n' +1482 ' mult-line\n' +1483 'comment \n' +1484 ' with spacing\n' +1485 '}}\n' +1486 '{{/if}}\n' +1487 '{{/each}}\n' +1488 '{{/if}}',1489 // -- output --1490 '{{#if}}\n' +1491 ' {{#each}}\n' +1492 ' {{#if}}\n' +1493 ' {{! \n' +1494 ' mult-line\n' +1495 'comment \n' +1496 ' with spacing\n' +1497 '}}\n' +1498 ' {{/if}}\n' +1499 ' {{#if}}\n' +1500 ' {{! \n' +1501 ' mult-line\n' +1502 'comment \n' +1503 ' with spacing\n' +1504 '}}\n' +1505 ' {{/if}}\n' +1506 ' {{/each}}\n' +1507 '{{/if}}');1508 test_fragment(1509 '{{#if 1}}\n' +1510 ' <div>\n' +1511 ' </div>\n' +1512 '{{/if}}');1513 test_fragment(1514 '{{#if 1}}\n' +1515 ' {{! \n' +1516 ' mult-line\n' +1517 'comment \n' +1518 ' with spacing\n' +1519 '}}\n' +1520 ' {{else}}\n' +1521 ' {{! \n' +1522 ' mult-line\n' +1523 'comment \n' +1524 ' with spacing\n' +1525 '}}\n' +1526 '{{/if}}',1527 // -- output --1528 '{{#if 1}}\n' +1529 ' {{! \n' +1530 ' mult-line\n' +1531 'comment \n' +1532 ' with spacing\n' +1533 '}}\n' +1534 '{{else}}\n' +1535 ' {{! \n' +1536 ' mult-line\n' +1537 'comment \n' +1538 ' with spacing\n' +1539 '}}\n' +1540 '{{/if}}');1541 test_fragment(1542 '{{#if 1}}\n' +1543 ' {{else}}\n' +1544 ' {{/if}}',1545 // -- output --1546 '{{#if 1}}\n' +1547 '{{else}}\n' +1548 '{{/if}}');1549 test_fragment(1550 '{{#if thing}}\n' +1551 '{{#if otherthing}}\n' +1552 ' {{! \n' +1553 ' mult-line\n' +1554 'comment \n' +1555 ' with spacing\n' +1556 '}}\n' +1557 ' {{else}}\n' +1558 '{{! \n' +1559 ' mult-line\n' +1560 'comment \n' +1561 ' with spacing\n' +1562 '}}\n' +1563 ' {{/if}}\n' +1564 ' {{else}}\n' +1565 '{{! \n' +1566 ' mult-line\n' +1567 'comment \n' +1568 ' with spacing\n' +1569 '}}\n' +1570 '{{/if}}',1571 // -- output --1572 '{{#if thing}}\n' +1573 ' {{#if otherthing}}\n' +1574 ' {{! \n' +1575 ' mult-line\n' +1576 'comment \n' +1577 ' with spacing\n' +1578 '}}\n' +1579 ' {{else}}\n' +1580 ' {{! \n' +1581 ' mult-line\n' +1582 'comment \n' +1583 ' with spacing\n' +1584 '}}\n' +1585 ' {{/if}}\n' +1586 '{{else}}\n' +1587 ' {{! \n' +1588 ' mult-line\n' +1589 'comment \n' +1590 ' with spacing\n' +1591 '}}\n' +1592 '{{/if}}');1593 test_fragment(1594 '<div{{somestyle}}></div>',1595 // -- output --1596 '<div {{somestyle}}></div>');1597 test_fragment(1598 '<div{{#if test}}class="foo"{{/if}}>{{! \n' +1599 ' mult-line\n' +1600 'comment \n' +1601 ' with spacing\n' +1602 '}}</div>',1603 // -- output --1604 '<div {{#if test}} class="foo" {{/if}}>{{! \n' +1605 ' mult-line\n' +1606 'comment \n' +1607 ' with spacing\n' +1608 '}}</div>');1609 test_fragment(1610 '<div{{#if thing}}{{somestyle}}class="{{class}}"{{else}}class="{{class2}}"{{/if}}>{{! \n' +1611 ' mult-line\n' +1612 'comment \n' +1613 ' with spacing\n' +1614 '}}</div>',1615 // -- output --1616 '<div {{#if thing}} {{somestyle}} class="{{class}}" {{else}} class="{{class2}}" {{/if}}>{{! \n' +1617 ' mult-line\n' +1618 'comment \n' +1619 ' with spacing\n' +1620 '}}</div>');1621 test_fragment(1622 '<span{{#if condition}}class="foo"{{/if}}>{{! \n' +1623 ' mult-line\n' +1624 'comment \n' +1625 ' with spacing\n' +1626 '}}</span>',1627 // -- output --1628 '<span {{#if condition}} class="foo" {{/if}}>{{! \n' +1629 ' mult-line\n' +1630 'comment \n' +1631 ' with spacing\n' +1632 '}}</span>');1633 test_fragment(1634 '<div unformatted="{{#if}}{{! \n' +1635 ' mult-line\n' +1636 'comment \n' +1637 ' with spacing\n' +1638 '}}{{/if}}">{{! \n' +1639 ' mult-line\n' +1640 'comment \n' +1641 ' with spacing\n' +1642 '}}</div>');1643 test_fragment(1644 '<div unformatted="{{#if }} {{! \n' +1645 ' mult-line\n' +1646 'comment \n' +1647 ' with spacing\n' +1648 '}}{{/if}}">{{! \n' +1649 ' mult-line\n' +1650 'comment \n' +1651 ' with spacing\n' +1652 '}}</div>');1653 test_fragment(1654 '<div class="{{#if thingIs "value"}}{{! \n' +1655 ' mult-line\n' +1656 'comment \n' +1657 ' with spacing\n' +1658 '}}{{/if}}"></div>');1659 test_fragment(1660 '<div class="{{#if thingIs \'value\'}}{{! \n' +1661 ' mult-line\n' +1662 'comment \n' +1663 ' with spacing\n' +1664 '}}{{/if}}"></div>');1665 test_fragment(1666 '<div class=\'{{#if thingIs "value"}}{{! \n' +1667 ' mult-line\n' +1668 'comment \n' +1669 ' with spacing\n' +1670 '}}{{/if}}\'></div>');1671 test_fragment(1672 '<div class=\'{{#if thingIs \'value\'}}{{! \n' +1673 ' mult-line\n' +1674 'comment \n' +1675 ' with spacing\n' +1676 '}}{{/if}}\'></div>');1677 test_fragment('<span>{{condition < 0 ? "result1" : "result2"}}</span>');1678 test_fragment('<span>{{condition1 && condition2 && condition3 && condition4 < 0 ? "resForTrue" : "resForFalse"}}</span>');1679 // Handlebars Indenting On - (content = "{{!-- \n mult-line\ncomment \n with spacing\n--}}")1680 reset_options();1681 opts.indent_handlebars = true;1682 test_fragment('{{page-title}}');1683 test_fragment('{{#if 0}}{{/if}}');1684 test_fragment(1685 '{{#if 0}}{{!-- \n' +1686 ' mult-line\n' +1687 'comment \n' +1688 ' with spacing\n' +1689 '--}}{{/if}}');1690 test_fragment(1691 '{{#if 0}}\n' +1692 '{{/if}}');1693 test_fragment(1694 '{{#if words}}{{/if}}',1695 // -- output --1696 '{{#if words}}{{/if}}');1697 test_fragment(1698 '{{#if words}}{{!-- \n' +1699 ' mult-line\n' +1700 'comment \n' +1701 ' with spacing\n' +1702 '--}}{{/if}}',1703 // -- output --1704 '{{#if words}}{{!-- \n' +1705 ' mult-line\n' +1706 'comment \n' +1707 ' with spacing\n' +1708 '--}}{{/if}}');1709 test_fragment(1710 '{{#if words}}{{!-- \n' +1711 ' mult-line\n' +1712 'comment \n' +1713 ' with spacing\n' +1714 '--}}{{/if}}',1715 // -- output --1716 '{{#if words}}{{!-- \n' +1717 ' mult-line\n' +1718 'comment \n' +1719 ' with spacing\n' +1720 '--}}{{/if}}');1721 test_fragment(1722 '{{#if 1}}\n' +1723 ' <div>\n' +1724 ' </div>\n' +1725 '{{/if}}');1726 test_fragment(1727 '{{#if 1}}\n' +1728 '<div>\n' +1729 '</div>\n' +1730 '{{/if}}',1731 // -- output --1732 '{{#if 1}}\n' +1733 ' <div>\n' +1734 ' </div>\n' +1735 '{{/if}}');1736 test_fragment(1737 '<div>\n' +1738 ' {{#if 1}}\n' +1739 ' {{/if}}\n' +1740 '</div>');1741 test_fragment(1742 '<div>\n' +1743 '{{#if 1}}\n' +1744 '{{/if}}\n' +1745 '</div>',1746 // -- output --1747 '<div>\n' +1748 ' {{#if 1}}\n' +1749 ' {{/if}}\n' +1750 '</div>');1751 test_fragment(1752 '{{#if}}\n' +1753 '{{#each}}\n' +1754 '{{#if}}\n' +1755 '{{!-- \n' +1756 ' mult-line\n' +1757 'comment \n' +1758 ' with spacing\n' +1759 '--}}\n' +1760 '{{/if}}\n' +1761 '{{#if}}\n' +1762 '{{!-- \n' +1763 ' mult-line\n' +1764 'comment \n' +1765 ' with spacing\n' +1766 '--}}\n' +1767 '{{/if}}\n' +1768 '{{/each}}\n' +1769 '{{/if}}',1770 // -- output --1771 '{{#if}}\n' +1772 ' {{#each}}\n' +1773 ' {{#if}}\n' +1774 ' {{!-- \n' +1775 ' mult-line\n' +1776 'comment \n' +1777 ' with spacing\n' +1778 '--}}\n' +1779 ' {{/if}}\n' +1780 ' {{#if}}\n' +1781 ' {{!-- \n' +1782 ' mult-line\n' +1783 'comment \n' +1784 ' with spacing\n' +1785 '--}}\n' +1786 ' {{/if}}\n' +1787 ' {{/each}}\n' +1788 '{{/if}}');1789 test_fragment(1790 '{{#if 1}}\n' +1791 ' <div>\n' +1792 ' </div>\n' +1793 '{{/if}}');1794 test_fragment(1795 '{{#if 1}}\n' +1796 ' {{!-- \n' +1797 ' mult-line\n' +1798 'comment \n' +1799 ' with spacing\n' +1800 '--}}\n' +1801 ' {{else}}\n' +1802 ' {{!-- \n' +1803 ' mult-line\n' +1804 'comment \n' +1805 ' with spacing\n' +1806 '--}}\n' +1807 '{{/if}}',1808 // -- output --1809 '{{#if 1}}\n' +1810 ' {{!-- \n' +1811 ' mult-line\n' +1812 'comment \n' +1813 ' with spacing\n' +1814 '--}}\n' +1815 '{{else}}\n' +1816 ' {{!-- \n' +1817 ' mult-line\n' +1818 'comment \n' +1819 ' with spacing\n' +1820 '--}}\n' +1821 '{{/if}}');1822 test_fragment(1823 '{{#if 1}}\n' +1824 ' {{else}}\n' +1825 ' {{/if}}',1826 // -- output --1827 '{{#if 1}}\n' +1828 '{{else}}\n' +1829 '{{/if}}');1830 test_fragment(1831 '{{#if thing}}\n' +1832 '{{#if otherthing}}\n' +1833 ' {{!-- \n' +1834 ' mult-line\n' +1835 'comment \n' +1836 ' with spacing\n' +1837 '--}}\n' +1838 ' {{else}}\n' +1839 '{{!-- \n' +1840 ' mult-line\n' +1841 'comment \n' +1842 ' with spacing\n' +1843 '--}}\n' +1844 ' {{/if}}\n' +1845 ' {{else}}\n' +1846 '{{!-- \n' +1847 ' mult-line\n' +1848 'comment \n' +1849 ' with spacing\n' +1850 '--}}\n' +1851 '{{/if}}',1852 // -- output --1853 '{{#if thing}}\n' +1854 ' {{#if otherthing}}\n' +1855 ' {{!-- \n' +1856 ' mult-line\n' +1857 'comment \n' +1858 ' with spacing\n' +1859 '--}}\n' +1860 ' {{else}}\n' +1861 ' {{!-- \n' +1862 ' mult-line\n' +1863 'comment \n' +1864 ' with spacing\n' +1865 '--}}\n' +1866 ' {{/if}}\n' +1867 '{{else}}\n' +1868 ' {{!-- \n' +1869 ' mult-line\n' +1870 'comment \n' +1871 ' with spacing\n' +1872 '--}}\n' +1873 '{{/if}}');1874 test_fragment(1875 '<div{{somestyle}}></div>',1876 // -- output --1877 '<div {{somestyle}}></div>');1878 test_fragment(1879 '<div{{#if test}}class="foo"{{/if}}>{{!-- \n' +1880 ' mult-line\n' +1881 'comment \n' +1882 ' with spacing\n' +1883 '--}}</div>',1884 // -- output --1885 '<div {{#if test}} class="foo" {{/if}}>{{!-- \n' +1886 ' mult-line\n' +1887 'comment \n' +1888 ' with spacing\n' +1889 '--}}</div>');1890 test_fragment(1891 '<div{{#if thing}}{{somestyle}}class="{{class}}"{{else}}class="{{class2}}"{{/if}}>{{!-- \n' +1892 ' mult-line\n' +1893 'comment \n' +1894 ' with spacing\n' +1895 '--}}</div>',1896 // -- output --1897 '<div {{#if thing}} {{somestyle}} class="{{class}}" {{else}} class="{{class2}}" {{/if}}>{{!-- \n' +1898 ' mult-line\n' +1899 'comment \n' +1900 ' with spacing\n' +1901 '--}}</div>');1902 test_fragment(1903 '<span{{#if condition}}class="foo"{{/if}}>{{!-- \n' +1904 ' mult-line\n' +1905 'comment \n' +1906 ' with spacing\n' +1907 '--}}</span>',1908 // -- output --1909 '<span {{#if condition}} class="foo" {{/if}}>{{!-- \n' +1910 ' mult-line\n' +1911 'comment \n' +1912 ' with spacing\n' +1913 '--}}</span>');1914 test_fragment(1915 '<div unformatted="{{#if}}{{!-- \n' +1916 ' mult-line\n' +1917 'comment \n' +1918 ' with spacing\n' +1919 '--}}{{/if}}">{{!-- \n' +1920 ' mult-line\n' +1921 'comment \n' +1922 ' with spacing\n' +1923 '--}}</div>');1924 test_fragment(1925 '<div unformatted="{{#if }} {{!-- \n' +1926 ' mult-line\n' +1927 'comment \n' +1928 ' with spacing\n' +1929 '--}}{{/if}}">{{!-- \n' +1930 ' mult-line\n' +1931 'comment \n' +1932 ' with spacing\n' +1933 '--}}</div>');1934 test_fragment(1935 '<div class="{{#if thingIs "value"}}{{!-- \n' +1936 ' mult-line\n' +1937 'comment \n' +1938 ' with spacing\n' +1939 '--}}{{/if}}"></div>');1940 test_fragment(1941 '<div class="{{#if thingIs \'value\'}}{{!-- \n' +1942 ' mult-line\n' +1943 'comment \n' +1944 ' with spacing\n' +1945 '--}}{{/if}}"></div>');1946 test_fragment(1947 '<div class=\'{{#if thingIs "value"}}{{!-- \n' +1948 ' mult-line\n' +1949 'comment \n' +1950 ' with spacing\n' +1951 '--}}{{/if}}\'></div>');1952 test_fragment(1953 '<div class=\'{{#if thingIs \'value\'}}{{!-- \n' +1954 ' mult-line\n' +1955 'comment \n' +1956 ' with spacing\n' +1957 '--}}{{/if}}\'></div>');1958 test_fragment('<span>{{condition < 0 ? "result1" : "result2"}}</span>');1959 test_fragment('<span>{{condition1 && condition2 && condition3 && condition4 < 0 ? "resForTrue" : "resForFalse"}}</span>');1960 // Handlebars Indenting On - (content = "{{!-- \n mult-line\ncomment \n{{#> component}}\n mult-line\ncomment \n with spacing\n {{/ component}}--}}")1961 reset_options();1962 opts.indent_handlebars = true;1963 test_fragment('{{page-title}}');1964 test_fragment('{{#if 0}}{{/if}}');1965 test_fragment(1966 '{{#if 0}}{{!-- \n' +1967 ' mult-line\n' +1968 'comment \n' +1969 '{{#> component}}\n' +1970 ' mult-line\n' +1971 'comment \n' +1972 ' with spacing\n' +1973 ' {{/ component}}--}}{{/if}}');1974 test_fragment(1975 '{{#if 0}}\n' +1976 '{{/if}}');1977 test_fragment(1978 '{{#if words}}{{/if}}',1979 // -- output --1980 '{{#if words}}{{/if}}');1981 test_fragment(1982 '{{#if words}}{{!-- \n' +1983 ' mult-line\n' +1984 'comment \n' +1985 '{{#> component}}\n' +1986 ' mult-line\n' +1987 'comment \n' +1988 ' with spacing\n' +1989 ' {{/ component}}--}}{{/if}}',1990 // -- output --1991 '{{#if words}}{{!-- \n' +1992 ' mult-line\n' +1993 'comment \n' +1994 '{{#> component}}\n' +1995 ' mult-line\n' +1996 'comment \n' +1997 ' with spacing\n' +1998 ' {{/ component}}--}}{{/if}}');1999 test_fragment(2000 '{{#if words}}{{!-- \n' +2001 ' mult-line\n' +2002 'comment \n' +2003 '{{#> component}}\n' +2004 ' mult-line\n' +2005 'comment \n' +2006 ' with spacing\n' +2007 ' {{/ component}}--}}{{/if}}',2008 // -- output --2009 '{{#if words}}{{!-- \n' +2010 ' mult-line\n' +2011 'comment \n' +2012 '{{#> component}}\n' +2013 ' mult-line\n' +2014 'comment \n' +2015 ' with spacing\n' +2016 ' {{/ component}}--}}{{/if}}');2017 test_fragment(2018 '{{#if 1}}\n' +2019 ' <div>\n' +2020 ' </div>\n' +2021 '{{/if}}');2022 test_fragment(2023 '{{#if 1}}\n' +2024 '<div>\n' +2025 '</div>\n' +2026 '{{/if}}',2027 // -- output --2028 '{{#if 1}}\n' +2029 ' <div>\n' +2030 ' </div>\n' +2031 '{{/if}}');2032 test_fragment(2033 '<div>\n' +2034 ' {{#if 1}}\n' +2035 ' {{/if}}\n' +2036 '</div>');2037 test_fragment(2038 '<div>\n' +2039 '{{#if 1}}\n' +2040 '{{/if}}\n' +2041 '</div>',2042 // -- output --2043 '<div>\n' +2044 ' {{#if 1}}\n' +2045 ' {{/if}}\n' +2046 '</div>');2047 test_fragment(2048 '{{#if}}\n' +2049 '{{#each}}\n' +2050 '{{#if}}\n' +2051 '{{!-- \n' +2052 ' mult-line\n' +2053 'comment \n' +2054 '{{#> component}}\n' +2055 ' mult-line\n' +2056 'comment \n' +2057 ' with spacing\n' +2058 ' {{/ component}}--}}\n' +2059 '{{/if}}\n' +2060 '{{#if}}\n' +2061 '{{!-- \n' +2062 ' mult-line\n' +2063 'comment \n' +2064 '{{#> component}}\n' +2065 ' mult-line\n' +2066 'comment \n' +2067 ' with spacing\n' +2068 ' {{/ component}}--}}\n' +2069 '{{/if}}\n' +2070 '{{/each}}\n' +2071 '{{/if}}',2072 // -- output --2073 '{{#if}}\n' +2074 ' {{#each}}\n' +2075 ' {{#if}}\n' +2076 ' {{!-- \n' +2077 ' mult-line\n' +2078 'comment \n' +2079 '{{#> component}}\n' +2080 ' mult-line\n' +2081 'comment \n' +2082 ' with spacing\n' +2083 ' {{/ component}}--}}\n' +2084 ' {{/if}}\n' +2085 ' {{#if}}\n' +2086 ' {{!-- \n' +2087 ' mult-line\n' +2088 'comment \n' +2089 '{{#> component}}\n' +2090 ' mult-line\n' +2091 'comment \n' +2092 ' with spacing\n' +2093 ' {{/ component}}--}}\n' +2094 ' {{/if}}\n' +2095 ' {{/each}}\n' +2096 '{{/if}}');2097 test_fragment(2098 '{{#if 1}}\n' +2099 ' <div>\n' +2100 ' </div>\n' +2101 '{{/if}}');2102 test_fragment(2103 '{{#if 1}}\n' +2104 ' {{!-- \n' +2105 ' mult-line\n' +2106 'comment \n' +2107 '{{#> component}}\n' +2108 ' mult-line\n' +2109 'comment \n' +2110 ' with spacing\n' +2111 ' {{/ component}}--}}\n' +2112 ' {{else}}\n' +2113 ' {{!-- \n' +2114 ' mult-line\n' +2115 'comment \n' +2116 '{{#> component}}\n' +2117 ' mult-line\n' +2118 'comment \n' +2119 ' with spacing\n' +2120 ' {{/ component}}--}}\n' +2121 '{{/if}}',2122 // -- output --2123 '{{#if 1}}\n' +2124 ' {{!-- \n' +2125 ' mult-line\n' +2126 'comment \n' +2127 '{{#> component}}\n' +2128 ' mult-line\n' +2129 'comment \n' +2130 ' with spacing\n' +2131 ' {{/ component}}--}}\n' +2132 '{{else}}\n' +2133 ' {{!-- \n' +2134 ' mult-line\n' +2135 'comment \n' +2136 '{{#> component}}\n' +2137 ' mult-line\n' +2138 'comment \n' +2139 ' with spacing\n' +2140 ' {{/ component}}--}}\n' +2141 '{{/if}}');2142 test_fragment(2143 '{{#if 1}}\n' +2144 ' {{else}}\n' +2145 ' {{/if}}',2146 // -- output --2147 '{{#if 1}}\n' +2148 '{{else}}\n' +2149 '{{/if}}');2150 test_fragment(2151 '{{#if thing}}\n' +2152 '{{#if otherthing}}\n' +2153 ' {{!-- \n' +2154 ' mult-line\n' +2155 'comment \n' +2156 '{{#> component}}\n' +2157 ' mult-line\n' +2158 'comment \n' +2159 ' with spacing\n' +2160 ' {{/ component}}--}}\n' +2161 ' {{else}}\n' +2162 '{{!-- \n' +2163 ' mult-line\n' +2164 'comment \n' +2165 '{{#> component}}\n' +2166 ' mult-line\n' +2167 'comment \n' +2168 ' with spacing\n' +2169 ' {{/ component}}--}}\n' +2170 ' {{/if}}\n' +2171 ' {{else}}\n' +2172 '{{!-- \n' +2173 ' mult-line\n' +2174 'comment \n' +2175 '{{#> component}}\n' +2176 ' mult-line\n' +2177 'comment \n' +2178 ' with spacing\n' +2179 ' {{/ component}}--}}\n' +2180 '{{/if}}',2181 // -- output --2182 '{{#if thing}}\n' +2183 ' {{#if otherthing}}\n' +2184 ' {{!-- \n' +2185 ' mult-line\n' +2186 'comment \n' +2187 '{{#> component}}\n' +2188 ' mult-line\n' +2189 'comment \n' +2190 ' with spacing\n' +2191 ' {{/ component}}--}}\n' +2192 ' {{else}}\n' +2193 ' {{!-- \n' +2194 ' mult-line\n' +2195 'comment \n' +2196 '{{#> component}}\n' +2197 ' mult-line\n' +2198 'comment \n' +2199 ' with spacing\n' +2200 ' {{/ component}}--}}\n' +2201 ' {{/if}}\n' +2202 '{{else}}\n' +2203 ' {{!-- \n' +2204 ' mult-line\n' +2205 'comment \n' +2206 '{{#> component}}\n' +2207 ' mult-line\n' +2208 'comment \n' +2209 ' with spacing\n' +2210 ' {{/ component}}--}}\n' +2211 '{{/if}}');2212 test_fragment(2213 '<div{{somestyle}}></div>',2214 // -- output --2215 '<div {{somestyle}}></div>');2216 test_fragment(2217 '<div{{#if test}}class="foo"{{/if}}>{{!-- \n' +2218 ' mult-line\n' +2219 'comment \n' +2220 '{{#> component}}\n' +2221 ' mult-line\n' +2222 'comment \n' +2223 ' with spacing\n' +2224 ' {{/ component}}--}}</div>',2225 // -- output --2226 '<div {{#if test}} class="foo" {{/if}}>{{!-- \n' +2227 ' mult-line\n' +2228 'comment \n' +2229 '{{#> component}}\n' +2230 ' mult-line\n' +2231 'comment \n' +2232 ' with spacing\n' +2233 ' {{/ component}}--}}</div>');2234 test_fragment(2235 '<div{{#if thing}}{{somestyle}}class="{{class}}"{{else}}class="{{class2}}"{{/if}}>{{!-- \n' +2236 ' mult-line\n' +2237 'comment \n' +2238 '{{#> component}}\n' +2239 ' mult-line\n' +2240 'comment \n' +2241 ' with spacing\n' +2242 ' {{/ component}}--}}</div>',2243 // -- output --2244 '<div {{#if thing}} {{somestyle}} class="{{class}}" {{else}} class="{{class2}}" {{/if}}>{{!-- \n' +2245 ' mult-line\n' +2246 'comment \n' +2247 '{{#> component}}\n' +2248 ' mult-line\n' +2249 'comment \n' +2250 ' with spacing\n' +2251 ' {{/ component}}--}}</div>');2252 test_fragment(2253 '<span{{#if condition}}class="foo"{{/if}}>{{!-- \n' +2254 ' mult-line\n' +2255 'comment \n' +2256 '{{#> component}}\n' +2257 ' mult-line\n' +2258 'comment \n' +2259 ' with spacing\n' +2260 ' {{/ component}}--}}</span>',2261 // -- output --2262 '<span {{#if condition}} class="foo" {{/if}}>{{!-- \n' +2263 ' mult-line\n' +2264 'comment \n' +2265 '{{#> component}}\n' +2266 ' mult-line\n' +2267 'comment \n' +2268 ' with spacing\n' +2269 ' {{/ component}}--}}</span>');2270 test_fragment(2271 '<div unformatted="{{#if}}{{!-- \n' +2272 ' mult-line\n' +2273 'comment \n' +2274 '{{#> component}}\n' +2275 ' mult-line\n' +2276 'comment \n' +2277 ' with spacing\n' +2278 ' {{/ component}}--}}{{/if}}">{{!-- \n' +2279 ' mult-line\n' +2280 'comment \n' +2281 '{{#> component}}\n' +2282 ' mult-line\n' +2283 'comment \n' +2284 ' with spacing\n' +2285 ' {{/ component}}--}}</div>');2286 test_fragment(2287 '<div unformatted="{{#if }} {{!-- \n' +2288 ' mult-line\n' +2289 'comment \n' +2290 '{{#> component}}\n' +2291 ' mult-line\n' +2292 'comment \n' +2293 ' with spacing\n' +2294 ' {{/ component}}--}}{{/if}}">{{!-- \n' +2295 ' mult-line\n' +2296 'comment \n' +2297 '{{#> component}}\n' +2298 ' mult-line\n' +2299 'comment \n' +2300 ' with spacing\n' +2301 ' {{/ component}}--}}</div>');2302 test_fragment(2303 '<div class="{{#if thingIs "value"}}{{!-- \n' +2304 ' mult-line\n' +2305 'comment \n' +2306 '{{#> component}}\n' +2307 ' mult-line\n' +2308 'comment \n' +2309 ' with spacing\n' +2310 ' {{/ component}}--}}{{/if}}"></div>');2311 test_fragment(2312 '<div class="{{#if thingIs \'value\'}}{{!-- \n' +2313 ' mult-line\n' +2314 'comment \n' +2315 '{{#> component}}\n' +2316 ' mult-line\n' +2317 'comment \n' +2318 ' with spacing\n' +2319 ' {{/ component}}--}}{{/if}}"></div>');2320 test_fragment(2321 '<div class=\'{{#if thingIs "value"}}{{!-- \n' +2322 ' mult-line\n' +2323 'comment \n' +2324 '{{#> component}}\n' +2325 ' mult-line\n' +2326 'comment \n' +2327 ' with spacing\n' +2328 ' {{/ component}}--}}{{/if}}\'></div>');2329 test_fragment(2330 '<div class=\'{{#if thingIs \'value\'}}{{!-- \n' +2331 ' mult-line\n' +2332 'comment \n' +2333 '{{#> component}}\n' +2334 ' mult-line\n' +2335 'comment \n' +2336 ' with spacing\n' +2337 ' {{/ component}}--}}{{/if}}\'></div>');2338 test_fragment('<span>{{condition < 0 ? "result1" : "result2"}}</span>');2339 test_fragment('<span>{{condition1 && condition2 && condition3 && condition4 < 0 ? "resForTrue" : "resForFalse"}}</span>');2340 // Handlebars Indenting On - (content = "content")2341 reset_options();2342 opts.indent_handlebars = true;2343 opts.wrap_line_length = 80;2344 test_fragment('{{page-title}}');2345 test_fragment('{{#if 0}}{{/if}}');2346 test_fragment('{{#if 0}}content{{/if}}');2347 test_fragment(2348 '{{#if 0}}\n' +2349 '{{/if}}');2350 test_fragment(2351 '{{#if words}}{{/if}}',2352 // -- output --2353 '{{#if words}}{{/if}}');2354 test_fragment(2355 '{{#if words}}content{{/if}}',2356 // -- output --2357 '{{#if words}}content{{/if}}');2358 test_fragment(2359 '{{#if words}}content{{/if}}',2360 // -- output --2361 '{{#if words}}content{{/if}}');2362 test_fragment(2363 '{{#if 1}}\n' +2364 ' <div>\n' +2365 ' </div>\n' +2366 '{{/if}}');2367 test_fragment(2368 '{{#if 1}}\n' +2369 '<div>\n' +2370 '</div>\n' +2371 '{{/if}}',2372 // -- output --2373 '{{#if 1}}\n' +2374 ' <div>\n' +2375 ' </div>\n' +2376 '{{/if}}');2377 test_fragment(2378 '<div>\n' +2379 ' {{#if 1}}\n' +2380 ' {{/if}}\n' +2381 '</div>');2382 test_fragment(2383 '<div>\n' +2384 '{{#if 1}}\n' +2385 '{{/if}}\n' +2386 '</div>',2387 // -- output --2388 '<div>\n' +2389 ' {{#if 1}}\n' +2390 ' {{/if}}\n' +2391 '</div>');2392 test_fragment(2393 '{{#if}}\n' +2394 '{{#each}}\n' +2395 '{{#if}}\n' +2396 'content\n' +2397 '{{/if}}\n' +2398 '{{#if}}\n' +2399 'content\n' +2400 '{{/if}}\n' +2401 '{{/each}}\n' +2402 '{{/if}}',2403 // -- output --2404 '{{#if}}\n' +2405 ' {{#each}}\n' +2406 ' {{#if}}\n' +2407 ' content\n' +2408 ' {{/if}}\n' +2409 ' {{#if}}\n' +2410 ' content\n' +2411 ' {{/if}}\n' +2412 ' {{/each}}\n' +2413 '{{/if}}');2414 test_fragment(2415 '{{#if 1}}\n' +2416 ' <div>\n' +2417 ' </div>\n' +2418 '{{/if}}');2419 test_fragment(2420 '{{#if 1}}\n' +2421 ' content\n' +2422 ' {{else}}\n' +2423 ' content\n' +2424 '{{/if}}',2425 // -- output --2426 '{{#if 1}}\n' +2427 ' content\n' +2428 '{{else}}\n' +2429 ' content\n' +2430 '{{/if}}');2431 test_fragment(2432 '{{#if 1}}\n' +2433 ' {{else}}\n' +2434 ' {{/if}}',2435 // -- output --2436 '{{#if 1}}\n' +2437 '{{else}}\n' +2438 '{{/if}}');2439 test_fragment(2440 '{{#if thing}}\n' +2441 '{{#if otherthing}}\n' +2442 ' content\n' +2443 ' {{else}}\n' +2444 'content\n' +2445 ' {{/if}}\n' +2446 ' {{else}}\n' +2447 'content\n' +2448 '{{/if}}',2449 // -- output --2450 '{{#if thing}}\n' +2451 ' {{#if otherthing}}\n' +2452 ' content\n' +2453 ' {{else}}\n' +2454 ' content\n' +2455 ' {{/if}}\n' +2456 '{{else}}\n' +2457 ' content\n' +2458 '{{/if}}');2459 test_fragment(2460 '<div{{somestyle}}></div>',2461 // -- output --2462 '<div {{somestyle}}></div>');2463 test_fragment(2464 '<div{{#if test}}class="foo"{{/if}}>content</div>',2465 // -- output --2466 '<div {{#if test}} class="foo" {{/if}}>content</div>');2467 test_fragment(2468 '<div{{#if thing}}{{somestyle}}class="{{class}}"{{else}}class="{{class2}}"{{/if}}>content</div>',2469 // -- output --2470 '<div {{#if thing}} {{somestyle}} class="{{class}}" {{else}} class="{{class2}}" {{/if}}>content</div>');2471 test_fragment(2472 '<span{{#if condition}}class="foo"{{/if}}>content</span>',2473 // -- output --2474 '<span {{#if condition}} class="foo" {{/if}}>content</span>');2475 test_fragment('<div unformatted="{{#if}}content{{/if}}">content</div>');2476 test_fragment('<div unformatted="{{#if }} content{{/if}}">content</div>');2477 test_fragment('<div class="{{#if thingIs "value"}}content{{/if}}"></div>');2478 test_fragment('<div class="{{#if thingIs \'value\'}}content{{/if}}"></div>');2479 test_fragment('<div class=\'{{#if thingIs "value"}}content{{/if}}\'></div>');2480 test_fragment('<div class=\'{{#if thingIs \'value\'}}content{{/if}}\'></div>');2481 test_fragment('<span>{{condition < 0 ? "result1" : "result2"}}</span>');2482 test_fragment('<span>{{condition1 && condition2 && condition3 && condition4 < 0 ? "resForTrue" : "resForFalse"}}</span>');2483 //============================================================2484 // Handlebars Else tag indenting2485 reset_options();2486 opts.indent_handlebars = true;2487 test_fragment(2488 '{{#if test}}<div></div>{{else}}<div></div>{{/if}}',2489 // -- output --2490 '{{#if test}}\n' +2491 ' <div></div>\n' +2492 '{{else}}\n' +2493 ' <div></div>\n' +2494 '{{/if}}');2495 test_fragment('{{#if test}}<span></span>{{else}}<span></span>{{/if}}');2496 //============================================================2497 // Unclosed html elements2498 reset_options();2499 test_fragment(2500 '<source>\n' +2501 '<source>');2502 test_fragment(2503 '<br>\n' +2504 '<br>');2505 test_fragment(2506 '<input>\n' +2507 '<input>');2508 test_fragment(2509 '<meta>\n' +2510 '<meta>');2511 test_fragment(2512 '<link>\n' +2513 '<link>');2514 test_fragment(2515 '<colgroup>\n' +2516 ' <col>\n' +2517 ' <col>\n' +2518 '</colgroup>');2519 //============================================================2520 // Unformatted tags2521 reset_options();2522 test_fragment(2523 '<ol>\n' +2524 ' <li>b<pre>c</pre></li>\n' +2525 '</ol>',2526 // -- output --2527 '<ol>\n' +2528 ' <li>b\n' +2529 ' <pre>c</pre>\n' +2530 ' </li>\n' +2531 '</ol>');2532 test_fragment(2533 '<ol>\n' +2534 ' <li>b<code>c</code></li>\n' +2535 '</ol>');2536 test_fragment(2537 '<ul>\n' +2538 ' <li>\n' +2539 ' <span class="octicon octicon-person"></span>\n' +2540 ' <a href="/contact/">Kontakt</a>\n' +2541 ' </li>\n' +2542 '</ul>');2543 test_fragment('<div class="searchform"><input type="text" value="" name="s" id="s" /><input type="submit" id="searchsubmit" value="Search" /></div>');2544 test_fragment('<div class="searchform"><input type="text" value="" name="s" id="s"><input type="submit" id="searchsubmit" value="Search"></div>');2545 test_fragment(2546 '<p>\n' +2547 ' <a href="/test/"><img src="test.jpg" /></a>\n' +2548 '</p>');2549 test_fragment(2550 '<p>\n' +2551 ' <a href="/test/"><img src="test.jpg" /></a><a href="/test/"><img src="test.jpg" /></a>\n' +2552 '</p>');2553 test_fragment(2554 '<p>\n' +2555 ' <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' +2556 '</p>');2557 test_fragment(2558 '<p>\n' +2559 ' <span>image: <img src="test.jpg" /></span><span>image: <img src="test.jpg" /></span>\n' +2560 '</p>');2561 test_fragment(2562 '<p>\n' +2563 ' <strong>image: <img src="test.jpg" /></strong><strong>image: <img src="test.jpg" /></strong>\n' +2564 '</p>');2565 //============================================================2566 // File starting with comment2567 reset_options();2568 test_fragment(2569 '<!--sample comment -->\n' +2570 '\n' +2571 '<html>\n' +2572 '<body>\n' +2573 ' <span>a span</span>\n' +2574 '</body>\n' +2575 '\n' +2576 '</html>');2577 //============================================================2578 // Php formatting2579 reset_options();2580 test_fragment(2581 '<h1 class="content-page-header"><?=$view["name"]; ?></h1>',2582 // -- output --2583 '<h1 class="content-page-header">\n' +2584 ' <?=$view["name"]; ?>\n' +2585 '</h1>');2586 test_fragment(2587 '<?php\n' +2588 'for($i = 1; $i <= 100; $i++;) {\n' +2589 ' #count to 100!\n' +2590 ' echo($i . "</br>");\n' +2591 '}\n' +2592 '?>');2593 test_fragment(2594 '<?php ?>\n' +2595 '<!DOCTYPE html>\n' +2596 '\n' +2597 '<html>\n' +2598 '\n' +2599 '<head></head>\n' +2600 '\n' +2601 '<body></body>\n' +2602 '\n' +2603 '</html>');2604 //============================================================2605 // Support simple language specific option inheritance/overriding - (h = " ", c = " ", j = " ")2606 reset_options();2607 opts.js = { 'indent_size': 3 };2608 opts.css = { 'indent_size': 5 };2609 test_fragment(2610 '<head>\n' +2611 ' <script>\n' +2612 ' if (a == b) {\n' +2613 ' test();\n' +2614 ' }\n' +2615 ' </script>\n' +2616 ' <style>\n' +2617 ' .selector {\n' +2618 ' font-size: 12px;\n' +2619 ' }\n' +2620 ' </style>\n' +2621 '</head>');2622 // Support simple language specific option inheritance/overriding - (h = " ", c = " ", j = " ")2623 reset_options();2624 opts.html = { 'js': { 'indent_size': 3 }, 'css': { 'indent_size': 5 } };2625 test_fragment(2626 '<head>\n' +2627 ' <script>\n' +2628 ' if (a == b) {\n' +2629 ' test();\n' +2630 ' }\n' +2631 ' </script>\n' +2632 ' <style>\n' +2633 ' .selector {\n' +2634 ' font-size: 12px;\n' +2635 ' }\n' +2636 ' </style>\n' +2637 '</head>');2638 // Support simple language specific option inheritance/overriding - (h = " ", c = " ", j = " ")2639 reset_options();2640 opts.indent_size = 9;2641 opts.html = { 'js': { 'indent_size': 3 }, 'css': { 'indent_size': 5 }, 'indent_size': 2};2642 opts.js = { 'indent_size': 5 };2643 opts.css = { 'indent_size': 3 };2644 test_fragment(2645 '<head>\n' +2646 ' <script>\n' +2647 ' if (a == b) {\n' +2648 ' test();\n' +2649 ' }\n' +2650 ' </script>\n' +2651 ' <style>\n' +2652 ' .selector {\n' +2653 ' font-size: 12px;\n' +2654 ' }\n' +2655 ' </style>\n' +2656 '</head>');2657 //============================================================2658 // underscore.js formatting2659 reset_options();2660 test_fragment(2661 '<div class="col-sm-9">\n' +2662 ' <textarea id="notes" class="form-control" rows="3">\n' +2663 ' <%= notes %>\n' +2664 ' </textarea>\n' +2665 '</div>');2666 //============================================================2667 // Indent with tabs2668 reset_options();2669 opts.indent_with_tabs = true;2670 test_fragment(2671 '<div>\n' +2672 '<div>\n' +2673 '</div>\n' +2674 '</div>',2675 // -- output --2676 '<div>\n' +2677 '\t<div>\n' +2678 '\t</div>\n' +2679 '</div>');2680 //============================================================2681 // Indent without tabs2682 reset_options();2683 opts.indent_with_tabs = false;2684 test_fragment(2685 '<div>\n' +2686 '<div>\n' +2687 '</div>\n' +2688 '</div>',2689 // -- output --2690 '<div>\n' +2691 ' <div>\n' +2692 ' </div>\n' +2693 '</div>');2694 //============================================================2695 // Indent body inner html by default2696 reset_options();2697 test_fragment(2698 '<html>\n' +2699 '<body>\n' +2700 '<div></div>\n' +2701 '</body>\n' +2702 '\n' +2703 '</html>',2704 // -- output --2705 '<html>\n' +2706 '<body>\n' +2707 ' <div></div>\n' +2708 '</body>\n' +2709 '\n' +2710 '</html>');2711 //============================================================2712 // indent_body_inner_html set to false prevents indent of body inner html2713 reset_options();2714 opts.indent_body_inner_html = false;2715 test_fragment(2716 '<html>\n' +2717 '<body>\n' +2718 '<div></div>\n' +2719 '</body>\n' +2720 '\n' +2721 '</html>');2722 //============================================================2723 // Indent head inner html by default2724 reset_options();2725 test_fragment(2726 '<html>\n' +2727 '\n' +2728 '<head>\n' +2729 '<meta>\n' +2730 '</head>\n' +2731 '\n' +2732 '</html>',2733 // -- output --2734 '<html>\n' +2735 '\n' +2736 '<head>\n' +2737 ' <meta>\n' +2738 '</head>\n' +2739 '\n' +2740 '</html>');2741 //============================================================2742 // indent_head_inner_html set to false prevents indent of head inner html2743 reset_options();2744 opts.indent_head_inner_html = false;2745 test_fragment(2746 '<html>\n' +2747 '\n' +2748 '<head>\n' +2749 '<meta>\n' +2750 '</head>\n' +2751 '\n' +2752 '</html>');2753 //============================================================2754 // content_unformatted to prevent formatting content2755 reset_options();2756 opts.content_unformatted = ['script', 'style', 'p', 'span', 'br'];2757 test_fragment(2758 '<html><body><h1>A</h1><script>if(1){f();}</script><style>.a{display:none;}</style></body></html>',2759 // -- output --2760 '<html>\n' +2761 '<body>\n' +2762 ' <h1>A</h1>\n' +2763 ' <script>if(1){f();}</script>\n' +2764 ' <style>.a{display:none;}</style>\n' +2765 '</body>\n' +2766 '\n' +2767 '</html>');2768 test_fragment(2769 '<div><p>Beautify me</p></div><p><p>But not me</p></p>',2770 // -- output --2771 '<div>\n' +2772 ' <p>Beautify me</p>\n' +2773 '</div>\n' +2774 '<p><p>But not me</p></p>');2775 test_fragment(2776 '<div><p\n' +2777 ' class="beauty-me"\n' +2778 '>Beautify me</p></div><p><p\n' +2779 ' class="iamalreadybeauty"\n' +2780 '>But not me</p></p>',2781 // -- output --2782 '<div>\n' +2783 ' <p class="beauty-me">Beautify me</p>\n' +2784 '</div>\n' +2785 '<p><p\n' +2786 ' class="iamalreadybeauty"\n' +2787 '>But not me</p></p>');2788 test_fragment('<div><span>blabla<div>something here</div></span></div>');2789 test_fragment('<div><br /></div>');2790 test_fragment(2791 '<div><pre>var a=1;\n' +2792 'var b=a;</pre></div>',2793 // -- output --2794 '<div>\n' +2795 ' <pre>var a=1; var b=a;</pre>\n' +2796 '</div>');2797 test_fragment(2798 '<div><pre>\n' +2799 'var a=1;\n' +2800 'var b=a;\n' +2801 '</pre></div>',2802 // -- output --2803 '<div>\n' +2804 ' <pre>\n' +2805 ' var a=1; var b=a;\n' +2806 ' </pre>\n' +2807 '</div>');2808 //============================================================2809 // default content_unformatted2810 reset_options();2811 test_fragment(2812 '<html><body><h1>A</h1><script>if(1){f();}</script><style>.a{display:none;}</style></body></html>',2813 // -- output --2814 '<html>\n' +2815 '<body>\n' +2816 ' <h1>A</h1>\n' +2817 ' <script>\n' +2818 ' if (1) {\n' +2819 ' f();\n' +2820 ' }\n' +2821 ' </script>\n' +2822 ' <style>\n' +2823 ' .a {\n' +2824 ' display: none;\n' +2825 ' }\n' +2826 ' </style>\n' +2827 '</body>\n' +2828 '\n' +2829 '</html>');2830 test_fragment(2831 '<div><p>Beautify me</p></div><p><p>But not me</p></p>',2832 // -- output --2833 '<div>\n' +2834 ' <p>Beautify me</p>\n' +2835 '</div>\n' +2836 '<p>\n' +2837 ' <p>But not me</p>\n' +2838 '</p>');2839 test_fragment(2840 '<div><p\n' +2841 ' class="beauty-me"\n' +2842 '>Beautify me</p></div><p><p\n' +2843 ' class="iamalreadybeauty"\n' +2844 '>But not me</p></p>',2845 // -- output --2846 '<div>\n' +2847 ' <p class="beauty-me">Beautify me</p>\n' +2848 '</div>\n' +2849 '<p>\n' +2850 ' <p class="iamalreadybeauty">But not me</p>\n' +2851 '</p>');2852 test_fragment('<div><span>blabla<div>something here</div></span></div>');2853 test_fragment('<div><br /></div>');2854 test_fragment(2855 '<div><pre>var a=1;\n' +2856 'var b=a;</pre></div>',2857 // -- output --2858 '<div>\n' +2859 ' <pre>var a=1;\n' +2860 'var b=a;</pre>\n' +2861 '</div>');2862 test_fragment(2863 '<div><pre>\n' +2864 'var a=1;\n' +2865 'var b=a;\n' +2866 '</pre></div>',2867 // -- output --2868 '<div>\n' +2869 ' <pre>\n' +2870 'var a=1;\n' +2871 'var b=a;\n' +2872 '</pre>\n' +2873 '</div>');2874 //============================================================2875 // New Test Suite2876 reset_options();2877 }2878 function beautifier_unconverted_tests()2879 {2880 sanitytest = test_obj;2881 reset_options();2882 //============================================================2883 opts.end_with_newline = true;2884 test_fragment('', '\n');2885 test_fragment('<div></div>\n');2886 test_fragment('<div></div>\n\n\n', '<div></div>\n');2887 test_fragment('<head>\n' +2888 ' <script>\n' +2889 ' mocha.setup("bdd");\n' +2890 '\n' +2891 ' </script>\n' +2892 '</head>\n');2893 opts.end_with_newline = false;2894 // error cases need love too2895 bth('<img title="Bad food!" src="foo.jpg" alt="Evil" ">');2896 bth("<!-- don't blow up if a comment is not complete"); // -->2897 test_fragment(2898 '<head>\n' +2899 ' <script>\n' +2900 ' mocha.setup("bdd");\n' +2901 ' </script>\n' +2902 '</head>');2903 test_fragment('<div></div>\n', '<div></div>');2904 bth('<div></div>');2905 bth('<div>content</div>');2906 bth('<div><div></div></div>',2907 '<div>\n' +2908 ' <div></div>\n' +2909 '</div>');2910 bth('<div><div>content</div></div>',2911 '<div>\n' +2912 ' <div>content</div>\n' +2913 '</div>');2914 bth('<div>\n' +2915 ' <span>content</span>\n' +2916 '</div>');2917 bth('<div>\n' +2918 '</div>');2919 bth('<div>\n' +2920 ' content\n' +2921 '</div>');2922 bth('<div>\n' +2923 ' </div>',2924 '<div>\n' +2925 '</div>');2926 bth(' <div>\n' +2927 ' </div>',2928 '<div>\n' +2929 '</div>');2930 bth('<div>\n' +2931 '</div>\n' +2932 ' <div>\n' +2933 ' </div>',2934 '<div>\n' +2935 '</div>\n' +2936 '<div>\n' +2937 '</div>');2938 bth(' <div>\n' +2939 '</div>',2940 '<div>\n' +2941 '</div>');2942 bth('<div >content</div>',2943 '<div>content</div>');2944 bth('<div thinger="preserve space here" ></div >',2945 '<div thinger="preserve space here"></div>');2946 bth('content\n' +2947 ' <div>\n' +2948 ' </div>\n' +2949 'content',2950 'content\n' +2951 '<div>\n' +2952 '</div>\n' +2953 'content');2954 bth('<li>\n' +2955 ' <div>\n' +2956 ' </div>\n' +2957 '</li>');2958 bth('<li>\n' +2959 '<div>\n' +2960 '</div>\n' +2961 '</li>',2962 '<li>\n' +2963 ' <div>\n' +2964 ' </div>\n' +2965 '</li>');2966 bth('<li>\n' +2967 ' content\n' +2968 '</li>\n' +2969 '<li>\n' +2970 ' content\n' +2971 '</li>');2972 bth('<img>content');2973 bth('<img> content');2974 bth('<img> content', '<img> content');2975 bth('<img><img>content');2976 bth('<img> <img>content');2977 bth('<img> <img>content', '<img> <img>content');2978 bth('<img><b>content</b>');2979 bth('<img> <b>content</b>');2980 bth('<img> <b>content</b>', '<img> <b>content</b>');2981 bth('<div>content<img>content</div>');2982 bth('<div> content <img> content</div>');2983 bth('<div> content <img> content </div>',2984 '<div> content <img> content </div>');2985 bth('Text <a href="#">Link</a> Text');2986 var unformatted = opts.unformatted;2987 opts.unformatted = ['script', 'style'];2988 bth('<script id="javascriptTemplate" type="text/x-kendo-template">\n' +2989 ' <ul>\n' +2990 ' # for (var i = 0; i < data.length; i++) { #\n' +2991 ' <li>#= data[i] #</li>\n' +2992 ' # } #\n' +2993 ' </ul>\n' +2994 '</script>');2995 bth('<style>\n' +2996 ' body {background-color:lightgrey}\n' +2997 ' h1 {color:blue}\n' +2998 '</style>');2999 opts.unformatted = unformatted;3000 unformatted = opts.unformatted;3001 opts.unformatted = ['custom-element'];3002 test_fragment('<div>should <custom-element>not</custom-element>' +3003 ' insert newlines</div>',3004 '<div>should <custom-element>not</custom-element>' +3005 ' insert newlines</div>');3006 opts.unformatted = unformatted;3007 // Tests that don't pass, but probably should.3008 // bth('<div><span>content</span></div>');3009 // Handlebars tests3010 // Without the indent option on, handlebars are treated as content.3011 opts.wrap_line_length = 0;3012 //...---------1---------2---------3---------4---------5---------6---------73013 //...12345678901234567890123456789012345678901234567890123456789012345678903014 bth('<div>Some text that should not wrap at all.</div>',3015 /* expected */3016 '<div>Some text that should not wrap at all.</div>');...

Full Screen

Full Screen

beautify-tests.js

Source:beautify-tests.js Github

copy

Full Screen

...27 }28 var sanitytest;29 // test the input on beautifier with the current flag settings30 // does not check the indentation / surroundings as bt() does31 function test_fragment(input, expected)32 {33 expected = expected || input;34 sanitytest.expect(input, expected);35 // if the expected is different from input, run it again36 // expected output should be unchanged when run twice.37 if (expected != input) {38 sanitytest.expect(expected, expected);39 }40 }41 // test the input on beautifier with the current flag settings42 // test both the input as well as { input } wrapping43 function bt(input, expectation)44 {45 var wrapped_input, wrapped_expectation;46 expectation = expectation || input;47 sanitytest.test_function(test_js_beautifier, 'js_beautify');48 test_fragment(input, expectation);49 // test also the returned indentation50 // e.g if input = "asdf();"51 // then test that this remains properly formatted as well:52 // {53 // asdf();54 // indent;55 // }56 if (opts.indent_size === 4 && input) {57 wrapped_input = '{\n' + input.replace(/^(.+)$/mg, ' $1') + '\n foo = bar;\n}';58 wrapped_expectation = '{\n' + expectation.replace(/^(.+)$/mg, ' $1') + '\n foo = bar;\n}';59 test_fragment(wrapped_input, wrapped_expectation);60 }61 }62 // test html63 function bth(input, expectation)64 {65 var wrapped_input, wrapped_expectation, field_input, field_expectation;66 expectation = expectation || input;67 sanitytest.test_function(test_html_beautifier, 'html_beautify');68 test_fragment(input, expectation);69 if (opts.indent_size === 4 && input) {70 wrapped_input = '<div>\n' + input.replace(/^(.+)$/mg, ' $1') + '\n <span>inline</span>\n</div>';71 wrapped_expectation = '<div>\n' + expectation.replace(/^(.+)$/mg, ' $1') + '\n <span>inline</span>\n</div>';72 test_fragment(wrapped_input, wrapped_expectation);73 }74 // Test that handlebars non-block {{}} tags act as content and do not75 // get any spacing or line breaks.76 if (input.indexOf('content') != -1) {77 // Just {{field}}78 field_input = input.replace(/content/g, '{{field}}');79 field_expectation = expectation.replace(/content/g, '{{field}}');80 test_fragment(field_input, field_expectation);81 // handlebars comment82 field_input = input.replace(/content/g, '{{! comment}}');83 field_expectation = expectation.replace(/content/g, '{{! comment}}');84 test_fragment(field_input, field_expectation);85 // mixed {{field}} and content86 field_input = input.replace(/content/g, 'pre{{field1}} {{field2}} {{field3}}post');87 field_expectation = expectation.replace(/content/g, 'pre{{field1}} {{field2}} {{field3}}post');88 test_fragment(field_input, field_expectation);89 }90 }91 // test css92 function btc(input, expectation)93 {94 var wrapped_input, wrapped_expectation;95 expectation = expectation || input;96 sanitytest.test_function(test_css_beautifier, 'css_beautify');97 test_fragment(input, expectation);98 }99 // test the input on beautifier with the current flag settings,100 // but dont't101 function bt_braces(input, expectation)102 {103 var braces_ex = opts.brace_style;104 opts.brace_style = 'expand';105 bt(input, expectation);106 opts.brace_style = braces_ex;107 }108 function beautifier_tests()109 {110 sanitytest = test_obj;111 opts.indent_size = 4;112 opts.indent_char = ' ';113 opts.preserve_newlines = true;114 opts.jslint_happy = false;115 opts.keep_array_indentation = false;116 opts.brace_style = "collapse";117 // unicode support118 bt('var ' + String.fromCharCode(3232) + '_' + String.fromCharCode(3232) + ' = "hi";');119 bt('var ' + String.fromCharCode(228) + 'x = {\n ' + String.fromCharCode(228) + 'rgerlich: true\n};');120 bt('');121 bt('return .5');122 test_fragment(' return .5');123 test_fragment(' return .5;\n a();');124 bt('a = 1', 'a = 1');125 bt('a=1', 'a = 1');126 bt("a();\n\nb();", "a();\n\nb();");127 bt('var a = 1 var b = 2', "var a = 1\nvar b = 2");128 bt('var a=1, b=c[d], e=6;', 'var a = 1,\n b = c[d],\n e = 6;');129 bt('var a,\n b,\n c;');130 bt('let a = 1 let b = 2', "let a = 1\nlet b = 2");131 bt('let a=1, b=c[d], e=6;', 'let a = 1,\n b = c[d],\n e = 6;');132 bt('let a,\n b,\n c;');133 bt('const a = 1 const b = 2', "const a = 1\nconst b = 2");134 bt('const a=1, b=c[d], e=6;', 'const a = 1,\n b = c[d],\n e = 6;');135 bt('const a,\n b,\n c;');136 bt('a = " 12345 "');137 bt("a = ' 12345 '");138 bt('if (a == 1) b = 2;', "if (a == 1) b = 2;");139 bt('if(1){2}else{3}', "if (1) {\n 2\n} else {\n 3\n}");140 bt('if(1||2);', 'if (1 || 2);');141 bt('(a==1)||(b==2)', '(a == 1) || (b == 2)');142 bt('var a = 1 if (2) 3;', "var a = 1\nif (2) 3;");143 bt('a = a + 1');144 bt('a = a == 1');145 bt('/12345[^678]*9+/.match(a)');146 bt('a /= 5');147 bt('a = 0.5 * 3');148 bt('a *= 10.55');149 bt('a < .5');150 bt('a <= .5');151 bt('a<.5', 'a < .5');152 bt('a<=.5', 'a <= .5');153 bt('a = 0xff;');154 bt('a=0xff+4', 'a = 0xff + 4');155 bt('a = [1, 2, 3, 4]');156 bt('F*(g/=f)*g+b', 'F * (g /= f) * g + b');157 bt('a.b({c:d})', 'a.b({\n c: d\n})');158 bt('a.b\n(\n{\nc:\nd\n}\n)', 'a.b({\n c: d\n})');159 bt('a.b({c:"d"})', 'a.b({\n c: "d"\n})');160 bt('a.b\n(\n{\nc:\n"d"\n}\n)', 'a.b({\n c: "d"\n})');161 bt('a=!b', 'a = !b');162 bt('a=!!b', 'a = !!b');163 bt('a?b:c', 'a ? b : c');164 bt('a?1:2', 'a ? 1 : 2');165 bt('a?(b):c', 'a ? (b) : c');166 bt('x={a:1,b:w=="foo"?x:y,c:z}', 'x = {\n a: 1,\n b: w == "foo" ? x : y,\n c: z\n}');167 bt('x=a?b?c?d:e:f:g;', 'x = a ? b ? c ? d : e : f : g;');168 bt('x=a?b?c?d:{e1:1,e2:2}:f:g;', 'x = a ? b ? c ? d : {\n e1: 1,\n e2: 2\n} : f : g;');169 bt('function void(void) {}');170 bt('if(!a)foo();', 'if (!a) foo();');171 bt('a=~a', 'a = ~a');172 bt('a;/*comment*/b;', "a; /*comment*/\nb;");173 bt('a;/* comment */b;', "a; /* comment */\nb;");174 test_fragment('a;/*\ncomment\n*/b;', "a;\n/*\ncomment\n*/\nb;"); // simple comments don't get touched at all175 bt('a;/**\n* javadoc\n*/b;', "a;\n/**\n * javadoc\n */\nb;");176 test_fragment('a;/**\n\nno javadoc\n*/b;', "a;\n/**\n\nno javadoc\n*/\nb;");177 bt('a;/*\n* javadoc\n*/b;', "a;\n/*\n * javadoc\n */\nb;"); // comment blocks detected and reindented even w/o javadoc starter178 bt('if(a)break;', "if (a) break;");179 bt('if(a){break}', "if (a) {\n break\n}");180 bt('if((a))foo();', 'if ((a)) foo();');181 bt('for(var i=0;;) a', 'for (var i = 0;;) a');182 bt('for(var i=0;;)\na', 'for (var i = 0;;)\n a');183 bt('a++;', 'a++;');184 bt('for(;;i++)a()', 'for (;; i++) a()');185 bt('for(;;i++)\na()', 'for (;; i++)\n a()');186 bt('for(;;++i)a', 'for (;; ++i) a');187 bt('return(1)', 'return (1)');188 bt('try{a();}catch(b){c();}finally{d();}', "try {\n a();\n} catch (b) {\n c();\n} finally {\n d();\n}");189 bt('(xx)()'); // magic function call190 bt('a[1]()'); // another magic function call191 bt('if(a){b();}else if(c) foo();', "if (a) {\n b();\n} else if (c) foo();");192 bt('switch(x) {case 0: case 1: a(); break; default: break}', "switch (x) {\n case 0:\n case 1:\n a();\n break;\n default:\n break\n}");193 bt('switch(x){case -1:break;case !y:break;}', 'switch (x) {\n case -1:\n break;\n case !y:\n break;\n}');194 bt('a !== b');195 bt('if (a) b(); else c();', "if (a) b();\nelse c();");196 bt("// comment\n(function something() {})"); // typical greasemonkey start197 bt("{\n\n x();\n\n}"); // was: duplicating newlines198 bt('if (a in b) foo();');199 bt('var a, b;');200 // bt('var a, b');201 bt('{a:1, b:2}', "{\n a: 1,\n b: 2\n}");202 bt('a={1:[-1],2:[+1]}', 'a = {\n 1: [-1],\n 2: [+1]\n}');203 bt('var l = {\'a\':\'1\', \'b\':\'2\'}', "var l = {\n 'a': '1',\n 'b': '2'\n}");204 bt('if (template.user[n] in bk) foo();');205 bt('{{}/z/}', "{\n {}\n /z/\n}");206 bt('return 45', "return 45");207 bt('return this.prevObject ||\n\n this.constructor(null);');208 bt('If[1]', "If[1]");209 bt('Then[1]', "Then[1]");210 bt('a = 1e10', "a = 1e10");211 bt('a = 1.3e10', "a = 1.3e10");212 bt('a = 1.3e-10', "a = 1.3e-10");213 bt('a = -1.3e-10', "a = -1.3e-10");214 bt('a = 1e-10', "a = 1e-10");215 bt('a = e - 10', "a = e - 10");216 bt('a = 11-10', "a = 11 - 10");217 bt("a = 1;// comment", "a = 1; // comment");218 bt("a = 1; // comment", "a = 1; // comment");219 bt("a = 1;\n // comment", "a = 1;\n// comment");220 bt('a = [-1, -1, -1]');221 // The exact formatting these should have is open for discussion, but they are at least reasonable222 bt('a = [ // comment\n -1, -1, -1\n]');223 bt('var a = [ // comment\n -1, -1, -1\n]');224 bt('a = [ // comment\n -1, // comment\n -1, -1\n]');225 bt('var a = [ // comment\n -1, // comment\n -1, -1\n]');226 bt('o = [{a:b},{c:d}]', 'o = [{\n a: b\n}, {\n c: d\n}]');227 bt("if (a) {\n do();\n}"); // was: extra space appended228 bt("if (a) {\n// comment\n}else{\n// comment\n}", "if (a) {\n // comment\n} else {\n // comment\n}"); // if/else statement with empty body229 bt("if (a) {\n// comment\n// comment\n}", "if (a) {\n // comment\n // comment\n}"); // multiple comments indentation230 bt("if (a) b() else c();", "if (a) b()\nelse c();");231 bt("if (a) b() else if c() d();", "if (a) b()\nelse if c() d();");232 bt("{}");233 bt("{\n\n}");234 bt("do { a(); } while ( 1 );", "do {\n a();\n} while (1);");235 bt("do {} while (1);");236 bt("do {\n} while (1);", "do {} while (1);");237 bt("do {\n\n} while (1);");238 bt("var a = x(a, b, c)");239 bt("delete x if (a) b();", "delete x\nif (a) b();");240 bt("delete x[x] if (a) b();", "delete x[x]\nif (a) b();");241 bt("for(var a=1,b=2)d", "for (var a = 1, b = 2) d");242 bt("for(var a=1,b=2,c=3) d", "for (var a = 1, b = 2, c = 3) d");243 bt("for(var a=1,b=2,c=3;d<3;d++)\ne", "for (var a = 1, b = 2, c = 3; d < 3; d++)\n e");244 bt("function x(){(a||b).c()}", "function x() {\n (a || b).c()\n}");245 bt("function x(){return - 1}", "function x() {\n return -1\n}");246 bt("function x(){return ! a}", "function x() {\n return !a\n}");247 bt("x => x", "x => x");248 bt("(x) => x", "(x) => x");249 bt("x => { x }", "x => {\n x\n}");250 bt("(x) => { x }", "(x) => {\n x\n}");251 // a common snippet in jQuery plugins252 bt("settings = $.extend({},defaults,settings);", "settings = $.extend({}, defaults, settings);");253 // reserved words used as property names254 bt("$http().then().finally().default()", "$http().then().finally().default()");255 bt("$http()\n.then()\n.finally()\n.default()", "$http()\n .then()\n .finally()\n .default()");256 bt("$http().when.in.new.catch().throw()", "$http().when.in.new.catch().throw()");257 bt("$http()\n.when\n.in\n.new\n.catch()\n.throw()", "$http()\n .when\n .in\n .new\n .catch()\n .throw()");258 bt('{xxx;}()', '{\n xxx;\n}()');259 bt("a = 'a'\nb = 'b'");260 bt("a = /reg/exp");261 bt("a = /reg/");262 bt('/abc/.test()');263 bt('/abc/i.test()');264 bt("{/abc/i.test()}", "{\n /abc/i.test()\n}");265 bt('var x=(a)/a;', 'var x = (a) / a;');266 bt('x != -1', 'x != -1');267 bt('for (; s-->0;)t', 'for (; s-- > 0;) t');268 bt('for (; s++>0;)u', 'for (; s++ > 0;) u');269 bt('a = s++>s--;', 'a = s++ > s--;');270 bt('a = s++>--s;', 'a = s++ > --s;');271 bt('{x=#1=[]}', '{\n x = #1=[]\n}');272 bt('{a:#1={}}', '{\n a: #1={}\n}');273 bt('{a:#1#}', '{\n a: #1#\n}');274 test_fragment('"incomplete-string');275 test_fragment("'incomplete-string");276 test_fragment('/incomplete-regex');277 test_fragment('`incomplete-template-string');278 test_fragment('{a:1},{a:2}', '{\n a: 1\n}, {\n a: 2\n}');279 test_fragment('var ary=[{a:1}, {a:2}];', 'var ary = [{\n a: 1\n}, {\n a: 2\n}];');280 test_fragment('{a:#1', '{\n a: #1'); // incomplete281 test_fragment('{a:#', '{\n a: #'); // incomplete282 test_fragment('}}}', '}\n}\n}'); // incomplete283 test_fragment('<!--\nvoid();\n// -->', '<!--\nvoid();\n// -->');284 test_fragment('a=/regexp', 'a = /regexp'); // incomplete regexp285 bt('{a:#1=[],b:#1#,c:#999999#}', '{\n a: #1=[],\n b: #1#,\n c: #999999#\n}');286 bt("a = 1e+2");287 bt("a = 1e-2");288 bt("do{x()}while(a>1)", "do {\n x()\n} while (a > 1)");289 bt("x(); /reg/exp.match(something)", "x();\n/reg/exp.match(something)");290 test_fragment("something();(", "something();\n(");291 test_fragment("#!she/bangs, she bangs\nf=1", "#!she/bangs, she bangs\n\nf = 1");292 test_fragment("#!she/bangs, she bangs\n\nf=1", "#!she/bangs, she bangs\n\nf = 1");293 test_fragment("#!she/bangs, she bangs\n\n/* comment */", "#!she/bangs, she bangs\n\n/* comment */");294 test_fragment("#!she/bangs, she bangs\n\n\n/* comment */", "#!she/bangs, she bangs\n\n\n/* comment */");295 test_fragment("#", "#");296 test_fragment("#!", "#!");297 bt("function namespace::something()");298 test_fragment("<!--\nsomething();\n-->", "<!--\nsomething();\n-->");299 test_fragment("<!--\nif(i<0){bla();}\n-->", "<!--\nif (i < 0) {\n bla();\n}\n-->");300 bt('{foo();--bar;}', '{\n foo();\n --bar;\n}');301 bt('{foo();++bar;}', '{\n foo();\n ++bar;\n}');302 bt('{--bar;}', '{\n --bar;\n}');303 bt('{++bar;}', '{\n ++bar;\n}');304 // Handling of newlines around unary ++ and -- operators305 bt('{foo\n++bar;}', '{\n foo\n ++bar;\n}');306 bt('{foo++\nbar;}', '{\n foo++\n bar;\n}');307 // This is invalid, but harder to guard against. Issue #203.308 bt('{foo\n++\nbar;}', '{\n foo\n ++\n bar;\n}');309 // regexps310 bt('a(/abc\\/\\/def/);b()', "a(/abc\\/\\/def/);\nb()");311 bt('a(/a[b\\[\\]c]d/);b()', "a(/a[b\\[\\]c]d/);\nb()");312 test_fragment('a(/a[b\\[', "a(/a[b\\["); // incomplete char class313 // allow unescaped / in char classes314 bt('a(/[a/b]/);b()', "a(/[a/b]/);\nb()");315 bt('function foo() {\n return [\n "one",\n "two"\n ];\n}');316 bt('a=[[1,2],[4,5],[7,8]]', "a = [\n [1, 2],\n [4, 5],\n [7, 8]\n]");317 bt('a=[[1,2],[4,5],function(){},[7,8]]',318 "a = [\n [1, 2],\n [4, 5],\n function() {},\n [7, 8]\n]");319 bt('a=[[1,2],[4,5],function(){},function(){},[7,8]]',320 "a = [\n [1, 2],\n [4, 5],\n function() {},\n function() {},\n [7, 8]\n]");321 bt('a=[[1,2],[4,5],function(){},[7,8]]',322 "a = [\n [1, 2],\n [4, 5],\n function() {},\n [7, 8]\n]");323 bt('a=[b,c,function(){},function(){},d]',324 "a = [b, c,\n function() {},\n function() {},\n d\n]");325 bt('a=[a[1],b[4],c[d[7]]]', "a = [a[1], b[4], c[d[7]]]");326 bt('[1,2,[3,4,[5,6],7],8]', "[1, 2, [3, 4, [5, 6], 7], 8]");327 bt('[[["1","2"],["3","4"]],[["5","6","7"],["8","9","0"]],[["1","2","3"],["4","5","6","7"],["8","9","0"]]]',328 '[\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]');329 bt('{[x()[0]];indent;}', '{\n [x()[0]];\n indent;\n}');330 bt('return ++i', 'return ++i');331 bt('return !!x', 'return !!x');332 bt('return !x', 'return !x');333 bt('return [1,2]', 'return [1, 2]');334 bt('return;', 'return;');335 bt('return\nfunc', 'return\nfunc');336 bt('catch(e)', 'catch (e)');337 bt('yield [1, 2]');338 bt('var a=1,b={foo:2,bar:3},{baz:4,wham:5},c=4;',339 'var a = 1,\n b = {\n foo: 2,\n bar: 3\n },\n {\n baz: 4,\n wham: 5\n }, c = 4;');340 bt('var a=1,b={foo:2,bar:3},{baz:4,wham:5},\nc=4;',341 'var a = 1,\n b = {\n foo: 2,\n bar: 3\n },\n {\n baz: 4,\n wham: 5\n },\n c = 4;');342 // inline comment343 bt('function x(/*int*/ start, /*string*/ foo)', 'function x( /*int*/ start, /*string*/ foo)');344 // javadoc comment345 bt('/**\n* foo\n*/', '/**\n * foo\n */');346 bt('{\n/**\n* foo\n*/\n}', '{\n /**\n * foo\n */\n}');347 // starless block comment348 bt('/**\nfoo\n*/');349 bt('/**\nfoo\n**/');350 bt('/**\nfoo\nbar\n**/');351 bt('/**\nfoo\n\nbar\n**/');352 bt('/**\nfoo\n bar\n**/');353 bt('{\n/**\nfoo\n*/\n}', '{\n /**\n foo\n */\n}');354 bt('{\n/**\nfoo\n**/\n}', '{\n /**\n foo\n **/\n}');355 bt('{\n/**\nfoo\nbar\n**/\n}', '{\n /**\n foo\n bar\n **/\n}');356 bt('{\n/**\nfoo\n\nbar\n**/\n}', '{\n /**\n foo\n\n bar\n **/\n}');357 bt('{\n/**\nfoo\n bar\n**/\n}', '{\n /**\n foo\n bar\n **/\n}');358 bt('{\n /**\n foo\nbar\n **/\n}');359 bt('var a,b,c=1,d,e,f=2;', 'var a, b, c = 1,\n d, e, f = 2;');360 bt('var a,b,c=[],d,e,f=2;', 'var a, b, c = [],\n d, e, f = 2;');361 bt('function() {\n var a, b, c, d, e = [],\n f;\n}');362 bt('do/regexp/;\nwhile(1);', 'do /regexp/;\nwhile (1);'); // hmmm363 bt('var a = a,\na;\nb = {\nb\n}', 'var a = a,\n a;\nb = {\n b\n}');364 bt('var a = a,\n /* c */\n b;');365 bt('var a = a,\n // c\n b;');366 bt('foo.("bar");'); // weird element referencing367 bt('if (a) a()\nelse b()\nnewline()');368 bt('if (a) a()\nnewline()');369 bt('a=typeof(x)', 'a = typeof(x)');370 bt('var a = function() {\n return null;\n },\n b = false;');371 bt('var a = function() {\n func1()\n}');372 bt('var a = function() {\n func1()\n}\nvar b = function() {\n func2()\n}');373 // code with and without semicolons374 bt( 'var whatever = require("whatever");\nfunction() {\n a = 6;\n}',375 'var whatever = require("whatever");\n\nfunction() {\n a = 6;\n}');376 bt( 'var whatever = require("whatever")\nfunction() {\n a = 6\n}',377 'var whatever = require("whatever")\n\nfunction() {\n a = 6\n}');378 opts.jslint_happy = true;379 bt('a=typeof(x)', 'a = typeof (x)');380 bt('x();\n\nfunction(){}', 'x();\n\nfunction () {}');381 bt('function () {\n var a, b, c, d, e = [],\n f;\n}');382 bt('switch(x) {case 0: case 1: a(); break; default: break}',383 "switch (x) {\ncase 0:\ncase 1:\n a();\n break;\ndefault:\n break\n}");384 bt('switch(x){case -1:break;case !y:break;}',385 'switch (x) {\ncase -1:\n break;\ncase !y:\n break;\n}');386 test_fragment("// comment 1\n(function()", "// comment 1\n(function ()"); // typical greasemonkey start387 bt('var o1=$.extend(a);function(){alert(x);}', 'var o1 = $.extend(a);\n\nfunction () {\n alert(x);\n}');388 bt('function* () {\n yield 1;\n}');389 opts.jslint_happy = false;390 bt('switch(x) {case 0: case 1: a(); break; default: break}',391 "switch (x) {\n case 0:\n case 1:\n a();\n break;\n default:\n break\n}");392 bt('switch(x){case -1:break;case !y:break;}',393 'switch (x) {\n case -1:\n break;\n case !y:\n break;\n}');394 test_fragment("// comment 2\n(function()", "// comment 2\n(function()"); // typical greasemonkey start395 bt("var a2, b2, c2, d2 = 0, c = function() {}, d = '';", "var a2, b2, c2, d2 = 0,\n c = function() {},\n d = '';");396 bt("var a2, b2, c2, d2 = 0, c = function() {},\nd = '';", "var a2, b2, c2, d2 = 0,\n c = function() {},\n d = '';");397 bt('var o2=$.extend(a);function(){alert(x);}', 'var o2 = $.extend(a);\n\nfunction() {\n alert(x);\n}');398 bt('function*() {\n yield 1;\n}');399 bt('function* x() {\n yield 1;\n}');400 bt('{"x":[{"a":1,"b":3},7,8,8,8,8,{"b":99},{"a":11}]}', '{\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}');401 bt('{"1":{"1a":"1b"},"2"}', '{\n "1": {\n "1a": "1b"\n },\n "2"\n}');402 bt('{a:{a:b},c}', '{\n a: {\n a: b\n },\n c\n}');403 bt('{[y[a]];keep_indent;}', '{\n [y[a]];\n keep_indent;\n}');404 bt('if (x) {y} else { if (x) {y}}', 'if (x) {\n y\n} else {\n if (x) {\n y\n }\n}');405 bt('if (foo) one()\ntwo()\nthree()');406 bt('if (1 + foo() && bar(baz()) / 2) one()\ntwo()\nthree()');407 bt('if (1 + foo() && bar(baz()) / 2) one();\ntwo();\nthree();');408 opts.indent_size = 1;409 opts.indent_char = ' ';410 bt('{ one_char() }', "{\n one_char()\n}");411 bt('var a,b=1,c=2', 'var a, b = 1,\n c = 2');412 opts.indent_size = 4;413 opts.indent_char = ' ';414 bt('{ one_char() }', "{\n one_char()\n}");415 opts.indent_size = 1;416 opts.indent_char = "\t";417 bt('{ one_char() }', "{\n\tone_char()\n}");418 bt('x = a ? b : c; x;', 'x = a ? b : c;\nx;');419 //set to something else than it should change to, but with tabs on, should override420 opts.indent_size = 5;421 opts.indent_char = ' ';422 opts.indent_with_tabs = true;423 bt('{ one_char() }', "{\n\tone_char()\n}");424 bt('x = a ? b : c; x;', 'x = a ? b : c;\nx;');425 opts.indent_size = 4;426 opts.indent_char = ' ';427 opts.indent_with_tabs = false;428 opts.preserve_newlines = false;429 bt('var\na=dont_preserve_newlines;', 'var a = dont_preserve_newlines;');430 // make sure the blank line between function definitions stays431 // even when preserve_newlines = false432 bt('function foo() {\n return 1;\n}\n\nfunction foo() {\n return 1;\n}');433 bt('function foo() {\n return 1;\n}\nfunction foo() {\n return 1;\n}',434 'function foo() {\n return 1;\n}\n\nfunction foo() {\n return 1;\n}'435 );436 bt('function foo() {\n return 1;\n}\n\n\nfunction foo() {\n return 1;\n}',437 'function foo() {\n return 1;\n}\n\nfunction foo() {\n return 1;\n}'438 );439 opts.preserve_newlines = true;440 bt('var\na=do_preserve_newlines;', 'var\n a = do_preserve_newlines;');441 bt('// a\n// b\n\n// c\n// d');442 bt('if (foo) // comment\n{\n bar();\n}');443 opts.keep_array_indentation = false;444 bt("a = ['a', 'b', 'c',\n 'd', 'e', 'f']",445 "a = ['a', 'b', 'c',\n 'd', 'e', 'f'\n]");446 bt("a = ['a', 'b', 'c',\n 'd', 'e', 'f',\n 'g', 'h', 'i']",447 "a = ['a', 'b', 'c',\n 'd', 'e', 'f',\n 'g', 'h', 'i'\n]");448 bt("a = ['a', 'b', 'c',\n 'd', 'e', 'f',\n 'g', 'h', 'i']",449 "a = ['a', 'b', 'c',\n 'd', 'e', 'f',\n 'g', 'h', 'i'\n]");450 bt('var x = [{}\n]', 'var x = [{}]');451 bt('var x = [{foo:bar}\n]', 'var x = [{\n foo: bar\n}]');452 bt("a = ['something',\n 'completely',\n 'different'];\nif (x);",453 "a = ['something',\n 'completely',\n 'different'\n];\nif (x);");454 bt("a = ['a','b','c']", "a = ['a', 'b', 'c']");455 bt("a = ['a', 'b','c']", "a = ['a', 'b', 'c']");456 bt("x = [{'a':0}]",457 "x = [{\n 'a': 0\n}]");458 bt('{a([[a1]], {b;});}',459 '{\n a([\n [a1]\n ], {\n b;\n });\n}');460 bt("a();\n [\n ['sdfsdfsd'],\n ['sdfsdfsdf']\n ].toString();",461 "a();\n[\n ['sdfsdfsd'],\n ['sdfsdfsdf']\n].toString();");462 bt("a();\na = [\n ['sdfsdfsd'],\n ['sdfsdfsdf']\n ].toString();",463 "a();\na = [\n ['sdfsdfsd'],\n ['sdfsdfsdf']\n].toString();");464 bt("function() {\n Foo([\n ['sdfsdfsd'],\n ['sdfsdfsdf']\n ]);\n}",465 "function() {\n Foo([\n ['sdfsdfsd'],\n ['sdfsdfsdf']\n ]);\n}");466 bt('function foo() {\n return [\n "one",\n "two"\n ];\n}');467 // 4 spaces per indent input, processed with 4-spaces per indent468 bt( "function foo() {\n" +469 " return [\n" +470 " {\n" +471 " one: 'x',\n" +472 " two: [\n" +473 " {\n" +474 " id: 'a',\n" +475 " name: 'apple'\n" +476 " }, {\n" +477 " id: 'b',\n" +478 " name: 'banana'\n" +479 " }\n" +480 " ]\n" +481 " }\n" +482 " ];\n" +483 "}",484 "function foo() {\n" +485 " return [{\n" +486 " one: 'x',\n" +487 " two: [{\n" +488 " id: 'a',\n" +489 " name: 'apple'\n" +490 " }, {\n" +491 " id: 'b',\n" +492 " name: 'banana'\n" +493 " }]\n" +494 " }];\n" +495 "}");496 // 3 spaces per indent input, processed with 4-spaces per indent497 bt( "function foo() {\n" +498 " return [\n" +499 " {\n" +500 " one: 'x',\n" +501 " two: [\n" +502 " {\n" +503 " id: 'a',\n" +504 " name: 'apple'\n" +505 " }, {\n" +506 " id: 'b',\n" +507 " name: 'banana'\n" +508 " }\n" +509 " ]\n" +510 " }\n" +511 " ];\n" +512 "}",513 "function foo() {\n" +514 " return [{\n" +515 " one: 'x',\n" +516 " two: [{\n" +517 " id: 'a',\n" +518 " name: 'apple'\n" +519 " }, {\n" +520 " id: 'b',\n" +521 " name: 'banana'\n" +522 " }]\n" +523 " }];\n" +524 "}");525 opts.keep_array_indentation = true;526 bt("a = ['a', 'b', 'c',\n 'd', 'e', 'f']");527 bt("a = ['a', 'b', 'c',\n 'd', 'e', 'f',\n 'g', 'h', 'i']");528 bt("a = ['a', 'b', 'c',\n 'd', 'e', 'f',\n 'g', 'h', 'i']");529 bt('var x = [{}\n]', 'var x = [{}\n]');530 bt('var x = [{foo:bar}\n]', 'var x = [{\n foo: bar\n }\n]');531 bt("a = ['something',\n 'completely',\n 'different'];\nif (x);");532 bt("a = ['a','b','c']", "a = ['a', 'b', 'c']");533 bt("a = ['a', 'b','c']", "a = ['a', 'b', 'c']");534 bt("x = [{'a':0}]",535 "x = [{\n 'a': 0\n}]");536 bt('{a([[a1]], {b;});}',537 '{\n a([[a1]], {\n b;\n });\n}');538 bt("a();\n [\n ['sdfsdfsd'],\n ['sdfsdfsdf']\n ].toString();",539 "a();\n [\n ['sdfsdfsd'],\n ['sdfsdfsdf']\n ].toString();");540 bt("a();\na = [\n ['sdfsdfsd'],\n ['sdfsdfsdf']\n ].toString();",541 "a();\na = [\n ['sdfsdfsd'],\n ['sdfsdfsdf']\n ].toString();");542 bt("function() {\n Foo([\n ['sdfsdfsd'],\n ['sdfsdfsdf']\n ]);\n}",543 "function() {\n Foo([\n ['sdfsdfsd'],\n ['sdfsdfsdf']\n ]);\n}");544 bt('function foo() {\n return [\n "one",\n "two"\n ];\n}');545 // 4 spaces per indent input, processed with 4-spaces per indent546 bt( "function foo() {\n" +547 " return [\n" +548 " {\n" +549 " one: 'x',\n" +550 " two: [\n" +551 " {\n" +552 " id: 'a',\n" +553 " name: 'apple'\n" +554 " }, {\n" +555 " id: 'b',\n" +556 " name: 'banana'\n" +557 " }\n" +558 " ]\n" +559 " }\n" +560 " ];\n" +561 "}");562 // 3 spaces per indent input, processed with 4-spaces per indent563 // Should be unchanged, but is not - #445564// bt( "function foo() {\n" +565// " return [\n" +566// " {\n" +567// " one: 'x',\n" +568// " two: [\n" +569// " {\n" +570// " id: 'a',\n" +571// " name: 'apple'\n" +572// " }, {\n" +573// " id: 'b',\n" +574// " name: 'banana'\n" +575// " }\n" +576// " ]\n" +577// " }\n" +578// " ];\n" +579// "}");580 opts.keep_array_indentation = false;581 bt('a = //comment\n /regex/;');582 test_fragment('/*\n * X\n */');583 test_fragment('/*\r\n * X\r\n */', '/*\n * X\n */');584 bt('if (a)\n{\nb;\n}\nelse\n{\nc;\n}', 'if (a) {\n b;\n} else {\n c;\n}');585 opts.brace_style = 'expand';586 bt('//case 1\nif (a == 1)\n{}\n//case 2\nelse if (a == 2)\n{}');587 bt('if(1){2}else{3}', "if (1)\n{\n 2\n}\nelse\n{\n 3\n}");588 bt('try{a();}catch(b){c();}catch(d){}finally{e();}',589 "try\n{\n a();\n}\ncatch (b)\n{\n c();\n}\ncatch (d)\n{}\nfinally\n{\n e();\n}");590 bt('if(a){b();}else if(c) foo();',591 "if (a)\n{\n b();\n}\nelse if (c) foo();");592 bt('if(X)if(Y)a();else b();else c();',593 "if (X)\n if (Y) a();\n else b();\nelse c();");594 bt("if (a) {\n// comment\n}else{\n// comment\n}",595 "if (a)\n{\n // comment\n}\nelse\n{\n // comment\n}"); // if/else statement with empty body596 bt('if (x) {y} else { if (x) {y}}',597 'if (x)\n{\n y\n}\nelse\n{\n if (x)\n {\n y\n }\n}');598 bt('if (a)\n{\nb;\n}\nelse\n{\nc;\n}',599 'if (a)\n{\n b;\n}\nelse\n{\n c;\n}');600 test_fragment(' /*\n* xx\n*/\n// xx\nif (foo) {\n bar();\n}',601 ' /*\n * xx\n */\n // xx\n if (foo)\n {\n bar();\n }');602 bt('if (foo)\n{}\nelse /regex/.test();');603 bt('if (foo) /regex/.test();');604 bt('if (a)\n{\nb;\n}\nelse\n{\nc;\n}', 'if (a)\n{\n b;\n}\nelse\n{\n c;\n}');605 test_fragment('if (foo) {', 'if (foo)\n{');606 test_fragment('foo {', 'foo\n{');607 test_fragment('return {', 'return {'); // return needs the brace.608 test_fragment('return /* inline */ {', 'return /* inline */ {');609 // test_fragment('return\n{', 'return\n{'); // can't support this?, but that's an improbable and extreme case anyway.610 test_fragment('return;\n{', 'return;\n{');611 bt("throw {}");612 bt("throw {\n foo;\n}");613 bt('var foo = {}');614 bt('if (foo) bar();\nelse break');615 bt('function x() {\n foo();\n}zzz', 'function x()\n{\n foo();\n}\nzzz');616 bt('a: do {} while (); xxx', 'a: do {} while ();\nxxx');617 bt('var a = new function();');618 bt('var a = new function() {};');619 bt('var a = new function()\n{};', 'var a = new function() {};');620 bt('var a = new function a()\n{};');621 bt('var a = new function a()\n {},\n b = new function b()\n {};');622 test_fragment('new function');623 bt("foo({\n 'a': 1\n},\n10);",624 "foo(\n {\n 'a': 1\n },\n 10);");625 bt('(["foo","bar"]).each(function(i) {return i;});',626 '(["foo", "bar"]).each(function(i)\n{\n return i;\n});');627 bt('(function(i) {return i;})();',628 '(function(i)\n{\n return i;\n})();');629 bt( "test( /*Argument 1*/ {\n" +630 " 'Value1': '1'\n" +631 "}, /*Argument 2\n" +632 " */ {\n" +633 " 'Value2': '2'\n" +634 "});",635 // expected636 "test( /*Argument 1*/\n" +637 " {\n" +638 " 'Value1': '1'\n" +639 " },\n" +640 " /*Argument 2\n" +641 " */\n" +642 " {\n" +643 " 'Value2': '2'\n" +644 " });");645 bt( "test(\n" +646 "/*Argument 1*/ {\n" +647 " 'Value1': '1'\n" +648 "},\n" +649 "/*Argument 2\n" +650 " */ {\n" +651 " 'Value2': '2'\n" +652 "});",653 // expected654 "test(\n" +655 " /*Argument 1*/\n" +656 " {\n" +657 " 'Value1': '1'\n" +658 " },\n" +659 " /*Argument 2\n" +660 " */\n" +661 " {\n" +662 " 'Value2': '2'\n" +663 " });");664 bt( "test( /*Argument 1*/\n" +665 "{\n" +666 " 'Value1': '1'\n" +667 "}, /*Argument 2\n" +668 " */\n" +669 "{\n" +670 " 'Value2': '2'\n" +671 "});",672 // expected673 "test( /*Argument 1*/\n" +674 " {\n" +675 " 'Value1': '1'\n" +676 " },\n" +677 " /*Argument 2\n" +678 " */\n" +679 " {\n" +680 " 'Value2': '2'\n" +681 " });");682 opts.brace_style = 'collapse';683 bt('//case 1\nif (a == 1) {}\n//case 2\nelse if (a == 2) {}');684 bt('if(1){2}else{3}', "if (1) {\n 2\n} else {\n 3\n}");685 bt('try{a();}catch(b){c();}catch(d){}finally{e();}',686 "try {\n a();\n} catch (b) {\n c();\n} catch (d) {} finally {\n e();\n}");687 bt('if(a){b();}else if(c) foo();',688 "if (a) {\n b();\n} else if (c) foo();");689 bt("if (a) {\n// comment\n}else{\n// comment\n}",690 "if (a) {\n // comment\n} else {\n // comment\n}"); // if/else statement with empty body691 bt('if (x) {y} else { if (x) {y}}',692 'if (x) {\n y\n} else {\n if (x) {\n y\n }\n}');693 bt('if (a)\n{\nb;\n}\nelse\n{\nc;\n}',694 'if (a) {\n b;\n} else {\n c;\n}');695 test_fragment(' /*\n* xx\n*/\n// xx\nif (foo) {\n bar();\n}',696 ' /*\n * xx\n */\n // xx\n if (foo) {\n bar();\n }');697 bt('if (foo) {} else /regex/.test();');698 bt('if (foo) /regex/.test();');699 bt('if (a)\n{\nb;\n}\nelse\n{\nc;\n}', 'if (a) {\n b;\n} else {\n c;\n}');700 test_fragment('if (foo) {', 'if (foo) {');701 test_fragment('foo {', 'foo {');702 test_fragment('return {', 'return {'); // return needs the brace.703 test_fragment('return /* inline */ {', 'return /* inline */ {');704 // test_fragment('return\n{', 'return\n{'); // can't support this?, but that's an improbable and extreme case anyway.705 test_fragment('return;\n{', 'return; {');706 bt("throw {}");707 bt("throw {\n foo;\n}");708 bt('var foo = {}');709 bt('if (foo) bar();\nelse break');710 bt('function x() {\n foo();\n}zzz', 'function x() {\n foo();\n}\nzzz');711 bt('a: do {} while (); xxx', 'a: do {} while ();\nxxx');712 bt('var a = new function();');713 bt('var a = new function() {};');714 bt('var a = new function a() {};');715 test_fragment('new function');716 bt("foo({\n 'a': 1\n},\n10);",717 "foo({\n 'a': 1\n },\n 10);");718 bt('(["foo","bar"]).each(function(i) {return i;});',719 '(["foo", "bar"]).each(function(i) {\n return i;\n});');720 bt('(function(i) {return i;})();',721 '(function(i) {\n return i;\n})();');722 bt( "test( /*Argument 1*/ {\n" +723 " 'Value1': '1'\n" +724 "}, /*Argument 2\n" +725 " */ {\n" +726 " 'Value2': '2'\n" +727 "});",728 // expected729 "test( /*Argument 1*/ {\n" +730 " 'Value1': '1'\n" +731 " },\n" +732 " /*Argument 2\n" +733 " */\n" +734 " {\n" +735 " 'Value2': '2'\n" +736 " });");737 bt( "test(\n" +738 "/*Argument 1*/ {\n" +739 " 'Value1': '1'\n" +740 "},\n" +741 "/*Argument 2\n" +742 " */ {\n" +743 " 'Value2': '2'\n" +744 "});",745 // expected746 "test(\n" +747 " /*Argument 1*/\n" +748 " {\n" +749 " 'Value1': '1'\n" +750 " },\n" +751 " /*Argument 2\n" +752 " */\n" +753 " {\n" +754 " 'Value2': '2'\n" +755 " });");756 bt( "test( /*Argument 1*/\n" +757 "{\n" +758 " 'Value1': '1'\n" +759 "}, /*Argument 2\n" +760 " */\n" +761 "{\n" +762 " 'Value2': '2'\n" +763 "});",764 // expected765 "test( /*Argument 1*/ {\n" +766 " 'Value1': '1'\n" +767 " },\n" +768 " /*Argument 2\n" +769 " */\n" +770 " {\n" +771 " 'Value2': '2'\n" +772 " });");773 opts.brace_style = "end-expand";774 bt('//case 1\nif (a == 1) {}\n//case 2\nelse if (a == 2) {}');775 bt('if(1){2}else{3}', "if (1) {\n 2\n}\nelse {\n 3\n}");776 bt('try{a();}catch(b){c();}catch(d){}finally{e();}',777 "try {\n a();\n}\ncatch (b) {\n c();\n}\ncatch (d) {}\nfinally {\n e();\n}");778 bt('if(a){b();}else if(c) foo();',779 "if (a) {\n b();\n}\nelse if (c) foo();");780 bt("if (a) {\n// comment\n}else{\n// comment\n}",781 "if (a) {\n // comment\n}\nelse {\n // comment\n}"); // if/else statement with empty body782 bt('if (x) {y} else { if (x) {y}}',783 'if (x) {\n y\n}\nelse {\n if (x) {\n y\n }\n}');784 bt('if (a)\n{\nb;\n}\nelse\n{\nc;\n}',785 'if (a) {\n b;\n}\nelse {\n c;\n}');786 test_fragment(' /*\n* xx\n*/\n// xx\nif (foo) {\n bar();\n}',787 ' /*\n * xx\n */\n // xx\n if (foo) {\n bar();\n }');788 bt('if (foo) {}\nelse /regex/.test();');789 bt('if (foo) /regex/.test();');790 bt('if (a)\n{\nb;\n}\nelse\n{\nc;\n}', 'if (a) {\n b;\n}\nelse {\n c;\n}');791 test_fragment('if (foo) {', 'if (foo) {');792 test_fragment('foo {', 'foo {');793 test_fragment('return {', 'return {'); // return needs the brace.794 test_fragment('return /* inline */ {', 'return /* inline */ {');795 // test_fragment('return\n{', 'return\n{'); // can't support this?, but that's an improbable and extreme case anyway.796 test_fragment('return;\n{', 'return; {');797 bt("throw {}");798 bt("throw {\n foo;\n}");799 bt('var foo = {}');800 bt('if (foo) bar();\nelse break');801 bt('function x() {\n foo();\n}zzz', 'function x() {\n foo();\n}\nzzz');802 bt('a: do {} while (); xxx', 'a: do {} while ();\nxxx');803 bt('var a = new function();');804 bt('var a = new function() {};');805 bt('var a = new function a() {};');806 test_fragment('new function');807 bt("foo({\n 'a': 1\n},\n10);",808 "foo({\n 'a': 1\n },\n 10);");809 bt('(["foo","bar"]).each(function(i) {return i;});',810 '(["foo", "bar"]).each(function(i) {\n return i;\n});');811 bt('(function(i) {return i;})();',812 '(function(i) {\n return i;\n})();');813 bt( "test( /*Argument 1*/ {\n" +814 " 'Value1': '1'\n" +815 "}, /*Argument 2\n" +816 " */ {\n" +817 " 'Value2': '2'\n" +818 "});",819 // expected820 "test( /*Argument 1*/ {\n" +821 " 'Value1': '1'\n" +822 " },\n" +823 " /*Argument 2\n" +824 " */\n" +825 " {\n" +826 " 'Value2': '2'\n" +827 " });");828 bt( "test(\n" +829 "/*Argument 1*/ {\n" +830 " 'Value1': '1'\n" +831 "},\n" +832 "/*Argument 2\n" +833 " */ {\n" +834 " 'Value2': '2'\n" +835 "});",836 // expected837 "test(\n" +838 " /*Argument 1*/\n" +839 " {\n" +840 " 'Value1': '1'\n" +841 " },\n" +842 " /*Argument 2\n" +843 " */\n" +844 " {\n" +845 " 'Value2': '2'\n" +846 " });");847 bt( "test( /*Argument 1*/\n" +848 "{\n" +849 " 'Value1': '1'\n" +850 "}, /*Argument 2\n" +851 " */\n" +852 "{\n" +853 " 'Value2': '2'\n" +854 "});",855 // expected856 "test( /*Argument 1*/ {\n" +857 " 'Value1': '1'\n" +858 " },\n" +859 " /*Argument 2\n" +860 " */\n" +861 " {\n" +862 " 'Value2': '2'\n" +863 " });");864 opts.brace_style = 'collapse';865 bt('a = <?= external() ?> ;'); // not the most perfect thing in the world, but you're the weirdo beaufifying php mix-ins with javascript beautifier866 bt('a = <%= external() %> ;');867 bt('// func-comment\n\nfunction foo() {}\n\n// end-func-comment');868 test_fragment('roo = {\n /*\n ****\n FOO\n ****\n */\n BAR: 0\n};');869 bt('"foo""bar""baz"', '"foo"\n"bar"\n"baz"');870 bt("'foo''bar''baz'", "'foo'\n'bar'\n'baz'");871 test_fragment("if (zz) {\n // ....\n}\n(function");872 bt("{\n get foo() {}\n}");873 bt("{\n var a = get\n foo();\n}");874 bt("{\n set foo() {}\n}");875 bt("{\n var a = set\n foo();\n}");876 bt("var x = {\n get function()\n}");877 bt("var x = {\n set function()\n}");878 bt("var x = set\n\na() {}", "var x = set\n\n a() {}");879 bt("var x = set\n\nfunction() {}", "var x = set\n\n function() {}");880 bt('<!-- foo\nbar();\n-->');881 bt('<!-- dont crash');882 bt('for () /abc/.test()');883 bt('if (k) /aaa/m.test(v) && l();');884 bt('switch (true) {\n case /swf/i.test(foo):\n bar();\n}');885 bt('createdAt = {\n type: Date,\n default: Date.now\n}');886 bt('switch (createdAt) {\n case a:\n Date,\n default:\n Date.now\n}');887 opts.space_before_conditional = false;888 bt('if(a) b()');889 opts.space_before_conditional = true;890 opts.preserve_newlines = true;891 bt('var a = 42; // foo\n\nvar b;');892 bt('var a = 42; // foo\n\n\nvar b;');893 bt("var a = 'foo' +\n 'bar';");894 bt("var a = \"foo\" +\n \"bar\";");895 bt('this.oa = new OAuth(\n' +896 ' _requestToken,\n' +897 ' _accessToken,\n' +898 ' consumer_key\n' +899 ');');900 opts.unescape_strings = false;901 test_fragment('"\\x22\\x27", \'\\x22\\x27\', "\\x5c", \'\\x5c\', "\\xff and \\xzz", "unicode \\u0000 \\u0022 \\u0027 \\u005c \\uffff \\uzzzz"');902 opts.unescape_strings = true;903 test_fragment('"\\x20\\x40\\x4a"', '" @J"');904 test_fragment('"\\xff\\x40\\x4a"');905 test_fragment('"\\u0072\\u016B\\u0137\\u012B\\u0074\\u0069\\u0073"', '"rūķītis"');906 test_fragment('"Google Chrome est\\u00E1 actualizado."', '"Google Chrome está actualizado."');907 /*908 bt('"\\x22\\x27",\'\\x22\\x27\',"\\x5c",\'\\x5c\',"\\xff and \\xzz","unicode \\u0000 \\u0022 \\u0027 \\u005c \\uffff \\uzzzz"',909 '"\\"\'", \'"\\\'\', "\\\\", \'\\\\\', "\\xff and \\xzz", "unicode \\u0000 \\" \' \\\\ \\uffff \\uzzzz"');910 */911 opts.unescape_strings = false;912 bt('return function();');913 bt('var a = function();');914 bt('var a = 5 + function();');915 bt('3.*7;', '3. * 7;');916 bt('import foo.*;', 'import foo.*;'); // actionscript's import917 test_fragment('function f(a: a, b: b)'); // actionscript918 bt('{\n foo // something\n ,\n bar // something\n baz\n}');919 bt('function a(a) {} function b(b) {} function c(c) {}', 'function a(a) {}\n\nfunction b(b) {}\n\nfunction c(c) {}');920 bt('foo(a, function() {})');921 bt('foo(a, /regex/)');922 bt('/* foo */\n"x"');923 opts.break_chained_methods = false;924 opts.preserve_newlines = false;925 bt('foo\n.bar()\n.baz().cucumber(fat)', 'foo.bar().baz().cucumber(fat)');926 bt('foo\n.bar()\n.baz().cucumber(fat); foo.bar().baz().cucumber(fat)', 'foo.bar().baz().cucumber(fat);\nfoo.bar().baz().cucumber(fat)');927 bt('foo\n.bar()\n.baz().cucumber(fat)\n foo.bar().baz().cucumber(fat)', 'foo.bar().baz().cucumber(fat)\nfoo.bar().baz().cucumber(fat)');928 bt('this\n.something = foo.bar()\n.baz().cucumber(fat)', 'this.something = foo.bar().baz().cucumber(fat)');929 bt('this.something.xxx = foo.moo.bar()');930 bt('this\n.something\n.xxx = foo.moo\n.bar()', 'this.something.xxx = foo.moo.bar()');931 opts.break_chained_methods = false;932 opts.preserve_newlines = true;933 bt('foo\n.bar()\n.baz().cucumber(fat)', 'foo\n .bar()\n .baz().cucumber(fat)');934 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)');935 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)');936 bt('this\n.something = foo.bar()\n.baz().cucumber(fat)', 'this\n .something = foo.bar()\n .baz().cucumber(fat)');937 bt('this.something.xxx = foo.moo.bar()');938 bt('this\n.something\n.xxx = foo.moo\n.bar()', 'this\n .something\n .xxx = foo.moo\n .bar()');939 opts.break_chained_methods = true;940 opts.preserve_newlines = false;941 bt('foo\n.bar()\n.baz().cucumber(fat)', 'foo.bar()\n .baz()\n .cucumber(fat)');942 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)');943 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)');944 bt('this\n.something = foo.bar()\n.baz().cucumber(fat)', 'this.something = foo.bar()\n .baz()\n .cucumber(fat)');945 bt('this.something.xxx = foo.moo.bar()');946 bt('this\n.something\n.xxx = foo.moo\n.bar()', 'this.something.xxx = foo.moo.bar()');947 opts.break_chained_methods = true;948 opts.preserve_newlines = true;949 bt('foo\n.bar()\n.baz().cucumber(fat)', 'foo\n .bar()\n .baz()\n .cucumber(fat)');950 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)');951 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)');952 bt('this\n.something = foo.bar()\n.baz().cucumber(fat)', 'this\n .something = foo.bar()\n .baz()\n .cucumber(fat)');953 bt('this.something.xxx = foo.moo.bar()');954 bt('this\n.something\n.xxx = foo.moo\n.bar()', 'this\n .something\n .xxx = foo.moo\n .bar()');955 opts.break_chained_methods = false;956 // Line wrap test intputs957 //.............---------1---------2---------3---------4---------5---------6---------7958 //.............1234567890123456789012345678901234567890123456789012345678901234567890959 wrap_input_1=('foo.bar().baz().cucumber((fat && "sassy") || (leans\n&& mean));\n' +960 'Test_very_long_variable_name_this_should_never_wrap\n.but_this_can\n' +961 'if (wraps_can_occur && inside_an_if_block) that_is_\n.okay();\n' +962 'object_literal = {\n' +963 ' property: first_token_should_never_wrap + but_this_can,\n' +964 ' propertz: first_token_should_never_wrap + !but_this_can,\n' +965 ' proper: "first_token_should_never_wrap" + "but_this_can"\n' +966 '}');967 //.............---------1---------2---------3---------4---------5---------6---------7968 //.............1234567890123456789012345678901234567890123456789012345678901234567890969 wrap_input_2=('{\n' +970 ' foo.bar().baz().cucumber((fat && "sassy") || (leans\n&& mean));\n' +971 ' Test_very_long_variable_name_this_should_never_wrap\n.but_this_can\n' +972 ' if (wraps_can_occur && inside_an_if_block) that_is_\n.okay();\n' +973 ' object_literal = {\n' +974 ' property: first_token_should_never_wrap + but_this_can,\n' +975 ' propertz: first_token_should_never_wrap + !but_this_can,\n' +976 ' proper: "first_token_should_never_wrap" + "but_this_can"\n' +977 ' }' +978 '}');979 opts.preserve_newlines = false;980 opts.wrap_line_length = 0;981 //.............---------1---------2---------3---------4---------5---------6---------7982 //.............1234567890123456789012345678901234567890123456789012345678901234567890983 test_fragment(wrap_input_1,984 /* expected */985 'foo.bar().baz().cucumber((fat && "sassy") || (leans && mean));\n' +986 'Test_very_long_variable_name_this_should_never_wrap.but_this_can\n' +987 'if (wraps_can_occur && inside_an_if_block) that_is_.okay();\n' +988 'object_literal = {\n' +989 ' property: first_token_should_never_wrap + but_this_can,\n' +990 ' propertz: first_token_should_never_wrap + !but_this_can,\n' +991 ' proper: "first_token_should_never_wrap" + "but_this_can"\n' +992 '}');993 opts.wrap_line_length = 70;994 //.............---------1---------2---------3---------4---------5---------6---------7995 //.............1234567890123456789012345678901234567890123456789012345678901234567890996 test_fragment(wrap_input_1,997 /* expected */998 'foo.bar().baz().cucumber((fat && "sassy") || (leans && mean));\n' +999 'Test_very_long_variable_name_this_should_never_wrap.but_this_can\n' +1000 'if (wraps_can_occur && inside_an_if_block) that_is_.okay();\n' +1001 'object_literal = {\n' +1002 ' property: first_token_should_never_wrap + but_this_can,\n' +1003 ' propertz: first_token_should_never_wrap + !but_this_can,\n' +1004 ' proper: "first_token_should_never_wrap" + "but_this_can"\n' +1005 '}');1006 opts.wrap_line_length = 40;1007 //.............---------1---------2---------3---------4---------5---------6---------71008 //.............12345678901234567890123456789012345678901234567890123456789012345678901009 test_fragment(wrap_input_1,1010 /* expected */1011 'foo.bar().baz().cucumber((fat &&\n' +1012 ' "sassy") || (leans && mean));\n' +1013 'Test_very_long_variable_name_this_should_never_wrap\n' +1014 ' .but_this_can\n' +1015 'if (wraps_can_occur &&\n' +1016 ' inside_an_if_block) that_is_.okay();\n' +1017 'object_literal = {\n' +1018 ' property: first_token_should_never_wrap +\n' +1019 ' but_this_can,\n' +1020 ' propertz: first_token_should_never_wrap +\n' +1021 ' !but_this_can,\n' +1022 ' proper: "first_token_should_never_wrap" +\n' +1023 ' "but_this_can"\n' +1024 '}');1025 opts.wrap_line_length = 41;1026 // NOTE: wrap is only best effort - line continues until next wrap point is found.1027 //.............---------1---------2---------3---------4---------5---------6---------71028 //.............12345678901234567890123456789012345678901234567890123456789012345678901029 test_fragment(wrap_input_1,1030 /* expected */1031 'foo.bar().baz().cucumber((fat && "sassy") ||\n' +1032 ' (leans && mean));\n' +1033 'Test_very_long_variable_name_this_should_never_wrap\n' +1034 ' .but_this_can\n' +1035 'if (wraps_can_occur &&\n' +1036 ' inside_an_if_block) that_is_.okay();\n' +1037 'object_literal = {\n' +1038 ' property: first_token_should_never_wrap +\n' +1039 ' but_this_can,\n' +1040 ' propertz: first_token_should_never_wrap +\n' +1041 ' !but_this_can,\n' +1042 ' proper: "first_token_should_never_wrap" +\n' +1043 ' "but_this_can"\n' +1044 '}');1045 opts.wrap_line_length = 45;1046 // NOTE: wrap is only best effort - line continues until next wrap point is found.1047 //.............---------1---------2---------3---------4---------5---------6---------71048 //.............12345678901234567890123456789012345678901234567890123456789012345678901049 test_fragment(wrap_input_2,1050 /* expected */1051 '{\n' +1052 ' foo.bar().baz().cucumber((fat && "sassy") ||\n' +1053 ' (leans && mean));\n' +1054 ' Test_very_long_variable_name_this_should_never_wrap\n' +1055 ' .but_this_can\n' +1056 ' if (wraps_can_occur &&\n' +1057 ' inside_an_if_block) that_is_.okay();\n' +1058 ' object_literal = {\n' +1059 ' property: first_token_should_never_wrap +\n' +1060 ' but_this_can,\n' +1061 ' propertz: first_token_should_never_wrap +\n' +1062 ' !but_this_can,\n' +1063 ' proper: "first_token_should_never_wrap" +\n' +1064 ' "but_this_can"\n' +1065 ' }\n'+1066 '}');1067 opts.preserve_newlines = true;1068 opts.wrap_line_length = 0;1069 //.............---------1---------2---------3---------4---------5---------6---------71070 //.............12345678901234567890123456789012345678901234567890123456789012345678901071 test_fragment(wrap_input_1,1072 /* expected */1073 'foo.bar().baz().cucumber((fat && "sassy") || (leans && mean));\n' +1074 'Test_very_long_variable_name_this_should_never_wrap\n' +1075 ' .but_this_can\n' +1076 'if (wraps_can_occur && inside_an_if_block) that_is_\n' +1077 ' .okay();\n' +1078 'object_literal = {\n' +1079 ' property: first_token_should_never_wrap + but_this_can,\n' +1080 ' propertz: first_token_should_never_wrap + !but_this_can,\n' +1081 ' proper: "first_token_should_never_wrap" + "but_this_can"\n' +1082 '}');1083 opts.wrap_line_length = 70;1084 //.............---------1---------2---------3---------4---------5---------6---------71085 //.............12345678901234567890123456789012345678901234567890123456789012345678901086 test_fragment(wrap_input_1,1087 /* expected */1088 'foo.bar().baz().cucumber((fat && "sassy") || (leans && mean));\n' +1089 'Test_very_long_variable_name_this_should_never_wrap\n' +1090 ' .but_this_can\n' +1091 'if (wraps_can_occur && inside_an_if_block) that_is_\n' +1092 ' .okay();\n' +1093 'object_literal = {\n' +1094 ' property: first_token_should_never_wrap + but_this_can,\n' +1095 ' propertz: first_token_should_never_wrap + !but_this_can,\n' +1096 ' proper: "first_token_should_never_wrap" + "but_this_can"\n' +1097 '}');1098 opts.wrap_line_length = 40;1099 //.............---------1---------2---------3---------4---------5---------6---------71100 //.............12345678901234567890123456789012345678901234567890123456789012345678901101 test_fragment(wrap_input_1,1102 /* expected */1103 'foo.bar().baz().cucumber((fat &&\n' +1104 ' "sassy") || (leans && mean));\n' +1105 'Test_very_long_variable_name_this_should_never_wrap\n' +1106 ' .but_this_can\n' +1107 'if (wraps_can_occur &&\n' +1108 ' inside_an_if_block) that_is_\n' +1109 ' .okay();\n' +1110 'object_literal = {\n' +1111 ' property: first_token_should_never_wrap +\n' +1112 ' but_this_can,\n' +1113 ' propertz: first_token_should_never_wrap +\n' +1114 ' !but_this_can,\n' +1115 ' proper: "first_token_should_never_wrap" +\n' +1116 ' "but_this_can"\n' +1117 '}');1118 opts.wrap_line_length = 41;1119 // NOTE: wrap is only best effort - line continues until next wrap point is found.1120 //.............---------1---------2---------3---------4---------5---------6---------71121 //.............12345678901234567890123456789012345678901234567890123456789012345678901122 test_fragment(wrap_input_1,1123 /* expected */1124 'foo.bar().baz().cucumber((fat && "sassy") ||\n' +1125 ' (leans && mean));\n' +1126 'Test_very_long_variable_name_this_should_never_wrap\n' +1127 ' .but_this_can\n' +1128 'if (wraps_can_occur &&\n' +1129 ' inside_an_if_block) that_is_\n' +1130 ' .okay();\n' +1131 'object_literal = {\n' +1132 ' property: first_token_should_never_wrap +\n' +1133 ' but_this_can,\n' +1134 ' propertz: first_token_should_never_wrap +\n' +1135 ' !but_this_can,\n' +1136 ' proper: "first_token_should_never_wrap" +\n' +1137 ' "but_this_can"\n' +1138 '}');1139 opts.wrap_line_length = 45;1140 // NOTE: wrap is only best effort - line continues until next wrap point is found.1141 //.............---------1---------2---------3---------4---------5---------6---------71142 //.............12345678901234567890123456789012345678901234567890123456789012345678901143 test_fragment(wrap_input_2,1144 /* expected */1145 '{\n' +1146 ' foo.bar().baz().cucumber((fat && "sassy") ||\n' +1147 ' (leans && mean));\n' +1148 ' Test_very_long_variable_name_this_should_never_wrap\n' +1149 ' .but_this_can\n' +1150 ' if (wraps_can_occur &&\n' +1151 ' inside_an_if_block) that_is_\n' +1152 ' .okay();\n' +1153 ' object_literal = {\n' +1154 ' property: first_token_should_never_wrap +\n' +1155 ' but_this_can,\n' +1156 ' propertz: first_token_should_never_wrap +\n' +1157 ' !but_this_can,\n' +1158 ' proper: "first_token_should_never_wrap" +\n' +1159 ' "but_this_can"\n' +1160 ' }\n'+1161 '}');1162 opts.wrap_line_length = 0;1163 opts.preserve_newlines = false;1164 bt('if (foo) // comment\n bar();');1165 bt('if (foo) // comment\n (bar());');1166 bt('if (foo) // comment\n (bar());');1167 bt('if (foo) // comment\n /asdf/;');1168 bt('this.oa = new OAuth(\n' +1169 ' _requestToken,\n' +1170 ' _accessToken,\n' +1171 ' consumer_key\n' +1172 ');',1173 'this.oa = new OAuth(_requestToken, _accessToken, consumer_key);');1174 bt('foo = {\n x: y, // #44\n w: z // #44\n}');1175 bt('switch (x) {\n case "a":\n // comment on newline\n break;\n case "b": // comment on same line\n break;\n}');1176 bt('this.type =\n this.options =\n // comment\n this.enabled null;',1177 'this.type = this.options =\n // comment\n this.enabled null;');1178 bt('someObj\n .someFunc1()\n // This comment should not break the indent\n .someFunc2();',1179 'someObj.someFunc1()\n // This comment should not break the indent\n .someFunc2();');1180 bt('if (true ||\n!true) return;', 'if (true || !true) return;');1181 // these aren't ready yet.1182 //bt('if (foo) // comment\n bar() /*i*/ + baz() /*j\n*/ + asdf();');1183 bt('if\n(foo)\nif\n(bar)\nif\n(baz)\nwhee();\na();',1184 'if (foo)\n if (bar)\n if (baz) whee();\na();');1185 bt('if\n(foo)\nif\n(bar)\nif\n(baz)\nwhee();\nelse\na();',1186 'if (foo)\n if (bar)\n if (baz) whee();\n else a();');1187 bt('if (foo)\nbar();\nelse\ncar();',1188 'if (foo) bar();\nelse car();');1189 bt('if (foo) if (bar) if (baz);\na();',1190 'if (foo)\n if (bar)\n if (baz);\na();');1191 bt('if (foo) if (bar) if (baz) whee();\na();',1192 'if (foo)\n if (bar)\n if (baz) whee();\na();');1193 bt('if (foo) a()\nif (bar) if (baz) whee();\na();',1194 'if (foo) a()\nif (bar)\n if (baz) whee();\na();');1195 bt('if (foo);\nif (bar) if (baz) whee();\na();',1196 'if (foo);\nif (bar)\n if (baz) whee();\na();');1197 bt('if (options)\n' +1198 ' for (var p in options)\n' +1199 ' this[p] = options[p];',1200 'if (options)\n'+1201 ' for (var p in options) this[p] = options[p];');1202 bt('if (options) for (var p in options) this[p] = options[p];',1203 'if (options)\n for (var p in options) this[p] = options[p];');1204 bt('if (options) do q(); while (b());',1205 'if (options)\n do q(); while (b());');1206 bt('if (options) while (b()) q();',1207 'if (options)\n while (b()) q();');1208 bt('if (options) do while (b()) q(); while (a());',1209 'if (options)\n do\n while (b()) q(); while (a());');1210 bt('function f(a, b, c,\nd, e) {}',1211 'function f(a, b, c, d, e) {}');1212 bt('function f(a,b) {if(a) b()}function g(a,b) {if(!a) b()}',1213 'function f(a, b) {\n if (a) b()\n}\n\nfunction g(a, b) {\n if (!a) b()\n}');1214 bt('function f(a,b) {if(a) b()}\n\n\n\nfunction g(a,b) {if(!a) b()}',1215 'function f(a, b) {\n if (a) b()\n}\n\nfunction g(a, b) {\n if (!a) b()\n}');1216 // This is not valid syntax, but still want to behave reasonably and not side-effect1217 bt('(if(a) b())(if(a) b())',1218 '(\n if (a) b())(\n if (a) b())');1219 bt('(if(a) b())\n\n\n(if(a) b())',1220 '(\n if (a) b())\n(\n if (a) b())');1221 bt("if\n(a)\nb();", "if (a) b();");1222 bt('var a =\nfoo', 'var a = foo');1223 bt('var a = {\n"a":1,\n"b":2}', "var a = {\n \"a\": 1,\n \"b\": 2\n}");1224 bt("var a = {\n'a':1,\n'b':2}", "var a = {\n 'a': 1,\n 'b': 2\n}");1225 bt('var a = /*i*/ "b";');1226 bt('var a = /*i*/\n"b";', 'var a = /*i*/ "b";');1227 bt('var a = /*i*/\nb;', 'var a = /*i*/ b;');1228 bt('{\n\n\n"x"\n}', '{\n "x"\n}');1229 bt('if(a &&\nb\n||\nc\n||d\n&&\ne) e = f', 'if (a && b || c || d && e) e = f');1230 bt('if(a &&\n(b\n||\nc\n||d)\n&&\ne) e = f', 'if (a && (b || c || d) && e) e = f');1231 test_fragment('\n\n"x"', '"x"');1232 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;',1233 'a = 1;\nb = 2;');1234 opts.preserve_newlines = true;1235 bt('if (foo) // comment\n bar();');1236 bt('if (foo) // comment\n (bar());');1237 bt('if (foo) // comment\n (bar());');1238 bt('if (foo) // comment\n /asdf/;');1239 bt('foo = {\n x: y, // #44\n w: z // #44\n}');1240 bt('switch (x) {\n case "a":\n // comment on newline\n break;\n case "b": // comment on same line\n break;\n}');1241 bt('this.type =\n this.options =\n // comment\n this.enabled null;');1242 bt('someObj\n .someFunc1()\n // This comment should not break the indent\n .someFunc2();');1243 bt('if (true ||\n!true) return;', 'if (true ||\n !true) return;');1244 // these aren't ready yet.1245 // bt('if (foo) // comment\n bar() /*i*/ + baz() /*j\n*/ + asdf();');1246 bt('if\n(foo)\nif\n(bar)\nif\n(baz)\nwhee();\na();',1247 'if (foo)\n if (bar)\n if (baz)\n whee();\na();');1248 bt('if\n(foo)\nif\n(bar)\nif\n(baz)\nwhee();\nelse\na();',1249 'if (foo)\n if (bar)\n if (baz)\n whee();\n else\n a();');1250 bt('if (foo) bar();\nelse\ncar();',1251 'if (foo) bar();\nelse\n car();');1252 bt('if (foo) if (bar) if (baz);\na();',1253 'if (foo)\n if (bar)\n if (baz);\na();');1254 bt('if (foo) if (bar) if (baz) whee();\na();',1255 'if (foo)\n if (bar)\n if (baz) whee();\na();');1256 bt('if (foo) a()\nif (bar) if (baz) whee();\na();',1257 'if (foo) a()\nif (bar)\n if (baz) whee();\na();');1258 bt('if (foo);\nif (bar) if (baz) whee();\na();',1259 'if (foo);\nif (bar)\n if (baz) whee();\na();');1260 bt('if (options)\n' +1261 ' for (var p in options)\n' +1262 ' this[p] = options[p];');1263 bt('if (options) for (var p in options) this[p] = options[p];',1264 'if (options)\n for (var p in options) this[p] = options[p];');1265 bt('if (options) do q(); while (b());',1266 'if (options)\n do q(); while (b());');1267 bt('if (options) do; while (b());',1268 'if (options)\n do; while (b());');1269 bt('if (options) while (b()) q();',1270 'if (options)\n while (b()) q();');1271 bt('if (options) do while (b()) q(); while (a());',1272 'if (options)\n do\n while (b()) q(); while (a());');1273 bt('function f(a, b, c,\nd, e) {}',1274 'function f(a, b, c,\n d, e) {}');1275 bt('function f(a,b) {if(a) b()}function g(a,b) {if(!a) b()}',1276 'function f(a, b) {\n if (a) b()\n}\n\nfunction g(a, b) {\n if (!a) b()\n}');1277 bt('function f(a,b) {if(a) b()}\n\n\n\nfunction g(a,b) {if(!a) b()}',1278 'function f(a, b) {\n if (a) b()\n}\n\n\n\nfunction g(a, b) {\n if (!a) b()\n}');1279 // This is not valid syntax, but still want to behave reasonably and not side-effect1280 bt('(if(a) b())(if(a) b())',1281 '(\n if (a) b())(\n if (a) b())');1282 bt('(if(a) b())\n\n\n(if(a) b())',1283 '(\n if (a) b())\n\n\n(\n if (a) b())');1284 // space between functions1285 bt('/*\n * foo\n */\nfunction foo() {}');1286 bt('// a nice function\nfunction foo() {}');1287 bt('function foo() {}\nfunction foo() {}',1288 'function foo() {}\n\nfunction foo() {}'1289 );1290 bt("if\n(a)\nb();", "if (a)\n b();");1291 bt('var a =\nfoo', 'var a =\n foo');1292 bt('var a = {\n"a":1,\n"b":2}', "var a = {\n \"a\": 1,\n \"b\": 2\n}");1293 bt("var a = {\n'a':1,\n'b':2}", "var a = {\n 'a': 1,\n 'b': 2\n}");1294 bt('var a = /*i*/ "b";');1295 bt('var a = /*i*/\n"b";', 'var a = /*i*/\n "b";');1296 bt('var a = /*i*/\nb;', 'var a = /*i*/\n b;');1297 bt('{\n\n\n"x"\n}', '{\n\n\n "x"\n}');1298 bt('if(a &&\nb\n||\nc\n||d\n&&\ne) e = f', 'if (a &&\n b ||\n c || d &&\n e) e = f');1299 bt('if(a &&\n(b\n||\nc\n||d)\n&&\ne) e = f', 'if (a &&\n (b ||\n c || d) &&\n e) e = f');1300 test_fragment('\n\n"x"', '"x"');1301 // this beavior differs between js and python, defaults to unlimited in js, 10 in python1302 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;',1303 '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;');1304 opts.max_preserve_newlines = 8;1305 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;',1306 'a = 1;\n\n\n\n\n\n\n\nb = 2;');1307 // Test the option to have spaces within parens1308 opts.space_in_paren = false;1309 bt('if(p) foo(a,b)', 'if (p) foo(a, b)');1310 bt('try{while(true){willThrow()}}catch(result)switch(result){case 1:++result }',1311 'try {\n while (true) {\n willThrow()\n }\n} catch (result) switch (result) {\n case 1:\n ++result\n}');1312 bt('((e/((a+(b)*c)-d))^2)*5;', '((e / ((a + (b) * c) - d)) ^ 2) * 5;');1313 bt('function f(a,b) {if(a) b()}function g(a,b) {if(!a) b()}',1314 'function f(a, b) {\n if (a) b()\n}\n\nfunction g(a, b) {\n if (!a) b()\n}');1315 bt('a=[];',1316 'a = [];');1317 bt('a=[b,c,d];',1318 'a = [b, c, d];');1319 bt('a= f[b];',1320 'a = f[b];');1321 opts.space_in_paren = true;1322 bt('if(p) foo(a,b)', 'if ( p ) foo( a, b )');1323 bt('try{while(true){willThrow()}}catch(result)switch(result){case 1:++result }',1324 'try {\n while ( true ) {\n willThrow()\n }\n} catch ( result ) switch ( result ) {\n case 1:\n ++result\n}');1325 bt('((e/((a+(b)*c)-d))^2)*5;', '( ( e / ( ( a + ( b ) * c ) - d ) ) ^ 2 ) * 5;');1326 bt('function f(a,b) {if(a) b()}function g(a,b) {if(!a) b()}',1327 'function f( a, b ) {\n if ( a ) b()\n}\n\nfunction g( a, b ) {\n if ( !a ) b()\n}');1328 bt('a=[];',1329 'a = [];');1330 bt('a=[b,c,d];',1331 'a = [ b, c, d ];');1332 bt('a= f[b];',1333 'a = f[ b ];');1334 opts.space_in_empty_paren = true;1335 bt('if(p) foo(a,b)', 'if ( p ) foo( a, b )');1336 bt('try{while(true){willThrow()}}catch(result)switch(result){case 1:++result }',1337 'try {\n while ( true ) {\n willThrow( )\n }\n} catch ( result ) switch ( result ) {\n case 1:\n ++result\n}');1338 bt('((e/((a+(b)*c)-d))^2)*5;', '( ( e / ( ( a + ( b ) * c ) - d ) ) ^ 2 ) * 5;');1339 bt('function f(a,b) {if(a) b()}function g(a,b) {if(!a) b()}',1340 'function f( a, b ) {\n if ( a ) b( )\n}\n\nfunction g( a, b ) {\n if ( !a ) b( )\n}');1341 bt('a=[];',1342 'a = [ ];');1343 bt('a=[b,c,d];',1344 'a = [ b, c, d ];');1345 bt('a= f[b];',1346 'a = f[ b ];');1347 opts.space_in_empty_paren = false;1348 opts.space_in_paren = false;1349 // Test template strings1350 bt('`This is a ${template} string.`', '`This is a ${template} string.`');1351 bt('`This\n is\n a\n ${template}\n string.`', '`This\n is\n a\n ${template}\n string.`');1352 // Test that e4x literals passed through when e4x-option is enabled1353 bt('xml=<a b="c"><d/><e>\n foo</e>x</a>;', 'xml = < a b = "c" > < d / > < e >\n foo < /e>x</a > ;');1354 opts.e4x = true;1355 bt('xml=<a b="c"><d/><e>\n foo</e>x</a>;', 'xml = <a b="c"><d/><e>\n foo</e>x</a>;');1356 bt('<a b=\'This is a quoted "c".\'/>', '<a b=\'This is a quoted "c".\'/>');1357 bt('<a b="This is a quoted \'c\'."/>', '<a b="This is a quoted \'c\'."/>');1358 bt('<a b="A quote \' inside string."/>', '<a b="A quote \' inside string."/>');1359 bt('<a b=\'A quote " inside string.\'/>', '<a b=\'A quote " inside string.\'/>');1360 bt('<a b=\'Some """ quotes "" inside string.\'/>', '<a b=\'Some """ quotes "" inside string.\'/>');1361 // Handles inline expressions1362 bt('xml=<{a} b="c"><d/><e v={z}>\n foo</e>x</{a}>;', 'xml = <{a} b="c"><d/><e v={z}>\n foo</e>x</{a}>;');1363 // xml literals with special characters in elem names1364 // see http://www.w3.org/TR/REC-xml/#NT-NameChar1365 bt('xml = <_:.valid.xml- _:.valid.xml-="123"/>;', 'xml = <_:.valid.xml- _:.valid.xml-="123"/>;');1366 // Handles CDATA1367 bt('xml=<![CDATA[ b="c"><d/><e v={z}>\n foo</e>x/]]>;', 'xml = <![CDATA[ b="c"><d/><e v={z}>\n foo</e>x/]]>;');1368 bt('xml=<![CDATA[]]>;', 'xml = <![CDATA[]]>;');1369 bt('xml=<a b="c"><![CDATA[d/></a></{}]]></a>;', 'xml = <a b="c"><![CDATA[d/></a></{}]]></a>;');1370 // Handles messed up tags, as long as it isn't the same name1371 // as the root tag. Also handles tags of same name as root tag1372 // as long as nesting matches.1373 bt('xml=<a x="jn"><c></b></f><a><d jnj="jnn"><f></a ></nj></a>;',1374 'xml = <a x="jn"><c></b></f><a><d jnj="jnn"><f></a ></nj></a>;');1375 // If xml is not terminated, the remainder of the file is treated1376 // as part of the xml-literal (passed through unaltered)1377 test_fragment('xml=<a></b>\nc<b;', 'xml = <a></b>\nc<b;');1378 opts.e4x = false;1379 // START tests for issue 2411380 bt('obj\n' +1381 ' .last({\n' +1382 ' foo: 1,\n' +1383 ' bar: 2\n' +1384 ' });\n' +1385 'var test = 1;');1386 bt('obj\n' +1387 ' .last(a, function() {\n' +1388 ' var test;\n' +1389 ' });\n' +1390 'var test = 1;');1391 bt('obj.first()\n' +1392 ' .second()\n' +1393 ' .last(function(err, response) {\n' +1394 ' console.log(err);\n' +1395 ' });');1396 // END tests for issue 2411397 // START tests for issue 268 and 2751398 bt('obj.last(a, function() {\n' +1399 ' var test;\n' +1400 '});\n' +1401 'var test = 1;');1402 bt('obj.last(a,\n' +1403 ' function() {\n' +1404 ' var test;\n' +1405 ' });\n' +1406 'var test = 1;');1407 bt('(function() {if (!window.FOO) window.FOO || (window.FOO = function() {var b = {bar: "zort"};});})();',1408 '(function() {\n' +1409 ' if (!window.FOO) window.FOO || (window.FOO = function() {\n' +1410 ' var b = {\n' +1411 ' bar: "zort"\n' +1412 ' };\n' +1413 ' });\n' +1414 '})();');1415 // END tests for issue 268 and 2751416 // START tests for issue 2811417 bt('define(["dojo/_base/declare", "my/Employee", "dijit/form/Button",\n' +1418 ' "dojo/_base/lang", "dojo/Deferred"\n' +1419 '], function(declare, Employee, Button, lang, Deferred) {\n' +1420 ' return declare(Employee, {\n' +1421 ' constructor: function() {\n' +1422 ' new Button({\n' +1423 ' onClick: lang.hitch(this, function() {\n' +1424 ' new Deferred().then(lang.hitch(this, function() {\n' +1425 ' this.salary * 0.25;\n' +1426 ' }));\n' +1427 ' })\n' +1428 ' });\n' +1429 ' }\n' +1430 ' });\n' +1431 '});');1432 bt('define(["dojo/_base/declare", "my/Employee", "dijit/form/Button",\n' +1433 ' "dojo/_base/lang", "dojo/Deferred"\n' +1434 ' ],\n' +1435 ' function(declare, Employee, Button, lang, Deferred) {\n' +1436 ' return declare(Employee, {\n' +1437 ' constructor: function() {\n' +1438 ' new Button({\n' +1439 ' onClick: lang.hitch(this, function() {\n' +1440 ' new Deferred().then(lang.hitch(this, function() {\n' +1441 ' this.salary * 0.25;\n' +1442 ' }));\n' +1443 ' })\n' +1444 ' });\n' +1445 ' }\n' +1446 ' });\n' +1447 ' });');1448 // END tests for issue 2811449 // START tests for issue 4591450 bt( '(function() {\n' +1451 ' return {\n' +1452 ' foo: function() {\n' +1453 ' return "bar";\n' +1454 ' },\n' +1455 ' bar: ["bar"]\n' +1456 ' };\n' +1457 '}());');1458 // END tests for issue 4591459 bt('var a=1,b={bang:2},c=3;',1460 'var a = 1,\n b = {\n bang: 2\n },\n c = 3;');1461 bt('var a={bing:1},b=2,c=3;',1462 'var a = {\n bing: 1\n },\n b = 2,\n c = 3;');1463 Urlencoded.run_tests(sanitytest);1464 bth('');1465 bth('<div></div>');1466 bth('<div>content</div>');1467 bth('<div><div></div></div>',1468 '<div>\n' +1469 ' <div></div>\n' +1470 '</div>');1471 bth('<div><div>content</div></div>',1472 '<div>\n' +1473 ' <div>content</div>\n' +1474 '</div>');1475 bth('<div>\n' +1476 ' <span>content</span>\n' +1477 '</div>');1478 bth('<div>\n' +1479 '</div>');1480 bth('<div>\n' +1481 ' content\n' +1482 '</div>');1483 bth('<div>\n' +1484 ' </div>',1485 '<div>\n' +1486 '</div>');1487 bth(' <div>\n' +1488 ' </div>',1489 '<div>\n' +1490 '</div>');1491 bth(' <div>\n' +1492 '</div>',1493 '<div>\n' +1494 '</div>');1495 bth('<div >content</div>',1496 '<div>content</div>');1497 bth('<div thinger="preserve space here" ></div >',1498 '<div thinger="preserve space here"></div>');1499 bth('content\n' +1500 ' <div>\n' +1501 ' </div>\n' +1502 'content',1503 'content\n' +1504 '<div>\n' +1505 '</div>\n' +1506 'content');1507 bth('<li>\n' +1508 ' <div>\n' +1509 ' </div>\n' +1510 '</li>');1511 bth('<li>\n' +1512 '<div>\n' +1513 '</div>\n' +1514 '</li>',1515 '<li>\n' +1516 ' <div>\n' +1517 ' </div>\n' +1518 '</li>');1519 bth('<li>\n' +1520 ' content\n' +1521 '</li>\n' +1522 '<li>\n' +1523 ' content\n' +1524 '</li>');1525 1526 // START tests for issue 4531527 bth('<script type="text/unknown"><div></div></script>',1528 '<script type="text/unknown">\n' +1529 ' <div></div>\n' +1530 '</script>');1531 bth('<script type="text/javascript"><div></div></script>',1532 '<script type="text/javascript">\n' +1533 ' < div > < /div>\n' +1534 '</script>');1535 bth('<script><div></div></script>',1536 '<script>\n' +1537 ' < div > < /div>\n' +1538 '</script>');1539 bth('<script type="text/javascript">var foo = "bar";</script>',1540 '<script type="text/javascript">\n' +1541 ' var foo = "bar";\n' +1542 '</script>'); 1543 bth('<script type="application/javascript">var foo = "bar";</script>',1544 '<script type="application/javascript">\n' +1545 ' var foo = "bar";\n' +1546 '</script>');1547 bth('<script type="application/javascript;version=1.8">var foo = "bar";</script>',1548 '<script type="application/javascript;version=1.8">\n' +1549 ' var foo = "bar";\n' +1550 '</script>');1551 bth('<script type="application/x-javascript">var foo = "bar";</script>',1552 '<script type="application/x-javascript">\n' +1553 ' var foo = "bar";\n' +1554 '</script>');1555 bth('<script type="application/ecmascript">var foo = "bar";</script>',1556 '<script type="application/ecmascript">\n' +1557 ' var foo = "bar";\n' +1558 '</script>');1559 bth('<script type="text/javascript1.5">var foo = "bar";</script>',1560 '<script type="text/javascript1.5">\n' +1561 ' var foo = "bar";\n' +1562 '</script>');1563 bth('<script>var foo = "bar";</script>',1564 '<script>\n' +1565 ' var foo = "bar";\n' +1566 '</script>'); 1567 1568 bth('<style type="text/unknown"><tag></tag></style>',1569 '<style type="text/unknown">\n' +1570 ' <tag></tag>\n' +1571 '</style>'); 1572 bth('<style type="text/css"><tag></tag></style>',1573 '<style type="text/css">\n' +1574 ' <tag></tag>\n' +1575 '</style>'); 1576 bth('<style><tag></tag></style>',1577 '<style>\n' +1578 ' <tag></tag>\n' +1579 '</style>'); 1580 bth('<style type="text/css">.selector {font-size:12px;}</style>',1581 '<style type="text/css">\n' +1582 ' .selector {\n' +1583 ' font-size: 12px;\n' +1584 ' }\n'+1585 '</style>');1586 bth('<style>.selector {font-size:12px;}</style>',1587 '<style>\n' +1588 ' .selector {\n' +1589 ' font-size: 12px;\n' +1590 ' }\n'+1591 '</style>'); 1592 // END tests for issue 4531593 1594 // Tests that don't pass, but probably should.1595 // bth('<div><span>content</span></div>');1596 // Handlebars tests1597 // Without the indent option on, handlebars are treated as content.1598 opts.indent_handlebars = false;1599 bth('{{#if 0}}\n' +1600 ' <div>\n' +1601 ' </div>\n' +1602 '{{/if}}',1603 '{{#if 0}}\n' +1604 '<div>\n' +1605 '</div>\n' +1606 '{{/if}}');1607 bth('<div>\n' +1608 '{{#each thing}}\n' +1609 ' {{name}}\n' +1610 '{{/each}}\n' +1611 '</div>',1612 '<div>\n' +1613 ' {{#each thing}} {{name}} {{/each}}\n' +1614 '</div>');1615 opts.indent_handlebars = true;1616 bth('{{#if 0}}{{/if}}');1617 bth('{{#if 0}}content{{/if}}');1618 bth('{{#if 0}}\n' +1619 '{{/if}}');1620 bth('{{#if words}}{{/if}}',1621 '{{#if words}}{{/if}}');1622 bth('{{#if words}}content{{/if}}',1623 '{{#if words}}content{{/if}}');1624 bth('{{#if words}}content{{/if}}',1625 '{{#if words}}content{{/if}}');1626 bth('{{#if 1}}\n' +1627 ' <div>\n' +1628 ' </div>\n' +1629 '{{/if}}');1630 bth('{{#if 1}}\n' +1631 '<div>\n' +1632 '</div>\n' +1633 '{{/if}}',1634 '{{#if 1}}\n' +1635 ' <div>\n' +1636 ' </div>\n' +1637 '{{/if}}');1638 bth('<div>\n' +1639 ' {{#if 1}}\n' +1640 ' {{/if}}\n' +1641 '</div>');1642 bth('<div>\n' +1643 '{{#if 1}}\n' +1644 '{{/if}}\n' +1645 '</div>',1646 '<div>\n' +1647 ' {{#if 1}}\n' +1648 ' {{/if}}\n' +1649 '</div>');1650 bth('{{#if}}\n' +1651 '{{#each}}\n' +1652 '{{#if}}\n' +1653 'content\n' +1654 '{{/if}}\n' +1655 '{{#if}}\n' +1656 'content\n' +1657 '{{/if}}\n' +1658 '{{/each}}\n' +1659 '{{/if}}',1660 '{{#if}}\n' +1661 ' {{#each}}\n' +1662 ' {{#if}}\n' +1663 ' content\n' +1664 ' {{/if}}\n' +1665 ' {{#if}}\n' +1666 ' content\n' +1667 ' {{/if}}\n' +1668 ' {{/each}}\n' +1669 '{{/if}}');1670 bth('{{#if 1}}\n' +1671 ' <div>\n' +1672 ' </div>\n' +1673 '{{/if}}');1674 // Test {{else}} aligned with {{#if}} and {{/if}}1675 bth('{{#if 1}}\n' +1676 ' content\n' +1677 ' {{else}}\n' +1678 ' content\n' +1679 '{{/if}}',1680 '{{#if 1}}\n' +1681 ' content\n' +1682 '{{else}}\n' +1683 ' content\n' +1684 '{{/if}}');1685 bth('{{#if 1}}\n' +1686 ' {{else}}\n' +1687 ' {{/if}}',1688 '{{#if 1}}\n' +1689 '{{else}}\n' +1690 '{{/if}}');1691 bth('{{#if thing}}\n' +1692 '{{#if otherthing}}\n' +1693 ' content\n' +1694 ' {{else}}\n' +1695 'content\n' +1696 ' {{/if}}\n' +1697 ' {{else}}\n'+1698 'content\n' +1699 '{{/if}}',1700 '{{#if thing}}\n' +1701 ' {{#if otherthing}}\n' +1702 ' content\n' +1703 ' {{else}}\n' +1704 ' content\n' +1705 ' {{/if}}\n' +1706 '{{else}}\n'+1707 ' content\n' +1708 '{{/if}}');1709 // Test {{}} inside of <> tags, which should be separated by spaces1710 // for readability, unless they are inside a string.1711 bth('<div{{somestyle}}></div>',1712 '<div {{somestyle}}></div>');1713 bth('<div{{#if test}}class="foo"{{/if}}>content</div>',1714 '<div {{#if test}} class="foo" {{/if}}>content</div>');1715 bth('<div{{#if thing}}{{somestyle}}class="{{class}}"{{else}}class="{{class2}}"{{/if}}>content</div>',1716 '<div {{#if thing}} {{somestyle}} class="{{class}}" {{else}} class="{{class2}}" {{/if}}>content</div>');1717 bth('<span{{#if condition}}class="foo"{{/if}}>content</span>',1718 '<span {{#if condition}} class="foo" {{/if}}>content</span>');1719 bth('<div unformatted="{{#if}}content{{/if}}">content</div>');1720 bth('<div unformatted="{{#if }} content{{/if}}">content</div>');1721 // Quotes found inside of Handlebars expressions inside of quoted1722 // strings themselves should not be considered string delimiters.1723 bth('<div class="{{#if thingIs "value"}}content{{/if}}"></div>');1724 bth('<div class="{{#if thingIs \'value\'}}content{{/if}}"></div>');1725 bth('<div class=\'{{#if thingIs "value"}}content{{/if}}\'></div>');1726 bth('<div class=\'{{#if thingIs \'value\'}}content{{/if}}\'></div>');1727 opts.wrap_line_length = 0;1728 //...---------1---------2---------3---------4---------5---------6---------71729 //...12345678901234567890123456789012345678901234567890123456789012345678901730 bth('<div>Some text that should not wrap at all.</div>',1731 /* expected */1732 '<div>Some text that should not wrap at all.</div>');1733 // A value of 0 means no max line length, and should not wrap.1734 //...---------1---------2---------3---------4---------5---------6---------7---------8---------9--------10--------11--------12--------13--------14--------15--------16--------17--------18--------19--------20--------21--------22--------23--------24--------25--------26--------27--------28--------291735 //...123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901736 bth('<div>Some text that should not wrap at all. Some text that should not wrap at all. Some text that should not wrap at all. Some text that should not wrap at all. Some text that should not wrap at all. Some text that should not wrap at all. Some text that should not wrap at all.</div>',1737 /* expected */1738 '<div>Some text that should not wrap at all. Some text that should not wrap at all. Some text that should not wrap at all. Some text that should not wrap at all. Some text that should not wrap at all. Some text that should not wrap at all. Some text that should not wrap at all.</div>');1739 opts.wrap_line_length = "0";1740 //...---------1---------2---------3---------4---------5---------6---------71741 //...12345678901234567890123456789012345678901234567890123456789012345678901742 bth('<div>Some text that should not wrap at all.</div>',1743 /* expected */1744 '<div>Some text that should not wrap at all.</div>');1745 // A value of "0" means no max line length, and should not wrap1746 //...---------1---------2---------3---------4---------5---------6---------7---------8---------9--------10--------11--------12--------13--------14--------15--------16--------17--------18--------19--------20--------21--------22--------23--------24--------25--------26--------27--------28--------291747 //...123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901748 bth('<div>Some text that should not wrap at all. Some text that should not wrap at all. Some text that should not wrap at all. Some text that should not wrap at all. Some text that should not wrap at all. Some text that should not wrap at all. Some text that should not wrap at all.</div>',1749 /* expected */1750 '<div>Some text that should not wrap at all. Some text that should not wrap at all. Some text that should not wrap at all. Some text that should not wrap at all. Some text that should not wrap at all. Some text that should not wrap at all. Some text that should not wrap at all.</div>');1751 //BUGBUG: This should wrap before 40 not after.1752 opts.wrap_line_length = 40;1753 //...---------1---------2---------3---------4---------5---------6---------71754 //...12345678901234567890123456789012345678901234567890123456789012345678901755 bth('<div>Some test text that should wrap_inside_this section here.</div>',1756 /* expected */1757 '<div>Some test text that should wrap_inside_this\n' +1758 ' section here.</div>');1759 opts.wrap_line_length = "40";1760 //...---------1---------2---------3---------4---------5---------6---------71761 //...12345678901234567890123456789012345678901234567890123456789012345678901762 bth('<div>Some test text that should wrap_inside_this section here.</div>',1763 /* expected */1764 '<div>Some test text that should wrap_inside_this\n' +1765 ' section here.</div>');1766 opts.indent_size = 1;1767 opts.indent_char = '\t';1768 opts.preserve_newlines = false;1769 bth('<div>\n\tfoo\n</div>', '<div>foo</div>');1770 opts.preserve_newlines = true;1771 bth('<div>\n\tfoo\n</div>');1772 // test preserve_newlines and max_preserve_newlines1773 opts.preserve_newlines = false;1774 test_fragment('<div>Should not</div>\n\n\n' +1775 '<div>preserve newlines</div>',1776 '<div>Should not</div>\n' +1777 '<div>preserve newlines</div>');1778 opts.preserve_newlines = true;1779 opts.max_preserve_newlines = 0;1780 test_fragment('<div>Should</div>\n\n\n' +1781 '<div>preserve zero newlines</div>',1782 '<div>Should</div>\n' +1783 '<div>preserve zero newlines</div>');1784 opts.max_preserve_newlines = 1;1785 test_fragment('<div>Should</div>\n\n\n' +1786 '<div>preserve one newline</div>',1787 '<div>Should</div>\n\n' +1788 '<div>preserve one newline</div>');1789 opts.max_preserve_newlines = null;1790 test_fragment('<div>Should</div>\n\n\n' +1791 '<div>preserve one newline</div>',1792 '<div>Should</div>\n\n\n' +1793 '<div>preserve one newline</div>');1794 // css beautifier1795 opts.indent_size = 1;1796 opts.indent_char = '\t';1797 opts.selector_separator_newline = true;1798 opts.end_with_newline = true;1799 // test basic css beautifier1800 btc('', '\n');1801 btc(".tabs{}", ".tabs {}\n");1802 btc(".tabs{color:red;}", ".tabs {\n\tcolor: red;\n}\n");1803 btc(".tabs{color:rgb(255, 255, 0)}", ".tabs {\n\tcolor: rgb(255, 255, 0)\n}\n");1804 btc(".tabs{background:url('back.jpg')}", ".tabs {\n\tbackground: url('back.jpg')\n}\n");...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1var wptdriver = require("wptdriver");2 if (err) {3 console.log(err);4 } else {5 console.log(data);6 }7});8var wptdriver = require("wptdriver");9 if (err) {10 console.log(err);11 } else {12 console.log(data);13 }14});15var wptdriver = require("wptdriver");16 if (err) {17 console.log(err);18 } else {19 console.log(data);20 }21});22var wptdriver = require("wptdriver");23 if (err) {24 console.log(err);25 } else {26 console.log(data);27 }28});29var wptdriver = require("wptdriver");30 if (err) {31 console.log(err);32 } else {33 console.log(data);34 }35});36var wptdriver = require("wptdriver");37 if (err) {38 console.log(err);39 } else {40 console.log(data);41 }42});43var wptdriver = require("wptdriver");44 if (err) {45 console.log(err);46 } else {47 console.log(data);48 }49});

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require("./wpt.js");2wpt.test_fragment(url, function(data) {3 console.log(data);4});5var request = require('request');6exports.test_fragment = function(url, callback) {7 var options = {8 headers: {9 }10 };11 function callback(error, response, body) {12 if (!error && response.statusCode == 200) {13 var info = JSON.parse(body);14 callback(info);15 }16 }17 request(options, callback);18};

Full Screen

Using AI Code Generation

copy

Full Screen

1 console.log(data);2});3 console.log(data);4});5 console.log(data);6});

Full Screen

Using AI Code Generation

copy

Full Screen

1function test_fragment(doc, win, test) {2 test_fragment(doc, win, test);3}4function test_fragment(doc, win, test) {5 fragment(doc, win, test);6}7function fragment(doc, win, test) {8 fragment(doc, win, test);9}10function fragment(doc, win, test) {11 fragment(doc, win, test);12}13function fragment(doc, win, test) {14 fragment(doc, win, test);15}16function fragment(doc, win, test) {17 fragment(doc, win, test);18}19function fragment(doc, win, test) {20 fragment(doc, win, test);21}22function fragment(doc, win, test) {

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run wpt automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful