| 1 |
#!/usr/bin/env python |
| 2 |
# -*- coding: utf-8 -*- |
| 3 |
|
| 4 |
''' |
| 5 |
AUTO-GENERATED. DO NOT MODIFY. |
| 6 |
Script: test/generate-tests.js |
| 7 |
Template: test/data/javascript/python.mustache |
| 8 |
Data: test/data/javascript/tests.js |
| 9 |
|
| 10 |
The MIT License (MIT) |
| 11 |
|
| 12 |
Copyright (c) 2007-2018 Einar Lielmanis, Liam Newman, and contributors. |
| 13 |
|
| 14 |
Permission is hereby granted, free of charge, to any person |
| 15 |
obtaining a copy of this software and associated documentation files |
| 16 |
(the "Software"), to deal in the Software without restriction, |
| 17 |
including without limitation the rights to use, copy, modify, merge, |
| 18 |
publish, distribute, sublicense, and/or sell copies of the Software, |
| 19 |
and to permit persons to whom the Software is furnished to do so, |
| 20 |
subject to the following conditions: |
| 21 |
|
| 22 |
The above copyright notice and this permission notice shall be |
| 23 |
included in all copies or substantial portions of the Software. |
| 24 |
|
| 25 |
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
| 26 |
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
| 27 |
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
| 28 |
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS |
| 29 |
BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN |
| 30 |
ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN |
| 31 |
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| 32 |
SOFTWARE. |
| 33 |
''' |
| 34 |
|
| 35 |
import re |
| 36 |
import unittest |
| 37 |
import jsbeautifier |
| 38 |
import copy |
| 39 |
|
| 40 |
class TestJSBeautifier(unittest.TestCase): |
| 41 |
options = None |
| 42 |
|
| 43 |
@classmethod |
| 44 |
def setUpClass(cls): |
| 45 |
pass |
| 46 |
cls.wrapregex = re.compile('^(.+)$', re.MULTILINE) |
| 47 |
|
| 48 |
def reset_options(self): |
| 49 |
true = True |
| 50 |
false = False |
| 51 |
|
| 52 |
default_options = jsbeautifier.default_options() |
| 53 |
default_options.indent_size = 4 |
| 54 |
default_options.indent_char = ' ' |
| 55 |
default_options.preserve_newlines = true |
| 56 |
default_options.jslint_happy = false |
| 57 |
default_options.indent_level = 0 |
| 58 |
default_options.break_chained_methods = false |
| 59 |
default_options.eol = '\n' |
| 60 |
|
| 61 |
default_options.indent_size = 4 |
| 62 |
default_options.indent_char = ' ' |
| 63 |
default_options.preserve_newlines = true |
| 64 |
default_options.jslint_happy = false |
| 65 |
|
| 66 |
self.options = copy.copy(default_options) |
| 67 |
|
| 68 |
def test_unescape(self): |
| 69 |
# Test cases contributed by <chrisjshull on GitHub.com> |
| 70 |
test_fragment = self.decodesto |
| 71 |
self.reset_options() |
| 72 |
bt = self.bt |
| 73 |
|
| 74 |
def unicode_char(value): |
| 75 |
return chr(value) |
| 76 |
|
| 77 |
bt('"\\\\s"') # == "\\s" in the js source |
| 78 |
bt("'\\\\s'") # == '\\s' in the js source |
| 79 |
bt("'\\\\\\s'") # == '\\\s' in the js source |
| 80 |
bt("'\\s'") # == '\s' in the js source |
| 81 |
bt('"•"') |
| 82 |
bt('"—"') |
| 83 |
bt('"\\x41\\x42\\x43\\x01"', '"\\x41\\x42\\x43\\x01"') |
| 84 |
bt('"\\u2022"', '"\\u2022"') |
| 85 |
bt('"\\u{2022}"', '"\\u{2022}"') |
| 86 |
bt('a = /\\s+/') |
| 87 |
#bt('a = /\\x41/','a = /A/') |
| 88 |
bt('"\\u2022";a = /\\s+/;"\\x41\\x42\\x43\\x01".match(/\\x41/);','"\\u2022";\na = /\\s+/;\n"\\x41\\x42\\x43\\x01".match(/\\x41/);') |
| 89 |
|
| 90 |
test_fragment('"\\x41\\x42\\x01\\x43"') |
| 91 |
test_fragment('"\\x41\\x42\\u0001\\x43"') |
| 92 |
test_fragment('"\\x41\\x42\\u{0001}\\x43"') |
| 93 |
test_fragment('"\\x20\\x40\\x4a"') |
| 94 |
test_fragment('"\\xff\\x40\\x4a"') |
| 95 |
test_fragment('"\\u0072\\u016B\\u0137\\u012B\\u0074\\u0069\\u0073"') |
| 96 |
test_fragment('"\\u{0072}\\u{016B}\\u{110000}\\u{137}\\u012B\\x74\\u{0000069}\\u{073}"') |
| 97 |
test_fragment('"Google Chrome est\\u00E1 actualizado."') |
| 98 |
test_fragment( |
| 99 |
'"\\x22\\x27",\'\\x22\\x27\',"\\x5c",\'\\x5c\',"\\xff and \\xzz","unicode \\u0000 \\u0022 \\u0027 \\u005c \\uffff \\uzzzz"', |
| 100 |
'"\\x22\\x27", \'\\x22\\x27\', "\\x5c", \'\\x5c\', "\\xff and \\xzz", "unicode \\u0000 \\u0022 \\u0027 \\u005c \\uffff \\uzzzz"') |
| 101 |
|
| 102 |
self.options.unescape_strings = True |
| 103 |
|
| 104 |
bt('"\\x41\\x42\\x01\\x43"', '"AB\\x01C"') |
| 105 |
bt('"\\x41\\x42\\u0001\\x43"', '"AB\\u0001C"') |
| 106 |
bt('"\\x41\\x42\\u{0001}\\x43"', '"AB\\u{0001}C"') |
| 107 |
test_fragment('"\\x20\\x40\\x4a"', '" @J"') |
| 108 |
test_fragment('"\\xff\\x40\\x4a"') |
| 109 |
test_fragment('"\\u0072\\u016B\\u0137\\u012B\\u0074\\u0069\\u0073"', '"\u0072\u016B\u0137\u012B\u0074\u0069\u0073"') |
| 110 |
test_fragment('"\\u{0072}\\u{016B}\\u{110000}\\u{137}\\u012B\\x74\\u{0000069}\\u{073}"', '"\u0072\u016B\\u{110000}\u0137\u012B\u0074\u0069\u0073"') |
| 111 |
|
| 112 |
bt('a = /\\s+/') |
| 113 |
test_fragment('"\\x22\\x27",\'\\x22\\x27\',"\\x5c",\'\\x5c\',"\\xff","unicode \\u0000 \\u0022 \\u0027 \\u005c \\uffff"', |
| 114 |
'"\\"\\\'", \'\\"\\\'\', "\\\\", \'\\\\\', "\\xff", "unicode \\u0000 \\" \\\' \\\\ ' + unicode_char(0xffff) + '"') |
| 115 |
|
| 116 |
# For error case, return the string unchanged |
| 117 |
test_fragment('"\\x22\\x27",\'\\x22\\x27\',"\\x5c",\'\\x5c\',"\\xff and \\xzz","unicode \\u0000 \\u0022 \\u0027 \\u005c \\uffff \\uzzzz"', |
| 118 |
'"\\"\\\'", \'\\"\\\'\', "\\\\", \'\\\\\', "\\xff and \\xzz", "unicode \\u0000 \\u0022 \\u0027 \\u005c \\uffff \\uzzzz"') |
| 119 |
|
| 120 |
self.options.unescape_strings = False |
| 121 |
|
| 122 |
def test_beautifier(self): |
| 123 |
test_fragment = self.decodesto |
| 124 |
bt = self.bt |
| 125 |
|
| 126 |
true = True |
| 127 |
false = False |
| 128 |
|
| 129 |
def unicode_char(value): |
| 130 |
return chr(value) |
| 131 |
|
| 132 |
##============================================================ |
| 133 |
# Line wrap test inputs |
| 134 |
#....---------1---------2---------3---------4---------5---------6---------7 |
| 135 |
#....1234567890123456789012345678901234567890123456789012345678901234567890 |
| 136 |
wrap_input_1=( |
| 137 |
'foo.bar().baz().cucumber((f && "sass") || (leans && mean));\n' + |
| 138 |
'Test_very_long_variable_name_this_should_never_wrap\n.but_this_can\n' + |
| 139 |
'return between_return_and_expression_should_never_wrap.but_this_can\n' + |
| 140 |
'throw between_throw_and_expression_should_never_wrap.but_this_can\n' + |
| 141 |
'if (wraps_can_occur && inside_an_if_block) that_is_\n.okay();\n' + |
| 142 |
'object_literal = {\n' + |
| 143 |
' propertx: first_token + 12345678.99999E-6,\n' + |
| 144 |
' property: first_token_should_never_wrap + but_this_can,\n' + |
| 145 |
' propertz: first_token_should_never_wrap + !but_this_can,\n' + |
| 146 |
' proper: "first_token_should_never_wrap" + "but_this_can"\n' + |
| 147 |
'}'); |
| 148 |
|
| 149 |
#....---------1---------2---------3---------4---------5---------6---------7 |
| 150 |
#....1234567890123456789012345678901234567890123456789012345678901234567890 |
| 151 |
wrap_input_2=( |
| 152 |
'{\n' + |
| 153 |
' foo.bar().baz().cucumber((f && "sass") || (leans && mean));\n' + |
| 154 |
' Test_very_long_variable_name_this_should_never_wrap\n.but_this_can\n' + |
| 155 |
' return between_return_and_expression_should_never_wrap.but_this_can\n' + |
| 156 |
' throw between_throw_and_expression_should_never_wrap.but_this_can\n' + |
| 157 |
' if (wraps_can_occur && inside_an_if_block) that_is_\n.okay();\n' + |
| 158 |
' object_literal = {\n' + |
| 159 |
' propertx: first_token + 12345678.99999E-6,\n' + |
| 160 |
' property: first_token_should_never_wrap + but_this_can,\n' + |
| 161 |
' propertz: first_token_should_never_wrap + !but_this_can,\n' + |
| 162 |
' proper: "first_token_should_never_wrap" + "but_this_can"\n' + |
| 163 |
' }' + |
| 164 |
'}'); |
| 165 |
|
| 166 |
|
| 167 |
#============================================================ |
| 168 |
# Unicode Support |
| 169 |
self.reset_options() |
| 170 |
bt('var ' + unicode_char(3232) + '_' + unicode_char(3232) + ' = "hi";') |
| 171 |
bt( |
| 172 |
'var ' + unicode_char(228) + 'x = {\n' + |
| 173 |
' ' + unicode_char(228) + 'rgerlich: true\n' + |
| 174 |
'};') |
| 175 |
bt( |
| 176 |
'var \\u00E4\\u0ca0\\u0cA0\\u0Ca0 = {\n' + |
| 177 |
' \\u0ca0rgerlich: true\n' + |
| 178 |
'};') |
| 179 |
bt( |
| 180 |
'var \\u00E4add\\u0025 = {\n' + |
| 181 |
' \\u0044rgerlich\\u0ca0: true\n' + |
| 182 |
'};') |
| 183 |
bt( |
| 184 |
'var' + unicode_char(160) + unicode_char(3232) + '_' + unicode_char(3232) + ' = "hi";', |
| 185 |
# -- output -- |
| 186 |
'var ' + unicode_char(3232) + '_' + unicode_char(3232) + ' = "hi";') |
| 187 |
|
| 188 |
# Issue #2159: Invalid prettification of object with unicode escape character as object key - test scenario: object with unicode as key |
| 189 |
bt( |
| 190 |
'{\\u{1d4b6}:"ascr"}', |
| 191 |
# -- output -- |
| 192 |
'{\n' + |
| 193 |
' \\u{1d4b6}: "ascr"\n' + |
| 194 |
'}') |
| 195 |
bt( |
| 196 |
'var \\u{E4}\\u{ca0}\\u{0cA0}\\u{000000Ca0} = {\n' + |
| 197 |
' \\u{ca0}rgerlich: true\n' + |
| 198 |
'};') |
| 199 |
|
| 200 |
|
| 201 |
#============================================================ |
| 202 |
# Test template and continuation strings |
| 203 |
self.reset_options() |
| 204 |
bt('`This is a ${template} string.`') |
| 205 |
bt( |
| 206 |
'`This\n' + |
| 207 |
' is\n' + |
| 208 |
' a\n' + |
| 209 |
' ${template}\n' + |
| 210 |
' string.`') |
| 211 |
bt( |
| 212 |
'a = `This is a continuation\\\n' + |
| 213 |
'string.`') |
| 214 |
bt( |
| 215 |
'a = "This is a continuation\\\n' + |
| 216 |
'string."') |
| 217 |
bt( |
| 218 |
'`SELECT\n' + |
| 219 |
' nextval(\'${this.options.schema ? `${this.options.schema}.` : \'\'}"${this.tableName}_${this.autoIncrementField}_seq"\'::regclass\n' + |
| 220 |
' ) nextval;`') |
| 221 |
|
| 222 |
# Tests for #1030 |
| 223 |
bt( |
| 224 |
'const composeUrl = (host) => {\n' + |
| 225 |
' return `${host `test`}`;\n' + |
| 226 |
'};') |
| 227 |
bt( |
| 228 |
'const composeUrl = (host, api, key, data) => {\n' + |
| 229 |
' switch (api) {\n' + |
| 230 |
' case "Init":\n' + |
| 231 |
' return `${host}/vwapi/Init?VWID=${key}&DATA=${encodeURIComponent(\n' + |
| 232 |
' Object.keys(data).map((k) => `${k}=${ data[k]}` ).join(";")\n' + |
| 233 |
' )}`;\n' + |
| 234 |
' case "Pay":\n' + |
| 235 |
' return `${host}/vwapi/Pay?SessionId=${par}`;\n' + |
| 236 |
' };\n' + |
| 237 |
'};') |
| 238 |
|
| 239 |
|
| 240 |
#============================================================ |
| 241 |
# Private Class Fields |
| 242 |
self.reset_options() |
| 243 |
bt('#foo') |
| 244 |
bt( |
| 245 |
'class X {\n' + |
| 246 |
' #foo = null;\n' + |
| 247 |
' get foo() {\n' + |
| 248 |
' return this.#foo;\n' + |
| 249 |
' }\n' + |
| 250 |
'}') |
| 251 |
bt( |
| 252 |
'class X {#foo=null;}', |
| 253 |
# -- output -- |
| 254 |
'class X {\n' + |
| 255 |
' #foo = null;\n' + |
| 256 |
'}') |
| 257 |
|
| 258 |
|
| 259 |
#============================================================ |
| 260 |
# ES7 Decorators |
| 261 |
self.reset_options() |
| 262 |
bt('@foo') |
| 263 |
bt('@foo(bar)') |
| 264 |
bt( |
| 265 |
'@foo(function(k, v) {\n' + |
| 266 |
' implementation();\n' + |
| 267 |
'})') |
| 268 |
|
| 269 |
|
| 270 |
#============================================================ |
| 271 |
# ES7 exponential |
| 272 |
self.reset_options() |
| 273 |
bt('x ** 2') |
| 274 |
bt('x ** -2') |
| 275 |
|
| 276 |
|
| 277 |
#============================================================ |
| 278 |
# Spread operator |
| 279 |
self.reset_options() |
| 280 |
self.options.brace_style = "collapse,preserve-inline" |
| 281 |
bt('const m = { ...item, c: 3 };') |
| 282 |
bt( |
| 283 |
'const m = {\n' + |
| 284 |
' ...item,\n' + |
| 285 |
' c: 3\n' + |
| 286 |
'};') |
| 287 |
bt('const m = { c: 3, ...item };') |
| 288 |
bt('const m = [...item, 3];') |
| 289 |
bt('const m = [3, ...item];') |
| 290 |
|
| 291 |
|
| 292 |
#============================================================ |
| 293 |
# Object literal shorthand functions |
| 294 |
self.reset_options() |
| 295 |
bt( |
| 296 |
'return {\n' + |
| 297 |
' foo() {\n' + |
| 298 |
' return 42;\n' + |
| 299 |
' }\n' + |
| 300 |
'}') |
| 301 |
bt( |
| 302 |
'var foo = {\n' + |
| 303 |
' * bar() {\n' + |
| 304 |
' yield 42;\n' + |
| 305 |
' }\n' + |
| 306 |
'};') |
| 307 |
bt( |
| 308 |
'var foo = {bar(){return 42;},*barGen(){yield 42;}};', |
| 309 |
# -- output -- |
| 310 |
'var foo = {\n' + |
| 311 |
' bar() {\n' + |
| 312 |
' return 42;\n' + |
| 313 |
' },\n' + |
| 314 |
' * barGen() {\n' + |
| 315 |
' yield 42;\n' + |
| 316 |
' }\n' + |
| 317 |
'};') |
| 318 |
|
| 319 |
# also handle generator shorthand in class - #1013 |
| 320 |
bt( |
| 321 |
'class A {\n' + |
| 322 |
' fn() {\n' + |
| 323 |
' return true;\n' + |
| 324 |
' }\n' + |
| 325 |
'\n' + |
| 326 |
' * gen() {\n' + |
| 327 |
' return true;\n' + |
| 328 |
' }\n' + |
| 329 |
'}') |
| 330 |
bt( |
| 331 |
'class A {\n' + |
| 332 |
' * gen() {\n' + |
| 333 |
' return true;\n' + |
| 334 |
' }\n' + |
| 335 |
'\n' + |
| 336 |
' fn() {\n' + |
| 337 |
' return true;\n' + |
| 338 |
' }\n' + |
| 339 |
'}') |
| 340 |
|
| 341 |
|
| 342 |
#============================================================ |
| 343 |
# End With Newline - (end_with_newline = "true") |
| 344 |
self.reset_options() |
| 345 |
self.options.end_with_newline = true |
| 346 |
test_fragment('', '\n') |
| 347 |
test_fragment(' return .5', ' return .5\n') |
| 348 |
test_fragment( |
| 349 |
' \n' + |
| 350 |
'\n' + |
| 351 |
'return .5\n' + |
| 352 |
'\n' + |
| 353 |
'\n' + |
| 354 |
'\n', |
| 355 |
# -- output -- |
| 356 |
' return .5\n') |
| 357 |
test_fragment('\n') |
| 358 |
|
| 359 |
# End With Newline - (end_with_newline = "false") |
| 360 |
self.reset_options() |
| 361 |
self.options.end_with_newline = false |
| 362 |
test_fragment('') |
| 363 |
test_fragment(' return .5') |
| 364 |
test_fragment( |
| 365 |
' \n' + |
| 366 |
'\n' + |
| 367 |
'return .5\n' + |
| 368 |
'\n' + |
| 369 |
'\n' + |
| 370 |
'\n', |
| 371 |
# -- output -- |
| 372 |
' return .5') |
| 373 |
test_fragment('\n', '') |
| 374 |
|
| 375 |
|
| 376 |
#============================================================ |
| 377 |
# Support Indent Level Options and Base Indent Autodetection - () |
| 378 |
self.reset_options() |
| 379 |
test_fragment(' a') |
| 380 |
test_fragment( |
| 381 |
' function test(){\n' + |
| 382 |
' console.log("this is a test");\n' + |
| 383 |
'}', |
| 384 |
# -- output -- |
| 385 |
' function test() {\n' + |
| 386 |
' console.log("this is a test");\n' + |
| 387 |
' }') |
| 388 |
test_fragment( |
| 389 |
' // This is a random comment\n' + |
| 390 |
'function test(){\n' + |
| 391 |
' console.log("this is a test");\n' + |
| 392 |
'}', |
| 393 |
# -- output -- |
| 394 |
' // This is a random comment\n' + |
| 395 |
' function test() {\n' + |
| 396 |
' console.log("this is a test");\n' + |
| 397 |
' }') |
| 398 |
|
| 399 |
# Support Indent Level Options and Base Indent Autodetection - (indent_level = "0") |
| 400 |
self.reset_options() |
| 401 |
self.options.indent_level = 0 |
| 402 |
test_fragment(' a') |
| 403 |
test_fragment( |
| 404 |
' function test(){\n' + |
| 405 |
' console.log("this is a test");\n' + |
| 406 |
'}', |
| 407 |
# -- output -- |
| 408 |
' function test() {\n' + |
| 409 |
' console.log("this is a test");\n' + |
| 410 |
' }') |
| 411 |
test_fragment( |
| 412 |
' // This is a random comment\n' + |
| 413 |
'function test(){\n' + |
| 414 |
' console.log("this is a test");\n' + |
| 415 |
'}', |
| 416 |
# -- output -- |
| 417 |
' // This is a random comment\n' + |
| 418 |
' function test() {\n' + |
| 419 |
' console.log("this is a test");\n' + |
| 420 |
' }') |
| 421 |
|
| 422 |
# Support Indent Level Options and Base Indent Autodetection - (indent_level = "1") |
| 423 |
self.reset_options() |
| 424 |
self.options.indent_level = 1 |
| 425 |
test_fragment(' a', ' a') |
| 426 |
test_fragment( |
| 427 |
' function test(){\n' + |
| 428 |
' console.log("this is a test");\n' + |
| 429 |
'}', |
| 430 |
# -- output -- |
| 431 |
' function test() {\n' + |
| 432 |
' console.log("this is a test");\n' + |
| 433 |
' }') |
| 434 |
test_fragment( |
| 435 |
' // This is a random comment\n' + |
| 436 |
'function test(){\n' + |
| 437 |
' console.log("this is a test");\n' + |
| 438 |
'}', |
| 439 |
# -- output -- |
| 440 |
' // This is a random comment\n' + |
| 441 |
' function test() {\n' + |
| 442 |
' console.log("this is a test");\n' + |
| 443 |
' }') |
| 444 |
|
| 445 |
# Support Indent Level Options and Base Indent Autodetection - (indent_level = "2") |
| 446 |
self.reset_options() |
| 447 |
self.options.indent_level = 2 |
| 448 |
test_fragment('a', ' a') |
| 449 |
test_fragment( |
| 450 |
'function test(){\n' + |
| 451 |
' console.log("this is a test");\n' + |
| 452 |
'}', |
| 453 |
# -- output -- |
| 454 |
' function test() {\n' + |
| 455 |
' console.log("this is a test");\n' + |
| 456 |
' }') |
| 457 |
test_fragment( |
| 458 |
'// This is a random comment\n' + |
| 459 |
'function test(){\n' + |
| 460 |
' console.log("this is a test");\n' + |
| 461 |
'}', |
| 462 |
# -- output -- |
| 463 |
' // This is a random comment\n' + |
| 464 |
' function test() {\n' + |
| 465 |
' console.log("this is a test");\n' + |
| 466 |
' }') |
| 467 |
|
| 468 |
# Support Indent Level Options and Base Indent Autodetection - (indent_with_tabs = "true", indent_level = "2") |
| 469 |
self.reset_options() |
| 470 |
self.options.indent_with_tabs = true |
| 471 |
self.options.indent_level = 2 |
| 472 |
test_fragment('a', '\t\ta') |
| 473 |
test_fragment( |
| 474 |
'function test(){\n' + |
| 475 |
' console.log("this is a test");\n' + |
| 476 |
'}', |
| 477 |
# -- output -- |
| 478 |
'\t\tfunction test() {\n' + |
| 479 |
'\t\t\tconsole.log("this is a test");\n' + |
| 480 |
'\t\t}') |
| 481 |
test_fragment( |
| 482 |
'// This is a random comment\n' + |
| 483 |
'function test(){\n' + |
| 484 |
' console.log("this is a test");\n' + |
| 485 |
'}', |
| 486 |
# -- output -- |
| 487 |
'\t\t// This is a random comment\n' + |
| 488 |
'\t\tfunction test() {\n' + |
| 489 |
'\t\t\tconsole.log("this is a test");\n' + |
| 490 |
'\t\t}') |
| 491 |
|
| 492 |
# Support Indent Level Options and Base Indent Autodetection - (indent_level = "0") |
| 493 |
self.reset_options() |
| 494 |
self.options.indent_level = 0 |
| 495 |
test_fragment('\t a') |
| 496 |
test_fragment( |
| 497 |
'\t function test(){\n' + |
| 498 |
' console.log("this is a test");\n' + |
| 499 |
'}', |
| 500 |
# -- output -- |
| 501 |
'\t function test() {\n' + |
| 502 |
'\t console.log("this is a test");\n' + |
| 503 |
'\t }') |
| 504 |
test_fragment( |
| 505 |
'\t // This is a random comment\n' + |
| 506 |
'function test(){\n' + |
| 507 |
' console.log("this is a test");\n' + |
| 508 |
'}', |
| 509 |
# -- output -- |
| 510 |
'\t // This is a random comment\n' + |
| 511 |
'\t function test() {\n' + |
| 512 |
'\t console.log("this is a test");\n' + |
| 513 |
'\t }') |
| 514 |
|
| 515 |
|
| 516 |
#============================================================ |
| 517 |
# Support simple language specific option inheritance/overriding - (js = "{ "indent_size": 3 }", css = "{ "indent_size": 5 }") |
| 518 |
self.reset_options() |
| 519 |
self.options.js = { 'indent_size': 3 } |
| 520 |
self.options.css = { 'indent_size': 5 } |
| 521 |
bt( |
| 522 |
'if (a == b) {\n' + |
| 523 |
' test();\n' + |
| 524 |
'}') |
| 525 |
|
| 526 |
# Support simple language specific option inheritance/overriding - (html = "{ "js": { "indent_size": 3 }, "css": { "indent_size": 5 } }") |
| 527 |
self.reset_options() |
| 528 |
self.options.html = { 'js': { 'indent_size': 3 }, 'css': { 'indent_size': 5 } } |
| 529 |
bt( |
| 530 |
'if (a == b) {\n' + |
| 531 |
' test();\n' + |
| 532 |
'}') |
| 533 |
|
| 534 |
# Support simple language specific option inheritance/overriding - (indent_size = "9", html = "{ "js": { "indent_size": 3 }, "css": { "indent_size": 5 }, "indent_size": 2}", js = "{ "indent_size": 4 }", css = "{ "indent_size": 3 }") |
| 535 |
self.reset_options() |
| 536 |
self.options.indent_size = 9 |
| 537 |
self.options.html = { 'js': { 'indent_size': 3 }, 'css': { 'indent_size': 5 }, 'indent_size': 2} |
| 538 |
self.options.js = { 'indent_size': 4 } |
| 539 |
self.options.css = { 'indent_size': 3 } |
| 540 |
bt( |
| 541 |
'if (a == b) {\n' + |
| 542 |
' test();\n' + |
| 543 |
'}') |
| 544 |
|
| 545 |
|
| 546 |
#============================================================ |
| 547 |
# Brace style permutations - (brace_style = ""collapse,preserve-inline"") |
| 548 |
self.reset_options() |
| 549 |
self.options.brace_style = 'collapse,preserve-inline' |
| 550 |
bt( |
| 551 |
'var a ={a: 2};\n' + |
| 552 |
'var a ={a: 2};', |
| 553 |
# -- output -- |
| 554 |
'var a = { a: 2 };\n' + |
| 555 |
'var a = { a: 2 };') |
| 556 |
bt( |
| 557 |
'//case 1\n' + |
| 558 |
'if (a == 1){}\n' + |
| 559 |
'//case 2\n' + |
| 560 |
'else if (a == 2){}', |
| 561 |
# -- output -- |
| 562 |
'//case 1\n' + |
| 563 |
'if (a == 1) {}\n' + |
| 564 |
'//case 2\n' + |
| 565 |
'else if (a == 2) {}') |
| 566 |
bt('if(1){2}else{3}', 'if (1) { 2 } else { 3 }') |
| 567 |
bt('try{a();}catch(b){c();}catch(d){}finally{e();}', 'try { a(); } catch (b) { c(); } catch (d) {} finally { e(); }') |
| 568 |
|
| 569 |
# Brace style permutations - (brace_style = ""collapse,preserve-inline"") |
| 570 |
self.reset_options() |
| 571 |
self.options.brace_style = 'collapse,preserve-inline' |
| 572 |
bt( |
| 573 |
'var a =\n' + |
| 574 |
'{\n' + |
| 575 |
'a: 2\n' + |
| 576 |
'}\n' + |
| 577 |
';\n' + |
| 578 |
'var a =\n' + |
| 579 |
'{\n' + |
| 580 |
'a: 2\n' + |
| 581 |
'}\n' + |
| 582 |
';', |
| 583 |
# -- output -- |
| 584 |
'var a = {\n' + |
| 585 |
' a: 2\n' + |
| 586 |
'};\n' + |
| 587 |
'var a = {\n' + |
| 588 |
' a: 2\n' + |
| 589 |
'};') |
| 590 |
bt( |
| 591 |
'//case 1\n' + |
| 592 |
'if (a == 1)\n' + |
| 593 |
'{}\n' + |
| 594 |
'//case 2\n' + |
| 595 |
'else if (a == 2)\n' + |
| 596 |
'{}', |
| 597 |
# -- output -- |
| 598 |
'//case 1\n' + |
| 599 |
'if (a == 1) {}\n' + |
| 600 |
'//case 2\n' + |
| 601 |
'else if (a == 2) {}') |
| 602 |
bt( |
| 603 |
'if(1)\n' + |
| 604 |
'{\n' + |
| 605 |
'2\n' + |
| 606 |
'}\n' + |
| 607 |
'else\n' + |
| 608 |
'{\n' + |
| 609 |
'3\n' + |
| 610 |
'}', |
| 611 |
# -- output -- |
| 612 |
'if (1) {\n' + |
| 613 |
' 2\n' + |
| 614 |
'} else {\n' + |
| 615 |
' 3\n' + |
| 616 |
'}') |
| 617 |
bt( |
| 618 |
'try\n' + |
| 619 |
'{\n' + |
| 620 |
'a();\n' + |
| 621 |
'}\n' + |
| 622 |
'catch(b)\n' + |
| 623 |
'{\n' + |
| 624 |
'c();\n' + |
| 625 |
'}\n' + |
| 626 |
'catch(d)\n' + |
| 627 |
'{}\n' + |
| 628 |
'finally\n' + |
| 629 |
'{\n' + |
| 630 |
'e();\n' + |
| 631 |
'}', |
| 632 |
# -- output -- |
| 633 |
'try {\n' + |
| 634 |
' a();\n' + |
| 635 |
'} catch (b) {\n' + |
| 636 |
' c();\n' + |
| 637 |
'} catch (d) {} finally {\n' + |
| 638 |
' e();\n' + |
| 639 |
'}') |
| 640 |
|
| 641 |
# Brace style permutations - () |
| 642 |
self.reset_options() |
| 643 |
bt( |
| 644 |
'var a ={a: 2};\n' + |
| 645 |
'var a ={a: 2};', |
| 646 |
# -- output -- |
| 647 |
'var a = {\n' + |
| 648 |
' a: 2\n' + |
| 649 |
'};\n' + |
| 650 |
'var a = {\n' + |
| 651 |
' a: 2\n' + |
| 652 |
'};') |
| 653 |
bt( |
| 654 |
'//case 1\n' + |
| 655 |
'if (a == 1){}\n' + |
| 656 |
'//case 2\n' + |
| 657 |
'else if (a == 2){}', |
| 658 |
# -- output -- |
| 659 |
'//case 1\n' + |
| 660 |
'if (a == 1) {}\n' + |
| 661 |
'//case 2\n' + |
| 662 |
'else if (a == 2) {}') |
| 663 |
bt( |
| 664 |
'if(1){2}else{3}', |
| 665 |
# -- output -- |
| 666 |
'if (1) {\n' + |
| 667 |
' 2\n' + |
| 668 |
'} else {\n' + |
| 669 |
' 3\n' + |
| 670 |
'}') |
| 671 |
bt( |
| 672 |
'try{a();}catch(b){c();}catch(d){}finally{e();}', |
| 673 |
# -- output -- |
| 674 |
'try {\n' + |
| 675 |
' a();\n' + |
| 676 |
'} catch (b) {\n' + |
| 677 |
' c();\n' + |
| 678 |
'} catch (d) {} finally {\n' + |
| 679 |
' e();\n' + |
| 680 |
'}') |
| 681 |
|
| 682 |
# Brace style permutations - (brace_style = ""collapse"") |
| 683 |
self.reset_options() |
| 684 |
self.options.brace_style = 'collapse' |
| 685 |
bt( |
| 686 |
'var a ={a: 2};\n' + |
| 687 |
'var a ={a: 2};', |
| 688 |
# -- output -- |
| 689 |
'var a = {\n' + |
| 690 |
' a: 2\n' + |
| 691 |
'};\n' + |
| 692 |
'var a = {\n' + |
| 693 |
' a: 2\n' + |
| 694 |
'};') |
| 695 |
bt( |
| 696 |
'//case 1\n' + |
| 697 |
'if (a == 1){}\n' + |
| 698 |
'//case 2\n' + |
| 699 |
'else if (a == 2){}', |
| 700 |
# -- output -- |
| 701 |
'//case 1\n' + |
| 702 |
'if (a == 1) {}\n' + |
| 703 |
'//case 2\n' + |
| 704 |
'else if (a == 2) {}') |
| 705 |
bt( |
| 706 |
'if(1){2}else{3}', |
| 707 |
# -- output -- |
| 708 |
'if (1) {\n' + |
| 709 |
' 2\n' + |
| 710 |
'} else {\n' + |
| 711 |
' 3\n' + |
| 712 |
'}') |
| 713 |
bt( |
| 714 |
'try{a();}catch(b){c();}catch(d){}finally{e();}', |
| 715 |
# -- output -- |
| 716 |
'try {\n' + |
| 717 |
' a();\n' + |
| 718 |
'} catch (b) {\n' + |
| 719 |
' c();\n' + |
| 720 |
'} catch (d) {} finally {\n' + |
| 721 |
' e();\n' + |
| 722 |
'}') |
| 723 |
|
| 724 |
# Brace style permutations - (brace_style = ""collapse"") |
| 725 |
self.reset_options() |
| 726 |
self.options.brace_style = 'collapse' |
| 727 |
bt( |
| 728 |
'var a =\n' + |
| 729 |
'{\n' + |
| 730 |
'a: 2\n' + |
| 731 |
'}\n' + |
| 732 |
';\n' + |
| 733 |
'var a =\n' + |
| 734 |
'{\n' + |
| 735 |
'a: 2\n' + |
| 736 |
'}\n' + |
| 737 |
';', |
| 738 |
# -- output -- |
| 739 |
'var a = {\n' + |
| 740 |
' a: 2\n' + |
| 741 |
'};\n' + |
| 742 |
'var a = {\n' + |
| 743 |
' a: 2\n' + |
| 744 |
'};') |
| 745 |
bt( |
| 746 |
'//case 1\n' + |
| 747 |
'if (a == 1)\n' + |
| 748 |
'{}\n' + |
| 749 |
'//case 2\n' + |
| 750 |
'else if (a == 2)\n' + |
| 751 |
'{}', |
| 752 |
# -- output -- |
| 753 |
'//case 1\n' + |
| 754 |
'if (a == 1) {}\n' + |
| 755 |
'//case 2\n' + |
| 756 |
'else if (a == 2) {}') |
| 757 |
bt( |
| 758 |
'if(1)\n' + |
| 759 |
'{\n' + |
| 760 |
'2\n' + |
| 761 |
'}\n' + |
| 762 |
'else\n' + |
| 763 |
'{\n' + |
| 764 |
'3\n' + |
| 765 |
'}', |
| 766 |
# -- output -- |
| 767 |
'if (1) {\n' + |
| 768 |
' 2\n' + |
| 769 |
'} else {\n' + |
| 770 |
' 3\n' + |
| 771 |
'}') |
| 772 |
bt( |
| 773 |
'try\n' + |
| 774 |
'{\n' + |
| 775 |
'a();\n' + |
| 776 |
'}\n' + |
| 777 |
'catch(b)\n' + |
| 778 |
'{\n' + |
| 779 |
'c();\n' + |
| 780 |
'}\n' + |
| 781 |
'catch(d)\n' + |
| 782 |
'{}\n' + |
| 783 |
'finally\n' + |
| 784 |
'{\n' + |
| 785 |
'e();\n' + |
| 786 |
'}', |
| 787 |
# -- output -- |
| 788 |
'try {\n' + |
| 789 |
' a();\n' + |
| 790 |
'} catch (b) {\n' + |
| 791 |
' c();\n' + |
| 792 |
'} catch (d) {} finally {\n' + |
| 793 |
' e();\n' + |
| 794 |
'}') |
| 795 |
|
| 796 |
|
| 797 |
#============================================================ |
| 798 |
# Comma-first option - (comma_first = "false") |
| 799 |
self.reset_options() |
| 800 |
self.options.comma_first = false |
| 801 |
bt( |
| 802 |
'{a:1, b:2}', |
| 803 |
# -- output -- |
| 804 |
'{\n' + |
| 805 |
' a: 1,\n' + |
| 806 |
' b: 2\n' + |
| 807 |
'}') |
| 808 |
bt( |
| 809 |
'var a=1, b=c[d], e=6;', |
| 810 |
# -- output -- |
| 811 |
'var a = 1,\n' + |
| 812 |
' b = c[d],\n' + |
| 813 |
' e = 6;') |
| 814 |
bt( |
| 815 |
'for(var a=1,b=2,c=3;d<3;d++)\n' + |
| 816 |
'e', |
| 817 |
# -- output -- |
| 818 |
'for (var a = 1, b = 2, c = 3; d < 3; d++)\n' + |
| 819 |
' e') |
| 820 |
bt( |
| 821 |
'for(var a=1,b=2,\n' + |
| 822 |
'c=3;d<3;d++)\n' + |
| 823 |
'e', |
| 824 |
# -- output -- |
| 825 |
'for (var a = 1, b = 2,\n' + |
| 826 |
' c = 3; d < 3; d++)\n' + |
| 827 |
' e') |
| 828 |
bt( |
| 829 |
'function foo() {\n' + |
| 830 |
' return [\n' + |
| 831 |
' "one",\n' + |
| 832 |
' "two"\n' + |
| 833 |
' ];\n' + |
| 834 |
'}') |
| 835 |
bt( |
| 836 |
'a=[[1,2],[4,5],[7,8]]', |
| 837 |
# -- output -- |
| 838 |
'a = [\n' + |
| 839 |
' [1, 2],\n' + |
| 840 |
' [4, 5],\n' + |
| 841 |
' [7, 8]\n' + |
| 842 |
']') |
| 843 |
bt( |
| 844 |
'a=[[1,2],[4,5],[7,8],]', |
| 845 |
# -- output -- |
| 846 |
'a = [\n' + |
| 847 |
' [1, 2],\n' + |
| 848 |
' [4, 5],\n' + |
| 849 |
' [7, 8],\n' + |
| 850 |
']') |
| 851 |
bt( |
| 852 |
'a=[[1,2],[4,5],function(){},[7,8]]', |
| 853 |
# -- output -- |
| 854 |
'a = [\n' + |
| 855 |
' [1, 2],\n' + |
| 856 |
' [4, 5],\n' + |
| 857 |
' function() {},\n' + |
| 858 |
' [7, 8]\n' + |
| 859 |
']') |
| 860 |
bt( |
| 861 |
'a=[[1,2],[4,5],function(){},function(){},[7,8]]', |
| 862 |
# -- output -- |
| 863 |
'a = [\n' + |
| 864 |
' [1, 2],\n' + |
| 865 |
' [4, 5],\n' + |
| 866 |
' function() {},\n' + |
| 867 |
' function() {},\n' + |
| 868 |
' [7, 8]\n' + |
| 869 |
']') |
| 870 |
bt( |
| 871 |
'a=[[1,2],[4,5],function(){},[7,8]]', |
| 872 |
# -- output -- |
| 873 |
'a = [\n' + |
| 874 |
' [1, 2],\n' + |
| 875 |
' [4, 5],\n' + |
| 876 |
' function() {},\n' + |
| 877 |
' [7, 8]\n' + |
| 878 |
']') |
| 879 |
bt('a=[b,c,function(){},function(){},d]', 'a = [b, c, function() {}, function() {}, d]') |
| 880 |
bt( |
| 881 |
'a=[b,c,\n' + |
| 882 |
'function(){},function(){},d]', |
| 883 |
# -- output -- |
| 884 |
'a = [b, c,\n' + |
| 885 |
' function() {},\n' + |
| 886 |
' function() {},\n' + |
| 887 |
' d\n' + |
| 888 |
']') |
| 889 |
bt('a=[a[1],b[4],c[d[7]]]', 'a = [a[1], b[4], c[d[7]]]') |
| 890 |
bt('[1,2,[3,4,[5,6],7],8]', '[1, 2, [3, 4, [5, 6], 7], 8]') |
| 891 |
bt( |
| 892 |
'[[["1","2"],["3","4"]],[["5","6","7"],["8","9","0"]],[["1","2","3"],["4","5","6","7"],["8","9","0"]]]', |
| 893 |
# -- output -- |
| 894 |
'[\n' + |
| 895 |
' [\n' + |
| 896 |
' ["1", "2"],\n' + |
| 897 |
' ["3", "4"]\n' + |
| 898 |
' ],\n' + |
| 899 |
' [\n' + |
| 900 |
' ["5", "6", "7"],\n' + |
| 901 |
' ["8", "9", "0"]\n' + |
| 902 |
' ],\n' + |
| 903 |
' [\n' + |
| 904 |
' ["1", "2", "3"],\n' + |
| 905 |
' ["4", "5", "6", "7"],\n' + |
| 906 |
' ["8", "9", "0"]\n' + |
| 907 |
' ]\n' + |
| 908 |
']') |
| 909 |
bt( |
| 910 |
'changeCollection.add({\n' + |
| 911 |
' name: "Jonathan" // New line inserted after this line on every save\n' + |
| 912 |
' , age: 25\n' + |
| 913 |
'});', |
| 914 |
# -- output -- |
| 915 |
'changeCollection.add({\n' + |
| 916 |
' name: "Jonathan" // New line inserted after this line on every save\n' + |
| 917 |
' ,\n' + |
| 918 |
' age: 25\n' + |
| 919 |
'});') |
| 920 |
bt( |
| 921 |
'changeCollection.add(\n' + |
| 922 |
' function() {\n' + |
| 923 |
' return true;\n' + |
| 924 |
' },\n' + |
| 925 |
' function() {\n' + |
| 926 |
' return true;\n' + |
| 927 |
' }\n' + |
| 928 |
');') |
| 929 |
|
| 930 |
# Comma-first option - (comma_first = "true") |
| 931 |
self.reset_options() |
| 932 |
self.options.comma_first = true |
| 933 |
bt( |
| 934 |
'{a:1, b:2}', |
| 935 |
# -- output -- |
| 936 |
'{\n' + |
| 937 |
' a: 1\n' + |
| 938 |
' , b: 2\n' + |
| 939 |
'}') |
| 940 |
bt( |
| 941 |
'var a=1, b=c[d], e=6;', |
| 942 |
# -- output -- |
| 943 |
'var a = 1\n' + |
| 944 |
' , b = c[d]\n' + |
| 945 |
' , e = 6;') |
| 946 |
bt( |
| 947 |
'for(var a=1,b=2,c=3;d<3;d++)\n' + |
| 948 |
'e', |
| 949 |
# -- output -- |
| 950 |
'for (var a = 1, b = 2, c = 3; d < 3; d++)\n' + |
| 951 |
' e') |
| 952 |
bt( |
| 953 |
'for(var a=1,b=2,\n' + |
| 954 |
'c=3;d<3;d++)\n' + |
| 955 |
'e', |
| 956 |
# -- output -- |
| 957 |
'for (var a = 1, b = 2\n' + |
| 958 |
' , c = 3; d < 3; d++)\n' + |
| 959 |
' e') |
| 960 |
bt( |
| 961 |
'function foo() {\n' + |
| 962 |
' return [\n' + |
| 963 |
' "one"\n' + |
| 964 |
' , "two"\n' + |
| 965 |
' ];\n' + |
| 966 |
'}') |
| 967 |
bt( |
| 968 |
'a=[[1,2],[4,5],[7,8]]', |
| 969 |
# -- output -- |
| 970 |
'a = [\n' + |
| 971 |
' [1, 2]\n' + |
| 972 |
' , [4, 5]\n' + |
| 973 |
' , [7, 8]\n' + |
| 974 |
']') |
| 975 |
bt( |
| 976 |
'a=[[1,2],[4,5],[7,8],]', |
| 977 |
# -- output -- |
| 978 |
'a = [\n' + |
| 979 |
' [1, 2]\n' + |
| 980 |
' , [4, 5]\n' + |
| 981 |
' , [7, 8]\n' + |
| 982 |
', ]') |
| 983 |
bt( |
| 984 |
'a=[[1,2],[4,5],function(){},[7,8]]', |
| 985 |
# -- output -- |
| 986 |
'a = [\n' + |
| 987 |
' [1, 2]\n' + |
| 988 |
' , [4, 5]\n' + |
| 989 |
' , function() {}\n' + |
| 990 |
' , [7, 8]\n' + |
| 991 |
']') |
| 992 |
bt( |
| 993 |
'a=[[1,2],[4,5],function(){},function(){},[7,8]]', |
| 994 |
# -- output -- |
| 995 |
'a = [\n' + |
| 996 |
' [1, 2]\n' + |
| 997 |
' , [4, 5]\n' + |
| 998 |
' , function() {}\n' + |
| 999 |
' , function() {}\n' + |
| 1000 |
' , [7, 8]\n' + |
| 1001 |
']') |
| 1002 |
bt( |
| 1003 |
'a=[[1,2],[4,5],function(){},[7,8]]', |
| 1004 |
# -- output -- |
| 1005 |
'a = [\n' + |
| 1006 |
' [1, 2]\n' + |
| 1007 |
' , [4, 5]\n' + |
| 1008 |
' , function() {}\n' + |
| 1009 |
' , [7, 8]\n' + |
| 1010 |
']') |
| 1011 |
bt('a=[b,c,function(){},function(){},d]', 'a = [b, c, function() {}, function() {}, d]') |
| 1012 |
bt( |
| 1013 |
'a=[b,c,\n' + |
| 1014 |
'function(){},function(){},d]', |
| 1015 |
# -- output -- |
| 1016 |
'a = [b, c\n' + |
| 1017 |
' , function() {}\n' + |
| 1018 |
' , function() {}\n' + |
| 1019 |
' , d\n' + |
| 1020 |
']') |
| 1021 |
bt('a=[a[1],b[4],c[d[7]]]', 'a = [a[1], b[4], c[d[7]]]') |
| 1022 |
bt('[1,2,[3,4,[5,6],7],8]', '[1, 2, [3, 4, [5, 6], 7], 8]') |
| 1023 |
bt( |
| 1024 |
'[[["1","2"],["3","4"]],[["5","6","7"],["8","9","0"]],[["1","2","3"],["4","5","6","7"],["8","9","0"]]]', |
| 1025 |
# -- output -- |
| 1026 |
'[\n' + |
| 1027 |
' [\n' + |
| 1028 |
' ["1", "2"]\n' + |
| 1029 |
' , ["3", "4"]\n' + |
| 1030 |
' ]\n' + |
| 1031 |
' , [\n' + |
| 1032 |
' ["5", "6", "7"]\n' + |
| 1033 |
' , ["8", "9", "0"]\n' + |
| 1034 |
' ]\n' + |
| 1035 |
' , [\n' + |
| 1036 |
' ["1", "2", "3"]\n' + |
| 1037 |
' , ["4", "5", "6", "7"]\n' + |
| 1038 |
' , ["8", "9", "0"]\n' + |
| 1039 |
' ]\n' + |
| 1040 |
']') |
| 1041 |
bt( |
| 1042 |
'changeCollection.add({\n' + |
| 1043 |
' name: "Jonathan" // New line inserted after this line on every save\n' + |
| 1044 |
' , age: 25\n' + |
| 1045 |
'});') |
| 1046 |
bt( |
| 1047 |
'changeCollection.add(\n' + |
| 1048 |
' function() {\n' + |
| 1049 |
' return true;\n' + |
| 1050 |
' },\n' + |
| 1051 |
' function() {\n' + |
| 1052 |
' return true;\n' + |
| 1053 |
' }\n' + |
| 1054 |
');', |
| 1055 |
# -- output -- |
| 1056 |
'changeCollection.add(\n' + |
| 1057 |
' function() {\n' + |
| 1058 |
' return true;\n' + |
| 1059 |
' }\n' + |
| 1060 |
' , function() {\n' + |
| 1061 |
' return true;\n' + |
| 1062 |
' }\n' + |
| 1063 |
');') |
| 1064 |
|
| 1065 |
|
| 1066 |
#============================================================ |
| 1067 |
# Unindent chained functions - (unindent_chained_methods = "true") |
| 1068 |
self.reset_options() |
| 1069 |
self.options.unindent_chained_methods = true |
| 1070 |
bt( |
| 1071 |
'f().f().f()\n' + |
| 1072 |
' .f().f();', |
| 1073 |
# -- output -- |
| 1074 |
'f().f().f()\n' + |
| 1075 |
'.f().f();') |
| 1076 |
bt( |
| 1077 |
'f()\n' + |
| 1078 |
' .f()\n' + |
| 1079 |
' .f();', |
| 1080 |
# -- output -- |
| 1081 |
'f()\n' + |
| 1082 |
'.f()\n' + |
| 1083 |
'.f();') |
| 1084 |
bt( |
| 1085 |
'f(function() {\n' + |
| 1086 |
' f()\n' + |
| 1087 |
' .f()\n' + |
| 1088 |
' .f();\n' + |
| 1089 |
'});', |
| 1090 |
# -- output -- |
| 1091 |
'f(function() {\n' + |
| 1092 |
' f()\n' + |
| 1093 |
' .f()\n' + |
| 1094 |
' .f();\n' + |
| 1095 |
'});') |
| 1096 |
|
| 1097 |
# regression test for fix #1378 |
| 1098 |
bt( |
| 1099 |
'f(function() {\n' + |
| 1100 |
' if(g === 1)\n' + |
| 1101 |
' g = 0;\n' + |
| 1102 |
' else\n' + |
| 1103 |
' g = 1;\n' + |
| 1104 |
'\n' + |
| 1105 |
' f()\n' + |
| 1106 |
' .f()\n' + |
| 1107 |
' .f();\n' + |
| 1108 |
'});', |
| 1109 |
# -- output -- |
| 1110 |
'f(function() {\n' + |
| 1111 |
' if (g === 1)\n' + |
| 1112 |
' g = 0;\n' + |
| 1113 |
' else\n' + |
| 1114 |
' g = 1;\n' + |
| 1115 |
'\n' + |
| 1116 |
' f()\n' + |
| 1117 |
' .f()\n' + |
| 1118 |
' .f();\n' + |
| 1119 |
'});') |
| 1120 |
|
| 1121 |
# regression test for fix #1533 |
| 1122 |
bt( |
| 1123 |
'angular.module("test").controller("testCtrl", function($scope) {\n' + |
| 1124 |
' $scope.tnew;\n' + |
| 1125 |
' $scope.toggle_tnew = function() {\n' + |
| 1126 |
' $scope.mode = 0;\n' + |
| 1127 |
' if (!$scope.tnew) {\n' + |
| 1128 |
' $scope.tnew = {};\n' + |
| 1129 |
' } else $scope.tnew = null;\n' + |
| 1130 |
' }\n' + |
| 1131 |
' $scope.fn = function() {\n' + |
| 1132 |
' return null;\n' + |
| 1133 |
' }\n' + |
| 1134 |
'});') |
| 1135 |
|
| 1136 |
|
| 1137 |
#============================================================ |
| 1138 |
# Space in parens tests - (space_in_paren = "false", space_in_empty_paren = "false") |
| 1139 |
self.reset_options() |
| 1140 |
self.options.space_in_paren = false |
| 1141 |
self.options.space_in_empty_paren = false |
| 1142 |
bt('if(p) foo(a,b);', 'if (p) foo(a, b);') |
| 1143 |
bt( |
| 1144 |
'try{while(true){willThrow()}}catch(result)switch(result){case 1:++result }', |
| 1145 |
# -- output -- |
| 1146 |
'try {\n' + |
| 1147 |
' while (true) {\n' + |
| 1148 |
' willThrow()\n' + |
| 1149 |
' }\n' + |
| 1150 |
'} catch (result) switch (result) {\n' + |
| 1151 |
' case 1:\n' + |
| 1152 |
' ++result\n' + |
| 1153 |
'}') |
| 1154 |
bt('((e/((a+(b)*c)-d))^2)*5;', '((e / ((a + (b) * c) - d)) ^ 2) * 5;') |
| 1155 |
bt( |
| 1156 |
'function f(a,b) {if(a) b()}function g(a,b) {if(!a) b()}', |
| 1157 |
# -- output -- |
| 1158 |
'function f(a, b) {\n' + |
| 1159 |
' if (a) b()\n' + |
| 1160 |
'}\n' + |
| 1161 |
'\n' + |
| 1162 |
'function g(a, b) {\n' + |
| 1163 |
' if (!a) b()\n' + |
| 1164 |
'}') |
| 1165 |
bt('a=[][ ]( );', 'a = [][]();') |
| 1166 |
bt('a=()( )[ ];', 'a = ()()[];') |
| 1167 |
bt('a=[b,c,d];', 'a = [b, c, d];') |
| 1168 |
bt('a= f[b];', 'a = f[b];') |
| 1169 |
|
| 1170 |
# Issue #1151 - inside class methods |
| 1171 |
bt( |
| 1172 |
'export default class Test extends Component {\n' + |
| 1173 |
' render() {\n' + |
| 1174 |
' someOther();\n' + |
| 1175 |
' return null;\n' + |
| 1176 |
' }\n' + |
| 1177 |
'}') |
| 1178 |
bt( |
| 1179 |
'{\n' + |
| 1180 |
' files: a[][ {\n' + |
| 1181 |
' expand: true,\n' + |
| 1182 |
' cwd: "www/gui/",\n' + |
| 1183 |
' src: b(c)[ "im/design_standards/*.*" ],\n' + |
| 1184 |
' dest: "www/gui/build"\n' + |
| 1185 |
' } ]\n' + |
| 1186 |
'}', |
| 1187 |
# -- output -- |
| 1188 |
'{\n' + |
| 1189 |
' files: a[][{\n' + |
| 1190 |
' expand: true,\n' + |
| 1191 |
' cwd: "www/gui/",\n' + |
| 1192 |
' src: b(c)["im/design_standards/*.*"],\n' + |
| 1193 |
' dest: "www/gui/build"\n' + |
| 1194 |
' }]\n' + |
| 1195 |
'}') |
| 1196 |
|
| 1197 |
# Space in parens tests - (space_in_paren = "false", space_in_empty_paren = "true") |
| 1198 |
self.reset_options() |
| 1199 |
self.options.space_in_paren = false |
| 1200 |
self.options.space_in_empty_paren = true |
| 1201 |
bt('if(p) foo(a,b);', 'if (p) foo(a, b);') |
| 1202 |
bt( |
| 1203 |
'try{while(true){willThrow()}}catch(result)switch(result){case 1:++result }', |
| 1204 |
# -- output -- |
| 1205 |
'try {\n' + |
| 1206 |
' while (true) {\n' + |
| 1207 |
' willThrow()\n' + |
| 1208 |
' }\n' + |
| 1209 |
'} catch (result) switch (result) {\n' + |
| 1210 |
' case 1:\n' + |
| 1211 |
' ++result\n' + |
| 1212 |
'}') |
| 1213 |
bt('((e/((a+(b)*c)-d))^2)*5;', '((e / ((a + (b) * c) - d)) ^ 2) * 5;') |
| 1214 |
bt( |
| 1215 |
'function f(a,b) {if(a) b()}function g(a,b) {if(!a) b()}', |
| 1216 |
# -- output -- |
| 1217 |
'function f(a, b) {\n' + |
| 1218 |
' if (a) b()\n' + |
| 1219 |
'}\n' + |
| 1220 |
'\n' + |
| 1221 |
'function g(a, b) {\n' + |
| 1222 |
' if (!a) b()\n' + |
| 1223 |
'}') |
| 1224 |
bt('a=[][ ]( );', 'a = [][]();') |
| 1225 |
bt('a=()( )[ ];', 'a = ()()[];') |
| 1226 |
bt('a=[b,c,d];', 'a = [b, c, d];') |
| 1227 |
bt('a= f[b];', 'a = f[b];') |
| 1228 |
|
| 1229 |
# Issue #1151 - inside class methods |
| 1230 |
bt( |
| 1231 |
'export default class Test extends Component {\n' + |
| 1232 |
' render() {\n' + |
| 1233 |
' someOther();\n' + |
| 1234 |
' return null;\n' + |
| 1235 |
' }\n' + |
| 1236 |
'}') |
| 1237 |
bt( |
| 1238 |
'{\n' + |
| 1239 |
' files: a[][ {\n' + |
| 1240 |
' expand: true,\n' + |
| 1241 |
' cwd: "www/gui/",\n' + |
| 1242 |
' src: b(c)[ "im/design_standards/*.*" ],\n' + |
| 1243 |
' dest: "www/gui/build"\n' + |
| 1244 |
' } ]\n' + |
| 1245 |
'}', |
| 1246 |
# -- output -- |
| 1247 |
'{\n' + |
| 1248 |
' files: a[][{\n' + |
| 1249 |
' expand: true,\n' + |
| 1250 |
' cwd: "www/gui/",\n' + |
| 1251 |
' src: b(c)["im/design_standards/*.*"],\n' + |
| 1252 |
' dest: "www/gui/build"\n' + |
| 1253 |
' }]\n' + |
| 1254 |
'}') |
| 1255 |
|
| 1256 |
# Space in parens tests - (space_in_paren = "true", space_in_empty_paren = "false") |
| 1257 |
self.reset_options() |
| 1258 |
self.options.space_in_paren = true |
| 1259 |
self.options.space_in_empty_paren = false |
| 1260 |
bt('if(p) foo(a,b);', 'if ( p ) foo( a, b );') |
| 1261 |
bt( |
| 1262 |
'try{while(true){willThrow()}}catch(result)switch(result){case 1:++result }', |
| 1263 |
# -- output -- |
| 1264 |
'try {\n' + |
| 1265 |
' while ( true ) {\n' + |
| 1266 |
' willThrow()\n' + |
| 1267 |
' }\n' + |
| 1268 |
'} catch ( result ) switch ( result ) {\n' + |
| 1269 |
' case 1:\n' + |
| 1270 |
' ++result\n' + |
| 1271 |
'}') |
| 1272 |
bt('((e/((a+(b)*c)-d))^2)*5;', '( ( e / ( ( a + ( b ) * c ) - d ) ) ^ 2 ) * 5;') |
| 1273 |
bt( |
| 1274 |
'function f(a,b) {if(a) b()}function g(a,b) {if(!a) b()}', |
| 1275 |
# -- output -- |
| 1276 |
'function f( a, b ) {\n' + |
| 1277 |
' if ( a ) b()\n' + |
| 1278 |
'}\n' + |
| 1279 |
'\n' + |
| 1280 |
'function g( a, b ) {\n' + |
| 1281 |
' if ( !a ) b()\n' + |
| 1282 |
'}') |
| 1283 |
bt('a=[][ ]( );', 'a = [][]();') |
| 1284 |
bt('a=()( )[ ];', 'a = ()()[];') |
| 1285 |
bt('a=[b,c,d];', 'a = [ b, c, d ];') |
| 1286 |
bt('a= f[b];', 'a = f[ b ];') |
| 1287 |
|
| 1288 |
# Issue #1151 - inside class methods |
| 1289 |
bt( |
| 1290 |
'export default class Test extends Component {\n' + |
| 1291 |
' render() {\n' + |
| 1292 |
' someOther();\n' + |
| 1293 |
' return null;\n' + |
| 1294 |
' }\n' + |
| 1295 |
'}') |
| 1296 |
bt( |
| 1297 |
'{\n' + |
| 1298 |
' files: a[][ {\n' + |
| 1299 |
' expand: true,\n' + |
| 1300 |
' cwd: "www/gui/",\n' + |
| 1301 |
' src: b(c)[ "im/design_standards/*.*" ],\n' + |
| 1302 |
' dest: "www/gui/build"\n' + |
| 1303 |
' } ]\n' + |
| 1304 |
'}', |
| 1305 |
# -- output -- |
| 1306 |
'{\n' + |
| 1307 |
' files: a[][ {\n' + |
| 1308 |
' expand: true,\n' + |
| 1309 |
' cwd: "www/gui/",\n' + |
| 1310 |
' src: b( c )[ "im/design_standards/*.*" ],\n' + |
| 1311 |
' dest: "www/gui/build"\n' + |
| 1312 |
' } ]\n' + |
| 1313 |
'}') |
| 1314 |
|
| 1315 |
# Space in parens tests - (space_in_paren = "true", space_in_empty_paren = "true") |
| 1316 |
self.reset_options() |
| 1317 |
self.options.space_in_paren = true |
| 1318 |
self.options.space_in_empty_paren = true |
| 1319 |
bt('if(p) foo(a,b);', 'if ( p ) foo( a, b );') |
| 1320 |
bt( |
| 1321 |
'try{while(true){willThrow()}}catch(result)switch(result){case 1:++result }', |
| 1322 |
# -- output -- |
| 1323 |
'try {\n' + |
| 1324 |
' while ( true ) {\n' + |
| 1325 |
' willThrow( )\n' + |
| 1326 |
' }\n' + |
| 1327 |
'} catch ( result ) switch ( result ) {\n' + |
| 1328 |
' case 1:\n' + |
| 1329 |
' ++result\n' + |
| 1330 |
'}') |
| 1331 |
bt('((e/((a+(b)*c)-d))^2)*5;', '( ( e / ( ( a + ( b ) * c ) - d ) ) ^ 2 ) * 5;') |
| 1332 |
bt( |
| 1333 |
'function f(a,b) {if(a) b()}function g(a,b) {if(!a) b()}', |
| 1334 |
# -- output -- |
| 1335 |
'function f( a, b ) {\n' + |
| 1336 |
' if ( a ) b( )\n' + |
| 1337 |
'}\n' + |
| 1338 |
'\n' + |
| 1339 |
'function g( a, b ) {\n' + |
| 1340 |
' if ( !a ) b( )\n' + |
| 1341 |
'}') |
| 1342 |
bt('a=[][ ]( );', 'a = [ ][ ]( );') |
| 1343 |
bt('a=()( )[ ];', 'a = ( )( )[ ];') |
| 1344 |
bt('a=[b,c,d];', 'a = [ b, c, d ];') |
| 1345 |
bt('a= f[b];', 'a = f[ b ];') |
| 1346 |
|
| 1347 |
# Issue #1151 - inside class methods |
| 1348 |
bt( |
| 1349 |
'export default class Test extends Component {\n' + |
| 1350 |
' render() {\n' + |
| 1351 |
' someOther();\n' + |
| 1352 |
' return null;\n' + |
| 1353 |
' }\n' + |
| 1354 |
'}', |
| 1355 |
# -- output -- |
| 1356 |
'export default class Test extends Component {\n' + |
| 1357 |
' render( ) {\n' + |
| 1358 |
' someOther( );\n' + |
| 1359 |
' return null;\n' + |
| 1360 |
' }\n' + |
| 1361 |
'}') |
| 1362 |
bt( |
| 1363 |
'{\n' + |
| 1364 |
' files: a[][ {\n' + |
| 1365 |
' expand: true,\n' + |
| 1366 |
' cwd: "www/gui/",\n' + |
| 1367 |
' src: b(c)[ "im/design_standards/*.*" ],\n' + |
| 1368 |
' dest: "www/gui/build"\n' + |
| 1369 |
' } ]\n' + |
| 1370 |
'}', |
| 1371 |
# -- output -- |
| 1372 |
'{\n' + |
| 1373 |
' files: a[ ][ {\n' + |
| 1374 |
' expand: true,\n' + |
| 1375 |
' cwd: "www/gui/",\n' + |
| 1376 |
' src: b( c )[ "im/design_standards/*.*" ],\n' + |
| 1377 |
' dest: "www/gui/build"\n' + |
| 1378 |
' } ]\n' + |
| 1379 |
'}') |
| 1380 |
|
| 1381 |
|
| 1382 |
#============================================================ |
| 1383 |
# general preserve_newlines tests - (preserve_newlines = "false") |
| 1384 |
self.reset_options() |
| 1385 |
self.options.preserve_newlines = false |
| 1386 |
bt( |
| 1387 |
'if (foo) // comment\n' + |
| 1388 |
' bar();') |
| 1389 |
bt( |
| 1390 |
'if (foo) // comment\n' + |
| 1391 |
' bar();') |
| 1392 |
bt( |
| 1393 |
'if (foo) // comment\n' + |
| 1394 |
' (bar());') |
| 1395 |
bt( |
| 1396 |
'if (foo) // comment\n' + |
| 1397 |
' (bar());') |
| 1398 |
bt( |
| 1399 |
'if (foo) // comment\n' + |
| 1400 |
' /asdf/;') |
| 1401 |
bt( |
| 1402 |
'this.oa = new OAuth(\n' + |
| 1403 |
' _requestToken,\n' + |
| 1404 |
' _accessToken,\n' + |
| 1405 |
' consumer_key\n' + |
| 1406 |
');', |
| 1407 |
# -- output -- |
| 1408 |
'this.oa = new OAuth(_requestToken, _accessToken, consumer_key);') |
| 1409 |
bt( |
| 1410 |
'foo = {\n' + |
| 1411 |
' x: y, // #44\n' + |
| 1412 |
' w: z // #44\n' + |
| 1413 |
'}') |
| 1414 |
bt( |
| 1415 |
'switch (x) {\n' + |
| 1416 |
' case "a":\n' + |
| 1417 |
' // comment on newline\n' + |
| 1418 |
' break;\n' + |
| 1419 |
' case "b": // comment on same line\n' + |
| 1420 |
' break;\n' + |
| 1421 |
'}') |
| 1422 |
bt( |
| 1423 |
'this.type =\n' + |
| 1424 |
' this.options =\n' + |
| 1425 |
' // comment\n' + |
| 1426 |
' this.enabled null;', |
| 1427 |
# -- output -- |
| 1428 |
'this.type = this.options =\n' + |
| 1429 |
' // comment\n' + |
| 1430 |
' this.enabled null;') |
| 1431 |
bt( |
| 1432 |
'someObj\n' + |
| 1433 |
' .someFunc1()\n' + |
| 1434 |
' // This comment should not break the indent\n' + |
| 1435 |
' .someFunc2();', |
| 1436 |
# -- output -- |
| 1437 |
'someObj.someFunc1()\n' + |
| 1438 |
' // This comment should not break the indent\n' + |
| 1439 |
' .someFunc2();') |
| 1440 |
bt( |
| 1441 |
'if (true ||\n' + |
| 1442 |
'!true) return;', |
| 1443 |
# -- output -- |
| 1444 |
'if (true || !true) return;') |
| 1445 |
bt( |
| 1446 |
'if\n' + |
| 1447 |
'(foo)\n' + |
| 1448 |
'if\n' + |
| 1449 |
'(bar)\n' + |
| 1450 |
'if\n' + |
| 1451 |
'(baz)\n' + |
| 1452 |
'whee();\n' + |
| 1453 |
'a();', |
| 1454 |
# -- output -- |
| 1455 |
'if (foo)\n' + |
| 1456 |
' if (bar)\n' + |
| 1457 |
' if (baz) whee();\n' + |
| 1458 |
'a();') |
| 1459 |
bt( |
| 1460 |
'if\n' + |
| 1461 |
'(foo)\n' + |
| 1462 |
'if\n' + |
| 1463 |
'(bar)\n' + |
| 1464 |
'if\n' + |
| 1465 |
'(baz)\n' + |
| 1466 |
'whee();\n' + |
| 1467 |
'else\n' + |
| 1468 |
'a();', |
| 1469 |
# -- output -- |
| 1470 |
'if (foo)\n' + |
| 1471 |
' if (bar)\n' + |
| 1472 |
' if (baz) whee();\n' + |
| 1473 |
' else a();') |
| 1474 |
bt( |
| 1475 |
'if (foo)\n' + |
| 1476 |
'bar();\n' + |
| 1477 |
'else\n' + |
| 1478 |
'car();', |
| 1479 |
# -- output -- |
| 1480 |
'if (foo) bar();\n' + |
| 1481 |
'else car();') |
| 1482 |
bt( |
| 1483 |
'if (foo) if (bar) if (baz);\n' + |
| 1484 |
'a();', |
| 1485 |
# -- output -- |
| 1486 |
'if (foo)\n' + |
| 1487 |
' if (bar)\n' + |
| 1488 |
' if (baz);\n' + |
| 1489 |
'a();') |
| 1490 |
bt( |
| 1491 |
'if (foo) if (bar) if (baz) whee();\n' + |
| 1492 |
'a();', |
| 1493 |
# -- output -- |
| 1494 |
'if (foo)\n' + |
| 1495 |
' if (bar)\n' + |
| 1496 |
' if (baz) whee();\n' + |
| 1497 |
'a();') |
| 1498 |
bt( |
| 1499 |
'if (foo) a()\n' + |
| 1500 |
'if (bar) if (baz) whee();\n' + |
| 1501 |
'a();', |
| 1502 |
# -- output -- |
| 1503 |
'if (foo) a()\n' + |
| 1504 |
'if (bar)\n' + |
| 1505 |
' if (baz) whee();\n' + |
| 1506 |
'a();') |
| 1507 |
bt( |
| 1508 |
'if (foo);\n' + |
| 1509 |
'if (bar) if (baz) whee();\n' + |
| 1510 |
'a();', |
| 1511 |
# -- output -- |
| 1512 |
'if (foo);\n' + |
| 1513 |
'if (bar)\n' + |
| 1514 |
' if (baz) whee();\n' + |
| 1515 |
'a();') |
| 1516 |
bt( |
| 1517 |
'if (options)\n' + |
| 1518 |
' for (var p in options)\n' + |
| 1519 |
' this[p] = options[p];', |
| 1520 |
# -- output -- |
| 1521 |
'if (options)\n' + |
| 1522 |
' for (var p in options) this[p] = options[p];') |
| 1523 |
bt( |
| 1524 |
'if (options) for (var p in options) this[p] = options[p];', |
| 1525 |
# -- output -- |
| 1526 |
'if (options)\n' + |
| 1527 |
' for (var p in options) this[p] = options[p];') |
| 1528 |
bt( |
| 1529 |
'if (options) do q(); while (b());', |
| 1530 |
# -- output -- |
| 1531 |
'if (options)\n' + |
| 1532 |
' do q(); while (b());') |
| 1533 |
bt( |
| 1534 |
'if (options) while (b()) q();', |
| 1535 |
# -- output -- |
| 1536 |
'if (options)\n' + |
| 1537 |
' while (b()) q();') |
| 1538 |
bt( |
| 1539 |
'if (options) do while (b()) q(); while (a());', |
| 1540 |
# -- output -- |
| 1541 |
'if (options)\n' + |
| 1542 |
' do\n' + |
| 1543 |
' while (b()) q(); while (a());') |
| 1544 |
bt( |
| 1545 |
'function f(a, b, c,\n' + |
| 1546 |
'd, e) {}', |
| 1547 |
# -- output -- |
| 1548 |
'function f(a, b, c, d, e) {}') |
| 1549 |
bt( |
| 1550 |
'function f(a,b) {if(a) b()}function g(a,b) {if(!a) b()}', |
| 1551 |
# -- output -- |
| 1552 |
'function f(a, b) {\n' + |
| 1553 |
' if (a) b()\n' + |
| 1554 |
'}\n' + |
| 1555 |
'\n' + |
| 1556 |
'function g(a, b) {\n' + |
| 1557 |
' if (!a) b()\n' + |
| 1558 |
'}') |
| 1559 |
bt( |
| 1560 |
'function f(a,b) {if(a) b()}\n' + |
| 1561 |
'\n' + |
| 1562 |
'\n' + |
| 1563 |
'\n' + |
| 1564 |
'function g(a,b) {if(!a) b()}', |
| 1565 |
# -- output -- |
| 1566 |
'function f(a, b) {\n' + |
| 1567 |
' if (a) b()\n' + |
| 1568 |
'}\n' + |
| 1569 |
'\n' + |
| 1570 |
'function g(a, b) {\n' + |
| 1571 |
' if (!a) b()\n' + |
| 1572 |
'}') |
| 1573 |
bt( |
| 1574 |
'(if(a) b())(if(a) b())', |
| 1575 |
# -- output -- |
| 1576 |
'(\n' + |
| 1577 |
' if (a) b())(\n' + |
| 1578 |
' if (a) b())') |
| 1579 |
bt( |
| 1580 |
'(if(a) b())\n' + |
| 1581 |
'\n' + |
| 1582 |
'\n' + |
| 1583 |
'(if(a) b())', |
| 1584 |
# -- output -- |
| 1585 |
'(\n' + |
| 1586 |
' if (a) b())\n' + |
| 1587 |
'(\n' + |
| 1588 |
' if (a) b())') |
| 1589 |
bt( |
| 1590 |
'if\n' + |
| 1591 |
'(a)\n' + |
| 1592 |
'b();', |
| 1593 |
# -- output -- |
| 1594 |
'if (a) b();') |
| 1595 |
bt( |
| 1596 |
'var a =\n' + |
| 1597 |
'foo', |
| 1598 |
# -- output -- |
| 1599 |
'var a = foo') |
| 1600 |
bt( |
| 1601 |
'var a = {\n' + |
| 1602 |
'"a":1,\n' + |
| 1603 |
'"b":2}', |
| 1604 |
# -- output -- |
| 1605 |
'var a = {\n' + |
| 1606 |
' "a": 1,\n' + |
| 1607 |
' "b": 2\n' + |
| 1608 |
'}') |
| 1609 |
bt( |
| 1610 |
'var a = {\n' + |
| 1611 |
'\'a\':1,\n' + |
| 1612 |
'\'b\':2}', |
| 1613 |
# -- output -- |
| 1614 |
'var a = {\n' + |
| 1615 |
' \'a\': 1,\n' + |
| 1616 |
' \'b\': 2\n' + |
| 1617 |
'}') |
| 1618 |
bt('var a = /*i*/ "b";') |
| 1619 |
bt( |
| 1620 |
'var a = /*i*/\n' + |
| 1621 |
'"b";', |
| 1622 |
# -- output -- |
| 1623 |
'var a = /*i*/ "b";') |
| 1624 |
bt( |
| 1625 |
'{\n' + |
| 1626 |
'\n' + |
| 1627 |
'\n' + |
| 1628 |
'"x"\n' + |
| 1629 |
'}', |
| 1630 |
# -- output -- |
| 1631 |
'{\n' + |
| 1632 |
' "x"\n' + |
| 1633 |
'}') |
| 1634 |
bt( |
| 1635 |
'if(a &&\n' + |
| 1636 |
'b\n' + |
| 1637 |
'||\n' + |
| 1638 |
'c\n' + |
| 1639 |
'||d\n' + |
| 1640 |
'&&\n' + |
| 1641 |
'e) e = f', |
| 1642 |
# -- output -- |
| 1643 |
'if (a && b || c || d && e) e = f') |
| 1644 |
bt( |
| 1645 |
'if(a &&\n' + |
| 1646 |
'(b\n' + |
| 1647 |
'||\n' + |
| 1648 |
'c\n' + |
| 1649 |
'||d)\n' + |
| 1650 |
'&&\n' + |
| 1651 |
'e) e = f', |
| 1652 |
# -- output -- |
| 1653 |
'if (a && (b || c || d) && e) e = f') |
| 1654 |
test_fragment( |
| 1655 |
'\n' + |
| 1656 |
'\n' + |
| 1657 |
'"x"', |
| 1658 |
# -- output -- |
| 1659 |
'"x"') |
| 1660 |
test_fragment( |
| 1661 |
'{\n' + |
| 1662 |
'\n' + |
| 1663 |
'"x"\n' + |
| 1664 |
'h=5;\n' + |
| 1665 |
'}', |
| 1666 |
# -- output -- |
| 1667 |
'{\n' + |
| 1668 |
' "x"\n' + |
| 1669 |
' h = 5;\n' + |
| 1670 |
'}') |
| 1671 |
bt( |
| 1672 |
'var a = "foo" +\n' + |
| 1673 |
' "bar";', |
| 1674 |
# -- output -- |
| 1675 |
'var a = "foo" + "bar";') |
| 1676 |
bt( |
| 1677 |
'var a = 42; // foo\n' + |
| 1678 |
'\n' + |
| 1679 |
'var b;', |
| 1680 |
# -- output -- |
| 1681 |
'var a = 42; // foo\n' + |
| 1682 |
'var b;') |
| 1683 |
bt( |
| 1684 |
'var a = 42; // foo\n' + |
| 1685 |
'\n' + |
| 1686 |
'\n' + |
| 1687 |
'var b;', |
| 1688 |
# -- output -- |
| 1689 |
'var a = 42; // foo\n' + |
| 1690 |
'var b;') |
| 1691 |
bt( |
| 1692 |
'a = 1;\n' + |
| 1693 |
'\n' + |
| 1694 |
'\n' + |
| 1695 |
'\n' + |
| 1696 |
'\n' + |
| 1697 |
'\n' + |
| 1698 |
'\n' + |
| 1699 |
'\n' + |
| 1700 |
'\n' + |
| 1701 |
'\n' + |
| 1702 |
'\n' + |
| 1703 |
'\n' + |
| 1704 |
'\n' + |
| 1705 |
'\n' + |
| 1706 |
'\n' + |
| 1707 |
'\n' + |
| 1708 |
'\n' + |
| 1709 |
'\n' + |
| 1710 |
'\n' + |
| 1711 |
'\n' + |
| 1712 |
'\n' + |
| 1713 |
'\n' + |
| 1714 |
'b = 2;', |
| 1715 |
# -- output -- |
| 1716 |
'a = 1;\n' + |
| 1717 |
'b = 2;') |
| 1718 |
|
| 1719 |
# general preserve_newlines tests - (preserve_newlines = "true") |
| 1720 |
self.reset_options() |
| 1721 |
self.options.preserve_newlines = true |
| 1722 |
bt( |
| 1723 |
'if (foo) // comment\n' + |
| 1724 |
' bar();') |
| 1725 |
bt( |
| 1726 |
'if (foo) // comment\n' + |
| 1727 |
' bar();') |
| 1728 |
bt( |
| 1729 |
'if (foo) // comment\n' + |
| 1730 |
' (bar());') |
| 1731 |
bt( |
| 1732 |
'if (foo) // comment\n' + |
| 1733 |
' (bar());') |
| 1734 |
bt( |
| 1735 |
'if (foo) // comment\n' + |
| 1736 |
' /asdf/;') |
| 1737 |
bt( |
| 1738 |
'this.oa = new OAuth(\n' + |
| 1739 |
' _requestToken,\n' + |
| 1740 |
' _accessToken,\n' + |
| 1741 |
' consumer_key\n' + |
| 1742 |
');') |
| 1743 |
bt( |
| 1744 |
'foo = {\n' + |
| 1745 |
' x: y, // #44\n' + |
| 1746 |
' w: z // #44\n' + |
| 1747 |
'}') |
| 1748 |
bt( |
| 1749 |
'switch (x) {\n' + |
| 1750 |
' case "a":\n' + |
| 1751 |
' // comment on newline\n' + |
| 1752 |
' break;\n' + |
| 1753 |
' case "b": // comment on same line\n' + |
| 1754 |
' break;\n' + |
| 1755 |
'}') |
| 1756 |
bt( |
| 1757 |
'this.type =\n' + |
| 1758 |
' this.options =\n' + |
| 1759 |
' // comment\n' + |
| 1760 |
' this.enabled null;') |
| 1761 |
bt( |
| 1762 |
'someObj\n' + |
| 1763 |
' .someFunc1()\n' + |
| 1764 |
' // This comment should not break the indent\n' + |
| 1765 |
' .someFunc2();') |
| 1766 |
bt( |
| 1767 |
'if (true ||\n' + |
| 1768 |
'!true) return;', |
| 1769 |
# -- output -- |
| 1770 |
'if (true ||\n' + |
| 1771 |
' !true) return;') |
| 1772 |
bt( |
| 1773 |
'if\n' + |
| 1774 |
'(foo)\n' + |
| 1775 |
'if\n' + |
| 1776 |
'(bar)\n' + |
| 1777 |
'if\n' + |
| 1778 |
'(baz)\n' + |
| 1779 |
'whee();\n' + |
| 1780 |
'a();', |
| 1781 |
# -- output -- |
| 1782 |
'if (foo)\n' + |
| 1783 |
' if (bar)\n' + |
| 1784 |
' if (baz)\n' + |
| 1785 |
' whee();\n' + |
| 1786 |
'a();') |
| 1787 |
bt( |
| 1788 |
'if\n' + |
| 1789 |
'(foo)\n' + |
| 1790 |
'if\n' + |
| 1791 |
'(bar)\n' + |
| 1792 |
'if\n' + |
| 1793 |
'(baz)\n' + |
| 1794 |
'whee();\n' + |
| 1795 |
'else\n' + |
| 1796 |
'a();', |
| 1797 |
# -- output -- |
| 1798 |
'if (foo)\n' + |
| 1799 |
' if (bar)\n' + |
| 1800 |
' if (baz)\n' + |
| 1801 |
' whee();\n' + |
| 1802 |
' else\n' + |
| 1803 |
' a();') |
| 1804 |
bt( |
| 1805 |
'if (foo)\n' + |
| 1806 |
'bar();\n' + |
| 1807 |
'else\n' + |
| 1808 |
'car();', |
| 1809 |
# -- output -- |
| 1810 |
'if (foo)\n' + |
| 1811 |
' bar();\n' + |
| 1812 |
'else\n' + |
| 1813 |
' car();') |
| 1814 |
bt( |
| 1815 |
'if (foo) if (bar) if (baz);\n' + |
| 1816 |
'a();', |
| 1817 |
# -- output -- |
| 1818 |
'if (foo)\n' + |
| 1819 |
' if (bar)\n' + |
| 1820 |
' if (baz);\n' + |
| 1821 |
'a();') |
| 1822 |
bt( |
| 1823 |
'if (foo) if (bar) if (baz) whee();\n' + |
| 1824 |
'a();', |
| 1825 |
# -- output -- |
| 1826 |
'if (foo)\n' + |
| 1827 |
' if (bar)\n' + |
| 1828 |
' if (baz) whee();\n' + |
| 1829 |
'a();') |
| 1830 |
bt( |
| 1831 |
'if (foo) a()\n' + |
| 1832 |
'if (bar) if (baz) whee();\n' + |
| 1833 |
'a();', |
| 1834 |
# -- output -- |
| 1835 |
'if (foo) a()\n' + |
| 1836 |
'if (bar)\n' + |
| 1837 |
' if (baz) whee();\n' + |
| 1838 |
'a();') |
| 1839 |
bt( |
| 1840 |
'if (foo);\n' + |
| 1841 |
'if (bar) if (baz) whee();\n' + |
| 1842 |
'a();', |
| 1843 |
# -- output -- |
| 1844 |
'if (foo);\n' + |
| 1845 |
'if (bar)\n' + |
| 1846 |
' if (baz) whee();\n' + |
| 1847 |
'a();') |
| 1848 |
bt( |
| 1849 |
'if (options)\n' + |
| 1850 |
' for (var p in options)\n' + |
| 1851 |
' this[p] = options[p];') |
| 1852 |
bt( |
| 1853 |
'if (options) for (var p in options) this[p] = options[p];', |
| 1854 |
# -- output -- |
| 1855 |
'if (options)\n' + |
| 1856 |
' for (var p in options) this[p] = options[p];') |
| 1857 |
bt( |
| 1858 |
'if (options) do q(); while (b());', |
| 1859 |
# -- output -- |
| 1860 |
'if (options)\n' + |
| 1861 |
' do q(); while (b());') |
| 1862 |
bt( |
| 1863 |
'if (options) while (b()) q();', |
| 1864 |
# -- output -- |
| 1865 |
'if (options)\n' + |
| 1866 |
' while (b()) q();') |
| 1867 |
bt( |
| 1868 |
'if (options) do while (b()) q(); while (a());', |
| 1869 |
# -- output -- |
| 1870 |
'if (options)\n' + |
| 1871 |
' do\n' + |
| 1872 |
' while (b()) q(); while (a());') |
| 1873 |
bt( |
| 1874 |
'function f(a, b, c,\n' + |
| 1875 |
'd, e) {}', |
| 1876 |
# -- output -- |
| 1877 |
'function f(a, b, c,\n' + |
| 1878 |
' d, e) {}') |
| 1879 |
bt( |
| 1880 |
'function f(a,b) {if(a) b()}function g(a,b) {if(!a) b()}', |
| 1881 |
# -- output -- |
| 1882 |
'function f(a, b) {\n' + |
| 1883 |
' if (a) b()\n' + |
| 1884 |
'}\n' + |
| 1885 |
'\n' + |
| 1886 |
'function g(a, b) {\n' + |
| 1887 |
' if (!a) b()\n' + |
| 1888 |
'}') |
| 1889 |
bt( |
| 1890 |
'function f(a,b) {if(a) b()}\n' + |
| 1891 |
'\n' + |
| 1892 |
'\n' + |
| 1893 |
'\n' + |
| 1894 |
'function g(a,b) {if(!a) b()}', |
| 1895 |
# -- output -- |
| 1896 |
'function f(a, b) {\n' + |
| 1897 |
' if (a) b()\n' + |
| 1898 |
'}\n' + |
| 1899 |
'\n' + |
| 1900 |
'\n' + |
| 1901 |
'\n' + |
| 1902 |
'function g(a, b) {\n' + |
| 1903 |
' if (!a) b()\n' + |
| 1904 |
'}') |
| 1905 |
bt( |
| 1906 |
'(if(a) b())(if(a) b())', |
| 1907 |
# -- output -- |
| 1908 |
'(\n' + |
| 1909 |
' if (a) b())(\n' + |
| 1910 |
' if (a) b())') |
| 1911 |
bt( |
| 1912 |
'(if(a) b())\n' + |
| 1913 |
'\n' + |
| 1914 |
'\n' + |
| 1915 |
'(if(a) b())', |
| 1916 |
# -- output -- |
| 1917 |
'(\n' + |
| 1918 |
' if (a) b())\n' + |
| 1919 |
'\n' + |
| 1920 |
'\n' + |
| 1921 |
'(\n' + |
| 1922 |
' if (a) b())') |
| 1923 |
bt( |
| 1924 |
'if\n' + |
| 1925 |
'(a)\n' + |
| 1926 |
'b();', |
| 1927 |
# -- output -- |
| 1928 |
'if (a)\n' + |
| 1929 |
' b();') |
| 1930 |
bt( |
| 1931 |
'var a =\n' + |
| 1932 |
'foo', |
| 1933 |
# -- output -- |
| 1934 |
'var a =\n' + |
| 1935 |
' foo') |
| 1936 |
bt( |
| 1937 |
'var a = {\n' + |
| 1938 |
'"a":1,\n' + |
| 1939 |
'"b":2}', |
| 1940 |
# -- output -- |
| 1941 |
'var a = {\n' + |
| 1942 |
' "a": 1,\n' + |
| 1943 |
' "b": 2\n' + |
| 1944 |
'}') |
| 1945 |
bt( |
| 1946 |
'var a = {\n' + |
| 1947 |
'\'a\':1,\n' + |
| 1948 |
'\'b\':2}', |
| 1949 |
# -- output -- |
| 1950 |
'var a = {\n' + |
| 1951 |
' \'a\': 1,\n' + |
| 1952 |
' \'b\': 2\n' + |
| 1953 |
'}') |
| 1954 |
bt('var a = /*i*/ "b";') |
| 1955 |
bt( |
| 1956 |
'var a = /*i*/\n' + |
| 1957 |
'"b";', |
| 1958 |
# -- output -- |
| 1959 |
'var a = /*i*/\n' + |
| 1960 |
' "b";') |
| 1961 |
bt( |
| 1962 |
'{\n' + |
| 1963 |
'\n' + |
| 1964 |
'\n' + |
| 1965 |
'"x"\n' + |
| 1966 |
'}', |
| 1967 |
# -- output -- |
| 1968 |
'{\n' + |
| 1969 |
'\n' + |
| 1970 |
'\n' + |
| 1971 |
' "x"\n' + |
| 1972 |
'}') |
| 1973 |
bt( |
| 1974 |
'if(a &&\n' + |
| 1975 |
'b\n' + |
| 1976 |
'||\n' + |
| 1977 |
'c\n' + |
| 1978 |
'||d\n' + |
| 1979 |
'&&\n' + |
| 1980 |
'e) e = f', |
| 1981 |
# -- output -- |
| 1982 |
'if (a &&\n' + |
| 1983 |
' b ||\n' + |
| 1984 |
' c ||\n' + |
| 1985 |
' d &&\n' + |
| 1986 |
' e) e = f') |
| 1987 |
bt( |
| 1988 |
'if(a &&\n' + |
| 1989 |
'(b\n' + |
| 1990 |
'||\n' + |
| 1991 |
'c\n' + |
| 1992 |
'||d)\n' + |
| 1993 |
'&&\n' + |
| 1994 |
'e) e = f', |
| 1995 |
# -- output -- |
| 1996 |
'if (a &&\n' + |
| 1997 |
' (b ||\n' + |
| 1998 |
' c ||\n' + |
| 1999 |
' d) &&\n' + |
| 2000 |
' e) e = f') |
| 2001 |
test_fragment( |
| 2002 |
'\n' + |
| 2003 |
'\n' + |
| 2004 |
'"x"', |
| 2005 |
# -- output -- |
| 2006 |
'"x"') |
| 2007 |
test_fragment( |
| 2008 |
'{\n' + |
| 2009 |
'\n' + |
| 2010 |
'"x"\n' + |
| 2011 |
'h=5;\n' + |
| 2012 |
'}', |
| 2013 |
# -- output -- |
| 2014 |
'{\n' + |
| 2015 |
'\n' + |
| 2016 |
' "x"\n' + |
| 2017 |
' h = 5;\n' + |
| 2018 |
'}') |
| 2019 |
bt( |
| 2020 |
'var a = "foo" +\n' + |
| 2021 |
' "bar";') |
| 2022 |
bt( |
| 2023 |
'var a = 42; // foo\n' + |
| 2024 |
'\n' + |
| 2025 |
'var b;') |
| 2026 |
bt( |
| 2027 |
'var a = 42; // foo\n' + |
| 2028 |
'\n' + |
| 2029 |
'\n' + |
| 2030 |
'var b;') |
| 2031 |
bt( |
| 2032 |
'a = 1;\n' + |
| 2033 |
'\n' + |
| 2034 |
'\n' + |
| 2035 |
'\n' + |
| 2036 |
'\n' + |
| 2037 |
'\n' + |
| 2038 |
'\n' + |
| 2039 |
'\n' + |
| 2040 |
'\n' + |
| 2041 |
'\n' + |
| 2042 |
'\n' + |
| 2043 |
'\n' + |
| 2044 |
'\n' + |
| 2045 |
'\n' + |
| 2046 |
'\n' + |
| 2047 |
'\n' + |
| 2048 |
'\n' + |
| 2049 |
'\n' + |
| 2050 |
'\n' + |
| 2051 |
'\n' + |
| 2052 |
'\n' + |
| 2053 |
'\n' + |
| 2054 |
'b = 2;') |
| 2055 |
|
| 2056 |
|
| 2057 |
#============================================================ |
| 2058 |
# break chained methods - (break_chained_methods = "false", preserve_newlines = "false") |
| 2059 |
self.reset_options() |
| 2060 |
self.options.break_chained_methods = false |
| 2061 |
self.options.preserve_newlines = false |
| 2062 |
bt( |
| 2063 |
'foo\n' + |
| 2064 |
'.bar()\n' + |
| 2065 |
'.baz().cucumber(fat)', |
| 2066 |
# -- output -- |
| 2067 |
'foo.bar().baz().cucumber(fat)') |
| 2068 |
bt( |
| 2069 |
'foo\n' + |
| 2070 |
'.bar()\n' + |
| 2071 |
'.baz().cucumber(fat); foo.bar().baz().cucumber(fat)', |
| 2072 |
# -- output -- |
| 2073 |
'foo.bar().baz().cucumber(fat);\n' + |
| 2074 |
'foo.bar().baz().cucumber(fat)') |
| 2075 |
bt( |
| 2076 |
'foo\n' + |
| 2077 |
'.bar()\n' + |
| 2078 |
'.baz().cucumber(fat)\n' + |
| 2079 |
' foo.bar().baz().cucumber(fat)', |
| 2080 |
# -- output -- |
| 2081 |
'foo.bar().baz().cucumber(fat)\n' + |
| 2082 |
'foo.bar().baz().cucumber(fat)') |
| 2083 |
bt( |
| 2084 |
'this\n' + |
| 2085 |
'.something = foo.bar()\n' + |
| 2086 |
'.baz().cucumber(fat)', |
| 2087 |
# -- output -- |
| 2088 |
'this.something = foo.bar().baz().cucumber(fat)') |
| 2089 |
bt('this.something.xxx = foo.moo.bar()') |
| 2090 |
bt( |
| 2091 |
'this\n' + |
| 2092 |
'.something\n' + |
| 2093 |
'.xxx = foo.moo\n' + |
| 2094 |
'.bar()', |
| 2095 |
# -- output -- |
| 2096 |
'this.something.xxx = foo.moo.bar()') |
| 2097 |
|
| 2098 |
# optional chaining operator |
| 2099 |
bt( |
| 2100 |
'foo\n' + |
| 2101 |
'?.bar()\n' + |
| 2102 |
'?.baz()?.cucumber(fat)', |
| 2103 |
# -- output -- |
| 2104 |
'foo?.bar()?.baz()?.cucumber(fat)') |
| 2105 |
bt( |
| 2106 |
'foo\n' + |
| 2107 |
'?.bar()\n' + |
| 2108 |
'?.baz()?.cucumber(fat); foo?.bar()?.baz()?.cucumber(fat)', |
| 2109 |
# -- output -- |
| 2110 |
'foo?.bar()?.baz()?.cucumber(fat);\n' + |
| 2111 |
'foo?.bar()?.baz()?.cucumber(fat)') |
| 2112 |
bt( |
| 2113 |
'foo\n' + |
| 2114 |
'?.bar()\n' + |
| 2115 |
'?.baz()?.cucumber(fat)\n' + |
| 2116 |
' foo?.bar()?.baz()?.cucumber(fat)', |
| 2117 |
# -- output -- |
| 2118 |
'foo?.bar()?.baz()?.cucumber(fat)\n' + |
| 2119 |
'foo?.bar()?.baz()?.cucumber(fat)') |
| 2120 |
bt( |
| 2121 |
'this\n' + |
| 2122 |
'?.something = foo?.bar()\n' + |
| 2123 |
'?.baz()?.cucumber(fat)', |
| 2124 |
# -- output -- |
| 2125 |
'this?.something = foo?.bar()?.baz()?.cucumber(fat)') |
| 2126 |
bt('this?.something?.xxx = foo?.moo?.bar()') |
| 2127 |
bt( |
| 2128 |
'this\n' + |
| 2129 |
'?.something\n' + |
| 2130 |
'?.xxx = foo?.moo\n' + |
| 2131 |
'?.bar()', |
| 2132 |
# -- output -- |
| 2133 |
'this?.something?.xxx = foo?.moo?.bar()') |
| 2134 |
|
| 2135 |
# break chained methods - (break_chained_methods = "false", preserve_newlines = "true") |
| 2136 |
self.reset_options() |
| 2137 |
self.options.break_chained_methods = false |
| 2138 |
self.options.preserve_newlines = true |
| 2139 |
bt( |
| 2140 |
'foo\n' + |
| 2141 |
'.bar()\n' + |
| 2142 |
'.baz().cucumber(fat)', |
| 2143 |
# -- output -- |
| 2144 |
'foo\n' + |
| 2145 |
' .bar()\n' + |
| 2146 |
' .baz().cucumber(fat)') |
| 2147 |
bt( |
| 2148 |
'foo\n' + |
| 2149 |
'.bar()\n' + |
| 2150 |
'.baz().cucumber(fat); foo.bar().baz().cucumber(fat)', |
| 2151 |
# -- output -- |
| 2152 |
'foo\n' + |
| 2153 |
' .bar()\n' + |
| 2154 |
' .baz().cucumber(fat);\n' + |
| 2155 |
'foo.bar().baz().cucumber(fat)') |
| 2156 |
bt( |
| 2157 |
'foo\n' + |
| 2158 |
'.bar()\n' + |
| 2159 |
'.baz().cucumber(fat)\n' + |
| 2160 |
' foo.bar().baz().cucumber(fat)', |
| 2161 |
# -- output -- |
| 2162 |
'foo\n' + |
| 2163 |
' .bar()\n' + |
| 2164 |
' .baz().cucumber(fat)\n' + |
| 2165 |
'foo.bar().baz().cucumber(fat)') |
| 2166 |
bt( |
| 2167 |
'this\n' + |
| 2168 |
'.something = foo.bar()\n' + |
| 2169 |
'.baz().cucumber(fat)', |
| 2170 |
# -- output -- |
| 2171 |
'this\n' + |
| 2172 |
' .something = foo.bar()\n' + |
| 2173 |
' .baz().cucumber(fat)') |
| 2174 |
bt('this.something.xxx = foo.moo.bar()') |
| 2175 |
bt( |
| 2176 |
'this\n' + |
| 2177 |
'.something\n' + |
| 2178 |
'.xxx = foo.moo\n' + |
| 2179 |
'.bar()', |
| 2180 |
# -- output -- |
| 2181 |
'this\n' + |
| 2182 |
' .something\n' + |
| 2183 |
' .xxx = foo.moo\n' + |
| 2184 |
' .bar()') |
| 2185 |
|
| 2186 |
# optional chaining operator |
| 2187 |
bt( |
| 2188 |
'foo\n' + |
| 2189 |
'?.bar()\n' + |
| 2190 |
'?.baz()?.cucumber(fat)', |
| 2191 |
# -- output -- |
| 2192 |
'foo\n' + |
| 2193 |
' ?.bar()\n' + |
| 2194 |
' ?.baz()?.cucumber(fat)') |
| 2195 |
bt( |
| 2196 |
'foo\n' + |
| 2197 |
'?.bar()\n' + |
| 2198 |
'?.baz()?.cucumber(fat); foo?.bar()?.baz()?.cucumber(fat)', |
| 2199 |
# -- output -- |
| 2200 |
'foo\n' + |
| 2201 |
' ?.bar()\n' + |
| 2202 |
' ?.baz()?.cucumber(fat);\n' + |
| 2203 |
'foo?.bar()?.baz()?.cucumber(fat)') |
| 2204 |
bt( |
| 2205 |
'foo\n' + |
| 2206 |
'?.bar()\n' + |
| 2207 |
'?.baz()?.cucumber(fat)\n' + |
| 2208 |
' foo?.bar()?.baz()?.cucumber(fat)', |
| 2209 |
# -- output -- |
| 2210 |
'foo\n' + |
| 2211 |
' ?.bar()\n' + |
| 2212 |
' ?.baz()?.cucumber(fat)\n' + |
| 2213 |
'foo?.bar()?.baz()?.cucumber(fat)') |
| 2214 |
bt( |
| 2215 |
'this\n' + |
| 2216 |
'?.something = foo?.bar()\n' + |
| 2217 |
'?.baz()?.cucumber(fat)', |
| 2218 |
# -- output -- |
| 2219 |
'this\n' + |
| 2220 |
' ?.something = foo?.bar()\n' + |
| 2221 |
' ?.baz()?.cucumber(fat)') |
| 2222 |
bt('this?.something?.xxx = foo?.moo?.bar()') |
| 2223 |
bt( |
| 2224 |
'this\n' + |
| 2225 |
'?.something\n' + |
| 2226 |
'?.xxx = foo?.moo\n' + |
| 2227 |
'?.bar()', |
| 2228 |
# -- output -- |
| 2229 |
'this\n' + |
| 2230 |
' ?.something\n' + |
| 2231 |
' ?.xxx = foo?.moo\n' + |
| 2232 |
' ?.bar()') |
| 2233 |
|
| 2234 |
# break chained methods - (break_chained_methods = "true", preserve_newlines = "false") |
| 2235 |
self.reset_options() |
| 2236 |
self.options.break_chained_methods = true |
| 2237 |
self.options.preserve_newlines = false |
| 2238 |
bt( |
| 2239 |
'foo\n' + |
| 2240 |
'.bar()\n' + |
| 2241 |
'.baz().cucumber(fat)', |
| 2242 |
# -- output -- |
| 2243 |
'foo.bar()\n' + |
| 2244 |
' .baz()\n' + |
| 2245 |
' .cucumber(fat)') |
| 2246 |
bt( |
| 2247 |
'foo\n' + |
| 2248 |
'.bar()\n' + |
| 2249 |
'.baz().cucumber(fat); foo.bar().baz().cucumber(fat)', |
| 2250 |
# -- output -- |
| 2251 |
'foo.bar()\n' + |
| 2252 |
' .baz()\n' + |
| 2253 |
' .cucumber(fat);\n' + |
| 2254 |
'foo.bar()\n' + |
| 2255 |
' .baz()\n' + |
| 2256 |
' .cucumber(fat)') |
| 2257 |
bt( |
| 2258 |
'foo\n' + |
| 2259 |
'.bar()\n' + |
| 2260 |
'.baz().cucumber(fat)\n' + |
| 2261 |
' foo.bar().baz().cucumber(fat)', |
| 2262 |
# -- output -- |
| 2263 |
'foo.bar()\n' + |
| 2264 |
' .baz()\n' + |
| 2265 |
' .cucumber(fat)\n' + |
| 2266 |
'foo.bar()\n' + |
| 2267 |
' .baz()\n' + |
| 2268 |
' .cucumber(fat)') |
| 2269 |
bt( |
| 2270 |
'this\n' + |
| 2271 |
'.something = foo.bar()\n' + |
| 2272 |
'.baz().cucumber(fat)', |
| 2273 |
# -- output -- |
| 2274 |
'this.something = foo.bar()\n' + |
| 2275 |
' .baz()\n' + |
| 2276 |
' .cucumber(fat)') |
| 2277 |
bt('this.something.xxx = foo.moo.bar()') |
| 2278 |
bt( |
| 2279 |
'this\n' + |
| 2280 |
'.something\n' + |
| 2281 |
'.xxx = foo.moo\n' + |
| 2282 |
'.bar()', |
| 2283 |
# -- output -- |
| 2284 |
'this.something.xxx = foo.moo.bar()') |
| 2285 |
|
| 2286 |
# optional chaining operator |
| 2287 |
bt( |
| 2288 |
'foo\n' + |
| 2289 |
'?.bar()\n' + |
| 2290 |
'?.baz()?.cucumber(fat)', |
| 2291 |
# -- output -- |
| 2292 |
'foo?.bar()\n' + |
| 2293 |
' ?.baz()\n' + |
| 2294 |
' ?.cucumber(fat)') |
| 2295 |
bt( |
| 2296 |
'foo\n' + |
| 2297 |
'?.bar()\n' + |
| 2298 |
'?.baz()?.cucumber(fat); foo?.bar()?.baz()?.cucumber(fat)', |
| 2299 |
# -- output -- |
| 2300 |
'foo?.bar()\n' + |
| 2301 |
' ?.baz()\n' + |
| 2302 |
' ?.cucumber(fat);\n' + |
| 2303 |
'foo?.bar()\n' + |
| 2304 |
' ?.baz()\n' + |
| 2305 |
' ?.cucumber(fat)') |
| 2306 |
bt( |
| 2307 |
'foo\n' + |
| 2308 |
'?.bar()\n' + |
| 2309 |
'?.baz()?.cucumber(fat)\n' + |
| 2310 |
' foo?.bar()?.baz()?.cucumber(fat)', |
| 2311 |
# -- output -- |
| 2312 |
'foo?.bar()\n' + |
| 2313 |
' ?.baz()\n' + |
| 2314 |
' ?.cucumber(fat)\n' + |
| 2315 |
'foo?.bar()\n' + |
| 2316 |
' ?.baz()\n' + |
| 2317 |
' ?.cucumber(fat)') |
| 2318 |
bt( |
| 2319 |
'this\n' + |
| 2320 |
'?.something = foo?.bar()\n' + |
| 2321 |
'?.baz()?.cucumber(fat)', |
| 2322 |
# -- output -- |
| 2323 |
'this?.something = foo?.bar()\n' + |
| 2324 |
' ?.baz()\n' + |
| 2325 |
' ?.cucumber(fat)') |
| 2326 |
bt('this?.something?.xxx = foo?.moo?.bar()') |
| 2327 |
bt( |
| 2328 |
'this\n' + |
| 2329 |
'?.something\n' + |
| 2330 |
'?.xxx = foo?.moo\n' + |
| 2331 |
'?.bar()', |
| 2332 |
# -- output -- |
| 2333 |
'this?.something?.xxx = foo?.moo?.bar()') |
| 2334 |
|
| 2335 |
# break chained methods - (break_chained_methods = "true", preserve_newlines = "true") |
| 2336 |
self.reset_options() |
| 2337 |
self.options.break_chained_methods = true |
| 2338 |
self.options.preserve_newlines = true |
| 2339 |
bt( |
| 2340 |
'foo\n' + |
| 2341 |
'.bar()\n' + |
| 2342 |
'.baz().cucumber(fat)', |
| 2343 |
# -- output -- |
| 2344 |
'foo\n' + |
| 2345 |
' .bar()\n' + |
| 2346 |
' .baz()\n' + |
| 2347 |
' .cucumber(fat)') |
| 2348 |
bt( |
| 2349 |
'foo\n' + |
| 2350 |
'.bar()\n' + |
| 2351 |
'.baz().cucumber(fat); foo.bar().baz().cucumber(fat)', |
| 2352 |
# -- output -- |
| 2353 |
'foo\n' + |
| 2354 |
' .bar()\n' + |
| 2355 |
' .baz()\n' + |
| 2356 |
' .cucumber(fat);\n' + |
| 2357 |
'foo.bar()\n' + |
| 2358 |
' .baz()\n' + |
| 2359 |
' .cucumber(fat)') |
| 2360 |
bt( |
| 2361 |
'foo\n' + |
| 2362 |
'.bar()\n' + |
| 2363 |
'.baz().cucumber(fat)\n' + |
| 2364 |
' foo.bar().baz().cucumber(fat)', |
| 2365 |
# -- output -- |
| 2366 |
'foo\n' + |
| 2367 |
' .bar()\n' + |
| 2368 |
' .baz()\n' + |
| 2369 |
' .cucumber(fat)\n' + |
| 2370 |
'foo.bar()\n' + |
| 2371 |
' .baz()\n' + |
| 2372 |
' .cucumber(fat)') |
| 2373 |
bt( |
| 2374 |
'this\n' + |
| 2375 |
'.something = foo.bar()\n' + |
| 2376 |
'.baz().cucumber(fat)', |
| 2377 |
# -- output -- |
| 2378 |
'this\n' + |
| 2379 |
' .something = foo.bar()\n' + |
| 2380 |
' .baz()\n' + |
| 2381 |
' .cucumber(fat)') |
| 2382 |
bt('this.something.xxx = foo.moo.bar()') |
| 2383 |
bt( |
| 2384 |
'this\n' + |
| 2385 |
'.something\n' + |
| 2386 |
'.xxx = foo.moo\n' + |
| 2387 |
'.bar()', |
| 2388 |
# -- output -- |
| 2389 |
'this\n' + |
| 2390 |
' .something\n' + |
| 2391 |
' .xxx = foo.moo\n' + |
| 2392 |
' .bar()') |
| 2393 |
|
| 2394 |
# optional chaining operator |
| 2395 |
bt( |
| 2396 |
'foo\n' + |
| 2397 |
'?.bar()\n' + |
| 2398 |
'?.baz()?.cucumber(fat)', |
| 2399 |
# -- output -- |
| 2400 |
'foo\n' + |
| 2401 |
' ?.bar()\n' + |
| 2402 |
' ?.baz()\n' + |
| 2403 |
' ?.cucumber(fat)') |
| 2404 |
bt( |
| 2405 |
'foo\n' + |
| 2406 |
'?.bar()\n' + |
| 2407 |
'?.baz()?.cucumber(fat); foo?.bar()?.baz()?.cucumber(fat)', |
| 2408 |
# -- output -- |
| 2409 |
'foo\n' + |
| 2410 |
' ?.bar()\n' + |
| 2411 |
' ?.baz()\n' + |
| 2412 |
' ?.cucumber(fat);\n' + |
| 2413 |
'foo?.bar()\n' + |
| 2414 |
' ?.baz()\n' + |
| 2415 |
' ?.cucumber(fat)') |
| 2416 |
bt( |
| 2417 |
'foo\n' + |
| 2418 |
'?.bar()\n' + |
| 2419 |
'?.baz()?.cucumber(fat)\n' + |
| 2420 |
' foo?.bar()?.baz()?.cucumber(fat)', |
| 2421 |
# -- output -- |
| 2422 |
'foo\n' + |
| 2423 |
' ?.bar()\n' + |
| 2424 |
' ?.baz()\n' + |
| 2425 |
' ?.cucumber(fat)\n' + |
| 2426 |
'foo?.bar()\n' + |
| 2427 |
' ?.baz()\n' + |
| 2428 |
' ?.cucumber(fat)') |
| 2429 |
bt( |
| 2430 |
'this\n' + |
| 2431 |
'?.something = foo?.bar()\n' + |
| 2432 |
'?.baz()?.cucumber(fat)', |
| 2433 |
# -- output -- |
| 2434 |
'this\n' + |
| 2435 |
' ?.something = foo?.bar()\n' + |
| 2436 |
' ?.baz()\n' + |
| 2437 |
' ?.cucumber(fat)') |
| 2438 |
bt('this?.something?.xxx = foo?.moo?.bar()') |
| 2439 |
bt( |
| 2440 |
'this\n' + |
| 2441 |
'?.something\n' + |
| 2442 |
'?.xxx = foo?.moo\n' + |
| 2443 |
'?.bar()', |
| 2444 |
# -- output -- |
| 2445 |
'this\n' + |
| 2446 |
' ?.something\n' + |
| 2447 |
' ?.xxx = foo?.moo\n' + |
| 2448 |
' ?.bar()') |
| 2449 |
|
| 2450 |
|
| 2451 |
#============================================================ |
| 2452 |
# line wrapping 0 |
| 2453 |
self.reset_options() |
| 2454 |
self.options.preserve_newlines = false |
| 2455 |
self.options.wrap_line_length = 0 |
| 2456 |
test_fragment( |
| 2457 |
'' + wrap_input_1 + '', |
| 2458 |
# -- output -- |
| 2459 |
'foo.bar().baz().cucumber((f && "sass") || (leans && mean));\n' + |
| 2460 |
'Test_very_long_variable_name_this_should_never_wrap.but_this_can\n' + |
| 2461 |
'return between_return_and_expression_should_never_wrap.but_this_can\n' + |
| 2462 |
'throw between_throw_and_expression_should_never_wrap.but_this_can\n' + |
| 2463 |
'if (wraps_can_occur && inside_an_if_block) that_is_.okay();\n' + |
| 2464 |
'object_literal = {\n' + |
| 2465 |
' propertx: first_token + 12345678.99999E-6,\n' + |
| 2466 |
' property: first_token_should_never_wrap + but_this_can,\n' + |
| 2467 |
' propertz: first_token_should_never_wrap + !but_this_can,\n' + |
| 2468 |
' proper: "first_token_should_never_wrap" + "but_this_can"\n' + |
| 2469 |
'}') |
| 2470 |
test_fragment( |
| 2471 |
'' + wrap_input_2 + '', |
| 2472 |
# -- output -- |
| 2473 |
'{\n' + |
| 2474 |
' foo.bar().baz().cucumber((f && "sass") || (leans && mean));\n' + |
| 2475 |
' Test_very_long_variable_name_this_should_never_wrap.but_this_can\n' + |
| 2476 |
' return between_return_and_expression_should_never_wrap.but_this_can\n' + |
| 2477 |
' throw between_throw_and_expression_should_never_wrap.but_this_can\n' + |
| 2478 |
' if (wraps_can_occur && inside_an_if_block) that_is_.okay();\n' + |
| 2479 |
' object_literal = {\n' + |
| 2480 |
' propertx: first_token + 12345678.99999E-6,\n' + |
| 2481 |
' property: first_token_should_never_wrap + but_this_can,\n' + |
| 2482 |
' propertz: first_token_should_never_wrap + !but_this_can,\n' + |
| 2483 |
' proper: "first_token_should_never_wrap" + "but_this_can"\n' + |
| 2484 |
' }\n' + |
| 2485 |
'}') |
| 2486 |
|
| 2487 |
|
| 2488 |
#============================================================ |
| 2489 |
# line wrapping 70 |
| 2490 |
self.reset_options() |
| 2491 |
self.options.preserve_newlines = false |
| 2492 |
self.options.wrap_line_length = 70 |
| 2493 |
test_fragment( |
| 2494 |
'' + wrap_input_1 + '', |
| 2495 |
# -- output -- |
| 2496 |
'foo.bar().baz().cucumber((f && "sass") || (leans && mean));\n' + |
| 2497 |
'Test_very_long_variable_name_this_should_never_wrap.but_this_can\n' + |
| 2498 |
'return between_return_and_expression_should_never_wrap.but_this_can\n' + |
| 2499 |
'throw between_throw_and_expression_should_never_wrap.but_this_can\n' + |
| 2500 |
'if (wraps_can_occur && inside_an_if_block) that_is_.okay();\n' + |
| 2501 |
'object_literal = {\n' + |
| 2502 |
' propertx: first_token + 12345678.99999E-6,\n' + |
| 2503 |
' property: first_token_should_never_wrap + but_this_can,\n' + |
| 2504 |
' propertz: first_token_should_never_wrap + !but_this_can,\n' + |
| 2505 |
' proper: "first_token_should_never_wrap" + "but_this_can"\n' + |
| 2506 |
'}') |
| 2507 |
test_fragment( |
| 2508 |
'' + wrap_input_2 + '', |
| 2509 |
# -- output -- |
| 2510 |
'{\n' + |
| 2511 |
' foo.bar().baz().cucumber((f && "sass") || (leans && mean));\n' + |
| 2512 |
' Test_very_long_variable_name_this_should_never_wrap.but_this_can\n' + |
| 2513 |
' return between_return_and_expression_should_never_wrap\n' + |
| 2514 |
' .but_this_can\n' + |
| 2515 |
' throw between_throw_and_expression_should_never_wrap.but_this_can\n' + |
| 2516 |
' if (wraps_can_occur && inside_an_if_block) that_is_.okay();\n' + |
| 2517 |
' object_literal = {\n' + |
| 2518 |
' propertx: first_token + 12345678.99999E-6,\n' + |
| 2519 |
' property: first_token_should_never_wrap + but_this_can,\n' + |
| 2520 |
' propertz: first_token_should_never_wrap + !but_this_can,\n' + |
| 2521 |
' proper: "first_token_should_never_wrap" + "but_this_can"\n' + |
| 2522 |
' }\n' + |
| 2523 |
'}') |
| 2524 |
|
| 2525 |
|
| 2526 |
#============================================================ |
| 2527 |
# line wrapping 40 |
| 2528 |
self.reset_options() |
| 2529 |
self.options.preserve_newlines = false |
| 2530 |
self.options.wrap_line_length = 40 |
| 2531 |
test_fragment( |
| 2532 |
'' + wrap_input_1 + '', |
| 2533 |
# -- output -- |
| 2534 |
'foo.bar().baz().cucumber((f &&\n' + |
| 2535 |
' "sass") || (leans && mean));\n' + |
| 2536 |
'Test_very_long_variable_name_this_should_never_wrap\n' + |
| 2537 |
' .but_this_can\n' + |
| 2538 |
'return between_return_and_expression_should_never_wrap\n' + |
| 2539 |
' .but_this_can\n' + |
| 2540 |
'throw between_throw_and_expression_should_never_wrap\n' + |
| 2541 |
' .but_this_can\n' + |
| 2542 |
'if (wraps_can_occur &&\n' + |
| 2543 |
' inside_an_if_block) that_is_.okay();\n' + |
| 2544 |
'object_literal = {\n' + |
| 2545 |
' propertx: first_token +\n' + |
| 2546 |
' 12345678.99999E-6,\n' + |
| 2547 |
' property: first_token_should_never_wrap +\n' + |
| 2548 |
' but_this_can,\n' + |
| 2549 |
' propertz: first_token_should_never_wrap +\n' + |
| 2550 |
' !but_this_can,\n' + |
| 2551 |
' proper: "first_token_should_never_wrap" +\n' + |
| 2552 |
' "but_this_can"\n' + |
| 2553 |
'}') |
| 2554 |
|
| 2555 |
# Issue #1932 - Javascript object property with -/+ symbol wraps issue |
| 2556 |
bt( |
| 2557 |
'{\n' + |
| 2558 |
' "1234567891234567891234567891234": -433,\n' + |
| 2559 |
' "abcdefghijklmnopqrstuvwxyz12345": +11\n' + |
| 2560 |
'}', |
| 2561 |
# -- output -- |
| 2562 |
'{\n' + |
| 2563 |
' "1234567891234567891234567891234": -433,\n' + |
| 2564 |
' "abcdefghijklmnopqrstuvwxyz12345": +11\n' + |
| 2565 |
'}') |
| 2566 |
test_fragment( |
| 2567 |
'' + wrap_input_2 + '', |
| 2568 |
# -- output -- |
| 2569 |
'{\n' + |
| 2570 |
' foo.bar().baz().cucumber((f &&\n' + |
| 2571 |
' "sass") || (leans &&\n' + |
| 2572 |
' mean));\n' + |
| 2573 |
' Test_very_long_variable_name_this_should_never_wrap\n' + |
| 2574 |
' .but_this_can\n' + |
| 2575 |
' return between_return_and_expression_should_never_wrap\n' + |
| 2576 |
' .but_this_can\n' + |
| 2577 |
' throw between_throw_and_expression_should_never_wrap\n' + |
| 2578 |
' .but_this_can\n' + |
| 2579 |
' if (wraps_can_occur &&\n' + |
| 2580 |
' inside_an_if_block) that_is_\n' + |
| 2581 |
' .okay();\n' + |
| 2582 |
' object_literal = {\n' + |
| 2583 |
' propertx: first_token +\n' + |
| 2584 |
' 12345678.99999E-6,\n' + |
| 2585 |
' property: first_token_should_never_wrap +\n' + |
| 2586 |
' but_this_can,\n' + |
| 2587 |
' propertz: first_token_should_never_wrap +\n' + |
| 2588 |
' !but_this_can,\n' + |
| 2589 |
' proper: "first_token_should_never_wrap" +\n' + |
| 2590 |
' "but_this_can"\n' + |
| 2591 |
' }\n' + |
| 2592 |
'}') |
| 2593 |
|
| 2594 |
|
| 2595 |
#============================================================ |
| 2596 |
# line wrapping 41 |
| 2597 |
self.reset_options() |
| 2598 |
self.options.preserve_newlines = false |
| 2599 |
self.options.wrap_line_length = 41 |
| 2600 |
test_fragment( |
| 2601 |
'' + wrap_input_1 + '', |
| 2602 |
# -- output -- |
| 2603 |
'foo.bar().baz().cucumber((f && "sass") ||\n' + |
| 2604 |
' (leans && mean));\n' + |
| 2605 |
'Test_very_long_variable_name_this_should_never_wrap\n' + |
| 2606 |
' .but_this_can\n' + |
| 2607 |
'return between_return_and_expression_should_never_wrap\n' + |
| 2608 |
' .but_this_can\n' + |
| 2609 |
'throw between_throw_and_expression_should_never_wrap\n' + |
| 2610 |
' .but_this_can\n' + |
| 2611 |
'if (wraps_can_occur &&\n' + |
| 2612 |
' inside_an_if_block) that_is_.okay();\n' + |
| 2613 |
'object_literal = {\n' + |
| 2614 |
' propertx: first_token +\n' + |
| 2615 |
' 12345678.99999E-6,\n' + |
| 2616 |
' property: first_token_should_never_wrap +\n' + |
| 2617 |
' but_this_can,\n' + |
| 2618 |
' propertz: first_token_should_never_wrap +\n' + |
| 2619 |
' !but_this_can,\n' + |
| 2620 |
' proper: "first_token_should_never_wrap" +\n' + |
| 2621 |
' "but_this_can"\n' + |
| 2622 |
'}') |
| 2623 |
test_fragment( |
| 2624 |
'' + wrap_input_2 + '', |
| 2625 |
# -- output -- |
| 2626 |
'{\n' + |
| 2627 |
' foo.bar().baz().cucumber((f &&\n' + |
| 2628 |
' "sass") || (leans &&\n' + |
| 2629 |
' mean));\n' + |
| 2630 |
' Test_very_long_variable_name_this_should_never_wrap\n' + |
| 2631 |
' .but_this_can\n' + |
| 2632 |
' return between_return_and_expression_should_never_wrap\n' + |
| 2633 |
' .but_this_can\n' + |
| 2634 |
' throw between_throw_and_expression_should_never_wrap\n' + |
| 2635 |
' .but_this_can\n' + |
| 2636 |
' if (wraps_can_occur &&\n' + |
| 2637 |
' inside_an_if_block) that_is_\n' + |
| 2638 |
' .okay();\n' + |
| 2639 |
' object_literal = {\n' + |
| 2640 |
' propertx: first_token +\n' + |
| 2641 |
' 12345678.99999E-6,\n' + |
| 2642 |
' property: first_token_should_never_wrap +\n' + |
| 2643 |
' but_this_can,\n' + |
| 2644 |
' propertz: first_token_should_never_wrap +\n' + |
| 2645 |
' !but_this_can,\n' + |
| 2646 |
' proper: "first_token_should_never_wrap" +\n' + |
| 2647 |
' "but_this_can"\n' + |
| 2648 |
' }\n' + |
| 2649 |
'}') |
| 2650 |
|
| 2651 |
|
| 2652 |
#============================================================ |
| 2653 |
# line wrapping 45 |
| 2654 |
self.reset_options() |
| 2655 |
self.options.preserve_newlines = false |
| 2656 |
self.options.wrap_line_length = 45 |
| 2657 |
test_fragment( |
| 2658 |
'' + wrap_input_1 + '', |
| 2659 |
# -- output -- |
| 2660 |
'foo.bar().baz().cucumber((f && "sass") || (\n' + |
| 2661 |
' leans && mean));\n' + |
| 2662 |
'Test_very_long_variable_name_this_should_never_wrap\n' + |
| 2663 |
' .but_this_can\n' + |
| 2664 |
'return between_return_and_expression_should_never_wrap\n' + |
| 2665 |
' .but_this_can\n' + |
| 2666 |
'throw between_throw_and_expression_should_never_wrap\n' + |
| 2667 |
' .but_this_can\n' + |
| 2668 |
'if (wraps_can_occur && inside_an_if_block)\n' + |
| 2669 |
' that_is_.okay();\n' + |
| 2670 |
'object_literal = {\n' + |
| 2671 |
' propertx: first_token +\n' + |
| 2672 |
' 12345678.99999E-6,\n' + |
| 2673 |
' property: first_token_should_never_wrap +\n' + |
| 2674 |
' but_this_can,\n' + |
| 2675 |
' propertz: first_token_should_never_wrap +\n' + |
| 2676 |
' !but_this_can,\n' + |
| 2677 |
' proper: "first_token_should_never_wrap" +\n' + |
| 2678 |
' "but_this_can"\n' + |
| 2679 |
'}') |
| 2680 |
test_fragment( |
| 2681 |
'' + wrap_input_2 + '', |
| 2682 |
# -- output -- |
| 2683 |
'{\n' + |
| 2684 |
' foo.bar().baz().cucumber((f && "sass") ||\n' + |
| 2685 |
' (leans && mean));\n' + |
| 2686 |
' Test_very_long_variable_name_this_should_never_wrap\n' + |
| 2687 |
' .but_this_can\n' + |
| 2688 |
' return between_return_and_expression_should_never_wrap\n' + |
| 2689 |
' .but_this_can\n' + |
| 2690 |
' throw between_throw_and_expression_should_never_wrap\n' + |
| 2691 |
' .but_this_can\n' + |
| 2692 |
' if (wraps_can_occur &&\n' + |
| 2693 |
' inside_an_if_block) that_is_.okay();\n' + |
| 2694 |
' object_literal = {\n' + |
| 2695 |
' propertx: first_token +\n' + |
| 2696 |
' 12345678.99999E-6,\n' + |
| 2697 |
' property: first_token_should_never_wrap +\n' + |
| 2698 |
' but_this_can,\n' + |
| 2699 |
' propertz: first_token_should_never_wrap +\n' + |
| 2700 |
' !but_this_can,\n' + |
| 2701 |
' proper: "first_token_should_never_wrap" +\n' + |
| 2702 |
' "but_this_can"\n' + |
| 2703 |
' }\n' + |
| 2704 |
'}') |
| 2705 |
|
| 2706 |
|
| 2707 |
#============================================================ |
| 2708 |
# line wrapping 0 |
| 2709 |
self.reset_options() |
| 2710 |
self.options.preserve_newlines = true |
| 2711 |
self.options.wrap_line_length = 0 |
| 2712 |
test_fragment( |
| 2713 |
'' + wrap_input_1 + '', |
| 2714 |
# -- output -- |
| 2715 |
'foo.bar().baz().cucumber((f && "sass") || (leans && mean));\n' + |
| 2716 |
'Test_very_long_variable_name_this_should_never_wrap\n' + |
| 2717 |
' .but_this_can\n' + |
| 2718 |
'return between_return_and_expression_should_never_wrap.but_this_can\n' + |
| 2719 |
'throw between_throw_and_expression_should_never_wrap.but_this_can\n' + |
| 2720 |
'if (wraps_can_occur && inside_an_if_block) that_is_\n' + |
| 2721 |
' .okay();\n' + |
| 2722 |
'object_literal = {\n' + |
| 2723 |
' propertx: first_token + 12345678.99999E-6,\n' + |
| 2724 |
' property: first_token_should_never_wrap + but_this_can,\n' + |
| 2725 |
' propertz: first_token_should_never_wrap + !but_this_can,\n' + |
| 2726 |
' proper: "first_token_should_never_wrap" + "but_this_can"\n' + |
| 2727 |
'}') |
| 2728 |
test_fragment( |
| 2729 |
'' + wrap_input_2 + '', |
| 2730 |
# -- output -- |
| 2731 |
'{\n' + |
| 2732 |
' foo.bar().baz().cucumber((f && "sass") || (leans && mean));\n' + |
| 2733 |
' Test_very_long_variable_name_this_should_never_wrap\n' + |
| 2734 |
' .but_this_can\n' + |
| 2735 |
' return between_return_and_expression_should_never_wrap.but_this_can\n' + |
| 2736 |
' throw between_throw_and_expression_should_never_wrap.but_this_can\n' + |
| 2737 |
' if (wraps_can_occur && inside_an_if_block) that_is_\n' + |
| 2738 |
' .okay();\n' + |
| 2739 |
' object_literal = {\n' + |
| 2740 |
' propertx: first_token + 12345678.99999E-6,\n' + |
| 2741 |
' property: first_token_should_never_wrap + but_this_can,\n' + |
| 2742 |
' propertz: first_token_should_never_wrap + !but_this_can,\n' + |
| 2743 |
' proper: "first_token_should_never_wrap" + "but_this_can"\n' + |
| 2744 |
' }\n' + |
| 2745 |
'}') |
| 2746 |
|
| 2747 |
|
| 2748 |
#============================================================ |
| 2749 |
# line wrapping 70 |
| 2750 |
self.reset_options() |
| 2751 |
self.options.preserve_newlines = true |
| 2752 |
self.options.wrap_line_length = 70 |
| 2753 |
test_fragment( |
| 2754 |
'' + wrap_input_1 + '', |
| 2755 |
# -- output -- |
| 2756 |
'foo.bar().baz().cucumber((f && "sass") || (leans && mean));\n' + |
| 2757 |
'Test_very_long_variable_name_this_should_never_wrap\n' + |
| 2758 |
' .but_this_can\n' + |
| 2759 |
'return between_return_and_expression_should_never_wrap.but_this_can\n' + |
| 2760 |
'throw between_throw_and_expression_should_never_wrap.but_this_can\n' + |
| 2761 |
'if (wraps_can_occur && inside_an_if_block) that_is_\n' + |
| 2762 |
' .okay();\n' + |
| 2763 |
'object_literal = {\n' + |
| 2764 |
' propertx: first_token + 12345678.99999E-6,\n' + |
| 2765 |
' property: first_token_should_never_wrap + but_this_can,\n' + |
| 2766 |
' propertz: first_token_should_never_wrap + !but_this_can,\n' + |
| 2767 |
' proper: "first_token_should_never_wrap" + "but_this_can"\n' + |
| 2768 |
'}') |
| 2769 |
test_fragment( |
| 2770 |
'' + wrap_input_2 + '', |
| 2771 |
# -- output -- |
| 2772 |
'{\n' + |
| 2773 |
' foo.bar().baz().cucumber((f && "sass") || (leans && mean));\n' + |
| 2774 |
' Test_very_long_variable_name_this_should_never_wrap\n' + |
| 2775 |
' .but_this_can\n' + |
| 2776 |
' return between_return_and_expression_should_never_wrap\n' + |
| 2777 |
' .but_this_can\n' + |
| 2778 |
' throw between_throw_and_expression_should_never_wrap.but_this_can\n' + |
| 2779 |
' if (wraps_can_occur && inside_an_if_block) that_is_\n' + |
| 2780 |
' .okay();\n' + |
| 2781 |
' object_literal = {\n' + |
| 2782 |
' propertx: first_token + 12345678.99999E-6,\n' + |
| 2783 |
' property: first_token_should_never_wrap + but_this_can,\n' + |
| 2784 |
' propertz: first_token_should_never_wrap + !but_this_can,\n' + |
| 2785 |
' proper: "first_token_should_never_wrap" + "but_this_can"\n' + |
| 2786 |
' }\n' + |
| 2787 |
'}') |
| 2788 |
|
| 2789 |
|
| 2790 |
#============================================================ |
| 2791 |
# line wrapping 40 |
| 2792 |
self.reset_options() |
| 2793 |
self.options.preserve_newlines = true |
| 2794 |
self.options.wrap_line_length = 40 |
| 2795 |
test_fragment( |
| 2796 |
'' + wrap_input_1 + '', |
| 2797 |
# -- output -- |
| 2798 |
'foo.bar().baz().cucumber((f &&\n' + |
| 2799 |
' "sass") || (leans && mean));\n' + |
| 2800 |
'Test_very_long_variable_name_this_should_never_wrap\n' + |
| 2801 |
' .but_this_can\n' + |
| 2802 |
'return between_return_and_expression_should_never_wrap\n' + |
| 2803 |
' .but_this_can\n' + |
| 2804 |
'throw between_throw_and_expression_should_never_wrap\n' + |
| 2805 |
' .but_this_can\n' + |
| 2806 |
'if (wraps_can_occur &&\n' + |
| 2807 |
' inside_an_if_block) that_is_\n' + |
| 2808 |
' .okay();\n' + |
| 2809 |
'object_literal = {\n' + |
| 2810 |
' propertx: first_token +\n' + |
| 2811 |
' 12345678.99999E-6,\n' + |
| 2812 |
' property: first_token_should_never_wrap +\n' + |
| 2813 |
' but_this_can,\n' + |
| 2814 |
' propertz: first_token_should_never_wrap +\n' + |
| 2815 |
' !but_this_can,\n' + |
| 2816 |
' proper: "first_token_should_never_wrap" +\n' + |
| 2817 |
' "but_this_can"\n' + |
| 2818 |
'}') |
| 2819 |
test_fragment( |
| 2820 |
'' + wrap_input_2 + '', |
| 2821 |
# -- output -- |
| 2822 |
'{\n' + |
| 2823 |
' foo.bar().baz().cucumber((f &&\n' + |
| 2824 |
' "sass") || (leans &&\n' + |
| 2825 |
' mean));\n' + |
| 2826 |
' Test_very_long_variable_name_this_should_never_wrap\n' + |
| 2827 |
' .but_this_can\n' + |
| 2828 |
' return between_return_and_expression_should_never_wrap\n' + |
| 2829 |
' .but_this_can\n' + |
| 2830 |
' throw between_throw_and_expression_should_never_wrap\n' + |
| 2831 |
' .but_this_can\n' + |
| 2832 |
' if (wraps_can_occur &&\n' + |
| 2833 |
' inside_an_if_block) that_is_\n' + |
| 2834 |
' .okay();\n' + |
| 2835 |
' object_literal = {\n' + |
| 2836 |
' propertx: first_token +\n' + |
| 2837 |
' 12345678.99999E-6,\n' + |
| 2838 |
' property: first_token_should_never_wrap +\n' + |
| 2839 |
' but_this_can,\n' + |
| 2840 |
' propertz: first_token_should_never_wrap +\n' + |
| 2841 |
' !but_this_can,\n' + |
| 2842 |
' proper: "first_token_should_never_wrap" +\n' + |
| 2843 |
' "but_this_can"\n' + |
| 2844 |
' }\n' + |
| 2845 |
'}') |
| 2846 |
|
| 2847 |
|
| 2848 |
#============================================================ |
| 2849 |
# line wrapping 41 |
| 2850 |
self.reset_options() |
| 2851 |
self.options.preserve_newlines = true |
| 2852 |
self.options.wrap_line_length = 41 |
| 2853 |
test_fragment( |
| 2854 |
'' + wrap_input_1 + '', |
| 2855 |
# -- output -- |
| 2856 |
'foo.bar().baz().cucumber((f && "sass") ||\n' + |
| 2857 |
' (leans && mean));\n' + |
| 2858 |
'Test_very_long_variable_name_this_should_never_wrap\n' + |
| 2859 |
' .but_this_can\n' + |
| 2860 |
'return between_return_and_expression_should_never_wrap\n' + |
| 2861 |
' .but_this_can\n' + |
| 2862 |
'throw between_throw_and_expression_should_never_wrap\n' + |
| 2863 |
' .but_this_can\n' + |
| 2864 |
'if (wraps_can_occur &&\n' + |
| 2865 |
' inside_an_if_block) that_is_\n' + |
| 2866 |
' .okay();\n' + |
| 2867 |
'object_literal = {\n' + |
| 2868 |
' propertx: first_token +\n' + |
| 2869 |
' 12345678.99999E-6,\n' + |
| 2870 |
' property: first_token_should_never_wrap +\n' + |
| 2871 |
' but_this_can,\n' + |
| 2872 |
' propertz: first_token_should_never_wrap +\n' + |
| 2873 |
' !but_this_can,\n' + |
| 2874 |
' proper: "first_token_should_never_wrap" +\n' + |
| 2875 |
' "but_this_can"\n' + |
| 2876 |
'}') |
| 2877 |
test_fragment( |
| 2878 |
'' + wrap_input_2 + '', |
| 2879 |
# -- output -- |
| 2880 |
'{\n' + |
| 2881 |
' foo.bar().baz().cucumber((f &&\n' + |
| 2882 |
' "sass") || (leans &&\n' + |
| 2883 |
' mean));\n' + |
| 2884 |
' Test_very_long_variable_name_this_should_never_wrap\n' + |
| 2885 |
' .but_this_can\n' + |
| 2886 |
' return between_return_and_expression_should_never_wrap\n' + |
| 2887 |
' .but_this_can\n' + |
| 2888 |
' throw between_throw_and_expression_should_never_wrap\n' + |
| 2889 |
' .but_this_can\n' + |
| 2890 |
' if (wraps_can_occur &&\n' + |
| 2891 |
' inside_an_if_block) that_is_\n' + |
| 2892 |
' .okay();\n' + |
| 2893 |
' object_literal = {\n' + |
| 2894 |
' propertx: first_token +\n' + |
| 2895 |
' 12345678.99999E-6,\n' + |
| 2896 |
' property: first_token_should_never_wrap +\n' + |
| 2897 |
' but_this_can,\n' + |
| 2898 |
' propertz: first_token_should_never_wrap +\n' + |
| 2899 |
' !but_this_can,\n' + |
| 2900 |
' proper: "first_token_should_never_wrap" +\n' + |
| 2901 |
' "but_this_can"\n' + |
| 2902 |
' }\n' + |
| 2903 |
'}') |
| 2904 |
|
| 2905 |
|
| 2906 |
#============================================================ |
| 2907 |
# line wrapping 45 |
| 2908 |
self.reset_options() |
| 2909 |
self.options.preserve_newlines = true |
| 2910 |
self.options.wrap_line_length = 45 |
| 2911 |
test_fragment( |
| 2912 |
'' + wrap_input_1 + '', |
| 2913 |
# -- output -- |
| 2914 |
'foo.bar().baz().cucumber((f && "sass") || (\n' + |
| 2915 |
' leans && mean));\n' + |
| 2916 |
'Test_very_long_variable_name_this_should_never_wrap\n' + |
| 2917 |
' .but_this_can\n' + |
| 2918 |
'return between_return_and_expression_should_never_wrap\n' + |
| 2919 |
' .but_this_can\n' + |
| 2920 |
'throw between_throw_and_expression_should_never_wrap\n' + |
| 2921 |
' .but_this_can\n' + |
| 2922 |
'if (wraps_can_occur && inside_an_if_block)\n' + |
| 2923 |
' that_is_\n' + |
| 2924 |
' .okay();\n' + |
| 2925 |
'object_literal = {\n' + |
| 2926 |
' propertx: first_token +\n' + |
| 2927 |
' 12345678.99999E-6,\n' + |
| 2928 |
' property: first_token_should_never_wrap +\n' + |
| 2929 |
' but_this_can,\n' + |
| 2930 |
' propertz: first_token_should_never_wrap +\n' + |
| 2931 |
' !but_this_can,\n' + |
| 2932 |
' proper: "first_token_should_never_wrap" +\n' + |
| 2933 |
' "but_this_can"\n' + |
| 2934 |
'}') |
| 2935 |
test_fragment( |
| 2936 |
'' + wrap_input_2 + '', |
| 2937 |
# -- output -- |
| 2938 |
'{\n' + |
| 2939 |
' foo.bar().baz().cucumber((f && "sass") ||\n' + |
| 2940 |
' (leans && mean));\n' + |
| 2941 |
' Test_very_long_variable_name_this_should_never_wrap\n' + |
| 2942 |
' .but_this_can\n' + |
| 2943 |
' return between_return_and_expression_should_never_wrap\n' + |
| 2944 |
' .but_this_can\n' + |
| 2945 |
' throw between_throw_and_expression_should_never_wrap\n' + |
| 2946 |
' .but_this_can\n' + |
| 2947 |
' if (wraps_can_occur &&\n' + |
| 2948 |
' inside_an_if_block) that_is_\n' + |
| 2949 |
' .okay();\n' + |
| 2950 |
' object_literal = {\n' + |
| 2951 |
' propertx: first_token +\n' + |
| 2952 |
' 12345678.99999E-6,\n' + |
| 2953 |
' property: first_token_should_never_wrap +\n' + |
| 2954 |
' but_this_can,\n' + |
| 2955 |
' propertz: first_token_should_never_wrap +\n' + |
| 2956 |
' !but_this_can,\n' + |
| 2957 |
' proper: "first_token_should_never_wrap" +\n' + |
| 2958 |
' "but_this_can"\n' + |
| 2959 |
' }\n' + |
| 2960 |
'}') |
| 2961 |
|
| 2962 |
|
| 2963 |
#============================================================ |
| 2964 |
# general preserve_newlines tests preserve limit |
| 2965 |
self.reset_options() |
| 2966 |
self.options.preserve_newlines = true |
| 2967 |
self.options.max_preserve_newlines = 8 |
| 2968 |
bt( |
| 2969 |
'a = 1;\n' + |
| 2970 |
'\n' + |
| 2971 |
'\n' + |
| 2972 |
'\n' + |
| 2973 |
'\n' + |
| 2974 |
'\n' + |
| 2975 |
'\n' + |
| 2976 |
'\n' + |
| 2977 |
'\n' + |
| 2978 |
'\n' + |
| 2979 |
'\n' + |
| 2980 |
'\n' + |
| 2981 |
'\n' + |
| 2982 |
'\n' + |
| 2983 |
'\n' + |
| 2984 |
'\n' + |
| 2985 |
'\n' + |
| 2986 |
'\n' + |
| 2987 |
'\n' + |
| 2988 |
'\n' + |
| 2989 |
'\n' + |
| 2990 |
'\n' + |
| 2991 |
'b = 2;', |
| 2992 |
# -- output -- |
| 2993 |
'a = 1;\n' + |
| 2994 |
'\n' + |
| 2995 |
'\n' + |
| 2996 |
'\n' + |
| 2997 |
'\n' + |
| 2998 |
'\n' + |
| 2999 |
'\n' + |
| 3000 |
'\n' + |
| 3001 |
'b = 2;') |
| 3002 |
|
| 3003 |
|
| 3004 |
#============================================================ |
| 3005 |
# more random test |
| 3006 |
self.reset_options() |
| 3007 |
bt('return function();') |
| 3008 |
bt('var a = function();') |
| 3009 |
bt('var a = 5 + function();') |
| 3010 |
|
| 3011 |
# actionscript import |
| 3012 |
bt('import foo.*;') |
| 3013 |
|
| 3014 |
# actionscript |
| 3015 |
bt('function f(a: a, b: b)') |
| 3016 |
bt( |
| 3017 |
'function a(a) {} function b(b) {} function c(c) {}', |
| 3018 |
# -- output -- |
| 3019 |
'function a(a) {}\n' + |
| 3020 |
'\n' + |
| 3021 |
'function b(b) {}\n' + |
| 3022 |
'\n' + |
| 3023 |
'function c(c) {}') |
| 3024 |
bt('foo(a, function() {})') |
| 3025 |
bt('foo(a, /regex/)') |
| 3026 |
bt( |
| 3027 |
'/* foo */\n' + |
| 3028 |
'"x"') |
| 3029 |
test_fragment( |
| 3030 |
'roo = {\n' + |
| 3031 |
' /*\n' + |
| 3032 |
' ****\n' + |
| 3033 |
' FOO\n' + |
| 3034 |
' ****\n' + |
| 3035 |
' */\n' + |
| 3036 |
' BAR: 0\n' + |
| 3037 |
'};') |
| 3038 |
test_fragment( |
| 3039 |
'if (zz) {\n' + |
| 3040 |
' // ....\n' + |
| 3041 |
'}\n' + |
| 3042 |
'(function') |
| 3043 |
bt( |
| 3044 |
'a = //comment\n' + |
| 3045 |
' /regex/;') |
| 3046 |
bt('var a = new function();') |
| 3047 |
bt('new function') |
| 3048 |
bt( |
| 3049 |
'if (a)\n' + |
| 3050 |
'{\n' + |
| 3051 |
'b;\n' + |
| 3052 |
'}\n' + |
| 3053 |
'else\n' + |
| 3054 |
'{\n' + |
| 3055 |
'c;\n' + |
| 3056 |
'}', |
| 3057 |
# -- output -- |
| 3058 |
'if (a) {\n' + |
| 3059 |
' b;\n' + |
| 3060 |
'} else {\n' + |
| 3061 |
' c;\n' + |
| 3062 |
'}') |
| 3063 |
bt('fn`tagged`') |
| 3064 |
bt('fn()`tagged`') |
| 3065 |
bt('fn`${algo} ${`6string`}`') |
| 3066 |
bt('fn`${fn2()} more text ${`${`more text`}`} banana ${fn3`test`} ${fn4()`moretest banana2`}`') |
| 3067 |
bt('`untagged`+`untagged`', '`untagged` + `untagged`') |
| 3068 |
bt('fun() `taggedd`') |
| 3069 |
bt('fn[0]`tagged`', 'fn[0] `tagged`') |
| 3070 |
|
| 3071 |
|
| 3072 |
#============================================================ |
| 3073 |
# operator_position option - ensure no newlines if preserve_newlines is false - (preserve_newlines = "false") |
| 3074 |
self.reset_options() |
| 3075 |
self.options.preserve_newlines = false |
| 3076 |
bt( |
| 3077 |
'var res = a + b - c / d * e % f;\n' + |
| 3078 |
'var res = g & h | i ^ j |> console.log;\n' + |
| 3079 |
'var res = (k && l || m) ? n ?? nn : o;\n' + |
| 3080 |
'var res = p >> q << r >>> s;\n' + |
| 3081 |
'var res = t === u !== v != w == x >= y <= z > aa < ab;\n' + |
| 3082 |
'res ??= a;\n' + |
| 3083 |
'res ||= b;\n' + |
| 3084 |
'res &&= c;\n' + |
| 3085 |
'ac + -ad') |
| 3086 |
bt( |
| 3087 |
'var res = a + b\n' + |
| 3088 |
'- c /\n' + |
| 3089 |
'd * e\n' + |
| 3090 |
'%\n' + |
| 3091 |
'f;\n' + |
| 3092 |
' var res = g & h\n' + |
| 3093 |
'| i ^\n' + |
| 3094 |
'j\n' + |
| 3095 |
'|> console.log;\n' + |
| 3096 |
'var res = (k &&\n' + |
| 3097 |
'l\n' + |
| 3098 |
'|| m) ?\n' + |
| 3099 |
'n\n' + |
| 3100 |
'?? nn\n' + |
| 3101 |
': o\n' + |
| 3102 |
';\n' + |
| 3103 |
'var res = p\n' + |
| 3104 |
'>> q <<\n' + |
| 3105 |
'r\n' + |
| 3106 |
'>>> s;\n' + |
| 3107 |
'var res\n' + |
| 3108 |
' = t\n' + |
| 3109 |
'\n' + |
| 3110 |
' === u !== v\n' + |
| 3111 |
' !=\n' + |
| 3112 |
'w\n' + |
| 3113 |
'== x >=\n' + |
| 3114 |
'y <= z > aa <\n' + |
| 3115 |
'ab;\n' + |
| 3116 |
'res??=a;res||=b;res&&=c;\n' + |
| 3117 |
'ac +\n' + |
| 3118 |
'-ad', |
| 3119 |
# -- output -- |
| 3120 |
'var res = a + b - c / d * e % f;\n' + |
| 3121 |
'var res = g & h | i ^ j |> console.log;\n' + |
| 3122 |
'var res = (k && l || m) ? n ?? nn : o;\n' + |
| 3123 |
'var res = p >> q << r >>> s;\n' + |
| 3124 |
'var res = t === u !== v != w == x >= y <= z > aa < ab;\n' + |
| 3125 |
'res ??= a;\n' + |
| 3126 |
'res ||= b;\n' + |
| 3127 |
'res &&= c;\n' + |
| 3128 |
'ac + -ad') |
| 3129 |
|
| 3130 |
# operator_position option - ensure no newlines if preserve_newlines is false - (operator_position = ""before-newline"", preserve_newlines = "false") |
| 3131 |
self.reset_options() |
| 3132 |
self.options.operator_position = 'before-newline' |
| 3133 |
self.options.preserve_newlines = false |
| 3134 |
bt( |
| 3135 |
'var res = a + b - c / d * e % f;\n' + |
| 3136 |
'var res = g & h | i ^ j |> console.log;\n' + |
| 3137 |
'var res = (k && l || m) ? n ?? nn : o;\n' + |
| 3138 |
'var res = p >> q << r >>> s;\n' + |
| 3139 |
'var res = t === u !== v != w == x >= y <= z > aa < ab;\n' + |
| 3140 |
'res ??= a;\n' + |
| 3141 |
'res ||= b;\n' + |
| 3142 |
'res &&= c;\n' + |
| 3143 |
'ac + -ad') |
| 3144 |
bt( |
| 3145 |
'var res = a + b\n' + |
| 3146 |
'- c /\n' + |
| 3147 |
'd * e\n' + |
| 3148 |
'%\n' + |
| 3149 |
'f;\n' + |
| 3150 |
' var res = g & h\n' + |
| 3151 |
'| i ^\n' + |
| 3152 |
'j\n' + |
| 3153 |
'|> console.log;\n' + |
| 3154 |
'var res = (k &&\n' + |
| 3155 |
'l\n' + |
| 3156 |
'|| m) ?\n' + |
| 3157 |
'n\n' + |
| 3158 |
'?? nn\n' + |
| 3159 |
': o\n' + |
| 3160 |
';\n' + |
| 3161 |
'var res = p\n' + |
| 3162 |
'>> q <<\n' + |
| 3163 |
'r\n' + |
| 3164 |
'>>> s;\n' + |
| 3165 |
'var res\n' + |
| 3166 |
' = t\n' + |
| 3167 |
'\n' + |
| 3168 |
' === u !== v\n' + |
| 3169 |
' !=\n' + |
| 3170 |
'w\n' + |
| 3171 |
'== x >=\n' + |
| 3172 |
'y <= z > aa <\n' + |
| 3173 |
'ab;\n' + |
| 3174 |
'res??=a;res||=b;res&&=c;\n' + |
| 3175 |
'ac +\n' + |
| 3176 |
'-ad', |
| 3177 |
# -- output -- |
| 3178 |
'var res = a + b - c / d * e % f;\n' + |
| 3179 |
'var res = g & h | i ^ j |> console.log;\n' + |
| 3180 |
'var res = (k && l || m) ? n ?? nn : o;\n' + |
| 3181 |
'var res = p >> q << r >>> s;\n' + |
| 3182 |
'var res = t === u !== v != w == x >= y <= z > aa < ab;\n' + |
| 3183 |
'res ??= a;\n' + |
| 3184 |
'res ||= b;\n' + |
| 3185 |
'res &&= c;\n' + |
| 3186 |
'ac + -ad') |
| 3187 |
|
| 3188 |
# operator_position option - ensure no newlines if preserve_newlines is false - (operator_position = ""after-newline"", preserve_newlines = "false") |
| 3189 |
self.reset_options() |
| 3190 |
self.options.operator_position = 'after-newline' |
| 3191 |
self.options.preserve_newlines = false |
| 3192 |
bt( |
| 3193 |
'var res = a + b - c / d * e % f;\n' + |
| 3194 |
'var res = g & h | i ^ j |> console.log;\n' + |
| 3195 |
'var res = (k && l || m) ? n ?? nn : o;\n' + |
| 3196 |
'var res = p >> q << r >>> s;\n' + |
| 3197 |
'var res = t === u !== v != w == x >= y <= z > aa < ab;\n' + |
| 3198 |
'res ??= a;\n' + |
| 3199 |
'res ||= b;\n' + |
| 3200 |
'res &&= c;\n' + |
| 3201 |
'ac + -ad') |
| 3202 |
bt( |
| 3203 |
'var res = a + b\n' + |
| 3204 |
'- c /\n' + |
| 3205 |
'd * e\n' + |
| 3206 |
'%\n' + |
| 3207 |
'f;\n' + |
| 3208 |
' var res = g & h\n' + |
| 3209 |
'| i ^\n' + |
| 3210 |
'j\n' + |
| 3211 |
'|> console.log;\n' + |
| 3212 |
'var res = (k &&\n' + |
| 3213 |
'l\n' + |
| 3214 |
'|| m) ?\n' + |
| 3215 |
'n\n' + |
| 3216 |
'?? nn\n' + |
| 3217 |
': o\n' + |
| 3218 |
';\n' + |
| 3219 |
'var res = p\n' + |
| 3220 |
'>> q <<\n' + |
| 3221 |
'r\n' + |
| 3222 |
'>>> s;\n' + |
| 3223 |
'var res\n' + |
| 3224 |
' = t\n' + |
| 3225 |
'\n' + |
| 3226 |
' === u !== v\n' + |
| 3227 |
' !=\n' + |
| 3228 |
'w\n' + |
| 3229 |
'== x >=\n' + |
| 3230 |
'y <= z > aa <\n' + |
| 3231 |
'ab;\n' + |
| 3232 |
'res??=a;res||=b;res&&=c;\n' + |
| 3233 |
'ac +\n' + |
| 3234 |
'-ad', |
| 3235 |
# -- output -- |
| 3236 |
'var res = a + b - c / d * e % f;\n' + |
| 3237 |
'var res = g & h | i ^ j |> console.log;\n' + |
| 3238 |
'var res = (k && l || m) ? n ?? nn : o;\n' + |
| 3239 |
'var res = p >> q << r >>> s;\n' + |
| 3240 |
'var res = t === u !== v != w == x >= y <= z > aa < ab;\n' + |
| 3241 |
'res ??= a;\n' + |
| 3242 |
'res ||= b;\n' + |
| 3243 |
'res &&= c;\n' + |
| 3244 |
'ac + -ad') |
| 3245 |
|
| 3246 |
# operator_position option - ensure no newlines if preserve_newlines is false - (operator_position = ""preserve-newline"", preserve_newlines = "false") |
| 3247 |
self.reset_options() |
| 3248 |
self.options.operator_position = 'preserve-newline' |
| 3249 |
self.options.preserve_newlines = false |
| 3250 |
bt( |
| 3251 |
'var res = a + b - c / d * e % f;\n' + |
| 3252 |
'var res = g & h | i ^ j |> console.log;\n' + |
| 3253 |
'var res = (k && l || m) ? n ?? nn : o;\n' + |
| 3254 |
'var res = p >> q << r >>> s;\n' + |
| 3255 |
'var res = t === u !== v != w == x >= y <= z > aa < ab;\n' + |
| 3256 |
'res ??= a;\n' + |
| 3257 |
'res ||= b;\n' + |
| 3258 |
'res &&= c;\n' + |
| 3259 |
'ac + -ad') |
| 3260 |
bt( |
| 3261 |
'var res = a + b\n' + |
| 3262 |
'- c /\n' + |
| 3263 |
'd * e\n' + |
| 3264 |
'%\n' + |
| 3265 |
'f;\n' + |
| 3266 |
' var res = g & h\n' + |
| 3267 |
'| i ^\n' + |
| 3268 |
'j\n' + |
| 3269 |
'|> console.log;\n' + |
| 3270 |
'var res = (k &&\n' + |
| 3271 |
'l\n' + |
| 3272 |
'|| m) ?\n' + |
| 3273 |
'n\n' + |
| 3274 |
'?? nn\n' + |
| 3275 |
': o\n' + |
| 3276 |
';\n' + |
| 3277 |
'var res = p\n' + |
| 3278 |
'>> q <<\n' + |
| 3279 |
'r\n' + |
| 3280 |
'>>> s;\n' + |
| 3281 |
'var res\n' + |
| 3282 |
' = t\n' + |
| 3283 |
'\n' + |
| 3284 |
' === u !== v\n' + |
| 3285 |
' !=\n' + |
| 3286 |
'w\n' + |
| 3287 |
'== x >=\n' + |
| 3288 |
'y <= z > aa <\n' + |
| 3289 |
'ab;\n' + |
| 3290 |
'res??=a;res||=b;res&&=c;\n' + |
| 3291 |
'ac +\n' + |
| 3292 |
'-ad', |
| 3293 |
# -- output -- |
| 3294 |
'var res = a + b - c / d * e % f;\n' + |
| 3295 |
'var res = g & h | i ^ j |> console.log;\n' + |
| 3296 |
'var res = (k && l || m) ? n ?? nn : o;\n' + |
| 3297 |
'var res = p >> q << r >>> s;\n' + |
| 3298 |
'var res = t === u !== v != w == x >= y <= z > aa < ab;\n' + |
| 3299 |
'res ??= a;\n' + |
| 3300 |
'res ||= b;\n' + |
| 3301 |
'res &&= c;\n' + |
| 3302 |
'ac + -ad') |
| 3303 |
|
| 3304 |
|
| 3305 |
#============================================================ |
| 3306 |
# operator_position option - set to "before-newline" (default value) - () |
| 3307 |
self.reset_options() |
| 3308 |
|
| 3309 |
# comprehensive, various newlines |
| 3310 |
bt( |
| 3311 |
'var res = a + b\n' + |
| 3312 |
'- c /\n' + |
| 3313 |
'd * e\n' + |
| 3314 |
'%\n' + |
| 3315 |
'f;\n' + |
| 3316 |
' var res = g & h\n' + |
| 3317 |
'| i ^\n' + |
| 3318 |
'j\n' + |
| 3319 |
'|> console.log;\n' + |
| 3320 |
'var res = (k &&\n' + |
| 3321 |
'l\n' + |
| 3322 |
'|| m) ?\n' + |
| 3323 |
'n\n' + |
| 3324 |
'?? nn\n' + |
| 3325 |
': o\n' + |
| 3326 |
';\n' + |
| 3327 |
'var res = p\n' + |
| 3328 |
'>> q <<\n' + |
| 3329 |
'r\n' + |
| 3330 |
'>>> s;\n' + |
| 3331 |
'var res\n' + |
| 3332 |
' = t\n' + |
| 3333 |
'\n' + |
| 3334 |
' === u !== v\n' + |
| 3335 |
' !=\n' + |
| 3336 |
'w\n' + |
| 3337 |
'== x >=\n' + |
| 3338 |
'y <= z > aa <\n' + |
| 3339 |
'ab;\n' + |
| 3340 |
'res??=a;res||=b;res&&=c;\n' + |
| 3341 |
'ac +\n' + |
| 3342 |
'-ad', |
| 3343 |
# -- output -- |
| 3344 |
'var res = a + b -\n' + |
| 3345 |
' c /\n' + |
| 3346 |
' d * e %\n' + |
| 3347 |
' f;\n' + |
| 3348 |
'var res = g & h |\n' + |
| 3349 |
' i ^\n' + |
| 3350 |
' j |>\n' + |
| 3351 |
' console.log;\n' + |
| 3352 |
'var res = (k &&\n' + |
| 3353 |
' l ||\n' + |
| 3354 |
' m) ?\n' + |
| 3355 |
' n ??\n' + |
| 3356 |
' nn :\n' + |
| 3357 |
' o;\n' + |
| 3358 |
'var res = p >>\n' + |
| 3359 |
' q <<\n' + |
| 3360 |
' r >>>\n' + |
| 3361 |
' s;\n' + |
| 3362 |
'var res = t\n' + |
| 3363 |
'\n' + |
| 3364 |
' ===\n' + |
| 3365 |
' u !== v !=\n' + |
| 3366 |
' w ==\n' + |
| 3367 |
' x >=\n' + |
| 3368 |
' y <= z > aa <\n' + |
| 3369 |
' ab;\n' + |
| 3370 |
'res ??= a;\n' + |
| 3371 |
'res ||= b;\n' + |
| 3372 |
'res &&= c;\n' + |
| 3373 |
'ac +\n' + |
| 3374 |
' -ad') |
| 3375 |
|
| 3376 |
# colon special case |
| 3377 |
bt( |
| 3378 |
'var a = {\n' + |
| 3379 |
' b\n' + |
| 3380 |
': bval,\n' + |
| 3381 |
' c:\n' + |
| 3382 |
'cval\n' + |
| 3383 |
' ,d: dval\n' + |
| 3384 |
'};\n' + |
| 3385 |
'var e = f ? g\n' + |
| 3386 |
': h;\n' + |
| 3387 |
'var i = j ? k :\n' + |
| 3388 |
'l;', |
| 3389 |
# -- output -- |
| 3390 |
'var a = {\n' + |
| 3391 |
' b: bval,\n' + |
| 3392 |
' c: cval,\n' + |
| 3393 |
' d: dval\n' + |
| 3394 |
'};\n' + |
| 3395 |
'var e = f ? g :\n' + |
| 3396 |
' h;\n' + |
| 3397 |
'var i = j ? k :\n' + |
| 3398 |
' l;') |
| 3399 |
|
| 3400 |
# catch-all, includes brackets and other various code |
| 3401 |
bt( |
| 3402 |
'var d = 1;\n' + |
| 3403 |
'if (a === b\n' + |
| 3404 |
' && c) {\n' + |
| 3405 |
' d = (c * everything\n' + |
| 3406 |
' / something_else) %\n' + |
| 3407 |
' b;\n' + |
| 3408 |
' e\n' + |
| 3409 |
' += d;\n' + |
| 3410 |
'\n' + |
| 3411 |
'} else if (!(complex && simple) ||\n' + |
| 3412 |
' (emotion && emotion.name === "happy")) {\n' + |
| 3413 |
' cryTearsOfJoy(many ||\n' + |
| 3414 |
' anOcean\n' + |
| 3415 |
' || aRiver);\n' + |
| 3416 |
'}', |
| 3417 |
# -- output -- |
| 3418 |
'var d = 1;\n' + |
| 3419 |
'if (a === b &&\n' + |
| 3420 |
' c) {\n' + |
| 3421 |
' d = (c * everything /\n' + |
| 3422 |
' something_else) %\n' + |
| 3423 |
' b;\n' + |
| 3424 |
' e\n' + |
| 3425 |
' += d;\n' + |
| 3426 |
'\n' + |
| 3427 |
'} else if (!(complex && simple) ||\n' + |
| 3428 |
' (emotion && emotion.name === "happy")) {\n' + |
| 3429 |
' cryTearsOfJoy(many ||\n' + |
| 3430 |
' anOcean ||\n' + |
| 3431 |
' aRiver);\n' + |
| 3432 |
'}') |
| 3433 |
|
| 3434 |
# operator_position option - set to "before-newline" (default value) - (operator_position = ""before-newline"") |
| 3435 |
self.reset_options() |
| 3436 |
self.options.operator_position = 'before-newline' |
| 3437 |
|
| 3438 |
# comprehensive, various newlines |
| 3439 |
bt( |
| 3440 |
'var res = a + b\n' + |
| 3441 |
'- c /\n' + |
| 3442 |
'd * e\n' + |
| 3443 |
'%\n' + |
| 3444 |
'f;\n' + |
| 3445 |
' var res = g & h\n' + |
| 3446 |
'| i ^\n' + |
| 3447 |
'j\n' + |
| 3448 |
'|> console.log;\n' + |
| 3449 |
'var res = (k &&\n' + |
| 3450 |
'l\n' + |
| 3451 |
'|| m) ?\n' + |
| 3452 |
'n\n' + |
| 3453 |
'?? nn\n' + |
| 3454 |
': o\n' + |
| 3455 |
';\n' + |
| 3456 |
'var res = p\n' + |
| 3457 |
'>> q <<\n' + |
| 3458 |
'r\n' + |
| 3459 |
'>>> s;\n' + |
| 3460 |
'var res\n' + |
| 3461 |
' = t\n' + |
| 3462 |
'\n' + |
| 3463 |
' === u !== v\n' + |
| 3464 |
' !=\n' + |
| 3465 |
'w\n' + |
| 3466 |
'== x >=\n' + |
| 3467 |
'y <= z > aa <\n' + |
| 3468 |
'ab;\n' + |
| 3469 |
'res??=a;res||=b;res&&=c;\n' + |
| 3470 |
'ac +\n' + |
| 3471 |
'-ad', |
| 3472 |
# -- output -- |
| 3473 |
'var res = a + b -\n' + |
| 3474 |
' c /\n' + |
| 3475 |
' d * e %\n' + |
| 3476 |
' f;\n' + |
| 3477 |
'var res = g & h |\n' + |
| 3478 |
' i ^\n' + |
| 3479 |
' j |>\n' + |
| 3480 |
' console.log;\n' + |
| 3481 |
'var res = (k &&\n' + |
| 3482 |
' l ||\n' + |
| 3483 |
' m) ?\n' + |
| 3484 |
' n ??\n' + |
| 3485 |
' nn :\n' + |
| 3486 |
' o;\n' + |
| 3487 |
'var res = p >>\n' + |
| 3488 |
' q <<\n' + |
| 3489 |
' r >>>\n' + |
| 3490 |
' s;\n' + |
| 3491 |
'var res = t\n' + |
| 3492 |
'\n' + |
| 3493 |
' ===\n' + |
| 3494 |
' u !== v !=\n' + |
| 3495 |
' w ==\n' + |
| 3496 |
' x >=\n' + |
| 3497 |
' y <= z > aa <\n' + |
| 3498 |
' ab;\n' + |
| 3499 |
'res ??= a;\n' + |
| 3500 |
'res ||= b;\n' + |
| 3501 |
'res &&= c;\n' + |
| 3502 |
'ac +\n' + |
| 3503 |
' -ad') |
| 3504 |
|
| 3505 |
# colon special case |
| 3506 |
bt( |
| 3507 |
'var a = {\n' + |
| 3508 |
' b\n' + |
| 3509 |
': bval,\n' + |
| 3510 |
' c:\n' + |
| 3511 |
'cval\n' + |
| 3512 |
' ,d: dval\n' + |
| 3513 |
'};\n' + |
| 3514 |
'var e = f ? g\n' + |
| 3515 |
': h;\n' + |
| 3516 |
'var i = j ? k :\n' + |
| 3517 |
'l;', |
| 3518 |
# -- output -- |
| 3519 |
'var a = {\n' + |
| 3520 |
' b: bval,\n' + |
| 3521 |
' c: cval,\n' + |
| 3522 |
' d: dval\n' + |
| 3523 |
'};\n' + |
| 3524 |
'var e = f ? g :\n' + |
| 3525 |
' h;\n' + |
| 3526 |
'var i = j ? k :\n' + |
| 3527 |
' l;') |
| 3528 |
|
| 3529 |
# catch-all, includes brackets and other various code |
| 3530 |
bt( |
| 3531 |
'var d = 1;\n' + |
| 3532 |
'if (a === b\n' + |
| 3533 |
' && c) {\n' + |
| 3534 |
' d = (c * everything\n' + |
| 3535 |
' / something_else) %\n' + |
| 3536 |
' b;\n' + |
| 3537 |
' e\n' + |
| 3538 |
' += d;\n' + |
| 3539 |
'\n' + |
| 3540 |
'} else if (!(complex && simple) ||\n' + |
| 3541 |
' (emotion && emotion.name === "happy")) {\n' + |
| 3542 |
' cryTearsOfJoy(many ||\n' + |
| 3543 |
' anOcean\n' + |
| 3544 |
' || aRiver);\n' + |
| 3545 |
'}', |
| 3546 |
# -- output -- |
| 3547 |
'var d = 1;\n' + |
| 3548 |
'if (a === b &&\n' + |
| 3549 |
' c) {\n' + |
| 3550 |
' d = (c * everything /\n' + |
| 3551 |
' something_else) %\n' + |
| 3552 |
' b;\n' + |
| 3553 |
' e\n' + |
| 3554 |
' += d;\n' + |
| 3555 |
'\n' + |
| 3556 |
'} else if (!(complex && simple) ||\n' + |
| 3557 |
' (emotion && emotion.name === "happy")) {\n' + |
| 3558 |
' cryTearsOfJoy(many ||\n' + |
| 3559 |
' anOcean ||\n' + |
| 3560 |
' aRiver);\n' + |
| 3561 |
'}') |
| 3562 |
|
| 3563 |
|
| 3564 |
#============================================================ |
| 3565 |
# operator_position option - set to "after_newline" |
| 3566 |
self.reset_options() |
| 3567 |
self.options.operator_position = 'after-newline' |
| 3568 |
|
| 3569 |
# comprehensive, various newlines |
| 3570 |
bt( |
| 3571 |
'var res = a + b\n' + |
| 3572 |
'- c /\n' + |
| 3573 |
'd * e\n' + |
| 3574 |
'%\n' + |
| 3575 |
'f;\n' + |
| 3576 |
' var res = g & h\n' + |
| 3577 |
'| i ^\n' + |
| 3578 |
'j\n' + |
| 3579 |
'|> console.log;\n' + |
| 3580 |
'var res = (k &&\n' + |
| 3581 |
'l\n' + |
| 3582 |
'|| m) ?\n' + |
| 3583 |
'n\n' + |
| 3584 |
'?? nn\n' + |
| 3585 |
': o\n' + |
| 3586 |
';\n' + |
| 3587 |
'var res = p\n' + |
| 3588 |
'>> q <<\n' + |
| 3589 |
'r\n' + |
| 3590 |
'>>> s;\n' + |
| 3591 |
'var res\n' + |
| 3592 |
' = t\n' + |
| 3593 |
'\n' + |
| 3594 |
' === u !== v\n' + |
| 3595 |
' !=\n' + |
| 3596 |
'w\n' + |
| 3597 |
'== x >=\n' + |
| 3598 |
'y <= z > aa <\n' + |
| 3599 |
'ab;\n' + |
| 3600 |
'res??=a;res||=b;res&&=c;\n' + |
| 3601 |
'ac +\n' + |
| 3602 |
'-ad', |
| 3603 |
# -- output -- |
| 3604 |
'var res = a + b\n' + |
| 3605 |
' - c\n' + |
| 3606 |
' / d * e\n' + |
| 3607 |
' % f;\n' + |
| 3608 |
'var res = g & h\n' + |
| 3609 |
' | i\n' + |
| 3610 |
' ^ j\n' + |
| 3611 |
' |> console.log;\n' + |
| 3612 |
'var res = (k\n' + |
| 3613 |
' && l\n' + |
| 3614 |
' || m)\n' + |
| 3615 |
' ? n\n' + |
| 3616 |
' ?? nn\n' + |
| 3617 |
' : o;\n' + |
| 3618 |
'var res = p\n' + |
| 3619 |
' >> q\n' + |
| 3620 |
' << r\n' + |
| 3621 |
' >>> s;\n' + |
| 3622 |
'var res = t\n' + |
| 3623 |
'\n' + |
| 3624 |
' === u !== v\n' + |
| 3625 |
' != w\n' + |
| 3626 |
' == x\n' + |
| 3627 |
' >= y <= z > aa\n' + |
| 3628 |
' < ab;\n' + |
| 3629 |
'res ??= a;\n' + |
| 3630 |
'res ||= b;\n' + |
| 3631 |
'res &&= c;\n' + |
| 3632 |
'ac\n' + |
| 3633 |
' + -ad') |
| 3634 |
|
| 3635 |
# colon special case |
| 3636 |
bt( |
| 3637 |
'var a = {\n' + |
| 3638 |
' b\n' + |
| 3639 |
': bval,\n' + |
| 3640 |
' c:\n' + |
| 3641 |
'cval\n' + |
| 3642 |
' ,d: dval\n' + |
| 3643 |
'};\n' + |
| 3644 |
'var e = f ? g\n' + |
| 3645 |
': h;\n' + |
| 3646 |
'var i = j ? k :\n' + |
| 3647 |
'l;', |
| 3648 |
# -- output -- |
| 3649 |
'var a = {\n' + |
| 3650 |
' b: bval,\n' + |
| 3651 |
' c: cval,\n' + |
| 3652 |
' d: dval\n' + |
| 3653 |
'};\n' + |
| 3654 |
'var e = f ? g\n' + |
| 3655 |
' : h;\n' + |
| 3656 |
'var i = j ? k\n' + |
| 3657 |
' : l;') |
| 3658 |
|
| 3659 |
# catch-all, includes brackets and other various code |
| 3660 |
bt( |
| 3661 |
'var d = 1;\n' + |
| 3662 |
'if (a === b\n' + |
| 3663 |
' && c) {\n' + |
| 3664 |
' d = (c * everything\n' + |
| 3665 |
' / something_else) %\n' + |
| 3666 |
' b;\n' + |
| 3667 |
' e\n' + |
| 3668 |
' += d;\n' + |
| 3669 |
'\n' + |
| 3670 |
'} else if (!(complex && simple) ||\n' + |
| 3671 |
' (emotion && emotion.name === "happy")) {\n' + |
| 3672 |
' cryTearsOfJoy(many ||\n' + |
| 3673 |
' anOcean\n' + |
| 3674 |
' || aRiver);\n' + |
| 3675 |
'}', |
| 3676 |
# -- output -- |
| 3677 |
'var d = 1;\n' + |
| 3678 |
'if (a === b\n' + |
| 3679 |
' && c) {\n' + |
| 3680 |
' d = (c * everything\n' + |
| 3681 |
' / something_else)\n' + |
| 3682 |
' % b;\n' + |
| 3683 |
' e\n' + |
| 3684 |
' += d;\n' + |
| 3685 |
'\n' + |
| 3686 |
'} else if (!(complex && simple)\n' + |
| 3687 |
' || (emotion && emotion.name === "happy")) {\n' + |
| 3688 |
' cryTearsOfJoy(many\n' + |
| 3689 |
' || anOcean\n' + |
| 3690 |
' || aRiver);\n' + |
| 3691 |
'}') |
| 3692 |
|
| 3693 |
|
| 3694 |
#============================================================ |
| 3695 |
# operator_position option - set to "preserve-newline" |
| 3696 |
self.reset_options() |
| 3697 |
self.options.operator_position = 'preserve-newline' |
| 3698 |
|
| 3699 |
# comprehensive, various newlines |
| 3700 |
bt( |
| 3701 |
'var res = a + b\n' + |
| 3702 |
'- c /\n' + |
| 3703 |
'd * e\n' + |
| 3704 |
'%\n' + |
| 3705 |
'f;\n' + |
| 3706 |
' var res = g & h\n' + |
| 3707 |
'| i ^\n' + |
| 3708 |
'j\n' + |
| 3709 |
'|> console.log;\n' + |
| 3710 |
'var res = (k &&\n' + |
| 3711 |
'l\n' + |
| 3712 |
'|| m) ?\n' + |
| 3713 |
'n\n' + |
| 3714 |
'?? nn\n' + |
| 3715 |
': o\n' + |
| 3716 |
';\n' + |
| 3717 |
'var res = p\n' + |
| 3718 |
'>> q <<\n' + |
| 3719 |
'r\n' + |
| 3720 |
'>>> s;\n' + |
| 3721 |
'var res\n' + |
| 3722 |
' = t\n' + |
| 3723 |
'\n' + |
| 3724 |
' === u !== v\n' + |
| 3725 |
' !=\n' + |
| 3726 |
'w\n' + |
| 3727 |
'== x >=\n' + |
| 3728 |
'y <= z > aa <\n' + |
| 3729 |
'ab;\n' + |
| 3730 |
'res??=a;res||=b;res&&=c;\n' + |
| 3731 |
'ac +\n' + |
| 3732 |
'-ad', |
| 3733 |
# -- output -- |
| 3734 |
'var res = a + b\n' + |
| 3735 |
' - c /\n' + |
| 3736 |
' d * e\n' + |
| 3737 |
' %\n' + |
| 3738 |
' f;\n' + |
| 3739 |
'var res = g & h\n' + |
| 3740 |
' | i ^\n' + |
| 3741 |
' j\n' + |
| 3742 |
' |> console.log;\n' + |
| 3743 |
'var res = (k &&\n' + |
| 3744 |
' l\n' + |
| 3745 |
' || m) ?\n' + |
| 3746 |
' n\n' + |
| 3747 |
' ?? nn\n' + |
| 3748 |
' : o;\n' + |
| 3749 |
'var res = p\n' + |
| 3750 |
' >> q <<\n' + |
| 3751 |
' r\n' + |
| 3752 |
' >>> s;\n' + |
| 3753 |
'var res = t\n' + |
| 3754 |
'\n' + |
| 3755 |
' === u !== v\n' + |
| 3756 |
' !=\n' + |
| 3757 |
' w\n' + |
| 3758 |
' == x >=\n' + |
| 3759 |
' y <= z > aa <\n' + |
| 3760 |
' ab;\n' + |
| 3761 |
'res ??= a;\n' + |
| 3762 |
'res ||= b;\n' + |
| 3763 |
'res &&= c;\n' + |
| 3764 |
'ac +\n' + |
| 3765 |
' -ad') |
| 3766 |
|
| 3767 |
# colon special case |
| 3768 |
bt( |
| 3769 |
'var a = {\n' + |
| 3770 |
' b\n' + |
| 3771 |
': bval,\n' + |
| 3772 |
' c:\n' + |
| 3773 |
'cval\n' + |
| 3774 |
' ,d: dval\n' + |
| 3775 |
'};\n' + |
| 3776 |
'var e = f ? g\n' + |
| 3777 |
': h;\n' + |
| 3778 |
'var i = j ? k :\n' + |
| 3779 |
'l;', |
| 3780 |
# -- output -- |
| 3781 |
'var a = {\n' + |
| 3782 |
' b: bval,\n' + |
| 3783 |
' c: cval,\n' + |
| 3784 |
' d: dval\n' + |
| 3785 |
'};\n' + |
| 3786 |
'var e = f ? g\n' + |
| 3787 |
' : h;\n' + |
| 3788 |
'var i = j ? k :\n' + |
| 3789 |
' l;') |
| 3790 |
|
| 3791 |
# catch-all, includes brackets and other various code |
| 3792 |
bt( |
| 3793 |
'var d = 1;\n' + |
| 3794 |
'if (a === b\n' + |
| 3795 |
' && c) {\n' + |
| 3796 |
' d = (c * everything\n' + |
| 3797 |
' / something_else) %\n' + |
| 3798 |
' b;\n' + |
| 3799 |
' e\n' + |
| 3800 |
' += d;\n' + |
| 3801 |
'\n' + |
| 3802 |
'} else if (!(complex && simple) ||\n' + |
| 3803 |
' (emotion && emotion.name === "happy")) {\n' + |
| 3804 |
' cryTearsOfJoy(many ||\n' + |
| 3805 |
' anOcean\n' + |
| 3806 |
' || aRiver);\n' + |
| 3807 |
'}') |
| 3808 |
|
| 3809 |
|
| 3810 |
#============================================================ |
| 3811 |
# Yield tests |
| 3812 |
self.reset_options() |
| 3813 |
bt('yield /foo\\//;') |
| 3814 |
bt('result = yield pgClient.query_(queryString);') |
| 3815 |
bt('yield [1, 2]') |
| 3816 |
bt('yield function() {};') |
| 3817 |
bt('yield* bar();') |
| 3818 |
|
| 3819 |
# yield should have no space between yield and star |
| 3820 |
bt('yield * bar();', 'yield* bar();') |
| 3821 |
|
| 3822 |
# yield should have space between star and generator |
| 3823 |
bt('yield *bar();', 'yield* bar();') |
| 3824 |
|
| 3825 |
|
| 3826 |
#============================================================ |
| 3827 |
# Async / await tests |
| 3828 |
self.reset_options() |
| 3829 |
bt('async function foo() {}') |
| 3830 |
bt('let w = async function foo() {}') |
| 3831 |
bt( |
| 3832 |
'async function foo() {}\n' + |
| 3833 |
'var x = await foo();') |
| 3834 |
|
| 3835 |
# async function as an input to another function |
| 3836 |
bt('wrapper(async function foo() {})') |
| 3837 |
|
| 3838 |
# await on inline anonymous function. should have a space after await |
| 3839 |
bt( |
| 3840 |
'async function() {\n' + |
| 3841 |
' var w = await(async function() {\n' + |
| 3842 |
' return await foo();\n' + |
| 3843 |
' })();\n' + |
| 3844 |
'}', |
| 3845 |
# -- output -- |
| 3846 |
'async function() {\n' + |
| 3847 |
' var w = await (async function() {\n' + |
| 3848 |
' return await foo();\n' + |
| 3849 |
' })();\n' + |
| 3850 |
'}') |
| 3851 |
|
| 3852 |
# Regression test #1228 |
| 3853 |
bt('const module = await import("...")') |
| 3854 |
|
| 3855 |
# Regression test #1658 |
| 3856 |
bt('.') |
| 3857 |
|
| 3858 |
# ensure that this doesn't break anyone with the async library |
| 3859 |
bt('async.map(function(t) {})') |
| 3860 |
|
| 3861 |
# async on arrow function. should have a space after async |
| 3862 |
bt( |
| 3863 |
'async() => {}', |
| 3864 |
# -- output -- |
| 3865 |
'async () => {}') |
| 3866 |
|
| 3867 |
# async on arrow function. should have a space after async |
| 3868 |
bt( |
| 3869 |
'async() => {\n' + |
| 3870 |
' return 5;\n' + |
| 3871 |
'}', |
| 3872 |
# -- output -- |
| 3873 |
'async () => {\n' + |
| 3874 |
' return 5;\n' + |
| 3875 |
'}') |
| 3876 |
|
| 3877 |
# async on arrow function returning expression. should have a space after async |
| 3878 |
bt( |
| 3879 |
'async() => 5;', |
| 3880 |
# -- output -- |
| 3881 |
'async () => 5;') |
| 3882 |
|
| 3883 |
# async on arrow function returning object literal. should have a space after async |
| 3884 |
bt( |
| 3885 |
'async(x) => ({\n' + |
| 3886 |
' foo: "5"\n' + |
| 3887 |
'})', |
| 3888 |
# -- output -- |
| 3889 |
'async (x) => ({\n' + |
| 3890 |
' foo: "5"\n' + |
| 3891 |
'})') |
| 3892 |
bt( |
| 3893 |
'async (x) => {\n' + |
| 3894 |
' return x * 2;\n' + |
| 3895 |
'}') |
| 3896 |
bt('async () => 5;') |
| 3897 |
bt('async x => x * 2;') |
| 3898 |
bt( |
| 3899 |
'async function() {\n' + |
| 3900 |
' const obj = {\n' + |
| 3901 |
' a: 1,\n' + |
| 3902 |
' b: await fn(),\n' + |
| 3903 |
' c: 2\n' + |
| 3904 |
' };\n' + |
| 3905 |
'}') |
| 3906 |
bt( |
| 3907 |
'const a = 1,\n' + |
| 3908 |
' b = a ? await foo() : b,\n' + |
| 3909 |
' c = await foo(),\n' + |
| 3910 |
' d = 3,\n' + |
| 3911 |
' e = (await foo()),\n' + |
| 3912 |
' f = 4;') |
| 3913 |
bt( |
| 3914 |
'a = {\n' + |
| 3915 |
' myVar: async function() {\n' + |
| 3916 |
' return a;\n' + |
| 3917 |
' },\n' + |
| 3918 |
' myOtherVar: async function() {\n' + |
| 3919 |
' yield b;\n' + |
| 3920 |
' }\n' + |
| 3921 |
'}') |
| 3922 |
bt( |
| 3923 |
'a = {\n' + |
| 3924 |
' myVar: async () => {\n' + |
| 3925 |
' return a;\n' + |
| 3926 |
' },\n' + |
| 3927 |
' myOtherVar: async async () => {\n' + |
| 3928 |
' yield b;\n' + |
| 3929 |
' }\n' + |
| 3930 |
'}') |
| 3931 |
|
| 3932 |
|
| 3933 |
#============================================================ |
| 3934 |
# e4x - Test that e4x literals passed through when e4x-option is enabled |
| 3935 |
self.reset_options() |
| 3936 |
self.options.e4x = true |
| 3937 |
bt( |
| 3938 |
'xml=<a b="c"><d/><e>\n' + |
| 3939 |
' foo</e>x</a>;', |
| 3940 |
# -- output -- |
| 3941 |
'xml = <a b="c"><d/><e>\n' + |
| 3942 |
' foo</e>x</a>;') |
| 3943 |
bt('<a b=\'This is a quoted "c".\'/>') |
| 3944 |
bt('<a b="This is a quoted \'c\'."/>') |
| 3945 |
bt('<a b="A quote \' inside string."/>') |
| 3946 |
bt('<a b=\'A quote " inside string.\'/>') |
| 3947 |
bt('<a b=\'Some """ quotes "" inside string.\'/>') |
| 3948 |
|
| 3949 |
# Handles inline expressions |
| 3950 |
bt( |
| 3951 |
'xml=<{a} b="c"><d/><e v={z}>\n' + |
| 3952 |
' foo</e>x</{a}>;', |
| 3953 |
# -- output -- |
| 3954 |
'xml = <{a} b="c"><d/><e v={z}>\n' + |
| 3955 |
' foo</e>x</{a}>;') |
| 3956 |
bt( |
| 3957 |
'xml=<{a} b="c">\n' + |
| 3958 |
' <e v={z}>\n' + |
| 3959 |
' foo</e>x</{a}>;', |
| 3960 |
# -- output -- |
| 3961 |
'xml = <{a} b="c">\n' + |
| 3962 |
' <e v={z}>\n' + |
| 3963 |
' foo</e>x</{a}>;') |
| 3964 |
|
| 3965 |
# xml literals with special characters in elem names - see http://www.w3.org/TR/REC-xml/#NT-NameChar |
| 3966 |
bt('xml = <_:.valid.xml- _:.valid.xml-="123"/>;') |
| 3967 |
|
| 3968 |
# xml literals with attributes without equal sign |
| 3969 |
bt('xml = <elem someAttr/>;') |
| 3970 |
|
| 3971 |
# Handles CDATA |
| 3972 |
bt( |
| 3973 |
'xml=<![CDATA[ b="c"><d/><e v={z}>\n' + |
| 3974 |
' foo</e>x/]]>;', |
| 3975 |
# -- output -- |
| 3976 |
'xml = <![CDATA[ b="c"><d/><e v={z}>\n' + |
| 3977 |
' foo</e>x/]]>;') |
| 3978 |
bt('xml=<![CDATA[]]>;', 'xml = <![CDATA[]]>;') |
| 3979 |
bt('xml=<a b="c"><![CDATA[d/></a></{}]]></a>;', 'xml = <a b="c"><![CDATA[d/></a></{}]]></a>;') |
| 3980 |
|
| 3981 |
# JSX - working jsx from http://prettydiff.com/unit_tests/beautification_javascript_jsx.txt |
| 3982 |
bt( |
| 3983 |
'var ListItem = React.createClass({\n' + |
| 3984 |
' render: function() {\n' + |
| 3985 |
' return (\n' + |
| 3986 |
' <li className="ListItem">\n' + |
| 3987 |
' <a href={ "/items/" + this.props.item.id }>\n' + |
| 3988 |
' this.props.item.name\n' + |
| 3989 |
' </a>\n' + |
| 3990 |
' </li>\n' + |
| 3991 |
' );\n' + |
| 3992 |
' }\n' + |
| 3993 |
'});') |
| 3994 |
bt( |
| 3995 |
'var List = React.createClass({\n' + |
| 3996 |
' renderList: function() {\n' + |
| 3997 |
' return this.props.items.map(function(item) {\n' + |
| 3998 |
' return <ListItem item={item} key={item.id} />;\n' + |
| 3999 |
' });\n' + |
| 4000 |
' },\n' + |
| 4001 |
'\n' + |
| 4002 |
' render: function() {\n' + |
| 4003 |
' return <ul className="List">\n' + |
| 4004 |
' this.renderList()\n' + |
| 4005 |
' </ul>\n' + |
| 4006 |
' }\n' + |
| 4007 |
'});') |
| 4008 |
bt( |
| 4009 |
'var Mist = React.createClass({\n' + |
| 4010 |
' renderList: function() {\n' + |
| 4011 |
' return this.props.items.map(function(item) {\n' + |
| 4012 |
' return <ListItem item={return <tag>{item}</tag>} key={item.id} />;\n' + |
| 4013 |
' });\n' + |
| 4014 |
' }\n' + |
| 4015 |
'});') |
| 4016 |
bt( |
| 4017 |
'// JSX\n' + |
| 4018 |
'var box = <Box>\n' + |
| 4019 |
' {shouldShowAnswer(user) ?\n' + |
| 4020 |
' <Answer value={false}>no</Answer> : <Box.Comment>\n' + |
| 4021 |
' Text Content\n' + |
| 4022 |
' </Box.Comment>}\n' + |
| 4023 |
' </Box>;\n' + |
| 4024 |
'var a = function() {\n' + |
| 4025 |
' return <tsdf>asdf</tsdf>;\n' + |
| 4026 |
'};\n' + |
| 4027 |
'\n' + |
| 4028 |
'var HelloMessage = React.createClass({\n' + |
| 4029 |
' render: function() {\n' + |
| 4030 |
' return <div {someAttr}>Hello {this.props.name}</div>;\n' + |
| 4031 |
' }\n' + |
| 4032 |
'});\n' + |
| 4033 |
'React.render(<HelloMessage name="John" />, mountNode);') |
| 4034 |
bt( |
| 4035 |
'var Timer = React.createClass({\n' + |
| 4036 |
' getInitialState: function() {\n' + |
| 4037 |
' return {\n' + |
| 4038 |
' secondsElapsed: 0\n' + |
| 4039 |
' };\n' + |
| 4040 |
' },\n' + |
| 4041 |
' tick: function() {\n' + |
| 4042 |
' this.setState({\n' + |
| 4043 |
' secondsElapsed: this.state.secondsElapsed + 1\n' + |
| 4044 |
' });\n' + |
| 4045 |
' },\n' + |
| 4046 |
' componentDidMount: function() {\n' + |
| 4047 |
' this.interval = setInterval(this.tick, 1000);\n' + |
| 4048 |
' },\n' + |
| 4049 |
' componentWillUnmount: function() {\n' + |
| 4050 |
' clearInterval(this.interval);\n' + |
| 4051 |
' },\n' + |
| 4052 |
' render: function() {\n' + |
| 4053 |
' return (\n' + |
| 4054 |
' <div>Seconds Elapsed: {this.state.secondsElapsed}</div>\n' + |
| 4055 |
' );\n' + |
| 4056 |
' }\n' + |
| 4057 |
'});\n' + |
| 4058 |
'React.render(<Timer />, mountNode);') |
| 4059 |
bt( |
| 4060 |
'var TodoList = React.createClass({\n' + |
| 4061 |
' render: function() {\n' + |
| 4062 |
' var createItem = function(itemText) {\n' + |
| 4063 |
' return <li>{itemText}</li>;\n' + |
| 4064 |
' };\n' + |
| 4065 |
' return <ul>{this.props.items.map(createItem)}</ul>;\n' + |
| 4066 |
' }\n' + |
| 4067 |
'});') |
| 4068 |
bt( |
| 4069 |
'var TodoApp = React.createClass({\n' + |
| 4070 |
' getInitialState: function() {\n' + |
| 4071 |
' return {\n' + |
| 4072 |
' items: [],\n' + |
| 4073 |
' text: \'\'\n' + |
| 4074 |
' };\n' + |
| 4075 |
' },\n' + |
| 4076 |
' onChange: function(e) {\n' + |
| 4077 |
' this.setState({\n' + |
| 4078 |
' text: e.target.value\n' + |
| 4079 |
' });\n' + |
| 4080 |
' },\n' + |
| 4081 |
' handleSubmit: function(e) {\n' + |
| 4082 |
' e.preventDefault();\n' + |
| 4083 |
' var nextItems = this.state.items.concat([this.state.text]);\n' + |
| 4084 |
' var nextText = \'\';\n' + |
| 4085 |
' this.setState({\n' + |
| 4086 |
' items: nextItems,\n' + |
| 4087 |
' text: nextText\n' + |
| 4088 |
' });\n' + |
| 4089 |
' },\n' + |
| 4090 |
' render: function() {\n' + |
| 4091 |
' return (\n' + |
| 4092 |
' <div>\n' + |
| 4093 |
' <h3 {someAttr}>TODO</h3>\n' + |
| 4094 |
' <TodoList items={this.state.items} />\n' + |
| 4095 |
' <form onSubmit={this.handleSubmit}>\n' + |
| 4096 |
' <input onChange={this.onChange} value={this.state.text} />\n' + |
| 4097 |
' <button>{\'Add #\' + (this.state.items.length + 1)}</button>\n' + |
| 4098 |
' </form>\n' + |
| 4099 |
' </div>\n' + |
| 4100 |
' );\n' + |
| 4101 |
' }\n' + |
| 4102 |
'});\n' + |
| 4103 |
'React.render(<TodoApp />, mountNode);') |
| 4104 |
bt( |
| 4105 |
'var converter = new Showdown.converter();\n' + |
| 4106 |
'var MarkdownEditor = React.createClass({\n' + |
| 4107 |
' getInitialState: function() {\n' + |
| 4108 |
' return {value: \'Type some *markdown* here!\'};\n' + |
| 4109 |
' },\n' + |
| 4110 |
' handleChange: function() {\n' + |
| 4111 |
' this.setState({value: this.refs.textarea.getDOMNode().value});\n' + |
| 4112 |
' },\n' + |
| 4113 |
' render: function() {\n' + |
| 4114 |
' return (\n' + |
| 4115 |
' <div className="MarkdownEditor">\n' + |
| 4116 |
' <h3>Input</h3>\n' + |
| 4117 |
' <textarea\n' + |
| 4118 |
' onChange={this.handleChange}\n' + |
| 4119 |
' ref="textarea"\n' + |
| 4120 |
' defaultValue={this.state.value} />\n' + |
| 4121 |
' <h3>Output</h3>\n' + |
| 4122 |
' <div\n' + |
| 4123 |
' className="content"\n' + |
| 4124 |
' dangerouslySetInnerHTML=\n' + |
| 4125 |
' />\n' + |
| 4126 |
' </div>\n' + |
| 4127 |
' );\n' + |
| 4128 |
' }\n' + |
| 4129 |
'});\n' + |
| 4130 |
'React.render(<MarkdownEditor />, mountNode);', |
| 4131 |
# -- output -- |
| 4132 |
'var converter = new Showdown.converter();\n' + |
| 4133 |
'var MarkdownEditor = React.createClass({\n' + |
| 4134 |
' getInitialState: function() {\n' + |
| 4135 |
' return {\n' + |
| 4136 |
' value: \'Type some *markdown* here!\'\n' + |
| 4137 |
' };\n' + |
| 4138 |
' },\n' + |
| 4139 |
' handleChange: function() {\n' + |
| 4140 |
' this.setState({\n' + |
| 4141 |
' value: this.refs.textarea.getDOMNode().value\n' + |
| 4142 |
' });\n' + |
| 4143 |
' },\n' + |
| 4144 |
' render: function() {\n' + |
| 4145 |
' return (\n' + |
| 4146 |
' <div className="MarkdownEditor">\n' + |
| 4147 |
' <h3>Input</h3>\n' + |
| 4148 |
' <textarea\n' + |
| 4149 |
' onChange={this.handleChange}\n' + |
| 4150 |
' ref="textarea"\n' + |
| 4151 |
' defaultValue={this.state.value} />\n' + |
| 4152 |
' <h3>Output</h3>\n' + |
| 4153 |
' <div\n' + |
| 4154 |
' className="content"\n' + |
| 4155 |
' dangerouslySetInnerHTML=\n' + |
| 4156 |
' />\n' + |
| 4157 |
' </div>\n' + |
| 4158 |
' );\n' + |
| 4159 |
' }\n' + |
| 4160 |
'});\n' + |
| 4161 |
'React.render(<MarkdownEditor />, mountNode);') |
| 4162 |
|
| 4163 |
# JSX - Not quite correct jsx formatting that still works |
| 4164 |
bt( |
| 4165 |
'var content = (\n' + |
| 4166 |
' <Nav>\n' + |
| 4167 |
' {/* child comment, put {} around */}\n' + |
| 4168 |
' <Person\n' + |
| 4169 |
' /* multi\n' + |
| 4170 |
' line\n' + |
| 4171 |
' comment */\n' + |
| 4172 |
' //attr="test"\n' + |
| 4173 |
' name={window.isLoggedIn ? window.name : \'\'} // end of line comment\n' + |
| 4174 |
' />\n' + |
| 4175 |
' </Nav>\n' + |
| 4176 |
' );\n' + |
| 4177 |
'var qwer = <DropDown> A dropdown list <Menu> <MenuItem>Do Something</MenuItem> <MenuItem>Do Something Fun!</MenuItem> <MenuItem>Do Something Else</MenuItem> </Menu> </DropDown>;\n' + |
| 4178 |
'render(dropdown);', |
| 4179 |
# -- output -- |
| 4180 |
'var content = (\n' + |
| 4181 |
' <Nav>\n' + |
| 4182 |
' {/* child comment, put {} around */}\n' + |
| 4183 |
' <Person\n' + |
| 4184 |
' /* multi\n' + |
| 4185 |
' line\n' + |
| 4186 |
' comment */\n' + |
| 4187 |
' //attr="test"\n' + |
| 4188 |
' name={window.isLoggedIn ? window.name : \'\'} // end of line comment\n' + |
| 4189 |
' />\n' + |
| 4190 |
' </Nav>\n' + |
| 4191 |
');\n' + |
| 4192 |
'var qwer = <DropDown> A dropdown list <Menu> <MenuItem>Do Something</MenuItem> <MenuItem>Do Something Fun!</MenuItem> <MenuItem>Do Something Else</MenuItem> </Menu> </DropDown>;\n' + |
| 4193 |
'render(dropdown);') |
| 4194 |
|
| 4195 |
# Handles messed up tags, as long as it isn't the same name |
| 4196 |
# as the root tag. Also handles tags of same name as root tag |
| 4197 |
# as long as nesting matches. |
| 4198 |
bt( |
| 4199 |
'xml=<a x="jn"><c></b></f><a><d jnj="jnn"><f></a ></nj></a>;', |
| 4200 |
# -- output -- |
| 4201 |
'xml = <a x="jn"><c></b></f><a><d jnj="jnn"><f></a ></nj></a>;') |
| 4202 |
|
| 4203 |
# If xml is not terminated, the remainder of the file is treated |
| 4204 |
# as part of the xml-literal (passed through unaltered) |
| 4205 |
test_fragment( |
| 4206 |
'xml=<a></b>\n' + |
| 4207 |
'c<b;', |
| 4208 |
# -- output -- |
| 4209 |
'xml = <a></b>\n' + |
| 4210 |
'c<b;') |
| 4211 |
|
| 4212 |
# Issue #646 = whitespace is allowed in attribute declarations |
| 4213 |
bt( |
| 4214 |
'let a = React.createClass({\n' + |
| 4215 |
' render() {\n' + |
| 4216 |
' return (\n' + |
| 4217 |
' <p className=\'a\'>\n' + |
| 4218 |
' <span>c</span>\n' + |
| 4219 |
' </p>\n' + |
| 4220 |
' );\n' + |
| 4221 |
' }\n' + |
| 4222 |
'});') |
| 4223 |
bt( |
| 4224 |
'let a = React.createClass({\n' + |
| 4225 |
' render() {\n' + |
| 4226 |
' return (\n' + |
| 4227 |
' <p className = \'b\'>\n' + |
| 4228 |
' <span>c</span>\n' + |
| 4229 |
' </p>\n' + |
| 4230 |
' );\n' + |
| 4231 |
' }\n' + |
| 4232 |
'});') |
| 4233 |
bt( |
| 4234 |
'let a = React.createClass({\n' + |
| 4235 |
' render() {\n' + |
| 4236 |
' return (\n' + |
| 4237 |
' <p className = "c">\n' + |
| 4238 |
' <span>c</span>\n' + |
| 4239 |
' </p>\n' + |
| 4240 |
' );\n' + |
| 4241 |
' }\n' + |
| 4242 |
'});') |
| 4243 |
bt( |
| 4244 |
'let a = React.createClass({\n' + |
| 4245 |
' render() {\n' + |
| 4246 |
' return (\n' + |
| 4247 |
' <{e} className = {d}>\n' + |
| 4248 |
' <span>c</span>\n' + |
| 4249 |
' </{e}>\n' + |
| 4250 |
' );\n' + |
| 4251 |
' }\n' + |
| 4252 |
'});') |
| 4253 |
|
| 4254 |
# Issue #914 - Multiline attribute in root tag |
| 4255 |
bt( |
| 4256 |
'return (\n' + |
| 4257 |
' <a href="#"\n' + |
| 4258 |
' onClick={e => {\n' + |
| 4259 |
' e.preventDefault()\n' + |
| 4260 |
' onClick()\n' + |
| 4261 |
' }}>\n' + |
| 4262 |
' {children}\n' + |
| 4263 |
' </a>\n' + |
| 4264 |
');') |
| 4265 |
bt( |
| 4266 |
'return (\n' + |
| 4267 |
' <{\n' + |
| 4268 |
' a + b\n' + |
| 4269 |
' } href="#"\n' + |
| 4270 |
' onClick={e => {\n' + |
| 4271 |
' e.preventDefault()\n' + |
| 4272 |
' onClick()\n' + |
| 4273 |
' }}>\n' + |
| 4274 |
' {children}\n' + |
| 4275 |
' </{\n' + |
| 4276 |
' a + b\n' + |
| 4277 |
' }>\n' + |
| 4278 |
');') |
| 4279 |
bt( |
| 4280 |
'return (\n' + |
| 4281 |
' <{\n' + |
| 4282 |
' a + b\n' + |
| 4283 |
' } href="#"\n' + |
| 4284 |
' onClick={e => {\n' + |
| 4285 |
' e.preventDefault()\n' + |
| 4286 |
' onClick()\n' + |
| 4287 |
' }}>\n' + |
| 4288 |
' {children}\n' + |
| 4289 |
' </{a + b}>\n' + |
| 4290 |
' );', |
| 4291 |
# -- output -- |
| 4292 |
'return (\n' + |
| 4293 |
' <{\n' + |
| 4294 |
' a + b\n' + |
| 4295 |
' } href="#"\n' + |
| 4296 |
' onClick={e => {\n' + |
| 4297 |
' e.preventDefault()\n' + |
| 4298 |
' onClick()\n' + |
| 4299 |
' }}>\n' + |
| 4300 |
' {children}\n' + |
| 4301 |
' </{a + b}>\n' + |
| 4302 |
');') |
| 4303 |
bt( |
| 4304 |
'class Columns extends React.Component {\n' + |
| 4305 |
' render() {\n' + |
| 4306 |
' return (\n' + |
| 4307 |
' <>\n' + |
| 4308 |
' <td>Hello</td>\n' + |
| 4309 |
' <td>World</td>\n' + |
| 4310 |
' </>\n' + |
| 4311 |
' );\n' + |
| 4312 |
' }\n' + |
| 4313 |
'}') |
| 4314 |
|
| 4315 |
|
| 4316 |
#============================================================ |
| 4317 |
# |
| 4318 |
self.reset_options() |
| 4319 |
|
| 4320 |
|
| 4321 |
#============================================================ |
| 4322 |
# e4x disabled |
| 4323 |
self.reset_options() |
| 4324 |
self.options.e4x = false |
| 4325 |
bt( |
| 4326 |
'xml=<a b="c"><d/><e>\n' + |
| 4327 |
' foo</e>x</a>;', |
| 4328 |
# -- output -- |
| 4329 |
'xml = < a b = "c" > < d / > < e >\n' + |
| 4330 |
' foo < /e>x</a > ;') |
| 4331 |
|
| 4332 |
|
| 4333 |
#============================================================ |
| 4334 |
# Multiple braces |
| 4335 |
self.reset_options() |
| 4336 |
bt( |
| 4337 |
'{{}/z/}', |
| 4338 |
# -- output -- |
| 4339 |
'{\n' + |
| 4340 |
' {}\n' + |
| 4341 |
' /z/\n' + |
| 4342 |
'}') |
| 4343 |
|
| 4344 |
|
| 4345 |
#============================================================ |
| 4346 |
# Space before conditional - (space_before_conditional = "false") |
| 4347 |
self.reset_options() |
| 4348 |
self.options.space_before_conditional = false |
| 4349 |
bt('if(a) b()') |
| 4350 |
bt('while(a) b()') |
| 4351 |
bt( |
| 4352 |
'do\n' + |
| 4353 |
' c();\n' + |
| 4354 |
'while(a) b()') |
| 4355 |
bt('switch(a) b()') |
| 4356 |
bt( |
| 4357 |
'if(a)\n' + |
| 4358 |
'b();', |
| 4359 |
# -- output -- |
| 4360 |
'if(a)\n' + |
| 4361 |
' b();') |
| 4362 |
bt( |
| 4363 |
'while(a)\n' + |
| 4364 |
'b();', |
| 4365 |
# -- output -- |
| 4366 |
'while(a)\n' + |
| 4367 |
' b();') |
| 4368 |
bt( |
| 4369 |
'do\n' + |
| 4370 |
'c();\n' + |
| 4371 |
'while(a);', |
| 4372 |
# -- output -- |
| 4373 |
'do\n' + |
| 4374 |
' c();\n' + |
| 4375 |
'while(a);') |
| 4376 |
bt( |
| 4377 |
'switch(a)\n' + |
| 4378 |
'b()', |
| 4379 |
# -- output -- |
| 4380 |
'switch(a)\n' + |
| 4381 |
' b()') |
| 4382 |
bt('return [];') |
| 4383 |
bt('return ();') |
| 4384 |
|
| 4385 |
# Space before conditional - (space_before_conditional = "true") |
| 4386 |
self.reset_options() |
| 4387 |
self.options.space_before_conditional = true |
| 4388 |
bt('if (a) b()') |
| 4389 |
bt('while (a) b()') |
| 4390 |
bt( |
| 4391 |
'do\n' + |
| 4392 |
' c();\n' + |
| 4393 |
'while (a) b()') |
| 4394 |
bt('switch (a) b()') |
| 4395 |
bt( |
| 4396 |
'if(a)\n' + |
| 4397 |
'b();', |
| 4398 |
# -- output -- |
| 4399 |
'if (a)\n' + |
| 4400 |
' b();') |
| 4401 |
bt( |
| 4402 |
'while(a)\n' + |
| 4403 |
'b();', |
| 4404 |
# -- output -- |
| 4405 |
'while (a)\n' + |
| 4406 |
' b();') |
| 4407 |
bt( |
| 4408 |
'do\n' + |
| 4409 |
'c();\n' + |
| 4410 |
'while(a);', |
| 4411 |
# -- output -- |
| 4412 |
'do\n' + |
| 4413 |
' c();\n' + |
| 4414 |
'while (a);') |
| 4415 |
bt( |
| 4416 |
'switch(a)\n' + |
| 4417 |
'b()', |
| 4418 |
# -- output -- |
| 4419 |
'switch (a)\n' + |
| 4420 |
' b()') |
| 4421 |
bt('return [];') |
| 4422 |
bt('return ();') |
| 4423 |
|
| 4424 |
|
| 4425 |
#============================================================ |
| 4426 |
# Beautify preserve formatting |
| 4427 |
self.reset_options() |
| 4428 |
bt( |
| 4429 |
'/* beautify preserve:start */\n' + |
| 4430 |
'/* beautify preserve:end */') |
| 4431 |
bt( |
| 4432 |
'/* beautify preserve:start */\n' + |
| 4433 |
' var a = 1;\n' + |
| 4434 |
'/* beautify preserve:end */') |
| 4435 |
bt( |
| 4436 |
'var a = 1;\n' + |
| 4437 |
'/* beautify preserve:start */\n' + |
| 4438 |
' var a = 1;\n' + |
| 4439 |
'/* beautify preserve:end */') |
| 4440 |
bt('/* beautify preserve:start */ {asdklgh;y;;{}dd2d}/* beautify preserve:end */') |
| 4441 |
bt( |
| 4442 |
'var a = 1;\n' + |
| 4443 |
'/* beautify preserve:start */\n' + |
| 4444 |
' var a = 1;\n' + |
| 4445 |
'/* beautify preserve:end */', |
| 4446 |
# -- output -- |
| 4447 |
'var a = 1;\n' + |
| 4448 |
'/* beautify preserve:start */\n' + |
| 4449 |
' var a = 1;\n' + |
| 4450 |
'/* beautify preserve:end */') |
| 4451 |
bt( |
| 4452 |
'var a = 1;\n' + |
| 4453 |
' /* beautify preserve:start */\n' + |
| 4454 |
' var a = 1;\n' + |
| 4455 |
'/* beautify preserve:end */', |
| 4456 |
# -- output -- |
| 4457 |
'var a = 1;\n' + |
| 4458 |
'/* beautify preserve:start */\n' + |
| 4459 |
' var a = 1;\n' + |
| 4460 |
'/* beautify preserve:end */') |
| 4461 |
bt( |
| 4462 |
'var a = {\n' + |
| 4463 |
' /* beautify preserve:start */\n' + |
| 4464 |
' one : 1\n' + |
| 4465 |
' two : 2,\n' + |
| 4466 |
' three : 3,\n' + |
| 4467 |
' ten : 10\n' + |
| 4468 |
' /* beautify preserve:end */\n' + |
| 4469 |
'};') |
| 4470 |
bt( |
| 4471 |
'var a = {\n' + |
| 4472 |
'/* beautify preserve:start */\n' + |
| 4473 |
' one : 1,\n' + |
| 4474 |
' two : 2,\n' + |
| 4475 |
' three : 3,\n' + |
| 4476 |
' ten : 10\n' + |
| 4477 |
'/* beautify preserve:end */\n' + |
| 4478 |
'};', |
| 4479 |
# -- output -- |
| 4480 |
'var a = {\n' + |
| 4481 |
' /* beautify preserve:start */\n' + |
| 4482 |
' one : 1,\n' + |
| 4483 |
' two : 2,\n' + |
| 4484 |
' three : 3,\n' + |
| 4485 |
' ten : 10\n' + |
| 4486 |
'/* beautify preserve:end */\n' + |
| 4487 |
'};') |
| 4488 |
|
| 4489 |
# one space before and after required, only single spaces inside. |
| 4490 |
bt( |
| 4491 |
'var a = {\n' + |
| 4492 |
'/* beautify preserve:start */\n' + |
| 4493 |
' one : 1,\n' + |
| 4494 |
' two : 2,\n' + |
| 4495 |
' three : 3,\n' + |
| 4496 |
' ten : 10\n' + |
| 4497 |
'};', |
| 4498 |
# -- output -- |
| 4499 |
'var a = {\n' + |
| 4500 |
' /* beautify preserve:start */\n' + |
| 4501 |
' one: 1,\n' + |
| 4502 |
' two: 2,\n' + |
| 4503 |
' three: 3,\n' + |
| 4504 |
' ten: 10\n' + |
| 4505 |
'};') |
| 4506 |
bt( |
| 4507 |
'var a = {\n' + |
| 4508 |
'/*beautify preserve:start*/\n' + |
| 4509 |
' one : 1,\n' + |
| 4510 |
' two : 2,\n' + |
| 4511 |
' three : 3,\n' + |
| 4512 |
' ten : 10\n' + |
| 4513 |
'};', |
| 4514 |
# -- output -- |
| 4515 |
'var a = {\n' + |
| 4516 |
' /*beautify preserve:start*/\n' + |
| 4517 |
' one: 1,\n' + |
| 4518 |
' two: 2,\n' + |
| 4519 |
' three: 3,\n' + |
| 4520 |
' ten: 10\n' + |
| 4521 |
'};') |
| 4522 |
bt( |
| 4523 |
'var a = {\n' + |
| 4524 |
'/*beautify preserve:start*/\n' + |
| 4525 |
' one : 1,\n' + |
| 4526 |
' two : 2,\n' + |
| 4527 |
' three : 3,\n' + |
| 4528 |
' ten : 10\n' + |
| 4529 |
'};', |
| 4530 |
# -- output -- |
| 4531 |
'var a = {\n' + |
| 4532 |
' /*beautify preserve:start*/\n' + |
| 4533 |
' one: 1,\n' + |
| 4534 |
' two: 2,\n' + |
| 4535 |
' three: 3,\n' + |
| 4536 |
' ten: 10\n' + |
| 4537 |
'};') |
| 4538 |
|
| 4539 |
# Directive: ignore |
| 4540 |
bt( |
| 4541 |
'/* beautify ignore:start */\n' + |
| 4542 |
'/* beautify ignore:end */') |
| 4543 |
bt( |
| 4544 |
'/* beautify ignore:start */\n' + |
| 4545 |
' var a,,,{ 1;\n' + |
| 4546 |
' /* beautify ignore:end */') |
| 4547 |
bt( |
| 4548 |
'var a = 1;\n' + |
| 4549 |
'/* beautify ignore:start */\n' + |
| 4550 |
' var a = 1;\n' + |
| 4551 |
'/* beautify ignore:end */') |
| 4552 |
|
| 4553 |
# ignore starts _after_ the start comment, ends after the end comment |
| 4554 |
bt('/* beautify ignore:start */ {asdklgh;y;+++;dd2d}/* beautify ignore:end */') |
| 4555 |
bt('/* beautify ignore:start */ {asdklgh;y;+++;dd2d} /* beautify ignore:end */') |
| 4556 |
bt( |
| 4557 |
'var a = 1;\n' + |
| 4558 |
'/* beautify ignore:start */\n' + |
| 4559 |
' var a,,,{ 1;\n' + |
| 4560 |
'/*beautify ignore:end*/', |
| 4561 |
# -- output -- |
| 4562 |
'var a = 1;\n' + |
| 4563 |
'/* beautify ignore:start */\n' + |
| 4564 |
' var a,,,{ 1;\n' + |
| 4565 |
'/*beautify ignore:end*/') |
| 4566 |
bt( |
| 4567 |
'var a = 1;\n' + |
| 4568 |
' /* beautify ignore:start */\n' + |
| 4569 |
' var a,,,{ 1;\n' + |
| 4570 |
'/* beautify ignore:end */', |
| 4571 |
# -- output -- |
| 4572 |
'var a = 1;\n' + |
| 4573 |
'/* beautify ignore:start */\n' + |
| 4574 |
' var a,,,{ 1;\n' + |
| 4575 |
'/* beautify ignore:end */') |
| 4576 |
bt( |
| 4577 |
'var a = {\n' + |
| 4578 |
' /* beautify ignore:start */\n' + |
| 4579 |
' one : 1\n' + |
| 4580 |
' two : 2,\n' + |
| 4581 |
' three : {\n' + |
| 4582 |
' ten : 10\n' + |
| 4583 |
' /* beautify ignore:end */\n' + |
| 4584 |
'};') |
| 4585 |
bt( |
| 4586 |
'var a = {\n' + |
| 4587 |
'/* beautify ignore:start */\n' + |
| 4588 |
' one : 1\n' + |
| 4589 |
' two : 2,\n' + |
| 4590 |
' three : {\n' + |
| 4591 |
' ten : 10\n' + |
| 4592 |
'/* beautify ignore:end */\n' + |
| 4593 |
'};', |
| 4594 |
# -- output -- |
| 4595 |
'var a = {\n' + |
| 4596 |
' /* beautify ignore:start */\n' + |
| 4597 |
' one : 1\n' + |
| 4598 |
' two : 2,\n' + |
| 4599 |
' three : {\n' + |
| 4600 |
' ten : 10\n' + |
| 4601 |
'/* beautify ignore:end */\n' + |
| 4602 |
'};') |
| 4603 |
|
| 4604 |
# Directives - multiple and interacting |
| 4605 |
bt( |
| 4606 |
'var a = {\n' + |
| 4607 |
'/* beautify preserve:start */\n' + |
| 4608 |
'/* beautify preserve:start */\n' + |
| 4609 |
' one : 1,\n' + |
| 4610 |
' /* beautify preserve:end */\n' + |
| 4611 |
' two : 2,\n' + |
| 4612 |
' three : 3,\n' + |
| 4613 |
'/* beautify preserve:start */\n' + |
| 4614 |
' ten : 10\n' + |
| 4615 |
'/* beautify preserve:end */\n' + |
| 4616 |
'};', |
| 4617 |
# -- output -- |
| 4618 |
'var a = {\n' + |
| 4619 |
' /* beautify preserve:start */\n' + |
| 4620 |
'/* beautify preserve:start */\n' + |
| 4621 |
' one : 1,\n' + |
| 4622 |
' /* beautify preserve:end */\n' + |
| 4623 |
' two: 2,\n' + |
| 4624 |
' three: 3,\n' + |
| 4625 |
' /* beautify preserve:start */\n' + |
| 4626 |
' ten : 10\n' + |
| 4627 |
'/* beautify preserve:end */\n' + |
| 4628 |
'};') |
| 4629 |
bt( |
| 4630 |
'var a = {\n' + |
| 4631 |
'/* beautify ignore:start */\n' + |
| 4632 |
' one : 1\n' + |
| 4633 |
' /* beautify ignore:end */\n' + |
| 4634 |
' two : 2,\n' + |
| 4635 |
'/* beautify ignore:start */\n' + |
| 4636 |
' three : {\n' + |
| 4637 |
' ten : 10\n' + |
| 4638 |
'/* beautify ignore:end */\n' + |
| 4639 |
'};', |
| 4640 |
# -- output -- |
| 4641 |
'var a = {\n' + |
| 4642 |
' /* beautify ignore:start */\n' + |
| 4643 |
' one : 1\n' + |
| 4644 |
' /* beautify ignore:end */\n' + |
| 4645 |
' two: 2,\n' + |
| 4646 |
' /* beautify ignore:start */\n' + |
| 4647 |
' three : {\n' + |
| 4648 |
' ten : 10\n' + |
| 4649 |
'/* beautify ignore:end */\n' + |
| 4650 |
'};') |
| 4651 |
|
| 4652 |
# Starts can occur together, ignore:end must occur alone. |
| 4653 |
bt( |
| 4654 |
'var a = {\n' + |
| 4655 |
'/* beautify ignore:start */\n' + |
| 4656 |
' one : 1\n' + |
| 4657 |
' NOTE: ignore end block does not support starting other directives\n' + |
| 4658 |
' This does not match the ending the ignore...\n' + |
| 4659 |
' /* beautify ignore:end preserve:start */\n' + |
| 4660 |
' two : 2,\n' + |
| 4661 |
'/* beautify ignore:start */\n' + |
| 4662 |
' three : {\n' + |
| 4663 |
' ten : 10\n' + |
| 4664 |
' ==The next comment ends the starting ignore==\n' + |
| 4665 |
'/* beautify ignore:end */\n' + |
| 4666 |
'};', |
| 4667 |
# -- output -- |
| 4668 |
'var a = {\n' + |
| 4669 |
' /* beautify ignore:start */\n' + |
| 4670 |
' one : 1\n' + |
| 4671 |
' NOTE: ignore end block does not support starting other directives\n' + |
| 4672 |
' This does not match the ending the ignore...\n' + |
| 4673 |
' /* beautify ignore:end preserve:start */\n' + |
| 4674 |
' two : 2,\n' + |
| 4675 |
'/* beautify ignore:start */\n' + |
| 4676 |
' three : {\n' + |
| 4677 |
' ten : 10\n' + |
| 4678 |
' ==The next comment ends the starting ignore==\n' + |
| 4679 |
'/* beautify ignore:end */\n' + |
| 4680 |
'};') |
| 4681 |
bt( |
| 4682 |
'var a = {\n' + |
| 4683 |
'/* beautify ignore:start preserve:start */\n' + |
| 4684 |
' one : {\n' + |
| 4685 |
' /* beautify ignore:end */\n' + |
| 4686 |
' two : 2,\n' + |
| 4687 |
' /* beautify ignore:start */\n' + |
| 4688 |
' three : {\n' + |
| 4689 |
'/* beautify ignore:end */\n' + |
| 4690 |
' ten : 10\n' + |
| 4691 |
' // This is all preserved\n' + |
| 4692 |
'};', |
| 4693 |
# -- output -- |
| 4694 |
'var a = {\n' + |
| 4695 |
' /* beautify ignore:start preserve:start */\n' + |
| 4696 |
' one : {\n' + |
| 4697 |
' /* beautify ignore:end */\n' + |
| 4698 |
' two : 2,\n' + |
| 4699 |
' /* beautify ignore:start */\n' + |
| 4700 |
' three : {\n' + |
| 4701 |
'/* beautify ignore:end */\n' + |
| 4702 |
' ten : 10\n' + |
| 4703 |
' // This is all preserved\n' + |
| 4704 |
'};') |
| 4705 |
bt( |
| 4706 |
'var a = {\n' + |
| 4707 |
'/* beautify ignore:start preserve:start */\n' + |
| 4708 |
' one : {\n' + |
| 4709 |
' /* beautify ignore:end */\n' + |
| 4710 |
' two : 2,\n' + |
| 4711 |
' /* beautify ignore:start */\n' + |
| 4712 |
' three : {\n' + |
| 4713 |
'/* beautify ignore:end */\n' + |
| 4714 |
' ten : 10,\n' + |
| 4715 |
'/* beautify preserve:end */\n' + |
| 4716 |
' eleven: 11\n' + |
| 4717 |
'};', |
| 4718 |
# -- output -- |
| 4719 |
'var a = {\n' + |
| 4720 |
' /* beautify ignore:start preserve:start */\n' + |
| 4721 |
' one : {\n' + |
| 4722 |
' /* beautify ignore:end */\n' + |
| 4723 |
' two : 2,\n' + |
| 4724 |
' /* beautify ignore:start */\n' + |
| 4725 |
' three : {\n' + |
| 4726 |
'/* beautify ignore:end */\n' + |
| 4727 |
' ten : 10,\n' + |
| 4728 |
'/* beautify preserve:end */\n' + |
| 4729 |
' eleven: 11\n' + |
| 4730 |
'};') |
| 4731 |
|
| 4732 |
|
| 4733 |
#============================================================ |
| 4734 |
# Comments and tests |
| 4735 |
self.reset_options() |
| 4736 |
|
| 4737 |
# #913 |
| 4738 |
bt( |
| 4739 |
'class test {\n' + |
| 4740 |
' method1() {\n' + |
| 4741 |
' let resp = null;\n' + |
| 4742 |
' }\n' + |
| 4743 |
' /**\n' + |
| 4744 |
' * @param {String} id\n' + |
| 4745 |
' */\n' + |
| 4746 |
' method2(id) {\n' + |
| 4747 |
' let resp2 = null;\n' + |
| 4748 |
' }\n' + |
| 4749 |
'}') |
| 4750 |
|
| 4751 |
# #1090 |
| 4752 |
bt( |
| 4753 |
'for (var i = 0; i < 20; ++i) // loop\n' + |
| 4754 |
' if (i % 3) {\n' + |
| 4755 |
' console.log(i);\n' + |
| 4756 |
' }\n' + |
| 4757 |
'console.log("done");') |
| 4758 |
|
| 4759 |
# #1043 |
| 4760 |
bt( |
| 4761 |
'var o = {\n' + |
| 4762 |
' k: 0\n' + |
| 4763 |
'}\n' + |
| 4764 |
'// ...\n' + |
| 4765 |
'foo(o)') |
| 4766 |
|
| 4767 |
# #713 and #964 |
| 4768 |
bt( |
| 4769 |
'Meteor.call("foo", bar, function(err, result) {\n' + |
| 4770 |
' Session.set("baz", result.lorem)\n' + |
| 4771 |
'})\n' + |
| 4772 |
'//blah blah') |
| 4773 |
|
| 4774 |
# #815 |
| 4775 |
bt( |
| 4776 |
'foo()\n' + |
| 4777 |
'// this is a comment\n' + |
| 4778 |
'bar()\n' + |
| 4779 |
'\n' + |
| 4780 |
'const foo = 5\n' + |
| 4781 |
'// comment\n' + |
| 4782 |
'bar()') |
| 4783 |
|
| 4784 |
# This shows current behavior. Note #1069 is not addressed yet. |
| 4785 |
bt( |
| 4786 |
'if (modulus === 2) {\n' + |
| 4787 |
' // i might be odd here\n' + |
| 4788 |
' i += (i & 1);\n' + |
| 4789 |
' // now i is guaranteed to be even\n' + |
| 4790 |
' // this block is obviously about the statement above\n' + |
| 4791 |
'\n' + |
| 4792 |
' // #1069 This should attach to the block below\n' + |
| 4793 |
' // this comment is about the block after it.\n' + |
| 4794 |
'} else {\n' + |
| 4795 |
' // rounding up using integer arithmetic only\n' + |
| 4796 |
' if (i % modulus)\n' + |
| 4797 |
' i += modulus - (i % modulus);\n' + |
| 4798 |
' // now i is divisible by modulus\n' + |
| 4799 |
' // behavior of comments should be different for single statements vs block statements/expressions\n' + |
| 4800 |
'}\n' + |
| 4801 |
'\n' + |
| 4802 |
'if (modulus === 2)\n' + |
| 4803 |
' // i might be odd here\n' + |
| 4804 |
' i += (i & 1);\n' + |
| 4805 |
'// now i is guaranteed to be even\n' + |
| 4806 |
'// non-braced comments unindent immediately\n' + |
| 4807 |
'\n' + |
| 4808 |
'// this comment is about the block after it.\n' + |
| 4809 |
'else\n' + |
| 4810 |
' // rounding up using integer arithmetic only\n' + |
| 4811 |
' if (i % modulus)\n' + |
| 4812 |
' i += modulus - (i % modulus);\n' + |
| 4813 |
'// behavior of comments should be different for single statements vs block statements/expressions') |
| 4814 |
|
| 4815 |
|
| 4816 |
#============================================================ |
| 4817 |
# minimal template handling - () |
| 4818 |
self.reset_options() |
| 4819 |
self.options.templating = ['django', 'erb', 'handlebars', 'php'] |
| 4820 |
bt('var a = <?php$view["name"]; ?>;', 'var a = <?php$view["name"]; ?>;') |
| 4821 |
bt( |
| 4822 |
'a = abc<?php\n' + |
| 4823 |
'for($i = 1; $i <= 100; $i++;) {\n' + |
| 4824 |
' #count to 100!\n' + |
| 4825 |
' echo($i . "</br>");\n' + |
| 4826 |
'}\n' + |
| 4827 |
'?>;') |
| 4828 |
test_fragment( |
| 4829 |
'<?php ?>\n' + |
| 4830 |
'test.met<?php someValue ?>hod();') |
| 4831 |
bt( |
| 4832 |
'<?php "A" ?>abc<?php "D" ?>;\n' + |
| 4833 |
'<?php "B" ?>.test();\n' + |
| 4834 |
'" <?php "C" \'D\' ?> "') |
| 4835 |
bt( |
| 4836 |
'<?php\n' + |
| 4837 |
'echo "A";\n' + |
| 4838 |
'?>;\n' + |
| 4839 |
'test.method();') |
| 4840 |
bt('"<?php";if(0){}"?>";') |
| 4841 |
|
| 4842 |
# minimal template handling - () |
| 4843 |
self.reset_options() |
| 4844 |
self.options.templating = ['django', 'erb', 'handlebars', 'php'] |
| 4845 |
bt('var a = <?=$view["name"]; ?>;', 'var a = <?=$view["name"]; ?>;') |
| 4846 |
bt( |
| 4847 |
'a = abc<?=\n' + |
| 4848 |
'for($i = 1; $i <= 100; $i++;) {\n' + |
| 4849 |
' #count to 100!\n' + |
| 4850 |
' echo($i . "</br>");\n' + |
| 4851 |
'}\n' + |
| 4852 |
'?>;') |
| 4853 |
test_fragment( |
| 4854 |
'<?= ?>\n' + |
| 4855 |
'test.met<?= someValue ?>hod();') |
| 4856 |
bt( |
| 4857 |
'<?= "A" ?>abc<?= "D" ?>;\n' + |
| 4858 |
'<?= "B" ?>.test();\n' + |
| 4859 |
'" <?= "C" \'D\' ?> "') |
| 4860 |
bt( |
| 4861 |
'<?=\n' + |
| 4862 |
'echo "A";\n' + |
| 4863 |
'?>;\n' + |
| 4864 |
'test.method();') |
| 4865 |
bt('"<?=";if(0){}"?>";') |
| 4866 |
|
| 4867 |
# minimal template handling - () |
| 4868 |
self.reset_options() |
| 4869 |
self.options.templating = ['django', 'erb', 'handlebars', 'php'] |
| 4870 |
bt('var a = <%$view["name"]; %>;', 'var a = <%$view["name"]; %>;') |
| 4871 |
bt( |
| 4872 |
'a = abc<%\n' + |
| 4873 |
'for($i = 1; $i <= 100; $i++;) {\n' + |
| 4874 |
' #count to 100!\n' + |
| 4875 |
' echo($i . "</br>");\n' + |
| 4876 |
'}\n' + |
| 4877 |
'%>;') |
| 4878 |
test_fragment( |
| 4879 |
'<% %>\n' + |
| 4880 |
'test.met<% someValue %>hod();') |
| 4881 |
bt( |
| 4882 |
'<% "A" %>abc<% "D" %>;\n' + |
| 4883 |
'<% "B" %>.test();\n' + |
| 4884 |
'" <% "C" \'D\' %> "') |
| 4885 |
bt( |
| 4886 |
'<%\n' + |
| 4887 |
'echo "A";\n' + |
| 4888 |
'%>;\n' + |
| 4889 |
'test.method();') |
| 4890 |
bt('"<%";if(0){}"%>";') |
| 4891 |
|
| 4892 |
# minimal template handling - () |
| 4893 |
self.reset_options() |
| 4894 |
self.options.templating = ['django', 'erb', 'handlebars', 'php'] |
| 4895 |
bt('var a = <%=$view["name"]; %>;', 'var a = <%=$view["name"]; %>;') |
| 4896 |
bt( |
| 4897 |
'a = abc<%=\n' + |
| 4898 |
'for($i = 1; $i <= 100; $i++;) {\n' + |
| 4899 |
' #count to 100!\n' + |
| 4900 |
' echo($i . "</br>");\n' + |
| 4901 |
'}\n' + |
| 4902 |
'%>;') |
| 4903 |
test_fragment( |
| 4904 |
'<%= %>\n' + |
| 4905 |
'test.met<%= someValue %>hod();') |
| 4906 |
bt( |
| 4907 |
'<%= "A" %>abc<%= "D" %>;\n' + |
| 4908 |
'<%= "B" %>.test();\n' + |
| 4909 |
'" <%= "C" \'D\' %> "') |
| 4910 |
bt( |
| 4911 |
'<%=\n' + |
| 4912 |
'echo "A";\n' + |
| 4913 |
'%>;\n' + |
| 4914 |
'test.method();') |
| 4915 |
bt('"<%=";if(0){}"%>";') |
| 4916 |
|
| 4917 |
# minimal template handling - () |
| 4918 |
self.reset_options() |
| 4919 |
self.options.templating = ['django', 'erb', 'handlebars', 'php'] |
| 4920 |
bt('var a = {{$view["name"]; }};', 'var a = {{$view["name"]; }};') |
| 4921 |
bt( |
| 4922 |
'a = abc{{\n' + |
| 4923 |
'for($i = 1; $i <= 100; $i++;) {\n' + |
| 4924 |
' #count to 100!\n' + |
| 4925 |
' echo($i . "</br>");\n' + |
| 4926 |
'}\n' + |
| 4927 |
'}};') |
| 4928 |
test_fragment( |
| 4929 |
'{{ }}\n' + |
| 4930 |
'test.met{{ someValue }}hod();') |
| 4931 |
bt( |
| 4932 |
'{{ "A" }}abc{{ "D" }};\n' + |
| 4933 |
'{{ "B" }}.test();\n' + |
| 4934 |
'" {{ "C" \'D\' }} "') |
| 4935 |
bt( |
| 4936 |
'{{\n' + |
| 4937 |
'echo "A";\n' + |
| 4938 |
'}};\n' + |
| 4939 |
'test.method();') |
| 4940 |
bt('"{{";if(0){}"}}";') |
| 4941 |
|
| 4942 |
# minimal template handling - () |
| 4943 |
self.reset_options() |
| 4944 |
self.options.templating = ['django', 'erb', 'handlebars', 'php'] |
| 4945 |
bt('var a = {#$view["name"]; #};', 'var a = {#$view["name"]; #};') |
| 4946 |
bt( |
| 4947 |
'a = abc{#\n' + |
| 4948 |
'for($i = 1; $i <= 100; $i++;) {\n' + |
| 4949 |
' #count to 100!\n' + |
| 4950 |
' echo($i . "</br>");\n' + |
| 4951 |
'}\n' + |
| 4952 |
'#};') |
| 4953 |
test_fragment( |
| 4954 |
'{# #}\n' + |
| 4955 |
'test.met{# someValue #}hod();') |
| 4956 |
bt( |
| 4957 |
'{# "A" #}abc{# "D" #};\n' + |
| 4958 |
'{# "B" #}.test();\n' + |
| 4959 |
'" {# "C" \'D\' #} "') |
| 4960 |
bt( |
| 4961 |
'{#\n' + |
| 4962 |
'echo "A";\n' + |
| 4963 |
'#};\n' + |
| 4964 |
'test.method();') |
| 4965 |
bt('"{#";if(0){}"#}";') |
| 4966 |
|
| 4967 |
# minimal template handling - () |
| 4968 |
self.reset_options() |
| 4969 |
self.options.templating = ['django', 'erb', 'handlebars', 'php'] |
| 4970 |
bt('var a = {%$view["name"]; %};', 'var a = {%$view["name"]; %};') |
| 4971 |
bt( |
| 4972 |
'a = abc{%\n' + |
| 4973 |
'for($i = 1; $i <= 100; $i++;) {\n' + |
| 4974 |
' #count to 100!\n' + |
| 4975 |
' echo($i . "</br>");\n' + |
| 4976 |
'}\n' + |
| 4977 |
'%};') |
| 4978 |
test_fragment( |
| 4979 |
'{% %}\n' + |
| 4980 |
'test.met{% someValue %}hod();') |
| 4981 |
bt( |
| 4982 |
'{% "A" %}abc{% "D" %};\n' + |
| 4983 |
'{% "B" %}.test();\n' + |
| 4984 |
'" {% "C" \'D\' %} "') |
| 4985 |
bt( |
| 4986 |
'{%\n' + |
| 4987 |
'echo "A";\n' + |
| 4988 |
'%};\n' + |
| 4989 |
'test.method();') |
| 4990 |
bt('"{%";if(0){}"%}";') |
| 4991 |
|
| 4992 |
# minimal template handling - () |
| 4993 |
self.reset_options() |
| 4994 |
self.options.templating = ['django', 'erb', 'handlebars', 'php'] |
| 4995 |
bt('var a = {{$view["name"]; }};', 'var a = {{$view["name"]; }};') |
| 4996 |
bt( |
| 4997 |
'a = abc{{\n' + |
| 4998 |
'for($i = 1; $i <= 100; $i++;) {\n' + |
| 4999 |
' #count to 100!\n' + |
| 5000 |
' echo($i . "</br>");\n' + |
| 5001 |
'}\n' + |
| 5002 |
'}};') |
| 5003 |
test_fragment( |
| 5004 |
'{{ }}\n' + |
| 5005 |
'test.met{{ someValue }}hod();') |
| 5006 |
bt( |
| 5007 |
'{{ "A" }}abc{{ "D" }};\n' + |
| 5008 |
'{{ "B" }}.test();\n' + |
| 5009 |
'" {{ "C" \'D\' }} "') |
| 5010 |
bt( |
| 5011 |
'{{\n' + |
| 5012 |
'echo "A";\n' + |
| 5013 |
'}};\n' + |
| 5014 |
'test.method();') |
| 5015 |
bt('"{{";if(0){}"}}";') |
| 5016 |
|
| 5017 |
# minimal template handling - () |
| 5018 |
self.reset_options() |
| 5019 |
self.options.templating = ['django', 'erb', 'handlebars', 'php'] |
| 5020 |
bt('var a = {{{$view["name"]; }}};', 'var a = {{{$view["name"]; }}};') |
| 5021 |
bt( |
| 5022 |
'a = abc{{{\n' + |
| 5023 |
'for($i = 1; $i <= 100; $i++;) {\n' + |
| 5024 |
' #count to 100!\n' + |
| 5025 |
' echo($i . "</br>");\n' + |
| 5026 |
'}\n' + |
| 5027 |
'}}};') |
| 5028 |
test_fragment( |
| 5029 |
'{{{ }}}\n' + |
| 5030 |
'test.met{{{ someValue }}}hod();') |
| 5031 |
bt( |
| 5032 |
'{{{ "A" }}}abc{{{ "D" }}};\n' + |
| 5033 |
'{{{ "B" }}}.test();\n' + |
| 5034 |
'" {{{ "C" \'D\' }}} "') |
| 5035 |
bt( |
| 5036 |
'{{{\n' + |
| 5037 |
'echo "A";\n' + |
| 5038 |
'}}};\n' + |
| 5039 |
'test.method();') |
| 5040 |
bt('"{{{";if(0){}"}}}";') |
| 5041 |
|
| 5042 |
# minimal template handling - () |
| 5043 |
self.reset_options() |
| 5044 |
self.options.templating = ['django', 'erb', 'handlebars', 'php'] |
| 5045 |
bt('var a = {{^$view["name"]; }};', 'var a = {{^$view["name"]; }};') |
| 5046 |
bt( |
| 5047 |
'a = abc{{^\n' + |
| 5048 |
'for($i = 1; $i <= 100; $i++;) {\n' + |
| 5049 |
' #count to 100!\n' + |
| 5050 |
' echo($i . "</br>");\n' + |
| 5051 |
'}\n' + |
| 5052 |
'}};') |
| 5053 |
test_fragment( |
| 5054 |
'{{^ }}\n' + |
| 5055 |
'test.met{{^ someValue }}hod();') |
| 5056 |
bt( |
| 5057 |
'{{^ "A" }}abc{{^ "D" }};\n' + |
| 5058 |
'{{^ "B" }}.test();\n' + |
| 5059 |
'" {{^ "C" \'D\' }} "') |
| 5060 |
bt( |
| 5061 |
'{{^\n' + |
| 5062 |
'echo "A";\n' + |
| 5063 |
'}};\n' + |
| 5064 |
'test.method();') |
| 5065 |
bt('"{{^";if(0){}"}}";') |
| 5066 |
|
| 5067 |
# minimal template handling - () |
| 5068 |
self.reset_options() |
| 5069 |
self.options.templating = ['django', 'erb', 'handlebars', 'php'] |
| 5070 |
bt('var a = {{#$view["name"]; }};', 'var a = {{#$view["name"]; }};') |
| 5071 |
bt( |
| 5072 |
'a = abc{{#\n' + |
| 5073 |
'for($i = 1; $i <= 100; $i++;) {\n' + |
| 5074 |
' #count to 100!\n' + |
| 5075 |
' echo($i . "</br>");\n' + |
| 5076 |
'}\n' + |
| 5077 |
'}};') |
| 5078 |
test_fragment( |
| 5079 |
'{{# }}\n' + |
| 5080 |
'test.met{{# someValue }}hod();') |
| 5081 |
bt( |
| 5082 |
'{{# "A" }}abc{{# "D" }};\n' + |
| 5083 |
'{{# "B" }}.test();\n' + |
| 5084 |
'" {{# "C" \'D\' }} "') |
| 5085 |
bt( |
| 5086 |
'{{#\n' + |
| 5087 |
'echo "A";\n' + |
| 5088 |
'}};\n' + |
| 5089 |
'test.method();') |
| 5090 |
bt('"{{#";if(0){}"}}";') |
| 5091 |
|
| 5092 |
# minimal template handling - () |
| 5093 |
self.reset_options() |
| 5094 |
self.options.templating = ['django', 'erb', 'handlebars', 'php'] |
| 5095 |
bt('var a = {{!$view["name"]; }};', 'var a = {{!$view["name"]; }};') |
| 5096 |
bt( |
| 5097 |
'a = abc{{!\n' + |
| 5098 |
'for($i = 1; $i <= 100; $i++;) {\n' + |
| 5099 |
' #count to 100!\n' + |
| 5100 |
' echo($i . "</br>");\n' + |
| 5101 |
'}\n' + |
| 5102 |
'}};') |
| 5103 |
test_fragment( |
| 5104 |
'{{! }}\n' + |
| 5105 |
'test.met{{! someValue }}hod();') |
| 5106 |
bt( |
| 5107 |
'{{! "A" }}abc{{! "D" }};\n' + |
| 5108 |
'{{! "B" }}.test();\n' + |
| 5109 |
'" {{! "C" \'D\' }} "') |
| 5110 |
bt( |
| 5111 |
'{{!\n' + |
| 5112 |
'echo "A";\n' + |
| 5113 |
'}};\n' + |
| 5114 |
'test.method();') |
| 5115 |
bt('"{{!";if(0){}"}}";') |
| 5116 |
|
| 5117 |
# minimal template handling - () |
| 5118 |
self.reset_options() |
| 5119 |
self.options.templating = ['django', 'erb', 'handlebars', 'php'] |
| 5120 |
bt('var a = {{!--$view["name"]; --}};', 'var a = {{!--$view["name"]; --}};') |
| 5121 |
bt( |
| 5122 |
'a = abc{{!--\n' + |
| 5123 |
'for($i = 1; $i <= 100; $i++;) {\n' + |
| 5124 |
' #count to 100!\n' + |
| 5125 |
' echo($i . "</br>");\n' + |
| 5126 |
'}\n' + |
| 5127 |
'--}};') |
| 5128 |
test_fragment( |
| 5129 |
'{{!-- --}}\n' + |
| 5130 |
'test.met{{!-- someValue --}}hod();') |
| 5131 |
bt( |
| 5132 |
'{{!-- "A" --}}abc{{!-- "D" --}};\n' + |
| 5133 |
'{{!-- "B" --}}.test();\n' + |
| 5134 |
'" {{!-- "C" \'D\' --}} "') |
| 5135 |
bt( |
| 5136 |
'{{!--\n' + |
| 5137 |
'echo "A";\n' + |
| 5138 |
'--}};\n' + |
| 5139 |
'test.method();') |
| 5140 |
bt('"{{!--";if(0){}"--}}";') |
| 5141 |
|
| 5142 |
|
| 5143 |
#============================================================ |
| 5144 |
# Templating disabled - ensure formatting - () |
| 5145 |
self.reset_options() |
| 5146 |
self.options.templating = ['auto'] |
| 5147 |
bt( |
| 5148 |
'"<?php";if(0){}"?>";', |
| 5149 |
# -- output -- |
| 5150 |
'"<?php";\n' + |
| 5151 |
'if (0) {}\n' + |
| 5152 |
'"?>";') |
| 5153 |
bt( |
| 5154 |
'"<?php";if(0){}', |
| 5155 |
# -- output -- |
| 5156 |
'"<?php";\n' + |
| 5157 |
'if (0) {}') |
| 5158 |
|
| 5159 |
# Templating disabled - ensure formatting - () |
| 5160 |
self.reset_options() |
| 5161 |
self.options.templating = ['auto'] |
| 5162 |
bt( |
| 5163 |
'"<?=";if(0){}"?>";', |
| 5164 |
# -- output -- |
| 5165 |
'"<?=";\n' + |
| 5166 |
'if (0) {}\n' + |
| 5167 |
'"?>";') |
| 5168 |
bt( |
| 5169 |
'"<?=";if(0){}', |
| 5170 |
# -- output -- |
| 5171 |
'"<?=";\n' + |
| 5172 |
'if (0) {}') |
| 5173 |
|
| 5174 |
# Templating disabled - ensure formatting - () |
| 5175 |
self.reset_options() |
| 5176 |
self.options.templating = ['auto'] |
| 5177 |
bt( |
| 5178 |
'"<%";if(0){}"%>";', |
| 5179 |
# -- output -- |
| 5180 |
'"<%";\n' + |
| 5181 |
'if (0) {}\n' + |
| 5182 |
'"%>";') |
| 5183 |
bt( |
| 5184 |
'"<%";if(0){}', |
| 5185 |
# -- output -- |
| 5186 |
'"<%";\n' + |
| 5187 |
'if (0) {}') |
| 5188 |
|
| 5189 |
# Templating disabled - ensure formatting - () |
| 5190 |
self.reset_options() |
| 5191 |
self.options.templating = ['auto'] |
| 5192 |
bt( |
| 5193 |
'"<%=";if(0){}"%>";', |
| 5194 |
# -- output -- |
| 5195 |
'"<%=";\n' + |
| 5196 |
'if (0) {}\n' + |
| 5197 |
'"%>";') |
| 5198 |
bt( |
| 5199 |
'"<%=";if(0){}', |
| 5200 |
# -- output -- |
| 5201 |
'"<%=";\n' + |
| 5202 |
'if (0) {}') |
| 5203 |
|
| 5204 |
# Templating disabled - ensure formatting - () |
| 5205 |
self.reset_options() |
| 5206 |
self.options.templating = ['auto'] |
| 5207 |
bt( |
| 5208 |
'"{{";if(0){}"}}";', |
| 5209 |
# -- output -- |
| 5210 |
'"{{";\n' + |
| 5211 |
'if (0) {}\n' + |
| 5212 |
'"}}";') |
| 5213 |
bt( |
| 5214 |
'"{{";if(0){}', |
| 5215 |
# -- output -- |
| 5216 |
'"{{";\n' + |
| 5217 |
'if (0) {}') |
| 5218 |
|
| 5219 |
# Templating disabled - ensure formatting - () |
| 5220 |
self.reset_options() |
| 5221 |
self.options.templating = ['auto'] |
| 5222 |
bt( |
| 5223 |
'"{#";if(0){}"#}";', |
| 5224 |
# -- output -- |
| 5225 |
'"{#";\n' + |
| 5226 |
'if (0) {}\n' + |
| 5227 |
'"#}";') |
| 5228 |
bt( |
| 5229 |
'"{#";if(0){}', |
| 5230 |
# -- output -- |
| 5231 |
'"{#";\n' + |
| 5232 |
'if (0) {}') |
| 5233 |
|
| 5234 |
# Templating disabled - ensure formatting - () |
| 5235 |
self.reset_options() |
| 5236 |
self.options.templating = ['auto'] |
| 5237 |
bt( |
| 5238 |
'"{%";if(0){}"%}";', |
| 5239 |
# -- output -- |
| 5240 |
'"{%";\n' + |
| 5241 |
'if (0) {}\n' + |
| 5242 |
'"%}";') |
| 5243 |
bt( |
| 5244 |
'"{%";if(0){}', |
| 5245 |
# -- output -- |
| 5246 |
'"{%";\n' + |
| 5247 |
'if (0) {}') |
| 5248 |
|
| 5249 |
# Templating disabled - ensure formatting - () |
| 5250 |
self.reset_options() |
| 5251 |
self.options.templating = ['auto'] |
| 5252 |
bt( |
| 5253 |
'"{{";if(0){}"}}";', |
| 5254 |
# -- output -- |
| 5255 |
'"{{";\n' + |
| 5256 |
'if (0) {}\n' + |
| 5257 |
'"}}";') |
| 5258 |
bt( |
| 5259 |
'"{{";if(0){}', |
| 5260 |
# -- output -- |
| 5261 |
'"{{";\n' + |
| 5262 |
'if (0) {}') |
| 5263 |
|
| 5264 |
# Templating disabled - ensure formatting - () |
| 5265 |
self.reset_options() |
| 5266 |
self.options.templating = ['auto'] |
| 5267 |
bt( |
| 5268 |
'"{{{";if(0){}"}}}";', |
| 5269 |
# -- output -- |
| 5270 |
'"{{{";\n' + |
| 5271 |
'if (0) {}\n' + |
| 5272 |
'"}}}";') |
| 5273 |
bt( |
| 5274 |
'"{{{";if(0){}', |
| 5275 |
# -- output -- |
| 5276 |
'"{{{";\n' + |
| 5277 |
'if (0) {}') |
| 5278 |
|
| 5279 |
# Templating disabled - ensure formatting - () |
| 5280 |
self.reset_options() |
| 5281 |
self.options.templating = ['auto'] |
| 5282 |
bt( |
| 5283 |
'"{{^";if(0){}"}}";', |
| 5284 |
# -- output -- |
| 5285 |
'"{{^";\n' + |
| 5286 |
'if (0) {}\n' + |
| 5287 |
'"}}";') |
| 5288 |
bt( |
| 5289 |
'"{{^";if(0){}', |
| 5290 |
# -- output -- |
| 5291 |
'"{{^";\n' + |
| 5292 |
'if (0) {}') |
| 5293 |
|
| 5294 |
# Templating disabled - ensure formatting - () |
| 5295 |
self.reset_options() |
| 5296 |
self.options.templating = ['auto'] |
| 5297 |
bt( |
| 5298 |
'"{{#";if(0){}"}}";', |
| 5299 |
# -- output -- |
| 5300 |
'"{{#";\n' + |
| 5301 |
'if (0) {}\n' + |
| 5302 |
'"}}";') |
| 5303 |
bt( |
| 5304 |
'"{{#";if(0){}', |
| 5305 |
# -- output -- |
| 5306 |
'"{{#";\n' + |
| 5307 |
'if (0) {}') |
| 5308 |
|
| 5309 |
# Templating disabled - ensure formatting - () |
| 5310 |
self.reset_options() |
| 5311 |
self.options.templating = ['auto'] |
| 5312 |
bt( |
| 5313 |
'"{{!";if(0){}"}}";', |
| 5314 |
# -- output -- |
| 5315 |
'"{{!";\n' + |
| 5316 |
'if (0) {}\n' + |
| 5317 |
'"}}";') |
| 5318 |
bt( |
| 5319 |
'"{{!";if(0){}', |
| 5320 |
# -- output -- |
| 5321 |
'"{{!";\n' + |
| 5322 |
'if (0) {}') |
| 5323 |
|
| 5324 |
# Templating disabled - ensure formatting - () |
| 5325 |
self.reset_options() |
| 5326 |
self.options.templating = ['auto'] |
| 5327 |
bt( |
| 5328 |
'"{{!--";if(0){}"--}}";', |
| 5329 |
# -- output -- |
| 5330 |
'"{{!--";\n' + |
| 5331 |
'if (0) {}\n' + |
| 5332 |
'"--}}";') |
| 5333 |
bt( |
| 5334 |
'"{{!--";if(0){}', |
| 5335 |
# -- output -- |
| 5336 |
'"{{!--";\n' + |
| 5337 |
'if (0) {}') |
| 5338 |
|
| 5339 |
|
| 5340 |
#============================================================ |
| 5341 |
# jslint and space after anon function - (jslint_happy = "true", space_after_anon_function = "true") |
| 5342 |
self.reset_options() |
| 5343 |
self.options.jslint_happy = true |
| 5344 |
self.options.space_after_anon_function = true |
| 5345 |
bt( |
| 5346 |
'a=typeof(x)', |
| 5347 |
# -- output -- |
| 5348 |
'a = typeof (x)') |
| 5349 |
bt( |
| 5350 |
'x();\n' + |
| 5351 |
'\n' + |
| 5352 |
'function(){}', |
| 5353 |
# -- output -- |
| 5354 |
'x();\n' + |
| 5355 |
'\n' + |
| 5356 |
'function () {}') |
| 5357 |
bt( |
| 5358 |
'x();\n' + |
| 5359 |
'\n' + |
| 5360 |
'function y(){}', |
| 5361 |
# -- output -- |
| 5362 |
'x();\n' + |
| 5363 |
'\n' + |
| 5364 |
'function y() {}') |
| 5365 |
bt( |
| 5366 |
'x();\n' + |
| 5367 |
'\n' + |
| 5368 |
'var x = {\n' + |
| 5369 |
'x: function(){}\n' + |
| 5370 |
'}', |
| 5371 |
# -- output -- |
| 5372 |
'x();\n' + |
| 5373 |
'\n' + |
| 5374 |
'var x = {\n' + |
| 5375 |
' x: function () {}\n' + |
| 5376 |
'}') |
| 5377 |
bt( |
| 5378 |
'x();\n' + |
| 5379 |
'\n' + |
| 5380 |
'var x = {\n' + |
| 5381 |
'x: function y(){}\n' + |
| 5382 |
'}', |
| 5383 |
# -- output -- |
| 5384 |
'x();\n' + |
| 5385 |
'\n' + |
| 5386 |
'var x = {\n' + |
| 5387 |
' x: function y() {}\n' + |
| 5388 |
'}') |
| 5389 |
bt( |
| 5390 |
'function () {\n' + |
| 5391 |
' var a, b, c, d, e = [],\n' + |
| 5392 |
' f;\n' + |
| 5393 |
'}') |
| 5394 |
bt( |
| 5395 |
'switch(x) {case 0: case 1: a(); break; default: break}', |
| 5396 |
# -- output -- |
| 5397 |
'switch (x) {\n' + |
| 5398 |
'case 0:\n' + |
| 5399 |
'case 1:\n' + |
| 5400 |
' a();\n' + |
| 5401 |
' break;\n' + |
| 5402 |
'default:\n' + |
| 5403 |
' break\n' + |
| 5404 |
'}') |
| 5405 |
bt( |
| 5406 |
'switch(x){case -1:break;case !y:break;}', |
| 5407 |
# -- output -- |
| 5408 |
'switch (x) {\n' + |
| 5409 |
'case -1:\n' + |
| 5410 |
' break;\n' + |
| 5411 |
'case !y:\n' + |
| 5412 |
' break;\n' + |
| 5413 |
'}') |
| 5414 |
|
| 5415 |
# Issue #1357 |
| 5416 |
bt( |
| 5417 |
'switch(x) {case 0: case 1:{a(); break;} default: break}', |
| 5418 |
# -- output -- |
| 5419 |
'switch (x) {\n' + |
| 5420 |
'case 0:\n' + |
| 5421 |
'case 1: {\n' + |
| 5422 |
' a();\n' + |
| 5423 |
' break;\n' + |
| 5424 |
'}\n' + |
| 5425 |
'default:\n' + |
| 5426 |
' break\n' + |
| 5427 |
'}') |
| 5428 |
|
| 5429 |
# Issue #1357 |
| 5430 |
bt( |
| 5431 |
'switch(x){case -1:break;case !y:{break;}}', |
| 5432 |
# -- output -- |
| 5433 |
'switch (x) {\n' + |
| 5434 |
'case -1:\n' + |
| 5435 |
' break;\n' + |
| 5436 |
'case !y: {\n' + |
| 5437 |
' break;\n' + |
| 5438 |
'}\n' + |
| 5439 |
'}') |
| 5440 |
|
| 5441 |
# Issue #1622 - basic class with function definitions |
| 5442 |
bt( |
| 5443 |
'class blah {\n' + |
| 5444 |
' constructor() {\n' + |
| 5445 |
' this.doStuff()\n' + |
| 5446 |
' }\n' + |
| 5447 |
' doStuff() {\n' + |
| 5448 |
' console.log("stuff")\n' + |
| 5449 |
' }\n' + |
| 5450 |
'}') |
| 5451 |
|
| 5452 |
# Issue #1622 - class with extends and function definitions |
| 5453 |
bt( |
| 5454 |
'class blah extends something {\n' + |
| 5455 |
' constructor() {\n' + |
| 5456 |
' this.zz = 2 + 2;\n' + |
| 5457 |
' }\n' + |
| 5458 |
' someOtherFunction() {\n' + |
| 5459 |
'this.y = 1;\n' + |
| 5460 |
' }\n' + |
| 5461 |
'}', |
| 5462 |
# -- output -- |
| 5463 |
'class blah extends something {\n' + |
| 5464 |
' constructor() {\n' + |
| 5465 |
' this.zz = 2 + 2;\n' + |
| 5466 |
' }\n' + |
| 5467 |
' someOtherFunction() {\n' + |
| 5468 |
' this.y = 1;\n' + |
| 5469 |
' }\n' + |
| 5470 |
'}') |
| 5471 |
|
| 5472 |
# Issue #1622 - class/extends as a property |
| 5473 |
bt( |
| 5474 |
'var a.class = {\n' + |
| 5475 |
' ...abc(),\n' + |
| 5476 |
'}\n' + |
| 5477 |
'b.extends({\n' + |
| 5478 |
' bb.s(),\n' + |
| 5479 |
'})', |
| 5480 |
# -- output -- |
| 5481 |
'var a.class = {\n' + |
| 5482 |
' ...abc(),\n' + |
| 5483 |
'}\n' + |
| 5484 |
'b.extends({\n' + |
| 5485 |
' bb.s(),\n' + |
| 5486 |
'})') |
| 5487 |
|
| 5488 |
# typical greasemonkey start |
| 5489 |
test_fragment( |
| 5490 |
'// comment 2\n' + |
| 5491 |
'(function ()') |
| 5492 |
bt( |
| 5493 |
'var a2, b2, c2, d2 = 0, c = function() {}, d = \'\';', |
| 5494 |
# -- output -- |
| 5495 |
'var a2, b2, c2, d2 = 0,\n' + |
| 5496 |
' c = function () {},\n' + |
| 5497 |
' d = \'\';') |
| 5498 |
bt( |
| 5499 |
'var a2, b2, c2, d2 = 0, c = function yoohoo() {}, d = \'\';', |
| 5500 |
# -- output -- |
| 5501 |
'var a2, b2, c2, d2 = 0,\n' + |
| 5502 |
' c = function yoohoo() {},\n' + |
| 5503 |
' d = \'\';') |
| 5504 |
bt( |
| 5505 |
'var a2, b2, c2, d2 = 0, c = function() {},\n' + |
| 5506 |
'd = \'\';', |
| 5507 |
# -- output -- |
| 5508 |
'var a2, b2, c2, d2 = 0,\n' + |
| 5509 |
' c = function () {},\n' + |
| 5510 |
' d = \'\';') |
| 5511 |
bt( |
| 5512 |
'var o2=$.extend(a);function(){alert(x);}', |
| 5513 |
# -- output -- |
| 5514 |
'var o2 = $.extend(a);\n' + |
| 5515 |
'\n' + |
| 5516 |
'function () {\n' + |
| 5517 |
' alert(x);\n' + |
| 5518 |
'}') |
| 5519 |
bt( |
| 5520 |
'var o2=$.extend(a);function yoohoo(){alert(x);}', |
| 5521 |
# -- output -- |
| 5522 |
'var o2 = $.extend(a);\n' + |
| 5523 |
'\n' + |
| 5524 |
'function yoohoo() {\n' + |
| 5525 |
' alert(x);\n' + |
| 5526 |
'}') |
| 5527 |
bt( |
| 5528 |
'function*() {\n' + |
| 5529 |
' yield 1;\n' + |
| 5530 |
'}', |
| 5531 |
# -- output -- |
| 5532 |
'function* () {\n' + |
| 5533 |
' yield 1;\n' + |
| 5534 |
'}') |
| 5535 |
bt( |
| 5536 |
'function* yoohoo() {\n' + |
| 5537 |
' yield 1;\n' + |
| 5538 |
'}') |
| 5539 |
bt( |
| 5540 |
'function* x() {\n' + |
| 5541 |
' yield 1;\n' + |
| 5542 |
'}') |
| 5543 |
bt( |
| 5544 |
'async x() {\n' + |
| 5545 |
' yield 1;\n' + |
| 5546 |
'}') |
| 5547 |
bt( |
| 5548 |
'var a={data(){},\n' + |
| 5549 |
'data2(){}}', |
| 5550 |
# -- output -- |
| 5551 |
'var a = {\n' + |
| 5552 |
' data() {},\n' + |
| 5553 |
' data2() {}\n' + |
| 5554 |
'}') |
| 5555 |
bt( |
| 5556 |
'new Vue({\n' + |
| 5557 |
'data(){},\n' + |
| 5558 |
'data2(){}, a:1})', |
| 5559 |
# -- output -- |
| 5560 |
'new Vue({\n' + |
| 5561 |
' data() {},\n' + |
| 5562 |
' data2() {},\n' + |
| 5563 |
' a: 1\n' + |
| 5564 |
'})') |
| 5565 |
bt( |
| 5566 |
'export default {data(){},\n' + |
| 5567 |
'data2(){},\n' + |
| 5568 |
'a:1}', |
| 5569 |
# -- output -- |
| 5570 |
'export default {\n' + |
| 5571 |
' data() {},\n' + |
| 5572 |
' data2() {},\n' + |
| 5573 |
' a: 1\n' + |
| 5574 |
'}') |
| 5575 |
bt( |
| 5576 |
'var a={*data(){},*data2(){}}', |
| 5577 |
# -- output -- |
| 5578 |
'var a = {\n' + |
| 5579 |
' * data() {},\n' + |
| 5580 |
' * data2() {}\n' + |
| 5581 |
'}') |
| 5582 |
bt( |
| 5583 |
'new Vue({\n' + |
| 5584 |
'*data(){},*data2(){}, a:1})', |
| 5585 |
# -- output -- |
| 5586 |
'new Vue({\n' + |
| 5587 |
' * data() {},\n' + |
| 5588 |
' * data2() {},\n' + |
| 5589 |
' a: 1\n' + |
| 5590 |
'})') |
| 5591 |
bt( |
| 5592 |
'export default {*data(){},*data2(){},\n' + |
| 5593 |
'a:1}', |
| 5594 |
# -- output -- |
| 5595 |
'export default {\n' + |
| 5596 |
' * data() {},\n' + |
| 5597 |
' * data2() {},\n' + |
| 5598 |
' a: 1\n' + |
| 5599 |
'}') |
| 5600 |
|
| 5601 |
# jslint and space after anon function - (jslint_happy = "true", space_after_anon_function = "false") |
| 5602 |
self.reset_options() |
| 5603 |
self.options.jslint_happy = true |
| 5604 |
self.options.space_after_anon_function = false |
| 5605 |
bt( |
| 5606 |
'a=typeof(x)', |
| 5607 |
# -- output -- |
| 5608 |
'a = typeof (x)') |
| 5609 |
bt( |
| 5610 |
'x();\n' + |
| 5611 |
'\n' + |
| 5612 |
'function(){}', |
| 5613 |
# -- output -- |
| 5614 |
'x();\n' + |
| 5615 |
'\n' + |
| 5616 |
'function () {}') |
| 5617 |
bt( |
| 5618 |
'x();\n' + |
| 5619 |
'\n' + |
| 5620 |
'function y(){}', |
| 5621 |
# -- output -- |
| 5622 |
'x();\n' + |
| 5623 |
'\n' + |
| 5624 |
'function y() {}') |
| 5625 |
bt( |
| 5626 |
'x();\n' + |
| 5627 |
'\n' + |
| 5628 |
'var x = {\n' + |
| 5629 |
'x: function(){}\n' + |
| 5630 |
'}', |
| 5631 |
# -- output -- |
| 5632 |
'x();\n' + |
| 5633 |
'\n' + |
| 5634 |
'var x = {\n' + |
| 5635 |
' x: function () {}\n' + |
| 5636 |
'}') |
| 5637 |
bt( |
| 5638 |
'x();\n' + |
| 5639 |
'\n' + |
| 5640 |
'var x = {\n' + |
| 5641 |
'x: function y(){}\n' + |
| 5642 |
'}', |
| 5643 |
# -- output -- |
| 5644 |
'x();\n' + |
| 5645 |
'\n' + |
| 5646 |
'var x = {\n' + |
| 5647 |
' x: function y() {}\n' + |
| 5648 |
'}') |
| 5649 |
bt( |
| 5650 |
'function () {\n' + |
| 5651 |
' var a, b, c, d, e = [],\n' + |
| 5652 |
' f;\n' + |
| 5653 |
'}') |
| 5654 |
bt( |
| 5655 |
'switch(x) {case 0: case 1: a(); break; default: break}', |
| 5656 |
# -- output -- |
| 5657 |
'switch (x) {\n' + |
| 5658 |
'case 0:\n' + |
| 5659 |
'case 1:\n' + |
| 5660 |
' a();\n' + |
| 5661 |
' break;\n' + |
| 5662 |
'default:\n' + |
| 5663 |
' break\n' + |
| 5664 |
'}') |
| 5665 |
bt( |
| 5666 |
'switch(x){case -1:break;case !y:break;}', |
| 5667 |
# -- output -- |
| 5668 |
'switch (x) {\n' + |
| 5669 |
'case -1:\n' + |
| 5670 |
' break;\n' + |
| 5671 |
'case !y:\n' + |
| 5672 |
' break;\n' + |
| 5673 |
'}') |
| 5674 |
|
| 5675 |
# Issue #1357 |
| 5676 |
bt( |
| 5677 |
'switch(x) {case 0: case 1:{a(); break;} default: break}', |
| 5678 |
# -- output -- |
| 5679 |
'switch (x) {\n' + |
| 5680 |
'case 0:\n' + |
| 5681 |
'case 1: {\n' + |
| 5682 |
' a();\n' + |
| 5683 |
' break;\n' + |
| 5684 |
'}\n' + |
| 5685 |
'default:\n' + |
| 5686 |
' break\n' + |
| 5687 |
'}') |
| 5688 |
|
| 5689 |
# Issue #1357 |
| 5690 |
bt( |
| 5691 |
'switch(x){case -1:break;case !y:{break;}}', |
| 5692 |
# -- output -- |
| 5693 |
'switch (x) {\n' + |
| 5694 |
'case -1:\n' + |
| 5695 |
' break;\n' + |
| 5696 |
'case !y: {\n' + |
| 5697 |
' break;\n' + |
| 5698 |
'}\n' + |
| 5699 |
'}') |
| 5700 |
|
| 5701 |
# Issue #1622 - basic class with function definitions |
| 5702 |
bt( |
| 5703 |
'class blah {\n' + |
| 5704 |
' constructor() {\n' + |
| 5705 |
' this.doStuff()\n' + |
| 5706 |
' }\n' + |
| 5707 |
' doStuff() {\n' + |
| 5708 |
' console.log("stuff")\n' + |
| 5709 |
' }\n' + |
| 5710 |
'}') |
| 5711 |
|
| 5712 |
# Issue #1622 - class with extends and function definitions |
| 5713 |
bt( |
| 5714 |
'class blah extends something {\n' + |
| 5715 |
' constructor() {\n' + |
| 5716 |
' this.zz = 2 + 2;\n' + |
| 5717 |
' }\n' + |
| 5718 |
' someOtherFunction() {\n' + |
| 5719 |
'this.y = 1;\n' + |
| 5720 |
' }\n' + |
| 5721 |
'}', |
| 5722 |
# -- output -- |
| 5723 |
'class blah extends something {\n' + |
| 5724 |
' constructor() {\n' + |
| 5725 |
' this.zz = 2 + 2;\n' + |
| 5726 |
' }\n' + |
| 5727 |
' someOtherFunction() {\n' + |
| 5728 |
' this.y = 1;\n' + |
| 5729 |
' }\n' + |
| 5730 |
'}') |
| 5731 |
|
| 5732 |
# Issue #1622 - class/extends as a property |
| 5733 |
bt( |
| 5734 |
'var a.class = {\n' + |
| 5735 |
' ...abc(),\n' + |
| 5736 |
'}\n' + |
| 5737 |
'b.extends({\n' + |
| 5738 |
' bb.s(),\n' + |
| 5739 |
'})', |
| 5740 |
# -- output -- |
| 5741 |
'var a.class = {\n' + |
| 5742 |
' ...abc(),\n' + |
| 5743 |
'}\n' + |
| 5744 |
'b.extends({\n' + |
| 5745 |
' bb.s(),\n' + |
| 5746 |
'})') |
| 5747 |
|
| 5748 |
# typical greasemonkey start |
| 5749 |
test_fragment( |
| 5750 |
'// comment 2\n' + |
| 5751 |
'(function ()') |
| 5752 |
bt( |
| 5753 |
'var a2, b2, c2, d2 = 0, c = function() {}, d = \'\';', |
| 5754 |
# -- output -- |
| 5755 |
'var a2, b2, c2, d2 = 0,\n' + |
| 5756 |
' c = function () {},\n' + |
| 5757 |
' d = \'\';') |
| 5758 |
bt( |
| 5759 |
'var a2, b2, c2, d2 = 0, c = function yoohoo() {}, d = \'\';', |
| 5760 |
# -- output -- |
| 5761 |
'var a2, b2, c2, d2 = 0,\n' + |
| 5762 |
' c = function yoohoo() {},\n' + |
| 5763 |
' d = \'\';') |
| 5764 |
bt( |
| 5765 |
'var a2, b2, c2, d2 = 0, c = function() {},\n' + |
| 5766 |
'd = \'\';', |
| 5767 |
# -- output -- |
| 5768 |
'var a2, b2, c2, d2 = 0,\n' + |
| 5769 |
' c = function () {},\n' + |
| 5770 |
' d = \'\';') |
| 5771 |
bt( |
| 5772 |
'var o2=$.extend(a);function(){alert(x);}', |
| 5773 |
# -- output -- |
| 5774 |
'var o2 = $.extend(a);\n' + |
| 5775 |
'\n' + |
| 5776 |
'function () {\n' + |
| 5777 |
' alert(x);\n' + |
| 5778 |
'}') |
| 5779 |
bt( |
| 5780 |
'var o2=$.extend(a);function yoohoo(){alert(x);}', |
| 5781 |
# -- output -- |
| 5782 |
'var o2 = $.extend(a);\n' + |
| 5783 |
'\n' + |
| 5784 |
'function yoohoo() {\n' + |
| 5785 |
' alert(x);\n' + |
| 5786 |
'}') |
| 5787 |
bt( |
| 5788 |
'function*() {\n' + |
| 5789 |
' yield 1;\n' + |
| 5790 |
'}', |
| 5791 |
# -- output -- |
| 5792 |
'function* () {\n' + |
| 5793 |
' yield 1;\n' + |
| 5794 |
'}') |
| 5795 |
bt( |
| 5796 |
'function* yoohoo() {\n' + |
| 5797 |
' yield 1;\n' + |
| 5798 |
'}') |
| 5799 |
bt( |
| 5800 |
'function* x() {\n' + |
| 5801 |
' yield 1;\n' + |
| 5802 |
'}') |
| 5803 |
bt( |
| 5804 |
'async x() {\n' + |
| 5805 |
' yield 1;\n' + |
| 5806 |
'}') |
| 5807 |
bt( |
| 5808 |
'var a={data(){},\n' + |
| 5809 |
'data2(){}}', |
| 5810 |
# -- output -- |
| 5811 |
'var a = {\n' + |
| 5812 |
' data() {},\n' + |
| 5813 |
' data2() {}\n' + |
| 5814 |
'}') |
| 5815 |
bt( |
| 5816 |
'new Vue({\n' + |
| 5817 |
'data(){},\n' + |
| 5818 |
'data2(){}, a:1})', |
| 5819 |
# -- output -- |
| 5820 |
'new Vue({\n' + |
| 5821 |
' data() {},\n' + |
| 5822 |
' data2() {},\n' + |
| 5823 |
' a: 1\n' + |
| 5824 |
'})') |
| 5825 |
bt( |
| 5826 |
'export default {data(){},\n' + |
| 5827 |
'data2(){},\n' + |
| 5828 |
'a:1}', |
| 5829 |
# -- output -- |
| 5830 |
'export default {\n' + |
| 5831 |
' data() {},\n' + |
| 5832 |
' data2() {},\n' + |
| 5833 |
' a: 1\n' + |
| 5834 |
'}') |
| 5835 |
bt( |
| 5836 |
'var a={*data(){},*data2(){}}', |
| 5837 |
# -- output -- |
| 5838 |
'var a = {\n' + |
| 5839 |
' * data() {},\n' + |
| 5840 |
' * data2() {}\n' + |
| 5841 |
'}') |
| 5842 |
bt( |
| 5843 |
'new Vue({\n' + |
| 5844 |
'*data(){},*data2(){}, a:1})', |
| 5845 |
# -- output -- |
| 5846 |
'new Vue({\n' + |
| 5847 |
' * data() {},\n' + |
| 5848 |
' * data2() {},\n' + |
| 5849 |
' a: 1\n' + |
| 5850 |
'})') |
| 5851 |
bt( |
| 5852 |
'export default {*data(){},*data2(){},\n' + |
| 5853 |
'a:1}', |
| 5854 |
# -- output -- |
| 5855 |
'export default {\n' + |
| 5856 |
' * data() {},\n' + |
| 5857 |
' * data2() {},\n' + |
| 5858 |
' a: 1\n' + |
| 5859 |
'}') |
| 5860 |
|
| 5861 |
# jslint and space after anon function - (jslint_happy = "false", space_after_anon_function = "true") |
| 5862 |
self.reset_options() |
| 5863 |
self.options.jslint_happy = false |
| 5864 |
self.options.space_after_anon_function = true |
| 5865 |
bt( |
| 5866 |
'a=typeof(x)', |
| 5867 |
# -- output -- |
| 5868 |
'a = typeof (x)') |
| 5869 |
bt( |
| 5870 |
'x();\n' + |
| 5871 |
'\n' + |
| 5872 |
'function(){}', |
| 5873 |
# -- output -- |
| 5874 |
'x();\n' + |
| 5875 |
'\n' + |
| 5876 |
'function () {}') |
| 5877 |
bt( |
| 5878 |
'x();\n' + |
| 5879 |
'\n' + |
| 5880 |
'function y(){}', |
| 5881 |
# -- output -- |
| 5882 |
'x();\n' + |
| 5883 |
'\n' + |
| 5884 |
'function y() {}') |
| 5885 |
bt( |
| 5886 |
'x();\n' + |
| 5887 |
'\n' + |
| 5888 |
'var x = {\n' + |
| 5889 |
'x: function(){}\n' + |
| 5890 |
'}', |
| 5891 |
# -- output -- |
| 5892 |
'x();\n' + |
| 5893 |
'\n' + |
| 5894 |
'var x = {\n' + |
| 5895 |
' x: function () {}\n' + |
| 5896 |
'}') |
| 5897 |
bt( |
| 5898 |
'x();\n' + |
| 5899 |
'\n' + |
| 5900 |
'var x = {\n' + |
| 5901 |
'x: function y(){}\n' + |
| 5902 |
'}', |
| 5903 |
# -- output -- |
| 5904 |
'x();\n' + |
| 5905 |
'\n' + |
| 5906 |
'var x = {\n' + |
| 5907 |
' x: function y() {}\n' + |
| 5908 |
'}') |
| 5909 |
bt( |
| 5910 |
'function () {\n' + |
| 5911 |
' var a, b, c, d, e = [],\n' + |
| 5912 |
' f;\n' + |
| 5913 |
'}') |
| 5914 |
bt( |
| 5915 |
'switch(x) {case 0: case 1: a(); break; default: break}', |
| 5916 |
# -- output -- |
| 5917 |
'switch (x) {\n' + |
| 5918 |
' case 0:\n' + |
| 5919 |
' case 1:\n' + |
| 5920 |
' a();\n' + |
| 5921 |
' break;\n' + |
| 5922 |
' default:\n' + |
| 5923 |
' break\n' + |
| 5924 |
'}') |
| 5925 |
bt( |
| 5926 |
'switch(x){case -1:break;case !y:break;}', |
| 5927 |
# -- output -- |
| 5928 |
'switch (x) {\n' + |
| 5929 |
' case -1:\n' + |
| 5930 |
' break;\n' + |
| 5931 |
' case !y:\n' + |
| 5932 |
' break;\n' + |
| 5933 |
'}') |
| 5934 |
|
| 5935 |
# Issue #1357 |
| 5936 |
bt( |
| 5937 |
'switch(x) {case 0: case 1:{a(); break;} default: break}', |
| 5938 |
# -- output -- |
| 5939 |
'switch (x) {\n' + |
| 5940 |
' case 0:\n' + |
| 5941 |
' case 1: {\n' + |
| 5942 |
' a();\n' + |
| 5943 |
' break;\n' + |
| 5944 |
' }\n' + |
| 5945 |
' default:\n' + |
| 5946 |
' break\n' + |
| 5947 |
'}') |
| 5948 |
|
| 5949 |
# Issue #1357 |
| 5950 |
bt( |
| 5951 |
'switch(x){case -1:break;case !y:{break;}}', |
| 5952 |
# -- output -- |
| 5953 |
'switch (x) {\n' + |
| 5954 |
' case -1:\n' + |
| 5955 |
' break;\n' + |
| 5956 |
' case !y: {\n' + |
| 5957 |
' break;\n' + |
| 5958 |
' }\n' + |
| 5959 |
'}') |
| 5960 |
|
| 5961 |
# Issue #1622 - basic class with function definitions |
| 5962 |
bt( |
| 5963 |
'class blah {\n' + |
| 5964 |
' constructor() {\n' + |
| 5965 |
' this.doStuff()\n' + |
| 5966 |
' }\n' + |
| 5967 |
' doStuff() {\n' + |
| 5968 |
' console.log("stuff")\n' + |
| 5969 |
' }\n' + |
| 5970 |
'}') |
| 5971 |
|
| 5972 |
# Issue #1622 - class with extends and function definitions |
| 5973 |
bt( |
| 5974 |
'class blah extends something {\n' + |
| 5975 |
' constructor() {\n' + |
| 5976 |
' this.zz = 2 + 2;\n' + |
| 5977 |
' }\n' + |
| 5978 |
' someOtherFunction() {\n' + |
| 5979 |
'this.y = 1;\n' + |
| 5980 |
' }\n' + |
| 5981 |
'}', |
| 5982 |
# -- output -- |
| 5983 |
'class blah extends something {\n' + |
| 5984 |
' constructor() {\n' + |
| 5985 |
' this.zz = 2 + 2;\n' + |
| 5986 |
' }\n' + |
| 5987 |
' someOtherFunction() {\n' + |
| 5988 |
' this.y = 1;\n' + |
| 5989 |
' }\n' + |
| 5990 |
'}') |
| 5991 |
|
| 5992 |
# Issue #1622 - class/extends as a property |
| 5993 |
bt( |
| 5994 |
'var a.class = {\n' + |
| 5995 |
' ...abc(),\n' + |
| 5996 |
'}\n' + |
| 5997 |
'b.extends({\n' + |
| 5998 |
' bb.s(),\n' + |
| 5999 |
'})', |
| 6000 |
# -- output -- |
| 6001 |
'var a.class = {\n' + |
| 6002 |
' ...abc(),\n' + |
| 6003 |
'}\n' + |
| 6004 |
'b.extends({\n' + |
| 6005 |
' bb.s(),\n' + |
| 6006 |
'})') |
| 6007 |
|
| 6008 |
# typical greasemonkey start |
| 6009 |
test_fragment( |
| 6010 |
'// comment 2\n' + |
| 6011 |
'(function ()') |
| 6012 |
bt( |
| 6013 |
'var a2, b2, c2, d2 = 0, c = function() {}, d = \'\';', |
| 6014 |
# -- output -- |
| 6015 |
'var a2, b2, c2, d2 = 0,\n' + |
| 6016 |
' c = function () {},\n' + |
| 6017 |
' d = \'\';') |
| 6018 |
bt( |
| 6019 |
'var a2, b2, c2, d2 = 0, c = function yoohoo() {}, d = \'\';', |
| 6020 |
# -- output -- |
| 6021 |
'var a2, b2, c2, d2 = 0,\n' + |
| 6022 |
' c = function yoohoo() {},\n' + |
| 6023 |
' d = \'\';') |
| 6024 |
bt( |
| 6025 |
'var a2, b2, c2, d2 = 0, c = function() {},\n' + |
| 6026 |
'd = \'\';', |
| 6027 |
# -- output -- |
| 6028 |
'var a2, b2, c2, d2 = 0,\n' + |
| 6029 |
' c = function () {},\n' + |
| 6030 |
' d = \'\';') |
| 6031 |
bt( |
| 6032 |
'var o2=$.extend(a);function(){alert(x);}', |
| 6033 |
# -- output -- |
| 6034 |
'var o2 = $.extend(a);\n' + |
| 6035 |
'\n' + |
| 6036 |
'function () {\n' + |
| 6037 |
' alert(x);\n' + |
| 6038 |
'}') |
| 6039 |
bt( |
| 6040 |
'var o2=$.extend(a);function yoohoo(){alert(x);}', |
| 6041 |
# -- output -- |
| 6042 |
'var o2 = $.extend(a);\n' + |
| 6043 |
'\n' + |
| 6044 |
'function yoohoo() {\n' + |
| 6045 |
' alert(x);\n' + |
| 6046 |
'}') |
| 6047 |
bt( |
| 6048 |
'function*() {\n' + |
| 6049 |
' yield 1;\n' + |
| 6050 |
'}', |
| 6051 |
# -- output -- |
| 6052 |
'function* () {\n' + |
| 6053 |
' yield 1;\n' + |
| 6054 |
'}') |
| 6055 |
bt( |
| 6056 |
'function* yoohoo() {\n' + |
| 6057 |
' yield 1;\n' + |
| 6058 |
'}') |
| 6059 |
bt( |
| 6060 |
'function* x() {\n' + |
| 6061 |
' yield 1;\n' + |
| 6062 |
'}') |
| 6063 |
bt( |
| 6064 |
'async x() {\n' + |
| 6065 |
' yield 1;\n' + |
| 6066 |
'}') |
| 6067 |
bt( |
| 6068 |
'var a={data(){},\n' + |
| 6069 |
'data2(){}}', |
| 6070 |
# -- output -- |
| 6071 |
'var a = {\n' + |
| 6072 |
' data() {},\n' + |
| 6073 |
' data2() {}\n' + |
| 6074 |
'}') |
| 6075 |
bt( |
| 6076 |
'new Vue({\n' + |
| 6077 |
'data(){},\n' + |
| 6078 |
'data2(){}, a:1})', |
| 6079 |
# -- output -- |
| 6080 |
'new Vue({\n' + |
| 6081 |
' data() {},\n' + |
| 6082 |
' data2() {},\n' + |
| 6083 |
' a: 1\n' + |
| 6084 |
'})') |
| 6085 |
bt( |
| 6086 |
'export default {data(){},\n' + |
| 6087 |
'data2(){},\n' + |
| 6088 |
'a:1}', |
| 6089 |
# -- output -- |
| 6090 |
'export default {\n' + |
| 6091 |
' data() {},\n' + |
| 6092 |
' data2() {},\n' + |
| 6093 |
' a: 1\n' + |
| 6094 |
'}') |
| 6095 |
bt( |
| 6096 |
'var a={*data(){},*data2(){}}', |
| 6097 |
# -- output -- |
| 6098 |
'var a = {\n' + |
| 6099 |
' * data() {},\n' + |
| 6100 |
' * data2() {}\n' + |
| 6101 |
'}') |
| 6102 |
bt( |
| 6103 |
'new Vue({\n' + |
| 6104 |
'*data(){},*data2(){}, a:1})', |
| 6105 |
# -- output -- |
| 6106 |
'new Vue({\n' + |
| 6107 |
' * data() {},\n' + |
| 6108 |
' * data2() {},\n' + |
| 6109 |
' a: 1\n' + |
| 6110 |
'})') |
| 6111 |
bt( |
| 6112 |
'export default {*data(){},*data2(){},\n' + |
| 6113 |
'a:1}', |
| 6114 |
# -- output -- |
| 6115 |
'export default {\n' + |
| 6116 |
' * data() {},\n' + |
| 6117 |
' * data2() {},\n' + |
| 6118 |
' a: 1\n' + |
| 6119 |
'}') |
| 6120 |
|
| 6121 |
# jslint and space after anon function - (jslint_happy = "false", space_after_anon_function = "false") |
| 6122 |
self.reset_options() |
| 6123 |
self.options.jslint_happy = false |
| 6124 |
self.options.space_after_anon_function = false |
| 6125 |
bt( |
| 6126 |
'a=typeof(x)', |
| 6127 |
# -- output -- |
| 6128 |
'a = typeof(x)') |
| 6129 |
bt( |
| 6130 |
'x();\n' + |
| 6131 |
'\n' + |
| 6132 |
'function(){}', |
| 6133 |
# -- output -- |
| 6134 |
'x();\n' + |
| 6135 |
'\n' + |
| 6136 |
'function() {}') |
| 6137 |
bt( |
| 6138 |
'x();\n' + |
| 6139 |
'\n' + |
| 6140 |
'function y(){}', |
| 6141 |
# -- output -- |
| 6142 |
'x();\n' + |
| 6143 |
'\n' + |
| 6144 |
'function y() {}') |
| 6145 |
bt( |
| 6146 |
'x();\n' + |
| 6147 |
'\n' + |
| 6148 |
'var x = {\n' + |
| 6149 |
'x: function(){}\n' + |
| 6150 |
'}', |
| 6151 |
# -- output -- |
| 6152 |
'x();\n' + |
| 6153 |
'\n' + |
| 6154 |
'var x = {\n' + |
| 6155 |
' x: function() {}\n' + |
| 6156 |
'}') |
| 6157 |
bt( |
| 6158 |
'x();\n' + |
| 6159 |
'\n' + |
| 6160 |
'var x = {\n' + |
| 6161 |
'x: function y(){}\n' + |
| 6162 |
'}', |
| 6163 |
# -- output -- |
| 6164 |
'x();\n' + |
| 6165 |
'\n' + |
| 6166 |
'var x = {\n' + |
| 6167 |
' x: function y() {}\n' + |
| 6168 |
'}') |
| 6169 |
bt( |
| 6170 |
'function () {\n' + |
| 6171 |
' var a, b, c, d, e = [],\n' + |
| 6172 |
' f;\n' + |
| 6173 |
'}', |
| 6174 |
# -- output -- |
| 6175 |
'function() {\n' + |
| 6176 |
' var a, b, c, d, e = [],\n' + |
| 6177 |
' f;\n' + |
| 6178 |
'}') |
| 6179 |
bt( |
| 6180 |
'switch(x) {case 0: case 1: a(); break; default: break}', |
| 6181 |
# -- output -- |
| 6182 |
'switch (x) {\n' + |
| 6183 |
' case 0:\n' + |
| 6184 |
' case 1:\n' + |
| 6185 |
' a();\n' + |
| 6186 |
' break;\n' + |
| 6187 |
' default:\n' + |
| 6188 |
' break\n' + |
| 6189 |
'}') |
| 6190 |
bt( |
| 6191 |
'switch(x){case -1:break;case !y:break;}', |
| 6192 |
# -- output -- |
| 6193 |
'switch (x) {\n' + |
| 6194 |
' case -1:\n' + |
| 6195 |
' break;\n' + |
| 6196 |
' case !y:\n' + |
| 6197 |
' break;\n' + |
| 6198 |
'}') |
| 6199 |
|
| 6200 |
# Issue #1357 |
| 6201 |
bt( |
| 6202 |
'switch(x) {case 0: case 1:{a(); break;} default: break}', |
| 6203 |
# -- output -- |
| 6204 |
'switch (x) {\n' + |
| 6205 |
' case 0:\n' + |
| 6206 |
' case 1: {\n' + |
| 6207 |
' a();\n' + |
| 6208 |
' break;\n' + |
| 6209 |
' }\n' + |
| 6210 |
' default:\n' + |
| 6211 |
' break\n' + |
| 6212 |
'}') |
| 6213 |
|
| 6214 |
# Issue #1357 |
| 6215 |
bt( |
| 6216 |
'switch(x){case -1:break;case !y:{break;}}', |
| 6217 |
# -- output -- |
| 6218 |
'switch (x) {\n' + |
| 6219 |
' case -1:\n' + |
| 6220 |
' break;\n' + |
| 6221 |
' case !y: {\n' + |
| 6222 |
' break;\n' + |
| 6223 |
' }\n' + |
| 6224 |
'}') |
| 6225 |
|
| 6226 |
# Issue #1622 - basic class with function definitions |
| 6227 |
bt( |
| 6228 |
'class blah {\n' + |
| 6229 |
' constructor() {\n' + |
| 6230 |
' this.doStuff()\n' + |
| 6231 |
' }\n' + |
| 6232 |
' doStuff() {\n' + |
| 6233 |
' console.log("stuff")\n' + |
| 6234 |
' }\n' + |
| 6235 |
'}') |
| 6236 |
|
| 6237 |
# Issue #1622 - class with extends and function definitions |
| 6238 |
bt( |
| 6239 |
'class blah extends something {\n' + |
| 6240 |
' constructor() {\n' + |
| 6241 |
' this.zz = 2 + 2;\n' + |
| 6242 |
' }\n' + |
| 6243 |
' someOtherFunction() {\n' + |
| 6244 |
'this.y = 1;\n' + |
| 6245 |
' }\n' + |
| 6246 |
'}', |
| 6247 |
# -- output -- |
| 6248 |
'class blah extends something {\n' + |
| 6249 |
' constructor() {\n' + |
| 6250 |
' this.zz = 2 + 2;\n' + |
| 6251 |
' }\n' + |
| 6252 |
' someOtherFunction() {\n' + |
| 6253 |
' this.y = 1;\n' + |
| 6254 |
' }\n' + |
| 6255 |
'}') |
| 6256 |
|
| 6257 |
# Issue #1622 - class/extends as a property |
| 6258 |
bt( |
| 6259 |
'var a.class = {\n' + |
| 6260 |
' ...abc(),\n' + |
| 6261 |
'}\n' + |
| 6262 |
'b.extends({\n' + |
| 6263 |
' bb.s(),\n' + |
| 6264 |
'})', |
| 6265 |
# -- output -- |
| 6266 |
'var a.class = {\n' + |
| 6267 |
' ...abc(),\n' + |
| 6268 |
'}\n' + |
| 6269 |
'b.extends({\n' + |
| 6270 |
' bb.s(),\n' + |
| 6271 |
'})') |
| 6272 |
|
| 6273 |
# typical greasemonkey start |
| 6274 |
test_fragment( |
| 6275 |
'// comment 2\n' + |
| 6276 |
'(function()') |
| 6277 |
bt( |
| 6278 |
'var a2, b2, c2, d2 = 0, c = function() {}, d = \'\';', |
| 6279 |
# -- output -- |
| 6280 |
'var a2, b2, c2, d2 = 0,\n' + |
| 6281 |
' c = function() {},\n' + |
| 6282 |
' d = \'\';') |
| 6283 |
bt( |
| 6284 |
'var a2, b2, c2, d2 = 0, c = function yoohoo() {}, d = \'\';', |
| 6285 |
# -- output -- |
| 6286 |
'var a2, b2, c2, d2 = 0,\n' + |
| 6287 |
' c = function yoohoo() {},\n' + |
| 6288 |
' d = \'\';') |
| 6289 |
bt( |
| 6290 |
'var a2, b2, c2, d2 = 0, c = function() {},\n' + |
| 6291 |
'd = \'\';', |
| 6292 |
# -- output -- |
| 6293 |
'var a2, b2, c2, d2 = 0,\n' + |
| 6294 |
' c = function() {},\n' + |
| 6295 |
' d = \'\';') |
| 6296 |
bt( |
| 6297 |
'var o2=$.extend(a);function(){alert(x);}', |
| 6298 |
# -- output -- |
| 6299 |
'var o2 = $.extend(a);\n' + |
| 6300 |
'\n' + |
| 6301 |
'function() {\n' + |
| 6302 |
' alert(x);\n' + |
| 6303 |
'}') |
| 6304 |
bt( |
| 6305 |
'var o2=$.extend(a);function yoohoo(){alert(x);}', |
| 6306 |
# -- output -- |
| 6307 |
'var o2 = $.extend(a);\n' + |
| 6308 |
'\n' + |
| 6309 |
'function yoohoo() {\n' + |
| 6310 |
' alert(x);\n' + |
| 6311 |
'}') |
| 6312 |
bt( |
| 6313 |
'function*() {\n' + |
| 6314 |
' yield 1;\n' + |
| 6315 |
'}') |
| 6316 |
bt( |
| 6317 |
'function* yoohoo() {\n' + |
| 6318 |
' yield 1;\n' + |
| 6319 |
'}') |
| 6320 |
bt( |
| 6321 |
'function* x() {\n' + |
| 6322 |
' yield 1;\n' + |
| 6323 |
'}') |
| 6324 |
bt( |
| 6325 |
'async x() {\n' + |
| 6326 |
' yield 1;\n' + |
| 6327 |
'}') |
| 6328 |
bt( |
| 6329 |
'var a={data(){},\n' + |
| 6330 |
'data2(){}}', |
| 6331 |
# -- output -- |
| 6332 |
'var a = {\n' + |
| 6333 |
' data() {},\n' + |
| 6334 |
' data2() {}\n' + |
| 6335 |
'}') |
| 6336 |
bt( |
| 6337 |
'new Vue({\n' + |
| 6338 |
'data(){},\n' + |
| 6339 |
'data2(){}, a:1})', |
| 6340 |
# -- output -- |
| 6341 |
'new Vue({\n' + |
| 6342 |
' data() {},\n' + |
| 6343 |
' data2() {},\n' + |
| 6344 |
' a: 1\n' + |
| 6345 |
'})') |
| 6346 |
bt( |
| 6347 |
'export default {data(){},\n' + |
| 6348 |
'data2(){},\n' + |
| 6349 |
'a:1}', |
| 6350 |
# -- output -- |
| 6351 |
'export default {\n' + |
| 6352 |
' data() {},\n' + |
| 6353 |
' data2() {},\n' + |
| 6354 |
' a: 1\n' + |
| 6355 |
'}') |
| 6356 |
bt( |
| 6357 |
'var a={*data(){},*data2(){}}', |
| 6358 |
# -- output -- |
| 6359 |
'var a = {\n' + |
| 6360 |
' * data() {},\n' + |
| 6361 |
' * data2() {}\n' + |
| 6362 |
'}') |
| 6363 |
bt( |
| 6364 |
'new Vue({\n' + |
| 6365 |
'*data(){},*data2(){}, a:1})', |
| 6366 |
# -- output -- |
| 6367 |
'new Vue({\n' + |
| 6368 |
' * data() {},\n' + |
| 6369 |
' * data2() {},\n' + |
| 6370 |
' a: 1\n' + |
| 6371 |
'})') |
| 6372 |
bt( |
| 6373 |
'export default {*data(){},*data2(){},\n' + |
| 6374 |
'a:1}', |
| 6375 |
# -- output -- |
| 6376 |
'export default {\n' + |
| 6377 |
' * data() {},\n' + |
| 6378 |
' * data2() {},\n' + |
| 6379 |
' a: 1\n' + |
| 6380 |
'}') |
| 6381 |
|
| 6382 |
# jslint and space after anon function - (space_after_named_function = "true") |
| 6383 |
self.reset_options() |
| 6384 |
self.options.space_after_named_function = true |
| 6385 |
bt( |
| 6386 |
'a=typeof(x)', |
| 6387 |
# -- output -- |
| 6388 |
'a = typeof(x)') |
| 6389 |
bt( |
| 6390 |
'x();\n' + |
| 6391 |
'\n' + |
| 6392 |
'function(){}', |
| 6393 |
# -- output -- |
| 6394 |
'x();\n' + |
| 6395 |
'\n' + |
| 6396 |
'function() {}') |
| 6397 |
bt( |
| 6398 |
'x();\n' + |
| 6399 |
'\n' + |
| 6400 |
'function y(){}', |
| 6401 |
# -- output -- |
| 6402 |
'x();\n' + |
| 6403 |
'\n' + |
| 6404 |
'function y () {}') |
| 6405 |
bt( |
| 6406 |
'x();\n' + |
| 6407 |
'\n' + |
| 6408 |
'var x = {\n' + |
| 6409 |
'x: function(){}\n' + |
| 6410 |
'}', |
| 6411 |
# -- output -- |
| 6412 |
'x();\n' + |
| 6413 |
'\n' + |
| 6414 |
'var x = {\n' + |
| 6415 |
' x: function() {}\n' + |
| 6416 |
'}') |
| 6417 |
bt( |
| 6418 |
'x();\n' + |
| 6419 |
'\n' + |
| 6420 |
'var x = {\n' + |
| 6421 |
'x: function y(){}\n' + |
| 6422 |
'}', |
| 6423 |
# -- output -- |
| 6424 |
'x();\n' + |
| 6425 |
'\n' + |
| 6426 |
'var x = {\n' + |
| 6427 |
' x: function y () {}\n' + |
| 6428 |
'}') |
| 6429 |
bt( |
| 6430 |
'function () {\n' + |
| 6431 |
' var a, b, c, d, e = [],\n' + |
| 6432 |
' f;\n' + |
| 6433 |
'}', |
| 6434 |
# -- output -- |
| 6435 |
'function() {\n' + |
| 6436 |
' var a, b, c, d, e = [],\n' + |
| 6437 |
' f;\n' + |
| 6438 |
'}') |
| 6439 |
bt( |
| 6440 |
'switch(x) {case 0: case 1: a(); break; default: break}', |
| 6441 |
# -- output -- |
| 6442 |
'switch (x) {\n' + |
| 6443 |
' case 0:\n' + |
| 6444 |
' case 1:\n' + |
| 6445 |
' a();\n' + |
| 6446 |
' break;\n' + |
| 6447 |
' default:\n' + |
| 6448 |
' break\n' + |
| 6449 |
'}') |
| 6450 |
bt( |
| 6451 |
'switch(x){case -1:break;case !y:break;}', |
| 6452 |
# -- output -- |
| 6453 |
'switch (x) {\n' + |
| 6454 |
' case -1:\n' + |
| 6455 |
' break;\n' + |
| 6456 |
' case !y:\n' + |
| 6457 |
' break;\n' + |
| 6458 |
'}') |
| 6459 |
|
| 6460 |
# Issue #1357 |
| 6461 |
bt( |
| 6462 |
'switch(x) {case 0: case 1:{a(); break;} default: break}', |
| 6463 |
# -- output -- |
| 6464 |
'switch (x) {\n' + |
| 6465 |
' case 0:\n' + |
| 6466 |
' case 1: {\n' + |
| 6467 |
' a();\n' + |
| 6468 |
' break;\n' + |
| 6469 |
' }\n' + |
| 6470 |
' default:\n' + |
| 6471 |
' break\n' + |
| 6472 |
'}') |
| 6473 |
|
| 6474 |
# Issue #1357 |
| 6475 |
bt( |
| 6476 |
'switch(x){case -1:break;case !y:{break;}}', |
| 6477 |
# -- output -- |
| 6478 |
'switch (x) {\n' + |
| 6479 |
' case -1:\n' + |
| 6480 |
' break;\n' + |
| 6481 |
' case !y: {\n' + |
| 6482 |
' break;\n' + |
| 6483 |
' }\n' + |
| 6484 |
'}') |
| 6485 |
|
| 6486 |
# Issue #1622 - basic class with function definitions |
| 6487 |
bt( |
| 6488 |
'class blah {\n' + |
| 6489 |
' constructor() {\n' + |
| 6490 |
' this.doStuff()\n' + |
| 6491 |
' }\n' + |
| 6492 |
' doStuff() {\n' + |
| 6493 |
' console.log("stuff")\n' + |
| 6494 |
' }\n' + |
| 6495 |
'}', |
| 6496 |
# -- output -- |
| 6497 |
'class blah {\n' + |
| 6498 |
' constructor () {\n' + |
| 6499 |
' this.doStuff()\n' + |
| 6500 |
' }\n' + |
| 6501 |
' doStuff () {\n' + |
| 6502 |
' console.log("stuff")\n' + |
| 6503 |
' }\n' + |
| 6504 |
'}') |
| 6505 |
|
| 6506 |
# Issue #1622 - class with extends and function definitions |
| 6507 |
bt( |
| 6508 |
'class blah extends something {\n' + |
| 6509 |
' constructor() {\n' + |
| 6510 |
' this.zz = 2 + 2;\n' + |
| 6511 |
' }\n' + |
| 6512 |
' someOtherFunction() {\n' + |
| 6513 |
'this.y = 1;\n' + |
| 6514 |
' }\n' + |
| 6515 |
'}', |
| 6516 |
# -- output -- |
| 6517 |
'class blah extends something {\n' + |
| 6518 |
' constructor () {\n' + |
| 6519 |
' this.zz = 2 + 2;\n' + |
| 6520 |
' }\n' + |
| 6521 |
' someOtherFunction () {\n' + |
| 6522 |
' this.y = 1;\n' + |
| 6523 |
' }\n' + |
| 6524 |
'}') |
| 6525 |
|
| 6526 |
# Issue #1622 - class/extends as a property |
| 6527 |
bt( |
| 6528 |
'var a.class = {\n' + |
| 6529 |
' ...abc(),\n' + |
| 6530 |
'}\n' + |
| 6531 |
'b.extends({\n' + |
| 6532 |
' bb.s(),\n' + |
| 6533 |
'})', |
| 6534 |
# -- output -- |
| 6535 |
'var a.class = {\n' + |
| 6536 |
' ...abc(),\n' + |
| 6537 |
'}\n' + |
| 6538 |
'b.extends({\n' + |
| 6539 |
' bb.s(),\n' + |
| 6540 |
'})') |
| 6541 |
|
| 6542 |
# typical greasemonkey start |
| 6543 |
test_fragment( |
| 6544 |
'// comment 2\n' + |
| 6545 |
'(function()') |
| 6546 |
bt( |
| 6547 |
'var a2, b2, c2, d2 = 0, c = function() {}, d = \'\';', |
| 6548 |
# -- output -- |
| 6549 |
'var a2, b2, c2, d2 = 0,\n' + |
| 6550 |
' c = function() {},\n' + |
| 6551 |
' d = \'\';') |
| 6552 |
bt( |
| 6553 |
'var a2, b2, c2, d2 = 0, c = function yoohoo() {}, d = \'\';', |
| 6554 |
# -- output -- |
| 6555 |
'var a2, b2, c2, d2 = 0,\n' + |
| 6556 |
' c = function yoohoo () {},\n' + |
| 6557 |
' d = \'\';') |
| 6558 |
bt( |
| 6559 |
'var a2, b2, c2, d2 = 0, c = function() {},\n' + |
| 6560 |
'd = \'\';', |
| 6561 |
# -- output -- |
| 6562 |
'var a2, b2, c2, d2 = 0,\n' + |
| 6563 |
' c = function() {},\n' + |
| 6564 |
' d = \'\';') |
| 6565 |
bt( |
| 6566 |
'var o2=$.extend(a);function(){alert(x);}', |
| 6567 |
# -- output -- |
| 6568 |
'var o2 = $.extend(a);\n' + |
| 6569 |
'\n' + |
| 6570 |
'function() {\n' + |
| 6571 |
' alert(x);\n' + |
| 6572 |
'}') |
| 6573 |
bt( |
| 6574 |
'var o2=$.extend(a);function yoohoo(){alert(x);}', |
| 6575 |
# -- output -- |
| 6576 |
'var o2 = $.extend(a);\n' + |
| 6577 |
'\n' + |
| 6578 |
'function yoohoo () {\n' + |
| 6579 |
' alert(x);\n' + |
| 6580 |
'}') |
| 6581 |
bt( |
| 6582 |
'function*() {\n' + |
| 6583 |
' yield 1;\n' + |
| 6584 |
'}') |
| 6585 |
bt( |
| 6586 |
'function* yoohoo() {\n' + |
| 6587 |
' yield 1;\n' + |
| 6588 |
'}', |
| 6589 |
# -- output -- |
| 6590 |
'function* yoohoo () {\n' + |
| 6591 |
' yield 1;\n' + |
| 6592 |
'}') |
| 6593 |
bt( |
| 6594 |
'function* x() {\n' + |
| 6595 |
' yield 1;\n' + |
| 6596 |
'}', |
| 6597 |
# -- output -- |
| 6598 |
'function* x () {\n' + |
| 6599 |
' yield 1;\n' + |
| 6600 |
'}') |
| 6601 |
bt( |
| 6602 |
'async x() {\n' + |
| 6603 |
' yield 1;\n' + |
| 6604 |
'}', |
| 6605 |
# -- output -- |
| 6606 |
'async x () {\n' + |
| 6607 |
' yield 1;\n' + |
| 6608 |
'}') |
| 6609 |
bt( |
| 6610 |
'var a={data(){},\n' + |
| 6611 |
'data2(){}}', |
| 6612 |
# -- output -- |
| 6613 |
'var a = {\n' + |
| 6614 |
' data () {},\n' + |
| 6615 |
' data2 () {}\n' + |
| 6616 |
'}') |
| 6617 |
bt( |
| 6618 |
'new Vue({\n' + |
| 6619 |
'data(){},\n' + |
| 6620 |
'data2(){}, a:1})', |
| 6621 |
# -- output -- |
| 6622 |
'new Vue({\n' + |
| 6623 |
' data () {},\n' + |
| 6624 |
' data2 () {},\n' + |
| 6625 |
' a: 1\n' + |
| 6626 |
'})') |
| 6627 |
bt( |
| 6628 |
'export default {data(){},\n' + |
| 6629 |
'data2(){},\n' + |
| 6630 |
'a:1}', |
| 6631 |
# -- output -- |
| 6632 |
'export default {\n' + |
| 6633 |
' data () {},\n' + |
| 6634 |
' data2 () {},\n' + |
| 6635 |
' a: 1\n' + |
| 6636 |
'}') |
| 6637 |
bt( |
| 6638 |
'var a={*data(){},*data2(){}}', |
| 6639 |
# -- output -- |
| 6640 |
'var a = {\n' + |
| 6641 |
' * data () {},\n' + |
| 6642 |
' * data2 () {}\n' + |
| 6643 |
'}') |
| 6644 |
bt( |
| 6645 |
'new Vue({\n' + |
| 6646 |
'*data(){},*data2(){}, a:1})', |
| 6647 |
# -- output -- |
| 6648 |
'new Vue({\n' + |
| 6649 |
' * data () {},\n' + |
| 6650 |
' * data2 () {},\n' + |
| 6651 |
' a: 1\n' + |
| 6652 |
'})') |
| 6653 |
bt( |
| 6654 |
'export default {*data(){},*data2(){},\n' + |
| 6655 |
'a:1}', |
| 6656 |
# -- output -- |
| 6657 |
'export default {\n' + |
| 6658 |
' * data () {},\n' + |
| 6659 |
' * data2 () {},\n' + |
| 6660 |
' a: 1\n' + |
| 6661 |
'}') |
| 6662 |
|
| 6663 |
|
| 6664 |
#============================================================ |
| 6665 |
# Regression tests |
| 6666 |
self.reset_options() |
| 6667 |
|
| 6668 |
# Issue 241 |
| 6669 |
bt( |
| 6670 |
'obj\n' + |
| 6671 |
' .last({\n' + |
| 6672 |
' foo: 1,\n' + |
| 6673 |
' bar: 2\n' + |
| 6674 |
' });\n' + |
| 6675 |
'var test = 1;') |
| 6676 |
|
| 6677 |
# Issue #1852 - semicolon followed by block statement |
| 6678 |
bt( |
| 6679 |
'(function() {\n' + |
| 6680 |
' some_code_here();\n' + |
| 6681 |
' {\n' + |
| 6682 |
' /* IE11 let bug bypass */\n' + |
| 6683 |
' let index;\n' + |
| 6684 |
' for (index in a) {\n' + |
| 6685 |
' a[index];\n' + |
| 6686 |
' }\n' + |
| 6687 |
' }\n' + |
| 6688 |
'})();') |
| 6689 |
|
| 6690 |
# Issue #1852 - semicolon followed by block statement 2 |
| 6691 |
bt( |
| 6692 |
'let x = { A: 1 }; { console.log("hello"); }', |
| 6693 |
# -- output -- |
| 6694 |
'let x = {\n' + |
| 6695 |
' A: 1\n' + |
| 6696 |
'};\n' + |
| 6697 |
'{\n' + |
| 6698 |
' console.log("hello");\n' + |
| 6699 |
'}') |
| 6700 |
|
| 6701 |
# Issue #772 |
| 6702 |
bt( |
| 6703 |
'this.initAttributes([\n' + |
| 6704 |
'"name",\n' + |
| 6705 |
'["parent", null, "parentName"],\n' + |
| 6706 |
'"length",\n' + |
| 6707 |
'["id", this.name],\n' + |
| 6708 |
']);', |
| 6709 |
# -- output -- |
| 6710 |
'this.initAttributes([\n' + |
| 6711 |
' "name",\n' + |
| 6712 |
' ["parent", null, "parentName"],\n' + |
| 6713 |
' "length",\n' + |
| 6714 |
' ["id", this.name],\n' + |
| 6715 |
']);') |
| 6716 |
|
| 6717 |
# Issue #1663 |
| 6718 |
bt( |
| 6719 |
'{\n' + |
| 6720 |
' /* howdy\n' + |
| 6721 |
' \n' + |
| 6722 |
' */\n' + |
| 6723 |
'}') |
| 6724 |
|
| 6725 |
# #1095 - Return without semicolon followed by prefix on a new line |
| 6726 |
bt( |
| 6727 |
'function x(){\n' + |
| 6728 |
'return\n' + |
| 6729 |
'++a\n' + |
| 6730 |
'}\n' + |
| 6731 |
'\n' + |
| 6732 |
'while(true) {\n' + |
| 6733 |
'return\n' + |
| 6734 |
'--b\n' + |
| 6735 |
'}', |
| 6736 |
# -- output -- |
| 6737 |
'function x() {\n' + |
| 6738 |
' return\n' + |
| 6739 |
' ++a\n' + |
| 6740 |
'}\n' + |
| 6741 |
'\n' + |
| 6742 |
'while (true) {\n' + |
| 6743 |
' return\n' + |
| 6744 |
' --b\n' + |
| 6745 |
'}') |
| 6746 |
|
| 6747 |
# #1095 |
| 6748 |
bt( |
| 6749 |
'function test(){\n' + |
| 6750 |
'if(x) return\n' + |
| 6751 |
'++x\n' + |
| 6752 |
'var y= 1;\n' + |
| 6753 |
'}\n' + |
| 6754 |
'function t1(){\n' + |
| 6755 |
'if(cc) return;\n' + |
| 6756 |
'else return\n' + |
| 6757 |
'--cc\n' + |
| 6758 |
'}', |
| 6759 |
# -- output -- |
| 6760 |
'function test() {\n' + |
| 6761 |
' if (x) return\n' + |
| 6762 |
' ++x\n' + |
| 6763 |
' var y = 1;\n' + |
| 6764 |
'}\n' + |
| 6765 |
'\n' + |
| 6766 |
'function t1() {\n' + |
| 6767 |
' if (cc) return;\n' + |
| 6768 |
' else return\n' + |
| 6769 |
' --cc\n' + |
| 6770 |
'}') |
| 6771 |
|
| 6772 |
# #1095 - Return with semicolon followed by a prefix on a new line |
| 6773 |
bt( |
| 6774 |
'function x(){\n' + |
| 6775 |
'return; ++a\n' + |
| 6776 |
'}\n' + |
| 6777 |
'\n' + |
| 6778 |
'while(true){return; --b\n' + |
| 6779 |
'}', |
| 6780 |
# -- output -- |
| 6781 |
'function x() {\n' + |
| 6782 |
' return;\n' + |
| 6783 |
' ++a\n' + |
| 6784 |
'}\n' + |
| 6785 |
'\n' + |
| 6786 |
'while (true) {\n' + |
| 6787 |
' return;\n' + |
| 6788 |
' --b\n' + |
| 6789 |
'}') |
| 6790 |
|
| 6791 |
# #1838 - handle class and interface word as an object property |
| 6792 |
bt( |
| 6793 |
'{\n' + |
| 6794 |
' class: {\n' + |
| 6795 |
' a: 1,\n' + |
| 6796 |
' b: 2,\n' + |
| 6797 |
' c: 3,\n' + |
| 6798 |
' }\n' + |
| 6799 |
' interface: {\n' + |
| 6800 |
' a: 1,\n' + |
| 6801 |
' b: 2,\n' + |
| 6802 |
' c: 3,\n' + |
| 6803 |
' }\n' + |
| 6804 |
'}') |
| 6805 |
|
| 6806 |
# #1838 - handle class word as an object property but with space after colon |
| 6807 |
bt( |
| 6808 |
'{\n' + |
| 6809 |
' class : { a: 1,\n' + |
| 6810 |
'b: 2,c : 3\n' + |
| 6811 |
' }\n' + |
| 6812 |
'}', |
| 6813 |
# -- output -- |
| 6814 |
'{\n' + |
| 6815 |
' class: {\n' + |
| 6816 |
' a: 1,\n' + |
| 6817 |
' b: 2,\n' + |
| 6818 |
' c: 3\n' + |
| 6819 |
' }\n' + |
| 6820 |
'}') |
| 6821 |
|
| 6822 |
# #1838 - handle class word as an object property but without spaces |
| 6823 |
bt( |
| 6824 |
'{class:{a:1,b:2,c:3,}}', |
| 6825 |
# -- output -- |
| 6826 |
'{\n' + |
| 6827 |
' class: {\n' + |
| 6828 |
' a: 1,\n' + |
| 6829 |
' b: 2,\n' + |
| 6830 |
' c: 3,\n' + |
| 6831 |
' }\n' + |
| 6832 |
'}') |
| 6833 |
|
| 6834 |
# #1838 - handle class word as a nested object property |
| 6835 |
bt( |
| 6836 |
'{x:{a:1,class:2,c:3,}}', |
| 6837 |
# -- output -- |
| 6838 |
'{\n' + |
| 6839 |
' x: {\n' + |
| 6840 |
' a: 1,\n' + |
| 6841 |
' class: 2,\n' + |
| 6842 |
' c: 3,\n' + |
| 6843 |
' }\n' + |
| 6844 |
'}') |
| 6845 |
bt( |
| 6846 |
'obj\n' + |
| 6847 |
' .last(a, function() {\n' + |
| 6848 |
' var test;\n' + |
| 6849 |
' });\n' + |
| 6850 |
'var test = 1;') |
| 6851 |
bt( |
| 6852 |
'obj.first()\n' + |
| 6853 |
' .second()\n' + |
| 6854 |
' .last(function(err, response) {\n' + |
| 6855 |
' console.log(err);\n' + |
| 6856 |
' });') |
| 6857 |
|
| 6858 |
# Issue 268 and 275 |
| 6859 |
bt( |
| 6860 |
'obj.last(a, function() {\n' + |
| 6861 |
' var test;\n' + |
| 6862 |
'});\n' + |
| 6863 |
'var test = 1;') |
| 6864 |
bt( |
| 6865 |
'obj.last(a,\n' + |
| 6866 |
' function() {\n' + |
| 6867 |
' var test;\n' + |
| 6868 |
' });\n' + |
| 6869 |
'var test = 1;') |
| 6870 |
bt( |
| 6871 |
'(function() {if (!window.FOO) window.FOO || (window.FOO = function() {var b = {bar: "zort"};});})();', |
| 6872 |
# -- output -- |
| 6873 |
'(function() {\n' + |
| 6874 |
' if (!window.FOO) window.FOO || (window.FOO = function() {\n' + |
| 6875 |
' var b = {\n' + |
| 6876 |
' bar: "zort"\n' + |
| 6877 |
' };\n' + |
| 6878 |
' });\n' + |
| 6879 |
'})();') |
| 6880 |
|
| 6881 |
# Issue 281 |
| 6882 |
bt( |
| 6883 |
'define(["dojo/_base/declare", "my/Employee", "dijit/form/Button",\n' + |
| 6884 |
' "dojo/_base/lang", "dojo/Deferred"\n' + |
| 6885 |
'], function(declare, Employee, Button, lang, Deferred) {\n' + |
| 6886 |
' return declare(Employee, {\n' + |
| 6887 |
' constructor: function() {\n' + |
| 6888 |
' new Button({\n' + |
| 6889 |
' onClick: lang.hitch(this, function() {\n' + |
| 6890 |
' new Deferred().then(lang.hitch(this, function() {\n' + |
| 6891 |
' this.salary * 0.25;\n' + |
| 6892 |
' }));\n' + |
| 6893 |
' })\n' + |
| 6894 |
' });\n' + |
| 6895 |
' }\n' + |
| 6896 |
' });\n' + |
| 6897 |
'});') |
| 6898 |
bt( |
| 6899 |
'define(["dojo/_base/declare", "my/Employee", "dijit/form/Button",\n' + |
| 6900 |
' "dojo/_base/lang", "dojo/Deferred"\n' + |
| 6901 |
' ],\n' + |
| 6902 |
' function(declare, Employee, Button, lang, Deferred) {\n' + |
| 6903 |
' return declare(Employee, {\n' + |
| 6904 |
' constructor: function() {\n' + |
| 6905 |
' new Button({\n' + |
| 6906 |
' onClick: lang.hitch(this, function() {\n' + |
| 6907 |
' new Deferred().then(lang.hitch(this, function() {\n' + |
| 6908 |
' this.salary * 0.25;\n' + |
| 6909 |
' }));\n' + |
| 6910 |
' })\n' + |
| 6911 |
' });\n' + |
| 6912 |
' }\n' + |
| 6913 |
' });\n' + |
| 6914 |
' });') |
| 6915 |
|
| 6916 |
# Issue 459 |
| 6917 |
bt( |
| 6918 |
'(function() {\n' + |
| 6919 |
' return {\n' + |
| 6920 |
' foo: function() {\n' + |
| 6921 |
' return "bar";\n' + |
| 6922 |
' },\n' + |
| 6923 |
' bar: ["bar"]\n' + |
| 6924 |
' };\n' + |
| 6925 |
'}());') |
| 6926 |
|
| 6927 |
# Issue 505 - strings should end at newline unless continued by backslash |
| 6928 |
bt( |
| 6929 |
'var name = "a;\n' + |
| 6930 |
'name = "b";') |
| 6931 |
bt( |
| 6932 |
'var name = "a;\\\n' + |
| 6933 |
' name = b";') |
| 6934 |
|
| 6935 |
# Issue 514 - some operators require spaces to distinguish them |
| 6936 |
bt('var c = "_ACTION_TO_NATIVEAPI_" + ++g++ + +new Date;') |
| 6937 |
bt('var c = "_ACTION_TO_NATIVEAPI_" - --g-- - -new Date;') |
| 6938 |
|
| 6939 |
# Issue 440 - reserved words can be used as object property names |
| 6940 |
bt( |
| 6941 |
'a = {\n' + |
| 6942 |
' function: {},\n' + |
| 6943 |
' "function": {},\n' + |
| 6944 |
' throw: {},\n' + |
| 6945 |
' "throw": {},\n' + |
| 6946 |
' var: {},\n' + |
| 6947 |
' "var": {},\n' + |
| 6948 |
' set: {},\n' + |
| 6949 |
' "set": {},\n' + |
| 6950 |
' get: {},\n' + |
| 6951 |
' "get": {},\n' + |
| 6952 |
' if: {},\n' + |
| 6953 |
' "if": {},\n' + |
| 6954 |
' then: {},\n' + |
| 6955 |
' "then": {},\n' + |
| 6956 |
' else: {},\n' + |
| 6957 |
' "else": {},\n' + |
| 6958 |
' yay: {}\n' + |
| 6959 |
'};') |
| 6960 |
|
| 6961 |
# Issue 331 - if-else with braces edge case |
| 6962 |
bt( |
| 6963 |
'if(x){a();}else{b();}if(y){c();}', |
| 6964 |
# -- output -- |
| 6965 |
'if (x) {\n' + |
| 6966 |
' a();\n' + |
| 6967 |
'} else {\n' + |
| 6968 |
' b();\n' + |
| 6969 |
'}\n' + |
| 6970 |
'if (y) {\n' + |
| 6971 |
' c();\n' + |
| 6972 |
'}') |
| 6973 |
|
| 6974 |
# Issue #1683 - switch-case wrong indentation |
| 6975 |
bt( |
| 6976 |
'switch (x) { case 0: if (y == z) { a(); } else { b(); } case 1: c(); }', |
| 6977 |
# -- output -- |
| 6978 |
'switch (x) {\n' + |
| 6979 |
' case 0:\n' + |
| 6980 |
' if (y == z) {\n' + |
| 6981 |
' a();\n' + |
| 6982 |
' } else {\n' + |
| 6983 |
' b();\n' + |
| 6984 |
' }\n' + |
| 6985 |
' case 1:\n' + |
| 6986 |
' c();\n' + |
| 6987 |
'}') |
| 6988 |
|
| 6989 |
# Issue 485 - ensure function declarations behave the same in arrays as elsewhere |
| 6990 |
bt( |
| 6991 |
'var v = ["a",\n' + |
| 6992 |
' function() {\n' + |
| 6993 |
' return;\n' + |
| 6994 |
' }, {\n' + |
| 6995 |
' id: 1\n' + |
| 6996 |
' }\n' + |
| 6997 |
'];') |
| 6998 |
bt( |
| 6999 |
'var v = ["a", function() {\n' + |
| 7000 |
' return;\n' + |
| 7001 |
'}, {\n' + |
| 7002 |
' id: 1\n' + |
| 7003 |
'}];') |
| 7004 |
|
| 7005 |
# Issue 382 - initial totally cursory support for es6 module export |
| 7006 |
bt( |
| 7007 |
'module "Even" {\n' + |
| 7008 |
' import odd from "Odd";\n' + |
| 7009 |
' export function sum(x, y) {\n' + |
| 7010 |
' return x + y;\n' + |
| 7011 |
' }\n' + |
| 7012 |
' export var pi = 3.141593;\n' + |
| 7013 |
' export default moduleName;\n' + |
| 7014 |
'}') |
| 7015 |
bt( |
| 7016 |
'module "Even" {\n' + |
| 7017 |
' export default function div(x, y) {}\n' + |
| 7018 |
'}') |
| 7019 |
|
| 7020 |
# Issue 889 - export default { ... } |
| 7021 |
bt( |
| 7022 |
'export default {\n' + |
| 7023 |
' func1() {},\n' + |
| 7024 |
' func2() {}\n' + |
| 7025 |
' func3() {}\n' + |
| 7026 |
'}') |
| 7027 |
bt( |
| 7028 |
'export default {\n' + |
| 7029 |
' a() {\n' + |
| 7030 |
' return 1;\n' + |
| 7031 |
' },\n' + |
| 7032 |
' b() {\n' + |
| 7033 |
' return 2;\n' + |
| 7034 |
' },\n' + |
| 7035 |
' c() {\n' + |
| 7036 |
' return 3;\n' + |
| 7037 |
' }\n' + |
| 7038 |
'}') |
| 7039 |
|
| 7040 |
# Issue 508 |
| 7041 |
bt('set["name"]') |
| 7042 |
bt('get["name"]') |
| 7043 |
test_fragment( |
| 7044 |
'a = {\n' + |
| 7045 |
' set b(x) {},\n' + |
| 7046 |
' c: 1,\n' + |
| 7047 |
' d: function() {}\n' + |
| 7048 |
'};') |
| 7049 |
test_fragment( |
| 7050 |
'a = {\n' + |
| 7051 |
' get b() {\n' + |
| 7052 |
' retun 0;\n' + |
| 7053 |
' },\n' + |
| 7054 |
' c: 1,\n' + |
| 7055 |
' d: function() {}\n' + |
| 7056 |
'};') |
| 7057 |
|
| 7058 |
# Issue 298 - do not under indent if/while/for condtionals experesions |
| 7059 |
bt( |
| 7060 |
'\'use strict\';\n' + |
| 7061 |
'if ([].some(function() {\n' + |
| 7062 |
' return false;\n' + |
| 7063 |
' })) {\n' + |
| 7064 |
' console.log("hello");\n' + |
| 7065 |
'}') |
| 7066 |
|
| 7067 |
# Issue 298 - do not under indent if/while/for condtionals experesions |
| 7068 |
bt( |
| 7069 |
'\'use strict\';\n' + |
| 7070 |
'if ([].some(function() {\n' + |
| 7071 |
' return false;\n' + |
| 7072 |
' })) {\n' + |
| 7073 |
' console.log("hello");\n' + |
| 7074 |
'}') |
| 7075 |
|
| 7076 |
# Issue 552 - Typescript? Okay... we didn't break it before, so try not to break it now. |
| 7077 |
bt( |
| 7078 |
'class Test {\n' + |
| 7079 |
' blah: string[];\n' + |
| 7080 |
' foo(): number {\n' + |
| 7081 |
' return 0;\n' + |
| 7082 |
' }\n' + |
| 7083 |
' bar(): number {\n' + |
| 7084 |
' return 0;\n' + |
| 7085 |
' }\n' + |
| 7086 |
'}') |
| 7087 |
|
| 7088 |
# Issue 1544 - Typescript declare formatting (no newline). |
| 7089 |
bt( |
| 7090 |
'declare const require: any;\n' + |
| 7091 |
'declare function greet(greeting: string): void;\n' + |
| 7092 |
'declare var foo: number;\n' + |
| 7093 |
'declare namespace myLib {\n' + |
| 7094 |
' function makeGreeting(s: string): string;\n' + |
| 7095 |
' let numberOfGreetings: number;\n' + |
| 7096 |
'}\n' + |
| 7097 |
'declare let test: any;') |
| 7098 |
bt( |
| 7099 |
'interface Test {\n' + |
| 7100 |
' blah: string[];\n' + |
| 7101 |
' foo(): number {\n' + |
| 7102 |
' return 0;\n' + |
| 7103 |
' }\n' + |
| 7104 |
' bar(): number {\n' + |
| 7105 |
' return 0;\n' + |
| 7106 |
' }\n' + |
| 7107 |
'}') |
| 7108 |
|
| 7109 |
# Issue 583 - Functions with comments after them should still indent correctly. |
| 7110 |
bt( |
| 7111 |
'function exit(code) {\n' + |
| 7112 |
' setTimeout(function() {\n' + |
| 7113 |
' phantom.exit(code);\n' + |
| 7114 |
' }, 0);\n' + |
| 7115 |
' phantom.onError = function() {};\n' + |
| 7116 |
'}\n' + |
| 7117 |
'// Comment') |
| 7118 |
|
| 7119 |
# Issue 806 - newline arrow functions |
| 7120 |
bt( |
| 7121 |
'a.b("c",\n' + |
| 7122 |
' () => d.e\n' + |
| 7123 |
')') |
| 7124 |
|
| 7125 |
# Issue 810 - es6 object literal detection |
| 7126 |
bt( |
| 7127 |
'function badFormatting() {\n' + |
| 7128 |
' return {\n' + |
| 7129 |
' a,\n' + |
| 7130 |
' b: c,\n' + |
| 7131 |
' d: e,\n' + |
| 7132 |
' f: g,\n' + |
| 7133 |
' h,\n' + |
| 7134 |
' i,\n' + |
| 7135 |
' j: k\n' + |
| 7136 |
' }\n' + |
| 7137 |
'}\n' + |
| 7138 |
'\n' + |
| 7139 |
'function goodFormatting() {\n' + |
| 7140 |
' return {\n' + |
| 7141 |
' a: b,\n' + |
| 7142 |
' c,\n' + |
| 7143 |
' d: e,\n' + |
| 7144 |
' f: g,\n' + |
| 7145 |
' h,\n' + |
| 7146 |
' i,\n' + |
| 7147 |
' j: k\n' + |
| 7148 |
' }\n' + |
| 7149 |
'}') |
| 7150 |
|
| 7151 |
# Issue 602 - ES6 object literal shorthand functions |
| 7152 |
bt( |
| 7153 |
'return {\n' + |
| 7154 |
' fn1() {},\n' + |
| 7155 |
' fn2() {}\n' + |
| 7156 |
'}') |
| 7157 |
bt( |
| 7158 |
'throw {\n' + |
| 7159 |
' fn1() {},\n' + |
| 7160 |
' fn2() {}\n' + |
| 7161 |
'}') |
| 7162 |
bt( |
| 7163 |
'foo({\n' + |
| 7164 |
' fn1(a) {}\n' + |
| 7165 |
' fn2(a) {}\n' + |
| 7166 |
'})') |
| 7167 |
bt( |
| 7168 |
'foo("text", {\n' + |
| 7169 |
' fn1(a) {}\n' + |
| 7170 |
' fn2(a) {}\n' + |
| 7171 |
'})') |
| 7172 |
bt( |
| 7173 |
'oneArg = {\n' + |
| 7174 |
' fn1(a) {\n' + |
| 7175 |
' do();\n' + |
| 7176 |
' },\n' + |
| 7177 |
' fn2() {}\n' + |
| 7178 |
'}') |
| 7179 |
bt( |
| 7180 |
'multiArg = {\n' + |
| 7181 |
' fn1(a, b, c) {\n' + |
| 7182 |
' do();\n' + |
| 7183 |
' },\n' + |
| 7184 |
' fn2() {}\n' + |
| 7185 |
'}') |
| 7186 |
bt( |
| 7187 |
'noArgs = {\n' + |
| 7188 |
' fn1() {\n' + |
| 7189 |
' do();\n' + |
| 7190 |
' },\n' + |
| 7191 |
' fn2() {}\n' + |
| 7192 |
'}') |
| 7193 |
bt( |
| 7194 |
'emptyFn = {\n' + |
| 7195 |
' fn1() {},\n' + |
| 7196 |
' fn2() {}\n' + |
| 7197 |
'}') |
| 7198 |
bt( |
| 7199 |
'nested = {\n' + |
| 7200 |
' fns: {\n' + |
| 7201 |
' fn1() {},\n' + |
| 7202 |
' fn2() {}\n' + |
| 7203 |
' }\n' + |
| 7204 |
'}') |
| 7205 |
bt( |
| 7206 |
'array = [{\n' + |
| 7207 |
' fn1() {},\n' + |
| 7208 |
' prop: val,\n' + |
| 7209 |
' fn2() {}\n' + |
| 7210 |
'}]') |
| 7211 |
bt( |
| 7212 |
'expr = expr ? expr : {\n' + |
| 7213 |
' fn1() {},\n' + |
| 7214 |
' fn2() {}\n' + |
| 7215 |
'}') |
| 7216 |
bt( |
| 7217 |
'strange = valid + {\n' + |
| 7218 |
' fn1() {},\n' + |
| 7219 |
' fn2() {\n' + |
| 7220 |
' return 1;\n' + |
| 7221 |
' }\n' + |
| 7222 |
'}.fn2()') |
| 7223 |
|
| 7224 |
# Issue 854 - Arrow function with statement block |
| 7225 |
bt( |
| 7226 |
'test(() => {\n' + |
| 7227 |
' var a = {}\n' + |
| 7228 |
'\n' + |
| 7229 |
' a.what = () => true ? 1 : 2\n' + |
| 7230 |
'\n' + |
| 7231 |
' a.thing = () => {\n' + |
| 7232 |
' b();\n' + |
| 7233 |
' }\n' + |
| 7234 |
'})') |
| 7235 |
|
| 7236 |
# Issue 1727 - Optional chaining |
| 7237 |
bt('true?.1:.2', 'true ? .1 : .2') |
| 7238 |
|
| 7239 |
# Issue 406 - Multiline array |
| 7240 |
bt( |
| 7241 |
'var tempName = [\n' + |
| 7242 |
' "temp",\n' + |
| 7243 |
' process.pid,\n' + |
| 7244 |
' (Math.random() * 0x1000000000).toString(36),\n' + |
| 7245 |
' new Date().getTime()\n' + |
| 7246 |
'].join("-");') |
| 7247 |
|
| 7248 |
# Issue 1801 - Optional chaining w/ obj?.[expr] syntax |
| 7249 |
bt( |
| 7250 |
'let nestedProp = obj?.["prop" + "Name"];\n' + |
| 7251 |
'let arrayItem = arr?.[42];') |
| 7252 |
|
| 7253 |
# Issue 1374 - Parameters starting with ! or [ merged into single line |
| 7254 |
bt( |
| 7255 |
'fn(\n' + |
| 7256 |
' 1,\n' + |
| 7257 |
' !1,\n' + |
| 7258 |
' 1,\n' + |
| 7259 |
' [1]\n' + |
| 7260 |
')') |
| 7261 |
|
| 7262 |
# Issue 1288 - Negative numbers remove newlines in array |
| 7263 |
bt( |
| 7264 |
'var array = [\n' + |
| 7265 |
' -1,\n' + |
| 7266 |
' 0,\n' + |
| 7267 |
' "a",\n' + |
| 7268 |
' -2,\n' + |
| 7269 |
' 1,\n' + |
| 7270 |
' -3,\n' + |
| 7271 |
'];') |
| 7272 |
|
| 7273 |
# Issue 1229 - Negated expressions in array |
| 7274 |
bt( |
| 7275 |
'a = [\n' + |
| 7276 |
' true && 1,\n' + |
| 7277 |
' true && 1,\n' + |
| 7278 |
' true && 1\n' + |
| 7279 |
']\n' + |
| 7280 |
'a = [\n' + |
| 7281 |
' !true && 1,\n' + |
| 7282 |
' !true && 1,\n' + |
| 7283 |
' !true && 1\n' + |
| 7284 |
']') |
| 7285 |
|
| 7286 |
# Issue #996 - Input ends with backslash throws exception |
| 7287 |
test_fragment( |
| 7288 |
'sd = 1;\n' + |
| 7289 |
'/') |
| 7290 |
|
| 7291 |
# Issue #1079 - unbraced if with comments should still look right |
| 7292 |
bt( |
| 7293 |
'if (console.log)\n' + |
| 7294 |
' for (var i = 0; i < 20; ++i)\n' + |
| 7295 |
' if (i % 3)\n' + |
| 7296 |
' console.log(i);\n' + |
| 7297 |
'// all done\n' + |
| 7298 |
'console.log("done");') |
| 7299 |
|
| 7300 |
# Issue #1085 - function should not have blank line in a number of cases |
| 7301 |
bt( |
| 7302 |
'var transformer =\n' + |
| 7303 |
' options.transformer ||\n' + |
| 7304 |
' globalSettings.transformer ||\n' + |
| 7305 |
' function(x) {\n' + |
| 7306 |
' return x;\n' + |
| 7307 |
' };') |
| 7308 |
|
| 7309 |
# Issue #1794 - support nullish-coalescing |
| 7310 |
bt('a = b ?? c') |
| 7311 |
|
| 7312 |
# Issue #569 - function should not have blank line in a number of cases |
| 7313 |
bt( |
| 7314 |
'(function(global) {\n' + |
| 7315 |
' "use strict";\n' + |
| 7316 |
'\n' + |
| 7317 |
' /* jshint ignore:start */\n' + |
| 7318 |
' include "somefile.js"\n' + |
| 7319 |
' /* jshint ignore:end */\n' + |
| 7320 |
'}(this));') |
| 7321 |
bt( |
| 7322 |
'function bindAuthEvent(eventName) {\n' + |
| 7323 |
' self.auth.on(eventName, function(event, meta) {\n' + |
| 7324 |
' self.emit(eventName, event, meta);\n' + |
| 7325 |
' });\n' + |
| 7326 |
'}\n' + |
| 7327 |
'["logged_in", "logged_out", "signed_up", "updated_user"].forEach(bindAuthEvent);\n' + |
| 7328 |
'\n' + |
| 7329 |
'function bindBrowserEvent(eventName) {\n' + |
| 7330 |
' browser.on(eventName, function(event, meta) {\n' + |
| 7331 |
' self.emit(eventName, event, meta);\n' + |
| 7332 |
' });\n' + |
| 7333 |
'}\n' + |
| 7334 |
'["navigating"].forEach(bindBrowserEvent);') |
| 7335 |
|
| 7336 |
# Issue #892 - new line between chained methods |
| 7337 |
bt( |
| 7338 |
'foo\n' + |
| 7339 |
' .who()\n' + |
| 7340 |
'\n' + |
| 7341 |
' .knows()\n' + |
| 7342 |
' // comment\n' + |
| 7343 |
' .nothing() // comment\n' + |
| 7344 |
'\n' + |
| 7345 |
' .more()') |
| 7346 |
|
| 7347 |
# Issue #1107 - Missing space between words for label |
| 7348 |
bt( |
| 7349 |
'function f(a) {c: do if (x) {} else if (y) {} while(0); return 0;}', |
| 7350 |
# -- output -- |
| 7351 |
'function f(a) {\n' + |
| 7352 |
' c: do\n' + |
| 7353 |
' if (x) {} else if (y) {}\n' + |
| 7354 |
' while (0);\n' + |
| 7355 |
' return 0;\n' + |
| 7356 |
'}') |
| 7357 |
bt( |
| 7358 |
'function f(a) {c: if (x) {} else if (y) {} return 0;}', |
| 7359 |
# -- output -- |
| 7360 |
'function f(a) {\n' + |
| 7361 |
' c: if (x) {} else if (y) {}\n' + |
| 7362 |
' return 0;\n' + |
| 7363 |
'}') |
| 7364 |
|
| 7365 |
|
| 7366 |
#============================================================ |
| 7367 |
# Test non-positionable-ops |
| 7368 |
self.reset_options() |
| 7369 |
bt('a += 2;') |
| 7370 |
bt('a -= 2;') |
| 7371 |
bt('a *= 2;') |
| 7372 |
bt('a /= 2;') |
| 7373 |
bt('a %= 2;') |
| 7374 |
bt('a &= 2;') |
| 7375 |
bt('a ^= 2;') |
| 7376 |
bt('a |= 2;') |
| 7377 |
bt('a **= 2;') |
| 7378 |
bt('a <<= 2;') |
| 7379 |
bt('a >>= 2;') |
| 7380 |
|
| 7381 |
|
| 7382 |
#============================================================ |
| 7383 |
# |
| 7384 |
self.reset_options() |
| 7385 |
|
| 7386 |
# exponent literals |
| 7387 |
bt('a = 1e10') |
| 7388 |
bt('a = 1.3e10') |
| 7389 |
bt('a = 1.3e-10') |
| 7390 |
bt('a = -12345.3e-10') |
| 7391 |
bt('a = .12345e-10') |
| 7392 |
bt('a = 06789e-10') |
| 7393 |
bt('a = e - 10') |
| 7394 |
bt('a = 1.3e+10') |
| 7395 |
bt('a = 1.e-7') |
| 7396 |
bt('a = -12345.3e+10') |
| 7397 |
bt('a = .12345e+10') |
| 7398 |
bt('a = 06789e+10') |
| 7399 |
bt('a = e + 10') |
| 7400 |
bt('a=0e-12345.3e-10', 'a = 0e-12345 .3e-10') |
| 7401 |
bt('a=0.e-12345.3e-10', 'a = 0.e-12345 .3e-10') |
| 7402 |
bt('a=0x.e-12345.3e-10', 'a = 0x.e - 12345.3e-10') |
| 7403 |
bt('a=0x0.e-12345.3e-10', 'a = 0x0.e - 12345.3e-10') |
| 7404 |
bt('a=0x0.0e-12345.3e-10', 'a = 0x0 .0e-12345 .3e-10') |
| 7405 |
bt('a=0g-12345.3e-10', 'a = 0 g - 12345.3e-10') |
| 7406 |
bt('a=0.g-12345.3e-10', 'a = 0. g - 12345.3e-10') |
| 7407 |
bt('a=0x.g-12345.3e-10', 'a = 0x.g - 12345.3e-10') |
| 7408 |
bt('a=0x0.g-12345.3e-10', 'a = 0x0.g - 12345.3e-10') |
| 7409 |
bt('a=0x0.0g-12345.3e-10', 'a = 0x0 .0 g - 12345.3e-10') |
| 7410 |
|
| 7411 |
# exponent literals with underscore |
| 7412 |
bt('a = 1_1e10') |
| 7413 |
bt('a = 1_.3e10') |
| 7414 |
bt('a = 1_1.3e10') |
| 7415 |
bt('a = 1__1.3e10') |
| 7416 |
bt('a = 1._3e10') |
| 7417 |
bt('a = 1.3_e10') |
| 7418 |
bt('a = 1.3e_10') |
| 7419 |
bt('a = 1.3e1_0') |
| 7420 |
bt('a = 1.3e10_') |
| 7421 |
|
| 7422 |
# Decimal literals |
| 7423 |
bt('a = 0123456789;') |
| 7424 |
bt('a = 9876543210;') |
| 7425 |
bt('a = 5647308291;') |
| 7426 |
bt('a=030e-5', 'a = 030e-5') |
| 7427 |
bt('a=00+4', 'a = 00 + 4') |
| 7428 |
bt('a=32+4', 'a = 32 + 4') |
| 7429 |
bt('a=0.6g+4', 'a = 0.6 g + 4') |
| 7430 |
bt('a=01.10', 'a = 01.10') |
| 7431 |
bt('a=a.10', 'a = a .10') |
| 7432 |
bt('a=00B0x0', 'a = 00 B0x0') |
| 7433 |
bt('a=00B0xb0', 'a = 00 B0xb0') |
| 7434 |
bt('a=00B0x0b0', 'a = 00 B0x0b0') |
| 7435 |
bt('a=0090x0', 'a = 0090 x0') |
| 7436 |
bt('a=0g0b0o0', 'a = 0 g0b0o0') |
| 7437 |
|
| 7438 |
# Decimal literals with underscore |
| 7439 |
bt('a = 0_123456789') |
| 7440 |
bt('a = 0__123456789') |
| 7441 |
bt('a = 0__') |
| 7442 |
bt('a = 0_1_2_3') |
| 7443 |
bt('a = 0_1_2_3_') |
| 7444 |
|
| 7445 |
# Hexadecimal literals |
| 7446 |
bt('a = 0x0123456789abcdef;') |
| 7447 |
bt('a = 0X0123456789ABCDEF;') |
| 7448 |
bt('a = 0xFeDcBa9876543210;') |
| 7449 |
bt('a=0x30e-5', 'a = 0x30e - 5') |
| 7450 |
bt('a=0xF0+4', 'a = 0xF0 + 4') |
| 7451 |
bt('a=0Xff+4', 'a = 0Xff + 4') |
| 7452 |
bt('a=0Xffg+4', 'a = 0Xff g + 4') |
| 7453 |
bt('a=0x01.10', 'a = 0x01 .10') |
| 7454 |
bt('a = 0xb0ce;') |
| 7455 |
bt('a = 0x0b0;') |
| 7456 |
bt('a=0x0B0x0', 'a = 0x0B0 x0') |
| 7457 |
bt('a=0x0B0xb0', 'a = 0x0B0 xb0') |
| 7458 |
bt('a=0x0B0x0b0', 'a = 0x0B0 x0b0') |
| 7459 |
bt('a=0X090x0', 'a = 0X090 x0') |
| 7460 |
bt('a=0Xg0b0o0', 'a = 0X g0b0o0') |
| 7461 |
|
| 7462 |
# Hexadecimal literals with underscore |
| 7463 |
bt('a = 0x0_123456789abcdef') |
| 7464 |
bt('a = 0x0__0123456789abcdef') |
| 7465 |
bt('a = 0x_0123456789abcdef') |
| 7466 |
bt('a = 0x__') |
| 7467 |
bt('a = 0x0_1_a_3') |
| 7468 |
bt('a = 0x_1_2_F_') |
| 7469 |
|
| 7470 |
# Octal literals |
| 7471 |
bt('a = 0o01234567;') |
| 7472 |
bt('a = 0O01234567;') |
| 7473 |
bt('a = 0o34120675;') |
| 7474 |
bt('a=0o30e-5', 'a = 0o30 e - 5') |
| 7475 |
bt('a=0o70+4', 'a = 0o70 + 4') |
| 7476 |
bt('a=0O77+4', 'a = 0O77 + 4') |
| 7477 |
bt('a=0O778+4', 'a = 0O77 8 + 4') |
| 7478 |
bt('a=0O77a+4', 'a = 0O77 a + 4') |
| 7479 |
bt('a=0o01.10', 'a = 0o01 .10') |
| 7480 |
bt('a=0o0B0x0', 'a = 0o0 B0x0') |
| 7481 |
bt('a=0o0B0xb0', 'a = 0o0 B0xb0') |
| 7482 |
bt('a=0o0B0x0b0', 'a = 0o0 B0x0b0') |
| 7483 |
bt('a=0O090x0', 'a = 0O0 90 x0') |
| 7484 |
bt('a=0Og0b0o0', 'a = 0O g0b0o0') |
| 7485 |
|
| 7486 |
# Octal literals with underscore |
| 7487 |
bt('a = 0o0_1234567') |
| 7488 |
bt('a = 0o0__1234567') |
| 7489 |
bt('a = 0o_01234567') |
| 7490 |
bt('a = 0o__') |
| 7491 |
bt('a = 0o0_1_2_3') |
| 7492 |
bt('a = 0o_1_2_3_') |
| 7493 |
|
| 7494 |
# Binary literals |
| 7495 |
bt('a = 0b010011;') |
| 7496 |
bt('a = 0B010011;') |
| 7497 |
bt('a = 0b01001100001111;') |
| 7498 |
bt('a=0b10e-5', 'a = 0b10 e - 5') |
| 7499 |
bt('a=0b10+4', 'a = 0b10 + 4') |
| 7500 |
bt('a=0B11+4', 'a = 0B11 + 4') |
| 7501 |
bt('a=0B112+4', 'a = 0B11 2 + 4') |
| 7502 |
bt('a=0B11a+4', 'a = 0B11 a + 4') |
| 7503 |
bt('a=0b01.10', 'a = 0b01 .10') |
| 7504 |
bt('a=0b0B0x0', 'a = 0b0 B0x0') |
| 7505 |
bt('a=0b0B0xb0', 'a = 0b0 B0xb0') |
| 7506 |
bt('a=0b0B0x0b0', 'a = 0b0 B0x0b0') |
| 7507 |
bt('a=0B090x0', 'a = 0B0 90 x0') |
| 7508 |
bt('a=0Bg0b0o0', 'a = 0B g0b0o0') |
| 7509 |
|
| 7510 |
# Binary literals with underscore |
| 7511 |
bt('a = 0b0_10011') |
| 7512 |
bt('a = 0b0__10011') |
| 7513 |
bt('a = 0b_010011') |
| 7514 |
bt('a = 0b__') |
| 7515 |
bt('a = 0b0_1_1_1') |
| 7516 |
bt('a = 0b_1_0_1_') |
| 7517 |
bt('a = 0B010_0_11;') |
| 7518 |
bt('a = 0b01_0011_0000_1111;') |
| 7519 |
|
| 7520 |
# BigInt literals |
| 7521 |
bt('a = 1n;') |
| 7522 |
bt('a = 1234567890123456789n;') |
| 7523 |
bt('a = -1234567890123456789n;') |
| 7524 |
bt('a = 1234567890123456789 N;') |
| 7525 |
bt('a=0b10e-5n', 'a = 0b10 e - 5n') |
| 7526 |
bt('a=.0n', 'a = .0 n') |
| 7527 |
bt('a=1.0n', 'a = 1.0 n') |
| 7528 |
bt('a=1e0n', 'a = 1e0 n') |
| 7529 |
bt('a=0n11a+4', 'a = 0n 11 a + 4') |
| 7530 |
|
| 7531 |
# BigInt literals with underscore |
| 7532 |
bt('a = 0_123456789n') |
| 7533 |
bt('a = 0__123456789n') |
| 7534 |
bt('a = 0__n') |
| 7535 |
bt('a = 0_1_2_3n') |
| 7536 |
bt('a = 0_1_2_3_n') |
| 7537 |
|
| 7538 |
# BigInt hexadecimal literals |
| 7539 |
bt('a = 0x0123456789abcdefn;') |
| 7540 |
bt('a = 0X0123456789ABCDEFn;') |
| 7541 |
bt('a = 0xFeDcBa9876543210n;') |
| 7542 |
bt('a=0x30en-5', 'a = 0x30en - 5') |
| 7543 |
bt('a=0xF0n+4', 'a = 0xF0n + 4') |
| 7544 |
bt('a=0Xffn+4', 'a = 0Xffn + 4') |
| 7545 |
bt('a=0Xffng+4', 'a = 0Xffn g + 4') |
| 7546 |
bt('a=0x01n.10', 'a = 0x01n .10') |
| 7547 |
bt('a = 0xb0cen;') |
| 7548 |
bt('a = 0x0b0n;') |
| 7549 |
bt('a=0x0B0nx0', 'a = 0x0B0n x0') |
| 7550 |
bt('a=0x0B0nxb0', 'a = 0x0B0n xb0') |
| 7551 |
bt('a=0x0B0nx0b0', 'a = 0x0B0n x0b0') |
| 7552 |
bt('a=0X090nx0', 'a = 0X090n x0') |
| 7553 |
|
| 7554 |
# BigInt hexadecimal literals with underscore |
| 7555 |
bt('a = 0x0_123456789abcdefn') |
| 7556 |
bt('a = 0x0__0123456789abcdefn') |
| 7557 |
bt('a = 0x_0123456789abcdefn') |
| 7558 |
bt('a = 0x__n') |
| 7559 |
bt('a = 0x0_1_a_3n') |
| 7560 |
bt('a = 0x_1_2_F_n') |
| 7561 |
|
| 7562 |
# BigInt octal literals |
| 7563 |
bt('a = 0o01234567n;') |
| 7564 |
bt('a = 0O01234567n;') |
| 7565 |
bt('a = 0o34120675n;') |
| 7566 |
bt('a=0o30ne-5', 'a = 0o30n e - 5') |
| 7567 |
bt('a=0o70n+4', 'a = 0o70n + 4') |
| 7568 |
bt('a=0O77n+4', 'a = 0O77n + 4') |
| 7569 |
bt('a=0O77n8+4', 'a = 0O77n 8 + 4') |
| 7570 |
bt('a=0O77na+4', 'a = 0O77n a + 4') |
| 7571 |
bt('a=0o01n.10', 'a = 0o01n .10') |
| 7572 |
bt('a=0o0nB0x0', 'a = 0o0n B0x0') |
| 7573 |
bt('a=0o0nB0xb0', 'a = 0o0n B0xb0') |
| 7574 |
bt('a=0o0nB0x0b0', 'a = 0o0n B0x0b0') |
| 7575 |
bt('a=0O0n90x0', 'a = 0O0n 90 x0') |
| 7576 |
|
| 7577 |
# BigInt octal literals with underscore |
| 7578 |
bt('a = 0o0_1234567n') |
| 7579 |
bt('a = 0o0__1234567n') |
| 7580 |
bt('a = 0o_01234567n') |
| 7581 |
bt('a = 0o__n') |
| 7582 |
bt('a = 0o0_1_2_3n') |
| 7583 |
bt('a = 0o_1_2_3_n') |
| 7584 |
|
| 7585 |
# BigInt binary literals |
| 7586 |
bt('a = 0b010011n;') |
| 7587 |
bt('a = 0B010011n;') |
| 7588 |
bt('a = 0b01001100001111n;') |
| 7589 |
bt('a=0b10ne-5', 'a = 0b10n e - 5') |
| 7590 |
bt('a=0b10n+4', 'a = 0b10n + 4') |
| 7591 |
bt('a=0B11n+4', 'a = 0B11n + 4') |
| 7592 |
bt('a=0B11n2+4', 'a = 0B11n 2 + 4') |
| 7593 |
bt('a=0B11na+4', 'a = 0B11n a + 4') |
| 7594 |
bt('a=0b01n.10', 'a = 0b01n .10') |
| 7595 |
bt('a=0b0nB0x0', 'a = 0b0n B0x0') |
| 7596 |
bt('a=0b0nB0xb0', 'a = 0b0n B0xb0') |
| 7597 |
bt('a=0b0nB0x0b0', 'a = 0b0n B0x0b0') |
| 7598 |
bt('a=0B0n90x0', 'a = 0B0n 90 x0') |
| 7599 |
|
| 7600 |
# BigInt binary literals with underscore |
| 7601 |
bt('a = 0b0_10011n') |
| 7602 |
bt('a = 0b0__10011n') |
| 7603 |
bt('a = 0b_010011') |
| 7604 |
bt('a = 0b__n') |
| 7605 |
bt('a = 0b0_1_1_1n') |
| 7606 |
bt('a = 0b_1_0_1_n') |
| 7607 |
bt('a = 0B010_0_11n;') |
| 7608 |
bt('a = 0b01_0011_0000_1111n;') |
| 7609 |
|
| 7610 |
|
| 7611 |
#============================================================ |
| 7612 |
# brace_style ,preserve-inline tests - (brace_style = ""collapse,preserve-inline"") |
| 7613 |
self.reset_options() |
| 7614 |
self.options.brace_style = 'collapse,preserve-inline' |
| 7615 |
bt('import { asdf } from "asdf";') |
| 7616 |
bt('import { get } from "asdf";') |
| 7617 |
bt('function inLine() { console.log("oh em gee"); }') |
| 7618 |
bt('if (cancer) { console.log("Im sorry but you only have so long to live..."); }') |
| 7619 |
bt('if (ding) { console.log("dong"); } else { console.log("dang"); }') |
| 7620 |
bt( |
| 7621 |
'function kindaComplex() {\n' + |
| 7622 |
' var a = 2;\n' + |
| 7623 |
' var obj = {};\n' + |
| 7624 |
' var obj2 = { a: "a", b: "b" };\n' + |
| 7625 |
' var obj3 = {\n' + |
| 7626 |
' c: "c",\n' + |
| 7627 |
' d: "d",\n' + |
| 7628 |
' e: "e"\n' + |
| 7629 |
' };\n' + |
| 7630 |
'}') |
| 7631 |
bt( |
| 7632 |
'function complex() {\n' + |
| 7633 |
' console.log("wowe");\n' + |
| 7634 |
' (function() { var a = 2; var b = 3; })();\n' + |
| 7635 |
' $.each(arr, function(el, idx) { return el; });\n' + |
| 7636 |
' var obj = {\n' + |
| 7637 |
' a: function() { console.log("test"); },\n' + |
| 7638 |
' b() {\n' + |
| 7639 |
' console.log("test2");\n' + |
| 7640 |
' }\n' + |
| 7641 |
' };\n' + |
| 7642 |
'}', |
| 7643 |
# -- output -- |
| 7644 |
'function complex() {\n' + |
| 7645 |
' console.log("wowe");\n' + |
| 7646 |
' (function() { var a = 2; var b = 3; })();\n' + |
| 7647 |
' $.each(arr, function(el, idx) { return el; });\n' + |
| 7648 |
' var obj = {\n' + |
| 7649 |
' a: function() { console.log("test"); },\n' + |
| 7650 |
' b() {\n' + |
| 7651 |
' console.log("test2");\n' + |
| 7652 |
' }\n' + |
| 7653 |
' };\n' + |
| 7654 |
'}') |
| 7655 |
|
| 7656 |
# brace_style ,preserve-inline tests - (brace_style = ""expand,preserve-inline"") |
| 7657 |
self.reset_options() |
| 7658 |
self.options.brace_style = 'expand,preserve-inline' |
| 7659 |
bt('import { asdf } from "asdf";') |
| 7660 |
bt('import { get } from "asdf";') |
| 7661 |
bt('function inLine() { console.log("oh em gee"); }') |
| 7662 |
bt('if (cancer) { console.log("Im sorry but you only have so long to live..."); }') |
| 7663 |
bt( |
| 7664 |
'if (ding) { console.log("dong"); } else { console.log("dang"); }', |
| 7665 |
# -- output -- |
| 7666 |
'if (ding) { console.log("dong"); }\n' + |
| 7667 |
'else { console.log("dang"); }') |
| 7668 |
bt( |
| 7669 |
'function kindaComplex() {\n' + |
| 7670 |
' var a = 2;\n' + |
| 7671 |
' var obj = {};\n' + |
| 7672 |
' var obj2 = { a: "a", b: "b" };\n' + |
| 7673 |
' var obj3 = {\n' + |
| 7674 |
' c: "c",\n' + |
| 7675 |
' d: "d",\n' + |
| 7676 |
' e: "e"\n' + |
| 7677 |
' };\n' + |
| 7678 |
'}', |
| 7679 |
# -- output -- |
| 7680 |
'function kindaComplex()\n' + |
| 7681 |
'{\n' + |
| 7682 |
' var a = 2;\n' + |
| 7683 |
' var obj = {};\n' + |
| 7684 |
' var obj2 = { a: "a", b: "b" };\n' + |
| 7685 |
' var obj3 = {\n' + |
| 7686 |
' c: "c",\n' + |
| 7687 |
' d: "d",\n' + |
| 7688 |
' e: "e"\n' + |
| 7689 |
' };\n' + |
| 7690 |
'}') |
| 7691 |
bt( |
| 7692 |
'function complex() {\n' + |
| 7693 |
' console.log("wowe");\n' + |
| 7694 |
' (function() { var a = 2; var b = 3; })();\n' + |
| 7695 |
' $.each(arr, function(el, idx) { return el; });\n' + |
| 7696 |
' var obj = {\n' + |
| 7697 |
' a: function() { console.log("test"); },\n' + |
| 7698 |
' b() {\n' + |
| 7699 |
' console.log("test2");\n' + |
| 7700 |
' }\n' + |
| 7701 |
' };\n' + |
| 7702 |
'}', |
| 7703 |
# -- output -- |
| 7704 |
'function complex()\n' + |
| 7705 |
'{\n' + |
| 7706 |
' console.log("wowe");\n' + |
| 7707 |
' (function() { var a = 2; var b = 3; })();\n' + |
| 7708 |
' $.each(arr, function(el, idx) { return el; });\n' + |
| 7709 |
' var obj = {\n' + |
| 7710 |
' a: function() { console.log("test"); },\n' + |
| 7711 |
' b()\n' + |
| 7712 |
' {\n' + |
| 7713 |
' console.log("test2");\n' + |
| 7714 |
' }\n' + |
| 7715 |
' };\n' + |
| 7716 |
'}') |
| 7717 |
|
| 7718 |
# brace_style ,preserve-inline tests - (brace_style = ""end-expand,preserve-inline"") |
| 7719 |
self.reset_options() |
| 7720 |
self.options.brace_style = 'end-expand,preserve-inline' |
| 7721 |
bt('import { asdf } from "asdf";') |
| 7722 |
bt('import { get } from "asdf";') |
| 7723 |
bt('function inLine() { console.log("oh em gee"); }') |
| 7724 |
bt('if (cancer) { console.log("Im sorry but you only have so long to live..."); }') |
| 7725 |
bt( |
| 7726 |
'if (ding) { console.log("dong"); } else { console.log("dang"); }', |
| 7727 |
# -- output -- |
| 7728 |
'if (ding) { console.log("dong"); }\n' + |
| 7729 |
'else { console.log("dang"); }') |
| 7730 |
bt( |
| 7731 |
'function kindaComplex() {\n' + |
| 7732 |
' var a = 2;\n' + |
| 7733 |
' var obj = {};\n' + |
| 7734 |
' var obj2 = { a: "a", b: "b" };\n' + |
| 7735 |
' var obj3 = {\n' + |
| 7736 |
' c: "c",\n' + |
| 7737 |
' d: "d",\n' + |
| 7738 |
' e: "e"\n' + |
| 7739 |
' };\n' + |
| 7740 |
'}') |
| 7741 |
bt( |
| 7742 |
'function complex() {\n' + |
| 7743 |
' console.log("wowe");\n' + |
| 7744 |
' (function() { var a = 2; var b = 3; })();\n' + |
| 7745 |
' $.each(arr, function(el, idx) { return el; });\n' + |
| 7746 |
' var obj = {\n' + |
| 7747 |
' a: function() { console.log("test"); },\n' + |
| 7748 |
' b() {\n' + |
| 7749 |
' console.log("test2");\n' + |
| 7750 |
' }\n' + |
| 7751 |
' };\n' + |
| 7752 |
'}', |
| 7753 |
# -- output -- |
| 7754 |
'function complex() {\n' + |
| 7755 |
' console.log("wowe");\n' + |
| 7756 |
' (function() { var a = 2; var b = 3; })();\n' + |
| 7757 |
' $.each(arr, function(el, idx) { return el; });\n' + |
| 7758 |
' var obj = {\n' + |
| 7759 |
' a: function() { console.log("test"); },\n' + |
| 7760 |
' b() {\n' + |
| 7761 |
' console.log("test2");\n' + |
| 7762 |
' }\n' + |
| 7763 |
' };\n' + |
| 7764 |
'}') |
| 7765 |
|
| 7766 |
# brace_style ,preserve-inline tests - (brace_style = ""none,preserve-inline"") |
| 7767 |
self.reset_options() |
| 7768 |
self.options.brace_style = 'none,preserve-inline' |
| 7769 |
bt('import { asdf } from "asdf";') |
| 7770 |
bt('import { get } from "asdf";') |
| 7771 |
bt('function inLine() { console.log("oh em gee"); }') |
| 7772 |
bt('if (cancer) { console.log("Im sorry but you only have so long to live..."); }') |
| 7773 |
bt('if (ding) { console.log("dong"); } else { console.log("dang"); }') |
| 7774 |
bt( |
| 7775 |
'function kindaComplex() {\n' + |
| 7776 |
' var a = 2;\n' + |
| 7777 |
' var obj = {};\n' + |
| 7778 |
' var obj2 = { a: "a", b: "b" };\n' + |
| 7779 |
' var obj3 = {\n' + |
| 7780 |
' c: "c",\n' + |
| 7781 |
' d: "d",\n' + |
| 7782 |
' e: "e"\n' + |
| 7783 |
' };\n' + |
| 7784 |
'}') |
| 7785 |
bt( |
| 7786 |
'function complex() {\n' + |
| 7787 |
' console.log("wowe");\n' + |
| 7788 |
' (function() { var a = 2; var b = 3; })();\n' + |
| 7789 |
' $.each(arr, function(el, idx) { return el; });\n' + |
| 7790 |
' var obj = {\n' + |
| 7791 |
' a: function() { console.log("test"); },\n' + |
| 7792 |
' b() {\n' + |
| 7793 |
' console.log("test2");\n' + |
| 7794 |
' }\n' + |
| 7795 |
' };\n' + |
| 7796 |
'}', |
| 7797 |
# -- output -- |
| 7798 |
'function complex() {\n' + |
| 7799 |
' console.log("wowe");\n' + |
| 7800 |
' (function() { var a = 2; var b = 3; })();\n' + |
| 7801 |
' $.each(arr, function(el, idx) { return el; });\n' + |
| 7802 |
' var obj = {\n' + |
| 7803 |
' a: function() { console.log("test"); },\n' + |
| 7804 |
' b() {\n' + |
| 7805 |
' console.log("test2");\n' + |
| 7806 |
' }\n' + |
| 7807 |
' };\n' + |
| 7808 |
'}') |
| 7809 |
|
| 7810 |
# brace_style ,preserve-inline tests - (brace_style = ""collapse-preserve-inline"") |
| 7811 |
self.reset_options() |
| 7812 |
self.options.brace_style = 'collapse-preserve-inline' |
| 7813 |
bt('import { asdf } from "asdf";') |
| 7814 |
bt('import { get } from "asdf";') |
| 7815 |
bt('function inLine() { console.log("oh em gee"); }') |
| 7816 |
bt('if (cancer) { console.log("Im sorry but you only have so long to live..."); }') |
| 7817 |
bt('if (ding) { console.log("dong"); } else { console.log("dang"); }') |
| 7818 |
bt( |
| 7819 |
'function kindaComplex() {\n' + |
| 7820 |
' var a = 2;\n' + |
| 7821 |
' var obj = {};\n' + |
| 7822 |
' var obj2 = { a: "a", b: "b" };\n' + |
| 7823 |
' var obj3 = {\n' + |
| 7824 |
' c: "c",\n' + |
| 7825 |
' d: "d",\n' + |
| 7826 |
' e: "e"\n' + |
| 7827 |
' };\n' + |
| 7828 |
'}') |
| 7829 |
bt( |
| 7830 |
'function complex() {\n' + |
| 7831 |
' console.log("wowe");\n' + |
| 7832 |
' (function() { var a = 2; var b = 3; })();\n' + |
| 7833 |
' $.each(arr, function(el, idx) { return el; });\n' + |
| 7834 |
' var obj = {\n' + |
| 7835 |
' a: function() { console.log("test"); },\n' + |
| 7836 |
' b() {\n' + |
| 7837 |
' console.log("test2");\n' + |
| 7838 |
' }\n' + |
| 7839 |
' };\n' + |
| 7840 |
'}', |
| 7841 |
# -- output -- |
| 7842 |
'function complex() {\n' + |
| 7843 |
' console.log("wowe");\n' + |
| 7844 |
' (function() { var a = 2; var b = 3; })();\n' + |
| 7845 |
' $.each(arr, function(el, idx) { return el; });\n' + |
| 7846 |
' var obj = {\n' + |
| 7847 |
' a: function() { console.log("test"); },\n' + |
| 7848 |
' b() {\n' + |
| 7849 |
' console.log("test2");\n' + |
| 7850 |
' }\n' + |
| 7851 |
' };\n' + |
| 7852 |
'}') |
| 7853 |
|
| 7854 |
|
| 7855 |
#============================================================ |
| 7856 |
# Destructured and related |
| 7857 |
self.reset_options() |
| 7858 |
self.options.brace_style = 'collapse,preserve-inline' |
| 7859 |
|
| 7860 |
# Issue 382 - import destructured |
| 7861 |
bt( |
| 7862 |
'module "Even" {\n' + |
| 7863 |
' import { odd, oddly } from "Odd";\n' + |
| 7864 |
'}') |
| 7865 |
bt( |
| 7866 |
'import defaultMember from "module-name";\n' + |
| 7867 |
'import * as name from "module-name";\n' + |
| 7868 |
'import { member } from "module-name";\n' + |
| 7869 |
'import { member as alias } from "module-name";\n' + |
| 7870 |
'import { member1, member2 } from "module-name";\n' + |
| 7871 |
'import { member1, member2 as alias2 } from "module-name";\n' + |
| 7872 |
'import defaultMember, { member, member2 } from "module-name";\n' + |
| 7873 |
'import defaultMember, * as name from "module-name";\n' + |
| 7874 |
'import "module-name";\n' + |
| 7875 |
'import("module-name")') |
| 7876 |
|
| 7877 |
# Issue #1393 - dynamic import() |
| 7878 |
bt( |
| 7879 |
'if (from < to) {\n' + |
| 7880 |
' import(`dynamic${library}`);\n' + |
| 7881 |
'} else {\n' + |
| 7882 |
' import("otherdynamic");\n' + |
| 7883 |
'}') |
| 7884 |
|
| 7885 |
# Issue #1197 - dynamic import() arrow syntax |
| 7886 |
bt('frontend = Async(() => import("../frontend").then(m => m.default ))', 'frontend = Async(() => import("../frontend").then(m => m.default))') |
| 7887 |
|
| 7888 |
# Issue #1978 - import.meta syntax support |
| 7889 |
bt('let x = import.meta', 'let x = import.meta') |
| 7890 |
|
| 7891 |
# Issue 858 - from is a keyword only after import |
| 7892 |
bt( |
| 7893 |
'if (from < to) {\n' + |
| 7894 |
' from++;\n' + |
| 7895 |
'} else {\n' + |
| 7896 |
' from--;\n' + |
| 7897 |
'}') |
| 7898 |
|
| 7899 |
# Issue 511 - destrutured |
| 7900 |
bt( |
| 7901 |
'var { b, c } = require("../stores");\n' + |
| 7902 |
'var { ProjectStore } = require("../stores");\n' + |
| 7903 |
'\n' + |
| 7904 |
'function takeThing({ prop }) {\n' + |
| 7905 |
' console.log("inner prop", prop)\n' + |
| 7906 |
'}') |
| 7907 |
|
| 7908 |
# Issue 315 - Short objects |
| 7909 |
bt('var a = { b: { c: { d: e } } };') |
| 7910 |
bt( |
| 7911 |
'var a = {\n' + |
| 7912 |
' b: {\n' + |
| 7913 |
' c: { d: e }\n' + |
| 7914 |
' c3: { d: e }\n' + |
| 7915 |
' },\n' + |
| 7916 |
' b2: { c: { d: e } }\n' + |
| 7917 |
'};') |
| 7918 |
|
| 7919 |
# Issue 370 - Short objects in array |
| 7920 |
bt( |
| 7921 |
'var methods = [\n' + |
| 7922 |
' { name: "to" },\n' + |
| 7923 |
' { name: "step" },\n' + |
| 7924 |
' { name: "move" },\n' + |
| 7925 |
' { name: "min" },\n' + |
| 7926 |
' { name: "max" }\n' + |
| 7927 |
'];') |
| 7928 |
|
| 7929 |
# Issue 838 - Short objects in array |
| 7930 |
bt( |
| 7931 |
'function(url, callback) {\n' + |
| 7932 |
' var script = document.createElement("script")\n' + |
| 7933 |
' if (true) script.onreadystatechange = function() {\n' + |
| 7934 |
' foo();\n' + |
| 7935 |
' }\n' + |
| 7936 |
' else script.onload = callback;\n' + |
| 7937 |
'}') |
| 7938 |
|
| 7939 |
# Issue 578 - Odd indenting after function |
| 7940 |
bt( |
| 7941 |
'function bindAuthEvent(eventName) {\n' + |
| 7942 |
' self.auth.on(eventName, function(event, meta) {\n' + |
| 7943 |
' self.emit(eventName, event, meta);\n' + |
| 7944 |
' });\n' + |
| 7945 |
'}\n' + |
| 7946 |
'["logged_in", "logged_out", "signed_up", "updated_user"].forEach(bindAuthEvent);') |
| 7947 |
|
| 7948 |
# Issue #487 - some short expressions examples |
| 7949 |
bt( |
| 7950 |
'if (a == 1) { a++; }\n' + |
| 7951 |
'a = { a: a };\n' + |
| 7952 |
'UserDB.findOne({ username: "xyz" }, function(err, user) {});\n' + |
| 7953 |
'import { fs } from "fs";') |
| 7954 |
|
| 7955 |
# Issue #982 - Fixed return expression collapse-preserve-inline |
| 7956 |
bt( |
| 7957 |
'function foo(arg) {\n' + |
| 7958 |
' if (!arg) { a(); }\n' + |
| 7959 |
' if (!arg) { return false; }\n' + |
| 7960 |
' if (!arg) { throw "inline"; }\n' + |
| 7961 |
' return true;\n' + |
| 7962 |
'}') |
| 7963 |
|
| 7964 |
# Issue #338 - Short expressions |
| 7965 |
bt( |
| 7966 |
'if (someCondition) { return something; }\n' + |
| 7967 |
'if (someCondition) {\n' + |
| 7968 |
' return something;\n' + |
| 7969 |
'}\n' + |
| 7970 |
'if (someCondition) { break; }\n' + |
| 7971 |
'if (someCondition) {\n' + |
| 7972 |
' return something;\n' + |
| 7973 |
'}') |
| 7974 |
|
| 7975 |
# Issue #1283 - Javascript ++ Operator get wrong indent |
| 7976 |
bt( |
| 7977 |
'{this.foo++\n' + |
| 7978 |
'bar}', |
| 7979 |
# -- output -- |
| 7980 |
'{\n' + |
| 7981 |
' this.foo++\n' + |
| 7982 |
' bar\n' + |
| 7983 |
'}') |
| 7984 |
|
| 7985 |
# Issue #1283 - Javascript ++ Operator get wrong indent (2) |
| 7986 |
bt( |
| 7987 |
'axios.interceptors.request.use(\n' + |
| 7988 |
' config => {\n' + |
| 7989 |
' // loading\n' + |
| 7990 |
' window.store.loading++\n' + |
| 7991 |
' let extraParams = {}\n' + |
| 7992 |
' }\n' + |
| 7993 |
')') |
| 7994 |
|
| 7995 |
# Issue ##1846 - in keyword in class method causes indentation problem |
| 7996 |
bt( |
| 7997 |
'class {\n' + |
| 7998 |
' get a() {\n' + |
| 7999 |
'\n' + |
| 8000 |
'\n' + |
| 8001 |
' }\n' + |
| 8002 |
'\n' + |
| 8003 |
'\n' + |
| 8004 |
' in() {\n' + |
| 8005 |
'\n' + |
| 8006 |
'\n' + |
| 8007 |
' }\n' + |
| 8008 |
'\n' + |
| 8009 |
'\n' + |
| 8010 |
' b() {\n' + |
| 8011 |
'\n' + |
| 8012 |
'\n' + |
| 8013 |
' }\n' + |
| 8014 |
'}', |
| 8015 |
# -- output -- |
| 8016 |
'class {\n' + |
| 8017 |
' get a() {\n' + |
| 8018 |
'\n' + |
| 8019 |
'\n' + |
| 8020 |
' }\n' + |
| 8021 |
'\n' + |
| 8022 |
'\n' + |
| 8023 |
' in() {\n' + |
| 8024 |
'\n' + |
| 8025 |
'\n' + |
| 8026 |
' }\n' + |
| 8027 |
'\n' + |
| 8028 |
'\n' + |
| 8029 |
' b() {\n' + |
| 8030 |
'\n' + |
| 8031 |
'\n' + |
| 8032 |
' }\n' + |
| 8033 |
'}') |
| 8034 |
|
| 8035 |
# Related to Issue ##1846 - Do not indent 'in' keyword if not a class method |
| 8036 |
bt( |
| 8037 |
'function test() {\n' + |
| 8038 |
'for x in nums {}\n' + |
| 8039 |
'"make" in car\n' + |
| 8040 |
'3 in number;\n' + |
| 8041 |
'}', |
| 8042 |
# -- output -- |
| 8043 |
'function test() {\n' + |
| 8044 |
' for x in nums {}\n' + |
| 8045 |
' "make" in car\n' + |
| 8046 |
' 3 in number;\n' + |
| 8047 |
'}') |
| 8048 |
|
| 8049 |
# Related to Issue ##1846 - of keyword in class method causes indentation problem |
| 8050 |
bt( |
| 8051 |
'class {\n' + |
| 8052 |
' get a() {\n' + |
| 8053 |
'\n' + |
| 8054 |
'\n' + |
| 8055 |
' }\n' + |
| 8056 |
'\n' + |
| 8057 |
'\n' + |
| 8058 |
' of() {\n' + |
| 8059 |
'\n' + |
| 8060 |
'\n' + |
| 8061 |
' }\n' + |
| 8062 |
'\n' + |
| 8063 |
'\n' + |
| 8064 |
' b() {\n' + |
| 8065 |
'\n' + |
| 8066 |
'\n' + |
| 8067 |
' }\n' + |
| 8068 |
'}', |
| 8069 |
# -- output -- |
| 8070 |
'class {\n' + |
| 8071 |
' get a() {\n' + |
| 8072 |
'\n' + |
| 8073 |
'\n' + |
| 8074 |
' }\n' + |
| 8075 |
'\n' + |
| 8076 |
'\n' + |
| 8077 |
' of() {\n' + |
| 8078 |
'\n' + |
| 8079 |
'\n' + |
| 8080 |
' }\n' + |
| 8081 |
'\n' + |
| 8082 |
'\n' + |
| 8083 |
' b() {\n' + |
| 8084 |
'\n' + |
| 8085 |
'\n' + |
| 8086 |
' }\n' + |
| 8087 |
'}') |
| 8088 |
|
| 8089 |
# Issue #1950: Do not remove whitespace after number - test scenario: number before a dot |
| 8090 |
bt('1000000000000001000 .toFixed(0)!==1000000000000001024', '1000000000000001000 .toFixed(0) !== 1000000000000001024') |
| 8091 |
|
| 8092 |
# Issue #1950: Do not remove whitespace after number - test scenario: variable ends with a number before a dot |
| 8093 |
bt('a.b21 . performAction()', 'a.b21.performAction()') |
| 8094 |
|
| 8095 |
|
| 8096 |
#============================================================ |
| 8097 |
# keep_array_indentation false |
| 8098 |
self.reset_options() |
| 8099 |
self.options.keep_array_indentation = false |
| 8100 |
bt( |
| 8101 |
'a = ["a", "b", "c",\n' + |
| 8102 |
' "d", "e", "f"]', |
| 8103 |
# -- output -- |
| 8104 |
'a = ["a", "b", "c",\n' + |
| 8105 |
' "d", "e", "f"\n' + |
| 8106 |
']') |
| 8107 |
bt( |
| 8108 |
'a = ["a", "b", "c",\n' + |
| 8109 |
' "d", "e", "f",\n' + |
| 8110 |
' "g", "h", "i"]', |
| 8111 |
# -- output -- |
| 8112 |
'a = ["a", "b", "c",\n' + |
| 8113 |
' "d", "e", "f",\n' + |
| 8114 |
' "g", "h", "i"\n' + |
| 8115 |
']') |
| 8116 |
bt( |
| 8117 |
'a = ["a", "b", "c",\n' + |
| 8118 |
' "d", "e", "f",\n' + |
| 8119 |
' "g", "h", "i"]', |
| 8120 |
# -- output -- |
| 8121 |
'a = ["a", "b", "c",\n' + |
| 8122 |
' "d", "e", "f",\n' + |
| 8123 |
' "g", "h", "i"\n' + |
| 8124 |
']') |
| 8125 |
bt( |
| 8126 |
'var x = [{}\n' + |
| 8127 |
']', |
| 8128 |
# -- output -- |
| 8129 |
'var x = [{}]') |
| 8130 |
bt( |
| 8131 |
'var x = [{foo:bar}\n' + |
| 8132 |
']', |
| 8133 |
# -- output -- |
| 8134 |
'var x = [{\n' + |
| 8135 |
' foo: bar\n' + |
| 8136 |
'}]') |
| 8137 |
bt( |
| 8138 |
'a = ["something",\n' + |
| 8139 |
' "completely",\n' + |
| 8140 |
' "different"];\n' + |
| 8141 |
'if (x);', |
| 8142 |
# -- output -- |
| 8143 |
'a = ["something",\n' + |
| 8144 |
' "completely",\n' + |
| 8145 |
' "different"\n' + |
| 8146 |
'];\n' + |
| 8147 |
'if (x);') |
| 8148 |
bt('a = ["a","b","c"]', 'a = ["a", "b", "c"]') |
| 8149 |
bt('a = ["a", "b","c"]', 'a = ["a", "b", "c"]') |
| 8150 |
bt( |
| 8151 |
'x = [{"a":0}]', |
| 8152 |
# -- output -- |
| 8153 |
'x = [{\n' + |
| 8154 |
' "a": 0\n' + |
| 8155 |
'}]') |
| 8156 |
bt( |
| 8157 |
'{a([[a1]], {b;});}', |
| 8158 |
# -- output -- |
| 8159 |
'{\n' + |
| 8160 |
' a([\n' + |
| 8161 |
' [a1]\n' + |
| 8162 |
' ], {\n' + |
| 8163 |
' b;\n' + |
| 8164 |
' });\n' + |
| 8165 |
'}') |
| 8166 |
bt( |
| 8167 |
'a ();\n' + |
| 8168 |
' [\n' + |
| 8169 |
' ["sdfsdfsd"],\n' + |
| 8170 |
' ["sdfsdfsdf"]\n' + |
| 8171 |
' ].toString();', |
| 8172 |
# -- output -- |
| 8173 |
'a();\n' + |
| 8174 |
'[\n' + |
| 8175 |
' ["sdfsdfsd"],\n' + |
| 8176 |
' ["sdfsdfsdf"]\n' + |
| 8177 |
'].toString();') |
| 8178 |
bt( |
| 8179 |
'a ();\n' + |
| 8180 |
'a = [\n' + |
| 8181 |
' ["sdfsdfsd"],\n' + |
| 8182 |
' ["sdfsdfsdf"]\n' + |
| 8183 |
' ].toString();', |
| 8184 |
# -- output -- |
| 8185 |
'a();\n' + |
| 8186 |
'a = [\n' + |
| 8187 |
' ["sdfsdfsd"],\n' + |
| 8188 |
' ["sdfsdfsdf"]\n' + |
| 8189 |
'].toString();') |
| 8190 |
bt( |
| 8191 |
'function() {\n' + |
| 8192 |
' Foo([\n' + |
| 8193 |
' ["sdfsdfsd"],\n' + |
| 8194 |
' ["sdfsdfsdf"]\n' + |
| 8195 |
' ]);\n' + |
| 8196 |
'}', |
| 8197 |
# -- output -- |
| 8198 |
'function() {\n' + |
| 8199 |
' Foo([\n' + |
| 8200 |
' ["sdfsdfsd"],\n' + |
| 8201 |
' ["sdfsdfsdf"]\n' + |
| 8202 |
' ]);\n' + |
| 8203 |
'}') |
| 8204 |
bt( |
| 8205 |
'function foo() {\n' + |
| 8206 |
' return [\n' + |
| 8207 |
' "one",\n' + |
| 8208 |
' "two"\n' + |
| 8209 |
' ];\n' + |
| 8210 |
'}', |
| 8211 |
# -- output -- |
| 8212 |
'function foo() {\n' + |
| 8213 |
' return [\n' + |
| 8214 |
' "one",\n' + |
| 8215 |
' "two"\n' + |
| 8216 |
' ];\n' + |
| 8217 |
'}') |
| 8218 |
bt( |
| 8219 |
'function foo() {\n' + |
| 8220 |
' return [\n' + |
| 8221 |
' {\n' + |
| 8222 |
' one: "x",\n' + |
| 8223 |
' two: [\n' + |
| 8224 |
' {\n' + |
| 8225 |
' id: "a",\n' + |
| 8226 |
' name: "apple"\n' + |
| 8227 |
' }, {\n' + |
| 8228 |
' id: "b",\n' + |
| 8229 |
' name: "banana"\n' + |
| 8230 |
' }\n' + |
| 8231 |
' ]\n' + |
| 8232 |
' }\n' + |
| 8233 |
' ];\n' + |
| 8234 |
'}', |
| 8235 |
# -- output -- |
| 8236 |
'function foo() {\n' + |
| 8237 |
' return [{\n' + |
| 8238 |
' one: "x",\n' + |
| 8239 |
' two: [{\n' + |
| 8240 |
' id: "a",\n' + |
| 8241 |
' name: "apple"\n' + |
| 8242 |
' }, {\n' + |
| 8243 |
' id: "b",\n' + |
| 8244 |
' name: "banana"\n' + |
| 8245 |
' }]\n' + |
| 8246 |
' }];\n' + |
| 8247 |
'}') |
| 8248 |
bt( |
| 8249 |
'function foo() {\n' + |
| 8250 |
' return [\n' + |
| 8251 |
' {\n' + |
| 8252 |
' one: "x",\n' + |
| 8253 |
' two: [\n' + |
| 8254 |
' {\n' + |
| 8255 |
' id: "a",\n' + |
| 8256 |
' name: "apple"\n' + |
| 8257 |
' }, {\n' + |
| 8258 |
' id: "b",\n' + |
| 8259 |
' name: "banana"\n' + |
| 8260 |
' }\n' + |
| 8261 |
' ]\n' + |
| 8262 |
' }\n' + |
| 8263 |
' ];\n' + |
| 8264 |
'}', |
| 8265 |
# -- output -- |
| 8266 |
'function foo() {\n' + |
| 8267 |
' return [{\n' + |
| 8268 |
' one: "x",\n' + |
| 8269 |
' two: [{\n' + |
| 8270 |
' id: "a",\n' + |
| 8271 |
' name: "apple"\n' + |
| 8272 |
' }, {\n' + |
| 8273 |
' id: "b",\n' + |
| 8274 |
' name: "banana"\n' + |
| 8275 |
' }]\n' + |
| 8276 |
' }];\n' + |
| 8277 |
'}') |
| 8278 |
|
| 8279 |
|
| 8280 |
#============================================================ |
| 8281 |
# keep_array_indentation true |
| 8282 |
self.reset_options() |
| 8283 |
self.options.keep_array_indentation = true |
| 8284 |
bt( |
| 8285 |
'a = ["a", "b", "c",\n' + |
| 8286 |
' "d", "e", "f"]', |
| 8287 |
# -- output -- |
| 8288 |
'a = ["a", "b", "c",\n' + |
| 8289 |
' "d", "e", "f"]') |
| 8290 |
bt( |
| 8291 |
'a = ["a", "b", "c",\n' + |
| 8292 |
' "d", "e", "f",\n' + |
| 8293 |
' "g", "h", "i"]', |
| 8294 |
# -- output -- |
| 8295 |
'a = ["a", "b", "c",\n' + |
| 8296 |
' "d", "e", "f",\n' + |
| 8297 |
' "g", "h", "i"]') |
| 8298 |
bt( |
| 8299 |
'a = ["a", "b", "c",\n' + |
| 8300 |
' "d", "e", "f",\n' + |
| 8301 |
' "g", "h", "i"]', |
| 8302 |
# -- output -- |
| 8303 |
'a = ["a", "b", "c",\n' + |
| 8304 |
' "d", "e", "f",\n' + |
| 8305 |
' "g", "h", "i"]') |
| 8306 |
bt( |
| 8307 |
'var x = [{}\n' + |
| 8308 |
']', |
| 8309 |
# -- output -- |
| 8310 |
'var x = [{}\n' + |
| 8311 |
']') |
| 8312 |
bt( |
| 8313 |
'var x = [{foo:bar}\n' + |
| 8314 |
']', |
| 8315 |
# -- output -- |
| 8316 |
'var x = [{\n' + |
| 8317 |
' foo: bar\n' + |
| 8318 |
' }\n' + |
| 8319 |
']') |
| 8320 |
bt( |
| 8321 |
'a = ["something",\n' + |
| 8322 |
' "completely",\n' + |
| 8323 |
' "different"];\n' + |
| 8324 |
'if (x);', |
| 8325 |
# -- output -- |
| 8326 |
'a = ["something",\n' + |
| 8327 |
' "completely",\n' + |
| 8328 |
' "different"];\n' + |
| 8329 |
'if (x);') |
| 8330 |
bt('a = ["a","b","c"]', 'a = ["a", "b", "c"]') |
| 8331 |
bt('a = ["a", "b","c"]', 'a = ["a", "b", "c"]') |
| 8332 |
bt( |
| 8333 |
'x = [{"a":0}]', |
| 8334 |
# -- output -- |
| 8335 |
'x = [{\n' + |
| 8336 |
' "a": 0\n' + |
| 8337 |
'}]') |
| 8338 |
bt( |
| 8339 |
'{a([[a1]], {b;});}', |
| 8340 |
# -- output -- |
| 8341 |
'{\n' + |
| 8342 |
' a([[a1]], {\n' + |
| 8343 |
' b;\n' + |
| 8344 |
' });\n' + |
| 8345 |
'}') |
| 8346 |
bt( |
| 8347 |
'a ();\n' + |
| 8348 |
' [\n' + |
| 8349 |
' ["sdfsdfsd"],\n' + |
| 8350 |
' ["sdfsdfsdf"]\n' + |
| 8351 |
' ].toString();', |
| 8352 |
# -- output -- |
| 8353 |
'a();\n' + |
| 8354 |
' [\n' + |
| 8355 |
' ["sdfsdfsd"],\n' + |
| 8356 |
' ["sdfsdfsdf"]\n' + |
| 8357 |
' ].toString();') |
| 8358 |
bt( |
| 8359 |
'a ();\n' + |
| 8360 |
'a = [\n' + |
| 8361 |
' ["sdfsdfsd"],\n' + |
| 8362 |
' ["sdfsdfsdf"]\n' + |
| 8363 |
' ].toString();', |
| 8364 |
# -- output -- |
| 8365 |
'a();\n' + |
| 8366 |
'a = [\n' + |
| 8367 |
' ["sdfsdfsd"],\n' + |
| 8368 |
' ["sdfsdfsdf"]\n' + |
| 8369 |
' ].toString();') |
| 8370 |
bt( |
| 8371 |
'function() {\n' + |
| 8372 |
' Foo([\n' + |
| 8373 |
' ["sdfsdfsd"],\n' + |
| 8374 |
' ["sdfsdfsdf"]\n' + |
| 8375 |
' ]);\n' + |
| 8376 |
'}', |
| 8377 |
# -- output -- |
| 8378 |
'function() {\n' + |
| 8379 |
' Foo([\n' + |
| 8380 |
' ["sdfsdfsd"],\n' + |
| 8381 |
' ["sdfsdfsdf"]\n' + |
| 8382 |
' ]);\n' + |
| 8383 |
'}') |
| 8384 |
bt( |
| 8385 |
'function foo() {\n' + |
| 8386 |
' return [\n' + |
| 8387 |
' "one",\n' + |
| 8388 |
' "two"\n' + |
| 8389 |
' ];\n' + |
| 8390 |
'}', |
| 8391 |
# -- output -- |
| 8392 |
'function foo() {\n' + |
| 8393 |
' return [\n' + |
| 8394 |
' "one",\n' + |
| 8395 |
' "two"\n' + |
| 8396 |
' ];\n' + |
| 8397 |
'}') |
| 8398 |
bt( |
| 8399 |
'function foo() {\n' + |
| 8400 |
' return [\n' + |
| 8401 |
' {\n' + |
| 8402 |
' one: "x",\n' + |
| 8403 |
' two: [\n' + |
| 8404 |
' {\n' + |
| 8405 |
' id: "a",\n' + |
| 8406 |
' name: "apple"\n' + |
| 8407 |
' }, {\n' + |
| 8408 |
' id: "b",\n' + |
| 8409 |
' name: "banana"\n' + |
| 8410 |
' }\n' + |
| 8411 |
' ]\n' + |
| 8412 |
' }\n' + |
| 8413 |
' ];\n' + |
| 8414 |
'}', |
| 8415 |
# -- output -- |
| 8416 |
'function foo() {\n' + |
| 8417 |
' return [\n' + |
| 8418 |
' {\n' + |
| 8419 |
' one: "x",\n' + |
| 8420 |
' two: [\n' + |
| 8421 |
' {\n' + |
| 8422 |
' id: "a",\n' + |
| 8423 |
' name: "apple"\n' + |
| 8424 |
' }, {\n' + |
| 8425 |
' id: "b",\n' + |
| 8426 |
' name: "banana"\n' + |
| 8427 |
' }\n' + |
| 8428 |
' ]\n' + |
| 8429 |
' }\n' + |
| 8430 |
' ];\n' + |
| 8431 |
'}') |
| 8432 |
|
| 8433 |
|
| 8434 |
#============================================================ |
| 8435 |
# indent_empty_lines true |
| 8436 |
self.reset_options() |
| 8437 |
self.options.indent_empty_lines = true |
| 8438 |
test_fragment( |
| 8439 |
'var a = 1;\n' + |
| 8440 |
'\n' + |
| 8441 |
'var b = 1;') |
| 8442 |
test_fragment( |
| 8443 |
'var a = 1;\n' + |
| 8444 |
' \n' + |
| 8445 |
'var b = 1;', |
| 8446 |
# -- output -- |
| 8447 |
'var a = 1;\n' + |
| 8448 |
'\n' + |
| 8449 |
'var b = 1;') |
| 8450 |
test_fragment( |
| 8451 |
'{\n' + |
| 8452 |
' var a = 1;\n' + |
| 8453 |
' \n' + |
| 8454 |
' var b = 1;\n' + |
| 8455 |
'\n' + |
| 8456 |
'}', |
| 8457 |
# -- output -- |
| 8458 |
'{\n' + |
| 8459 |
' var a = 1;\n' + |
| 8460 |
' \n' + |
| 8461 |
' var b = 1;\n' + |
| 8462 |
' \n' + |
| 8463 |
'}') |
| 8464 |
test_fragment( |
| 8465 |
'{\n' + |
| 8466 |
'\n' + |
| 8467 |
' var a = 1;\n' + |
| 8468 |
'\n' + |
| 8469 |
'\n' + |
| 8470 |
'\n' + |
| 8471 |
' var b = 1;\n' + |
| 8472 |
'\n' + |
| 8473 |
'}', |
| 8474 |
# -- output -- |
| 8475 |
'{\n' + |
| 8476 |
' \n' + |
| 8477 |
' var a = 1;\n' + |
| 8478 |
' \n' + |
| 8479 |
' \n' + |
| 8480 |
' \n' + |
| 8481 |
' var b = 1;\n' + |
| 8482 |
' \n' + |
| 8483 |
'}') |
| 8484 |
test_fragment( |
| 8485 |
'{\n' + |
| 8486 |
'\n' + |
| 8487 |
' var a = 1;\n' + |
| 8488 |
'\n' + |
| 8489 |
'function A() {\n' + |
| 8490 |
'\n' + |
| 8491 |
'}\n' + |
| 8492 |
'\n' + |
| 8493 |
' var b = 1;\n' + |
| 8494 |
'\n' + |
| 8495 |
'}', |
| 8496 |
# -- output -- |
| 8497 |
'{\n' + |
| 8498 |
' \n' + |
| 8499 |
' var a = 1;\n' + |
| 8500 |
' \n' + |
| 8501 |
' function A() {\n' + |
| 8502 |
' \n' + |
| 8503 |
' }\n' + |
| 8504 |
' \n' + |
| 8505 |
' var b = 1;\n' + |
| 8506 |
' \n' + |
| 8507 |
'}') |
| 8508 |
|
| 8509 |
|
| 8510 |
#============================================================ |
| 8511 |
# indent_empty_lines false |
| 8512 |
self.reset_options() |
| 8513 |
self.options.indent_empty_lines = false |
| 8514 |
test_fragment( |
| 8515 |
'var a = 1;\n' + |
| 8516 |
'\n' + |
| 8517 |
'var b = 1;') |
| 8518 |
test_fragment( |
| 8519 |
'var a = 1;\n' + |
| 8520 |
' \n' + |
| 8521 |
'var b = 1;', |
| 8522 |
# -- output -- |
| 8523 |
'var a = 1;\n' + |
| 8524 |
'\n' + |
| 8525 |
'var b = 1;') |
| 8526 |
test_fragment( |
| 8527 |
'{\n' + |
| 8528 |
' var a = 1;\n' + |
| 8529 |
' \n' + |
| 8530 |
' var b = 1;\n' + |
| 8531 |
'\n' + |
| 8532 |
'}', |
| 8533 |
# -- output -- |
| 8534 |
'{\n' + |
| 8535 |
' var a = 1;\n' + |
| 8536 |
'\n' + |
| 8537 |
' var b = 1;\n' + |
| 8538 |
'\n' + |
| 8539 |
'}') |
| 8540 |
test_fragment( |
| 8541 |
'{\n' + |
| 8542 |
'\n' + |
| 8543 |
' var a = 1;\n' + |
| 8544 |
'\n' + |
| 8545 |
'\n' + |
| 8546 |
'\n' + |
| 8547 |
' var b = 1;\n' + |
| 8548 |
'\n' + |
| 8549 |
'}') |
| 8550 |
test_fragment( |
| 8551 |
'{\n' + |
| 8552 |
'\n' + |
| 8553 |
' var a = 1;\n' + |
| 8554 |
'\n' + |
| 8555 |
'function A() {\n' + |
| 8556 |
'\n' + |
| 8557 |
'}\n' + |
| 8558 |
'\n' + |
| 8559 |
' var b = 1;\n' + |
| 8560 |
'\n' + |
| 8561 |
'}', |
| 8562 |
# -- output -- |
| 8563 |
'{\n' + |
| 8564 |
'\n' + |
| 8565 |
' var a = 1;\n' + |
| 8566 |
'\n' + |
| 8567 |
' function A() {\n' + |
| 8568 |
'\n' + |
| 8569 |
' }\n' + |
| 8570 |
'\n' + |
| 8571 |
' var b = 1;\n' + |
| 8572 |
'\n' + |
| 8573 |
'}') |
| 8574 |
|
| 8575 |
|
| 8576 |
#============================================================ |
| 8577 |
# Record data type |
| 8578 |
self.reset_options() |
| 8579 |
|
| 8580 |
# regular record with primitive |
| 8581 |
bt( |
| 8582 |
'a = #{ b:"c", d:1, e:true };', |
| 8583 |
# -- output -- |
| 8584 |
'a = #{\n' + |
| 8585 |
' b: "c",\n' + |
| 8586 |
' d: 1,\n' + |
| 8587 |
' e: true\n' + |
| 8588 |
'};') |
| 8589 |
|
| 8590 |
# nested record |
| 8591 |
bt( |
| 8592 |
'a = #{b:#{ c:1,d:2,}, e:"f"};', |
| 8593 |
# -- output -- |
| 8594 |
'a = #{\n' + |
| 8595 |
' b: #{\n' + |
| 8596 |
' c: 1,\n' + |
| 8597 |
' d: 2,\n' + |
| 8598 |
' },\n' + |
| 8599 |
' e: "f"\n' + |
| 8600 |
'};') |
| 8601 |
|
| 8602 |
# # not directly followed by { is not handled as record |
| 8603 |
bt( |
| 8604 |
'a = # {\n' + |
| 8605 |
' b: 1,\n' + |
| 8606 |
' d: true\n' + |
| 8607 |
'};') |
| 8608 |
|
| 8609 |
# example of already valid and beautified record |
| 8610 |
bt( |
| 8611 |
'a = #{\n' + |
| 8612 |
' b: 1,\n' + |
| 8613 |
' d: true\n' + |
| 8614 |
'};') |
| 8615 |
|
| 8616 |
|
| 8617 |
#============================================================ |
| 8618 |
# Old tests |
| 8619 |
self.reset_options() |
| 8620 |
bt('') |
| 8621 |
test_fragment(' return .5') |
| 8622 |
test_fragment( |
| 8623 |
' return .5;\n' + |
| 8624 |
' a();') |
| 8625 |
test_fragment( |
| 8626 |
' return .5;\n' + |
| 8627 |
' a();') |
| 8628 |
test_fragment( |
| 8629 |
' return .5;\n' + |
| 8630 |
' a();') |
| 8631 |
test_fragment(' < div') |
| 8632 |
bt('a = 1', 'a = 1') |
| 8633 |
bt('a=1', 'a = 1') |
| 8634 |
bt('(3) / 2') |
| 8635 |
bt('["a", "b"].join("")') |
| 8636 |
bt( |
| 8637 |
'a();\n' + |
| 8638 |
'\n' + |
| 8639 |
'b();') |
| 8640 |
bt( |
| 8641 |
'var a = 1 var b = 2', |
| 8642 |
# -- output -- |
| 8643 |
'var a = 1\n' + |
| 8644 |
'var b = 2') |
| 8645 |
bt( |
| 8646 |
'var a=1, b=c[d], e=6;', |
| 8647 |
# -- output -- |
| 8648 |
'var a = 1,\n' + |
| 8649 |
' b = c[d],\n' + |
| 8650 |
' e = 6;') |
| 8651 |
bt( |
| 8652 |
'var a,\n' + |
| 8653 |
' b,\n' + |
| 8654 |
' c;') |
| 8655 |
bt( |
| 8656 |
'let a = 1 let b = 2', |
| 8657 |
# -- output -- |
| 8658 |
'let a = 1\n' + |
| 8659 |
'let b = 2') |
| 8660 |
bt( |
| 8661 |
'let a=1, b=c[d], e=6;', |
| 8662 |
# -- output -- |
| 8663 |
'let a = 1,\n' + |
| 8664 |
' b = c[d],\n' + |
| 8665 |
' e = 6;') |
| 8666 |
bt( |
| 8667 |
'let a,\n' + |
| 8668 |
' b,\n' + |
| 8669 |
' c;') |
| 8670 |
bt( |
| 8671 |
'const a = 1 const b = 2', |
| 8672 |
# -- output -- |
| 8673 |
'const a = 1\n' + |
| 8674 |
'const b = 2') |
| 8675 |
bt( |
| 8676 |
'const a=1, b=c[d], e=6;', |
| 8677 |
# -- output -- |
| 8678 |
'const a = 1,\n' + |
| 8679 |
' b = c[d],\n' + |
| 8680 |
' e = 6;') |
| 8681 |
bt( |
| 8682 |
'const a,\n' + |
| 8683 |
' b,\n' + |
| 8684 |
' c;') |
| 8685 |
bt('a = " 12345 "') |
| 8686 |
bt('a = \' 12345 \'') |
| 8687 |
bt('if (a == 1) b = 2;') |
| 8688 |
bt( |
| 8689 |
'if(1){2}else{3}', |
| 8690 |
# -- output -- |
| 8691 |
'if (1) {\n' + |
| 8692 |
' 2\n' + |
| 8693 |
'} else {\n' + |
| 8694 |
' 3\n' + |
| 8695 |
'}') |
| 8696 |
bt('if(1||2);', 'if (1 || 2);') |
| 8697 |
bt('(a==1)||(b==2)', '(a == 1) || (b == 2)') |
| 8698 |
bt( |
| 8699 |
'var a = 1 if (2) 3;', |
| 8700 |
# -- output -- |
| 8701 |
'var a = 1\n' + |
| 8702 |
'if (2) 3;') |
| 8703 |
bt('a = a + 1') |
| 8704 |
bt('a = a == 1') |
| 8705 |
bt('/12345[^678]*9+/.match(a)') |
| 8706 |
bt('a /= 5') |
| 8707 |
bt('a = 0.5 * 3') |
| 8708 |
bt('a *= 10.55') |
| 8709 |
bt('a < .5') |
| 8710 |
bt('a <= .5') |
| 8711 |
bt('a<.5', 'a < .5') |
| 8712 |
bt('a<=.5', 'a <= .5') |
| 8713 |
bt('a = [1, 2, 3, 4]') |
| 8714 |
bt('F*(g/=f)*g+b', 'F * (g /= f) * g + b') |
| 8715 |
bt( |
| 8716 |
'a.b({c:d})', |
| 8717 |
# -- output -- |
| 8718 |
'a.b({\n' + |
| 8719 |
' c: d\n' + |
| 8720 |
'})') |
| 8721 |
bt( |
| 8722 |
'a.b\n' + |
| 8723 |
'(\n' + |
| 8724 |
'{\n' + |
| 8725 |
'c:\n' + |
| 8726 |
'd\n' + |
| 8727 |
'}\n' + |
| 8728 |
')', |
| 8729 |
# -- output -- |
| 8730 |
'a.b({\n' + |
| 8731 |
' c: d\n' + |
| 8732 |
'})') |
| 8733 |
bt( |
| 8734 |
'a.b({c:"d"})', |
| 8735 |
# -- output -- |
| 8736 |
'a.b({\n' + |
| 8737 |
' c: "d"\n' + |
| 8738 |
'})') |
| 8739 |
bt( |
| 8740 |
'a.b\n' + |
| 8741 |
'(\n' + |
| 8742 |
'{\n' + |
| 8743 |
'c:\n' + |
| 8744 |
'"d"\n' + |
| 8745 |
'}\n' + |
| 8746 |
')', |
| 8747 |
# -- output -- |
| 8748 |
'a.b({\n' + |
| 8749 |
' c: "d"\n' + |
| 8750 |
'})') |
| 8751 |
bt('a=!b', 'a = !b') |
| 8752 |
bt('a=!!b', 'a = !!b') |
| 8753 |
bt('a?b:c', 'a ? b : c') |
| 8754 |
bt('a?1:2', 'a ? 1 : 2') |
| 8755 |
bt('a?(b):c', 'a ? (b) : c') |
| 8756 |
bt( |
| 8757 |
'x={a:1,b:w=="foo"?x:y,c:z}', |
| 8758 |
# -- output -- |
| 8759 |
'x = {\n' + |
| 8760 |
' a: 1,\n' + |
| 8761 |
' b: w == "foo" ? x : y,\n' + |
| 8762 |
' c: z\n' + |
| 8763 |
'}') |
| 8764 |
bt('x=a?b?c?d:e:f:g;', 'x = a ? b ? c ? d : e : f : g;') |
| 8765 |
bt( |
| 8766 |
'x=a?b?c?d:{e1:1,e2:2}:f:g;', |
| 8767 |
# -- output -- |
| 8768 |
'x = a ? b ? c ? d : {\n' + |
| 8769 |
' e1: 1,\n' + |
| 8770 |
' e2: 2\n' + |
| 8771 |
'} : f : g;') |
| 8772 |
bt('function void(void) {}') |
| 8773 |
bt('if(!a)foo();', 'if (!a) foo();') |
| 8774 |
bt('a=~a', 'a = ~a') |
| 8775 |
bt( |
| 8776 |
'a;/*comment*/b;', |
| 8777 |
# -- output -- |
| 8778 |
'a; /*comment*/\n' + |
| 8779 |
'b;') |
| 8780 |
bt( |
| 8781 |
'a;/* comment */b;', |
| 8782 |
# -- output -- |
| 8783 |
'a; /* comment */\n' + |
| 8784 |
'b;') |
| 8785 |
|
| 8786 |
# simple comments don't get touched at all |
| 8787 |
test_fragment( |
| 8788 |
'a;/*\n' + |
| 8789 |
'comment\n' + |
| 8790 |
'*/b;', |
| 8791 |
# -- output -- |
| 8792 |
'a;\n' + |
| 8793 |
'/*\n' + |
| 8794 |
'comment\n' + |
| 8795 |
'*/\n' + |
| 8796 |
'b;') |
| 8797 |
bt( |
| 8798 |
'a;/**\n' + |
| 8799 |
'* javadoc\n' + |
| 8800 |
'*/b;', |
| 8801 |
# -- output -- |
| 8802 |
'a;\n' + |
| 8803 |
'/**\n' + |
| 8804 |
' * javadoc\n' + |
| 8805 |
' */\n' + |
| 8806 |
'b;') |
| 8807 |
test_fragment( |
| 8808 |
'a;/**\n' + |
| 8809 |
'\n' + |
| 8810 |
'no javadoc\n' + |
| 8811 |
'*/b;', |
| 8812 |
# -- output -- |
| 8813 |
'a;\n' + |
| 8814 |
'/**\n' + |
| 8815 |
'\n' + |
| 8816 |
'no javadoc\n' + |
| 8817 |
'*/\n' + |
| 8818 |
'b;') |
| 8819 |
|
| 8820 |
# comment blocks detected and reindented even w/o javadoc starter |
| 8821 |
bt( |
| 8822 |
'a;/*\n' + |
| 8823 |
'* javadoc\n' + |
| 8824 |
'*/b;', |
| 8825 |
# -- output -- |
| 8826 |
'a;\n' + |
| 8827 |
'/*\n' + |
| 8828 |
' * javadoc\n' + |
| 8829 |
' */\n' + |
| 8830 |
'b;') |
| 8831 |
bt('if(a)break;', 'if (a) break;') |
| 8832 |
bt( |
| 8833 |
'if(a){break}', |
| 8834 |
# -- output -- |
| 8835 |
'if (a) {\n' + |
| 8836 |
' break\n' + |
| 8837 |
'}') |
| 8838 |
bt('if((a))foo();', 'if ((a)) foo();') |
| 8839 |
bt('for(var i=0;;) a', 'for (var i = 0;;) a') |
| 8840 |
bt( |
| 8841 |
'for(var i=0;;)\n' + |
| 8842 |
'a', |
| 8843 |
# -- output -- |
| 8844 |
'for (var i = 0;;)\n' + |
| 8845 |
' a') |
| 8846 |
bt('a++;') |
| 8847 |
bt('for(;;i++)a()', 'for (;; i++) a()') |
| 8848 |
bt( |
| 8849 |
'for(;;i++)\n' + |
| 8850 |
'a()', |
| 8851 |
# -- output -- |
| 8852 |
'for (;; i++)\n' + |
| 8853 |
' a()') |
| 8854 |
bt('for(;;++i)a', 'for (;; ++i) a') |
| 8855 |
bt('return(1)', 'return (1)') |
| 8856 |
bt( |
| 8857 |
'try{a();}catch(b){c();}finally{d();}', |
| 8858 |
# -- output -- |
| 8859 |
'try {\n' + |
| 8860 |
' a();\n' + |
| 8861 |
'} catch (b) {\n' + |
| 8862 |
' c();\n' + |
| 8863 |
'} finally {\n' + |
| 8864 |
' d();\n' + |
| 8865 |
'}') |
| 8866 |
|
| 8867 |
# magic function call |
| 8868 |
bt('(xx)()') |
| 8869 |
|
| 8870 |
# another magic function call |
| 8871 |
bt('a[1]()') |
| 8872 |
bt( |
| 8873 |
'if(a){b();}else if(c) foo();', |
| 8874 |
# -- output -- |
| 8875 |
'if (a) {\n' + |
| 8876 |
' b();\n' + |
| 8877 |
'} else if (c) foo();') |
| 8878 |
bt( |
| 8879 |
'switch(x) {case 0: case 1: a(); break; default: break}', |
| 8880 |
# -- output -- |
| 8881 |
'switch (x) {\n' + |
| 8882 |
' case 0:\n' + |
| 8883 |
' case 1:\n' + |
| 8884 |
' a();\n' + |
| 8885 |
' break;\n' + |
| 8886 |
' default:\n' + |
| 8887 |
' break\n' + |
| 8888 |
'}') |
| 8889 |
bt( |
| 8890 |
'switch(x) {default: case 1: a(); break; case 0: break}', |
| 8891 |
# -- output -- |
| 8892 |
'switch (x) {\n' + |
| 8893 |
' default:\n' + |
| 8894 |
' case 1:\n' + |
| 8895 |
' a();\n' + |
| 8896 |
' break;\n' + |
| 8897 |
' case 0:\n' + |
| 8898 |
' break\n' + |
| 8899 |
'}') |
| 8900 |
bt( |
| 8901 |
'switch(x){case -1:break;case !y:break;}', |
| 8902 |
# -- output -- |
| 8903 |
'switch (x) {\n' + |
| 8904 |
' case -1:\n' + |
| 8905 |
' break;\n' + |
| 8906 |
' case !y:\n' + |
| 8907 |
' break;\n' + |
| 8908 |
'}') |
| 8909 |
bt('a !== b') |
| 8910 |
bt( |
| 8911 |
'if (a) b(); else c();', |
| 8912 |
# -- output -- |
| 8913 |
'if (a) b();\n' + |
| 8914 |
'else c();') |
| 8915 |
|
| 8916 |
# typical greasemonkey start |
| 8917 |
bt( |
| 8918 |
'// comment\n' + |
| 8919 |
'(function something() {})') |
| 8920 |
|
| 8921 |
# duplicating newlines |
| 8922 |
bt( |
| 8923 |
'{\n' + |
| 8924 |
'\n' + |
| 8925 |
' x();\n' + |
| 8926 |
'\n' + |
| 8927 |
'}') |
| 8928 |
bt('if (a in b) foo();') |
| 8929 |
bt('if (a of b) foo();') |
| 8930 |
bt('if (a of [1, 2, 3]) foo();') |
| 8931 |
bt( |
| 8932 |
'if(X)if(Y)a();else b();else c();', |
| 8933 |
# -- output -- |
| 8934 |
'if (X)\n' + |
| 8935 |
' if (Y) a();\n' + |
| 8936 |
' else b();\n' + |
| 8937 |
'else c();') |
| 8938 |
bt( |
| 8939 |
'if (foo) bar();\n' + |
| 8940 |
'else break') |
| 8941 |
bt('var a, b;') |
| 8942 |
bt('var a = new function();') |
| 8943 |
test_fragment('new function') |
| 8944 |
bt('var a, b') |
| 8945 |
bt( |
| 8946 |
'{a:1, b:2}', |
| 8947 |
# -- output -- |
| 8948 |
'{\n' + |
| 8949 |
' a: 1,\n' + |
| 8950 |
' b: 2\n' + |
| 8951 |
'}') |
| 8952 |
bt( |
| 8953 |
'a={1:[-1],2:[+1]}', |
| 8954 |
# -- output -- |
| 8955 |
'a = {\n' + |
| 8956 |
' 1: [-1],\n' + |
| 8957 |
' 2: [+1]\n' + |
| 8958 |
'}') |
| 8959 |
bt( |
| 8960 |
'var l = {\'a\':\'1\', \'b\':\'2\'}', |
| 8961 |
# -- output -- |
| 8962 |
'var l = {\n' + |
| 8963 |
' \'a\': \'1\',\n' + |
| 8964 |
' \'b\': \'2\'\n' + |
| 8965 |
'}') |
| 8966 |
bt('if (template.user[n] in bk) foo();') |
| 8967 |
bt('return 45') |
| 8968 |
bt( |
| 8969 |
'return this.prevObject ||\n' + |
| 8970 |
'\n' + |
| 8971 |
' this.constructor(null);') |
| 8972 |
bt('If[1]') |
| 8973 |
bt('Then[1]') |
| 8974 |
bt('a = 1;// comment', 'a = 1; // comment') |
| 8975 |
bt('a = 1; // comment') |
| 8976 |
bt( |
| 8977 |
'a = 1;\n' + |
| 8978 |
' // comment', |
| 8979 |
# -- output -- |
| 8980 |
'a = 1;\n' + |
| 8981 |
'// comment') |
| 8982 |
bt('a = [-1, -1, -1]') |
| 8983 |
bt( |
| 8984 |
'// a\n' + |
| 8985 |
'// b\n' + |
| 8986 |
'\n' + |
| 8987 |
'\n' + |
| 8988 |
'\n' + |
| 8989 |
'// c\n' + |
| 8990 |
'// d') |
| 8991 |
bt( |
| 8992 |
'// func-comment\n' + |
| 8993 |
'\n' + |
| 8994 |
'function foo() {}\n' + |
| 8995 |
'\n' + |
| 8996 |
'// end-func-comment') |
| 8997 |
|
| 8998 |
# The exact formatting these should have is open for discussion, but they are at least reasonable |
| 8999 |
bt( |
| 9000 |
'a = [ // comment\n' + |
| 9001 |
' -1, -1, -1\n' + |
| 9002 |
']') |
| 9003 |
bt( |
| 9004 |
'var a = [ // comment\n' + |
| 9005 |
' -1, -1, -1\n' + |
| 9006 |
']') |
| 9007 |
bt( |
| 9008 |
'a = [ // comment\n' + |
| 9009 |
' -1, // comment\n' + |
| 9010 |
' -1, -1\n' + |
| 9011 |
']') |
| 9012 |
bt( |
| 9013 |
'var a = [ // comment\n' + |
| 9014 |
' -1, // comment\n' + |
| 9015 |
' -1, -1\n' + |
| 9016 |
']') |
| 9017 |
bt( |
| 9018 |
'o = [{a:b},{c:d}]', |
| 9019 |
# -- output -- |
| 9020 |
'o = [{\n' + |
| 9021 |
' a: b\n' + |
| 9022 |
'}, {\n' + |
| 9023 |
' c: d\n' + |
| 9024 |
'}]') |
| 9025 |
|
| 9026 |
# was: extra space appended |
| 9027 |
bt( |
| 9028 |
'if (a) {\n' + |
| 9029 |
' do();\n' + |
| 9030 |
'}') |
| 9031 |
|
| 9032 |
# if/else statement with empty body |
| 9033 |
bt( |
| 9034 |
'if (a) {\n' + |
| 9035 |
'// comment\n' + |
| 9036 |
'}else{\n' + |
| 9037 |
'// comment\n' + |
| 9038 |
'}', |
| 9039 |
# -- output -- |
| 9040 |
'if (a) {\n' + |
| 9041 |
' // comment\n' + |
| 9042 |
'} else {\n' + |
| 9043 |
' // comment\n' + |
| 9044 |
'}') |
| 9045 |
|
| 9046 |
# multiple comments indentation |
| 9047 |
bt( |
| 9048 |
'if (a) {\n' + |
| 9049 |
'// comment\n' + |
| 9050 |
'// comment\n' + |
| 9051 |
'}', |
| 9052 |
# -- output -- |
| 9053 |
'if (a) {\n' + |
| 9054 |
' // comment\n' + |
| 9055 |
' // comment\n' + |
| 9056 |
'}') |
| 9057 |
bt( |
| 9058 |
'if (a) b() else c();', |
| 9059 |
# -- output -- |
| 9060 |
'if (a) b()\n' + |
| 9061 |
'else c();') |
| 9062 |
bt( |
| 9063 |
'if (a) b() else if c() d();', |
| 9064 |
# -- output -- |
| 9065 |
'if (a) b()\n' + |
| 9066 |
'else if c() d();') |
| 9067 |
bt('{}') |
| 9068 |
bt( |
| 9069 |
'{\n' + |
| 9070 |
'\n' + |
| 9071 |
'}') |
| 9072 |
bt( |
| 9073 |
'do { a(); } while ( 1 );', |
| 9074 |
# -- output -- |
| 9075 |
'do {\n' + |
| 9076 |
' a();\n' + |
| 9077 |
'} while (1);') |
| 9078 |
bt('do {} while (1);') |
| 9079 |
bt( |
| 9080 |
'do {\n' + |
| 9081 |
'} while (1);', |
| 9082 |
# -- output -- |
| 9083 |
'do {} while (1);') |
| 9084 |
bt( |
| 9085 |
'do {\n' + |
| 9086 |
'\n' + |
| 9087 |
'} while (1);') |
| 9088 |
bt('var a = x(a, b, c)') |
| 9089 |
bt( |
| 9090 |
'delete x if (a) b();', |
| 9091 |
# -- output -- |
| 9092 |
'delete x\n' + |
| 9093 |
'if (a) b();') |
| 9094 |
bt( |
| 9095 |
'delete x[x] if (a) b();', |
| 9096 |
# -- output -- |
| 9097 |
'delete x[x]\n' + |
| 9098 |
'if (a) b();') |
| 9099 |
bt('for(var a=1,b=2)d', 'for (var a = 1, b = 2) d') |
| 9100 |
bt('for(var a=1,b=2,c=3) d', 'for (var a = 1, b = 2, c = 3) d') |
| 9101 |
bt( |
| 9102 |
'for(var a=1,b=2,c=3;d<3;d++)\n' + |
| 9103 |
'e', |
| 9104 |
# -- output -- |
| 9105 |
'for (var a = 1, b = 2, c = 3; d < 3; d++)\n' + |
| 9106 |
' e') |
| 9107 |
bt( |
| 9108 |
'function x(){(a||b).c()}', |
| 9109 |
# -- output -- |
| 9110 |
'function x() {\n' + |
| 9111 |
' (a || b).c()\n' + |
| 9112 |
'}') |
| 9113 |
bt( |
| 9114 |
'function x(){return - 1}', |
| 9115 |
# -- output -- |
| 9116 |
'function x() {\n' + |
| 9117 |
' return -1\n' + |
| 9118 |
'}') |
| 9119 |
bt( |
| 9120 |
'function x(){return ! a}', |
| 9121 |
# -- output -- |
| 9122 |
'function x() {\n' + |
| 9123 |
' return !a\n' + |
| 9124 |
'}') |
| 9125 |
bt('x => x') |
| 9126 |
bt('(x) => x') |
| 9127 |
bt( |
| 9128 |
'x => { x }', |
| 9129 |
# -- output -- |
| 9130 |
'x => {\n' + |
| 9131 |
' x\n' + |
| 9132 |
'}') |
| 9133 |
bt( |
| 9134 |
'(x) => { x }', |
| 9135 |
# -- output -- |
| 9136 |
'(x) => {\n' + |
| 9137 |
' x\n' + |
| 9138 |
'}') |
| 9139 |
|
| 9140 |
# a common snippet in jQuery plugins |
| 9141 |
bt( |
| 9142 |
'settings = $.extend({},defaults,settings);', |
| 9143 |
# -- output -- |
| 9144 |
'settings = $.extend({}, defaults, settings);') |
| 9145 |
bt('$http().then().finally().default()') |
| 9146 |
bt( |
| 9147 |
'$http()\n' + |
| 9148 |
'.then()\n' + |
| 9149 |
'.finally()\n' + |
| 9150 |
'.default()', |
| 9151 |
# -- output -- |
| 9152 |
'$http()\n' + |
| 9153 |
' .then()\n' + |
| 9154 |
' .finally()\n' + |
| 9155 |
' .default()') |
| 9156 |
bt('$http().when.in.new.catch().throw()') |
| 9157 |
bt( |
| 9158 |
'$http()\n' + |
| 9159 |
'.when\n' + |
| 9160 |
'.in\n' + |
| 9161 |
'.new\n' + |
| 9162 |
'.catch()\n' + |
| 9163 |
'.throw()', |
| 9164 |
# -- output -- |
| 9165 |
'$http()\n' + |
| 9166 |
' .when\n' + |
| 9167 |
' .in\n' + |
| 9168 |
' .new\n' + |
| 9169 |
' .catch()\n' + |
| 9170 |
' .throw()') |
| 9171 |
bt( |
| 9172 |
'{xxx;}()', |
| 9173 |
# -- output -- |
| 9174 |
'{\n' + |
| 9175 |
' xxx;\n' + |
| 9176 |
'}()') |
| 9177 |
bt( |
| 9178 |
'a = \'a\'\n' + |
| 9179 |
'b = \'b\'') |
| 9180 |
bt('a = /reg/exp') |
| 9181 |
bt('a = /reg/') |
| 9182 |
bt('/abc/.test()') |
| 9183 |
bt('/abc/i.test()') |
| 9184 |
bt( |
| 9185 |
'{/abc/i.test()}', |
| 9186 |
# -- output -- |
| 9187 |
'{\n' + |
| 9188 |
' /abc/i.test()\n' + |
| 9189 |
'}') |
| 9190 |
bt('var x=(a)/a;', 'var x = (a) / a;') |
| 9191 |
bt('x != -1') |
| 9192 |
bt('for (; s-->0;)t', 'for (; s-- > 0;) t') |
| 9193 |
bt('for (; s++>0;)u', 'for (; s++ > 0;) u') |
| 9194 |
bt('a = s++>s--;', 'a = s++ > s--;') |
| 9195 |
bt('a = s++>--s;', 'a = s++ > --s;') |
| 9196 |
bt( |
| 9197 |
'{x=#1=[]}', |
| 9198 |
# -- output -- |
| 9199 |
'{\n' + |
| 9200 |
' x = #1=[]\n' + |
| 9201 |
'}') |
| 9202 |
bt( |
| 9203 |
'{a:#1={}}', |
| 9204 |
# -- output -- |
| 9205 |
'{\n' + |
| 9206 |
' a: #1={}\n' + |
| 9207 |
'}') |
| 9208 |
bt( |
| 9209 |
'{a:#1#}', |
| 9210 |
# -- output -- |
| 9211 |
'{\n' + |
| 9212 |
' a: #1#\n' + |
| 9213 |
'}') |
| 9214 |
test_fragment('"incomplete-string') |
| 9215 |
test_fragment('\'incomplete-string') |
| 9216 |
test_fragment('/incomplete-regex') |
| 9217 |
test_fragment('`incomplete-template-string') |
| 9218 |
test_fragment( |
| 9219 |
'{a:1},{a:2}', |
| 9220 |
# -- output -- |
| 9221 |
'{\n' + |
| 9222 |
' a: 1\n' + |
| 9223 |
'}, {\n' + |
| 9224 |
' a: 2\n' + |
| 9225 |
'}') |
| 9226 |
test_fragment( |
| 9227 |
'var ary=[{a:1}, {a:2}];', |
| 9228 |
# -- output -- |
| 9229 |
'var ary = [{\n' + |
| 9230 |
' a: 1\n' + |
| 9231 |
'}, {\n' + |
| 9232 |
' a: 2\n' + |
| 9233 |
'}];') |
| 9234 |
|
| 9235 |
# incomplete |
| 9236 |
test_fragment( |
| 9237 |
'{a:#1', |
| 9238 |
# -- output -- |
| 9239 |
'{\n' + |
| 9240 |
' a: #1') |
| 9241 |
|
| 9242 |
# incomplete |
| 9243 |
test_fragment( |
| 9244 |
'{a:#', |
| 9245 |
# -- output -- |
| 9246 |
'{\n' + |
| 9247 |
' a: #') |
| 9248 |
|
| 9249 |
# incomplete |
| 9250 |
test_fragment( |
| 9251 |
'}}}', |
| 9252 |
# -- output -- |
| 9253 |
'}\n' + |
| 9254 |
'}\n' + |
| 9255 |
'}') |
| 9256 |
test_fragment( |
| 9257 |
'<!--\n' + |
| 9258 |
'void();\n' + |
| 9259 |
'// -->') |
| 9260 |
|
| 9261 |
# incomplete regexp |
| 9262 |
test_fragment('a=/regexp', 'a = /regexp') |
| 9263 |
bt( |
| 9264 |
'{a:#1=[],b:#1#,c:#999999#}', |
| 9265 |
# -- output -- |
| 9266 |
'{\n' + |
| 9267 |
' a: #1=[],\n' + |
| 9268 |
' b: #1#,\n' + |
| 9269 |
' c: #999999#\n' + |
| 9270 |
'}') |
| 9271 |
bt( |
| 9272 |
'do{x()}while(a>1)', |
| 9273 |
# -- output -- |
| 9274 |
'do {\n' + |
| 9275 |
' x()\n' + |
| 9276 |
'} while (a > 1)') |
| 9277 |
bt( |
| 9278 |
'x(); /reg/exp.match(something)', |
| 9279 |
# -- output -- |
| 9280 |
'x();\n' + |
| 9281 |
'/reg/exp.match(something)') |
| 9282 |
test_fragment( |
| 9283 |
'something();(', |
| 9284 |
# -- output -- |
| 9285 |
'something();\n' + |
| 9286 |
'(') |
| 9287 |
test_fragment( |
| 9288 |
'#!she/bangs, she bangs\n' + |
| 9289 |
'f=1', |
| 9290 |
# -- output -- |
| 9291 |
'#!she/bangs, she bangs\n' + |
| 9292 |
'\n' + |
| 9293 |
'f = 1') |
| 9294 |
test_fragment( |
| 9295 |
'#!she/bangs, she bangs\n' + |
| 9296 |
'\n' + |
| 9297 |
'f=1', |
| 9298 |
# -- output -- |
| 9299 |
'#!she/bangs, she bangs\n' + |
| 9300 |
'\n' + |
| 9301 |
'f = 1') |
| 9302 |
test_fragment( |
| 9303 |
'#!she/bangs, she bangs\n' + |
| 9304 |
'\n' + |
| 9305 |
'/* comment */') |
| 9306 |
test_fragment( |
| 9307 |
'#!she/bangs, she bangs\n' + |
| 9308 |
'\n' + |
| 9309 |
'\n' + |
| 9310 |
'/* comment */') |
| 9311 |
test_fragment('#') |
| 9312 |
test_fragment('#!') |
| 9313 |
test_fragment('#include') |
| 9314 |
test_fragment('#include "settings.jsxinc"') |
| 9315 |
test_fragment( |
| 9316 |
'#include "settings.jsxinc"\n' + |
| 9317 |
'\n' + |
| 9318 |
'\n' + |
| 9319 |
'/* comment */') |
| 9320 |
test_fragment( |
| 9321 |
'#include "settings.jsxinc"\n' + |
| 9322 |
'\n' + |
| 9323 |
'\n' + |
| 9324 |
'#include "settings.jsxinc"\n' + |
| 9325 |
'\n' + |
| 9326 |
'\n' + |
| 9327 |
'/* comment */') |
| 9328 |
bt('function namespace::something()') |
| 9329 |
test_fragment( |
| 9330 |
'<!--\n' + |
| 9331 |
'something();\n' + |
| 9332 |
'-->') |
| 9333 |
test_fragment( |
| 9334 |
'<!--\n' + |
| 9335 |
'if(i<0){bla();}\n' + |
| 9336 |
'-->', |
| 9337 |
# -- output -- |
| 9338 |
'<!--\n' + |
| 9339 |
'if (i < 0) {\n' + |
| 9340 |
' bla();\n' + |
| 9341 |
'}\n' + |
| 9342 |
'-->') |
| 9343 |
bt( |
| 9344 |
'{foo();--bar;}', |
| 9345 |
# -- output -- |
| 9346 |
'{\n' + |
| 9347 |
' foo();\n' + |
| 9348 |
' --bar;\n' + |
| 9349 |
'}') |
| 9350 |
bt( |
| 9351 |
'{foo();++bar;}', |
| 9352 |
# -- output -- |
| 9353 |
'{\n' + |
| 9354 |
' foo();\n' + |
| 9355 |
' ++bar;\n' + |
| 9356 |
'}') |
| 9357 |
bt( |
| 9358 |
'{--bar;}', |
| 9359 |
# -- output -- |
| 9360 |
'{\n' + |
| 9361 |
' --bar;\n' + |
| 9362 |
'}') |
| 9363 |
bt( |
| 9364 |
'{++bar;}', |
| 9365 |
# -- output -- |
| 9366 |
'{\n' + |
| 9367 |
' ++bar;\n' + |
| 9368 |
'}') |
| 9369 |
bt('if(true)++a;', 'if (true) ++a;') |
| 9370 |
bt( |
| 9371 |
'if(true)\n' + |
| 9372 |
'++a;', |
| 9373 |
# -- output -- |
| 9374 |
'if (true)\n' + |
| 9375 |
' ++a;') |
| 9376 |
bt('if(true)--a;', 'if (true) --a;') |
| 9377 |
bt( |
| 9378 |
'if(true)\n' + |
| 9379 |
'--a;', |
| 9380 |
# -- output -- |
| 9381 |
'if (true)\n' + |
| 9382 |
' --a;') |
| 9383 |
bt('elem[array]++;') |
| 9384 |
bt('elem++ * elem[array]++;') |
| 9385 |
bt('elem-- * -elem[array]++;') |
| 9386 |
bt('elem-- + elem[array]++;') |
| 9387 |
bt('elem-- - elem[array]++;') |
| 9388 |
bt('elem-- - -elem[array]++;') |
| 9389 |
bt('elem-- - +elem[array]++;') |
| 9390 |
|
| 9391 |
# Handling of newlines around unary ++ and -- operators |
| 9392 |
bt( |
| 9393 |
'{foo\n' + |
| 9394 |
'++bar;}', |
| 9395 |
# -- output -- |
| 9396 |
'{\n' + |
| 9397 |
' foo\n' + |
| 9398 |
' ++bar;\n' + |
| 9399 |
'}') |
| 9400 |
bt( |
| 9401 |
'{foo++\n' + |
| 9402 |
'bar;}', |
| 9403 |
# -- output -- |
| 9404 |
'{\n' + |
| 9405 |
' foo++\n' + |
| 9406 |
' bar;\n' + |
| 9407 |
'}') |
| 9408 |
|
| 9409 |
# This is invalid, but harder to guard against. Issue #203. |
| 9410 |
bt( |
| 9411 |
'{foo\n' + |
| 9412 |
'++\n' + |
| 9413 |
'bar;}', |
| 9414 |
# -- output -- |
| 9415 |
'{\n' + |
| 9416 |
' foo\n' + |
| 9417 |
' ++\n' + |
| 9418 |
' bar;\n' + |
| 9419 |
'}') |
| 9420 |
|
| 9421 |
# regexps |
| 9422 |
bt( |
| 9423 |
'a(/abc\\/\\/def/);b()', |
| 9424 |
# -- output -- |
| 9425 |
'a(/abc\\/\\/def/);\n' + |
| 9426 |
'b()') |
| 9427 |
bt( |
| 9428 |
'a(/a[b\\[\\]c]d/);b()', |
| 9429 |
# -- output -- |
| 9430 |
'a(/a[b\\[\\]c]d/);\n' + |
| 9431 |
'b()') |
| 9432 |
|
| 9433 |
# incomplete char class |
| 9434 |
test_fragment('a(/a[b\\[') |
| 9435 |
|
| 9436 |
# allow unescaped / in char classes |
| 9437 |
bt( |
| 9438 |
'a(/[a/b]/);b()', |
| 9439 |
# -- output -- |
| 9440 |
'a(/[a/b]/);\n' + |
| 9441 |
'b()') |
| 9442 |
bt('typeof /foo\\//;') |
| 9443 |
bt('throw /foo\\//;') |
| 9444 |
bt('do /foo\\//;') |
| 9445 |
bt('return /foo\\//;') |
| 9446 |
bt( |
| 9447 |
'switch (a) {\n' + |
| 9448 |
' case /foo\\//:\n' + |
| 9449 |
' b\n' + |
| 9450 |
'}') |
| 9451 |
bt( |
| 9452 |
'if (a) /foo\\//\n' + |
| 9453 |
'else /foo\\//;') |
| 9454 |
bt('if (foo) /regex/.test();') |
| 9455 |
bt('for (index in [1, 2, 3]) /^test$/i.test(s)') |
| 9456 |
bt( |
| 9457 |
'function foo() {\n' + |
| 9458 |
' return [\n' + |
| 9459 |
' "one",\n' + |
| 9460 |
' "two"\n' + |
| 9461 |
' ];\n' + |
| 9462 |
'}') |
| 9463 |
bt( |
| 9464 |
'a=[[1,2],[4,5],[7,8]]', |
| 9465 |
# -- output -- |
| 9466 |
'a = [\n' + |
| 9467 |
' [1, 2],\n' + |
| 9468 |
' [4, 5],\n' + |
| 9469 |
' [7, 8]\n' + |
| 9470 |
']') |
| 9471 |
bt( |
| 9472 |
'a=[[1,2],[4,5],function(){},[7,8]]', |
| 9473 |
# -- output -- |
| 9474 |
'a = [\n' + |
| 9475 |
' [1, 2],\n' + |
| 9476 |
' [4, 5],\n' + |
| 9477 |
' function() {},\n' + |
| 9478 |
' [7, 8]\n' + |
| 9479 |
']') |
| 9480 |
bt( |
| 9481 |
'a=[[1,2],[4,5],function(){},function(){},[7,8]]', |
| 9482 |
# -- output -- |
| 9483 |
'a = [\n' + |
| 9484 |
' [1, 2],\n' + |
| 9485 |
' [4, 5],\n' + |
| 9486 |
' function() {},\n' + |
| 9487 |
' function() {},\n' + |
| 9488 |
' [7, 8]\n' + |
| 9489 |
']') |
| 9490 |
bt( |
| 9491 |
'a=[[1,2],[4,5],function(){},[7,8]]', |
| 9492 |
# -- output -- |
| 9493 |
'a = [\n' + |
| 9494 |
' [1, 2],\n' + |
| 9495 |
' [4, 5],\n' + |
| 9496 |
' function() {},\n' + |
| 9497 |
' [7, 8]\n' + |
| 9498 |
']') |
| 9499 |
bt('a=[b,c,function(){},function(){},d]', 'a = [b, c, function() {}, function() {}, d]') |
| 9500 |
bt( |
| 9501 |
'a=[b,c,\n' + |
| 9502 |
'function(){},function(){},d]', |
| 9503 |
# -- output -- |
| 9504 |
'a = [b, c,\n' + |
| 9505 |
' function() {},\n' + |
| 9506 |
' function() {},\n' + |
| 9507 |
' d\n' + |
| 9508 |
']') |
| 9509 |
bt('a=[a[1],b[4],c[d[7]]]', 'a = [a[1], b[4], c[d[7]]]') |
| 9510 |
bt('[1,2,[3,4,[5,6],7],8]', '[1, 2, [3, 4, [5, 6], 7], 8]') |
| 9511 |
bt( |
| 9512 |
'[[["1","2"],["3","4"]],[["5","6","7"],["8","9","0"]],[["1","2","3"],["4","5","6","7"],["8","9","0"]]]', |
| 9513 |
# -- output -- |
| 9514 |
'[\n' + |
| 9515 |
' [\n' + |
| 9516 |
' ["1", "2"],\n' + |
| 9517 |
' ["3", "4"]\n' + |
| 9518 |
' ],\n' + |
| 9519 |
' [\n' + |
| 9520 |
' ["5", "6", "7"],\n' + |
| 9521 |
' ["8", "9", "0"]\n' + |
| 9522 |
' ],\n' + |
| 9523 |
' [\n' + |
| 9524 |
' ["1", "2", "3"],\n' + |
| 9525 |
' ["4", "5", "6", "7"],\n' + |
| 9526 |
' ["8", "9", "0"]\n' + |
| 9527 |
' ]\n' + |
| 9528 |
']') |
| 9529 |
bt( |
| 9530 |
'{[x()[0]];indent;}', |
| 9531 |
# -- output -- |
| 9532 |
'{\n' + |
| 9533 |
' [x()[0]];\n' + |
| 9534 |
' indent;\n' + |
| 9535 |
'}') |
| 9536 |
bt( |
| 9537 |
'/*\n' + |
| 9538 |
' foo trailing space \n' + |
| 9539 |
' * bar trailing space \n' + |
| 9540 |
'**/') |
| 9541 |
bt( |
| 9542 |
'{\n' + |
| 9543 |
' /*\n' + |
| 9544 |
' foo \n' + |
| 9545 |
' * bar \n' + |
| 9546 |
' */\n' + |
| 9547 |
'}') |
| 9548 |
bt('return ++i') |
| 9549 |
bt( |
| 9550 |
'obj.num++\n' + |
| 9551 |
'foo()\n' + |
| 9552 |
'bar()\n' + |
| 9553 |
'\n' + |
| 9554 |
'obj.num--\n' + |
| 9555 |
'foo()\n' + |
| 9556 |
'bar()') |
| 9557 |
bt('return !!x') |
| 9558 |
bt('return !x') |
| 9559 |
bt('return [1,2]', 'return [1, 2]') |
| 9560 |
bt('return;') |
| 9561 |
bt( |
| 9562 |
'return\n' + |
| 9563 |
'func') |
| 9564 |
bt('catch(e)', 'catch (e)') |
| 9565 |
bt( |
| 9566 |
'var a=1,b={foo:2,bar:3},{baz:4,wham:5},c=4;', |
| 9567 |
# -- output -- |
| 9568 |
'var a = 1,\n' + |
| 9569 |
' b = {\n' + |
| 9570 |
' foo: 2,\n' + |
| 9571 |
' bar: 3\n' + |
| 9572 |
' },\n' + |
| 9573 |
' {\n' + |
| 9574 |
' baz: 4,\n' + |
| 9575 |
' wham: 5\n' + |
| 9576 |
' }, c = 4;') |
| 9577 |
bt( |
| 9578 |
'var a=1,b={foo:2,bar:3},{baz:4,wham:5},\n' + |
| 9579 |
'c=4;', |
| 9580 |
# -- output -- |
| 9581 |
'var a = 1,\n' + |
| 9582 |
' b = {\n' + |
| 9583 |
' foo: 2,\n' + |
| 9584 |
' bar: 3\n' + |
| 9585 |
' },\n' + |
| 9586 |
' {\n' + |
| 9587 |
' baz: 4,\n' + |
| 9588 |
' wham: 5\n' + |
| 9589 |
' },\n' + |
| 9590 |
' c = 4;') |
| 9591 |
|
| 9592 |
# inline comment |
| 9593 |
bt( |
| 9594 |
'function x(/*int*/ start, /*string*/ foo)', |
| 9595 |
# -- output -- |
| 9596 |
'function x( /*int*/ start, /*string*/ foo)') |
| 9597 |
|
| 9598 |
# javadoc comment |
| 9599 |
bt( |
| 9600 |
'/**\n' + |
| 9601 |
'* foo\n' + |
| 9602 |
'*/', |
| 9603 |
# -- output -- |
| 9604 |
'/**\n' + |
| 9605 |
' * foo\n' + |
| 9606 |
' */') |
| 9607 |
bt( |
| 9608 |
'{\n' + |
| 9609 |
'/**\n' + |
| 9610 |
'* foo\n' + |
| 9611 |
'*/\n' + |
| 9612 |
'}', |
| 9613 |
# -- output -- |
| 9614 |
'{\n' + |
| 9615 |
' /**\n' + |
| 9616 |
' * foo\n' + |
| 9617 |
' */\n' + |
| 9618 |
'}') |
| 9619 |
|
| 9620 |
# starless block comment |
| 9621 |
bt( |
| 9622 |
'/**\n' + |
| 9623 |
'foo\n' + |
| 9624 |
'*/') |
| 9625 |
bt( |
| 9626 |
'/**\n' + |
| 9627 |
'foo\n' + |
| 9628 |
'**/') |
| 9629 |
bt( |
| 9630 |
'/**\n' + |
| 9631 |
'foo\n' + |
| 9632 |
'bar\n' + |
| 9633 |
'**/') |
| 9634 |
bt( |
| 9635 |
'/**\n' + |
| 9636 |
'foo\n' + |
| 9637 |
'\n' + |
| 9638 |
'bar\n' + |
| 9639 |
'**/') |
| 9640 |
bt( |
| 9641 |
'/**\n' + |
| 9642 |
'foo\n' + |
| 9643 |
' bar\n' + |
| 9644 |
'**/') |
| 9645 |
bt( |
| 9646 |
'{\n' + |
| 9647 |
'/**\n' + |
| 9648 |
'foo\n' + |
| 9649 |
'*/\n' + |
| 9650 |
'}', |
| 9651 |
# -- output -- |
| 9652 |
'{\n' + |
| 9653 |
' /**\n' + |
| 9654 |
' foo\n' + |
| 9655 |
' */\n' + |
| 9656 |
'}') |
| 9657 |
bt( |
| 9658 |
'{\n' + |
| 9659 |
'/**\n' + |
| 9660 |
'foo\n' + |
| 9661 |
'**/\n' + |
| 9662 |
'}', |
| 9663 |
# -- output -- |
| 9664 |
'{\n' + |
| 9665 |
' /**\n' + |
| 9666 |
' foo\n' + |
| 9667 |
' **/\n' + |
| 9668 |
'}') |
| 9669 |
bt( |
| 9670 |
'{\n' + |
| 9671 |
'/**\n' + |
| 9672 |
'foo\n' + |
| 9673 |
'bar\n' + |
| 9674 |
'**/\n' + |
| 9675 |
'}', |
| 9676 |
# -- output -- |
| 9677 |
'{\n' + |
| 9678 |
' /**\n' + |
| 9679 |
' foo\n' + |
| 9680 |
' bar\n' + |
| 9681 |
' **/\n' + |
| 9682 |
'}') |
| 9683 |
bt( |
| 9684 |
'{\n' + |
| 9685 |
'/**\n' + |
| 9686 |
'foo\n' + |
| 9687 |
'\n' + |
| 9688 |
'bar\n' + |
| 9689 |
'**/\n' + |
| 9690 |
'}', |
| 9691 |
# -- output -- |
| 9692 |
'{\n' + |
| 9693 |
' /**\n' + |
| 9694 |
' foo\n' + |
| 9695 |
'\n' + |
| 9696 |
' bar\n' + |
| 9697 |
' **/\n' + |
| 9698 |
'}') |
| 9699 |
bt( |
| 9700 |
'{\n' + |
| 9701 |
'/**\n' + |
| 9702 |
'foo\n' + |
| 9703 |
' bar\n' + |
| 9704 |
'**/\n' + |
| 9705 |
'}', |
| 9706 |
# -- output -- |
| 9707 |
'{\n' + |
| 9708 |
' /**\n' + |
| 9709 |
' foo\n' + |
| 9710 |
' bar\n' + |
| 9711 |
' **/\n' + |
| 9712 |
'}') |
| 9713 |
bt( |
| 9714 |
'{\n' + |
| 9715 |
' /**\n' + |
| 9716 |
' foo\n' + |
| 9717 |
'bar\n' + |
| 9718 |
' **/\n' + |
| 9719 |
'}') |
| 9720 |
bt( |
| 9721 |
'var a,b,c=1,d,e,f=2;', |
| 9722 |
# -- output -- |
| 9723 |
'var a, b, c = 1,\n' + |
| 9724 |
' d, e, f = 2;') |
| 9725 |
bt( |
| 9726 |
'var a,b,c=[],d,e,f=2;', |
| 9727 |
# -- output -- |
| 9728 |
'var a, b, c = [],\n' + |
| 9729 |
' d, e, f = 2;') |
| 9730 |
bt( |
| 9731 |
'function() {\n' + |
| 9732 |
' var a, b, c, d, e = [],\n' + |
| 9733 |
' f;\n' + |
| 9734 |
'}') |
| 9735 |
bt( |
| 9736 |
'do/regexp/;\n' + |
| 9737 |
'while(1);', |
| 9738 |
# -- output -- |
| 9739 |
'do /regexp/;\n' + |
| 9740 |
'while (1);') |
| 9741 |
bt( |
| 9742 |
'var a = a,\n' + |
| 9743 |
'a;\n' + |
| 9744 |
'b = {\n' + |
| 9745 |
'b\n' + |
| 9746 |
'}', |
| 9747 |
# -- output -- |
| 9748 |
'var a = a,\n' + |
| 9749 |
' a;\n' + |
| 9750 |
'b = {\n' + |
| 9751 |
' b\n' + |
| 9752 |
'}') |
| 9753 |
bt( |
| 9754 |
'var a = a,\n' + |
| 9755 |
' /* c */\n' + |
| 9756 |
' b;') |
| 9757 |
bt( |
| 9758 |
'var a = a,\n' + |
| 9759 |
' // c\n' + |
| 9760 |
' b;') |
| 9761 |
|
| 9762 |
# weird element referencing |
| 9763 |
bt('foo.("bar");') |
| 9764 |
bt( |
| 9765 |
'if (a) a()\n' + |
| 9766 |
'else b()\n' + |
| 9767 |
'newline()') |
| 9768 |
bt( |
| 9769 |
'if (a) a()\n' + |
| 9770 |
'newline()') |
| 9771 |
bt('a=typeof(x)', 'a = typeof(x)') |
| 9772 |
bt( |
| 9773 |
'var a = function() {\n' + |
| 9774 |
' return null;\n' + |
| 9775 |
' },\n' + |
| 9776 |
' b = false;') |
| 9777 |
bt( |
| 9778 |
'var a = function() {\n' + |
| 9779 |
' func1()\n' + |
| 9780 |
'}') |
| 9781 |
bt( |
| 9782 |
'var a = function() {\n' + |
| 9783 |
' func1()\n' + |
| 9784 |
'}\n' + |
| 9785 |
'var b = function() {\n' + |
| 9786 |
' func2()\n' + |
| 9787 |
'}') |
| 9788 |
|
| 9789 |
# code with and without semicolons |
| 9790 |
bt( |
| 9791 |
'var whatever = require("whatever");\n' + |
| 9792 |
'function() {\n' + |
| 9793 |
' a = 6;\n' + |
| 9794 |
'}', |
| 9795 |
# -- output -- |
| 9796 |
'var whatever = require("whatever");\n' + |
| 9797 |
'\n' + |
| 9798 |
'function() {\n' + |
| 9799 |
' a = 6;\n' + |
| 9800 |
'}') |
| 9801 |
bt( |
| 9802 |
'var whatever = require("whatever")\n' + |
| 9803 |
'function() {\n' + |
| 9804 |
' a = 6\n' + |
| 9805 |
'}', |
| 9806 |
# -- output -- |
| 9807 |
'var whatever = require("whatever")\n' + |
| 9808 |
'\n' + |
| 9809 |
'function() {\n' + |
| 9810 |
' a = 6\n' + |
| 9811 |
'}') |
| 9812 |
bt( |
| 9813 |
'{"x":[{"a":1,"b":3},\n' + |
| 9814 |
'7,8,8,8,8,{"b":99},{"a":11}]}', |
| 9815 |
# -- output -- |
| 9816 |
'{\n' + |
| 9817 |
' "x": [{\n' + |
| 9818 |
' "a": 1,\n' + |
| 9819 |
' "b": 3\n' + |
| 9820 |
' },\n' + |
| 9821 |
' 7, 8, 8, 8, 8, {\n' + |
| 9822 |
' "b": 99\n' + |
| 9823 |
' }, {\n' + |
| 9824 |
' "a": 11\n' + |
| 9825 |
' }\n' + |
| 9826 |
' ]\n' + |
| 9827 |
'}') |
| 9828 |
bt( |
| 9829 |
'{"x":[{"a":1,"b":3},7,8,8,8,8,{"b":99},{"a":11}]}', |
| 9830 |
# -- output -- |
| 9831 |
'{\n' + |
| 9832 |
' "x": [{\n' + |
| 9833 |
' "a": 1,\n' + |
| 9834 |
' "b": 3\n' + |
| 9835 |
' }, 7, 8, 8, 8, 8, {\n' + |
| 9836 |
' "b": 99\n' + |
| 9837 |
' }, {\n' + |
| 9838 |
' "a": 11\n' + |
| 9839 |
' }]\n' + |
| 9840 |
'}') |
| 9841 |
bt( |
| 9842 |
'{"1":{"1a":"1b"},"2"}', |
| 9843 |
# -- output -- |
| 9844 |
'{\n' + |
| 9845 |
' "1": {\n' + |
| 9846 |
' "1a": "1b"\n' + |
| 9847 |
' },\n' + |
| 9848 |
' "2"\n' + |
| 9849 |
'}') |
| 9850 |
bt( |
| 9851 |
'{a:{a:b},c}', |
| 9852 |
# -- output -- |
| 9853 |
'{\n' + |
| 9854 |
' a: {\n' + |
| 9855 |
' a: b\n' + |
| 9856 |
' },\n' + |
| 9857 |
' c\n' + |
| 9858 |
'}') |
| 9859 |
bt( |
| 9860 |
'{[y[a]];keep_indent;}', |
| 9861 |
# -- output -- |
| 9862 |
'{\n' + |
| 9863 |
' [y[a]];\n' + |
| 9864 |
' keep_indent;\n' + |
| 9865 |
'}') |
| 9866 |
bt( |
| 9867 |
'if (x) {y} else { if (x) {y}}', |
| 9868 |
# -- output -- |
| 9869 |
'if (x) {\n' + |
| 9870 |
' y\n' + |
| 9871 |
'} else {\n' + |
| 9872 |
' if (x) {\n' + |
| 9873 |
' y\n' + |
| 9874 |
' }\n' + |
| 9875 |
'}') |
| 9876 |
bt( |
| 9877 |
'if (foo) one()\n' + |
| 9878 |
'two()\n' + |
| 9879 |
'three()') |
| 9880 |
bt( |
| 9881 |
'if (1 + foo() && bar(baz()) / 2) one()\n' + |
| 9882 |
'two()\n' + |
| 9883 |
'three()') |
| 9884 |
bt( |
| 9885 |
'if (1 + foo() && bar(baz()) / 2) one();\n' + |
| 9886 |
'two();\n' + |
| 9887 |
'three();') |
| 9888 |
bt( |
| 9889 |
'var a=1,b={bang:2},c=3;', |
| 9890 |
# -- output -- |
| 9891 |
'var a = 1,\n' + |
| 9892 |
' b = {\n' + |
| 9893 |
' bang: 2\n' + |
| 9894 |
' },\n' + |
| 9895 |
' c = 3;') |
| 9896 |
bt( |
| 9897 |
'var a={bing:1},b=2,c=3;', |
| 9898 |
# -- output -- |
| 9899 |
'var a = {\n' + |
| 9900 |
' bing: 1\n' + |
| 9901 |
' },\n' + |
| 9902 |
' b = 2,\n' + |
| 9903 |
' c = 3;') |
| 9904 |
|
| 9905 |
# Issue #1896: Handle newlines with bitwise ~ operator |
| 9906 |
bt( |
| 9907 |
'if (foo) {\n' + |
| 9908 |
'var bar = 1;\n' + |
| 9909 |
'~bar ? 0 : 1\n' + |
| 9910 |
' }', |
| 9911 |
# -- output -- |
| 9912 |
'if (foo) {\n' + |
| 9913 |
' var bar = 1;\n' + |
| 9914 |
' ~bar ? 0 : 1\n' + |
| 9915 |
'}') |
| 9916 |
|
| 9917 |
# Issue #2128 - NPE in python implementation |
| 9918 |
test_fragment(') / a / g') |
| 9919 |
|
| 9920 |
|
| 9921 |
|
| 9922 |
def test_beautifier_unconverted(self): |
| 9923 |
test_fragment = self.decodesto |
| 9924 |
bt = self.bt |
| 9925 |
|
| 9926 |
self.reset_options() |
| 9927 |
#============================================================ |
| 9928 |
bt(None, "") |
| 9929 |
|
| 9930 |
self.reset_options() |
| 9931 |
#============================================================ |
| 9932 |
# Test user pebkac protection, converts dash names to underscored names |
| 9933 |
setattr(self.options, 'end-with-newline', True) |
| 9934 |
test_fragment(None, '\n') |
| 9935 |
|
| 9936 |
self.reset_options() |
| 9937 |
#============================================================ |
| 9938 |
# Test passing dictionary or tuple |
| 9939 |
self.options = {'end_with_newline': True, 'eol': '\r\n' } |
| 9940 |
test_fragment(None, '\r\n') |
| 9941 |
|
| 9942 |
self.options = {'end-with-newline': True} |
| 9943 |
test_fragment(None, '\n') |
| 9944 |
|
| 9945 |
self.options = {'end-with-newline': False} |
| 9946 |
test_fragment(None, '') |
| 9947 |
|
| 9948 |
self.options = ( ('end-with-newline', True), ('eol', '\r') ) |
| 9949 |
test_fragment(None, '\r') |
| 9950 |
|
| 9951 |
self.reset_options() |
| 9952 |
#============================================================ |
| 9953 |
self.options.indent_size = 1 |
| 9954 |
self.options.indent_char = ' ' |
| 9955 |
bt('{ one_char() }', "{\n one_char()\n}") |
| 9956 |
|
| 9957 |
bt('var a,b=1,c=2', 'var a, b = 1,\n c = 2') |
| 9958 |
|
| 9959 |
self.options.indent_size = 4 |
| 9960 |
self.options.indent_char = ' ' |
| 9961 |
bt('{ one_char() }', "{\n one_char()\n}") |
| 9962 |
|
| 9963 |
self.options.indent_size = 1 |
| 9964 |
self.options.indent_char = "\t" |
| 9965 |
bt('{ one_char() }', "{\n\tone_char()\n}") |
| 9966 |
bt('x = a ? b : c; x;', 'x = a ? b : c;\nx;') |
| 9967 |
|
| 9968 |
#set to something else than it should change to, but with tabs on, should override |
| 9969 |
self.options.indent_size = 5 |
| 9970 |
self.options.indent_char = ' ' |
| 9971 |
self.options.indent_with_tabs = True |
| 9972 |
|
| 9973 |
bt('{ one_char() }', "{\n\tone_char()\n}") |
| 9974 |
bt('x = a ? b : c; x;', 'x = a ? b : c;\nx;') |
| 9975 |
|
| 9976 |
|
| 9977 |
self.reset_options() |
| 9978 |
#============================================================ |
| 9979 |
self.options.preserve_newlines = False |
| 9980 |
bt('var\na=dont_preserve_newlines;', 'var a = dont_preserve_newlines;') |
| 9981 |
|
| 9982 |
# make sure the blank line between function definitions stays |
| 9983 |
# even when preserve_newlines = False |
| 9984 |
bt('function foo() {\n return 1;\n}\n\nfunction foo() {\n return 1;\n}') |
| 9985 |
bt('function foo() {\n return 1;\n}\nfunction foo() {\n return 1;\n}', |
| 9986 |
'function foo() {\n return 1;\n}\n\nfunction foo() {\n return 1;\n}' |
| 9987 |
) |
| 9988 |
bt('function foo() {\n return 1;\n}\n\n\nfunction foo() {\n return 1;\n}', |
| 9989 |
'function foo() {\n return 1;\n}\n\nfunction foo() {\n return 1;\n}' |
| 9990 |
) |
| 9991 |
|
| 9992 |
|
| 9993 |
self.options.preserve_newlines = True |
| 9994 |
bt('var\na=do_preserve_newlines;', 'var\n a = do_preserve_newlines;') |
| 9995 |
bt('if (foo) // comment\n{\n bar();\n}') |
| 9996 |
|
| 9997 |
|
| 9998 |
self.reset_options() |
| 9999 |
#============================================================ |
| 10000 |
# START tests for brace positioning |
| 10001 |
|
| 10002 |
# If this is ever supported, update tests for each brace style. |
| 10003 |
# test_fragment('return\n{', 'return\n{') # can't support this?, but that's an improbable and extreme case anyway. |
| 10004 |
|
| 10005 |
self.options.brace_style = 'expand' |
| 10006 |
|
| 10007 |
bt('//case 1\nif (a == 1)\n{}\n//case 2\nelse if (a == 2)\n{}') |
| 10008 |
bt('if(1){2}else{3}', "if (1)\n{\n 2\n}\nelse\n{\n 3\n}") |
| 10009 |
bt('try{a();}catch(b){c();}catch(d){}finally{e();}', |
| 10010 |
"try\n{\n a();\n}\ncatch (b)\n{\n c();\n}\ncatch (d)\n{}\nfinally\n{\n e();\n}") |
| 10011 |
bt('if(a){b();}else if(c) foo();', |
| 10012 |
"if (a)\n{\n b();\n}\nelse if (c) foo();") |
| 10013 |
bt("if (a) {\n// comment\n}else{\n// comment\n}", |
| 10014 |
"if (a)\n{\n // comment\n}\nelse\n{\n // comment\n}") # if/else statement with empty body |
| 10015 |
bt('if (x) {y} else { if (x) {y}}', |
| 10016 |
'if (x)\n{\n y\n}\nelse\n{\n if (x)\n {\n y\n }\n}') |
| 10017 |
bt('if (a)\n{\nb;\n}\nelse\n{\nc;\n}', |
| 10018 |
'if (a)\n{\n b;\n}\nelse\n{\n c;\n}') |
| 10019 |
test_fragment(' /*\n* xx\n*/\n// xx\nif (foo) {\n bar();\n}', |
| 10020 |
' /*\n * xx\n */\n // xx\n if (foo)\n {\n bar();\n }') |
| 10021 |
bt('if (foo)\n{}\nelse /regex/.test();') |
| 10022 |
test_fragment('if (foo) {', 'if (foo)\n{') |
| 10023 |
test_fragment('foo {', 'foo\n{') |
| 10024 |
test_fragment('return {', 'return {') # return needs the brace. |
| 10025 |
test_fragment('return /* inline */ {', 'return /* inline */ {') |
| 10026 |
test_fragment('return;\n{', 'return;\n{') |
| 10027 |
bt("throw {}") |
| 10028 |
bt("throw {\n foo;\n}") |
| 10029 |
bt('var foo = {}') |
| 10030 |
bt('function x() {\n foo();\n}zzz', 'function x()\n{\n foo();\n}\nzzz') |
| 10031 |
test_fragment('a: do {} while (); xxx', 'a: do {} while ();\nxxx') |
| 10032 |
bt('{a: do {} while (); xxx}', '{\n a: do {} while ();xxx\n}') |
| 10033 |
bt('var a = new function() {};') |
| 10034 |
bt('var a = new function a() {};', 'var a = new function a()\n{};') |
| 10035 |
bt('var a = new function()\n{};', 'var a = new function() {};') |
| 10036 |
bt('var a = new function a()\n{};') |
| 10037 |
bt('var a = new function a()\n {},\n b = new function b()\n {};') |
| 10038 |
bt("foo({\n 'a': 1\n},\n10);", |
| 10039 |
"foo(\n {\n 'a': 1\n },\n 10);") |
| 10040 |
bt('(["foo","bar"]).each(function(i) {return i;});', |
| 10041 |
'(["foo", "bar"]).each(function(i)\n{\n return i;\n});') |
| 10042 |
bt('(function(i) {return i;})();', |
| 10043 |
'(function(i)\n{\n return i;\n})();') |
| 10044 |
bt( "test( /*Argument 1*/ {\n" + |
| 10045 |
" 'Value1': '1'\n" + |
| 10046 |
"}, /*Argument 2\n" + |
| 10047 |
" */ {\n" + |
| 10048 |
" 'Value2': '2'\n" + |
| 10049 |
"});", |
| 10050 |
# expected |
| 10051 |
"test( /*Argument 1*/\n" + |
| 10052 |
" {\n" + |
| 10053 |
" 'Value1': '1'\n" + |
| 10054 |
" },\n" + |
| 10055 |
" /*Argument 2\n" + |
| 10056 |
" */\n" + |
| 10057 |
" {\n" + |
| 10058 |
" 'Value2': '2'\n" + |
| 10059 |
" });") |
| 10060 |
bt( "test(\n" + |
| 10061 |
"/*Argument 1*/ {\n" + |
| 10062 |
" 'Value1': '1'\n" + |
| 10063 |
"},\n" + |
| 10064 |
"/*Argument 2\n" + |
| 10065 |
" */ {\n" + |
| 10066 |
" 'Value2': '2'\n" + |
| 10067 |
"});", |
| 10068 |
# expected |
| 10069 |
"test(\n" + |
| 10070 |
" /*Argument 1*/\n" + |
| 10071 |
" {\n" + |
| 10072 |
" 'Value1': '1'\n" + |
| 10073 |
" },\n" + |
| 10074 |
" /*Argument 2\n" + |
| 10075 |
" */\n" + |
| 10076 |
" {\n" + |
| 10077 |
" 'Value2': '2'\n" + |
| 10078 |
" });") |
| 10079 |
bt( "test( /*Argument 1*/\n" + |
| 10080 |
"{\n" + |
| 10081 |
" 'Value1': '1'\n" + |
| 10082 |
"}, /*Argument 2\n" + |
| 10083 |
" */\n" + |
| 10084 |
"{\n" + |
| 10085 |
" 'Value2': '2'\n" + |
| 10086 |
"});", |
| 10087 |
# expected |
| 10088 |
"test( /*Argument 1*/\n" + |
| 10089 |
" {\n" + |
| 10090 |
" 'Value1': '1'\n" + |
| 10091 |
" },\n" + |
| 10092 |
" /*Argument 2\n" + |
| 10093 |
" */\n" + |
| 10094 |
" {\n" + |
| 10095 |
" 'Value2': '2'\n" + |
| 10096 |
" });") |
| 10097 |
|
| 10098 |
self.options.brace_style = 'collapse' |
| 10099 |
|
| 10100 |
bt('//case 1\nif (a == 1) {}\n//case 2\nelse if (a == 2) {}') |
| 10101 |
bt('if(1){2}else{3}', "if (1) {\n 2\n} else {\n 3\n}") |
| 10102 |
bt('try{a();}catch(b){c();}catch(d){}finally{e();}', |
| 10103 |
"try {\n a();\n} catch (b) {\n c();\n} catch (d) {} finally {\n e();\n}") |
| 10104 |
bt('if(a){b();}else if(c) foo();', |
| 10105 |
"if (a) {\n b();\n} else if (c) foo();") |
| 10106 |
bt("if (a) {\n// comment\n}else{\n// comment\n}", |
| 10107 |
"if (a) {\n // comment\n} else {\n // comment\n}") # if/else statement with empty body |
| 10108 |
bt('if (x) {y} else { if (x) {y}}', |
| 10109 |
'if (x) {\n y\n} else {\n if (x) {\n y\n }\n}') |
| 10110 |
bt('if (a)\n{\nb;\n}\nelse\n{\nc;\n}', |
| 10111 |
'if (a) {\n b;\n} else {\n c;\n}') |
| 10112 |
test_fragment(' /*\n* xx\n*/\n// xx\nif (foo) {\n bar();\n}', |
| 10113 |
' /*\n * xx\n */\n // xx\n if (foo) {\n bar();\n }') |
| 10114 |
bt('if (foo) {} else /regex/.test();') |
| 10115 |
test_fragment('if (foo) {', 'if (foo) {') |
| 10116 |
test_fragment('foo {', 'foo {') |
| 10117 |
test_fragment('return {', 'return {') # return needs the brace. |
| 10118 |
test_fragment('return /* inline */ {', 'return /* inline */ {') |
| 10119 |
test_fragment('return;\n{', 'return;\n{') |
| 10120 |
bt("throw {}") |
| 10121 |
bt("throw {\n foo;\n}") |
| 10122 |
bt('var foo = {}') |
| 10123 |
bt('function x() {\n foo();\n}zzz', 'function x() {\n foo();\n}\nzzz') |
| 10124 |
test_fragment('a: do {} while (); xxx', 'a: do {} while ();\nxxx') |
| 10125 |
bt('{a: do {} while (); xxx}', '{\n a: do {} while ();xxx\n}') |
| 10126 |
bt('var a = new function() {};') |
| 10127 |
bt('var a = new function a() {};') |
| 10128 |
bt('var a = new function()\n{};', 'var a = new function() {};') |
| 10129 |
bt('var a = new function a()\n{};', 'var a = new function a() {};') |
| 10130 |
bt('var a = new function a()\n {},\n b = new function b()\n {};', 'var a = new function a() {},\n b = new function b() {};') |
| 10131 |
bt("foo({\n 'a': 1\n},\n10);", |
| 10132 |
"foo({\n 'a': 1\n },\n 10);") |
| 10133 |
bt('(["foo","bar"]).each(function(i) {return i;});', |
| 10134 |
'(["foo", "bar"]).each(function(i) {\n return i;\n});') |
| 10135 |
bt('(function(i) {return i;})();', |
| 10136 |
'(function(i) {\n return i;\n})();') |
| 10137 |
bt( "test( /*Argument 1*/ {\n" + |
| 10138 |
" 'Value1': '1'\n" + |
| 10139 |
"}, /*Argument 2\n" + |
| 10140 |
" */ {\n" + |
| 10141 |
" 'Value2': '2'\n" + |
| 10142 |
"});", |
| 10143 |
# expected |
| 10144 |
"test( /*Argument 1*/ {\n" + |
| 10145 |
" 'Value1': '1'\n" + |
| 10146 |
" },\n" + |
| 10147 |
" /*Argument 2\n" + |
| 10148 |
" */\n" + |
| 10149 |
" {\n" + |
| 10150 |
" 'Value2': '2'\n" + |
| 10151 |
" });") |
| 10152 |
bt( "test(\n" + |
| 10153 |
"/*Argument 1*/ {\n" + |
| 10154 |
" 'Value1': '1'\n" + |
| 10155 |
"},\n" + |
| 10156 |
"/*Argument 2\n" + |
| 10157 |
" */ {\n" + |
| 10158 |
" 'Value2': '2'\n" + |
| 10159 |
"});", |
| 10160 |
# expected |
| 10161 |
"test(\n" + |
| 10162 |
" /*Argument 1*/\n" + |
| 10163 |
" {\n" + |
| 10164 |
" 'Value1': '1'\n" + |
| 10165 |
" },\n" + |
| 10166 |
" /*Argument 2\n" + |
| 10167 |
" */\n" + |
| 10168 |
" {\n" + |
| 10169 |
" 'Value2': '2'\n" + |
| 10170 |
" });") |
| 10171 |
bt( "test( /*Argument 1*/\n" + |
| 10172 |
"{\n" + |
| 10173 |
" 'Value1': '1'\n" + |
| 10174 |
"}, /*Argument 2\n" + |
| 10175 |
" */\n" + |
| 10176 |
"{\n" + |
| 10177 |
" 'Value2': '2'\n" + |
| 10178 |
"});", |
| 10179 |
# expected |
| 10180 |
"test( /*Argument 1*/ {\n" + |
| 10181 |
" 'Value1': '1'\n" + |
| 10182 |
" },\n" + |
| 10183 |
" /*Argument 2\n" + |
| 10184 |
" */\n" + |
| 10185 |
" {\n" + |
| 10186 |
" 'Value2': '2'\n" + |
| 10187 |
" });") |
| 10188 |
|
| 10189 |
self.options.brace_style = "end-expand" |
| 10190 |
|
| 10191 |
bt('//case 1\nif (a == 1) {}\n//case 2\nelse if (a == 2) {}') |
| 10192 |
bt('if(1){2}else{3}', "if (1) {\n 2\n}\nelse {\n 3\n}") |
| 10193 |
bt('try{a();}catch(b){c();}catch(d){}finally{e();}', |
| 10194 |
"try {\n a();\n}\ncatch (b) {\n c();\n}\ncatch (d) {}\nfinally {\n e();\n}") |
| 10195 |
bt('if(a){b();}else if(c) foo();', |
| 10196 |
"if (a) {\n b();\n}\nelse if (c) foo();") |
| 10197 |
bt("if (a) {\n// comment\n}else{\n// comment\n}", |
| 10198 |
"if (a) {\n // comment\n}\nelse {\n // comment\n}") # if/else statement with empty body |
| 10199 |
bt('if (x) {y} else { if (x) {y}}', |
| 10200 |
'if (x) {\n y\n}\nelse {\n if (x) {\n y\n }\n}') |
| 10201 |
bt('if (a)\n{\nb;\n}\nelse\n{\nc;\n}', |
| 10202 |
'if (a) {\n b;\n}\nelse {\n c;\n}') |
| 10203 |
test_fragment(' /*\n* xx\n*/\n// xx\nif (foo) {\n bar();\n}', |
| 10204 |
' /*\n * xx\n */\n // xx\n if (foo) {\n bar();\n }') |
| 10205 |
bt('if (foo) {}\nelse /regex/.test();') |
| 10206 |
test_fragment('if (foo) {', 'if (foo) {') |
| 10207 |
test_fragment('foo {', 'foo {') |
| 10208 |
test_fragment('return {', 'return {') # return needs the brace. |
| 10209 |
test_fragment('return /* inline */ {', 'return /* inline */ {') |
| 10210 |
test_fragment('return;\n{', 'return;\n{') |
| 10211 |
bt("throw {}") |
| 10212 |
bt("throw {\n foo;\n}") |
| 10213 |
bt('var foo = {}') |
| 10214 |
bt('function x() {\n foo();\n}zzz', 'function x() {\n foo();\n}\nzzz') |
| 10215 |
test_fragment('a: do {} while (); xxx', 'a: do {} while ();\nxxx') |
| 10216 |
bt('{a: do {} while (); xxx}', '{\n a: do {} while ();xxx\n}') |
| 10217 |
bt('var a = new function() {};') |
| 10218 |
bt('var a = new function a() {};') |
| 10219 |
bt('var a = new function()\n{};', 'var a = new function() {};') |
| 10220 |
bt('var a = new function a()\n{};', 'var a = new function a() {};') |
| 10221 |
bt('var a = new function a()\n {},\n b = new function b()\n {};', 'var a = new function a() {},\n b = new function b() {};') |
| 10222 |
bt("foo({\n 'a': 1\n},\n10);", |
| 10223 |
"foo({\n 'a': 1\n },\n 10);") |
| 10224 |
bt('(["foo","bar"]).each(function(i) {return i;});', |
| 10225 |
'(["foo", "bar"]).each(function(i) {\n return i;\n});') |
| 10226 |
bt('(function(i) {return i;})();', |
| 10227 |
'(function(i) {\n return i;\n})();') |
| 10228 |
bt( "test( /*Argument 1*/ {\n" + |
| 10229 |
" 'Value1': '1'\n" + |
| 10230 |
"}, /*Argument 2\n" + |
| 10231 |
" */ {\n" + |
| 10232 |
" 'Value2': '2'\n" + |
| 10233 |
"});", |
| 10234 |
# expected |
| 10235 |
"test( /*Argument 1*/ {\n" + |
| 10236 |
" 'Value1': '1'\n" + |
| 10237 |
" },\n" + |
| 10238 |
" /*Argument 2\n" + |
| 10239 |
" */\n" + |
| 10240 |
" {\n" + |
| 10241 |
" 'Value2': '2'\n" + |
| 10242 |
" });") |
| 10243 |
bt( "test(\n" + |
| 10244 |
"/*Argument 1*/ {\n" + |
| 10245 |
" 'Value1': '1'\n" + |
| 10246 |
"},\n" + |
| 10247 |
"/*Argument 2\n" + |
| 10248 |
" */ {\n" + |
| 10249 |
" 'Value2': '2'\n" + |
| 10250 |
"});", |
| 10251 |
# expected |
| 10252 |
"test(\n" + |
| 10253 |
" /*Argument 1*/\n" + |
| 10254 |
" {\n" + |
| 10255 |
" 'Value1': '1'\n" + |
| 10256 |
" },\n" + |
| 10257 |
" /*Argument 2\n" + |
| 10258 |
" */\n" + |
| 10259 |
" {\n" + |
| 10260 |
" 'Value2': '2'\n" + |
| 10261 |
" });") |
| 10262 |
bt( "test( /*Argument 1*/\n" + |
| 10263 |
"{\n" + |
| 10264 |
" 'Value1': '1'\n" + |
| 10265 |
"}, /*Argument 2\n" + |
| 10266 |
" */\n" + |
| 10267 |
"{\n" + |
| 10268 |
" 'Value2': '2'\n" + |
| 10269 |
"});", |
| 10270 |
# expected |
| 10271 |
"test( /*Argument 1*/ {\n" + |
| 10272 |
" 'Value1': '1'\n" + |
| 10273 |
" },\n" + |
| 10274 |
" /*Argument 2\n" + |
| 10275 |
" */\n" + |
| 10276 |
" {\n" + |
| 10277 |
" 'Value2': '2'\n" + |
| 10278 |
" });") |
| 10279 |
|
| 10280 |
self.options.brace_style = 'none' |
| 10281 |
|
| 10282 |
bt('//case 1\nif (a == 1)\n{}\n//case 2\nelse if (a == 2)\n{}') |
| 10283 |
bt('if(1){2}else{3}', "if (1) {\n 2\n} else {\n 3\n}") |
| 10284 |
bt('try{a();}catch(b){c();}catch(d){}finally{e();}', |
| 10285 |
"try {\n a();\n} catch (b) {\n c();\n} catch (d) {} finally {\n e();\n}") |
| 10286 |
bt('if(a){b();}else if(c) foo();', |
| 10287 |
"if (a) {\n b();\n} else if (c) foo();") |
| 10288 |
bt("if (a) {\n// comment\n}else{\n// comment\n}", |
| 10289 |
"if (a) {\n // comment\n} else {\n // comment\n}") # if/else statement with empty body |
| 10290 |
bt('if (x) {y} else { if (x) {y}}', |
| 10291 |
'if (x) {\n y\n} else {\n if (x) {\n y\n }\n}') |
| 10292 |
bt('if (a)\n{\nb;\n}\nelse\n{\nc;\n}', |
| 10293 |
'if (a)\n{\n b;\n}\nelse\n{\n c;\n}') |
| 10294 |
test_fragment(' /*\n* xx\n*/\n// xx\nif (foo) {\n bar();\n}', |
| 10295 |
' /*\n * xx\n */\n // xx\n if (foo) {\n bar();\n }') |
| 10296 |
bt('if (foo)\n{}\nelse /regex/.test();') |
| 10297 |
test_fragment('if (foo) {') |
| 10298 |
test_fragment('foo {') |
| 10299 |
test_fragment('return {') # return needs the brace. |
| 10300 |
test_fragment('return /* inline */ {') |
| 10301 |
test_fragment('return;\n{') |
| 10302 |
bt("throw {}") |
| 10303 |
bt("throw {\n foo;\n}") |
| 10304 |
bt('var foo = {}') |
| 10305 |
bt('function x() {\n foo();\n}zzz', 'function x() {\n foo();\n}\nzzz') |
| 10306 |
test_fragment('a: do {} while (); xxx', 'a: do {} while ();\nxxx') |
| 10307 |
bt('{a: do {} while (); xxx}', '{\n a: do {} while ();xxx\n}') |
| 10308 |
bt('var a = new function() {};') |
| 10309 |
bt('var a = new function a() {};') |
| 10310 |
bt('var a = new function()\n{};', 'var a = new function() {};') |
| 10311 |
bt('var a = new function a()\n{};') |
| 10312 |
bt('var a = new function a()\n {},\n b = new function b()\n {};') |
| 10313 |
bt("foo({\n 'a': 1\n},\n10);", |
| 10314 |
"foo({\n 'a': 1\n },\n 10);") |
| 10315 |
bt('(["foo","bar"]).each(function(i) {return i;});', |
| 10316 |
'(["foo", "bar"]).each(function(i) {\n return i;\n});') |
| 10317 |
bt('(function(i) {return i;})();', |
| 10318 |
'(function(i) {\n return i;\n})();') |
| 10319 |
bt( "test( /*Argument 1*/ {\n" + |
| 10320 |
" 'Value1': '1'\n" + |
| 10321 |
"}, /*Argument 2\n" + |
| 10322 |
" */ {\n" + |
| 10323 |
" 'Value2': '2'\n" + |
| 10324 |
"});", |
| 10325 |
# expected |
| 10326 |
"test( /*Argument 1*/ {\n" + |
| 10327 |
" 'Value1': '1'\n" + |
| 10328 |
" },\n" + |
| 10329 |
" /*Argument 2\n" + |
| 10330 |
" */\n" + |
| 10331 |
" {\n" + |
| 10332 |
" 'Value2': '2'\n" + |
| 10333 |
" });") |
| 10334 |
bt( "test(\n" + |
| 10335 |
"/*Argument 1*/ {\n" + |
| 10336 |
" 'Value1': '1'\n" + |
| 10337 |
"},\n" + |
| 10338 |
"/*Argument 2\n" + |
| 10339 |
" */ {\n" + |
| 10340 |
" 'Value2': '2'\n" + |
| 10341 |
"});", |
| 10342 |
# expected |
| 10343 |
"test(\n" + |
| 10344 |
" /*Argument 1*/\n" + |
| 10345 |
" {\n" + |
| 10346 |
" 'Value1': '1'\n" + |
| 10347 |
" },\n" + |
| 10348 |
" /*Argument 2\n" + |
| 10349 |
" */\n" + |
| 10350 |
" {\n" + |
| 10351 |
" 'Value2': '2'\n" + |
| 10352 |
" });") |
| 10353 |
bt( "test( /*Argument 1*/\n" + |
| 10354 |
"{\n" + |
| 10355 |
" 'Value1': '1'\n" + |
| 10356 |
"}, /*Argument 2\n" + |
| 10357 |
" */\n" + |
| 10358 |
"{\n" + |
| 10359 |
" 'Value2': '2'\n" + |
| 10360 |
"});", |
| 10361 |
# expected |
| 10362 |
"test( /*Argument 1*/\n" + |
| 10363 |
" {\n" + |
| 10364 |
" 'Value1': '1'\n" + |
| 10365 |
" },\n" + |
| 10366 |
" /*Argument 2\n" + |
| 10367 |
" */\n" + |
| 10368 |
" {\n" + |
| 10369 |
" 'Value2': '2'\n" + |
| 10370 |
" });") |
| 10371 |
# END tests for brace position |
| 10372 |
|
| 10373 |
self.reset_options() |
| 10374 |
#============================================================ |
| 10375 |
self.options.preserve_newlines = True |
| 10376 |
bt("var a = 'foo' +\n 'bar';") |
| 10377 |
|
| 10378 |
bt('"foo""bar""baz"', '"foo"\n"bar"\n"baz"') |
| 10379 |
bt("'foo''bar''baz'", "'foo'\n'bar'\n'baz'") |
| 10380 |
bt("{\n get foo() {}\n}") |
| 10381 |
bt("{\n var a = get\n foo();\n}") |
| 10382 |
bt("{\n set foo() {}\n}") |
| 10383 |
bt("{\n var a = set\n foo();\n}") |
| 10384 |
bt("var x = {\n get function()\n}") |
| 10385 |
bt("var x = {\n set function()\n}") |
| 10386 |
|
| 10387 |
# According to my current research get/set have no special meaning outside of an object literal |
| 10388 |
bt("var x = set\n\na() {}", "var x = set\n\na() {}") |
| 10389 |
bt("var x = set\n\nfunction() {}", "var x = set\n\nfunction() {}") |
| 10390 |
|
| 10391 |
bt('for () /abc/.test()') |
| 10392 |
bt('if (k) /aaa/m.test(v) && l();') |
| 10393 |
bt('switch (true) {\n case /swf/i.test(foo):\n bar();\n}') |
| 10394 |
bt('createdAt = {\n type: Date,\n default: Date.now\n}') |
| 10395 |
bt('switch (createdAt) {\n case a:\n Date,\n default:\n Date.now\n}') |
| 10396 |
|
| 10397 |
self.reset_options() |
| 10398 |
#============================================================ |
| 10399 |
|
| 10400 |
|
| 10401 |
def decodesto(self, input, expectation=None): |
| 10402 |
if expectation is None: |
| 10403 |
expectation = input |
| 10404 |
|
| 10405 |
self.assertMultiLineEqual( |
| 10406 |
jsbeautifier.beautify(input, self.options), expectation) |
| 10407 |
|
| 10408 |
# if the expected is different from input, run it again |
| 10409 |
# expected output should be unchanged when run twice. |
| 10410 |
if not expectation is None: |
| 10411 |
self.assertMultiLineEqual( |
| 10412 |
jsbeautifier.beautify(expectation, self.options), expectation) |
| 10413 |
|
| 10414 |
if self.options is None or not isinstance(self.options, (dict, tuple)): |
| 10415 |
# Everywhere we do newlines, they should be replaced with opts.eol |
| 10416 |
self.options.eol = '\r\\n' |
| 10417 |
expectation = expectation.replace('\n', '\r\n') |
| 10418 |
self.options.disabled = True |
| 10419 |
self.assertMultiLineEqual( |
| 10420 |
jsbeautifier.beautify(input, self.options), input or '') |
| 10421 |
self.assertMultiLineEqual( |
| 10422 |
jsbeautifier.beautify('\n\n' + expectation, self.options), '\n\n' + expectation) |
| 10423 |
self.options.disabled = False; |
| 10424 |
self.assertMultiLineEqual( |
| 10425 |
jsbeautifier.beautify(input, self.options), expectation) |
| 10426 |
if input and input.find('\n') != -1: |
| 10427 |
input = input.replace('\n', '\r\n') |
| 10428 |
self.assertMultiLineEqual( |
| 10429 |
jsbeautifier.beautify(input, self.options), expectation) |
| 10430 |
# Ensure support for auto eol detection |
| 10431 |
self.options.eol = 'auto' |
| 10432 |
self.assertMultiLineEqual( |
| 10433 |
jsbeautifier.beautify(input, self.options), expectation) |
| 10434 |
self.options.eol = '\n' |
| 10435 |
|
| 10436 |
def wrap(self, text): |
| 10437 |
return self.wrapregex.sub(' \\1', text) |
| 10438 |
|
| 10439 |
def bt(self, input, expectation=None): |
| 10440 |
if expectation is None: |
| 10441 |
expectation = input |
| 10442 |
|
| 10443 |
self.decodesto(input, expectation) |
| 10444 |
# If we set raw, input should be unchanged |
| 10445 |
self.options.test_output_raw = True |
| 10446 |
if self.options.end_with_newline: |
| 10447 |
self.decodesto(input, input) |
| 10448 |
self.options.test_output_raw = False |
| 10449 |
|
| 10450 |
current_indent_size = None |
| 10451 |
if self.options.js and self.options.js['indent_size']: |
| 10452 |
current_indent_size = self.options.js['indent_size'] |
| 10453 |
|
| 10454 |
if not current_indent_size: |
| 10455 |
current_indent_size = self.options.indent_size |
| 10456 |
|
| 10457 |
if current_indent_size == 4 and input: |
| 10458 |
wrapped_input = '{\n%s\n foo = bar;\n}' % self.wrap(input) |
| 10459 |
wrapped_expect = '{\n%s\n foo = bar;\n}' % self.wrap(expectation) |
| 10460 |
self.decodesto(wrapped_input, wrapped_expect) |
| 10461 |
|
| 10462 |
# If we set raw, input should be unchanged |
| 10463 |
self.options.test_output_raw = True |
| 10464 |
if self.options.end_with_newline: |
| 10465 |
self.decodesto(wrapped_input, wrapped_input) |
| 10466 |
self.options.test_output_raw = False |
| 10467 |
|
| 10468 |
|
| 10469 |
if __name__ == '__main__': |
| 10470 |
unittest.main() |