mirror of
https://github.com/beautifier/js-beautify.git
synced 2024-11-27 14:40:23 +00:00
Add tests for keep_array_indentation = false
This commit is contained in:
parent
8ec9cb1dd4
commit
dd1c5d01d7
@ -422,21 +422,40 @@ function run_beautifier_tests(test_obj, Urlencoded, js_beautify)
|
||||
bt('if (foo) // comment\n{\n bar();\n}');
|
||||
|
||||
|
||||
opts.keep_array_indentation = false;
|
||||
bt("a = ['a', 'b', 'c',\n 'd', 'e', 'f']",
|
||||
"a = ['a', 'b', 'c',\n 'd', 'e', 'f'\n]");
|
||||
bt("a = ['a', 'b', 'c',\n 'd', 'e', 'f',\n 'g', 'h', 'i']",
|
||||
"a = ['a', 'b', 'c',\n 'd', 'e', 'f',\n 'g', 'h', 'i'\n]");
|
||||
bt("a = ['a', 'b', 'c',\n 'd', 'e', 'f',\n 'g', 'h', 'i']",
|
||||
"a = ['a', 'b', 'c',\n 'd', 'e', 'f',\n 'g', 'h', 'i'\n]");
|
||||
bt('var x = [{}\n]', 'var x = [{}]');
|
||||
bt('var x = [{foo:bar}\n]', 'var x = [{\n foo: bar\n }\n]');
|
||||
bt("a = ['something',\n 'completely',\n 'different'];\nif (x);",
|
||||
"a = ['something',\n 'completely',\n 'different'\n];\nif (x);");
|
||||
bt("a = ['a','b','c']", "a = ['a', 'b', 'c']");
|
||||
bt("a = ['a', 'b','c']", "a = ['a', 'b', 'c']");
|
||||
bt("x = [{'a':0}]",
|
||||
"x = [{\n 'a': 0\n }\n]");
|
||||
// this is not great, but is accurate
|
||||
bt('{a([[a1]], {b;});}',
|
||||
'{\n a([\n [a1]\n ], {\n b;\n });\n}');
|
||||
|
||||
opts.keep_array_indentation = true;
|
||||
bt("a = ['a', 'b', 'c',\n 'd', 'e', 'f']");
|
||||
bt("a = ['a', 'b', 'c',\n 'd', 'e', 'f',\n 'g', 'h', 'i']");
|
||||
bt("a = ['a', 'b', 'c',\n 'd', 'e', 'f',\n 'g', 'h', 'i']");
|
||||
|
||||
|
||||
bt('var x = [{}\n]', 'var x = [{}\n]');
|
||||
bt('var x = [{foo:bar}\n]', 'var x = [{\n foo: bar\n }\n]');
|
||||
bt("a = ['something',\n 'completely',\n 'different'];\nif (x);");
|
||||
bt("a = ['a','b','c']", "a = ['a', 'b', 'c']");
|
||||
bt("a = ['a', 'b','c']", "a = ['a', 'b', 'c']");
|
||||
bt("x = [{'a':0}]",
|
||||
"x = [{\n 'a': 0\n }]");
|
||||
bt('{a([[a1]], {b;});}',
|
||||
'{\n a([[a1]], {\n b;\n });\n}');
|
||||
opts.keep_array_indentation = false;
|
||||
|
||||
bt("x = [{'a':0}]", "x = [{\n 'a': 0\n }]");
|
||||
|
||||
bt('{a([[a1]], {b;});}', '{\n a([[a1]], {\n b;\n });\n}');
|
||||
|
||||
bt('a = //comment\n/regex/;');
|
||||
|
||||
|
@ -375,22 +375,40 @@ class TestJSBeautifier(unittest.TestCase):
|
||||
bt('// a\n// b\n\n// c\n// d')
|
||||
bt('if (foo) // comment\n{\n bar();\n}')
|
||||
|
||||
self.options.keep_array_indentation = True;
|
||||
|
||||
self.options.keep_array_indentation = False;
|
||||
bt("a = ['a', 'b', 'c',\n 'd', 'e', 'f']",
|
||||
"a = ['a', 'b', 'c',\n 'd', 'e', 'f'\n]");
|
||||
bt("a = ['a', 'b', 'c',\n 'd', 'e', 'f',\n 'g', 'h', 'i']",
|
||||
"a = ['a', 'b', 'c',\n 'd', 'e', 'f',\n 'g', 'h', 'i'\n]");
|
||||
bt("a = ['a', 'b', 'c',\n 'd', 'e', 'f',\n 'g', 'h', 'i']",
|
||||
"a = ['a', 'b', 'c',\n 'd', 'e', 'f',\n 'g', 'h', 'i'\n]");
|
||||
bt('var x = [{}\n]', 'var x = [{}]');
|
||||
bt('var x = [{foo:bar}\n]', 'var x = [{\n foo: bar\n }\n]');
|
||||
bt("a = ['something',\n 'completely',\n 'different'];\nif (x);",
|
||||
"a = ['something',\n 'completely',\n 'different'\n];\nif (x);");
|
||||
bt("a = ['a','b','c']", "a = ['a', 'b', 'c']");
|
||||
bt("a = ['a', 'b','c']", "a = ['a', 'b', 'c']");
|
||||
bt("x = [{'a':0}]",
|
||||
"x = [{\n 'a': 0\n }\n]");
|
||||
# this is not great, but is accurate
|
||||
bt('{a([[a1]], {b;});}',
|
||||
'{\n a([\n [a1]\n ], {\n b;\n });\n}');
|
||||
|
||||
self.options.keep_array_indentation = True;
|
||||
bt("a = ['a', 'b', 'c',\n 'd', 'e', 'f']");
|
||||
bt("a = ['a', 'b', 'c',\n 'd', 'e', 'f',\n 'g', 'h', 'i']");
|
||||
bt("a = ['a', 'b', 'c',\n 'd', 'e', 'f',\n 'g', 'h', 'i']");
|
||||
|
||||
|
||||
bt('var x = [{}\n]', 'var x = [{}\n]');
|
||||
bt('var x = [{foo:bar}\n]', 'var x = [{\n foo: bar\n }\n]');
|
||||
bt("a = ['something',\n 'completely',\n 'different'];\nif (x);");
|
||||
bt("a = ['a','b','c']", "a = ['a', 'b', 'c']");
|
||||
bt("a = ['a', 'b','c']", "a = ['a', 'b', 'c']");
|
||||
|
||||
bt("x = [{'a':0}]", "x = [{\n 'a': 0\n }]");
|
||||
|
||||
bt('{a([[a1]], {b;});}', '{\n a([[a1]], {\n b;\n });\n}');
|
||||
bt("x = [{'a':0}]",
|
||||
"x = [{\n 'a': 0\n }]");
|
||||
bt('{a([[a1]], {b;});}',
|
||||
'{\n a([[a1]], {\n b;\n });\n}');
|
||||
self.options.keep_array_indentation = False;
|
||||
|
||||
bt('a = //comment\n/regex/;');
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user