"Fossies" - the Fresh Open Source Software Archive

Member "js-beautify-1.14.0/python/jsbeautifier/tests/generated/tests.py" (14 Jun 2021, 313274 Bytes) of package /linux/www/js-beautify-1.14.0.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Python source code syntax highlighting (style: standard) with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file. See also the latest Fossies "Diffs" side-by-side code changes report for "tests.py": 1.13.13_vs_1.14.0.

    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 six
   39 import copy
   40 
   41 class TestJSBeautifier(unittest.TestCase):
   42     options = None
   43 
   44     @classmethod
   45     def setUpClass(cls):
   46         pass
   47         cls.wrapregex = re.compile('^(.+)$', re.MULTILINE)
   48 
   49     def reset_options(self):
   50         true = True
   51         false = False
   52 
   53         default_options = jsbeautifier.default_options()
   54         default_options.indent_size = 4
   55         default_options.indent_char = ' '
   56         default_options.preserve_newlines = true
   57         default_options.jslint_happy = false
   58         default_options.indent_level = 0
   59         default_options.break_chained_methods = false
   60         default_options.eol = '\n'
   61 
   62         default_options.indent_size = 4
   63         default_options.indent_char = ' '
   64         default_options.preserve_newlines = true
   65         default_options.jslint_happy = false
   66 
   67         self.options = copy.copy(default_options)
   68 
   69     def test_unescape(self):
   70         # Test cases contributed by <chrisjshull on GitHub.com>
   71         test_fragment = self.decodesto
   72         self.reset_options()
   73         bt = self.bt
   74 
   75         def unicode_char(value):
   76             return six.unichr(value)
   77 
   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("'\\s'") # == '\s' in the js source
   82         bt('"•"')
   83         bt('"—"')
   84         bt('"\\x41\\x42\\x43\\x01"', '"\\x41\\x42\\x43\\x01"')
   85         bt('"\\u2022"', '"\\u2022"')
   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         test_fragment('"\\x22\\x27",\'\\x22\\x27\',"\\x5c",\'\\x5c\',"\\xff and \\xzz","unicode \\u0000 \\u0022 \\u0027 \\u005c \\uffff \\uzzzz"', '"\\x22\\x27", \'\\x22\\x27\', "\\x5c", \'\\x5c\', "\\xff and \\xzz", "unicode \\u0000 \\u0022 \\u0027 \\u005c \\uffff \\uzzzz"')
   90 
   91         self.options.unescape_strings = True
   92 
   93         bt('"\\x41\\x42\\x43\\x01"', '"ABC\\x01"')
   94         test_fragment('"\\x20\\x40\\x4a"', '" @J"')
   95         test_fragment('"\\xff\\x40\\x4a"')
   96         test_fragment('"\\u0072\\u016B\\u0137\\u012B\\u0074\\u0069\\u0073"', six.u('"\u0072\u016B\u0137\u012B\u0074\u0069\u0073"'))
   97 
   98         bt('a = /\s+/')
   99         test_fragment('"\\x22\\x27",\'\\x22\\x27\',"\\x5c",\'\\x5c\',"\\xff","unicode \\u0000 \\u0022 \\u0027 \\u005c \\uffff"',
  100            '"\\"\\\'", \'\\"\\\'\', "\\\\", \'\\\\\', "\\xff", "unicode \\u0000 \\" \\\' \\\\ ' + unicode_char(0xffff) + '"')
  101 
  102         # For error case, return the string unchanged
  103         test_fragment('"\\x22\\x27",\'\\x22\\x27\',"\\x5c",\'\\x5c\',"\\xff and \\xzz","unicode \\u0000 \\u0022 \\u0027 \\u005c \\uffff \\uzzzz"',
  104             '"\\"\\\'", \'\\"\\\'\', "\\\\", \'\\\\\', "\\xff and \\xzz", "unicode \\u0000 \\u0022 \\u0027 \\u005c \\uffff \\uzzzz"')
  105 
  106         self.options.unescape_strings = False
  107 
  108     def test_beautifier(self):
  109         test_fragment = self.decodesto
  110         bt = self.bt
  111 
  112         true = True
  113         false = False
  114 
  115         def unicode_char(value):
  116             return six.unichr(value)
  117 
  118         ##============================================================
  119         # Line wrap test inputs
  120         #....---------1---------2---------3---------4---------5---------6---------7
  121         #....1234567890123456789012345678901234567890123456789012345678901234567890
  122         wrap_input_1=(
  123             'foo.bar().baz().cucumber((f && "sass") || (leans && mean));\n' +
  124             'Test_very_long_variable_name_this_should_never_wrap\n.but_this_can\n' +
  125             'return between_return_and_expression_should_never_wrap.but_this_can\n' +
  126             'throw between_throw_and_expression_should_never_wrap.but_this_can\n' +
  127             'if (wraps_can_occur && inside_an_if_block) that_is_\n.okay();\n' +
  128             'object_literal = {\n' +
  129             '    propertx: first_token + 12345678.99999E-6,\n' +
  130             '    property: first_token_should_never_wrap + but_this_can,\n' +
  131             '    propertz: first_token_should_never_wrap + !but_this_can,\n' +
  132             '    proper: "first_token_should_never_wrap" + "but_this_can"\n' +
  133             '}');
  134 
  135         #....---------1---------2---------3---------4---------5---------6---------7
  136         #....1234567890123456789012345678901234567890123456789012345678901234567890
  137         wrap_input_2=(
  138             '{\n' +
  139             '    foo.bar().baz().cucumber((f && "sass") || (leans && mean));\n' +
  140             '    Test_very_long_variable_name_this_should_never_wrap\n.but_this_can\n' +
  141             '    return between_return_and_expression_should_never_wrap.but_this_can\n' +
  142             '    throw between_throw_and_expression_should_never_wrap.but_this_can\n' +
  143             '    if (wraps_can_occur && inside_an_if_block) that_is_\n.okay();\n' +
  144             '    object_literal = {\n' +
  145             '        propertx: first_token + 12345678.99999E-6,\n' +
  146             '        property: first_token_should_never_wrap + but_this_can,\n' +
  147             '        propertz: first_token_should_never_wrap + !but_this_can,\n' +
  148             '        proper: "first_token_should_never_wrap" + "but_this_can"\n' +
  149             '    }' +
  150             '}');
  151 
  152 
  153         #============================================================
  154         # Unicode Support
  155         self.reset_options()
  156         bt('var ' + unicode_char(3232) + '_' + unicode_char(3232) + ' = "hi";')
  157         bt(
  158             'var ' + unicode_char(228) + 'x = {\n' +
  159             '    ' + unicode_char(228) + 'rgerlich: true\n' +
  160             '};')
  161         bt(
  162             'var \\u00E4\\u0ca0\\u0cA0\\u0Ca0 = {\n' +
  163             '    \\u0ca0rgerlich: true\n' +
  164             '};')
  165         bt(
  166             'var \\u00E4add\\u0025 = {\n' +
  167             '    \\u0044rgerlich\\u0ca0: true\n' +
  168             '};')
  169         bt(
  170             'var' + unicode_char(160) + unicode_char(3232) + '_' + unicode_char(3232) + ' = "hi";',
  171             #  -- output --
  172             'var ' + unicode_char(3232) + '_' + unicode_char(3232) + ' = "hi";')
  173 
  174 
  175         #============================================================
  176         # Test template and continuation strings
  177         self.reset_options()
  178         bt('`This is a ${template} string.`')
  179         bt(
  180             '`This\n' +
  181             '  is\n' +
  182             '  a\n' +
  183             '  ${template}\n' +
  184             '  string.`')
  185         bt(
  186             'a = `This is a continuation\\\n' +
  187             'string.`')
  188         bt(
  189             'a = "This is a continuation\\\n' +
  190             'string."')
  191         bt(
  192             '`SELECT\n' +
  193             '  nextval(\'${this.options.schema ? `${this.options.schema}.` : \'\'}"${this.tableName}_${this.autoIncrementField}_seq"\'::regclass\n' +
  194             '  ) nextval;`')
  195         
  196         # Tests for #1030
  197         bt(
  198             'const composeUrl = (host) => {\n' +
  199             '    return `${host `test`}`;\n' +
  200             '};')
  201         bt(
  202             'const composeUrl = (host, api, key, data) => {\n' +
  203             '    switch (api) {\n' +
  204             '        case "Init":\n' +
  205             '            return `${host}/vwapi/Init?VWID=${key}&DATA=${encodeURIComponent(\n' +
  206             '                Object.keys(data).map((k) => `${k}=${ data[k]}` ).join(";")\n' +
  207             '            )}`;\n' +
  208             '        case "Pay":\n' +
  209             '            return `${host}/vwapi/Pay?SessionId=${par}`;\n' +
  210             '    };\n' +
  211             '};')
  212 
  213 
  214         #============================================================
  215         # Private Class Fields
  216         self.reset_options()
  217         bt('#foo')
  218         bt(
  219             'class X {\n' +
  220             '    #foo = null;\n' +
  221             '    get foo() {\n' +
  222             '        return this.#foo;\n' +
  223             '    }\n' +
  224             '}')
  225         bt(
  226             'class X {#foo=null;}',
  227             #  -- output --
  228             'class X {\n' +
  229             '    #foo = null;\n' +
  230             '}')
  231 
  232 
  233         #============================================================
  234         # ES7 Decorators
  235         self.reset_options()
  236         bt('@foo')
  237         bt('@foo(bar)')
  238         bt(
  239             '@foo(function(k, v) {\n' +
  240             '    implementation();\n' +
  241             '})')
  242 
  243 
  244         #============================================================
  245         # ES7 exponential
  246         self.reset_options()
  247         bt('x ** 2')
  248         bt('x ** -2')
  249 
  250 
  251         #============================================================
  252         # Spread operator
  253         self.reset_options()
  254         self.options.brace_style = "collapse,preserve-inline"
  255         bt('const m = { ...item, c: 3 };')
  256         bt(
  257             'const m = {\n' +
  258             '    ...item,\n' +
  259             '    c: 3\n' +
  260             '};')
  261         bt('const m = { c: 3, ...item };')
  262         bt('const m = [...item, 3];')
  263         bt('const m = [3, ...item];')
  264 
  265 
  266         #============================================================
  267         # Object literal shorthand functions
  268         self.reset_options()
  269         bt(
  270             'return {\n' +
  271             '    foo() {\n' +
  272             '        return 42;\n' +
  273             '    }\n' +
  274             '}')
  275         bt(
  276             'var foo = {\n' +
  277             '    * bar() {\n' +
  278             '        yield 42;\n' +
  279             '    }\n' +
  280             '};')
  281         bt(
  282             'var foo = {bar(){return 42;},*barGen(){yield 42;}};',
  283             #  -- output --
  284             'var foo = {\n' +
  285             '    bar() {\n' +
  286             '        return 42;\n' +
  287             '    },\n' +
  288             '    * barGen() {\n' +
  289             '        yield 42;\n' +
  290             '    }\n' +
  291             '};')
  292         
  293         # also handle generator shorthand in class - #1013
  294         bt(
  295             'class A {\n' +
  296             '    fn() {\n' +
  297             '        return true;\n' +
  298             '    }\n' +
  299             '\n' +
  300             '    * gen() {\n' +
  301             '        return true;\n' +
  302             '    }\n' +
  303             '}')
  304         bt(
  305             'class A {\n' +
  306             '    * gen() {\n' +
  307             '        return true;\n' +
  308             '    }\n' +
  309             '\n' +
  310             '    fn() {\n' +
  311             '        return true;\n' +
  312             '    }\n' +
  313             '}')
  314 
  315 
  316         #============================================================
  317         # End With Newline - (end_with_newline = "true")
  318         self.reset_options()
  319         self.options.end_with_newline = true
  320         test_fragment('', '\n')
  321         test_fragment('   return .5', '   return .5\n')
  322         test_fragment(
  323             '   \n' +
  324             '\n' +
  325             'return .5\n' +
  326             '\n' +
  327             '\n' +
  328             '\n',
  329             #  -- output --
  330             '   return .5\n')
  331         test_fragment('\n')
  332 
  333         # End With Newline - (end_with_newline = "false")
  334         self.reset_options()
  335         self.options.end_with_newline = false
  336         test_fragment('')
  337         test_fragment('   return .5')
  338         test_fragment(
  339             '   \n' +
  340             '\n' +
  341             'return .5\n' +
  342             '\n' +
  343             '\n' +
  344             '\n',
  345             #  -- output --
  346             '   return .5')
  347         test_fragment('\n', '')
  348 
  349 
  350         #============================================================
  351         # Support Indent Level Options and Base Indent Autodetection - ()
  352         self.reset_options()
  353         test_fragment('   a')
  354         test_fragment(
  355             '   function test(){\n' +
  356             '  console.log("this is a test");\n' +
  357             '}',
  358             #  -- output --
  359             '   function test() {\n' +
  360             '       console.log("this is a test");\n' +
  361             '   }')
  362         test_fragment(
  363             '   // This is a random comment\n' +
  364             'function test(){\n' +
  365             '  console.log("this is a test");\n' +
  366             '}',
  367             #  -- output --
  368             '   // This is a random comment\n' +
  369             '   function test() {\n' +
  370             '       console.log("this is a test");\n' +
  371             '   }')
  372 
  373         # Support Indent Level Options and Base Indent Autodetection - (indent_level = "0")
  374         self.reset_options()
  375         self.options.indent_level = 0
  376         test_fragment('   a')
  377         test_fragment(
  378             '   function test(){\n' +
  379             '  console.log("this is a test");\n' +
  380             '}',
  381             #  -- output --
  382             '   function test() {\n' +
  383             '       console.log("this is a test");\n' +
  384             '   }')
  385         test_fragment(
  386             '   // This is a random comment\n' +
  387             'function test(){\n' +
  388             '  console.log("this is a test");\n' +
  389             '}',
  390             #  -- output --
  391             '   // This is a random comment\n' +
  392             '   function test() {\n' +
  393             '       console.log("this is a test");\n' +
  394             '   }')
  395 
  396         # Support Indent Level Options and Base Indent Autodetection - (indent_level = "1")
  397         self.reset_options()
  398         self.options.indent_level = 1
  399         test_fragment('   a', '    a')
  400         test_fragment(
  401             '   function test(){\n' +
  402             '  console.log("this is a test");\n' +
  403             '}',
  404             #  -- output --
  405             '    function test() {\n' +
  406             '        console.log("this is a test");\n' +
  407             '    }')
  408         test_fragment(
  409             '   // This is a random comment\n' +
  410             'function test(){\n' +
  411             '  console.log("this is a test");\n' +
  412             '}',
  413             #  -- output --
  414             '    // This is a random comment\n' +
  415             '    function test() {\n' +
  416             '        console.log("this is a test");\n' +
  417             '    }')
  418 
  419         # Support Indent Level Options and Base Indent Autodetection - (indent_level = "2")
  420         self.reset_options()
  421         self.options.indent_level = 2
  422         test_fragment('a', '        a')
  423         test_fragment(
  424             'function test(){\n' +
  425             '  console.log("this is a test");\n' +
  426             '}',
  427             #  -- output --
  428             '        function test() {\n' +
  429             '            console.log("this is a test");\n' +
  430             '        }')
  431         test_fragment(
  432             '// This is a random comment\n' +
  433             'function test(){\n' +
  434             '  console.log("this is a test");\n' +
  435             '}',
  436             #  -- output --
  437             '        // This is a random comment\n' +
  438             '        function test() {\n' +
  439             '            console.log("this is a test");\n' +
  440             '        }')
  441 
  442         # Support Indent Level Options and Base Indent Autodetection - (indent_with_tabs = "true", indent_level = "2")
  443         self.reset_options()
  444         self.options.indent_with_tabs = true
  445         self.options.indent_level = 2
  446         test_fragment('a', '\t\ta')
  447         test_fragment(
  448             'function test(){\n' +
  449             '  console.log("this is a test");\n' +
  450             '}',
  451             #  -- output --
  452             '\t\tfunction test() {\n' +
  453             '\t\t\tconsole.log("this is a test");\n' +
  454             '\t\t}')
  455         test_fragment(
  456             '// This is a random comment\n' +
  457             'function test(){\n' +
  458             '  console.log("this is a test");\n' +
  459             '}',
  460             #  -- output --
  461             '\t\t// This is a random comment\n' +
  462             '\t\tfunction test() {\n' +
  463             '\t\t\tconsole.log("this is a test");\n' +
  464             '\t\t}')
  465 
  466         # Support Indent Level Options and Base Indent Autodetection - (indent_level = "0")
  467         self.reset_options()
  468         self.options.indent_level = 0
  469         test_fragment('\t   a')
  470         test_fragment(
  471             '\t   function test(){\n' +
  472             '  console.log("this is a test");\n' +
  473             '}',
  474             #  -- output --
  475             '\t   function test() {\n' +
  476             '\t       console.log("this is a test");\n' +
  477             '\t   }')
  478         test_fragment(
  479             '\t   // This is a random comment\n' +
  480             'function test(){\n' +
  481             '  console.log("this is a test");\n' +
  482             '}',
  483             #  -- output --
  484             '\t   // This is a random comment\n' +
  485             '\t   function test() {\n' +
  486             '\t       console.log("this is a test");\n' +
  487             '\t   }')
  488 
  489 
  490         #============================================================
  491         # Support simple language specific option inheritance/overriding - (js = "{ "indent_size": 3 }", css = "{ "indent_size": 5 }")
  492         self.reset_options()
  493         self.options.js = { 'indent_size': 3 }
  494         self.options.css = { 'indent_size': 5 }
  495         bt(
  496             'if (a == b) {\n' +
  497             '   test();\n' +
  498             '}')
  499 
  500         # Support simple language specific option inheritance/overriding - (html = "{ "js": { "indent_size": 3 }, "css": { "indent_size": 5 } }")
  501         self.reset_options()
  502         self.options.html = { 'js': { 'indent_size': 3 }, 'css': { 'indent_size': 5 } }
  503         bt(
  504             'if (a == b) {\n' +
  505             '    test();\n' +
  506             '}')
  507 
  508         # 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 }")
  509         self.reset_options()
  510         self.options.indent_size = 9
  511         self.options.html = { 'js': { 'indent_size': 3 }, 'css': { 'indent_size': 5 }, 'indent_size': 2}
  512         self.options.js = { 'indent_size': 4 }
  513         self.options.css = { 'indent_size': 3 }
  514         bt(
  515             'if (a == b) {\n' +
  516             '    test();\n' +
  517             '}')
  518 
  519 
  520         #============================================================
  521         # Brace style permutations - (brace_style = ""collapse,preserve-inline"")
  522         self.reset_options()
  523         self.options.brace_style = 'collapse,preserve-inline'
  524         bt(
  525             'var a ={a: 2};\n' +
  526             'var a ={a: 2};',
  527             #  -- output --
  528             'var a = { a: 2 };\n' +
  529             'var a = { a: 2 };')
  530         bt(
  531             '//case 1\n' +
  532             'if (a == 1){}\n' +
  533             '//case 2\n' +
  534             'else if (a == 2){}',
  535             #  -- output --
  536             '//case 1\n' +
  537             'if (a == 1) {}\n' +
  538             '//case 2\n' +
  539             'else if (a == 2) {}')
  540         bt('if(1){2}else{3}', 'if (1) { 2 } else { 3 }')
  541         bt('try{a();}catch(b){c();}catch(d){}finally{e();}', 'try { a(); } catch (b) { c(); } catch (d) {} finally { e(); }')
  542 
  543         # Brace style permutations - (brace_style = ""collapse,preserve-inline"")
  544         self.reset_options()
  545         self.options.brace_style = 'collapse,preserve-inline'
  546         bt(
  547             'var a =\n' +
  548             '{\n' +
  549             'a: 2\n' +
  550             '}\n' +
  551             ';\n' +
  552             'var a =\n' +
  553             '{\n' +
  554             'a: 2\n' +
  555             '}\n' +
  556             ';',
  557             #  -- output --
  558             'var a = {\n' +
  559             '    a: 2\n' +
  560             '};\n' +
  561             'var a = {\n' +
  562             '    a: 2\n' +
  563             '};')
  564         bt(
  565             '//case 1\n' +
  566             'if (a == 1)\n' +
  567             '{}\n' +
  568             '//case 2\n' +
  569             'else if (a == 2)\n' +
  570             '{}',
  571             #  -- output --
  572             '//case 1\n' +
  573             'if (a == 1) {}\n' +
  574             '//case 2\n' +
  575             'else if (a == 2) {}')
  576         bt(
  577             'if(1)\n' +
  578             '{\n' +
  579             '2\n' +
  580             '}\n' +
  581             'else\n' +
  582             '{\n' +
  583             '3\n' +
  584             '}',
  585             #  -- output --
  586             'if (1) {\n' +
  587             '    2\n' +
  588             '} else {\n' +
  589             '    3\n' +
  590             '}')
  591         bt(
  592             'try\n' +
  593             '{\n' +
  594             'a();\n' +
  595             '}\n' +
  596             'catch(b)\n' +
  597             '{\n' +
  598             'c();\n' +
  599             '}\n' +
  600             'catch(d)\n' +
  601             '{}\n' +
  602             'finally\n' +
  603             '{\n' +
  604             'e();\n' +
  605             '}',
  606             #  -- output --
  607             'try {\n' +
  608             '    a();\n' +
  609             '} catch (b) {\n' +
  610             '    c();\n' +
  611             '} catch (d) {} finally {\n' +
  612             '    e();\n' +
  613             '}')
  614 
  615         # Brace style permutations - ()
  616         self.reset_options()
  617         bt(
  618             'var a ={a: 2};\n' +
  619             'var a ={a: 2};',
  620             #  -- output --
  621             'var a = {\n' +
  622             '    a: 2\n' +
  623             '};\n' +
  624             'var a = {\n' +
  625             '    a: 2\n' +
  626             '};')
  627         bt(
  628             '//case 1\n' +
  629             'if (a == 1){}\n' +
  630             '//case 2\n' +
  631             'else if (a == 2){}',
  632             #  -- output --
  633             '//case 1\n' +
  634             'if (a == 1) {}\n' +
  635             '//case 2\n' +
  636             'else if (a == 2) {}')
  637         bt(
  638             'if(1){2}else{3}',
  639             #  -- output --
  640             'if (1) {\n' +
  641             '    2\n' +
  642             '} else {\n' +
  643             '    3\n' +
  644             '}')
  645         bt(
  646             'try{a();}catch(b){c();}catch(d){}finally{e();}',
  647             #  -- output --
  648             'try {\n' +
  649             '    a();\n' +
  650             '} catch (b) {\n' +
  651             '    c();\n' +
  652             '} catch (d) {} finally {\n' +
  653             '    e();\n' +
  654             '}')
  655 
  656         # Brace style permutations - (brace_style = ""collapse"")
  657         self.reset_options()
  658         self.options.brace_style = 'collapse'
  659         bt(
  660             'var a ={a: 2};\n' +
  661             'var a ={a: 2};',
  662             #  -- output --
  663             'var a = {\n' +
  664             '    a: 2\n' +
  665             '};\n' +
  666             'var a = {\n' +
  667             '    a: 2\n' +
  668             '};')
  669         bt(
  670             '//case 1\n' +
  671             'if (a == 1){}\n' +
  672             '//case 2\n' +
  673             'else if (a == 2){}',
  674             #  -- output --
  675             '//case 1\n' +
  676             'if (a == 1) {}\n' +
  677             '//case 2\n' +
  678             'else if (a == 2) {}')
  679         bt(
  680             'if(1){2}else{3}',
  681             #  -- output --
  682             'if (1) {\n' +
  683             '    2\n' +
  684             '} else {\n' +
  685             '    3\n' +
  686             '}')
  687         bt(
  688             'try{a();}catch(b){c();}catch(d){}finally{e();}',
  689             #  -- output --
  690             'try {\n' +
  691             '    a();\n' +
  692             '} catch (b) {\n' +
  693             '    c();\n' +
  694             '} catch (d) {} finally {\n' +
  695             '    e();\n' +
  696             '}')
  697 
  698         # Brace style permutations - (brace_style = ""collapse"")
  699         self.reset_options()
  700         self.options.brace_style = 'collapse'
  701         bt(
  702             'var a =\n' +
  703             '{\n' +
  704             'a: 2\n' +
  705             '}\n' +
  706             ';\n' +
  707             'var a =\n' +
  708             '{\n' +
  709             'a: 2\n' +
  710             '}\n' +
  711             ';',
  712             #  -- output --
  713             'var a = {\n' +
  714             '    a: 2\n' +
  715             '};\n' +
  716             'var a = {\n' +
  717             '    a: 2\n' +
  718             '};')
  719         bt(
  720             '//case 1\n' +
  721             'if (a == 1)\n' +
  722             '{}\n' +
  723             '//case 2\n' +
  724             'else if (a == 2)\n' +
  725             '{}',
  726             #  -- output --
  727             '//case 1\n' +
  728             'if (a == 1) {}\n' +
  729             '//case 2\n' +
  730             'else if (a == 2) {}')
  731         bt(
  732             'if(1)\n' +
  733             '{\n' +
  734             '2\n' +
  735             '}\n' +
  736             'else\n' +
  737             '{\n' +
  738             '3\n' +
  739             '}',
  740             #  -- output --
  741             'if (1) {\n' +
  742             '    2\n' +
  743             '} else {\n' +
  744             '    3\n' +
  745             '}')
  746         bt(
  747             'try\n' +
  748             '{\n' +
  749             'a();\n' +
  750             '}\n' +
  751             'catch(b)\n' +
  752             '{\n' +
  753             'c();\n' +
  754             '}\n' +
  755             'catch(d)\n' +
  756             '{}\n' +
  757             'finally\n' +
  758             '{\n' +
  759             'e();\n' +
  760             '}',
  761             #  -- output --
  762             'try {\n' +
  763             '    a();\n' +
  764             '} catch (b) {\n' +
  765             '    c();\n' +
  766             '} catch (d) {} finally {\n' +
  767             '    e();\n' +
  768             '}')
  769 
  770 
  771         #============================================================
  772         # Comma-first option - (comma_first = "false")
  773         self.reset_options()
  774         self.options.comma_first = false
  775         bt(
  776             '{a:1, b:2}',
  777             #  -- output --
  778             '{\n' +
  779             '    a: 1,\n' +
  780             '    b: 2\n' +
  781             '}')
  782         bt(
  783             'var a=1, b=c[d], e=6;',
  784             #  -- output --
  785             'var a = 1,\n' +
  786             '    b = c[d],\n' +
  787             '    e = 6;')
  788         bt(
  789             'for(var a=1,b=2,c=3;d<3;d++)\n' +
  790             'e',
  791             #  -- output --
  792             'for (var a = 1, b = 2, c = 3; d < 3; d++)\n' +
  793             '    e')
  794         bt(
  795             'for(var a=1,b=2,\n' +
  796             'c=3;d<3;d++)\n' +
  797             'e',
  798             #  -- output --
  799             'for (var a = 1, b = 2,\n' +
  800             '        c = 3; d < 3; d++)\n' +
  801             '    e')
  802         bt(
  803             'function foo() {\n' +
  804             '    return [\n' +
  805             '        "one",\n' +
  806             '        "two"\n' +
  807             '    ];\n' +
  808             '}')
  809         bt(
  810             'a=[[1,2],[4,5],[7,8]]',
  811             #  -- output --
  812             'a = [\n' +
  813             '    [1, 2],\n' +
  814             '    [4, 5],\n' +
  815             '    [7, 8]\n' +
  816             ']')
  817         bt(
  818             'a=[[1,2],[4,5],[7,8],]',
  819             #  -- output --
  820             'a = [\n' +
  821             '    [1, 2],\n' +
  822             '    [4, 5],\n' +
  823             '    [7, 8],\n' +
  824             ']')
  825         bt(
  826             'a=[[1,2],[4,5],function(){},[7,8]]',
  827             #  -- output --
  828             'a = [\n' +
  829             '    [1, 2],\n' +
  830             '    [4, 5],\n' +
  831             '    function() {},\n' +
  832             '    [7, 8]\n' +
  833             ']')
  834         bt(
  835             'a=[[1,2],[4,5],function(){},function(){},[7,8]]',
  836             #  -- output --
  837             'a = [\n' +
  838             '    [1, 2],\n' +
  839             '    [4, 5],\n' +
  840             '    function() {},\n' +
  841             '    function() {},\n' +
  842             '    [7, 8]\n' +
  843             ']')
  844         bt(
  845             'a=[[1,2],[4,5],function(){},[7,8]]',
  846             #  -- output --
  847             'a = [\n' +
  848             '    [1, 2],\n' +
  849             '    [4, 5],\n' +
  850             '    function() {},\n' +
  851             '    [7, 8]\n' +
  852             ']')
  853         bt('a=[b,c,function(){},function(){},d]', 'a = [b, c, function() {}, function() {}, d]')
  854         bt(
  855             'a=[b,c,\n' +
  856             'function(){},function(){},d]',
  857             #  -- output --
  858             'a = [b, c,\n' +
  859             '    function() {},\n' +
  860             '    function() {},\n' +
  861             '    d\n' +
  862             ']')
  863         bt('a=[a[1],b[4],c[d[7]]]', 'a = [a[1], b[4], c[d[7]]]')
  864         bt('[1,2,[3,4,[5,6],7],8]', '[1, 2, [3, 4, [5, 6], 7], 8]')
  865         bt(
  866             '[[["1","2"],["3","4"]],[["5","6","7"],["8","9","0"]],[["1","2","3"],["4","5","6","7"],["8","9","0"]]]',
  867             #  -- output --
  868             '[\n' +
  869             '    [\n' +
  870             '        ["1", "2"],\n' +
  871             '        ["3", "4"]\n' +
  872             '    ],\n' +
  873             '    [\n' +
  874             '        ["5", "6", "7"],\n' +
  875             '        ["8", "9", "0"]\n' +
  876             '    ],\n' +
  877             '    [\n' +
  878             '        ["1", "2", "3"],\n' +
  879             '        ["4", "5", "6", "7"],\n' +
  880             '        ["8", "9", "0"]\n' +
  881             '    ]\n' +
  882             ']')
  883         bt(
  884             'changeCollection.add({\n' +
  885             '    name: "Jonathan" // New line inserted after this line on every save\n' +
  886             '    , age: 25\n' +
  887             '});',
  888             #  -- output --
  889             'changeCollection.add({\n' +
  890             '    name: "Jonathan" // New line inserted after this line on every save\n' +
  891             '        ,\n' +
  892             '    age: 25\n' +
  893             '});')
  894         bt(
  895             'changeCollection.add(\n' +
  896             '    function() {\n' +
  897             '        return true;\n' +
  898             '    },\n' +
  899             '    function() {\n' +
  900             '        return true;\n' +
  901             '    }\n' +
  902             ');')
  903 
  904         # Comma-first option - (comma_first = "true")
  905         self.reset_options()
  906         self.options.comma_first = true
  907         bt(
  908             '{a:1, b:2}',
  909             #  -- output --
  910             '{\n' +
  911             '    a: 1\n' +
  912             '    , b: 2\n' +
  913             '}')
  914         bt(
  915             'var a=1, b=c[d], e=6;',
  916             #  -- output --
  917             'var a = 1\n' +
  918             '    , b = c[d]\n' +
  919             '    , e = 6;')
  920         bt(
  921             'for(var a=1,b=2,c=3;d<3;d++)\n' +
  922             'e',
  923             #  -- output --
  924             'for (var a = 1, b = 2, c = 3; d < 3; d++)\n' +
  925             '    e')
  926         bt(
  927             'for(var a=1,b=2,\n' +
  928             'c=3;d<3;d++)\n' +
  929             'e',
  930             #  -- output --
  931             'for (var a = 1, b = 2\n' +
  932             '        , c = 3; d < 3; d++)\n' +
  933             '    e')
  934         bt(
  935             'function foo() {\n' +
  936             '    return [\n' +
  937             '        "one"\n' +
  938             '        , "two"\n' +
  939             '    ];\n' +
  940             '}')
  941         bt(
  942             'a=[[1,2],[4,5],[7,8]]',
  943             #  -- output --
  944             'a = [\n' +
  945             '    [1, 2]\n' +
  946             '    , [4, 5]\n' +
  947             '    , [7, 8]\n' +
  948             ']')
  949         bt(
  950             'a=[[1,2],[4,5],[7,8],]',
  951             #  -- output --
  952             'a = [\n' +
  953             '    [1, 2]\n' +
  954             '    , [4, 5]\n' +
  955             '    , [7, 8]\n' +
  956             ', ]')
  957         bt(
  958             'a=[[1,2],[4,5],function(){},[7,8]]',
  959             #  -- output --
  960             'a = [\n' +
  961             '    [1, 2]\n' +
  962             '    , [4, 5]\n' +
  963             '    , function() {}\n' +
  964             '    , [7, 8]\n' +
  965             ']')
  966         bt(
  967             'a=[[1,2],[4,5],function(){},function(){},[7,8]]',
  968             #  -- output --
  969             'a = [\n' +
  970             '    [1, 2]\n' +
  971             '    , [4, 5]\n' +
  972             '    , function() {}\n' +
  973             '    , function() {}\n' +
  974             '    , [7, 8]\n' +
  975             ']')
  976         bt(
  977             'a=[[1,2],[4,5],function(){},[7,8]]',
  978             #  -- output --
  979             'a = [\n' +
  980             '    [1, 2]\n' +
  981             '    , [4, 5]\n' +
  982             '    , function() {}\n' +
  983             '    , [7, 8]\n' +
  984             ']')
  985         bt('a=[b,c,function(){},function(){},d]', 'a = [b, c, function() {}, function() {}, d]')
  986         bt(
  987             'a=[b,c,\n' +
  988             'function(){},function(){},d]',
  989             #  -- output --
  990             'a = [b, c\n' +
  991             '    , function() {}\n' +
  992             '    , function() {}\n' +
  993             '    , d\n' +
  994             ']')
  995         bt('a=[a[1],b[4],c[d[7]]]', 'a = [a[1], b[4], c[d[7]]]')
  996         bt('[1,2,[3,4,[5,6],7],8]', '[1, 2, [3, 4, [5, 6], 7], 8]')
  997         bt(
  998             '[[["1","2"],["3","4"]],[["5","6","7"],["8","9","0"]],[["1","2","3"],["4","5","6","7"],["8","9","0"]]]',
  999             #  -- output --
 1000             '[\n' +
 1001             '    [\n' +
 1002             '        ["1", "2"]\n' +
 1003             '        , ["3", "4"]\n' +
 1004             '    ]\n' +
 1005             '    , [\n' +
 1006             '        ["5", "6", "7"]\n' +
 1007             '        , ["8", "9", "0"]\n' +
 1008             '    ]\n' +
 1009             '    , [\n' +
 1010             '        ["1", "2", "3"]\n' +
 1011             '        , ["4", "5", "6", "7"]\n' +
 1012             '        , ["8", "9", "0"]\n' +
 1013             '    ]\n' +
 1014             ']')
 1015         bt(
 1016             'changeCollection.add({\n' +
 1017             '    name: "Jonathan" // New line inserted after this line on every save\n' +
 1018             '    , age: 25\n' +
 1019             '});')
 1020         bt(
 1021             'changeCollection.add(\n' +
 1022             '    function() {\n' +
 1023             '        return true;\n' +
 1024             '    },\n' +
 1025             '    function() {\n' +
 1026             '        return true;\n' +
 1027             '    }\n' +
 1028             ');',
 1029             #  -- output --
 1030             'changeCollection.add(\n' +
 1031             '    function() {\n' +
 1032             '        return true;\n' +
 1033             '    }\n' +
 1034             '    , function() {\n' +
 1035             '        return true;\n' +
 1036             '    }\n' +
 1037             ');')
 1038 
 1039 
 1040         #============================================================
 1041         # Unindent chained functions - (unindent_chained_methods = "true")
 1042         self.reset_options()
 1043         self.options.unindent_chained_methods = true
 1044         bt(
 1045             'f().f().f()\n' +
 1046             '    .f().f();',
 1047             #  -- output --
 1048             'f().f().f()\n' +
 1049             '.f().f();')
 1050         bt(
 1051             'f()\n' +
 1052             '    .f()\n' +
 1053             '    .f();',
 1054             #  -- output --
 1055             'f()\n' +
 1056             '.f()\n' +
 1057             '.f();')
 1058         bt(
 1059             'f(function() {\n' +
 1060             '    f()\n' +
 1061             '        .f()\n' +
 1062             '        .f();\n' +
 1063             '});',
 1064             #  -- output --
 1065             'f(function() {\n' +
 1066             '    f()\n' +
 1067             '    .f()\n' +
 1068             '    .f();\n' +
 1069             '});')
 1070         
 1071         # regression test for fix #1378
 1072         bt(
 1073             'f(function() {\n' +
 1074             '    if(g === 1)\n' +
 1075             '        g = 0;\n' +
 1076             '    else\n' +
 1077             '        g = 1;\n' +
 1078             '\n' +
 1079             '    f()\n' +
 1080             '        .f()\n' +
 1081             '        .f();\n' +
 1082             '});',
 1083             #  -- output --
 1084             'f(function() {\n' +
 1085             '    if (g === 1)\n' +
 1086             '        g = 0;\n' +
 1087             '    else\n' +
 1088             '        g = 1;\n' +
 1089             '\n' +
 1090             '    f()\n' +
 1091             '    .f()\n' +
 1092             '    .f();\n' +
 1093             '});')
 1094         
 1095         # regression test for fix #1533
 1096         bt(
 1097             'angular.module("test").controller("testCtrl", function($scope) {\n' +
 1098             '    $scope.tnew;\n' +
 1099             '    $scope.toggle_tnew = function() {\n' +
 1100             '        $scope.mode = 0;\n' +
 1101             '        if (!$scope.tnew) {\n' +
 1102             '            $scope.tnew = {};\n' +
 1103             '        } else $scope.tnew = null;\n' +
 1104             '    }\n' +
 1105             '    $scope.fn = function() {\n' +
 1106             '        return null;\n' +
 1107             '    }\n' +
 1108             '});')
 1109 
 1110 
 1111         #============================================================
 1112         # Space in parens tests - (space_in_paren = "false", space_in_empty_paren = "false")
 1113         self.reset_options()
 1114         self.options.space_in_paren = false
 1115         self.options.space_in_empty_paren = false
 1116         bt('if(p) foo(a,b);', 'if (p) foo(a, b);')
 1117         bt(
 1118             'try{while(true){willThrow()}}catch(result)switch(result){case 1:++result }',
 1119             #  -- output --
 1120             'try {\n' +
 1121             '    while (true) {\n' +
 1122             '        willThrow()\n' +
 1123             '    }\n' +
 1124             '} catch (result) switch (result) {\n' +
 1125             '    case 1:\n' +
 1126             '        ++result\n' +
 1127             '}')
 1128         bt('((e/((a+(b)*c)-d))^2)*5;', '((e / ((a + (b) * c) - d)) ^ 2) * 5;')
 1129         bt(
 1130             'function f(a,b) {if(a) b()}function g(a,b) {if(!a) b()}',
 1131             #  -- output --
 1132             'function f(a, b) {\n' +
 1133             '    if (a) b()\n' +
 1134             '}\n' +
 1135             '\n' +
 1136             'function g(a, b) {\n' +
 1137             '    if (!a) b()\n' +
 1138             '}')
 1139         bt('a=[][    ](  );', 'a = [][]();')
 1140         bt('a=()(    )[  ];', 'a = ()()[];')
 1141         bt('a=[b,c,d];', 'a = [b, c, d];')
 1142         bt('a= f[b];', 'a = f[b];')
 1143         bt(
 1144             '{\n' +
 1145             '    files: a[][ {\n' +
 1146             '        expand: true,\n' +
 1147             '        cwd: "www/gui/",\n' +
 1148             '        src: b(c)[ "im/design_standards/*.*" ],\n' +
 1149             '        dest: "www/gui/build"\n' +
 1150             '    } ]\n' +
 1151             '}',
 1152             #  -- output --
 1153             '{\n' +
 1154             '    files: a[][{\n' +
 1155             '        expand: true,\n' +
 1156             '        cwd: "www/gui/",\n' +
 1157             '        src: b(c)["im/design_standards/*.*"],\n' +
 1158             '        dest: "www/gui/build"\n' +
 1159             '    }]\n' +
 1160             '}')
 1161 
 1162         # Space in parens tests - (space_in_paren = "false", space_in_empty_paren = "true")
 1163         self.reset_options()
 1164         self.options.space_in_paren = false
 1165         self.options.space_in_empty_paren = true
 1166         bt('if(p) foo(a,b);', 'if (p) foo(a, b);')
 1167         bt(
 1168             'try{while(true){willThrow()}}catch(result)switch(result){case 1:++result }',
 1169             #  -- output --
 1170             'try {\n' +
 1171             '    while (true) {\n' +
 1172             '        willThrow()\n' +
 1173             '    }\n' +
 1174             '} catch (result) switch (result) {\n' +
 1175             '    case 1:\n' +
 1176             '        ++result\n' +
 1177             '}')
 1178         bt('((e/((a+(b)*c)-d))^2)*5;', '((e / ((a + (b) * c) - d)) ^ 2) * 5;')
 1179         bt(
 1180             'function f(a,b) {if(a) b()}function g(a,b) {if(!a) b()}',
 1181             #  -- output --
 1182             'function f(a, b) {\n' +
 1183             '    if (a) b()\n' +
 1184             '}\n' +
 1185             '\n' +
 1186             'function g(a, b) {\n' +
 1187             '    if (!a) b()\n' +
 1188             '}')
 1189         bt('a=[][    ](  );', 'a = [][]();')
 1190         bt('a=()(    )[  ];', 'a = ()()[];')
 1191         bt('a=[b,c,d];', 'a = [b, c, d];')
 1192         bt('a= f[b];', 'a = f[b];')
 1193         bt(
 1194             '{\n' +
 1195             '    files: a[][ {\n' +
 1196             '        expand: true,\n' +
 1197             '        cwd: "www/gui/",\n' +
 1198             '        src: b(c)[ "im/design_standards/*.*" ],\n' +
 1199             '        dest: "www/gui/build"\n' +
 1200             '    } ]\n' +
 1201             '}',
 1202             #  -- output --
 1203             '{\n' +
 1204             '    files: a[][{\n' +
 1205             '        expand: true,\n' +
 1206             '        cwd: "www/gui/",\n' +
 1207             '        src: b(c)["im/design_standards/*.*"],\n' +
 1208             '        dest: "www/gui/build"\n' +
 1209             '    }]\n' +
 1210             '}')
 1211 
 1212         # Space in parens tests - (space_in_paren = "true", space_in_empty_paren = "false")
 1213         self.reset_options()
 1214         self.options.space_in_paren = true
 1215         self.options.space_in_empty_paren = false
 1216         bt('if(p) foo(a,b);', 'if ( p ) foo( a, b );')
 1217         bt(
 1218             'try{while(true){willThrow()}}catch(result)switch(result){case 1:++result }',
 1219             #  -- output --
 1220             'try {\n' +
 1221             '    while ( true ) {\n' +
 1222             '        willThrow()\n' +
 1223             '    }\n' +
 1224             '} catch ( result ) switch ( result ) {\n' +
 1225             '    case 1:\n' +
 1226             '        ++result\n' +
 1227             '}')
 1228         bt('((e/((a+(b)*c)-d))^2)*5;', '( ( e / ( ( a + ( b ) * c ) - d ) ) ^ 2 ) * 5;')
 1229         bt(
 1230             'function f(a,b) {if(a) b()}function g(a,b) {if(!a) b()}',
 1231             #  -- output --
 1232             'function f( a, b ) {\n' +
 1233             '    if ( a ) b()\n' +
 1234             '}\n' +
 1235             '\n' +
 1236             'function g( a, b ) {\n' +
 1237             '    if ( !a ) b()\n' +
 1238             '}')
 1239         bt('a=[][    ](  );', 'a = [][]();')
 1240         bt('a=()(    )[  ];', 'a = ()()[];')
 1241         bt('a=[b,c,d];', 'a = [ b, c, d ];')
 1242         bt('a= f[b];', 'a = f[ b ];')
 1243         bt(
 1244             '{\n' +
 1245             '    files: a[][ {\n' +
 1246             '        expand: true,\n' +
 1247             '        cwd: "www/gui/",\n' +
 1248             '        src: b(c)[ "im/design_standards/*.*" ],\n' +
 1249             '        dest: "www/gui/build"\n' +
 1250             '    } ]\n' +
 1251             '}',
 1252             #  -- output --
 1253             '{\n' +
 1254             '    files: a[][ {\n' +
 1255             '        expand: true,\n' +
 1256             '        cwd: "www/gui/",\n' +
 1257             '        src: b( c )[ "im/design_standards/*.*" ],\n' +
 1258             '        dest: "www/gui/build"\n' +
 1259             '    } ]\n' +
 1260             '}')
 1261 
 1262         # Space in parens tests - (space_in_paren = "true", space_in_empty_paren = "true")
 1263         self.reset_options()
 1264         self.options.space_in_paren = true
 1265         self.options.space_in_empty_paren = true
 1266         bt('if(p) foo(a,b);', 'if ( p ) foo( a, b );')
 1267         bt(
 1268             'try{while(true){willThrow()}}catch(result)switch(result){case 1:++result }',
 1269             #  -- output --
 1270             'try {\n' +
 1271             '    while ( true ) {\n' +
 1272             '        willThrow( )\n' +
 1273             '    }\n' +
 1274             '} catch ( result ) switch ( result ) {\n' +
 1275             '    case 1:\n' +
 1276             '        ++result\n' +
 1277             '}')
 1278         bt('((e/((a+(b)*c)-d))^2)*5;', '( ( e / ( ( a + ( b ) * c ) - d ) ) ^ 2 ) * 5;')
 1279         bt(
 1280             'function f(a,b) {if(a) b()}function g(a,b) {if(!a) b()}',
 1281             #  -- output --
 1282             'function f( a, b ) {\n' +
 1283             '    if ( a ) b( )\n' +
 1284             '}\n' +
 1285             '\n' +
 1286             'function g( a, b ) {\n' +
 1287             '    if ( !a ) b( )\n' +
 1288             '}')
 1289         bt('a=[][    ](  );', 'a = [ ][ ]( );')
 1290         bt('a=()(    )[  ];', 'a = ( )( )[ ];')
 1291         bt('a=[b,c,d];', 'a = [ b, c, d ];')
 1292         bt('a= f[b];', 'a = f[ b ];')
 1293         bt(
 1294             '{\n' +
 1295             '    files: a[][ {\n' +
 1296             '        expand: true,\n' +
 1297             '        cwd: "www/gui/",\n' +
 1298             '        src: b(c)[ "im/design_standards/*.*" ],\n' +
 1299             '        dest: "www/gui/build"\n' +
 1300             '    } ]\n' +
 1301             '}',
 1302             #  -- output --
 1303             '{\n' +
 1304             '    files: a[ ][ {\n' +
 1305             '        expand: true,\n' +
 1306             '        cwd: "www/gui/",\n' +
 1307             '        src: b( c )[ "im/design_standards/*.*" ],\n' +
 1308             '        dest: "www/gui/build"\n' +
 1309             '    } ]\n' +
 1310             '}')
 1311 
 1312 
 1313         #============================================================
 1314         # general preserve_newlines tests - (preserve_newlines = "false")
 1315         self.reset_options()
 1316         self.options.preserve_newlines = false
 1317         bt(
 1318             'if (foo) // comment\n' +
 1319             '    bar();')
 1320         bt(
 1321             'if (foo) // comment\n' +
 1322             '    bar();')
 1323         bt(
 1324             'if (foo) // comment\n' +
 1325             '    (bar());')
 1326         bt(
 1327             'if (foo) // comment\n' +
 1328             '    (bar());')
 1329         bt(
 1330             'if (foo) // comment\n' +
 1331             '    /asdf/;')
 1332         bt(
 1333             'this.oa = new OAuth(\n' +
 1334             '    _requestToken,\n' +
 1335             '    _accessToken,\n' +
 1336             '    consumer_key\n' +
 1337             ');',
 1338             #  -- output --
 1339             'this.oa = new OAuth(_requestToken, _accessToken, consumer_key);')
 1340         bt(
 1341             'foo = {\n' +
 1342             '    x: y, // #44\n' +
 1343             '    w: z // #44\n' +
 1344             '}')
 1345         bt(
 1346             'switch (x) {\n' +
 1347             '    case "a":\n' +
 1348             '        // comment on newline\n' +
 1349             '        break;\n' +
 1350             '    case "b": // comment on same line\n' +
 1351             '        break;\n' +
 1352             '}')
 1353         bt(
 1354             'this.type =\n' +
 1355             '    this.options =\n' +
 1356             '    // comment\n' +
 1357             '    this.enabled null;',
 1358             #  -- output --
 1359             'this.type = this.options =\n' +
 1360             '    // comment\n' +
 1361             '    this.enabled null;')
 1362         bt(
 1363             'someObj\n' +
 1364             '    .someFunc1()\n' +
 1365             '    // This comment should not break the indent\n' +
 1366             '    .someFunc2();',
 1367             #  -- output --
 1368             'someObj.someFunc1()\n' +
 1369             '    // This comment should not break the indent\n' +
 1370             '    .someFunc2();')
 1371         bt(
 1372             'if (true ||\n' +
 1373             '!true) return;',
 1374             #  -- output --
 1375             'if (true || !true) return;')
 1376         bt(
 1377             'if\n' +
 1378             '(foo)\n' +
 1379             'if\n' +
 1380             '(bar)\n' +
 1381             'if\n' +
 1382             '(baz)\n' +
 1383             'whee();\n' +
 1384             'a();',
 1385             #  -- output --
 1386             'if (foo)\n' +
 1387             '    if (bar)\n' +
 1388             '        if (baz) whee();\n' +
 1389             'a();')
 1390         bt(
 1391             'if\n' +
 1392             '(foo)\n' +
 1393             'if\n' +
 1394             '(bar)\n' +
 1395             'if\n' +
 1396             '(baz)\n' +
 1397             'whee();\n' +
 1398             'else\n' +
 1399             'a();',
 1400             #  -- output --
 1401             'if (foo)\n' +
 1402             '    if (bar)\n' +
 1403             '        if (baz) whee();\n' +
 1404             '        else a();')
 1405         bt(
 1406             'if (foo)\n' +
 1407             'bar();\n' +
 1408             'else\n' +
 1409             'car();',
 1410             #  -- output --
 1411             'if (foo) bar();\n' +
 1412             'else car();')
 1413         bt(
 1414             'if (foo) if (bar) if (baz);\n' +
 1415             'a();',
 1416             #  -- output --
 1417             'if (foo)\n' +
 1418             '    if (bar)\n' +
 1419             '        if (baz);\n' +
 1420             'a();')
 1421         bt(
 1422             'if (foo) if (bar) if (baz) whee();\n' +
 1423             'a();',
 1424             #  -- output --
 1425             'if (foo)\n' +
 1426             '    if (bar)\n' +
 1427             '        if (baz) whee();\n' +
 1428             'a();')
 1429         bt(
 1430             'if (foo) a()\n' +
 1431             'if (bar) if (baz) whee();\n' +
 1432             'a();',
 1433             #  -- output --
 1434             'if (foo) a()\n' +
 1435             'if (bar)\n' +
 1436             '    if (baz) whee();\n' +
 1437             'a();')
 1438         bt(
 1439             'if (foo);\n' +
 1440             'if (bar) if (baz) whee();\n' +
 1441             'a();',
 1442             #  -- output --
 1443             'if (foo);\n' +
 1444             'if (bar)\n' +
 1445             '    if (baz) whee();\n' +
 1446             'a();')
 1447         bt(
 1448             'if (options)\n' +
 1449             '    for (var p in options)\n' +
 1450             '        this[p] = options[p];',
 1451             #  -- output --
 1452             'if (options)\n' +
 1453             '    for (var p in options) this[p] = options[p];')
 1454         bt(
 1455             'if (options) for (var p in options) this[p] = options[p];',
 1456             #  -- output --
 1457             'if (options)\n' +
 1458             '    for (var p in options) this[p] = options[p];')
 1459         bt(
 1460             'if (options) do q(); while (b());',
 1461             #  -- output --
 1462             'if (options)\n' +
 1463             '    do q(); while (b());')
 1464         bt(
 1465             'if (options) while (b()) q();',
 1466             #  -- output --
 1467             'if (options)\n' +
 1468             '    while (b()) q();')
 1469         bt(
 1470             'if (options) do while (b()) q(); while (a());',
 1471             #  -- output --
 1472             'if (options)\n' +
 1473             '    do\n' +
 1474             '        while (b()) q(); while (a());')
 1475         bt(
 1476             'function f(a, b, c,\n' +
 1477             'd, e) {}',
 1478             #  -- output --
 1479             'function f(a, b, c, d, e) {}')
 1480         bt(
 1481             'function f(a,b) {if(a) b()}function g(a,b) {if(!a) b()}',
 1482             #  -- output --
 1483             'function f(a, b) {\n' +
 1484             '    if (a) b()\n' +
 1485             '}\n' +
 1486             '\n' +
 1487             'function g(a, b) {\n' +
 1488             '    if (!a) b()\n' +
 1489             '}')
 1490         bt(
 1491             'function f(a,b) {if(a) b()}\n' +
 1492             '\n' +
 1493             '\n' +
 1494             '\n' +
 1495             'function g(a,b) {if(!a) b()}',
 1496             #  -- output --
 1497             'function f(a, b) {\n' +
 1498             '    if (a) b()\n' +
 1499             '}\n' +
 1500             '\n' +
 1501             'function g(a, b) {\n' +
 1502             '    if (!a) b()\n' +
 1503             '}')
 1504         bt(
 1505             '(if(a) b())(if(a) b())',
 1506             #  -- output --
 1507             '(\n' +
 1508             '    if (a) b())(\n' +
 1509             '    if (a) b())')
 1510         bt(
 1511             '(if(a) b())\n' +
 1512             '\n' +
 1513             '\n' +
 1514             '(if(a) b())',
 1515             #  -- output --
 1516             '(\n' +
 1517             '    if (a) b())\n' +
 1518             '(\n' +
 1519             '    if (a) b())')
 1520         bt(
 1521             'if\n' +
 1522             '(a)\n' +
 1523             'b();',
 1524             #  -- output --
 1525             'if (a) b();')
 1526         bt(
 1527             'var a =\n' +
 1528             'foo',
 1529             #  -- output --
 1530             'var a = foo')
 1531         bt(
 1532             'var a = {\n' +
 1533             '"a":1,\n' +
 1534             '"b":2}',
 1535             #  -- output --
 1536             'var a = {\n' +
 1537             '    "a": 1,\n' +
 1538             '    "b": 2\n' +
 1539             '}')
 1540         bt(
 1541             'var a = {\n' +
 1542             '\'a\':1,\n' +
 1543             '\'b\':2}',
 1544             #  -- output --
 1545             'var a = {\n' +
 1546             '    \'a\': 1,\n' +
 1547             '    \'b\': 2\n' +
 1548             '}')
 1549         bt('var a = /*i*/ "b";')
 1550         bt(
 1551             'var a = /*i*/\n' +
 1552             '"b";',
 1553             #  -- output --
 1554             'var a = /*i*/ "b";')
 1555         bt(
 1556             '{\n' +
 1557             '\n' +
 1558             '\n' +
 1559             '"x"\n' +
 1560             '}',
 1561             #  -- output --
 1562             '{\n' +
 1563             '    "x"\n' +
 1564             '}')
 1565         bt(
 1566             'if(a &&\n' +
 1567             'b\n' +
 1568             '||\n' +
 1569             'c\n' +
 1570             '||d\n' +
 1571             '&&\n' +
 1572             'e) e = f',
 1573             #  -- output --
 1574             'if (a && b || c || d && e) e = f')
 1575         bt(
 1576             'if(a &&\n' +
 1577             '(b\n' +
 1578             '||\n' +
 1579             'c\n' +
 1580             '||d)\n' +
 1581             '&&\n' +
 1582             'e) e = f',
 1583             #  -- output --
 1584             'if (a && (b || c || d) && e) e = f')
 1585         test_fragment(
 1586             '\n' +
 1587             '\n' +
 1588             '"x"',
 1589             #  -- output --
 1590             '"x"')
 1591         test_fragment(
 1592             '{\n' +
 1593             '\n' +
 1594             '"x"\n' +
 1595             'h=5;\n' +
 1596             '}',
 1597             #  -- output --
 1598             '{\n' +
 1599             '    "x"\n' +
 1600             '    h = 5;\n' +
 1601             '}')
 1602         bt(
 1603             'var a = "foo" +\n' +
 1604             '    "bar";',
 1605             #  -- output --
 1606             'var a = "foo" + "bar";')
 1607         bt(
 1608             'var a = 42; // foo\n' +
 1609             '\n' +
 1610             'var b;',
 1611             #  -- output --
 1612             'var a = 42; // foo\n' +
 1613             'var b;')
 1614         bt(
 1615             'var a = 42; // foo\n' +
 1616             '\n' +
 1617             '\n' +
 1618             'var b;',
 1619             #  -- output --
 1620             'var a = 42; // foo\n' +
 1621             'var b;')
 1622         bt(
 1623             'a = 1;\n' +
 1624             '\n' +
 1625             '\n' +
 1626             '\n' +
 1627             '\n' +
 1628             '\n' +
 1629             '\n' +
 1630             '\n' +
 1631             '\n' +
 1632             '\n' +
 1633             '\n' +
 1634             '\n' +
 1635             '\n' +
 1636             '\n' +
 1637             '\n' +
 1638             '\n' +
 1639             '\n' +
 1640             '\n' +
 1641             '\n' +
 1642             '\n' +
 1643             '\n' +
 1644             '\n' +
 1645             'b = 2;',
 1646             #  -- output --
 1647             'a = 1;\n' +
 1648             'b = 2;')
 1649 
 1650         # general preserve_newlines tests - (preserve_newlines = "true")
 1651         self.reset_options()
 1652         self.options.preserve_newlines = true
 1653         bt(
 1654             'if (foo) // comment\n' +
 1655             '    bar();')
 1656         bt(
 1657             'if (foo) // comment\n' +
 1658             '    bar();')
 1659         bt(
 1660             'if (foo) // comment\n' +
 1661             '    (bar());')
 1662         bt(
 1663             'if (foo) // comment\n' +
 1664             '    (bar());')
 1665         bt(
 1666             'if (foo) // comment\n' +
 1667             '    /asdf/;')
 1668         bt(
 1669             'this.oa = new OAuth(\n' +
 1670             '    _requestToken,\n' +
 1671             '    _accessToken,\n' +
 1672             '    consumer_key\n' +
 1673             ');')
 1674         bt(
 1675             'foo = {\n' +
 1676             '    x: y, // #44\n' +
 1677             '    w: z // #44\n' +
 1678             '}')
 1679         bt(
 1680             'switch (x) {\n' +
 1681             '    case "a":\n' +
 1682             '        // comment on newline\n' +
 1683             '        break;\n' +
 1684             '    case "b": // comment on same line\n' +
 1685             '        break;\n' +
 1686             '}')
 1687         bt(
 1688             'this.type =\n' +
 1689             '    this.options =\n' +
 1690             '    // comment\n' +
 1691             '    this.enabled null;')
 1692         bt(
 1693             'someObj\n' +
 1694             '    .someFunc1()\n' +
 1695             '    // This comment should not break the indent\n' +
 1696             '    .someFunc2();')
 1697         bt(
 1698             'if (true ||\n' +
 1699             '!true) return;',
 1700             #  -- output --
 1701             'if (true ||\n' +
 1702             '    !true) return;')
 1703         bt(
 1704             'if\n' +
 1705             '(foo)\n' +
 1706             'if\n' +
 1707             '(bar)\n' +
 1708             'if\n' +
 1709             '(baz)\n' +
 1710             'whee();\n' +
 1711             'a();',
 1712             #  -- output --
 1713             'if (foo)\n' +
 1714             '    if (bar)\n' +
 1715             '        if (baz)\n' +
 1716             '            whee();\n' +
 1717             'a();')
 1718         bt(
 1719             'if\n' +
 1720             '(foo)\n' +
 1721             'if\n' +
 1722             '(bar)\n' +
 1723             'if\n' +
 1724             '(baz)\n' +
 1725             'whee();\n' +
 1726             'else\n' +
 1727             'a();',
 1728             #  -- output --
 1729             'if (foo)\n' +
 1730             '    if (bar)\n' +
 1731             '        if (baz)\n' +
 1732             '            whee();\n' +
 1733             '        else\n' +
 1734             '            a();')
 1735         bt(
 1736             'if (foo)\n' +
 1737             'bar();\n' +
 1738             'else\n' +
 1739             'car();',
 1740             #  -- output --
 1741             'if (foo)\n' +
 1742             '    bar();\n' +
 1743             'else\n' +
 1744             '    car();')
 1745         bt(
 1746             'if (foo) if (bar) if (baz);\n' +
 1747             'a();',
 1748             #  -- output --
 1749             'if (foo)\n' +
 1750             '    if (bar)\n' +
 1751             '        if (baz);\n' +
 1752             'a();')
 1753         bt(
 1754             'if (foo) if (bar) if (baz) whee();\n' +
 1755             'a();',
 1756             #  -- output --
 1757             'if (foo)\n' +
 1758             '    if (bar)\n' +
 1759             '        if (baz) whee();\n' +
 1760             'a();')
 1761         bt(
 1762             'if (foo) a()\n' +
 1763             'if (bar) if (baz) whee();\n' +
 1764             'a();',
 1765             #  -- output --
 1766             'if (foo) a()\n' +
 1767             'if (bar)\n' +
 1768             '    if (baz) whee();\n' +
 1769             'a();')
 1770         bt(
 1771             'if (foo);\n' +
 1772             'if (bar) if (baz) whee();\n' +
 1773             'a();',
 1774             #  -- output --
 1775             'if (foo);\n' +
 1776             'if (bar)\n' +
 1777             '    if (baz) whee();\n' +
 1778             'a();')
 1779         bt(
 1780             'if (options)\n' +
 1781             '    for (var p in options)\n' +
 1782             '        this[p] = options[p];')
 1783         bt(
 1784             'if (options) for (var p in options) this[p] = options[p];',
 1785             #  -- output --
 1786             'if (options)\n' +
 1787             '    for (var p in options) this[p] = options[p];')
 1788         bt(
 1789             'if (options) do q(); while (b());',
 1790             #  -- output --
 1791             'if (options)\n' +
 1792             '    do q(); while (b());')
 1793         bt(
 1794             'if (options) while (b()) q();',
 1795             #  -- output --
 1796             'if (options)\n' +
 1797             '    while (b()) q();')
 1798         bt(
 1799             'if (options) do while (b()) q(); while (a());',
 1800             #  -- output --
 1801             'if (options)\n' +
 1802             '    do\n' +
 1803             '        while (b()) q(); while (a());')
 1804         bt(
 1805             'function f(a, b, c,\n' +
 1806             'd, e) {}',
 1807             #  -- output --
 1808             'function f(a, b, c,\n' +
 1809             '    d, e) {}')
 1810         bt(
 1811             'function f(a,b) {if(a) b()}function g(a,b) {if(!a) b()}',
 1812             #  -- output --
 1813             'function f(a, b) {\n' +
 1814             '    if (a) b()\n' +
 1815             '}\n' +
 1816             '\n' +
 1817             'function g(a, b) {\n' +
 1818             '    if (!a) b()\n' +
 1819             '}')
 1820         bt(
 1821             'function f(a,b) {if(a) b()}\n' +
 1822             '\n' +
 1823             '\n' +
 1824             '\n' +
 1825             'function g(a,b) {if(!a) b()}',
 1826             #  -- output --
 1827             'function f(a, b) {\n' +
 1828             '    if (a) b()\n' +
 1829             '}\n' +
 1830             '\n' +
 1831             '\n' +
 1832             '\n' +
 1833             'function g(a, b) {\n' +
 1834             '    if (!a) b()\n' +
 1835             '}')
 1836         bt(
 1837             '(if(a) b())(if(a) b())',
 1838             #  -- output --
 1839             '(\n' +
 1840             '    if (a) b())(\n' +
 1841             '    if (a) b())')
 1842         bt(
 1843             '(if(a) b())\n' +
 1844             '\n' +
 1845             '\n' +
 1846             '(if(a) b())',
 1847             #  -- output --
 1848             '(\n' +
 1849             '    if (a) b())\n' +
 1850             '\n' +
 1851             '\n' +
 1852             '(\n' +
 1853             '    if (a) b())')
 1854         bt(
 1855             'if\n' +
 1856             '(a)\n' +
 1857             'b();',
 1858             #  -- output --
 1859             'if (a)\n' +
 1860             '    b();')
 1861         bt(
 1862             'var a =\n' +
 1863             'foo',
 1864             #  -- output --
 1865             'var a =\n' +
 1866             '    foo')
 1867         bt(
 1868             'var a = {\n' +
 1869             '"a":1,\n' +
 1870             '"b":2}',
 1871             #  -- output --
 1872             'var a = {\n' +
 1873             '    "a": 1,\n' +
 1874             '    "b": 2\n' +
 1875             '}')
 1876         bt(
 1877             'var a = {\n' +
 1878             '\'a\':1,\n' +
 1879             '\'b\':2}',
 1880             #  -- output --
 1881             'var a = {\n' +
 1882             '    \'a\': 1,\n' +
 1883             '    \'b\': 2\n' +
 1884             '}')
 1885         bt('var a = /*i*/ "b";')
 1886         bt(
 1887             'var a = /*i*/\n' +
 1888             '"b";',
 1889             #  -- output --
 1890             'var a = /*i*/\n' +
 1891             '    "b";')
 1892         bt(
 1893             '{\n' +
 1894             '\n' +
 1895             '\n' +
 1896             '"x"\n' +
 1897             '}',
 1898             #  -- output --
 1899             '{\n' +
 1900             '\n' +
 1901             '\n' +
 1902             '    "x"\n' +
 1903             '}')
 1904         bt(
 1905             'if(a &&\n' +
 1906             'b\n' +
 1907             '||\n' +
 1908             'c\n' +
 1909             '||d\n' +
 1910             '&&\n' +
 1911             'e) e = f',
 1912             #  -- output --
 1913             'if (a &&\n' +
 1914             '    b ||\n' +
 1915             '    c ||\n' +
 1916             '    d &&\n' +
 1917             '    e) e = f')
 1918         bt(
 1919             'if(a &&\n' +
 1920             '(b\n' +
 1921             '||\n' +
 1922             'c\n' +
 1923             '||d)\n' +
 1924             '&&\n' +
 1925             'e) e = f',
 1926             #  -- output --
 1927             'if (a &&\n' +
 1928             '    (b ||\n' +
 1929             '        c ||\n' +
 1930             '        d) &&\n' +
 1931             '    e) e = f')
 1932         test_fragment(
 1933             '\n' +
 1934             '\n' +
 1935             '"x"',
 1936             #  -- output --
 1937             '"x"')
 1938         test_fragment(
 1939             '{\n' +
 1940             '\n' +
 1941             '"x"\n' +
 1942             'h=5;\n' +
 1943             '}',
 1944             #  -- output --
 1945             '{\n' +
 1946             '\n' +
 1947             '    "x"\n' +
 1948             '    h = 5;\n' +
 1949             '}')
 1950         bt(
 1951             'var a = "foo" +\n' +
 1952             '    "bar";')
 1953         bt(
 1954             'var a = 42; // foo\n' +
 1955             '\n' +
 1956             'var b;')
 1957         bt(
 1958             'var a = 42; // foo\n' +
 1959             '\n' +
 1960             '\n' +
 1961             'var b;')
 1962         bt(
 1963             'a = 1;\n' +
 1964             '\n' +
 1965             '\n' +
 1966             '\n' +
 1967             '\n' +
 1968             '\n' +
 1969             '\n' +
 1970             '\n' +
 1971             '\n' +
 1972             '\n' +
 1973             '\n' +
 1974             '\n' +
 1975             '\n' +
 1976             '\n' +
 1977             '\n' +
 1978             '\n' +
 1979             '\n' +
 1980             '\n' +
 1981             '\n' +
 1982             '\n' +
 1983             '\n' +
 1984             '\n' +
 1985             'b = 2;')
 1986 
 1987 
 1988         #============================================================
 1989         # break chained methods - (break_chained_methods = "false", preserve_newlines = "false")
 1990         self.reset_options()
 1991         self.options.break_chained_methods = false
 1992         self.options.preserve_newlines = false
 1993         bt(
 1994             'foo\n' +
 1995             '.bar()\n' +
 1996             '.baz().cucumber(fat)',
 1997             #  -- output --
 1998             'foo.bar().baz().cucumber(fat)')
 1999         bt(
 2000             'foo\n' +
 2001             '.bar()\n' +
 2002             '.baz().cucumber(fat); foo.bar().baz().cucumber(fat)',
 2003             #  -- output --
 2004             'foo.bar().baz().cucumber(fat);\n' +
 2005             'foo.bar().baz().cucumber(fat)')
 2006         bt(
 2007             'foo\n' +
 2008             '.bar()\n' +
 2009             '.baz().cucumber(fat)\n' +
 2010             ' foo.bar().baz().cucumber(fat)',
 2011             #  -- output --
 2012             'foo.bar().baz().cucumber(fat)\n' +
 2013             'foo.bar().baz().cucumber(fat)')
 2014         bt(
 2015             'this\n' +
 2016             '.something = foo.bar()\n' +
 2017             '.baz().cucumber(fat)',
 2018             #  -- output --
 2019             'this.something = foo.bar().baz().cucumber(fat)')
 2020         bt('this.something.xxx = foo.moo.bar()')
 2021         bt(
 2022             'this\n' +
 2023             '.something\n' +
 2024             '.xxx = foo.moo\n' +
 2025             '.bar()',
 2026             #  -- output --
 2027             'this.something.xxx = foo.moo.bar()')
 2028         
 2029         # optional chaining operator
 2030         bt(
 2031             'foo\n' +
 2032             '?.bar()\n' +
 2033             '?.baz()?.cucumber(fat)',
 2034             #  -- output --
 2035             'foo?.bar()?.baz()?.cucumber(fat)')
 2036         bt(
 2037             'foo\n' +
 2038             '?.bar()\n' +
 2039             '?.baz()?.cucumber(fat); foo?.bar()?.baz()?.cucumber(fat)',
 2040             #  -- output --
 2041             'foo?.bar()?.baz()?.cucumber(fat);\n' +
 2042             'foo?.bar()?.baz()?.cucumber(fat)')
 2043         bt(
 2044             'foo\n' +
 2045             '?.bar()\n' +
 2046             '?.baz()?.cucumber(fat)\n' +
 2047             ' foo?.bar()?.baz()?.cucumber(fat)',
 2048             #  -- output --
 2049             'foo?.bar()?.baz()?.cucumber(fat)\n' +
 2050             'foo?.bar()?.baz()?.cucumber(fat)')
 2051         bt(
 2052             'this\n' +
 2053             '?.something = foo?.bar()\n' +
 2054             '?.baz()?.cucumber(fat)',
 2055             #  -- output --
 2056             'this?.something = foo?.bar()?.baz()?.cucumber(fat)')
 2057         bt('this?.something?.xxx = foo?.moo?.bar()')
 2058         bt(
 2059             'this\n' +
 2060             '?.something\n' +
 2061             '?.xxx = foo?.moo\n' +
 2062             '?.bar()',
 2063             #  -- output --
 2064             'this?.something?.xxx = foo?.moo?.bar()')
 2065 
 2066         # break chained methods - (break_chained_methods = "false", preserve_newlines = "true")
 2067         self.reset_options()
 2068         self.options.break_chained_methods = false
 2069         self.options.preserve_newlines = true
 2070         bt(
 2071             'foo\n' +
 2072             '.bar()\n' +
 2073             '.baz().cucumber(fat)',
 2074             #  -- output --
 2075             'foo\n' +
 2076             '    .bar()\n' +
 2077             '    .baz().cucumber(fat)')
 2078         bt(
 2079             'foo\n' +
 2080             '.bar()\n' +
 2081             '.baz().cucumber(fat); foo.bar().baz().cucumber(fat)',
 2082             #  -- output --
 2083             'foo\n' +
 2084             '    .bar()\n' +
 2085             '    .baz().cucumber(fat);\n' +
 2086             'foo.bar().baz().cucumber(fat)')
 2087         bt(
 2088             'foo\n' +
 2089             '.bar()\n' +
 2090             '.baz().cucumber(fat)\n' +
 2091             ' foo.bar().baz().cucumber(fat)',
 2092             #  -- output --
 2093             'foo\n' +
 2094             '    .bar()\n' +
 2095             '    .baz().cucumber(fat)\n' +
 2096             'foo.bar().baz().cucumber(fat)')
 2097         bt(
 2098             'this\n' +
 2099             '.something = foo.bar()\n' +
 2100             '.baz().cucumber(fat)',
 2101             #  -- output --
 2102             'this\n' +
 2103             '    .something = foo.bar()\n' +
 2104             '    .baz().cucumber(fat)')
 2105         bt('this.something.xxx = foo.moo.bar()')
 2106         bt(
 2107             'this\n' +
 2108             '.something\n' +
 2109             '.xxx = foo.moo\n' +
 2110             '.bar()',
 2111             #  -- output --
 2112             'this\n' +
 2113             '    .something\n' +
 2114             '    .xxx = foo.moo\n' +
 2115             '    .bar()')
 2116         
 2117         # optional chaining operator
 2118         bt(
 2119             'foo\n' +
 2120             '?.bar()\n' +
 2121             '?.baz()?.cucumber(fat)',
 2122             #  -- output --
 2123             'foo\n' +
 2124             '    ?.bar()\n' +
 2125             '    ?.baz()?.cucumber(fat)')
 2126         bt(
 2127             'foo\n' +
 2128             '?.bar()\n' +
 2129             '?.baz()?.cucumber(fat); foo?.bar()?.baz()?.cucumber(fat)',
 2130             #  -- output --
 2131             'foo\n' +
 2132             '    ?.bar()\n' +
 2133             '    ?.baz()?.cucumber(fat);\n' +
 2134             'foo?.bar()?.baz()?.cucumber(fat)')
 2135         bt(
 2136             'foo\n' +
 2137             '?.bar()\n' +
 2138             '?.baz()?.cucumber(fat)\n' +
 2139             ' foo?.bar()?.baz()?.cucumber(fat)',
 2140             #  -- output --
 2141             'foo\n' +
 2142             '    ?.bar()\n' +
 2143             '    ?.baz()?.cucumber(fat)\n' +
 2144             'foo?.bar()?.baz()?.cucumber(fat)')
 2145         bt(
 2146             'this\n' +
 2147             '?.something = foo?.bar()\n' +
 2148             '?.baz()?.cucumber(fat)',
 2149             #  -- output --
 2150             'this\n' +
 2151             '    ?.something = foo?.bar()\n' +
 2152             '    ?.baz()?.cucumber(fat)')
 2153         bt('this?.something?.xxx = foo?.moo?.bar()')
 2154         bt(
 2155             'this\n' +
 2156             '?.something\n' +
 2157             '?.xxx = foo?.moo\n' +
 2158             '?.bar()',
 2159             #  -- output --
 2160             'this\n' +
 2161             '    ?.something\n' +
 2162             '    ?.xxx = foo?.moo\n' +
 2163             '    ?.bar()')
 2164 
 2165         # break chained methods - (break_chained_methods = "true", preserve_newlines = "false")
 2166         self.reset_options()
 2167         self.options.break_chained_methods = true
 2168         self.options.preserve_newlines = false
 2169         bt(
 2170             'foo\n' +
 2171             '.bar()\n' +
 2172             '.baz().cucumber(fat)',
 2173             #  -- output --
 2174             'foo.bar()\n' +
 2175             '    .baz()\n' +
 2176             '    .cucumber(fat)')
 2177         bt(
 2178             'foo\n' +
 2179             '.bar()\n' +
 2180             '.baz().cucumber(fat); foo.bar().baz().cucumber(fat)',
 2181             #  -- output --
 2182             'foo.bar()\n' +
 2183             '    .baz()\n' +
 2184             '    .cucumber(fat);\n' +
 2185             'foo.bar()\n' +
 2186             '    .baz()\n' +
 2187             '    .cucumber(fat)')
 2188         bt(
 2189             'foo\n' +
 2190             '.bar()\n' +
 2191             '.baz().cucumber(fat)\n' +
 2192             ' foo.bar().baz().cucumber(fat)',
 2193             #  -- output --
 2194             'foo.bar()\n' +
 2195             '    .baz()\n' +
 2196             '    .cucumber(fat)\n' +
 2197             'foo.bar()\n' +
 2198             '    .baz()\n' +
 2199             '    .cucumber(fat)')
 2200         bt(
 2201             'this\n' +
 2202             '.something = foo.bar()\n' +
 2203             '.baz().cucumber(fat)',
 2204             #  -- output --
 2205             'this.something = foo.bar()\n' +
 2206             '    .baz()\n' +
 2207             '    .cucumber(fat)')
 2208         bt('this.something.xxx = foo.moo.bar()')
 2209         bt(
 2210             'this\n' +
 2211             '.something\n' +
 2212             '.xxx = foo.moo\n' +
 2213             '.bar()',
 2214             #  -- output --
 2215             'this.something.xxx = foo.moo.bar()')
 2216         
 2217         # optional chaining operator
 2218         bt(
 2219             'foo\n' +
 2220             '?.bar()\n' +
 2221             '?.baz()?.cucumber(fat)',
 2222             #  -- output --
 2223             'foo?.bar()\n' +
 2224             '    ?.baz()\n' +
 2225             '    ?.cucumber(fat)')
 2226         bt(
 2227             'foo\n' +
 2228             '?.bar()\n' +
 2229             '?.baz()?.cucumber(fat); foo?.bar()?.baz()?.cucumber(fat)',
 2230             #  -- output --
 2231             'foo?.bar()\n' +
 2232             '    ?.baz()\n' +
 2233             '    ?.cucumber(fat);\n' +
 2234             'foo?.bar()\n' +
 2235             '    ?.baz()\n' +
 2236             '    ?.cucumber(fat)')
 2237         bt(
 2238             'foo\n' +
 2239             '?.bar()\n' +
 2240             '?.baz()?.cucumber(fat)\n' +
 2241             ' foo?.bar()?.baz()?.cucumber(fat)',
 2242             #  -- output --
 2243             'foo?.bar()\n' +
 2244             '    ?.baz()\n' +
 2245             '    ?.cucumber(fat)\n' +
 2246             'foo?.bar()\n' +
 2247             '    ?.baz()\n' +
 2248             '    ?.cucumber(fat)')
 2249         bt(
 2250             'this\n' +
 2251             '?.something = foo?.bar()\n' +
 2252             '?.baz()?.cucumber(fat)',
 2253             #  -- output --
 2254             'this?.something = foo?.bar()\n' +
 2255             '    ?.baz()\n' +
 2256             '    ?.cucumber(fat)')
 2257         bt('this?.something?.xxx = foo?.moo?.bar()')
 2258         bt(
 2259             'this\n' +
 2260             '?.something\n' +
 2261             '?.xxx = foo?.moo\n' +
 2262             '?.bar()',
 2263             #  -- output --
 2264             'this?.something?.xxx = foo?.moo?.bar()')
 2265 
 2266         # break chained methods - (break_chained_methods = "true", preserve_newlines = "true")
 2267         self.reset_options()
 2268         self.options.break_chained_methods = true
 2269         self.options.preserve_newlines = true
 2270         bt(
 2271             'foo\n' +
 2272             '.bar()\n' +
 2273             '.baz().cucumber(fat)',
 2274             #  -- output --
 2275             'foo\n' +
 2276             '    .bar()\n' +
 2277             '    .baz()\n' +
 2278             '    .cucumber(fat)')
 2279         bt(
 2280             'foo\n' +
 2281             '.bar()\n' +
 2282             '.baz().cucumber(fat); foo.bar().baz().cucumber(fat)',
 2283             #  -- output --
 2284             'foo\n' +
 2285             '    .bar()\n' +
 2286             '    .baz()\n' +
 2287             '    .cucumber(fat);\n' +
 2288             'foo.bar()\n' +
 2289             '    .baz()\n' +
 2290             '    .cucumber(fat)')
 2291         bt(
 2292             'foo\n' +
 2293             '.bar()\n' +
 2294             '.baz().cucumber(fat)\n' +
 2295             ' foo.bar().baz().cucumber(fat)',
 2296             #  -- output --
 2297             'foo\n' +
 2298             '    .bar()\n' +
 2299             '    .baz()\n' +
 2300             '    .cucumber(fat)\n' +
 2301             'foo.bar()\n' +
 2302             '    .baz()\n' +
 2303             '    .cucumber(fat)')
 2304         bt(
 2305             'this\n' +
 2306             '.something = foo.bar()\n' +
 2307             '.baz().cucumber(fat)',
 2308             #  -- output --
 2309             'this\n' +
 2310             '    .something = foo.bar()\n' +
 2311             '    .baz()\n' +
 2312             '    .cucumber(fat)')
 2313         bt('this.something.xxx = foo.moo.bar()')
 2314         bt(
 2315             'this\n' +
 2316             '.something\n' +
 2317             '.xxx = foo.moo\n' +
 2318             '.bar()',
 2319             #  -- output --
 2320             'this\n' +
 2321             '    .something\n' +
 2322             '    .xxx = foo.moo\n' +
 2323             '    .bar()')
 2324         
 2325         # optional chaining operator
 2326         bt(
 2327             'foo\n' +
 2328             '?.bar()\n' +
 2329             '?.baz()?.cucumber(fat)',
 2330             #  -- output --
 2331             'foo\n' +
 2332             '    ?.bar()\n' +
 2333             '    ?.baz()\n' +
 2334             '    ?.cucumber(fat)')
 2335         bt(
 2336             'foo\n' +
 2337             '?.bar()\n' +
 2338             '?.baz()?.cucumber(fat); foo?.bar()?.baz()?.cucumber(fat)',
 2339             #  -- output --
 2340             'foo\n' +
 2341             '    ?.bar()\n' +
 2342             '    ?.baz()\n' +
 2343             '    ?.cucumber(fat);\n' +
 2344             'foo?.bar()\n' +
 2345             '    ?.baz()\n' +
 2346             '    ?.cucumber(fat)')
 2347         bt(
 2348             'foo\n' +
 2349             '?.bar()\n' +
 2350             '?.baz()?.cucumber(fat)\n' +
 2351             ' 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             'this\n' +
 2362             '?.something = foo?.bar()\n' +
 2363             '?.baz()?.cucumber(fat)',
 2364             #  -- output --
 2365             'this\n' +
 2366             '    ?.something = foo?.bar()\n' +
 2367             '    ?.baz()\n' +
 2368             '    ?.cucumber(fat)')
 2369         bt('this?.something?.xxx = foo?.moo?.bar()')
 2370         bt(
 2371             'this\n' +
 2372             '?.something\n' +
 2373             '?.xxx = foo?.moo\n' +
 2374             '?.bar()',
 2375             #  -- output --
 2376             'this\n' +
 2377             '    ?.something\n' +
 2378             '    ?.xxx = foo?.moo\n' +
 2379             '    ?.bar()')
 2380 
 2381 
 2382         #============================================================
 2383         # line wrapping 0
 2384         self.reset_options()
 2385         self.options.preserve_newlines = false
 2386         self.options.wrap_line_length = 0
 2387         test_fragment(
 2388             '' + wrap_input_1 + '',
 2389             #  -- output --
 2390             'foo.bar().baz().cucumber((f && "sass") || (leans && mean));\n' +
 2391             'Test_very_long_variable_name_this_should_never_wrap.but_this_can\n' +
 2392             'return between_return_and_expression_should_never_wrap.but_this_can\n' +
 2393             'throw between_throw_and_expression_should_never_wrap.but_this_can\n' +
 2394             'if (wraps_can_occur && inside_an_if_block) that_is_.okay();\n' +
 2395             'object_literal = {\n' +
 2396             '    propertx: first_token + 12345678.99999E-6,\n' +
 2397             '    property: first_token_should_never_wrap + but_this_can,\n' +
 2398             '    propertz: first_token_should_never_wrap + !but_this_can,\n' +
 2399             '    proper: "first_token_should_never_wrap" + "but_this_can"\n' +
 2400             '}')
 2401         test_fragment(
 2402             '' + wrap_input_2 + '',
 2403             #  -- output --
 2404             '{\n' +
 2405             '    foo.bar().baz().cucumber((f && "sass") || (leans && mean));\n' +
 2406             '    Test_very_long_variable_name_this_should_never_wrap.but_this_can\n' +
 2407             '    return between_return_and_expression_should_never_wrap.but_this_can\n' +
 2408             '    throw between_throw_and_expression_should_never_wrap.but_this_can\n' +
 2409             '    if (wraps_can_occur && inside_an_if_block) that_is_.okay();\n' +
 2410             '    object_literal = {\n' +
 2411             '        propertx: first_token + 12345678.99999E-6,\n' +
 2412             '        property: first_token_should_never_wrap + but_this_can,\n' +
 2413             '        propertz: first_token_should_never_wrap + !but_this_can,\n' +
 2414             '        proper: "first_token_should_never_wrap" + "but_this_can"\n' +
 2415             '    }\n' +
 2416             '}')
 2417 
 2418 
 2419         #============================================================
 2420         # line wrapping 70
 2421         self.reset_options()
 2422         self.options.preserve_newlines = false
 2423         self.options.wrap_line_length = 70
 2424         test_fragment(
 2425             '' + wrap_input_1 + '',
 2426             #  -- output --
 2427             'foo.bar().baz().cucumber((f && "sass") || (leans && mean));\n' +
 2428             'Test_very_long_variable_name_this_should_never_wrap.but_this_can\n' +
 2429             'return between_return_and_expression_should_never_wrap.but_this_can\n' +
 2430             'throw between_throw_and_expression_should_never_wrap.but_this_can\n' +
 2431             'if (wraps_can_occur && inside_an_if_block) that_is_.okay();\n' +
 2432             'object_literal = {\n' +
 2433             '    propertx: first_token + 12345678.99999E-6,\n' +
 2434             '    property: first_token_should_never_wrap + but_this_can,\n' +
 2435             '    propertz: first_token_should_never_wrap + !but_this_can,\n' +
 2436             '    proper: "first_token_should_never_wrap" + "but_this_can"\n' +
 2437             '}')
 2438         test_fragment(
 2439             '' + wrap_input_2 + '',
 2440             #  -- output --
 2441             '{\n' +
 2442             '    foo.bar().baz().cucumber((f && "sass") || (leans && mean));\n' +
 2443             '    Test_very_long_variable_name_this_should_never_wrap.but_this_can\n' +
 2444             '    return between_return_and_expression_should_never_wrap\n' +
 2445             '        .but_this_can\n' +
 2446             '    throw between_throw_and_expression_should_never_wrap.but_this_can\n' +
 2447             '    if (wraps_can_occur && inside_an_if_block) that_is_.okay();\n' +
 2448             '    object_literal = {\n' +
 2449             '        propertx: first_token + 12345678.99999E-6,\n' +
 2450             '        property: first_token_should_never_wrap + but_this_can,\n' +
 2451             '        propertz: first_token_should_never_wrap + !but_this_can,\n' +
 2452             '        proper: "first_token_should_never_wrap" + "but_this_can"\n' +
 2453             '    }\n' +
 2454             '}')
 2455 
 2456 
 2457         #============================================================
 2458         # line wrapping 40
 2459         self.reset_options()
 2460         self.options.preserve_newlines = false
 2461         self.options.wrap_line_length = 40
 2462         test_fragment(
 2463             '' + wrap_input_1 + '',
 2464             #  -- output --
 2465             'foo.bar().baz().cucumber((f &&\n' +
 2466             '    "sass") || (leans && mean));\n' +
 2467             'Test_very_long_variable_name_this_should_never_wrap\n' +
 2468             '    .but_this_can\n' +
 2469             'return between_return_and_expression_should_never_wrap\n' +
 2470             '    .but_this_can\n' +
 2471             'throw between_throw_and_expression_should_never_wrap\n' +
 2472             '    .but_this_can\n' +
 2473             'if (wraps_can_occur &&\n' +
 2474             '    inside_an_if_block) that_is_.okay();\n' +
 2475             'object_literal = {\n' +
 2476             '    propertx: first_token +\n' +
 2477             '        12345678.99999E-6,\n' +
 2478             '    property: first_token_should_never_wrap +\n' +
 2479             '        but_this_can,\n' +
 2480             '    propertz: first_token_should_never_wrap +\n' +
 2481             '        !but_this_can,\n' +
 2482             '    proper: "first_token_should_never_wrap" +\n' +
 2483             '        "but_this_can"\n' +
 2484             '}')
 2485         test_fragment(
 2486             '' + wrap_input_2 + '',
 2487             #  -- output --
 2488             '{\n' +
 2489             '    foo.bar().baz().cucumber((f &&\n' +
 2490             '        "sass") || (leans &&\n' +
 2491             '        mean));\n' +
 2492             '    Test_very_long_variable_name_this_should_never_wrap\n' +
 2493             '        .but_this_can\n' +
 2494             '    return between_return_and_expression_should_never_wrap\n' +
 2495             '        .but_this_can\n' +
 2496             '    throw between_throw_and_expression_should_never_wrap\n' +
 2497             '        .but_this_can\n' +
 2498             '    if (wraps_can_occur &&\n' +
 2499             '        inside_an_if_block) that_is_\n' +
 2500             '        .okay();\n' +
 2501             '    object_literal = {\n' +
 2502             '        propertx: first_token +\n' +
 2503             '            12345678.99999E-6,\n' +
 2504             '        property: first_token_should_never_wrap +\n' +
 2505             '            but_this_can,\n' +
 2506             '        propertz: first_token_should_never_wrap +\n' +
 2507             '            !but_this_can,\n' +
 2508             '        proper: "first_token_should_never_wrap" +\n' +
 2509             '            "but_this_can"\n' +
 2510             '    }\n' +
 2511             '}')
 2512 
 2513 
 2514         #============================================================
 2515         # line wrapping 41
 2516         self.reset_options()
 2517         self.options.preserve_newlines = false
 2518         self.options.wrap_line_length = 41
 2519         test_fragment(
 2520             '' + wrap_input_1 + '',
 2521             #  -- output --
 2522             'foo.bar().baz().cucumber((f && "sass") ||\n' +
 2523             '    (leans && mean));\n' +
 2524             'Test_very_long_variable_name_this_should_never_wrap\n' +
 2525             '    .but_this_can\n' +
 2526             'return between_return_and_expression_should_never_wrap\n' +
 2527             '    .but_this_can\n' +
 2528             'throw between_throw_and_expression_should_never_wrap\n' +
 2529             '    .but_this_can\n' +
 2530             'if (wraps_can_occur &&\n' +
 2531             '    inside_an_if_block) that_is_.okay();\n' +
 2532             'object_literal = {\n' +
 2533             '    propertx: first_token +\n' +
 2534             '        12345678.99999E-6,\n' +
 2535             '    property: first_token_should_never_wrap +\n' +
 2536             '        but_this_can,\n' +
 2537             '    propertz: first_token_should_never_wrap +\n' +
 2538             '        !but_this_can,\n' +
 2539             '    proper: "first_token_should_never_wrap" +\n' +
 2540             '        "but_this_can"\n' +
 2541             '}')
 2542         test_fragment(
 2543             '' + wrap_input_2 + '',
 2544             #  -- output --
 2545             '{\n' +
 2546             '    foo.bar().baz().cucumber((f &&\n' +
 2547             '        "sass") || (leans &&\n' +
 2548             '        mean));\n' +
 2549             '    Test_very_long_variable_name_this_should_never_wrap\n' +
 2550             '        .but_this_can\n' +
 2551             '    return between_return_and_expression_should_never_wrap\n' +
 2552             '        .but_this_can\n' +
 2553             '    throw between_throw_and_expression_should_never_wrap\n' +
 2554             '        .but_this_can\n' +
 2555             '    if (wraps_can_occur &&\n' +
 2556             '        inside_an_if_block) that_is_\n' +
 2557             '        .okay();\n' +
 2558             '    object_literal = {\n' +
 2559             '        propertx: first_token +\n' +
 2560             '            12345678.99999E-6,\n' +
 2561             '        property: first_token_should_never_wrap +\n' +
 2562             '            but_this_can,\n' +
 2563             '        propertz: first_token_should_never_wrap +\n' +
 2564             '            !but_this_can,\n' +
 2565             '        proper: "first_token_should_never_wrap" +\n' +
 2566             '            "but_this_can"\n' +
 2567             '    }\n' +
 2568             '}')
 2569 
 2570 
 2571         #============================================================
 2572         # line wrapping 45
 2573         self.reset_options()
 2574         self.options.preserve_newlines = false
 2575         self.options.wrap_line_length = 45
 2576         test_fragment(
 2577             '' + wrap_input_1 + '',
 2578             #  -- output --
 2579             'foo.bar().baz().cucumber((f && "sass") || (\n' +
 2580             '    leans && mean));\n' +
 2581             'Test_very_long_variable_name_this_should_never_wrap\n' +
 2582             '    .but_this_can\n' +
 2583             'return between_return_and_expression_should_never_wrap\n' +
 2584             '    .but_this_can\n' +
 2585             'throw between_throw_and_expression_should_never_wrap\n' +
 2586             '    .but_this_can\n' +
 2587             'if (wraps_can_occur && inside_an_if_block)\n' +
 2588             '    that_is_.okay();\n' +
 2589             'object_literal = {\n' +
 2590             '    propertx: first_token +\n' +
 2591             '        12345678.99999E-6,\n' +
 2592             '    property: first_token_should_never_wrap +\n' +
 2593             '        but_this_can,\n' +
 2594             '    propertz: first_token_should_never_wrap +\n' +
 2595             '        !but_this_can,\n' +
 2596             '    proper: "first_token_should_never_wrap" +\n' +
 2597             '        "but_this_can"\n' +
 2598             '}')
 2599         test_fragment(
 2600             '' + wrap_input_2 + '',
 2601             #  -- output --
 2602             '{\n' +
 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             '    }\n' +
 2623             '}')
 2624 
 2625 
 2626         #============================================================
 2627         # line wrapping 0
 2628         self.reset_options()
 2629         self.options.preserve_newlines = true
 2630         self.options.wrap_line_length = 0
 2631         test_fragment(
 2632             '' + wrap_input_1 + '',
 2633             #  -- output --
 2634             'foo.bar().baz().cucumber((f && "sass") || (leans && mean));\n' +
 2635             'Test_very_long_variable_name_this_should_never_wrap\n' +
 2636             '    .but_this_can\n' +
 2637             'return between_return_and_expression_should_never_wrap.but_this_can\n' +
 2638             'throw between_throw_and_expression_should_never_wrap.but_this_can\n' +
 2639             'if (wraps_can_occur && inside_an_if_block) that_is_\n' +
 2640             '    .okay();\n' +
 2641             'object_literal = {\n' +
 2642             '    propertx: first_token + 12345678.99999E-6,\n' +
 2643             '    property: first_token_should_never_wrap + but_this_can,\n' +
 2644             '    propertz: first_token_should_never_wrap + !but_this_can,\n' +
 2645             '    proper: "first_token_should_never_wrap" + "but_this_can"\n' +
 2646             '}')
 2647         test_fragment(
 2648             '' + wrap_input_2 + '',
 2649             #  -- output --
 2650             '{\n' +
 2651             '    foo.bar().baz().cucumber((f && "sass") || (leans && mean));\n' +
 2652             '    Test_very_long_variable_name_this_should_never_wrap\n' +
 2653             '        .but_this_can\n' +
 2654             '    return between_return_and_expression_should_never_wrap.but_this_can\n' +
 2655             '    throw between_throw_and_expression_should_never_wrap.but_this_can\n' +
 2656             '    if (wraps_can_occur && inside_an_if_block) that_is_\n' +
 2657             '        .okay();\n' +
 2658             '    object_literal = {\n' +
 2659             '        propertx: first_token + 12345678.99999E-6,\n' +
 2660             '        property: first_token_should_never_wrap + but_this_can,\n' +
 2661             '        propertz: first_token_should_never_wrap + !but_this_can,\n' +
 2662             '        proper: "first_token_should_never_wrap" + "but_this_can"\n' +
 2663             '    }\n' +
 2664             '}')
 2665 
 2666 
 2667         #============================================================
 2668         # line wrapping 70
 2669         self.reset_options()
 2670         self.options.preserve_newlines = true
 2671         self.options.wrap_line_length = 70
 2672         test_fragment(
 2673             '' + wrap_input_1 + '',
 2674             #  -- output --
 2675             'foo.bar().baz().cucumber((f && "sass") || (leans && mean));\n' +
 2676             'Test_very_long_variable_name_this_should_never_wrap\n' +
 2677             '    .but_this_can\n' +
 2678             'return between_return_and_expression_should_never_wrap.but_this_can\n' +
 2679             'throw between_throw_and_expression_should_never_wrap.but_this_can\n' +
 2680             'if (wraps_can_occur && inside_an_if_block) that_is_\n' +
 2681             '    .okay();\n' +
 2682             'object_literal = {\n' +
 2683             '    propertx: first_token + 12345678.99999E-6,\n' +
 2684             '    property: first_token_should_never_wrap + but_this_can,\n' +
 2685             '    propertz: first_token_should_never_wrap + !but_this_can,\n' +
 2686             '    proper: "first_token_should_never_wrap" + "but_this_can"\n' +
 2687             '}')
 2688         test_fragment(
 2689             '' + wrap_input_2 + '',
 2690             #  -- output --
 2691             '{\n' +
 2692             '    foo.bar().baz().cucumber((f && "sass") || (leans && mean));\n' +
 2693             '    Test_very_long_variable_name_this_should_never_wrap\n' +
 2694             '        .but_this_can\n' +
 2695             '    return between_return_and_expression_should_never_wrap\n' +
 2696             '        .but_this_can\n' +
 2697             '    throw between_throw_and_expression_should_never_wrap.but_this_can\n' +
 2698             '    if (wraps_can_occur && inside_an_if_block) that_is_\n' +
 2699             '        .okay();\n' +
 2700             '    object_literal = {\n' +
 2701             '        propertx: first_token + 12345678.99999E-6,\n' +
 2702             '        property: first_token_should_never_wrap + but_this_can,\n' +
 2703             '        propertz: first_token_should_never_wrap + !but_this_can,\n' +
 2704             '        proper: "first_token_should_never_wrap" + "but_this_can"\n' +
 2705             '    }\n' +
 2706             '}')
 2707 
 2708 
 2709         #============================================================
 2710         # line wrapping 40
 2711         self.reset_options()
 2712         self.options.preserve_newlines = true
 2713         self.options.wrap_line_length = 40
 2714         test_fragment(
 2715             '' + wrap_input_1 + '',
 2716             #  -- output --
 2717             'foo.bar().baz().cucumber((f &&\n' +
 2718             '    "sass") || (leans && mean));\n' +
 2719             'Test_very_long_variable_name_this_should_never_wrap\n' +
 2720             '    .but_this_can\n' +
 2721             'return between_return_and_expression_should_never_wrap\n' +
 2722             '    .but_this_can\n' +
 2723             'throw between_throw_and_expression_should_never_wrap\n' +
 2724             '    .but_this_can\n' +
 2725             'if (wraps_can_occur &&\n' +
 2726             '    inside_an_if_block) that_is_\n' +
 2727             '    .okay();\n' +
 2728             'object_literal = {\n' +
 2729             '    propertx: first_token +\n' +
 2730             '        12345678.99999E-6,\n' +
 2731             '    property: first_token_should_never_wrap +\n' +
 2732             '        but_this_can,\n' +
 2733             '    propertz: first_token_should_never_wrap +\n' +
 2734             '        !but_this_can,\n' +
 2735             '    proper: "first_token_should_never_wrap" +\n' +
 2736             '        "but_this_can"\n' +
 2737             '}')
 2738         test_fragment(
 2739             '' + wrap_input_2 + '',
 2740             #  -- output --
 2741             '{\n' +
 2742             '    foo.bar().baz().cucumber((f &&\n' +
 2743             '        "sass") || (leans &&\n' +
 2744             '        mean));\n' +
 2745             '    Test_very_long_variable_name_this_should_never_wrap\n' +
 2746             '        .but_this_can\n' +
 2747             '    return between_return_and_expression_should_never_wrap\n' +
 2748             '        .but_this_can\n' +
 2749             '    throw between_throw_and_expression_should_never_wrap\n' +
 2750             '        .but_this_can\n' +
 2751             '    if (wraps_can_occur &&\n' +
 2752             '        inside_an_if_block) that_is_\n' +
 2753             '        .okay();\n' +
 2754             '    object_literal = {\n' +
 2755             '        propertx: first_token +\n' +
 2756             '            12345678.99999E-6,\n' +
 2757             '        property: first_token_should_never_wrap +\n' +
 2758             '            but_this_can,\n' +
 2759             '        propertz: first_token_should_never_wrap +\n' +
 2760             '            !but_this_can,\n' +
 2761             '        proper: "first_token_should_never_wrap" +\n' +
 2762             '            "but_this_can"\n' +
 2763             '    }\n' +
 2764             '}')
 2765 
 2766 
 2767         #============================================================
 2768         # line wrapping 41
 2769         self.reset_options()
 2770         self.options.preserve_newlines = true
 2771         self.options.wrap_line_length = 41
 2772         test_fragment(
 2773             '' + wrap_input_1 + '',
 2774             #  -- output --
 2775             'foo.bar().baz().cucumber((f && "sass") ||\n' +
 2776             '    (leans && mean));\n' +
 2777             'Test_very_long_variable_name_this_should_never_wrap\n' +
 2778             '    .but_this_can\n' +
 2779             'return between_return_and_expression_should_never_wrap\n' +
 2780             '    .but_this_can\n' +
 2781             'throw between_throw_and_expression_should_never_wrap\n' +
 2782             '    .but_this_can\n' +
 2783             'if (wraps_can_occur &&\n' +
 2784             '    inside_an_if_block) that_is_\n' +
 2785             '    .okay();\n' +
 2786             'object_literal = {\n' +
 2787             '    propertx: first_token +\n' +
 2788             '        12345678.99999E-6,\n' +
 2789             '    property: first_token_should_never_wrap +\n' +
 2790             '        but_this_can,\n' +
 2791             '    propertz: first_token_should_never_wrap +\n' +
 2792             '        !but_this_can,\n' +
 2793             '    proper: "first_token_should_never_wrap" +\n' +
 2794             '        "but_this_can"\n' +
 2795             '}')
 2796         test_fragment(
 2797             '' + wrap_input_2 + '',
 2798             #  -- output --
 2799             '{\n' +
 2800             '    foo.bar().baz().cucumber((f &&\n' +
 2801             '        "sass") || (leans &&\n' +
 2802             '        mean));\n' +
 2803             '    Test_very_long_variable_name_this_should_never_wrap\n' +
 2804             '        .but_this_can\n' +
 2805             '    return between_return_and_expression_should_never_wrap\n' +
 2806             '        .but_this_can\n' +
 2807             '    throw between_throw_and_expression_should_never_wrap\n' +
 2808             '        .but_this_can\n' +
 2809             '    if (wraps_can_occur &&\n' +
 2810             '        inside_an_if_block) that_is_\n' +
 2811             '        .okay();\n' +
 2812             '    object_literal = {\n' +
 2813             '        propertx: first_token +\n' +
 2814             '            12345678.99999E-6,\n' +
 2815             '        property: first_token_should_never_wrap +\n' +
 2816             '            but_this_can,\n' +
 2817             '        propertz: first_token_should_never_wrap +\n' +
 2818             '            !but_this_can,\n' +
 2819             '        proper: "first_token_should_never_wrap" +\n' +
 2820             '            "but_this_can"\n' +
 2821             '    }\n' +
 2822             '}')
 2823 
 2824 
 2825         #============================================================
 2826         # line wrapping 45
 2827         self.reset_options()
 2828         self.options.preserve_newlines = true
 2829         self.options.wrap_line_length = 45
 2830         test_fragment(
 2831             '' + wrap_input_1 + '',
 2832             #  -- output --
 2833             'foo.bar().baz().cucumber((f && "sass") || (\n' +
 2834             '    leans && mean));\n' +
 2835             'Test_very_long_variable_name_this_should_never_wrap\n' +
 2836             '    .but_this_can\n' +
 2837             'return between_return_and_expression_should_never_wrap\n' +
 2838             '    .but_this_can\n' +
 2839             'throw between_throw_and_expression_should_never_wrap\n' +
 2840             '    .but_this_can\n' +
 2841             'if (wraps_can_occur && inside_an_if_block)\n' +
 2842             '    that_is_\n' +
 2843             '    .okay();\n' +
 2844             'object_literal = {\n' +
 2845             '    propertx: first_token +\n' +
 2846             '        12345678.99999E-6,\n' +
 2847             '    property: first_token_should_never_wrap +\n' +
 2848             '        but_this_can,\n' +
 2849             '    propertz: first_token_should_never_wrap +\n' +
 2850             '        !but_this_can,\n' +
 2851             '    proper: "first_token_should_never_wrap" +\n' +
 2852             '        "but_this_can"\n' +
 2853             '}')
 2854         test_fragment(
 2855             '' + wrap_input_2 + '',
 2856             #  -- output --
 2857             '{\n' +
 2858             '    foo.bar().baz().cucumber((f && "sass") ||\n' +
 2859             '        (leans && mean));\n' +
 2860             '    Test_very_long_variable_name_this_should_never_wrap\n' +
 2861             '        .but_this_can\n' +
 2862             '    return between_return_and_expression_should_never_wrap\n' +
 2863             '        .but_this_can\n' +
 2864             '    throw between_throw_and_expression_should_never_wrap\n' +
 2865             '        .but_this_can\n' +
 2866             '    if (wraps_can_occur &&\n' +
 2867             '        inside_an_if_block) that_is_\n' +
 2868             '        .okay();\n' +
 2869             '    object_literal = {\n' +
 2870             '        propertx: first_token +\n' +
 2871             '            12345678.99999E-6,\n' +
 2872             '        property: first_token_should_never_wrap +\n' +
 2873             '            but_this_can,\n' +
 2874             '        propertz: first_token_should_never_wrap +\n' +
 2875             '            !but_this_can,\n' +
 2876             '        proper: "first_token_should_never_wrap" +\n' +
 2877             '            "but_this_can"\n' +
 2878             '    }\n' +
 2879             '}')
 2880 
 2881 
 2882         #============================================================
 2883         # general preserve_newlines tests preserve limit
 2884         self.reset_options()
 2885         self.options.preserve_newlines = true
 2886         self.options.max_preserve_newlines = 8
 2887         bt(
 2888             'a = 1;\n' +
 2889             '\n' +
 2890             '\n' +
 2891             '\n' +
 2892             '\n' +
 2893             '\n' +
 2894             '\n' +
 2895             '\n' +
 2896             '\n' +
 2897             '\n' +
 2898             '\n' +
 2899             '\n' +
 2900             '\n' +
 2901             '\n' +
 2902             '\n' +
 2903             '\n' +
 2904             '\n' +
 2905             '\n' +
 2906             '\n' +
 2907             '\n' +
 2908             '\n' +
 2909             '\n' +
 2910             'b = 2;',
 2911             #  -- output --
 2912             'a = 1;\n' +
 2913             '\n' +
 2914             '\n' +
 2915             '\n' +
 2916             '\n' +
 2917             '\n' +
 2918             '\n' +
 2919             '\n' +
 2920             'b = 2;')
 2921 
 2922 
 2923         #============================================================
 2924         # more random test
 2925         self.reset_options()
 2926         bt('return function();')
 2927         bt('var a = function();')
 2928         bt('var a = 5 + function();')
 2929         
 2930         # actionscript import
 2931         bt('import foo.*;')
 2932         
 2933         # actionscript
 2934         bt('function f(a: a, b: b)')
 2935         bt(
 2936             'function a(a) {} function b(b) {} function c(c) {}',
 2937             #  -- output --
 2938             'function a(a) {}\n' +
 2939             '\n' +
 2940             'function b(b) {}\n' +
 2941             '\n' +
 2942             'function c(c) {}')
 2943         bt('foo(a, function() {})')
 2944         bt('foo(a, /regex/)')
 2945         bt(
 2946             '/* foo */\n' +
 2947             '"x"')
 2948         test_fragment(
 2949             'roo = {\n' +
 2950             '    /*\n' +
 2951             '    ****\n' +
 2952             '      FOO\n' +
 2953             '    ****\n' +
 2954             '    */\n' +
 2955             '    BAR: 0\n' +
 2956             '};')
 2957         test_fragment(
 2958             'if (zz) {\n' +
 2959             '    // ....\n' +
 2960             '}\n' +
 2961             '(function')
 2962         bt(
 2963             'a = //comment\n' +
 2964             '    /regex/;')
 2965         bt('var a = new function();')
 2966         bt('new function')
 2967         bt(
 2968             'if (a)\n' +
 2969             '{\n' +
 2970             'b;\n' +
 2971             '}\n' +
 2972             'else\n' +
 2973             '{\n' +
 2974             'c;\n' +
 2975             '}',
 2976             #  -- output --
 2977             'if (a) {\n' +
 2978             '    b;\n' +
 2979             '} else {\n' +
 2980             '    c;\n' +
 2981             '}')
 2982         bt('fn`tagged`')
 2983         bt('fn()`tagged`')
 2984         bt('fn`${algo} ${`6string`}`')
 2985         bt('fn`${fn2()} more text ${`${`more text`}`} banana ${fn3`test`} ${fn4()`moretest banana2`}`')
 2986         bt('`untagged`+`untagged`', '`untagged` + `untagged`')
 2987         bt('fun() `taggedd`')
 2988         bt('fn[0]`tagged`', 'fn[0] `tagged`')
 2989 
 2990 
 2991         #============================================================
 2992         # operator_position option - ensure no newlines if preserve_newlines is false - (preserve_newlines = "false")
 2993         self.reset_options()
 2994         self.options.preserve_newlines = false
 2995         bt(
 2996             'var res = a + b - c / d * e % f;\n' +
 2997             'var res = g & h | i ^ j |> console.log;\n' +
 2998             'var res = (k && l || m) ? n ?? nn : o;\n' +
 2999             'var res = p >> q << r >>> s;\n' +
 3000             'var res = t === u !== v != w == x >= y <= z > aa < ab;\n' +
 3001             'ac + -ad')
 3002         bt(
 3003             'var res = a + b\n' +
 3004             '- c /\n' +
 3005             'd  *     e\n' +
 3006             '%\n' +
 3007             'f;\n' +
 3008             '   var res = g & h\n' +
 3009             '| i ^\n' +
 3010             'j\n' +
 3011             '|> console.log;\n' +
 3012             'var res = (k &&\n' +
 3013             'l\n' +
 3014             '|| m) ?\n' +
 3015             'n\n' +
 3016             '?? nn\n' +
 3017             ': o\n' +
 3018             ';\n' +
 3019             'var res = p\n' +
 3020             '>> q <<\n' +
 3021             'r\n' +
 3022             '>>> s;\n' +
 3023             'var res\n' +
 3024             '  = t\n' +
 3025             '\n' +
 3026             ' === u !== v\n' +
 3027             ' !=\n' +
 3028             'w\n' +
 3029             '== x >=\n' +
 3030             'y <= z > aa <\n' +
 3031             'ab;\n' +
 3032             'ac +\n' +
 3033             '-ad',
 3034             #  -- output --
 3035             'var res = a + b - c / d * e % f;\n' +
 3036             'var res = g & h | i ^ j |> console.log;\n' +
 3037             'var res = (k && l || m) ? n ?? nn : o;\n' +
 3038             'var res = p >> q << r >>> s;\n' +
 3039             'var res = t === u !== v != w == x >= y <= z > aa < ab;\n' +
 3040             'ac + -ad')
 3041 
 3042         # operator_position option - ensure no newlines if preserve_newlines is false - (operator_position = ""before-newline"", preserve_newlines = "false")
 3043         self.reset_options()
 3044         self.options.operator_position = 'before-newline'
 3045         self.options.preserve_newlines = false
 3046         bt(
 3047             'var res = a + b - c / d * e % f;\n' +
 3048             'var res = g & h | i ^ j |> console.log;\n' +
 3049             'var res = (k && l || m) ? n ?? nn : o;\n' +
 3050             'var res = p >> q << r >>> s;\n' +
 3051             'var res = t === u !== v != w == x >= y <= z > aa < ab;\n' +
 3052             'ac + -ad')
 3053         bt(
 3054             'var res = a + b\n' +
 3055             '- c /\n' +
 3056             'd  *     e\n' +
 3057             '%\n' +
 3058             'f;\n' +
 3059             '   var res = g & h\n' +
 3060             '| i ^\n' +
 3061             'j\n' +
 3062             '|> console.log;\n' +
 3063             'var res = (k &&\n' +
 3064             'l\n' +
 3065             '|| m) ?\n' +
 3066             'n\n' +
 3067             '?? nn\n' +
 3068             ': o\n' +
 3069             ';\n' +
 3070             'var res = p\n' +
 3071             '>> q <<\n' +
 3072             'r\n' +
 3073             '>>> s;\n' +
 3074             'var res\n' +
 3075             '  = t\n' +
 3076             '\n' +
 3077             ' === u !== v\n' +
 3078             ' !=\n' +
 3079             'w\n' +
 3080             '== x >=\n' +
 3081             'y <= z > aa <\n' +
 3082             'ab;\n' +
 3083             'ac +\n' +
 3084             '-ad',
 3085             #  -- output --
 3086             'var res = a + b - c / d * e % f;\n' +
 3087             'var res = g & h | i ^ j |> console.log;\n' +
 3088             'var res = (k && l || m) ? n ?? nn : o;\n' +
 3089             'var res = p >> q << r >>> s;\n' +
 3090             'var res = t === u !== v != w == x >= y <= z > aa < ab;\n' +
 3091             'ac + -ad')
 3092 
 3093         # operator_position option - ensure no newlines if preserve_newlines is false - (operator_position = ""after-newline"", preserve_newlines = "false")
 3094         self.reset_options()
 3095         self.options.operator_position = 'after-newline'
 3096         self.options.preserve_newlines = false
 3097         bt(
 3098             'var res = a + b - c / d * e % f;\n' +
 3099             'var res = g & h | i ^ j |> console.log;\n' +
 3100             'var res = (k && l || m) ? n ?? nn : o;\n' +
 3101             'var res = p >> q << r >>> s;\n' +
 3102             'var res = t === u !== v != w == x >= y <= z > aa < ab;\n' +
 3103             'ac + -ad')
 3104         bt(
 3105             'var res = a + b\n' +
 3106             '- c /\n' +
 3107             'd  *     e\n' +
 3108             '%\n' +
 3109             'f;\n' +
 3110             '   var res = g & h\n' +
 3111             '| i ^\n' +
 3112             'j\n' +
 3113             '|> console.log;\n' +
 3114             'var res = (k &&\n' +
 3115             'l\n' +
 3116             '|| m) ?\n' +
 3117             'n\n' +
 3118             '?? nn\n' +
 3119             ': o\n' +
 3120             ';\n' +
 3121             'var res = p\n' +
 3122             '>> q <<\n' +
 3123             'r\n' +
 3124             '>>> s;\n' +
 3125             'var res\n' +
 3126             '  = t\n' +
 3127             '\n' +
 3128             ' === u !== v\n' +
 3129             ' !=\n' +
 3130             'w\n' +
 3131             '== x >=\n' +
 3132             'y <= z > aa <\n' +
 3133             'ab;\n' +
 3134             'ac +\n' +
 3135             '-ad',
 3136             #  -- output --
 3137             'var res = a + b - c / d * e % f;\n' +
 3138             'var res = g & h | i ^ j |> console.log;\n' +
 3139             'var res = (k && l || m) ? n ?? nn : o;\n' +
 3140             'var res = p >> q << r >>> s;\n' +
 3141             'var res = t === u !== v != w == x >= y <= z > aa < ab;\n' +
 3142             'ac + -ad')
 3143 
 3144         # operator_position option - ensure no newlines if preserve_newlines is false - (operator_position = ""preserve-newline"", preserve_newlines = "false")
 3145         self.reset_options()
 3146         self.options.operator_position = 'preserve-newline'
 3147         self.options.preserve_newlines = false
 3148         bt(
 3149             'var res = a + b - c / d * e % f;\n' +
 3150             'var res = g & h | i ^ j |> console.log;\n' +
 3151             'var res = (k && l || m) ? n ?? nn : o;\n' +
 3152             'var res = p >> q << r >>> s;\n' +
 3153             'var res = t === u !== v != w == x >= y <= z > aa < ab;\n' +
 3154             'ac + -ad')
 3155         bt(
 3156             'var res = a + b\n' +
 3157             '- c /\n' +
 3158             'd  *     e\n' +
 3159             '%\n' +
 3160             'f;\n' +
 3161             '   var res = g & h\n' +
 3162             '| i ^\n' +
 3163             'j\n' +
 3164             '|> console.log;\n' +
 3165             'var res = (k &&\n' +
 3166             'l\n' +
 3167             '|| m) ?\n' +
 3168             'n\n' +
 3169             '?? nn\n' +
 3170             ': o\n' +
 3171             ';\n' +
 3172             'var res = p\n' +
 3173             '>> q <<\n' +
 3174             'r\n' +
 3175             '>>> s;\n' +
 3176             'var res\n' +
 3177             '  = t\n' +
 3178             '\n' +
 3179             ' === u !== v\n' +
 3180             ' !=\n' +
 3181             'w\n' +
 3182             '== x >=\n' +
 3183             'y <= z > aa <\n' +
 3184             'ab;\n' +
 3185             'ac +\n' +
 3186             '-ad',
 3187             #  -- output --
 3188             'var res = a + b - c / d * e % f;\n' +
 3189             'var res = g & h | i ^ j |> console.log;\n' +
 3190             'var res = (k && l || m) ? n ?? nn : o;\n' +
 3191             'var res = p >> q << r >>> s;\n' +
 3192             'var res = t === u !== v != w == x >= y <= z > aa < ab;\n' +
 3193             'ac + -ad')
 3194 
 3195 
 3196         #============================================================
 3197         # operator_position option - set to "before-newline" (default value) - ()
 3198         self.reset_options()
 3199         
 3200         # comprehensive, various newlines
 3201         bt(
 3202             'var res = a + b\n' +
 3203             '- c /\n' +
 3204             'd  *     e\n' +
 3205             '%\n' +
 3206             'f;\n' +
 3207             '   var res = g & h\n' +
 3208             '| i ^\n' +
 3209             'j\n' +
 3210             '|> console.log;\n' +
 3211             'var res = (k &&\n' +
 3212             'l\n' +
 3213             '|| m) ?\n' +
 3214             'n\n' +
 3215             '?? nn\n' +
 3216             ': o\n' +
 3217             ';\n' +
 3218             'var res = p\n' +
 3219             '>> q <<\n' +
 3220             'r\n' +
 3221             '>>> s;\n' +
 3222             'var res\n' +
 3223             '  = t\n' +
 3224             '\n' +
 3225             ' === u !== v\n' +
 3226             ' !=\n' +
 3227             'w\n' +
 3228             '== x >=\n' +
 3229             'y <= z > aa <\n' +
 3230             'ab;\n' +
 3231             'ac +\n' +
 3232             '-ad',
 3233             #  -- output --
 3234             'var res = a + b -\n' +
 3235             '    c /\n' +
 3236             '    d * e %\n' +
 3237             '    f;\n' +
 3238             'var res = g & h |\n' +
 3239             '    i ^\n' +
 3240             '    j |>\n' +
 3241             '    console.log;\n' +
 3242             'var res = (k &&\n' +
 3243             '        l ||\n' +
 3244             '        m) ?\n' +
 3245             '    n ??\n' +
 3246             '    nn :\n' +
 3247             '    o;\n' +
 3248             'var res = p >>\n' +
 3249             '    q <<\n' +
 3250             '    r >>>\n' +
 3251             '    s;\n' +
 3252             'var res = t\n' +
 3253             '\n' +
 3254             '    ===\n' +
 3255             '    u !== v !=\n' +
 3256             '    w ==\n' +
 3257             '    x >=\n' +
 3258             '    y <= z > aa <\n' +
 3259             '    ab;\n' +
 3260             'ac +\n' +
 3261             '    -ad')
 3262         
 3263         # colon special case
 3264         bt(
 3265             'var a = {\n' +
 3266             '    b\n' +
 3267             ': bval,\n' +
 3268             '    c:\n' +
 3269             'cval\n' +
 3270             '    ,d: dval\n' +
 3271             '};\n' +
 3272             'var e = f ? g\n' +
 3273             ': h;\n' +
 3274             'var i = j ? k :\n' +
 3275             'l;',
 3276             #  -- output --
 3277             'var a = {\n' +
 3278             '    b: bval,\n' +
 3279             '    c: cval,\n' +
 3280             '    d: dval\n' +
 3281             '};\n' +
 3282             'var e = f ? g :\n' +
 3283             '    h;\n' +
 3284             'var i = j ? k :\n' +
 3285             '    l;')
 3286         
 3287         # catch-all, includes brackets and other various code
 3288         bt(
 3289             'var d = 1;\n' +
 3290             'if (a === b\n' +
 3291             '    && c) {\n' +
 3292             '    d = (c * everything\n' +
 3293             '            / something_else) %\n' +
 3294             '        b;\n' +
 3295             '    e\n' +
 3296             '        += d;\n' +
 3297             '\n' +
 3298             '} else if (!(complex && simple) ||\n' +
 3299             '    (emotion && emotion.name === "happy")) {\n' +
 3300             '    cryTearsOfJoy(many ||\n' +
 3301             '        anOcean\n' +
 3302             '        || aRiver);\n' +
 3303             '}',
 3304             #  -- output --
 3305             'var d = 1;\n' +
 3306             'if (a === b &&\n' +
 3307             '    c) {\n' +
 3308             '    d = (c * everything /\n' +
 3309             '            something_else) %\n' +
 3310             '        b;\n' +
 3311             '    e\n' +
 3312             '        += d;\n' +
 3313             '\n' +
 3314             '} else if (!(complex && simple) ||\n' +
 3315             '    (emotion && emotion.name === "happy")) {\n' +
 3316             '    cryTearsOfJoy(many ||\n' +
 3317             '        anOcean ||\n' +
 3318             '        aRiver);\n' +
 3319             '}')
 3320 
 3321         # operator_position option - set to "before-newline" (default value) - (operator_position = ""before-newline"")
 3322         self.reset_options()
 3323         self.options.operator_position = 'before-newline'
 3324         
 3325         # comprehensive, various newlines
 3326         bt(
 3327             'var res = a + b\n' +
 3328             '- c /\n' +
 3329             'd  *     e\n' +
 3330             '%\n' +
 3331             'f;\n' +
 3332             '   var res = g & h\n' +
 3333             '| i ^\n' +
 3334             'j\n' +
 3335             '|> console.log;\n' +
 3336             'var res = (k &&\n' +
 3337             'l\n' +
 3338             '|| m) ?\n' +
 3339             'n\n' +
 3340             '?? nn\n' +
 3341             ': o\n' +
 3342             ';\n' +
 3343             'var res = p\n' +
 3344             '>> q <<\n' +
 3345             'r\n' +
 3346             '>>> s;\n' +
 3347             'var res\n' +
 3348             '  = t\n' +
 3349             '\n' +
 3350             ' === u !== v\n' +
 3351             ' !=\n' +
 3352             'w\n' +
 3353             '== x >=\n' +
 3354             'y <= z > aa <\n' +
 3355             'ab;\n' +
 3356             'ac +\n' +
 3357             '-ad',
 3358             #  -- output --
 3359             'var res = a + b -\n' +
 3360             '    c /\n' +
 3361             '    d * e %\n' +
 3362             '    f;\n' +
 3363             'var res = g & h |\n' +
 3364             '    i ^\n' +
 3365             '    j |>\n' +
 3366             '    console.log;\n' +
 3367             'var res = (k &&\n' +
 3368             '        l ||\n' +
 3369             '        m) ?\n' +
 3370             '    n ??\n' +
 3371             '    nn :\n' +
 3372             '    o;\n' +
 3373             'var res = p >>\n' +
 3374             '    q <<\n' +
 3375             '    r >>>\n' +
 3376             '    s;\n' +
 3377             'var res = t\n' +
 3378             '\n' +
 3379             '    ===\n' +
 3380             '    u !== v !=\n' +
 3381             '    w ==\n' +
 3382             '    x >=\n' +
 3383             '    y <= z > aa <\n' +
 3384             '    ab;\n' +
 3385             'ac +\n' +
 3386             '    -ad')
 3387         
 3388         # colon special case
 3389         bt(
 3390             'var a = {\n' +
 3391             '    b\n' +
 3392             ': bval,\n' +
 3393             '    c:\n' +
 3394             'cval\n' +
 3395             '    ,d: dval\n' +
 3396             '};\n' +
 3397             'var e = f ? g\n' +
 3398             ': h;\n' +
 3399             'var i = j ? k :\n' +
 3400             'l;',
 3401             #  -- output --
 3402             'var a = {\n' +
 3403             '    b: bval,\n' +
 3404             '    c: cval,\n' +
 3405             '    d: dval\n' +
 3406             '};\n' +
 3407             'var e = f ? g :\n' +
 3408             '    h;\n' +
 3409             'var i = j ? k :\n' +
 3410             '    l;')
 3411         
 3412         # catch-all, includes brackets and other various code
 3413         bt(
 3414             'var d = 1;\n' +
 3415             'if (a === b\n' +
 3416             '    && c) {\n' +
 3417             '    d = (c * everything\n' +
 3418             '            / something_else) %\n' +
 3419             '        b;\n' +
 3420             '    e\n' +
 3421             '        += d;\n' +
 3422             '\n' +
 3423             '} else if (!(complex && simple) ||\n' +
 3424             '    (emotion && emotion.name === "happy")) {\n' +
 3425             '    cryTearsOfJoy(many ||\n' +
 3426             '        anOcean\n' +
 3427             '        || aRiver);\n' +
 3428             '}',
 3429             #  -- output --
 3430             'var d = 1;\n' +
 3431             'if (a === b &&\n' +
 3432             '    c) {\n' +
 3433             '    d = (c * everything /\n' +
 3434             '            something_else) %\n' +
 3435             '        b;\n' +
 3436             '    e\n' +
 3437             '        += d;\n' +
 3438             '\n' +
 3439             '} else if (!(complex && simple) ||\n' +
 3440             '    (emotion && emotion.name === "happy")) {\n' +
 3441             '    cryTearsOfJoy(many ||\n' +
 3442             '        anOcean ||\n' +
 3443             '        aRiver);\n' +
 3444             '}')
 3445 
 3446 
 3447         #============================================================
 3448         # operator_position option - set to "after_newline"
 3449         self.reset_options()
 3450         self.options.operator_position = 'after-newline'
 3451         
 3452         # comprehensive, various newlines
 3453         bt(
 3454             'var res = a + b\n' +
 3455             '- c /\n' +
 3456             'd  *     e\n' +
 3457             '%\n' +
 3458             'f;\n' +
 3459             '   var res = g & h\n' +
 3460             '| i ^\n' +
 3461             'j\n' +
 3462             '|> console.log;\n' +
 3463             'var res = (k &&\n' +
 3464             'l\n' +
 3465             '|| m) ?\n' +
 3466             'n\n' +
 3467             '?? nn\n' +
 3468             ': o\n' +
 3469             ';\n' +
 3470             'var res = p\n' +
 3471             '>> q <<\n' +
 3472             'r\n' +
 3473             '>>> s;\n' +
 3474             'var res\n' +
 3475             '  = t\n' +
 3476             '\n' +
 3477             ' === u !== v\n' +
 3478             ' !=\n' +
 3479             'w\n' +
 3480             '== x >=\n' +
 3481             'y <= z > aa <\n' +
 3482             'ab;\n' +
 3483             'ac +\n' +
 3484             '-ad',
 3485             #  -- output --
 3486             'var res = a + b\n' +
 3487             '    - c\n' +
 3488             '    / d * e\n' +
 3489             '    % f;\n' +
 3490             'var res = g & h\n' +
 3491             '    | i\n' +
 3492             '    ^ j\n' +
 3493             '    |> console.log;\n' +
 3494             'var res = (k\n' +
 3495             '        && l\n' +
 3496             '        || m)\n' +
 3497             '    ? n\n' +
 3498             '    ?? nn\n' +
 3499             '    : o;\n' +
 3500             'var res = p\n' +
 3501             '    >> q\n' +
 3502             '    << r\n' +
 3503             '    >>> s;\n' +
 3504             'var res = t\n' +
 3505             '\n' +
 3506             '    === u !== v\n' +
 3507             '    != w\n' +
 3508             '    == x\n' +
 3509             '    >= y <= z > aa\n' +
 3510             '    < ab;\n' +
 3511             'ac\n' +
 3512             '    + -ad')
 3513         
 3514         # colon special case
 3515         bt(
 3516             'var a = {\n' +
 3517             '    b\n' +
 3518             ': bval,\n' +
 3519             '    c:\n' +
 3520             'cval\n' +
 3521             '    ,d: dval\n' +
 3522             '};\n' +
 3523             'var e = f ? g\n' +
 3524             ': h;\n' +
 3525             'var i = j ? k :\n' +
 3526             'l;',
 3527             #  -- output --
 3528             'var a = {\n' +
 3529             '    b: bval,\n' +
 3530             '    c: cval,\n' +
 3531             '    d: dval\n' +
 3532             '};\n' +
 3533             'var e = f ? g\n' +
 3534             '    : h;\n' +
 3535             'var i = j ? k\n' +
 3536             '    : l;')
 3537         
 3538         # catch-all, includes brackets and other various code
 3539         bt(
 3540             'var d = 1;\n' +
 3541             'if (a === b\n' +
 3542             '    && c) {\n' +
 3543             '    d = (c * everything\n' +
 3544             '            / something_else) %\n' +
 3545             '        b;\n' +
 3546             '    e\n' +
 3547             '        += d;\n' +
 3548             '\n' +
 3549             '} else if (!(complex && simple) ||\n' +
 3550             '    (emotion && emotion.name === "happy")) {\n' +
 3551             '    cryTearsOfJoy(many ||\n' +
 3552             '        anOcean\n' +
 3553             '        || aRiver);\n' +
 3554             '}',
 3555             #  -- output --
 3556             'var d = 1;\n' +
 3557             'if (a === b\n' +
 3558             '    && c) {\n' +
 3559             '    d = (c * everything\n' +
 3560             '            / something_else)\n' +
 3561             '        % b;\n' +
 3562             '    e\n' +
 3563             '        += d;\n' +
 3564             '\n' +
 3565             '} else if (!(complex && simple)\n' +
 3566             '    || (emotion && emotion.name === "happy")) {\n' +
 3567             '    cryTearsOfJoy(many\n' +
 3568             '        || anOcean\n' +
 3569             '        || aRiver);\n' +
 3570             '}')
 3571 
 3572 
 3573         #============================================================
 3574         # operator_position option - set to "preserve-newline"
 3575         self.reset_options()
 3576         self.options.operator_position = 'preserve-newline'
 3577         
 3578         # comprehensive, various newlines
 3579         bt(
 3580             'var res = a + b\n' +
 3581             '- c /\n' +
 3582             'd  *     e\n' +
 3583             '%\n' +
 3584             'f;\n' +
 3585             '   var res = g & h\n' +
 3586             '| i ^\n' +
 3587             'j\n' +
 3588             '|> console.log;\n' +
 3589             'var res = (k &&\n' +
 3590             'l\n' +
 3591             '|| m) ?\n' +
 3592             'n\n' +
 3593             '?? nn\n' +
 3594             ': o\n' +
 3595             ';\n' +
 3596             'var res = p\n' +
 3597             '>> q <<\n' +
 3598             'r\n' +
 3599             '>>> s;\n' +
 3600             'var res\n' +
 3601             '  = t\n' +
 3602             '\n' +
 3603             ' === u !== v\n' +
 3604             ' !=\n' +
 3605             'w\n' +
 3606             '== x >=\n' +
 3607             'y <= z > aa <\n' +
 3608             'ab;\n' +
 3609             'ac +\n' +
 3610             '-ad',
 3611             #  -- output --
 3612             'var res = a + b\n' +
 3613             '    - c /\n' +
 3614             '    d * e\n' +
 3615             '    %\n' +
 3616             '    f;\n' +
 3617             'var res = g & h\n' +
 3618             '    | i ^\n' +
 3619             '    j\n' +
 3620             '    |> console.log;\n' +
 3621             'var res = (k &&\n' +
 3622             '        l\n' +
 3623             '        || m) ?\n' +
 3624             '    n\n' +
 3625             '    ?? nn\n' +
 3626             '    : o;\n' +
 3627             'var res = p\n' +
 3628             '    >> q <<\n' +
 3629             '    r\n' +
 3630             '    >>> s;\n' +
 3631             'var res = t\n' +
 3632             '\n' +
 3633             '    === u !== v\n' +
 3634             '    !=\n' +
 3635             '    w\n' +
 3636             '    == x >=\n' +
 3637             '    y <= z > aa <\n' +
 3638             '    ab;\n' +
 3639             'ac +\n' +
 3640             '    -ad')
 3641         
 3642         # colon special case
 3643         bt(
 3644             'var a = {\n' +
 3645             '    b\n' +
 3646             ': bval,\n' +
 3647             '    c:\n' +
 3648             'cval\n' +
 3649             '    ,d: dval\n' +
 3650             '};\n' +
 3651             'var e = f ? g\n' +
 3652             ': h;\n' +
 3653             'var i = j ? k :\n' +
 3654             'l;',
 3655             #  -- output --
 3656             'var a = {\n' +
 3657             '    b: bval,\n' +
 3658             '    c: cval,\n' +
 3659             '    d: dval\n' +
 3660             '};\n' +
 3661             'var e = f ? g\n' +
 3662             '    : h;\n' +
 3663             'var i = j ? k :\n' +
 3664             '    l;')
 3665         
 3666         # catch-all, includes brackets and other various code
 3667         bt(
 3668             'var d = 1;\n' +
 3669             'if (a === b\n' +
 3670             '    && c) {\n' +
 3671             '    d = (c * everything\n' +
 3672             '            / something_else) %\n' +
 3673             '        b;\n' +
 3674             '    e\n' +
 3675             '        += d;\n' +
 3676             '\n' +
 3677             '} else if (!(complex && simple) ||\n' +
 3678             '    (emotion && emotion.name === "happy")) {\n' +
 3679             '    cryTearsOfJoy(many ||\n' +
 3680             '        anOcean\n' +
 3681             '        || aRiver);\n' +
 3682             '}')
 3683 
 3684 
 3685         #============================================================
 3686         # Yield tests
 3687         self.reset_options()
 3688         bt('yield /foo\\//;')
 3689         bt('result = yield pgClient.query_(queryString);')
 3690         bt('yield [1, 2]')
 3691         bt('yield function() {};')
 3692         bt('yield* bar();')
 3693         
 3694         # yield should have no space between yield and star
 3695         bt('yield * bar();', 'yield* bar();')
 3696         
 3697         # yield should have space between star and generator
 3698         bt('yield *bar();', 'yield* bar();')
 3699 
 3700 
 3701         #============================================================
 3702         # Async / await tests
 3703         self.reset_options()
 3704         bt('async function foo() {}')
 3705         bt('let w = async function foo() {}')
 3706         bt(
 3707             'async function foo() {}\n' +
 3708             'var x = await foo();')
 3709         
 3710         # async function as an input to another function
 3711         bt('wrapper(async function foo() {})')
 3712         
 3713         # await on inline anonymous function. should have a space after await
 3714         bt(
 3715             'async function() {\n' +
 3716             '    var w = await(async function() {\n' +
 3717             '        return await foo();\n' +
 3718             '    })();\n' +
 3719             '}',
 3720             #  -- output --
 3721             'async function() {\n' +
 3722             '    var w = await (async function() {\n' +
 3723             '        return await foo();\n' +
 3724             '    })();\n' +
 3725             '}')
 3726         
 3727         # Regression test #1228
 3728         bt('const module = await import("...")')
 3729         
 3730         # Regression test #1658
 3731         bt('.')
 3732         
 3733         # ensure that this doesn't break anyone with the async library
 3734         bt('async.map(function(t) {})')
 3735         
 3736         # async on arrow function. should have a space after async
 3737         bt(
 3738             'async() => {}',
 3739             #  -- output --
 3740             'async () => {}')
 3741         
 3742         # async on arrow function. should have a space after async
 3743         bt(
 3744             'async() => {\n' +
 3745             '    return 5;\n' +
 3746             '}',
 3747             #  -- output --
 3748             'async () => {\n' +
 3749             '    return 5;\n' +
 3750             '}')
 3751         
 3752         # async on arrow function returning expression. should have a space after async
 3753         bt(
 3754             'async() => 5;',
 3755             #  -- output --
 3756             'async () => 5;')
 3757         
 3758         # async on arrow function returning object literal. should have a space after async
 3759         bt(
 3760             'async(x) => ({\n' +
 3761             '    foo: "5"\n' +
 3762             '})',
 3763             #  -- output --
 3764             'async (x) => ({\n' +
 3765             '    foo: "5"\n' +
 3766             '})')
 3767         bt(
 3768             'async (x) => {\n' +
 3769             '    return x * 2;\n' +
 3770             '}')
 3771         bt('async () => 5;')
 3772         bt('async x => x * 2;')
 3773         bt(
 3774             'async function() {\n' +
 3775             '    const obj = {\n' +
 3776             '        a: 1,\n' +
 3777             '        b: await fn(),\n' +
 3778             '        c: 2\n' +
 3779             '    };\n' +
 3780             '}')
 3781         bt(
 3782             'const a = 1,\n' +
 3783             '    b = a ? await foo() : b,\n' +
 3784             '    c = await foo(),\n' +
 3785             '    d = 3,\n' +
 3786             '    e = (await foo()),\n' +
 3787             '    f = 4;')
 3788         bt(
 3789             'a = {\n' +
 3790             '    myVar: async function() {\n' +
 3791             '        return a;\n' +
 3792             '    },\n' +
 3793             '    myOtherVar: async function() {\n' +
 3794             '        yield b;\n' +
 3795             '    }\n' +
 3796             '}')
 3797         bt(
 3798             'a = {\n' +
 3799             '    myVar: async () => {\n' +
 3800             '        return a;\n' +
 3801             '    },\n' +
 3802             '    myOtherVar: async async () => {\n' +
 3803             '        yield b;\n' +
 3804             '    }\n' +
 3805             '}')
 3806 
 3807 
 3808         #============================================================
 3809         # e4x - Test that e4x literals passed through when e4x-option is enabled
 3810         self.reset_options()
 3811         self.options.e4x = true
 3812         bt(
 3813             'xml=<a b="c"><d/><e>\n' +
 3814             ' foo</e>x</a>;',
 3815             #  -- output --
 3816             'xml = <a b="c"><d/><e>\n' +
 3817             ' foo</e>x</a>;')
 3818         bt('<a b=\'This is a quoted "c".\'/>')
 3819         bt('<a b="This is a quoted \'c\'."/>')
 3820         bt('<a b="A quote \' inside string."/>')
 3821         bt('<a b=\'A quote " inside string.\'/>')
 3822         bt('<a b=\'Some """ quotes ""  inside string.\'/>')
 3823         
 3824         # Handles inline expressions
 3825         bt(
 3826             'xml=<{a} b="c"><d/><e v={z}>\n' +
 3827             ' foo</e>x</{a}>;',
 3828             #  -- output --
 3829             'xml = <{a} b="c"><d/><e v={z}>\n' +
 3830             ' foo</e>x</{a}>;')
 3831         bt(
 3832             'xml=<{a} b="c">\n' +
 3833             '    <e v={z}>\n' +
 3834             ' foo</e>x</{a}>;',
 3835             #  -- output --
 3836             'xml = <{a} b="c">\n' +
 3837             '    <e v={z}>\n' +
 3838             ' foo</e>x</{a}>;')
 3839         
 3840         # xml literals with special characters in elem names - see http://www.w3.org/TR/REC-xml/#NT-NameChar
 3841         bt('xml = <_:.valid.xml- _:.valid.xml-="123"/>;')
 3842         
 3843         # xml literals with attributes without equal sign
 3844         bt('xml = <elem someAttr/>;')
 3845         
 3846         # Handles CDATA
 3847         bt(
 3848             'xml=<![CDATA[ b="c"><d/><e v={z}>\n' +
 3849             ' foo</e>x/]]>;',
 3850             #  -- output --
 3851             'xml = <![CDATA[ b="c"><d/><e v={z}>\n' +
 3852             ' foo</e>x/]]>;')
 3853         bt('xml=<![CDATA[]]>;', 'xml = <![CDATA[]]>;')
 3854         bt('xml=<a b="c"><![CDATA[d/></a></{}]]></a>;', 'xml = <a b="c"><![CDATA[d/></a></{}]]></a>;')
 3855         
 3856         # JSX - working jsx from http://prettydiff.com/unit_tests/beautification_javascript_jsx.txt
 3857         bt(
 3858             'var ListItem = React.createClass({\n' +
 3859             '    render: function() {\n' +
 3860             '        return (\n' +
 3861             '            <li className="ListItem">\n' +
 3862             '                <a href={ "/items/" + this.props.item.id }>\n' +
 3863             '                    this.props.item.name\n' +
 3864             '                </a>\n' +
 3865             '            </li>\n' +
 3866             '        );\n' +
 3867             '    }\n' +
 3868             '});')
 3869         bt(
 3870             'var List = React.createClass({\n' +
 3871             '    renderList: function() {\n' +
 3872             '        return this.props.items.map(function(item) {\n' +
 3873             '            return <ListItem item={item} key={item.id} />;\n' +
 3874             '        });\n' +
 3875             '    },\n' +
 3876             '\n' +
 3877             '    render: function() {\n' +
 3878             '        return <ul className="List">\n' +
 3879             '                this.renderList()\n' +
 3880             '            </ul>\n' +
 3881             '    }\n' +
 3882             '});')
 3883         bt(
 3884             'var Mist = React.createClass({\n' +
 3885             '    renderList: function() {\n' +
 3886             '        return this.props.items.map(function(item) {\n' +
 3887             '            return <ListItem item={return <tag>{item}</tag>} key={item.id} />;\n' +
 3888             '        });\n' +
 3889             '    }\n' +
 3890             '});')
 3891         bt(
 3892             '// JSX\n' +
 3893             'var box = <Box>\n' +
 3894             '    {shouldShowAnswer(user) ?\n' +
 3895             '        <Answer value={false}>no</Answer> : <Box.Comment>\n' +
 3896             '        Text Content\n' +
 3897             '        </Box.Comment>}\n' +
 3898             '    </Box>;\n' +
 3899             'var a = function() {\n' +
 3900             '    return <tsdf>asdf</tsdf>;\n' +
 3901             '};\n' +
 3902             '\n' +
 3903             'var HelloMessage = React.createClass({\n' +
 3904             '    render: function() {\n' +
 3905             '        return <div {someAttr}>Hello {this.props.name}</div>;\n' +
 3906             '    }\n' +
 3907             '});\n' +
 3908             'React.render(<HelloMessage name="John" />, mountNode);')
 3909         bt(
 3910             'var Timer = React.createClass({\n' +
 3911             '    getInitialState: function() {\n' +
 3912             '        return {\n' +
 3913             '            secondsElapsed: 0\n' +
 3914             '        };\n' +
 3915             '    },\n' +
 3916             '    tick: function() {\n' +
 3917             '        this.setState({\n' +
 3918             '            secondsElapsed: this.state.secondsElapsed + 1\n' +
 3919             '        });\n' +
 3920             '    },\n' +
 3921             '    componentDidMount: function() {\n' +
 3922             '        this.interval = setInterval(this.tick, 1000);\n' +
 3923             '    },\n' +
 3924             '    componentWillUnmount: function() {\n' +
 3925             '        clearInterval(this.interval);\n' +
 3926             '    },\n' +
 3927             '    render: function() {\n' +
 3928             '        return (\n' +
 3929             '            <div>Seconds Elapsed: {this.state.secondsElapsed}</div>\n' +
 3930             '        );\n' +
 3931             '    }\n' +
 3932             '});\n' +
 3933             'React.render(<Timer />, mountNode);')
 3934         bt(
 3935             'var TodoList = React.createClass({\n' +
 3936             '    render: function() {\n' +
 3937             '        var createItem = function(itemText) {\n' +
 3938             '            return <li>{itemText}</li>;\n' +
 3939             '        };\n' +
 3940             '        return <ul>{this.props.items.map(createItem)}</ul>;\n' +
 3941             '    }\n' +
 3942             '});')
 3943         bt(
 3944             'var TodoApp = React.createClass({\n' +
 3945             '    getInitialState: function() {\n' +
 3946             '        return {\n' +
 3947             '            items: [],\n' +
 3948             '            text: \'\'\n' +
 3949             '        };\n' +
 3950             '    },\n' +
 3951             '    onChange: function(e) {\n' +
 3952             '        this.setState({\n' +
 3953             '            text: e.target.value\n' +
 3954             '        });\n' +
 3955             '    },\n' +
 3956             '    handleSubmit: function(e) {\n' +
 3957             '        e.preventDefault();\n' +
 3958             '        var nextItems = this.state.items.concat([this.state.text]);\n' +
 3959             '        var nextText = \'\';\n' +
 3960             '        this.setState({\n' +
 3961             '            items: nextItems,\n' +
 3962             '            text: nextText\n' +
 3963             '        });\n' +
 3964             '    },\n' +
 3965             '    render: function() {\n' +
 3966             '        return (\n' +
 3967             '            <div>\n' +
 3968             '                <h3 {someAttr}>TODO</h3>\n' +
 3969             '                <TodoList items={this.state.items} />\n' +
 3970             '                <form onSubmit={this.handleSubmit}>\n' +
 3971             '                    <input onChange={this.onChange} value={this.state.text} />\n' +
 3972             '                    <button>{\'Add #\' + (this.state.items.length + 1)}</button>\n' +
 3973             '                </form>\n' +
 3974             '            </div>\n' +
 3975             '        );\n' +
 3976             '    }\n' +
 3977             '});\n' +
 3978             'React.render(<TodoApp />, mountNode);')
 3979         bt(
 3980             'var converter = new Showdown.converter();\n' +
 3981             'var MarkdownEditor = React.createClass({\n' +
 3982             '    getInitialState: function() {\n' +
 3983             '        return {value: \'Type some *markdown* here!\'};\n' +
 3984             '    },\n' +
 3985             '    handleChange: function() {\n' +
 3986             '        this.setState({value: this.refs.textarea.getDOMNode().value});\n' +
 3987             '    },\n' +
 3988             '    render: function() {\n' +
 3989             '        return (\n' +
 3990             '            <div className="MarkdownEditor">\n' +
 3991             '                <h3>Input</h3>\n' +
 3992             '                <textarea\n' +
 3993             '                    onChange={this.handleChange}\n' +
 3994             '                    ref="textarea"\n' +
 3995             '                    defaultValue={this.state.value} />\n' +
 3996             '                <h3>Output</h3>\n' +
 3997             '            <div\n' +
 3998             '                className="content"\n' +
 3999             '                dangerouslySetInnerHTML=\n' +
 4000             '                />\n' +
 4001             '            </div>\n' +
 4002             '        );\n' +
 4003             '    }\n' +
 4004             '});\n' +
 4005             'React.render(<MarkdownEditor />, mountNode);',
 4006             #  -- output --
 4007             'var converter = new Showdown.converter();\n' +
 4008             'var MarkdownEditor = React.createClass({\n' +
 4009             '    getInitialState: function() {\n' +
 4010             '        return {\n' +
 4011             '            value: \'Type some *markdown* here!\'\n' +
 4012             '        };\n' +
 4013             '    },\n' +
 4014             '    handleChange: function() {\n' +
 4015             '        this.setState({\n' +
 4016             '            value: this.refs.textarea.getDOMNode().value\n' +
 4017             '        });\n' +
 4018             '    },\n' +
 4019             '    render: function() {\n' +
 4020             '        return (\n' +
 4021             '            <div className="MarkdownEditor">\n' +
 4022             '                <h3>Input</h3>\n' +
 4023             '                <textarea\n' +
 4024             '                    onChange={this.handleChange}\n' +
 4025             '                    ref="textarea"\n' +
 4026             '                    defaultValue={this.state.value} />\n' +
 4027             '                <h3>Output</h3>\n' +
 4028             '            <div\n' +
 4029             '                className="content"\n' +
 4030             '                dangerouslySetInnerHTML=\n' +
 4031             '                />\n' +
 4032             '            </div>\n' +
 4033             '        );\n' +
 4034             '    }\n' +
 4035             '});\n' +
 4036             'React.render(<MarkdownEditor />, mountNode);')
 4037         
 4038         # JSX - Not quite correct jsx formatting that still works
 4039         bt(
 4040             'var content = (\n' +
 4041             '        <Nav>\n' +
 4042             '            {/* child comment, put {} around */}\n' +
 4043             '            <Person\n' +
 4044             '                /* multi\n' +
 4045             '         line\n' +
 4046             '         comment */\n' +
 4047             '         //attr="test"\n' +
 4048             '                name={window.isLoggedIn ? window.name : \'\'} // end of line comment\n' +
 4049             '            />\n' +
 4050             '        </Nav>\n' +
 4051             '    );\n' +
 4052             'var qwer = <DropDown> A dropdown list <Menu> <MenuItem>Do Something</MenuItem> <MenuItem>Do Something Fun!</MenuItem> <MenuItem>Do Something Else</MenuItem> </Menu> </DropDown>;\n' +
 4053             'render(dropdown);',
 4054             #  -- output --
 4055             'var content = (\n' +
 4056             '    <Nav>\n' +
 4057             '            {/* child comment, put {} around */}\n' +
 4058             '            <Person\n' +
 4059             '                /* multi\n' +
 4060             '         line\n' +
 4061             '         comment */\n' +
 4062             '         //attr="test"\n' +
 4063             '                name={window.isLoggedIn ? window.name : \'\'} // end of line comment\n' +
 4064             '            />\n' +
 4065             '        </Nav>\n' +
 4066             ');\n' +
 4067             'var qwer = <DropDown> A dropdown list <Menu> <MenuItem>Do Something</MenuItem> <MenuItem>Do Something Fun!</MenuItem> <MenuItem>Do Something Else</MenuItem> </Menu> </DropDown>;\n' +
 4068             'render(dropdown);')
 4069         
 4070         # Handles messed up tags, as long as it isn't the same name
 4071         # as the root tag. Also handles tags of same name as root tag
 4072         # as long as nesting matches.
 4073         bt(
 4074             'xml=<a x="jn"><c></b></f><a><d jnj="jnn"><f></a ></nj></a>;',
 4075             #  -- output --
 4076             'xml = <a x="jn"><c></b></f><a><d jnj="jnn"><f></a ></nj></a>;')
 4077         
 4078         # If xml is not terminated, the remainder of the file is treated
 4079         # as part of the xml-literal (passed through unaltered)
 4080         test_fragment(
 4081             'xml=<a></b>\n' +
 4082             'c<b;',
 4083             #  -- output --
 4084             'xml = <a></b>\n' +
 4085             'c<b;')
 4086         
 4087         # Issue #646 = whitespace is allowed in attribute declarations
 4088         bt(
 4089             'let a = React.createClass({\n' +
 4090             '    render() {\n' +
 4091             '        return (\n' +
 4092             '            <p className=\'a\'>\n' +
 4093             '                <span>c</span>\n' +
 4094             '            </p>\n' +
 4095             '        );\n' +
 4096             '    }\n' +
 4097             '});')
 4098         bt(
 4099             'let a = React.createClass({\n' +
 4100             '    render() {\n' +
 4101             '        return (\n' +
 4102             '            <p className = \'b\'>\n' +
 4103             '                <span>c</span>\n' +
 4104             '            </p>\n' +
 4105             '        );\n' +
 4106             '    }\n' +
 4107             '});')
 4108         bt(
 4109             'let a = React.createClass({\n' +
 4110             '    render() {\n' +
 4111             '        return (\n' +
 4112             '            <p className = "c">\n' +
 4113             '                <span>c</span>\n' +
 4114             '            </p>\n' +
 4115             '        );\n' +
 4116             '    }\n' +
 4117             '});')
 4118         bt(
 4119             'let a = React.createClass({\n' +
 4120             '    render() {\n' +
 4121             '        return (\n' +
 4122             '            <{e}  className = {d}>\n' +
 4123             '                <span>c</span>\n' +
 4124             '            </{e}>\n' +
 4125             '        );\n' +
 4126             '    }\n' +
 4127             '});')
 4128         
 4129         # Issue #914 - Multiline attribute in root tag
 4130         bt(
 4131             'return (\n' +
 4132             '    <a href="#"\n' +
 4133             '        onClick={e => {\n' +
 4134             '            e.preventDefault()\n' +
 4135             '            onClick()\n' +
 4136             '       }}>\n' +
 4137             '       {children}\n' +
 4138             '    </a>\n' +
 4139             ');')
 4140         bt(
 4141             'return (\n' +
 4142             '    <{\n' +
 4143             '        a + b\n' +
 4144             '    } href="#"\n' +
 4145             '        onClick={e => {\n' +
 4146             '            e.preventDefault()\n' +
 4147             '            onClick()\n' +
 4148             '       }}>\n' +
 4149             '       {children}\n' +
 4150             '    </{\n' +
 4151             '        a + b\n' +
 4152             '    }>\n' +
 4153             ');')
 4154         bt(
 4155             'return (\n' +
 4156             '    <{\n' +
 4157             '        a + b\n' +
 4158             '    } href="#"\n' +
 4159             '        onClick={e => {\n' +
 4160             '            e.preventDefault()\n' +
 4161             '            onClick()\n' +
 4162             '       }}>\n' +
 4163             '       {children}\n' +
 4164             '    </{a + b}>\n' +
 4165             '    );',
 4166             #  -- output --
 4167             'return (\n' +
 4168             '    <{\n' +
 4169             '        a + b\n' +
 4170             '    } href="#"\n' +
 4171             '        onClick={e => {\n' +
 4172             '            e.preventDefault()\n' +
 4173             '            onClick()\n' +
 4174             '       }}>\n' +
 4175             '       {children}\n' +
 4176             '    </{a + b}>\n' +
 4177             ');')
 4178         bt(
 4179             'class Columns extends React.Component {\n' +
 4180             '    render() {\n' +
 4181             '        return (\n' +
 4182             '            <>\n' +
 4183             '              <td>Hello</td>\n' +
 4184             '              <td>World</td>\n' +
 4185             '            </>\n' +
 4186             '        );\n' +
 4187             '    }\n' +
 4188             '}')
 4189 
 4190 
 4191         #============================================================
 4192         # 
 4193         self.reset_options()
 4194 
 4195 
 4196         #============================================================
 4197         # e4x disabled
 4198         self.reset_options()
 4199         self.options.e4x = false
 4200         bt(
 4201             'xml=<a b="c"><d/><e>\n' +
 4202             ' foo</e>x</a>;',
 4203             #  -- output --
 4204             'xml = < a b = "c" > < d / > < e >\n' +
 4205             '    foo < /e>x</a > ;')
 4206 
 4207 
 4208         #============================================================
 4209         # Multiple braces
 4210         self.reset_options()
 4211         bt(
 4212             '{{}/z/}',
 4213             #  -- output --
 4214             '{\n' +
 4215             '    {}\n' +
 4216             '    /z/\n' +
 4217             '}')
 4218 
 4219 
 4220         #============================================================
 4221         # Space before conditional - (space_before_conditional = "false")
 4222         self.reset_options()
 4223         self.options.space_before_conditional = false
 4224         bt('if(a) b()')
 4225         bt('while(a) b()')
 4226         bt(
 4227             'do\n' +
 4228             '    c();\n' +
 4229             'while(a) b()')
 4230         bt('switch(a) b()')
 4231         bt(
 4232             'if(a)\n' +
 4233             'b();',
 4234             #  -- output --
 4235             'if(a)\n' +
 4236             '    b();')
 4237         bt(
 4238             'while(a)\n' +
 4239             'b();',
 4240             #  -- output --
 4241             'while(a)\n' +
 4242             '    b();')
 4243         bt(
 4244             'do\n' +
 4245             'c();\n' +
 4246             'while(a);',
 4247             #  -- output --
 4248             'do\n' +
 4249             '    c();\n' +
 4250             'while(a);')
 4251         bt(
 4252             'switch(a)\n' +
 4253             'b()',
 4254             #  -- output --
 4255             'switch(a)\n' +
 4256             '    b()')
 4257         bt('return [];')
 4258         bt('return ();')
 4259 
 4260         # Space before conditional - (space_before_conditional = "true")
 4261         self.reset_options()
 4262         self.options.space_before_conditional = true
 4263         bt('if (a) b()')
 4264         bt('while (a) b()')
 4265         bt(
 4266             'do\n' +
 4267             '    c();\n' +
 4268             'while (a) b()')
 4269         bt('switch (a) b()')
 4270         bt(
 4271             'if(a)\n' +
 4272             'b();',
 4273             #  -- output --
 4274             'if (a)\n' +
 4275             '    b();')
 4276         bt(
 4277             'while(a)\n' +
 4278             'b();',
 4279             #  -- output --
 4280             'while (a)\n' +
 4281             '    b();')
 4282         bt(
 4283             'do\n' +
 4284             'c();\n' +
 4285             'while(a);',
 4286             #  -- output --
 4287             'do\n' +
 4288             '    c();\n' +
 4289             'while (a);')
 4290         bt(
 4291             'switch(a)\n' +
 4292             'b()',
 4293             #  -- output --
 4294             'switch (a)\n' +
 4295             '    b()')
 4296         bt('return [];')
 4297         bt('return ();')
 4298 
 4299 
 4300         #============================================================
 4301         # Beautify preserve formatting
 4302         self.reset_options()
 4303         bt(
 4304             '/* beautify preserve:start */\n' +
 4305             '/* beautify preserve:end */')
 4306         bt(
 4307             '/* beautify preserve:start */\n' +
 4308             '   var a = 1;\n' +
 4309             '/* beautify preserve:end */')
 4310         bt(
 4311             'var a = 1;\n' +
 4312             '/* beautify preserve:start */\n' +
 4313             '   var a = 1;\n' +
 4314             '/* beautify preserve:end */')
 4315         bt('/* beautify preserve:start */     {asdklgh;y;;{}dd2d}/* beautify preserve:end */')
 4316         bt(
 4317             'var a =  1;\n' +
 4318             '/* beautify preserve:start */\n' +
 4319             '   var a = 1;\n' +
 4320             '/* beautify preserve:end */',
 4321             #  -- output --
 4322             'var a = 1;\n' +
 4323             '/* beautify preserve:start */\n' +
 4324             '   var a = 1;\n' +
 4325             '/* beautify preserve:end */')
 4326         bt(
 4327             'var a = 1;\n' +
 4328             ' /* beautify preserve:start */\n' +
 4329             '   var a = 1;\n' +
 4330             '/* beautify preserve:end */',
 4331             #  -- output --
 4332             'var a = 1;\n' +
 4333             '/* beautify preserve:start */\n' +
 4334             '   var a = 1;\n' +
 4335             '/* beautify preserve:end */')
 4336         bt(
 4337             'var a = {\n' +
 4338             '    /* beautify preserve:start */\n' +
 4339             '    one   :  1\n' +
 4340             '    two   :  2,\n' +
 4341             '    three :  3,\n' +
 4342             '    ten   : 10\n' +
 4343             '    /* beautify preserve:end */\n' +
 4344             '};')
 4345         bt(
 4346             'var a = {\n' +
 4347             '/* beautify preserve:start */\n' +
 4348             '    one   :  1,\n' +
 4349             '    two   :  2,\n' +
 4350             '    three :  3,\n' +
 4351             '    ten   : 10\n' +
 4352             '/* beautify preserve:end */\n' +
 4353             '};',
 4354             #  -- output --
 4355             'var a = {\n' +
 4356             '    /* beautify preserve:start */\n' +
 4357             '    one   :  1,\n' +
 4358             '    two   :  2,\n' +
 4359             '    three :  3,\n' +
 4360             '    ten   : 10\n' +
 4361             '/* beautify preserve:end */\n' +
 4362             '};')
 4363         
 4364         # one space before and after required, only single spaces inside.
 4365         bt(
 4366             'var a = {\n' +
 4367             '/*  beautify preserve:start  */\n' +
 4368             '    one   :  1,\n' +
 4369             '    two   :  2,\n' +
 4370             '    three :  3,\n' +
 4371             '    ten   : 10\n' +
 4372             '};',
 4373             #  -- output --
 4374             'var a = {\n' +
 4375             '    /*  beautify preserve:start  */\n' +
 4376             '    one: 1,\n' +
 4377             '    two: 2,\n' +
 4378             '    three: 3,\n' +
 4379             '    ten: 10\n' +
 4380             '};')
 4381         bt(
 4382             'var a = {\n' +
 4383             '/*beautify preserve:start*/\n' +
 4384             '    one   :  1,\n' +
 4385             '    two   :  2,\n' +
 4386             '    three :  3,\n' +
 4387             '    ten   : 10\n' +
 4388             '};',
 4389             #  -- output --
 4390             'var a = {\n' +
 4391             '    /*beautify preserve:start*/\n' +
 4392             '    one: 1,\n' +
 4393             '    two: 2,\n' +
 4394             '    three: 3,\n' +
 4395             '    ten: 10\n' +
 4396             '};')
 4397         bt(
 4398             'var a = {\n' +
 4399             '/*beautify  preserve:start*/\n' +
 4400             '    one   :  1,\n' +
 4401             '    two   :  2,\n' +
 4402             '    three :  3,\n' +
 4403             '    ten   : 10\n' +
 4404             '};',
 4405             #  -- output --
 4406             'var a = {\n' +
 4407             '    /*beautify  preserve:start*/\n' +
 4408             '    one: 1,\n' +
 4409             '    two: 2,\n' +
 4410             '    three: 3,\n' +
 4411             '    ten: 10\n' +
 4412             '};')
 4413         
 4414         # Directive: ignore
 4415         bt(
 4416             '/* beautify ignore:start */\n' +
 4417             '/* beautify ignore:end */')
 4418         bt(
 4419             '/* beautify ignore:start */\n' +
 4420             '   var a,,,{ 1;\n' +
 4421             '  /* beautify ignore:end */')
 4422         bt(
 4423             'var a = 1;\n' +
 4424             '/* beautify ignore:start */\n' +
 4425             '   var a = 1;\n' +
 4426             '/* beautify ignore:end */')
 4427         
 4428         # ignore starts _after_ the start comment, ends after the end comment
 4429         bt('/* beautify ignore:start */     {asdklgh;y;+++;dd2d}/* beautify ignore:end */')
 4430         bt('/* beautify ignore:start */  {asdklgh;y;+++;dd2d}    /* beautify ignore:end */')
 4431         bt(
 4432             'var a =  1;\n' +
 4433             '/* beautify ignore:start */\n' +
 4434             '   var a,,,{ 1;\n' +
 4435             '/*beautify ignore:end*/',
 4436             #  -- output --
 4437             'var a = 1;\n' +
 4438             '/* beautify ignore:start */\n' +
 4439             '   var a,,,{ 1;\n' +
 4440             '/*beautify ignore:end*/')
 4441         bt(
 4442             'var a = 1;\n' +
 4443             ' /* beautify ignore:start */\n' +
 4444             '   var a,,,{ 1;\n' +
 4445             '/* beautify ignore:end */',
 4446             #  -- output --
 4447             'var a = 1;\n' +
 4448             '/* beautify ignore:start */\n' +
 4449             '   var a,,,{ 1;\n' +
 4450             '/* beautify ignore:end */')
 4451         bt(
 4452             'var a = {\n' +
 4453             '    /* beautify ignore:start */\n' +
 4454             '    one   :  1\n' +
 4455             '    two   :  2,\n' +
 4456             '    three :  {\n' +
 4457             '    ten   : 10\n' +
 4458             '    /* beautify ignore:end */\n' +
 4459             '};')
 4460         bt(
 4461             'var a = {\n' +
 4462             '/* beautify ignore:start */\n' +
 4463             '    one   :  1\n' +
 4464             '    two   :  2,\n' +
 4465             '    three :  {\n' +
 4466             '    ten   : 10\n' +
 4467             '/* beautify ignore:end */\n' +
 4468             '};',
 4469             #  -- output --
 4470             'var a = {\n' +
 4471             '    /* beautify ignore:start */\n' +
 4472             '    one   :  1\n' +
 4473             '    two   :  2,\n' +
 4474             '    three :  {\n' +
 4475             '    ten   : 10\n' +
 4476             '/* beautify ignore:end */\n' +
 4477             '};')
 4478         
 4479         # Directives - multiple and interacting
 4480         bt(
 4481             'var a = {\n' +
 4482             '/* beautify preserve:start */\n' +
 4483             '/* beautify preserve:start */\n' +
 4484             '    one   :  1,\n' +
 4485             '  /* beautify preserve:end */\n' +
 4486             '    two   :  2,\n' +
 4487             '    three :  3,\n' +
 4488             '/* beautify preserve:start */\n' +
 4489             '    ten   : 10\n' +
 4490             '/* beautify preserve:end */\n' +
 4491             '};',
 4492             #  -- output --
 4493             'var a = {\n' +
 4494             '    /* beautify preserve:start */\n' +
 4495             '/* beautify preserve:start */\n' +
 4496             '    one   :  1,\n' +
 4497             '  /* beautify preserve:end */\n' +
 4498             '    two: 2,\n' +
 4499             '    three: 3,\n' +
 4500             '    /* beautify preserve:start */\n' +
 4501             '    ten   : 10\n' +
 4502             '/* beautify preserve:end */\n' +
 4503             '};')
 4504         bt(
 4505             'var a = {\n' +
 4506             '/* beautify ignore:start */\n' +
 4507             '    one   :  1\n' +
 4508             ' /* beautify ignore:end */\n' +
 4509             '    two   :  2,\n' +
 4510             '/* beautify ignore:start */\n' +
 4511             '    three :  {\n' +
 4512             '    ten   : 10\n' +
 4513             '/* beautify ignore:end */\n' +
 4514             '};',
 4515             #  -- output --
 4516             'var a = {\n' +
 4517             '    /* beautify ignore:start */\n' +
 4518             '    one   :  1\n' +
 4519             ' /* beautify ignore:end */\n' +
 4520             '    two: 2,\n' +
 4521             '    /* beautify ignore:start */\n' +
 4522             '    three :  {\n' +
 4523             '    ten   : 10\n' +
 4524             '/* beautify ignore:end */\n' +
 4525             '};')
 4526         
 4527         # Starts can occur together, ignore:end must occur alone.
 4528         bt(
 4529             'var a = {\n' +
 4530             '/* beautify ignore:start */\n' +
 4531             '    one   :  1\n' +
 4532             '    NOTE: ignore end block does not support starting other directives\n' +
 4533             '    This does not match the ending the ignore...\n' +
 4534             ' /* beautify ignore:end preserve:start */\n' +
 4535             '    two   :  2,\n' +
 4536             '/* beautify ignore:start */\n' +
 4537             '    three :  {\n' +
 4538             '    ten   : 10\n' +
 4539             '    ==The next comment ends the starting ignore==\n' +
 4540             '/* beautify ignore:end */\n' +
 4541             '};',
 4542             #  -- output --
 4543             'var a = {\n' +
 4544             '    /* beautify ignore:start */\n' +
 4545             '    one   :  1\n' +
 4546             '    NOTE: ignore end block does not support starting other directives\n' +
 4547             '    This does not match the ending the ignore...\n' +
 4548             ' /* beautify ignore:end preserve:start */\n' +
 4549             '    two   :  2,\n' +
 4550             '/* beautify ignore:start */\n' +
 4551             '    three :  {\n' +
 4552             '    ten   : 10\n' +
 4553             '    ==The next comment ends the starting ignore==\n' +
 4554             '/* beautify ignore:end */\n' +
 4555             '};')
 4556         bt(
 4557             'var a = {\n' +
 4558             '/* beautify ignore:start preserve:start */\n' +
 4559             '    one   :  {\n' +
 4560             ' /* beautify ignore:end */\n' +
 4561             '    two   :  2,\n' +
 4562             '  /* beautify ignore:start */\n' +
 4563             '    three :  {\n' +
 4564             '/* beautify ignore:end */\n' +
 4565             '    ten   : 10\n' +
 4566             '   // This is all preserved\n' +
 4567             '};',
 4568             #  -- output --
 4569             'var a = {\n' +
 4570             '    /* beautify ignore:start preserve:start */\n' +
 4571             '    one   :  {\n' +
 4572             ' /* beautify ignore:end */\n' +
 4573             '    two   :  2,\n' +
 4574             '  /* beautify ignore:start */\n' +
 4575             '    three :  {\n' +
 4576             '/* beautify ignore:end */\n' +
 4577             '    ten   : 10\n' +
 4578             '   // This is all preserved\n' +
 4579             '};')
 4580         bt(
 4581             'var a = {\n' +
 4582             '/* beautify ignore:start preserve:start */\n' +
 4583             '    one   :  {\n' +
 4584             ' /* beautify ignore:end */\n' +
 4585             '    two   :  2,\n' +
 4586             '  /* beautify ignore:start */\n' +
 4587             '    three :  {\n' +
 4588             '/* beautify ignore:end */\n' +
 4589             '    ten   : 10,\n' +
 4590             '/* beautify preserve:end */\n' +
 4591             '     eleven: 11\n' +
 4592             '};',
 4593             #  -- output --
 4594             'var a = {\n' +
 4595             '    /* beautify ignore:start preserve:start */\n' +
 4596             '    one   :  {\n' +
 4597             ' /* beautify ignore:end */\n' +
 4598             '    two   :  2,\n' +
 4599             '  /* beautify ignore:start */\n' +
 4600             '    three :  {\n' +
 4601             '/* beautify ignore:end */\n' +
 4602             '    ten   : 10,\n' +
 4603             '/* beautify preserve:end */\n' +
 4604             '    eleven: 11\n' +
 4605             '};')
 4606 
 4607 
 4608         #============================================================
 4609         # Comments and  tests
 4610         self.reset_options()
 4611         
 4612         # #913
 4613         bt(
 4614             'class test {\n' +
 4615             '    method1() {\n' +
 4616             '        let resp = null;\n' +
 4617             '    }\n' +
 4618             '    /**\n' +
 4619             '     * @param {String} id\n' +
 4620             '     */\n' +
 4621             '    method2(id) {\n' +
 4622             '        let resp2 = null;\n' +
 4623             '    }\n' +
 4624             '}')
 4625         
 4626         # #1090
 4627         bt(
 4628             'for (var i = 0; i < 20; ++i) // loop\n' +
 4629             '    if (i % 3) {\n' +
 4630             '        console.log(i);\n' +
 4631             '    }\n' +
 4632             'console.log("done");')
 4633         
 4634         # #1043
 4635         bt(
 4636             'var o = {\n' +
 4637             '    k: 0\n' +
 4638             '}\n' +
 4639             '// ...\n' +
 4640             'foo(o)')
 4641         
 4642         # #713 and #964
 4643         bt(
 4644             'Meteor.call("foo", bar, function(err, result) {\n' +
 4645             '    Session.set("baz", result.lorem)\n' +
 4646             '})\n' +
 4647             '//blah blah')
 4648         
 4649         # #815
 4650         bt(
 4651             'foo()\n' +
 4652             '// this is a comment\n' +
 4653             'bar()\n' +
 4654             '\n' +
 4655             'const foo = 5\n' +
 4656             '// comment\n' +
 4657             'bar()')
 4658         
 4659         # This shows current behavior.  Note #1069 is not addressed yet.
 4660         bt(
 4661             'if (modulus === 2) {\n' +
 4662             '    // i might be odd here\n' +
 4663             '    i += (i & 1);\n' +
 4664             '    // now i is guaranteed to be even\n' +
 4665             '    // this block is obviously about the statement above\n' +
 4666             '\n' +
 4667             '    // #1069 This should attach to the block below\n' +
 4668             '    // this comment is about the block after it.\n' +
 4669             '} else {\n' +
 4670             '    // rounding up using integer arithmetic only\n' +
 4671             '    if (i % modulus)\n' +
 4672             '        i += modulus - (i % modulus);\n' +
 4673             '    // now i is divisible by modulus\n' +
 4674             '    // behavior of comments should be different for single statements vs block statements/expressions\n' +
 4675             '}\n' +
 4676             '\n' +
 4677             'if (modulus === 2)\n' +
 4678             '    // i might be odd here\n' +
 4679             '    i += (i & 1);\n' +
 4680             '// now i is guaranteed to be even\n' +
 4681             '// non-braced comments unindent immediately\n' +
 4682             '\n' +
 4683             '// this comment is about the block after it.\n' +
 4684             'else\n' +
 4685             '    // rounding up using integer arithmetic only\n' +
 4686             '    if (i % modulus)\n' +
 4687             '        i += modulus - (i % modulus);\n' +
 4688             '// behavior of comments should be different for single statements vs block statements/expressions')
 4689 
 4690 
 4691         #============================================================
 4692         # minimal template handling - ()
 4693         self.reset_options()
 4694         self.options.templating = ['django', 'erb', 'handlebars', 'php']
 4695         bt('var  a = <?php$view["name"]; ?>;', 'var a = <?php$view["name"]; ?>;')
 4696         bt(
 4697             'a = abc<?php\n' +
 4698             'for($i = 1; $i <= 100; $i++;) {\n' +
 4699             '    #count to 100!\n' +
 4700             '    echo($i . "</br>");\n' +
 4701             '}\n' +
 4702             '?>;')
 4703         test_fragment(
 4704             '<?php ?>\n' +
 4705             'test.met<?php someValue ?>hod();')
 4706         bt(
 4707             '<?php "A" ?>abc<?php "D" ?>;\n' +
 4708             '<?php "B" ?>.test();\n' +
 4709             '" <?php   "C" \'D\'  ?>  "')
 4710         bt(
 4711             '<?php\n' +
 4712             'echo "A";\n' +
 4713             '?>;\n' +
 4714             'test.method();')
 4715         bt('"<?php";if(0){}"?>";')
 4716 
 4717         # minimal template handling - ()
 4718         self.reset_options()
 4719         self.options.templating = ['django', 'erb', 'handlebars', 'php']
 4720         bt('var  a = <?=$view["name"]; ?>;', 'var a = <?=$view["name"]; ?>;')
 4721         bt(
 4722             'a = abc<?=\n' +
 4723             'for($i = 1; $i <= 100; $i++;) {\n' +
 4724             '    #count to 100!\n' +
 4725             '    echo($i . "</br>");\n' +
 4726             '}\n' +
 4727             '?>;')
 4728         test_fragment(
 4729             '<?= ?>\n' +
 4730             'test.met<?= someValue ?>hod();')
 4731         bt(
 4732             '<?= "A" ?>abc<?= "D" ?>;\n' +
 4733             '<?= "B" ?>.test();\n' +
 4734             '" <?=   "C" \'D\'  ?>  "')
 4735         bt(
 4736             '<?=\n' +
 4737             'echo "A";\n' +
 4738             '?>;\n' +
 4739             'test.method();')
 4740         bt('"<?=";if(0){}"?>";')
 4741 
 4742         # minimal template handling - ()
 4743         self.reset_options()
 4744         self.options.templating = ['django', 'erb', 'handlebars', 'php']
 4745         bt('var  a = <%$view["name"]; %>;', 'var a = <%$view["name"]; %>;')
 4746         bt(
 4747             'a = abc<%\n' +
 4748             'for($i = 1; $i <= 100; $i++;) {\n' +
 4749             '    #count to 100!\n' +
 4750             '    echo($i . "</br>");\n' +
 4751             '}\n' +
 4752             '%>;')
 4753         test_fragment(
 4754             '<% %>\n' +
 4755             'test.met<% someValue %>hod();')
 4756         bt(
 4757             '<% "A" %>abc<% "D" %>;\n' +
 4758             '<% "B" %>.test();\n' +
 4759             '" <%   "C" \'D\'  %>  "')
 4760         bt(
 4761             '<%\n' +
 4762             'echo "A";\n' +
 4763             '%>;\n' +
 4764             'test.method();')
 4765         bt('"<%";if(0){}"%>";')
 4766 
 4767         # minimal template handling - ()
 4768         self.reset_options()
 4769         self.options.templating = ['django', 'erb', 'handlebars', 'php']
 4770         bt('var  a = <%=$view["name"]; %>;', 'var a = <%=$view["name"]; %>;')
 4771         bt(
 4772             'a = abc<%=\n' +
 4773             'for($i = 1; $i <= 100; $i++;) {\n' +
 4774             '    #count to 100!\n' +
 4775             '    echo($i . "</br>");\n' +
 4776             '}\n' +
 4777             '%>;')
 4778         test_fragment(
 4779             '<%= %>\n' +
 4780             'test.met<%= someValue %>hod();')
 4781         bt(
 4782             '<%= "A" %>abc<%= "D" %>;\n' +
 4783             '<%= "B" %>.test();\n' +
 4784             '" <%=   "C" \'D\'  %>  "')
 4785         bt(
 4786             '<%=\n' +
 4787             'echo "A";\n' +
 4788             '%>;\n' +
 4789             'test.method();')
 4790         bt('"<%=";if(0){}"%>";')
 4791 
 4792         # minimal template handling - ()
 4793         self.reset_options()
 4794         self.options.templating = ['django', 'erb', 'handlebars', 'php']
 4795         bt('var  a = {{$view["name"]; }};', 'var a = {{$view["name"]; }};')
 4796         bt(
 4797             'a = abc{{\n' +
 4798             'for($i = 1; $i <= 100; $i++;) {\n' +
 4799             '    #count to 100!\n' +
 4800             '    echo($i . "</br>");\n' +
 4801             '}\n' +
 4802             '}};')
 4803         test_fragment(
 4804             '{{ }}\n' +
 4805             'test.met{{ someValue }}hod();')
 4806         bt(
 4807             '{{ "A" }}abc{{ "D" }};\n' +
 4808             '{{ "B" }}.test();\n' +
 4809             '" {{   "C" \'D\'  }}  "')
 4810         bt(
 4811             '{{\n' +
 4812             'echo "A";\n' +
 4813             '}};\n' +
 4814             'test.method();')
 4815         bt('"{{";if(0){}"}}";')
 4816 
 4817         # minimal template handling - ()
 4818         self.reset_options()
 4819         self.options.templating = ['django', 'erb', 'handlebars', 'php']
 4820         bt('var  a = {#$view["name"]; #};', 'var a = {#$view["name"]; #};')
 4821         bt(
 4822             'a = abc{#\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             '{# #}\n' +
 4830             'test.met{# someValue #}hod();')
 4831         bt(
 4832             '{# "A" #}abc{# "D" #};\n' +
 4833             '{# "B" #}.test();\n' +
 4834             '" {#   "C" \'D\'  #}  "')
 4835         bt(
 4836             '{#\n' +
 4837             'echo "A";\n' +
 4838             '#};\n' +
 4839             'test.method();')
 4840         bt('"{#";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 
 5018         #============================================================
 5019         # Templating disabled - ensure formatting - ()
 5020         self.reset_options()
 5021         self.options.templating = ['auto']
 5022         bt(
 5023             '"<?php";if(0){}"?>";',
 5024             #  -- output --
 5025             '"<?php";\n' +
 5026             'if (0) {}\n' +
 5027             '"?>";')
 5028         bt(
 5029             '"<?php";if(0){}',
 5030             #  -- output --
 5031             '"<?php";\n' +
 5032             'if (0) {}')
 5033 
 5034         # Templating disabled - ensure formatting - ()
 5035         self.reset_options