mirror of
https://github.com/beautifier/js-beautify.git
synced 2024-11-30 08:00:55 +00:00
Allow wrapping of tokens inside an object literal property
When a token is not the first one in a object literal property, we should allow wrapping of those tokens. Fixes #331
This commit is contained in:
parent
7693fc8c81
commit
33082bda27
@ -542,6 +542,11 @@
|
||||
}
|
||||
}
|
||||
|
||||
function start_of_object_property() {
|
||||
return flags.mode === MODE.ObjectLiteral && flags.last_text === ':' &&
|
||||
flags.ternary_depth === 0;
|
||||
}
|
||||
|
||||
function start_of_statement() {
|
||||
if (
|
||||
(flags.last_text === 'do' ||
|
||||
@ -1059,7 +1064,7 @@
|
||||
// (c || d));
|
||||
if (token_text === '(') {
|
||||
if (last_type === 'TK_EQUALS' || last_type === 'TK_OPERATOR') {
|
||||
if (flags.mode !== MODE.ObjectLiteral) {
|
||||
if (!start_of_object_property()) {
|
||||
allow_wrap_or_preserved_newline();
|
||||
}
|
||||
}
|
||||
@ -1266,7 +1271,7 @@
|
||||
}
|
||||
|
||||
if (last_type === 'TK_COMMA' || last_type === 'TK_START_EXPR' || last_type === 'TK_EQUALS' || last_type === 'TK_OPERATOR') {
|
||||
if (flags.mode !== MODE.ObjectLiteral) {
|
||||
if (!start_of_object_property()) {
|
||||
allow_wrap_or_preserved_newline();
|
||||
}
|
||||
}
|
||||
@ -1399,7 +1404,7 @@
|
||||
} else if (last_type === 'TK_WORD') {
|
||||
output_space_before_token = true;
|
||||
} else if (last_type === 'TK_COMMA' || last_type === 'TK_START_EXPR' || last_type === 'TK_EQUALS' || last_type === 'TK_OPERATOR') {
|
||||
if (flags.mode !== MODE.ObjectLiteral) {
|
||||
if (!start_of_object_property()) {
|
||||
allow_wrap_or_preserved_newline();
|
||||
}
|
||||
} else {
|
||||
|
@ -156,8 +156,10 @@ function run_beautifier_tests(test_obj, Urlencoded, js_beautify, html_beautify)
|
||||
bt('a=0xff+4', 'a = 0xff + 4');
|
||||
bt('a = [1, 2, 3, 4]');
|
||||
bt('F*(g/=f)*g+b', 'F * (g /= f) * g + b');
|
||||
bt('a.b({c:d})', "a.b({\n c: d\n})");
|
||||
bt('a.b\n(\n{\nc:\nd\n}\n)', "a.b({\n c: d\n})");
|
||||
bt('a.b({c:d})', 'a.b({\n c: d\n})');
|
||||
bt('a.b\n(\n{\nc:\nd\n}\n)', 'a.b({\n c: d\n})');
|
||||
bt('a.b({c:"d"})', 'a.b({\n c: "d"\n})');
|
||||
bt('a.b\n(\n{\nc:\n"d"\n}\n)', 'a.b({\n c: "d"\n})');
|
||||
bt('a=!b', 'a = !b');
|
||||
bt('a?b:c', 'a ? b : c');
|
||||
bt('a?1:2', 'a ? 1 : 2');
|
||||
@ -928,36 +930,62 @@ function run_beautifier_tests(test_obj, Urlencoded, js_beautify, html_beautify)
|
||||
//.............1234567890123456789012345678901234567890123456789012345678901234567890
|
||||
test_fragment('foo.bar().baz().cucumber((fat && "sassy") || (leans\n&& mean));\n' +
|
||||
'Test_very_long_variable_name_this_should_never_wrap\n.but_this_can\n' +
|
||||
'if (wraps_can_occur && inside_an_if_block) that_is_\n.okay();',
|
||||
'if (wraps_can_occur && inside_an_if_block) that_is_\n.okay();\n' +
|
||||
'object_literal = {\n' +
|
||||
' property: first_token_should_never_wrap + but_this_can,\n' +
|
||||
' proper: "first_token_should_never_wrap" + "but_this_can"\n' +
|
||||
'}',
|
||||
/* expected */
|
||||
'foo.bar().baz().cucumber((fat && "sassy") || (leans && mean));\n' +
|
||||
'Test_very_long_variable_name_this_should_never_wrap.but_this_can\n' +
|
||||
'if (wraps_can_occur && inside_an_if_block) that_is_.okay();');
|
||||
'if (wraps_can_occur && inside_an_if_block) that_is_.okay();\n' +
|
||||
'object_literal = {\n' +
|
||||
' property: first_token_should_never_wrap + but_this_can,\n' +
|
||||
' proper: "first_token_should_never_wrap" + "but_this_can"\n' +
|
||||
'}');
|
||||
|
||||
opts.wrap_line_length = 70;
|
||||
//.............---------1---------2---------3---------4---------5---------6---------7
|
||||
//.............1234567890123456789012345678901234567890123456789012345678901234567890
|
||||
test_fragment('foo.bar().baz().cucumber((fat && "sassy") || (leans\n&& mean));\n' +
|
||||
'Test_very_long_variable_name_this_should_never_wrap\n.but_this_can\n' +
|
||||
'if (wraps_can_occur && inside_an_if_block) that_is_\n.okay();',
|
||||
'if (wraps_can_occur && inside_an_if_block) that_is_\n.okay();\n' +
|
||||
'object_literal = {\n' +
|
||||
' property: first_token_should_never_wrap + but_this_can,\n' +
|
||||
' proper: "first_token_should_never_wrap" + "but_this_can"\n' +
|
||||
'}',
|
||||
/* expected */
|
||||
'foo.bar().baz().cucumber((fat && "sassy") || (leans && mean));\n' +
|
||||
'Test_very_long_variable_name_this_should_never_wrap.but_this_can\n' +
|
||||
'if (wraps_can_occur && inside_an_if_block) that_is_.okay();');
|
||||
'if (wraps_can_occur && inside_an_if_block) that_is_.okay();\n' +
|
||||
'object_literal = {\n' +
|
||||
' property: first_token_should_never_wrap + but_this_can,\n' +
|
||||
' proper: "first_token_should_never_wrap" + "but_this_can"\n' +
|
||||
'}');
|
||||
|
||||
opts.wrap_line_length = 40;
|
||||
//.............---------1---------2---------3---------4---------5---------6---------7
|
||||
//.............1234567890123456789012345678901234567890123456789012345678901234567890
|
||||
test_fragment('foo.bar().baz().cucumber((fat && "sassy") || (leans\n&& mean));\n' +
|
||||
'Test_very_long_variable_name_this_should_never_wrap\n.but_this_can\n' +
|
||||
'if (wraps_can_occur && inside_an_if_block) that_is_\n.okay();',
|
||||
'if (wraps_can_occur && inside_an_if_block) that_is_\n.okay();\n' +
|
||||
'object_literal = {\n' +
|
||||
' property: first_token_should_never_wrap + but_this_can,\n' +
|
||||
' proper: "first_token_should_never_wrap" + "but_this_can"\n' +
|
||||
'}',
|
||||
/* expected */
|
||||
'foo.bar().baz().cucumber((fat &&\n' +
|
||||
' "sassy") || (leans && mean));\n' +
|
||||
'Test_very_long_variable_name_this_should_never_wrap\n' +
|
||||
' .but_this_can\n' +
|
||||
'if (wraps_can_occur &&\n' +
|
||||
' inside_an_if_block) that_is_.okay();');
|
||||
' inside_an_if_block) that_is_.okay();\n' +
|
||||
'object_literal = {\n' +
|
||||
' property: first_token_should_never_wrap +\n' +
|
||||
' but_this_can,\n' +
|
||||
' proper: "first_token_should_never_wrap" +\n' +
|
||||
' "but_this_can"\n' +
|
||||
'}');
|
||||
|
||||
opts.wrap_line_length = 41;
|
||||
// NOTE: wrap is only best effort - line continues until next wrap point is found.
|
||||
@ -965,14 +993,24 @@ function run_beautifier_tests(test_obj, Urlencoded, js_beautify, html_beautify)
|
||||
//.............1234567890123456789012345678901234567890123456789012345678901234567890
|
||||
test_fragment('foo.bar().baz().cucumber((fat && "sassy") || (leans\n&& mean));\n' +
|
||||
'Test_very_long_variable_name_this_should_never_wrap\n.but_this_can\n' +
|
||||
'if (wraps_can_occur && inside_an_if_block) that_is_\n.okay();',
|
||||
'if (wraps_can_occur && inside_an_if_block) that_is_\n.okay();\n' +
|
||||
'object_literal = {\n' +
|
||||
' property: first_token_should_never_wrap + but_this_can,\n' +
|
||||
' proper: "first_token_should_never_wrap" + "but_this_can"\n' +
|
||||
'}',
|
||||
/* expected */
|
||||
'foo.bar().baz().cucumber((fat && "sassy") ||\n' +
|
||||
' (leans && mean));\n' +
|
||||
'Test_very_long_variable_name_this_should_never_wrap\n' +
|
||||
' .but_this_can\n' +
|
||||
'if (wraps_can_occur &&\n' +
|
||||
' inside_an_if_block) that_is_.okay();');
|
||||
' inside_an_if_block) that_is_.okay();\n' +
|
||||
'object_literal = {\n' +
|
||||
' property: first_token_should_never_wrap +\n' +
|
||||
' but_this_can,\n' +
|
||||
' proper: "first_token_should_never_wrap" +\n' +
|
||||
' "but_this_can"\n' +
|
||||
'}');
|
||||
|
||||
opts.wrap_line_length = 45;
|
||||
// NOTE: wrap is only best effort - line continues until next wrap point is found.
|
||||
@ -982,6 +1020,10 @@ function run_beautifier_tests(test_obj, Urlencoded, js_beautify, html_beautify)
|
||||
' foo.bar().baz().cucumber((fat && "sassy") || (leans\n&& mean));\n' +
|
||||
' Test_very_long_variable_name_this_should_never_wrap\n.but_this_can\n' +
|
||||
' if (wraps_can_occur && inside_an_if_block) that_is_\n.okay();\n' +
|
||||
' object_literal = {\n' +
|
||||
' property: first_token_should_never_wrap + but_this_can,\n' +
|
||||
' proper: "first_token_should_never_wrap" + "but_this_can"\n' +
|
||||
' }' +
|
||||
'}',
|
||||
/* expected */
|
||||
'{\n' +
|
||||
@ -991,6 +1033,12 @@ function run_beautifier_tests(test_obj, Urlencoded, js_beautify, html_beautify)
|
||||
' .but_this_can\n' +
|
||||
' if (wraps_can_occur &&\n' +
|
||||
' inside_an_if_block) that_is_.okay();\n' +
|
||||
' object_literal = {\n' +
|
||||
' property: first_token_should_never_wrap +\n' +
|
||||
' but_this_can,\n' +
|
||||
' proper: "first_token_should_never_wrap" +\n' +
|
||||
' "but_this_can"\n' +
|
||||
' }\n'+
|
||||
'}');
|
||||
|
||||
opts.preserve_newlines = true;
|
||||
@ -999,26 +1047,42 @@ function run_beautifier_tests(test_obj, Urlencoded, js_beautify, html_beautify)
|
||||
//.............1234567890123456789012345678901234567890123456789012345678901234567890
|
||||
test_fragment('foo.bar().baz().cucumber((fat && "sassy") || (leans\n&& mean));\n' +
|
||||
'Test_very_long_variable_name_this_should_never_wrap\n.but_this_can\n' +
|
||||
'if (wraps_can_occur && inside_an_if_block) that_is_\n.okay();',
|
||||
'if (wraps_can_occur && inside_an_if_block) that_is_\n.okay();\n' +
|
||||
'object_literal = {\n' +
|
||||
' property: first_token_should_never_wrap + but_this_can,\n' +
|
||||
' proper: "first_token_should_never_wrap" + "but_this_can"\n' +
|
||||
'}',
|
||||
/* expected */
|
||||
'foo.bar().baz().cucumber((fat && "sassy") || (leans && mean));\n' +
|
||||
'Test_very_long_variable_name_this_should_never_wrap\n' +
|
||||
' .but_this_can\n' +
|
||||
'if (wraps_can_occur && inside_an_if_block) that_is_\n' +
|
||||
' .okay();');
|
||||
' .okay();\n' +
|
||||
'object_literal = {\n' +
|
||||
' property: first_token_should_never_wrap + but_this_can,\n' +
|
||||
' proper: "first_token_should_never_wrap" + "but_this_can"\n' +
|
||||
'}');
|
||||
|
||||
opts.wrap_line_length = 70;
|
||||
//.............---------1---------2---------3---------4---------5---------6---------7
|
||||
//.............1234567890123456789012345678901234567890123456789012345678901234567890
|
||||
test_fragment('foo.bar().baz().cucumber((fat && "sassy") || (leans\n&& mean));\n' +
|
||||
'Test_very_long_variable_name_this_should_never_wrap\n.but_this_can\n' +
|
||||
'if (wraps_can_occur && inside_an_if_block) that_is_\n.okay();',
|
||||
'if (wraps_can_occur && inside_an_if_block) that_is_\n.okay();\n' +
|
||||
'object_literal = {\n' +
|
||||
' property: first_token_should_never_wrap + but_this_can,\n' +
|
||||
' proper: "first_token_should_never_wrap" + "but_this_can"\n' +
|
||||
'}',
|
||||
/* expected */
|
||||
'foo.bar().baz().cucumber((fat && "sassy") || (leans && mean));\n' +
|
||||
'Test_very_long_variable_name_this_should_never_wrap\n' +
|
||||
' .but_this_can\n' +
|
||||
'if (wraps_can_occur && inside_an_if_block) that_is_\n' +
|
||||
' .okay();');
|
||||
' .okay();\n' +
|
||||
'object_literal = {\n' +
|
||||
' property: first_token_should_never_wrap + but_this_can,\n' +
|
||||
' proper: "first_token_should_never_wrap" + "but_this_can"\n' +
|
||||
'}');
|
||||
|
||||
|
||||
opts.wrap_line_length = 40;
|
||||
@ -1026,7 +1090,11 @@ function run_beautifier_tests(test_obj, Urlencoded, js_beautify, html_beautify)
|
||||
//.............1234567890123456789012345678901234567890123456789012345678901234567890
|
||||
test_fragment('foo.bar().baz().cucumber((fat && "sassy") || (leans\n&& mean));\n' +
|
||||
'Test_very_long_variable_name_this_should_never_wrap\n.but_this_can\n' +
|
||||
'if (wraps_can_occur && inside_an_if_block) that_is_\n.okay();',
|
||||
'if (wraps_can_occur && inside_an_if_block) that_is_\n.okay();\n' +
|
||||
'object_literal = {\n' +
|
||||
' property: first_token_should_never_wrap + but_this_can,\n' +
|
||||
' proper: "first_token_should_never_wrap" + "but_this_can"\n' +
|
||||
'}',
|
||||
/* expected */
|
||||
'foo.bar().baz().cucumber((fat &&\n' +
|
||||
' "sassy") || (leans && mean));\n' +
|
||||
@ -1034,7 +1102,13 @@ function run_beautifier_tests(test_obj, Urlencoded, js_beautify, html_beautify)
|
||||
' .but_this_can\n' +
|
||||
'if (wraps_can_occur &&\n' +
|
||||
' inside_an_if_block) that_is_\n' +
|
||||
' .okay();');
|
||||
' .okay();\n' +
|
||||
'object_literal = {\n' +
|
||||
' property: first_token_should_never_wrap +\n' +
|
||||
' but_this_can,\n' +
|
||||
' proper: "first_token_should_never_wrap" +\n' +
|
||||
' "but_this_can"\n' +
|
||||
'}');
|
||||
|
||||
opts.wrap_line_length = 41;
|
||||
// NOTE: wrap is only best effort - line continues until next wrap point is found.
|
||||
@ -1042,7 +1116,11 @@ function run_beautifier_tests(test_obj, Urlencoded, js_beautify, html_beautify)
|
||||
//.............1234567890123456789012345678901234567890123456789012345678901234567890
|
||||
test_fragment('foo.bar().baz().cucumber((fat && "sassy") || (leans\n&& mean));\n' +
|
||||
'Test_very_long_variable_name_this_should_never_wrap\n.but_this_can\n' +
|
||||
'if (wraps_can_occur && inside_an_if_block) that_is_\n.okay();',
|
||||
'if (wraps_can_occur && inside_an_if_block) that_is_\n.okay();\n' +
|
||||
'object_literal = {\n' +
|
||||
' property: first_token_should_never_wrap + but_this_can,\n' +
|
||||
' proper: "first_token_should_never_wrap" + "but_this_can"\n' +
|
||||
'}',
|
||||
/* expected */
|
||||
'foo.bar().baz().cucumber((fat && "sassy") ||\n' +
|
||||
' (leans && mean));\n' +
|
||||
@ -1050,7 +1128,13 @@ function run_beautifier_tests(test_obj, Urlencoded, js_beautify, html_beautify)
|
||||
' .but_this_can\n' +
|
||||
'if (wraps_can_occur &&\n' +
|
||||
' inside_an_if_block) that_is_\n' +
|
||||
' .okay();');
|
||||
' .okay();\n' +
|
||||
'object_literal = {\n' +
|
||||
' property: first_token_should_never_wrap +\n' +
|
||||
' but_this_can,\n' +
|
||||
' proper: "first_token_should_never_wrap" +\n' +
|
||||
' "but_this_can"\n' +
|
||||
'}');
|
||||
|
||||
opts.wrap_line_length = 45;
|
||||
// NOTE: wrap is only best effort - line continues until next wrap point is found.
|
||||
@ -1060,6 +1144,10 @@ function run_beautifier_tests(test_obj, Urlencoded, js_beautify, html_beautify)
|
||||
' foo.bar().baz().cucumber((fat && "sassy") || (leans\n&& mean));\n' +
|
||||
' Test_very_long_variable_name_this_should_never_wrap\n.but_this_can\n' +
|
||||
' if (wraps_can_occur && inside_an_if_block) that_is_\n.okay();\n' +
|
||||
' object_literal = {\n' +
|
||||
' property: first_token_should_never_wrap + but_this_can,\n' +
|
||||
' proper: "first_token_should_never_wrap" + "but_this_can"\n' +
|
||||
' }' +
|
||||
'}',
|
||||
/* expected */
|
||||
'{\n' +
|
||||
@ -1070,6 +1158,12 @@ function run_beautifier_tests(test_obj, Urlencoded, js_beautify, html_beautify)
|
||||
' if (wraps_can_occur &&\n' +
|
||||
' inside_an_if_block) that_is_\n' +
|
||||
' .okay();\n' +
|
||||
' object_literal = {\n' +
|
||||
' property: first_token_should_never_wrap +\n' +
|
||||
' but_this_can,\n' +
|
||||
' proper: "first_token_should_never_wrap" +\n' +
|
||||
' "but_this_can"\n' +
|
||||
' }\n'+
|
||||
'}');
|
||||
|
||||
opts.wrap_line_length = 0;
|
||||
|
@ -532,6 +532,10 @@ class Beautifier:
|
||||
self.previous_flags = self.flags
|
||||
self.flags = self.flag_store.pop()
|
||||
|
||||
def start_of_object_property(self):
|
||||
return self.flags.mode == MODE.ObjectLiteral and self.flags.last_text == ':' and \
|
||||
self.flags.ternary_depth == 0
|
||||
|
||||
def start_of_statement(self):
|
||||
if (self.flags.last_text == 'do' \
|
||||
or (self.flags.last_text == 'else' and self.token_text != 'if' ) \
|
||||
@ -906,7 +910,7 @@ class Beautifier:
|
||||
# a = (b &&
|
||||
# (c || d));
|
||||
if self.last_type in ['TK_EQUALS', 'TK_OPERATOR']:
|
||||
if self.flags.mode != MODE.ObjectLiteral:
|
||||
if not self.start_of_object_property():
|
||||
self.allow_wrap_or_preserved_newline(token_text)
|
||||
|
||||
self.set_mode(next_mode)
|
||||
@ -1082,7 +1086,7 @@ class Beautifier:
|
||||
self.append_newline()
|
||||
|
||||
if self.last_type in ['TK_COMMA', 'TK_START_EXPR', 'TK_EQUALS', 'TK_OPERATOR']:
|
||||
if self.flags.mode != MODE.ObjectLiteral:
|
||||
if not self.start_of_object_property():
|
||||
self.allow_wrap_or_preserved_newline(token_text)
|
||||
|
||||
if token_text == 'function':
|
||||
@ -1201,7 +1205,7 @@ class Beautifier:
|
||||
elif self.last_type == 'TK_WORD':
|
||||
self.output_space_before_token = True
|
||||
elif self.last_type in ['TK_COMMA', 'TK_START_EXPR', 'TK_EQUALS', 'TK_OPERATOR']:
|
||||
if self.flags.mode != MODE.ObjectLiteral:
|
||||
if not self.start_of_object_property():
|
||||
self.allow_wrap_or_preserved_newline(token_text)
|
||||
else:
|
||||
self.append_newline()
|
||||
|
@ -67,8 +67,10 @@ class TestJSBeautifier(unittest.TestCase):
|
||||
bt('a=0xff+4', 'a = 0xff + 4');
|
||||
bt('a = [1, 2, 3, 4]');
|
||||
bt('F*(g/=f)*g+b', 'F * (g /= f) * g + b');
|
||||
bt('a.b({c:d})', "a.b({\n c: d\n})");
|
||||
bt('a.b\n(\n{\nc:\nd\n}\n)', "a.b({\n c: d\n})");
|
||||
bt('a.b({c:d})', 'a.b({\n c: d\n})');
|
||||
bt('a.b\n(\n{\nc:\nd\n}\n)', 'a.b({\n c: d\n})');
|
||||
bt('a.b({c:"d"})', 'a.b({\n c: "d"\n})');
|
||||
bt('a.b\n(\n{\nc:\n"d"\n}\n)', 'a.b({\n c: "d"\n})');
|
||||
bt('a=!b', 'a = !b');
|
||||
bt('a?b:c', 'a ? b : c');
|
||||
bt('a?1:2', 'a ? 1 : 2');
|
||||
@ -811,36 +813,62 @@ class TestJSBeautifier(unittest.TestCase):
|
||||
#..............1234567890123456789012345678901234567890123456789012345678901234567890
|
||||
test_fragment('foo.bar().baz().cucumber((fat && "sassy") || (leans\n&& mean));\n' +
|
||||
'Test_very_long_variable_name_this_should_never_wrap\n.but_this_can\n' +
|
||||
'if (wraps_can_occur && inside_an_if_block) that_is_\n.okay();',
|
||||
'if (wraps_can_occur && inside_an_if_block) that_is_\n.okay();\n' +
|
||||
'object_literal = {\n' +
|
||||
' property: first_token_should_never_wrap + but_this_can,\n' +
|
||||
' proper: "first_token_should_never_wrap" + "but_this_can"\n' +
|
||||
'}',
|
||||
# expected #
|
||||
'foo.bar().baz().cucumber((fat && "sassy") || (leans && mean));\n' +
|
||||
'Test_very_long_variable_name_this_should_never_wrap.but_this_can\n' +
|
||||
'if (wraps_can_occur && inside_an_if_block) that_is_.okay();')
|
||||
'if (wraps_can_occur && inside_an_if_block) that_is_.okay();\n' +
|
||||
'object_literal = {\n' +
|
||||
' property: first_token_should_never_wrap + but_this_can,\n' +
|
||||
' proper: "first_token_should_never_wrap" + "but_this_can"\n' +
|
||||
'}');
|
||||
|
||||
self.options.wrap_line_length = 70
|
||||
#..............---------1---------2---------3---------4---------5---------6---------7
|
||||
#..............1234567890123456789012345678901234567890123456789012345678901234567890
|
||||
test_fragment('foo.bar().baz().cucumber((fat && "sassy") || (leans\n&& mean));\n' +
|
||||
'Test_very_long_variable_name_this_should_never_wrap\n.but_this_can\n' +
|
||||
'if (wraps_can_occur && inside_an_if_block) that_is_\n.okay();',
|
||||
'if (wraps_can_occur && inside_an_if_block) that_is_\n.okay();\n' +
|
||||
'object_literal = {\n' +
|
||||
' property: first_token_should_never_wrap + but_this_can,\n' +
|
||||
' proper: "first_token_should_never_wrap" + "but_this_can"\n' +
|
||||
'}',
|
||||
# expected #
|
||||
'foo.bar().baz().cucumber((fat && "sassy") || (leans && mean));\n' +
|
||||
'Test_very_long_variable_name_this_should_never_wrap.but_this_can\n' +
|
||||
'if (wraps_can_occur && inside_an_if_block) that_is_.okay();');
|
||||
'if (wraps_can_occur && inside_an_if_block) that_is_.okay();\n' +
|
||||
'object_literal = {\n' +
|
||||
' property: first_token_should_never_wrap + but_this_can,\n' +
|
||||
' proper: "first_token_should_never_wrap" + "but_this_can"\n' +
|
||||
'}');
|
||||
|
||||
self.options.wrap_line_length = 40
|
||||
#..............---------1---------2---------3---------4---------5---------6---------7
|
||||
#..............1234567890123456789012345678901234567890123456789012345678901234567890
|
||||
test_fragment('foo.bar().baz().cucumber((fat && "sassy") || (leans\n&& mean));\n' +
|
||||
'Test_very_long_variable_name_this_should_never_wrap\n.but_this_can\n' +
|
||||
'if (wraps_can_occur && inside_an_if_block) that_is_\n.okay();',
|
||||
'if (wraps_can_occur && inside_an_if_block) that_is_\n.okay();\n' +
|
||||
'object_literal = {\n' +
|
||||
' property: first_token_should_never_wrap + but_this_can,\n' +
|
||||
' proper: "first_token_should_never_wrap" + "but_this_can"\n' +
|
||||
'}',
|
||||
# expected #
|
||||
'foo.bar().baz().cucumber((fat &&\n' +
|
||||
' "sassy") || (leans && mean));\n' +
|
||||
'Test_very_long_variable_name_this_should_never_wrap\n' +
|
||||
' .but_this_can\n' +
|
||||
'if (wraps_can_occur &&\n' +
|
||||
' inside_an_if_block) that_is_.okay();');
|
||||
' inside_an_if_block) that_is_.okay();\n' +
|
||||
'object_literal = {\n' +
|
||||
' property: first_token_should_never_wrap +\n' +
|
||||
' but_this_can,\n' +
|
||||
' proper: "first_token_should_never_wrap" +\n' +
|
||||
' "but_this_can"\n' +
|
||||
'}');
|
||||
|
||||
self.options.wrap_line_length = 41
|
||||
# NOTE: wrap is only best effort - line continues until next wrap point is found.
|
||||
@ -848,14 +876,25 @@ class TestJSBeautifier(unittest.TestCase):
|
||||
#..............1234567890123456789012345678901234567890123456789012345678901234567890
|
||||
test_fragment('foo.bar().baz().cucumber((fat && "sassy") || (leans\n&& mean));\n' +
|
||||
'Test_very_long_variable_name_this_should_never_wrap\n.but_this_can\n' +
|
||||
'if (wraps_can_occur && inside_an_if_block) that_is_\n.okay();',
|
||||
'if (wraps_can_occur && inside_an_if_block) that_is_\n.okay();\n' +
|
||||
'object_literal = {\n' +
|
||||
' property: first_token_should_never_wrap + but_this_can,\n' +
|
||||
' proper: "first_token_should_never_wrap" + "but_this_can"\n' +
|
||||
'}',
|
||||
# expected #
|
||||
'foo.bar().baz().cucumber((fat && "sassy") ||\n' +
|
||||
' (leans && mean));\n' +
|
||||
'Test_very_long_variable_name_this_should_never_wrap\n' +
|
||||
' .but_this_can\n' +
|
||||
'if (wraps_can_occur &&\n' +
|
||||
' inside_an_if_block) that_is_.okay();');
|
||||
' inside_an_if_block) that_is_.okay();\n' +
|
||||
'object_literal = {\n' +
|
||||
' property: first_token_should_never_wrap +\n' +
|
||||
' but_this_can,\n' +
|
||||
' proper: "first_token_should_never_wrap" +\n' +
|
||||
' "but_this_can"\n' +
|
||||
'}');
|
||||
|
||||
|
||||
self.options.wrap_line_length = 45
|
||||
# NOTE: wrap is only best effort - line continues until next wrap point is found.
|
||||
@ -865,6 +904,10 @@ class TestJSBeautifier(unittest.TestCase):
|
||||
' foo.bar().baz().cucumber((fat && "sassy") || (leans\n&& mean));\n' +
|
||||
' Test_very_long_variable_name_this_should_never_wrap\n.but_this_can\n' +
|
||||
' if (wraps_can_occur && inside_an_if_block) that_is_\n.okay();\n' +
|
||||
' object_literal = {\n' +
|
||||
' property: first_token_should_never_wrap + but_this_can,\n' +
|
||||
' proper: "first_token_should_never_wrap" + "but_this_can"\n' +
|
||||
' }' +
|
||||
'}',
|
||||
# expected #
|
||||
'{\n' +
|
||||
@ -874,6 +917,12 @@ class TestJSBeautifier(unittest.TestCase):
|
||||
' .but_this_can\n' +
|
||||
' if (wraps_can_occur &&\n' +
|
||||
' inside_an_if_block) that_is_.okay();\n' +
|
||||
' object_literal = {\n' +
|
||||
' property: first_token_should_never_wrap +\n' +
|
||||
' but_this_can,\n' +
|
||||
' proper: "first_token_should_never_wrap" +\n' +
|
||||
' "but_this_can"\n' +
|
||||
' }\n'+
|
||||
'}');
|
||||
|
||||
self.options.preserve_newlines = True
|
||||
@ -882,26 +931,43 @@ class TestJSBeautifier(unittest.TestCase):
|
||||
#..............1234567890123456789012345678901234567890123456789012345678901234567890
|
||||
test_fragment('foo.bar().baz().cucumber((fat && "sassy") || (leans\n&& mean));\n' +
|
||||
'Test_very_long_variable_name_this_should_never_wrap\n.but_this_can\n' +
|
||||
'if (wraps_can_occur && inside_an_if_block) that_is_\n.okay();',
|
||||
'if (wraps_can_occur && inside_an_if_block) that_is_\n.okay();\n' +
|
||||
'object_literal = {\n' +
|
||||
' property: first_token_should_never_wrap + but_this_can,\n' +
|
||||
' proper: "first_token_should_never_wrap" + "but_this_can"\n' +
|
||||
'}',
|
||||
# expected #
|
||||
'foo.bar().baz().cucumber((fat && "sassy") || (leans && mean));\n' +
|
||||
'Test_very_long_variable_name_this_should_never_wrap\n' +
|
||||
' .but_this_can\n' +
|
||||
'if (wraps_can_occur && inside_an_if_block) that_is_\n' +
|
||||
' .okay();');
|
||||
' .okay();\n' +
|
||||
'object_literal = {\n' +
|
||||
' property: first_token_should_never_wrap + but_this_can,\n' +
|
||||
' proper: "first_token_should_never_wrap" + "but_this_can"\n' +
|
||||
'}');
|
||||
|
||||
|
||||
self.options.wrap_line_length = 70
|
||||
#..............---------1---------2---------3---------4---------5---------6---------7
|
||||
#..............1234567890123456789012345678901234567890123456789012345678901234567890
|
||||
test_fragment('foo.bar().baz().cucumber((fat && "sassy") || (leans\n&& mean));\n' +
|
||||
'Test_very_long_variable_name_this_should_never_wrap\n.but_this_can\n' +
|
||||
'if (wraps_can_occur && inside_an_if_block) that_is_\n.okay();',
|
||||
'if (wraps_can_occur && inside_an_if_block) that_is_\n.okay();\n' +
|
||||
'object_literal = {\n' +
|
||||
' property: first_token_should_never_wrap + but_this_can,\n' +
|
||||
' proper: "first_token_should_never_wrap" + "but_this_can"\n' +
|
||||
'}',
|
||||
# expected #
|
||||
'foo.bar().baz().cucumber((fat && "sassy") || (leans && mean));\n' +
|
||||
'Test_very_long_variable_name_this_should_never_wrap\n' +
|
||||
' .but_this_can\n' +
|
||||
'if (wraps_can_occur && inside_an_if_block) that_is_\n' +
|
||||
' .okay();');
|
||||
' .okay();\n' +
|
||||
'object_literal = {\n' +
|
||||
' property: first_token_should_never_wrap + but_this_can,\n' +
|
||||
' proper: "first_token_should_never_wrap" + "but_this_can"\n' +
|
||||
'}');
|
||||
|
||||
|
||||
self.options.wrap_line_length = 40
|
||||
@ -909,7 +975,11 @@ class TestJSBeautifier(unittest.TestCase):
|
||||
#..............1234567890123456789012345678901234567890123456789012345678901234567890
|
||||
test_fragment('foo.bar().baz().cucumber((fat && "sassy") || (leans\n&& mean));\n' +
|
||||
'Test_very_long_variable_name_this_should_never_wrap\n.but_this_can\n' +
|
||||
'if (wraps_can_occur && inside_an_if_block) that_is_\n.okay();',
|
||||
'if (wraps_can_occur && inside_an_if_block) that_is_\n.okay();\n' +
|
||||
'object_literal = {\n' +
|
||||
' property: first_token_should_never_wrap + but_this_can,\n' +
|
||||
' proper: "first_token_should_never_wrap" + "but_this_can"\n' +
|
||||
'}',
|
||||
# expected #
|
||||
'foo.bar().baz().cucumber((fat &&\n' +
|
||||
' "sassy") || (leans && mean));\n' +
|
||||
@ -917,7 +987,13 @@ class TestJSBeautifier(unittest.TestCase):
|
||||
' .but_this_can\n' +
|
||||
'if (wraps_can_occur &&\n' +
|
||||
' inside_an_if_block) that_is_\n' +
|
||||
' .okay();');
|
||||
' .okay();\n' +
|
||||
'object_literal = {\n' +
|
||||
' property: first_token_should_never_wrap +\n' +
|
||||
' but_this_can,\n' +
|
||||
' proper: "first_token_should_never_wrap" +\n' +
|
||||
' "but_this_can"\n' +
|
||||
'}');
|
||||
|
||||
self.options.wrap_line_length = 41
|
||||
# NOTE: wrap is only best effort - line continues until next wrap point is found.
|
||||
@ -925,7 +1001,11 @@ class TestJSBeautifier(unittest.TestCase):
|
||||
#..............1234567890123456789012345678901234567890123456789012345678901234567890
|
||||
test_fragment('foo.bar().baz().cucumber((fat && "sassy") || (leans\n&& mean));\n' +
|
||||
'Test_very_long_variable_name_this_should_never_wrap\n.but_this_can\n' +
|
||||
'if (wraps_can_occur && inside_an_if_block) that_is_\n.okay();',
|
||||
'if (wraps_can_occur && inside_an_if_block) that_is_\n.okay();\n' +
|
||||
'object_literal = {\n' +
|
||||
' property: first_token_should_never_wrap + but_this_can,\n' +
|
||||
' proper: "first_token_should_never_wrap" + "but_this_can"\n' +
|
||||
'}',
|
||||
# expected #
|
||||
'foo.bar().baz().cucumber((fat && "sassy") ||\n' +
|
||||
' (leans && mean));\n' +
|
||||
@ -933,7 +1013,13 @@ class TestJSBeautifier(unittest.TestCase):
|
||||
' .but_this_can\n' +
|
||||
'if (wraps_can_occur &&\n' +
|
||||
' inside_an_if_block) that_is_\n' +
|
||||
' .okay();');
|
||||
' .okay();\n' +
|
||||
'object_literal = {\n' +
|
||||
' property: first_token_should_never_wrap +\n' +
|
||||
' but_this_can,\n' +
|
||||
' proper: "first_token_should_never_wrap" +\n' +
|
||||
' "but_this_can"\n' +
|
||||
'}');
|
||||
|
||||
self.options.wrap_line_length = 45
|
||||
# NOTE: wrap is only best effort - line continues until next wrap point is found.
|
||||
@ -943,6 +1029,10 @@ class TestJSBeautifier(unittest.TestCase):
|
||||
' foo.bar().baz().cucumber((fat && "sassy") || (leans\n&& mean));\n' +
|
||||
' Test_very_long_variable_name_this_should_never_wrap\n.but_this_can\n' +
|
||||
' if (wraps_can_occur && inside_an_if_block) that_is_\n.okay();\n' +
|
||||
' object_literal = {\n' +
|
||||
' property: first_token_should_never_wrap + but_this_can,\n' +
|
||||
' proper: "first_token_should_never_wrap" + "but_this_can"\n' +
|
||||
' }' +
|
||||
'}',
|
||||
# expected #
|
||||
'{\n' +
|
||||
@ -953,6 +1043,12 @@ class TestJSBeautifier(unittest.TestCase):
|
||||
' if (wraps_can_occur &&\n' +
|
||||
' inside_an_if_block) that_is_\n' +
|
||||
' .okay();\n' +
|
||||
' object_literal = {\n' +
|
||||
' property: first_token_should_never_wrap +\n' +
|
||||
' but_this_can,\n' +
|
||||
' proper: "first_token_should_never_wrap" +\n' +
|
||||
' "but_this_can"\n' +
|
||||
' }\n'+
|
||||
'}');
|
||||
|
||||
self.options.wrap_line_length = 0
|
||||
|
Loading…
Reference in New Issue
Block a user