PageRenderTime 71ms CodeModel.GetById 35ms RepoModel.GetById 1ms app.codeStats 0ms

/node_modules/js-beautify/test/data/javascript/python.mustache

http://github.com/jonswar/perl-code-tidyall
Mustache | 1322 lines | 1251 code | 71 blank | 0 comment | 95 complexity | 30f60b9654201a84408645a1a6c814c7 MD5 | raw file
Possible License(s): BSD-3-Clause, AGPL-1.0, 0BSD, MIT

Large files files are truncated, but you can click here to view the full file

  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. '''
  4. {{&header_text}}
  5. The MIT License (MIT)
  6. Copyright (c) 2007-2017 Einar Lielmanis, Liam Newman, and contributors.
  7. Permission is hereby granted, free of charge, to any person
  8. obtaining a copy of this software and associated documentation files
  9. (the "Software"), to deal in the Software without restriction,
  10. including without limitation the rights to use, copy, modify, merge,
  11. publish, distribute, sublicense, and/or sell copies of the Software,
  12. and to permit persons to whom the Software is furnished to do so,
  13. subject to the following conditions:
  14. The above copyright notice and this permission notice shall be
  15. included in all copies or substantial portions of the Software.
  16. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  17. EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  18. MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  19. NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
  20. BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
  21. ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  22. CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  23. SOFTWARE.
  24. '''
  25. import re
  26. import unittest
  27. import jsbeautifier
  28. import six
  29. import copy
  30. class TestJSBeautifier(unittest.TestCase):
  31. options = None
  32. @classmethod
  33. def setUpClass(cls):
  34. true = True
  35. false = False
  36. default_options = jsbeautifier.default_options()
  37. default_options.indent_size = 4
  38. default_options.indent_char = ' '
  39. default_options.preserve_newlines = True
  40. default_options.jslint_happy = False
  41. default_options.keep_array_indentation = False
  42. default_options.brace_style = 'collapse'
  43. default_options.indent_level = 0
  44. default_options.break_chained_methods = False
  45. default_options.eol = '\n'
  46. {{#default_options}} default_options.{{name}} = {{&value}}
  47. {{/default_options}}
  48. cls.default_options = default_options
  49. cls.wrapregex = re.compile('^(.+)$', re.MULTILINE)
  50. def reset_options(self):
  51. self.options = copy.copy(self.default_options)
  52. def test_unescape(self):
  53. # Test cases contributed by <chrisjshull on GitHub.com>
  54. test_fragment = self.decodesto
  55. self.reset_options()
  56. bt = self.bt
  57. def unicode_char(value):
  58. return six.unichr(value)
  59. bt('"\\\\s"') # == "\\s" in the js source
  60. bt("'\\\\s'") # == '\\s' in the js source
  61. bt("'\\\\\\s'") # == '\\\s' in the js source
  62. bt("'\\s'") # == '\s' in the js source
  63. bt('"•"')
  64. bt('"—"')
  65. bt('"\\x41\\x42\\x43\\x01"', '"\\x41\\x42\\x43\\x01"')
  66. bt('"\\u2022"', '"\\u2022"')
  67. bt('a = /\s+/')
  68. #bt('a = /\\x41/','a = /A/')
  69. bt('"\\u2022";a = /\s+/;"\\x41\\x42\\x43\\x01".match(/\\x41/);','"\\u2022";\na = /\s+/;\n"\\x41\\x42\\x43\\x01".match(/\\x41/);')
  70. 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"')
  71. self.options.unescape_strings = True
  72. bt('"\\x41\\x42\\x43\\x01"', '"ABC\\x01"')
  73. test_fragment('"\\x20\\x40\\x4a"', '" @J"');
  74. test_fragment('"\\xff\\x40\\x4a"');
  75. test_fragment('"\\u0072\\u016B\\u0137\\u012B\\u0074\\u0069\\u0073"', six.u('"\u0072\u016B\u0137\u012B\u0074\u0069\u0073"'));
  76. bt('a = /\s+/')
  77. test_fragment('"\\x22\\x27",\'\\x22\\x27\',"\\x5c",\'\\x5c\',"\\xff","unicode \\u0000 \\u0022 \\u0027 \\u005c \\uffff"',
  78. '"\\"\\\'", \'\\"\\\'\', "\\\\", \'\\\\\', "\\xff", "unicode \\u0000 \\" \\\' \\\\ ' + unicode_char(0xffff) + '"');
  79. # For error case, return the string unchanged
  80. test_fragment('"\\x22\\x27",\'\\x22\\x27\',"\\x5c",\'\\x5c\',"\\xff and \\xzz","unicode \\u0000 \\u0022 \\u0027 \\u005c \\uffff \\uzzzz"',
  81. '"\\"\\\'", \'\\"\\\'\', "\\\\", \'\\\\\', "\\xff and \\xzz", "unicode \\u0000 \\u0022 \\u0027 \\u005c \\uffff \\uzzzz"');
  82. self.options.unescape_strings = False
  83. def test_beautifier(self):
  84. test_fragment = self.decodesto
  85. bt = self.bt
  86. true = True
  87. false = False
  88. def unicode_char(value):
  89. return six.unichr(value)
  90. {{#groups}}{{#set_mustache_tags}}.{{/set_mustache_tags}}
  91. #============================================================
  92. {{^matrix}}
  93. # {{&name}}
  94. self.reset_options();
  95. {{#options}}
  96. self.options.{{name}} = {{&value}}
  97. {{/options}}
  98. {{#tests}}
  99. {{#test_line}}.{{/test_line}}
  100. {{/tests}}
  101. {{/matrix}}
  102. {{#matrix}}
  103. # {{&name}} - ({{#matrix_context_string}}.{{/matrix_context_string}})
  104. self.reset_options();
  105. {{#options}}
  106. self.options.{{name}} = {{&value}}
  107. {{/options}}
  108. {{#tests}}
  109. {{#test_line}}.{{/test_line}}
  110. {{/tests}}
  111. {{/matrix}}
  112. {{#unset_mustache_tags}}.{{/unset_mustache_tags}}{{/groups}}
  113. def test_beautifier_unconverted(self):
  114. test_fragment = self.decodesto
  115. bt = self.bt
  116. self.reset_options();
  117. #============================================================
  118. self.options.indent_size = 1;
  119. self.options.indent_char = ' ';
  120. bt('{ one_char() }', "{\n one_char()\n}")
  121. bt('var a,b=1,c=2', 'var a, b = 1,\n c = 2')
  122. self.options.indent_size = 4;
  123. self.options.indent_char = ' ';
  124. bt('{ one_char() }', "{\n one_char()\n}")
  125. self.options.indent_size = 1;
  126. self.options.indent_char = "\t";
  127. bt('{ one_char() }', "{\n\tone_char()\n}")
  128. bt('x = a ? b : c; x;', 'x = a ? b : c;\nx;')
  129. #set to something else than it should change to, but with tabs on, should override
  130. self.options.indent_size = 5;
  131. self.options.indent_char = ' ';
  132. self.options.indent_with_tabs = True;
  133. bt('{ one_char() }', "{\n\tone_char()\n}")
  134. bt('x = a ? b : c; x;', 'x = a ? b : c;\nx;')
  135. self.reset_options();
  136. #============================================================
  137. self.options.preserve_newlines = False;
  138. bt('var\na=dont_preserve_newlines;', 'var a = dont_preserve_newlines;')
  139. # make sure the blank line between function definitions stays
  140. # even when preserve_newlines = False
  141. bt('function foo() {\n return 1;\n}\n\nfunction foo() {\n return 1;\n}')
  142. bt('function foo() {\n return 1;\n}\nfunction foo() {\n return 1;\n}',
  143. 'function foo() {\n return 1;\n}\n\nfunction foo() {\n return 1;\n}'
  144. )
  145. bt('function foo() {\n return 1;\n}\n\n\nfunction foo() {\n return 1;\n}',
  146. 'function foo() {\n return 1;\n}\n\nfunction foo() {\n return 1;\n}'
  147. )
  148. self.options.preserve_newlines = True;
  149. bt('var\na=do_preserve_newlines;', 'var\n a = do_preserve_newlines;')
  150. bt('if (foo) // comment\n{\n bar();\n}')
  151. self.reset_options();
  152. #============================================================
  153. self.options.keep_array_indentation = False;
  154. bt("a = ['a', 'b', 'c',\n 'd', 'e', 'f']",
  155. "a = ['a', 'b', 'c',\n 'd', 'e', 'f'\n]")
  156. bt("a = ['a', 'b', 'c',\n 'd', 'e', 'f',\n 'g', 'h', 'i']",
  157. "a = ['a', 'b', 'c',\n 'd', 'e', 'f',\n 'g', 'h', 'i'\n]")
  158. bt("a = ['a', 'b', 'c',\n 'd', 'e', 'f',\n 'g', 'h', 'i']",
  159. "a = ['a', 'b', 'c',\n 'd', 'e', 'f',\n 'g', 'h', 'i'\n]")
  160. bt('var x = [{}\n]', 'var x = [{}]')
  161. bt('var x = [{foo:bar}\n]', 'var x = [{\n foo: bar\n}]')
  162. bt("a = ['something',\n 'completely',\n 'different'];\nif (x);",
  163. "a = ['something',\n 'completely',\n 'different'\n];\nif (x);")
  164. bt("a = ['a','b','c']", "a = ['a', 'b', 'c']")
  165. bt("a = ['a', 'b','c']", "a = ['a', 'b', 'c']")
  166. bt("x = [{'a':0}]",
  167. "x = [{\n 'a': 0\n}]")
  168. bt('{a([[a1]], {b;});}',
  169. '{\n a([\n [a1]\n ], {\n b;\n });\n}')
  170. bt("a();\n [\n ['sdfsdfsd'],\n ['sdfsdfsdf']\n ].toString();",
  171. "a();\n[\n ['sdfsdfsd'],\n ['sdfsdfsdf']\n].toString();")
  172. bt("a();\na = [\n ['sdfsdfsd'],\n ['sdfsdfsdf']\n ].toString();",
  173. "a();\na = [\n ['sdfsdfsd'],\n ['sdfsdfsdf']\n].toString();")
  174. bt("function() {\n Foo([\n ['sdfsdfsd'],\n ['sdfsdfsdf']\n ]);\n}",
  175. "function() {\n Foo([\n ['sdfsdfsd'],\n ['sdfsdfsdf']\n ]);\n}")
  176. bt('function foo() {\n return [\n "one",\n "two"\n ];\n}')
  177. # 4 spaces per indent input, processed with 4-spaces per indent
  178. bt( "function foo() {\n" +
  179. " return [\n" +
  180. " {\n" +
  181. " one: 'x',\n" +
  182. " two: [\n" +
  183. " {\n" +
  184. " id: 'a',\n" +
  185. " name: 'apple'\n" +
  186. " }, {\n" +
  187. " id: 'b',\n" +
  188. " name: 'banana'\n" +
  189. " }\n" +
  190. " ]\n" +
  191. " }\n" +
  192. " ];\n" +
  193. "}",
  194. "function foo() {\n" +
  195. " return [{\n" +
  196. " one: 'x',\n" +
  197. " two: [{\n" +
  198. " id: 'a',\n" +
  199. " name: 'apple'\n" +
  200. " }, {\n" +
  201. " id: 'b',\n" +
  202. " name: 'banana'\n" +
  203. " }]\n" +
  204. " }];\n" +
  205. "}")
  206. # 3 spaces per indent input, processed with 4-spaces per indent
  207. bt( "function foo() {\n" +
  208. " return [\n" +
  209. " {\n" +
  210. " one: 'x',\n" +
  211. " two: [\n" +
  212. " {\n" +
  213. " id: 'a',\n" +
  214. " name: 'apple'\n" +
  215. " }, {\n" +
  216. " id: 'b',\n" +
  217. " name: 'banana'\n" +
  218. " }\n" +
  219. " ]\n" +
  220. " }\n" +
  221. " ];\n" +
  222. "}",
  223. "function foo() {\n" +
  224. " return [{\n" +
  225. " one: 'x',\n" +
  226. " two: [{\n" +
  227. " id: 'a',\n" +
  228. " name: 'apple'\n" +
  229. " }, {\n" +
  230. " id: 'b',\n" +
  231. " name: 'banana'\n" +
  232. " }]\n" +
  233. " }];\n" +
  234. "}")
  235. self.options.keep_array_indentation = True;
  236. bt("a = ['a', 'b', 'c',\n 'd', 'e', 'f']")
  237. bt("a = ['a', 'b', 'c',\n 'd', 'e', 'f',\n 'g', 'h', 'i']")
  238. bt("a = ['a', 'b', 'c',\n 'd', 'e', 'f',\n 'g', 'h', 'i']")
  239. bt('var x = [{}\n]', 'var x = [{}\n]')
  240. bt('var x = [{foo:bar}\n]', 'var x = [{\n foo: bar\n }\n]')
  241. bt("a = ['something',\n 'completely',\n 'different'];\nif (x);")
  242. bt("a = ['a','b','c']", "a = ['a', 'b', 'c']")
  243. bt("a = ['a', 'b','c']", "a = ['a', 'b', 'c']")
  244. bt("x = [{'a':0}]",
  245. "x = [{\n 'a': 0\n}]")
  246. bt('{a([[a1]], {b;});}',
  247. '{\n a([[a1]], {\n b;\n });\n}')
  248. bt("a();\n [\n ['sdfsdfsd'],\n ['sdfsdfsdf']\n ].toString();",
  249. "a();\n [\n ['sdfsdfsd'],\n ['sdfsdfsdf']\n ].toString();")
  250. bt("a();\na = [\n ['sdfsdfsd'],\n ['sdfsdfsdf']\n ].toString();",
  251. "a();\na = [\n ['sdfsdfsd'],\n ['sdfsdfsdf']\n ].toString();")
  252. bt("function() {\n Foo([\n ['sdfsdfsd'],\n ['sdfsdfsdf']\n ]);\n}",
  253. "function() {\n Foo([\n ['sdfsdfsd'],\n ['sdfsdfsdf']\n ]);\n}")
  254. bt('function foo() {\n return [\n "one",\n "two"\n ];\n}')
  255. # 4 spaces per indent input, processed with 4-spaces per indent
  256. bt( "function foo() {\n" +
  257. " return [\n" +
  258. " {\n" +
  259. " one: 'x',\n" +
  260. " two: [\n" +
  261. " {\n" +
  262. " id: 'a',\n" +
  263. " name: 'apple'\n" +
  264. " }, {\n" +
  265. " id: 'b',\n" +
  266. " name: 'banana'\n" +
  267. " }\n" +
  268. " ]\n" +
  269. " }\n" +
  270. " ];\n" +
  271. "}")
  272. # 3 spaces per indent input, processed with 4-spaces per indent
  273. # Should be unchanged, but is not - #445
  274. # bt( "function foo() {\n" +
  275. # " return [\n" +
  276. # " {\n" +
  277. # " one: 'x',\n" +
  278. # " two: [\n" +
  279. # " {\n" +
  280. # " id: 'a',\n" +
  281. # " name: 'apple'\n" +
  282. # " }, {\n" +
  283. # " id: 'b',\n" +
  284. # " name: 'banana'\n" +
  285. # " }\n" +
  286. # " ]\n" +
  287. # " }\n" +
  288. # " ];\n" +
  289. # "}")
  290. self.reset_options();
  291. #============================================================
  292. bt('a = //comment\n /regex/;')
  293. bt('if (a)\n{\nb;\n}\nelse\n{\nc;\n}', 'if (a) {\n b;\n} else {\n c;\n}')
  294. bt('var a = new function();')
  295. test_fragment('new function')
  296. self.reset_options();
  297. #============================================================
  298. # START tests for brace positioning
  299. # If this is ever supported, update tests for each brace style.
  300. # test_fragment('return\n{', 'return\n{') # can't support this?, but that's an improbable and extreme case anyway.
  301. self.options.brace_style = 'expand';
  302. bt('//case 1\nif (a == 1)\n{}\n//case 2\nelse if (a == 2)\n{}')
  303. bt('if(1){2}else{3}', "if (1)\n{\n 2\n}\nelse\n{\n 3\n}")
  304. bt('try{a();}catch(b){c();}catch(d){}finally{e();}',
  305. "try\n{\n a();\n}\ncatch (b)\n{\n c();\n}\ncatch (d)\n{}\nfinally\n{\n e();\n}")
  306. bt('if(a){b();}else if(c) foo();',
  307. "if (a)\n{\n b();\n}\nelse if (c) foo();")
  308. bt("if (a) {\n// comment\n}else{\n// comment\n}",
  309. "if (a)\n{\n // comment\n}\nelse\n{\n // comment\n}") # if/else statement with empty body
  310. bt('if (x) {y} else { if (x) {y}}',
  311. 'if (x)\n{\n y\n}\nelse\n{\n if (x)\n {\n y\n }\n}')
  312. bt('if (a)\n{\nb;\n}\nelse\n{\nc;\n}',
  313. 'if (a)\n{\n b;\n}\nelse\n{\n c;\n}')
  314. test_fragment(' /*\n* xx\n*/\n// xx\nif (foo) {\n bar();\n}',
  315. ' /*\n * xx\n */\n // xx\n if (foo)\n {\n bar();\n }')
  316. bt('if (foo)\n{}\nelse /regex/.test();')
  317. test_fragment('if (foo) {', 'if (foo)\n{')
  318. test_fragment('foo {', 'foo\n{')
  319. test_fragment('return {', 'return {') # return needs the brace.
  320. test_fragment('return /* inline */ {', 'return /* inline */ {')
  321. test_fragment('return;\n{', 'return;\n{')
  322. bt("throw {}")
  323. bt("throw {\n foo;\n}")
  324. bt('var foo = {}')
  325. bt('function x() {\n foo();\n}zzz', 'function x()\n{\n foo();\n}\nzzz')
  326. test_fragment('a: do {} while (); xxx', 'a: do {} while ();\nxxx')
  327. bt('{a: do {} while (); xxx}', '{\n a: do {} while ();xxx\n}')
  328. bt('var a = new function() {};')
  329. bt('var a = new function a() {};', 'var a = new function a()\n{};')
  330. bt('var a = new function()\n{};', 'var a = new function() {};')
  331. bt('var a = new function a()\n{};')
  332. bt('var a = new function a()\n {},\n b = new function b()\n {};')
  333. bt("foo({\n 'a': 1\n},\n10);",
  334. "foo(\n {\n 'a': 1\n },\n 10);")
  335. bt('(["foo","bar"]).each(function(i) {return i;});',
  336. '(["foo", "bar"]).each(function(i)\n{\n return i;\n});')
  337. bt('(function(i) {return i;})();',
  338. '(function(i)\n{\n return i;\n})();')
  339. bt( "test( /*Argument 1*/ {\n" +
  340. " 'Value1': '1'\n" +
  341. "}, /*Argument 2\n" +
  342. " */ {\n" +
  343. " 'Value2': '2'\n" +
  344. "});",
  345. # expected
  346. "test( /*Argument 1*/\n" +
  347. " {\n" +
  348. " 'Value1': '1'\n" +
  349. " },\n" +
  350. " /*Argument 2\n" +
  351. " */\n" +
  352. " {\n" +
  353. " 'Value2': '2'\n" +
  354. " });")
  355. bt( "test(\n" +
  356. "/*Argument 1*/ {\n" +
  357. " 'Value1': '1'\n" +
  358. "},\n" +
  359. "/*Argument 2\n" +
  360. " */ {\n" +
  361. " 'Value2': '2'\n" +
  362. "});",
  363. # expected
  364. "test(\n" +
  365. " /*Argument 1*/\n" +
  366. " {\n" +
  367. " 'Value1': '1'\n" +
  368. " },\n" +
  369. " /*Argument 2\n" +
  370. " */\n" +
  371. " {\n" +
  372. " 'Value2': '2'\n" +
  373. " });")
  374. bt( "test( /*Argument 1*/\n" +
  375. "{\n" +
  376. " 'Value1': '1'\n" +
  377. "}, /*Argument 2\n" +
  378. " */\n" +
  379. "{\n" +
  380. " 'Value2': '2'\n" +
  381. "});",
  382. # expected
  383. "test( /*Argument 1*/\n" +
  384. " {\n" +
  385. " 'Value1': '1'\n" +
  386. " },\n" +
  387. " /*Argument 2\n" +
  388. " */\n" +
  389. " {\n" +
  390. " 'Value2': '2'\n" +
  391. " });")
  392. self.options.brace_style = 'collapse';
  393. bt('//case 1\nif (a == 1) {}\n//case 2\nelse if (a == 2) {}')
  394. bt('if(1){2}else{3}', "if (1) {\n 2\n} else {\n 3\n}")
  395. bt('try{a();}catch(b){c();}catch(d){}finally{e();}',
  396. "try {\n a();\n} catch (b) {\n c();\n} catch (d) {} finally {\n e();\n}")
  397. bt('if(a){b();}else if(c) foo();',
  398. "if (a) {\n b();\n} else if (c) foo();")
  399. bt("if (a) {\n// comment\n}else{\n// comment\n}",
  400. "if (a) {\n // comment\n} else {\n // comment\n}") # if/else statement with empty body
  401. bt('if (x) {y} else { if (x) {y}}',
  402. 'if (x) {\n y\n} else {\n if (x) {\n y\n }\n}')
  403. bt('if (a)\n{\nb;\n}\nelse\n{\nc;\n}',
  404. 'if (a) {\n b;\n} else {\n c;\n}')
  405. test_fragment(' /*\n* xx\n*/\n// xx\nif (foo) {\n bar();\n}',
  406. ' /*\n * xx\n */\n // xx\n if (foo) {\n bar();\n }')
  407. bt('if (foo) {} else /regex/.test();')
  408. test_fragment('if (foo) {', 'if (foo) {')
  409. test_fragment('foo {', 'foo {')
  410. test_fragment('return {', 'return {') # return needs the brace.
  411. test_fragment('return /* inline */ {', 'return /* inline */ {')
  412. test_fragment('return;\n{', 'return; {')
  413. bt("throw {}")
  414. bt("throw {\n foo;\n}")
  415. bt('var foo = {}')
  416. bt('function x() {\n foo();\n}zzz', 'function x() {\n foo();\n}\nzzz')
  417. test_fragment('a: do {} while (); xxx', 'a: do {} while ();\nxxx')
  418. bt('{a: do {} while (); xxx}', '{\n a: do {} while ();xxx\n}')
  419. bt('var a = new function() {};')
  420. bt('var a = new function a() {};')
  421. bt('var a = new function()\n{};', 'var a = new function() {};')
  422. bt('var a = new function a()\n{};', 'var a = new function a() {};')
  423. bt('var a = new function a()\n {},\n b = new function b()\n {};', 'var a = new function a() {},\n b = new function b() {};')
  424. bt("foo({\n 'a': 1\n},\n10);",
  425. "foo({\n 'a': 1\n },\n 10);")
  426. bt('(["foo","bar"]).each(function(i) {return i;});',
  427. '(["foo", "bar"]).each(function(i) {\n return i;\n});')
  428. bt('(function(i) {return i;})();',
  429. '(function(i) {\n return i;\n})();')
  430. bt( "test( /*Argument 1*/ {\n" +
  431. " 'Value1': '1'\n" +
  432. "}, /*Argument 2\n" +
  433. " */ {\n" +
  434. " 'Value2': '2'\n" +
  435. "});",
  436. # expected
  437. "test( /*Argument 1*/ {\n" +
  438. " 'Value1': '1'\n" +
  439. " },\n" +
  440. " /*Argument 2\n" +
  441. " */\n" +
  442. " {\n" +
  443. " 'Value2': '2'\n" +
  444. " });")
  445. bt( "test(\n" +
  446. "/*Argument 1*/ {\n" +
  447. " 'Value1': '1'\n" +
  448. "},\n" +
  449. "/*Argument 2\n" +
  450. " */ {\n" +
  451. " 'Value2': '2'\n" +
  452. "});",
  453. # expected
  454. "test(\n" +
  455. " /*Argument 1*/\n" +
  456. " {\n" +
  457. " 'Value1': '1'\n" +
  458. " },\n" +
  459. " /*Argument 2\n" +
  460. " */\n" +
  461. " {\n" +
  462. " 'Value2': '2'\n" +
  463. " });")
  464. bt( "test( /*Argument 1*/\n" +
  465. "{\n" +
  466. " 'Value1': '1'\n" +
  467. "}, /*Argument 2\n" +
  468. " */\n" +
  469. "{\n" +
  470. " 'Value2': '2'\n" +
  471. "});",
  472. # expected
  473. "test( /*Argument 1*/ {\n" +
  474. " 'Value1': '1'\n" +
  475. " },\n" +
  476. " /*Argument 2\n" +
  477. " */\n" +
  478. " {\n" +
  479. " 'Value2': '2'\n" +
  480. " });")
  481. self.options.brace_style = "end-expand";
  482. bt('//case 1\nif (a == 1) {}\n//case 2\nelse if (a == 2) {}')
  483. bt('if(1){2}else{3}', "if (1) {\n 2\n}\nelse {\n 3\n}")
  484. bt('try{a();}catch(b){c();}catch(d){}finally{e();}',
  485. "try {\n a();\n}\ncatch (b) {\n c();\n}\ncatch (d) {}\nfinally {\n e();\n}")
  486. bt('if(a){b();}else if(c) foo();',
  487. "if (a) {\n b();\n}\nelse if (c) foo();")
  488. bt("if (a) {\n// comment\n}else{\n// comment\n}",
  489. "if (a) {\n // comment\n}\nelse {\n // comment\n}") # if/else statement with empty body
  490. bt('if (x) {y} else { if (x) {y}}',
  491. 'if (x) {\n y\n}\nelse {\n if (x) {\n y\n }\n}')
  492. bt('if (a)\n{\nb;\n}\nelse\n{\nc;\n}',
  493. 'if (a) {\n b;\n}\nelse {\n c;\n}')
  494. test_fragment(' /*\n* xx\n*/\n// xx\nif (foo) {\n bar();\n}',
  495. ' /*\n * xx\n */\n // xx\n if (foo) {\n bar();\n }')
  496. bt('if (foo) {}\nelse /regex/.test();')
  497. test_fragment('if (foo) {', 'if (foo) {')
  498. test_fragment('foo {', 'foo {')
  499. test_fragment('return {', 'return {') # return needs the brace.
  500. test_fragment('return /* inline */ {', 'return /* inline */ {')
  501. test_fragment('return;\n{', 'return; {')
  502. bt("throw {}")
  503. bt("throw {\n foo;\n}")
  504. bt('var foo = {}')
  505. bt('function x() {\n foo();\n}zzz', 'function x() {\n foo();\n}\nzzz')
  506. test_fragment('a: do {} while (); xxx', 'a: do {} while ();\nxxx')
  507. bt('{a: do {} while (); xxx}', '{\n a: do {} while ();xxx\n}')
  508. bt('var a = new function() {};')
  509. bt('var a = new function a() {};')
  510. bt('var a = new function()\n{};', 'var a = new function() {};')
  511. bt('var a = new function a()\n{};', 'var a = new function a() {};')
  512. bt('var a = new function a()\n {},\n b = new function b()\n {};', 'var a = new function a() {},\n b = new function b() {};')
  513. bt("foo({\n 'a': 1\n},\n10);",
  514. "foo({\n 'a': 1\n },\n 10);")
  515. bt('(["foo","bar"]).each(function(i) {return i;});',
  516. '(["foo", "bar"]).each(function(i) {\n return i;\n});')
  517. bt('(function(i) {return i;})();',
  518. '(function(i) {\n return i;\n})();')
  519. bt( "test( /*Argument 1*/ {\n" +
  520. " 'Value1': '1'\n" +
  521. "}, /*Argument 2\n" +
  522. " */ {\n" +
  523. " 'Value2': '2'\n" +
  524. "});",
  525. # expected
  526. "test( /*Argument 1*/ {\n" +
  527. " 'Value1': '1'\n" +
  528. " },\n" +
  529. " /*Argument 2\n" +
  530. " */\n" +
  531. " {\n" +
  532. " 'Value2': '2'\n" +
  533. " });")
  534. bt( "test(\n" +
  535. "/*Argument 1*/ {\n" +
  536. " 'Value1': '1'\n" +
  537. "},\n" +
  538. "/*Argument 2\n" +
  539. " */ {\n" +
  540. " 'Value2': '2'\n" +
  541. "});",
  542. # expected
  543. "test(\n" +
  544. " /*Argument 1*/\n" +
  545. " {\n" +
  546. " 'Value1': '1'\n" +
  547. " },\n" +
  548. " /*Argument 2\n" +
  549. " */\n" +
  550. " {\n" +
  551. " 'Value2': '2'\n" +
  552. " });")
  553. bt( "test( /*Argument 1*/\n" +
  554. "{\n" +
  555. " 'Value1': '1'\n" +
  556. "}, /*Argument 2\n" +
  557. " */\n" +
  558. "{\n" +
  559. " 'Value2': '2'\n" +
  560. "});",
  561. # expected
  562. "test( /*Argument 1*/ {\n" +
  563. " 'Value1': '1'\n" +
  564. " },\n" +
  565. " /*Argument 2\n" +
  566. " */\n" +
  567. " {\n" +
  568. " 'Value2': '2'\n" +
  569. " });")
  570. self.options.brace_style = 'none';
  571. bt('//case 1\nif (a == 1)\n{}\n//case 2\nelse if (a == 2)\n{}')
  572. bt('if(1){2}else{3}', "if (1) {\n 2\n} else {\n 3\n}")
  573. bt('try{a();}catch(b){c();}catch(d){}finally{e();}',
  574. "try {\n a();\n} catch (b) {\n c();\n} catch (d) {} finally {\n e();\n}")
  575. bt('if(a){b();}else if(c) foo();',
  576. "if (a) {\n b();\n} else if (c) foo();")
  577. bt("if (a) {\n// comment\n}else{\n// comment\n}",
  578. "if (a) {\n // comment\n} else {\n // comment\n}") # if/else statement with empty body
  579. bt('if (x) {y} else { if (x) {y}}',
  580. 'if (x) {\n y\n} else {\n if (x) {\n y\n }\n}')
  581. bt('if (a)\n{\nb;\n}\nelse\n{\nc;\n}',
  582. 'if (a)\n{\n b;\n}\nelse\n{\n c;\n}')
  583. test_fragment(' /*\n* xx\n*/\n// xx\nif (foo) {\n bar();\n}',
  584. ' /*\n * xx\n */\n // xx\n if (foo) {\n bar();\n }')
  585. bt('if (foo)\n{}\nelse /regex/.test();')
  586. test_fragment('if (foo) {')
  587. test_fragment('foo {')
  588. test_fragment('return {') # return needs the brace.
  589. test_fragment('return /* inline */ {')
  590. test_fragment('return;\n{')
  591. bt("throw {}")
  592. bt("throw {\n foo;\n}")
  593. bt('var foo = {}')
  594. bt('function x() {\n foo();\n}zzz', 'function x() {\n foo();\n}\nzzz')
  595. test_fragment('a: do {} while (); xxx', 'a: do {} while ();\nxxx')
  596. bt('{a: do {} while (); xxx}', '{\n a: do {} while ();xxx\n}')
  597. bt('var a = new function() {};')
  598. bt('var a = new function a() {};')
  599. bt('var a = new function()\n{};', 'var a = new function() {};')
  600. bt('var a = new function a()\n{};')
  601. bt('var a = new function a()\n {},\n b = new function b()\n {};')
  602. bt("foo({\n 'a': 1\n},\n10);",
  603. "foo({\n 'a': 1\n },\n 10);")
  604. bt('(["foo","bar"]).each(function(i) {return i;});',
  605. '(["foo", "bar"]).each(function(i) {\n return i;\n});')
  606. bt('(function(i) {return i;})();',
  607. '(function(i) {\n return i;\n})();')
  608. bt( "test( /*Argument 1*/ {\n" +
  609. " 'Value1': '1'\n" +
  610. "}, /*Argument 2\n" +
  611. " */ {\n" +
  612. " 'Value2': '2'\n" +
  613. "});",
  614. # expected
  615. "test( /*Argument 1*/ {\n" +
  616. " 'Value1': '1'\n" +
  617. " },\n" +
  618. " /*Argument 2\n" +
  619. " */\n" +
  620. " {\n" +
  621. " 'Value2': '2'\n" +
  622. " });")
  623. bt( "test(\n" +
  624. "/*Argument 1*/ {\n" +
  625. " 'Value1': '1'\n" +
  626. "},\n" +
  627. "/*Argument 2\n" +
  628. " */ {\n" +
  629. " 'Value2': '2'\n" +
  630. "});",
  631. # expected
  632. "test(\n" +
  633. " /*Argument 1*/\n" +
  634. " {\n" +
  635. " 'Value1': '1'\n" +
  636. " },\n" +
  637. " /*Argument 2\n" +
  638. " */\n" +
  639. " {\n" +
  640. " 'Value2': '2'\n" +
  641. " });")
  642. bt( "test( /*Argument 1*/\n" +
  643. "{\n" +
  644. " 'Value1': '1'\n" +
  645. "}, /*Argument 2\n" +
  646. " */\n" +
  647. "{\n" +
  648. " 'Value2': '2'\n" +
  649. "});",
  650. # expected
  651. "test( /*Argument 1*/\n" +
  652. " {\n" +
  653. " 'Value1': '1'\n" +
  654. " },\n" +
  655. " /*Argument 2\n" +
  656. " */\n" +
  657. " {\n" +
  658. " 'Value2': '2'\n" +
  659. " });")
  660. # END tests for brace position
  661. self.reset_options();
  662. #============================================================
  663. test_fragment('roo = {\n /*\n ****\n FOO\n ****\n */\n BAR: 0\n};')
  664. test_fragment("if (zz) {\n // ....\n}\n(function")
  665. self.reset_options();
  666. #============================================================
  667. self.options.preserve_newlines = True;
  668. bt('var a = 42; // foo\n\nvar b;')
  669. bt('var a = 42; // foo\n\n\nvar b;')
  670. bt("var a = 'foo' +\n 'bar';")
  671. bt("var a = \"foo\" +\n \"bar\";")
  672. bt('"foo""bar""baz"', '"foo"\n"bar"\n"baz"')
  673. bt("'foo''bar''baz'", "'foo'\n'bar'\n'baz'")
  674. bt("{\n get foo() {}\n}")
  675. bt("{\n var a = get\n foo();\n}")
  676. bt("{\n set foo() {}\n}")
  677. bt("{\n var a = set\n foo();\n}")
  678. bt("var x = {\n get function()\n}")
  679. bt("var x = {\n set function()\n}")
  680. # According to my current research get/set have no special meaning outside of an object literal
  681. bt("var x = set\n\na() {}", "var x = set\n\na() {}")
  682. bt("var x = set\n\nfunction() {}", "var x = set\n\nfunction() {}")
  683. bt('<!-- foo\nbar();\n-->')
  684. bt('<!-- dont crash') # -->
  685. bt('for () /abc/.test()')
  686. bt('if (k) /aaa/m.test(v) && l();')
  687. bt('switch (true) {\n case /swf/i.test(foo):\n bar();\n}')
  688. bt('createdAt = {\n type: Date,\n default: Date.now\n}')
  689. bt('switch (createdAt) {\n case a:\n Date,\n default:\n Date.now\n}')
  690. bt('return function();')
  691. bt('var a = function();')
  692. bt('var a = 5 + function();')
  693. bt('{\n foo // something\n ,\n bar // something\n baz\n}')
  694. bt('function a(a) {} function b(b) {} function c(c) {}', 'function a(a) {}\n\nfunction b(b) {}\n\nfunction c(c) {}')
  695. bt('import foo.*;', 'import foo.*;') # actionscript's import
  696. test_fragment('function f(a: a, b: b)') # actionscript
  697. bt('foo(a, function() {})')
  698. bt('foo(a, /regex/)')
  699. bt('/* foo */\n"x"')
  700. self.reset_options();
  701. #============================================================
  702. self.options.break_chained_methods = False
  703. self.options.preserve_newlines = False
  704. bt('foo\n.bar()\n.baz().cucumber(fat)', 'foo.bar().baz().cucumber(fat)')
  705. bt('foo\n.bar()\n.baz().cucumber(fat); foo.bar().baz().cucumber(fat)', 'foo.bar().baz().cucumber(fat);\nfoo.bar().baz().cucumber(fat)')
  706. bt('foo\n.bar()\n.baz().cucumber(fat)\n foo.bar().baz().cucumber(fat)', 'foo.bar().baz().cucumber(fat)\nfoo.bar().baz().cucumber(fat)')
  707. bt('this\n.something = foo.bar()\n.baz().cucumber(fat)', 'this.something = foo.bar().baz().cucumber(fat)')
  708. bt('this.something.xxx = foo.moo.bar()')
  709. bt('this\n.something\n.xxx = foo.moo\n.bar()', 'this.something.xxx = foo.moo.bar()')
  710. self.options.break_chained_methods = False
  711. self.options.preserve_newlines = True
  712. bt('foo\n.bar()\n.baz().cucumber(fat)', 'foo\n .bar()\n .baz().cucumber(fat)')
  713. bt('foo\n.bar()\n.baz().cucumber(fat); foo.bar().baz().cucumber(fat)', 'foo\n .bar()\n .baz().cucumber(fat);\nfoo.bar().baz().cucumber(fat)')
  714. bt('foo\n.bar()\n.baz().cucumber(fat)\n foo.bar().baz().cucumber(fat)', 'foo\n .bar()\n .baz().cucumber(fat)\nfoo.bar().baz().cucumber(fat)')
  715. bt('this\n.something = foo.bar()\n.baz().cucumber(fat)', 'this\n .something = foo.bar()\n .baz().cucumber(fat)')
  716. bt('this.something.xxx = foo.moo.bar()')
  717. bt('this\n.something\n.xxx = foo.moo\n.bar()', 'this\n .something\n .xxx = foo.moo\n .bar()')
  718. self.options.break_chained_methods = True
  719. self.options.preserve_newlines = False
  720. bt('foo\n.bar()\n.baz().cucumber(fat)', 'foo.bar()\n .baz()\n .cucumber(fat)')
  721. bt('foo\n.bar()\n.baz().cucumber(fat); foo.bar().baz().cucumber(fat)', 'foo.bar()\n .baz()\n .cucumber(fat);\nfoo.bar()\n .baz()\n .cucumber(fat)')
  722. bt('foo\n.bar()\n.baz().cucumber(fat)\n foo.bar().baz().cucumber(fat)', 'foo.bar()\n .baz()\n .cucumber(fat)\nfoo.bar()\n .baz()\n .cucumber(fat)')
  723. bt('this\n.something = foo.bar()\n.baz().cucumber(fat)', 'this.something = foo.bar()\n .baz()\n .cucumber(fat)')
  724. bt('this.something.xxx = foo.moo.bar()')
  725. bt('this\n.something\n.xxx = foo.moo\n.bar()', 'this.something.xxx = foo.moo.bar()')
  726. self.options.break_chained_methods = True
  727. self.options.preserve_newlines = True
  728. bt('foo\n.bar()\n.baz().cucumber(fat)', 'foo\n .bar()\n .baz()\n .cucumber(fat)')
  729. bt('foo\n.bar()\n.baz().cucumber(fat); foo.bar().baz().cucumber(fat)', 'foo\n .bar()\n .baz()\n .cucumber(fat);\nfoo.bar()\n .baz()\n .cucumber(fat)')
  730. bt('foo\n.bar()\n.baz().cucumber(fat)\n foo.bar().baz().cucumber(fat)', 'foo\n .bar()\n .baz()\n .cucumber(fat)\nfoo.bar()\n .baz()\n .cucumber(fat)')
  731. bt('this\n.something = foo.bar()\n.baz().cucumber(fat)', 'this\n .something = foo.bar()\n .baz()\n .cucumber(fat)')
  732. bt('this.something.xxx = foo.moo.bar()')
  733. bt('this\n.something\n.xxx = foo.moo\n.bar()', 'this\n .something\n .xxx = foo.moo\n .bar()')
  734. self.reset_options();
  735. #============================================================
  736. # Line wrap test intputs
  737. #..............---------1---------2---------3---------4---------5---------6---------7
  738. #..............1234567890123456789012345678901234567890123456789012345678901234567890
  739. wrap_input_1=('foo.bar().baz().cucumber((fat && "sassy") || (leans && mean));\n' +
  740. 'Test_very_long_variable_name_this_should_never_wrap\n.but_this_can\n' +
  741. 'return between_return_and_expression_should_never_wrap.but_this_can\n' +
  742. 'throw between_throw_and_expression_should_never_wrap.but_this_can\n' +
  743. 'if (wraps_can_occur && inside_an_if_block) that_is_\n.okay();\n' +
  744. 'object_literal = {\n' +
  745. ' propertx: first_token + 12345678.99999E-6,\n' +
  746. ' property: first_token_should_never_wrap + but_this_can,\n' +
  747. ' propertz: first_token_should_never_wrap + !but_this_can,\n' +
  748. ' proper: "first_token_should_never_wrap" + "but_this_can"\n' +
  749. '}')
  750. #..............---------1---------2---------3---------4---------5---------6---------7
  751. #..............1234567890123456789012345678901234567890123456789012345678901234567890
  752. wrap_input_2=('{\n' +
  753. ' foo.bar().baz().cucumber((fat && "sassy") || (leans && mean));\n' +
  754. ' Test_very_long_variable_name_this_should_never_wrap\n.but_this_can\n' +
  755. ' return between_return_and_expression_should_never_wrap.but_this_can\n' +
  756. ' throw between_throw_and_expression_should_never_wrap.but_this_can\n' +
  757. ' if (wraps_can_occur && inside_an_if_block) that_is_\n.okay();\n' +
  758. ' object_literal = {\n' +
  759. ' propertx: first_token + 12345678.99999E-6,\n' +
  760. ' property: first_token_should_never_wrap + but_this_can,\n' +
  761. ' propertz: first_token_should_never_wrap + !but_this_can,\n' +
  762. ' proper: "first_token_should_never_wrap" + "but_this_can"\n' +
  763. ' }' +
  764. '}')
  765. self.options.preserve_newlines = False
  766. self.options.wrap_line_length = 0
  767. #..............---------1---------2---------3---------4---------5---------6---------7
  768. #..............1234567890123456789012345678901234567890123456789012345678901234567890
  769. test_fragment(wrap_input_1,
  770. # expected #
  771. 'foo.bar().baz().cucumber((fat && "sassy") || (leans && mean));\n' +
  772. 'Test_very_long_variable_name_this_should_never_wrap.but_this_can\n' +
  773. 'return between_return_and_expression_should_never_wrap.but_this_can\n' +
  774. 'throw between_throw_and_expression_should_never_wrap.but_this_can\n' +
  775. 'if (wraps_can_occur && inside_an_if_block) that_is_.okay();\n' +
  776. 'object_literal = {\n' +
  777. ' propertx: first_token + 12345678.99999E-6,\n' +
  778. ' property: first_token_should_never_wrap + but_this_can,\n' +
  779. ' propertz: first_token_should_never_wrap + !but_this_can,\n' +
  780. ' proper: "first_token_should_never_wrap" + "but_this_can"\n' +
  781. '}')
  782. self.options.wrap_line_length = 70
  783. #..............---------1---------2---------3---------4---------5---------6---------7
  784. #..............1234567890123456789012345678901234567890123456789012345678901234567890
  785. test_fragment(wrap_input_1,
  786. # expected #
  787. 'foo.bar().baz().cucumber((fat && "sassy") || (leans && mean));\n' +
  788. 'Test_very_long_variable_name_this_should_never_wrap.but_this_can\n' +
  789. 'return between_return_and_expression_should_never_wrap.but_this_can\n' +
  790. 'throw between_throw_and_expression_should_never_wrap.but_this_can\n' +
  791. 'if (wraps_can_occur && inside_an_if_block) that_is_.okay();\n' +
  792. 'object_literal = {\n' +
  793. ' propertx: first_token + 12345678.99999E-6,\n' +
  794. ' property: first_token_should_never_wrap + but_this_can,\n' +
  795. ' propertz: first_token_should_never_wrap + !but_this_can,\n' +
  796. ' proper: "first_token_should_never_wrap" + "but_this_can"\n' +
  797. '}')
  798. self.options.wrap_line_length = 40
  799. #..............---------1---------2---------3---------4---------5---------6---------7
  800. #..............1234567890123456789012345678901234567890123456789012345678901234567890
  801. test_fragment(wrap_input_1,
  802. # expected #
  803. 'foo.bar().baz().cucumber((fat &&\n' +
  804. ' "sassy") || (leans && mean));\n' +
  805. 'Test_very_long_variable_name_this_should_never_wrap\n' +
  806. ' .but_this_can\n' +
  807. 'return between_return_and_expression_should_never_wrap\n' +
  808. ' .but_this_can\n' +
  809. 'throw between_throw_and_expression_should_never_wrap\n' +
  810. ' .but_this_can\n' +
  811. 'if (wraps_can_occur &&\n' +
  812. ' inside_an_if_block) that_is_.okay();\n' +
  813. 'object_literal = {\n' +
  814. ' propertx: first_token +\n' +
  815. ' 12345678.99999E-6,\n' +
  816. ' property: first_token_should_never_wrap +\n' +
  817. ' but_this_can,\n' +
  818. ' propertz: first_token_should_never_wrap +\n' +
  819. ' !but_this_can,\n' +
  820. ' proper: "first_token_should_never_wrap" +\n' +
  821. ' "but_this_can"\n' +
  822. '}')
  823. self.options.wrap_line_length = 41
  824. # NOTE: wrap is only best effort - line continues until next wrap point is found.
  825. #..............---------1---------2---------3---------4---------5---------6---------7
  826. #..............1234567890123456789012345678901234567890123456789012345678901234567890
  827. test_fragment(wrap_input_1,
  828. # expected #
  829. 'foo.bar().baz().cucumber((fat && "sassy") ||\n' +
  830. ' (leans && mean));\n' +
  831. 'Test_very_long_variable_name_this_should_never_wrap\n' +
  832. ' .but_this_can\n' +
  833. 'return between_return_and_expression_should_never_wrap\n' +
  834. ' .but_this_can\n' +
  835. 'throw between_throw_and_expression_should_never_wrap\n' +
  836. ' .but_this_can\n' +
  837. 'if (wraps_can_occur &&\n' +
  838. ' inside_an_if_block) that_is_.okay();\n' +
  839. 'object_literal = {\n' +
  840. ' propertx: first_token +\n' +
  841. ' 12345678.99999E-6,\n' +
  842. ' property: first_token_should_never_wrap +\n' +
  843. ' but_this_can,\n' +
  844. ' propertz: first_token_should_never_wrap +\n' +
  845. ' !but_this_can,\n' +
  846. ' proper: "first_token_should_never_wrap" +\n' +
  847. ' "but_this_can"\n' +
  848. '}')
  849. self.options.wrap_line_length = 45
  850. # NOTE: wrap is only best effort - line continues until next wrap point is found.
  851. #..............---------1---------2---------3---------4---------5---------6---------7
  852. #..............1234567890123456789012345678901234567890123456789012345678901234567890
  853. test_fragment(wrap_input_2,
  854. # expected #
  855. '{\n' +
  856. ' foo.bar().baz().cucumber((fat && "sassy") ||\n' +
  857. ' (leans && mean));\n' +
  858. ' Test_very_long_variable_name_this_should_never_wrap\n' +
  859. ' .but_this_can\n' +
  860. ' return between_return_and_expression_should_never_wrap\n' +
  861. ' .but_this_can\n' +
  862. ' throw between_throw_and_expression_should_never_wrap\n' +
  863. ' .but_this_can\n' +
  864. ' if (wraps_can_occur &&\n' +
  865. ' inside_an_if_block) that_is_.okay();\n' +
  866. ' object_literal = {\n' +
  867. ' propertx: first_token +\n' +
  868. ' 12345678.99999E-6,\n' +
  869. ' property: first_token_should_never_wrap +\n' +
  870. ' but_this_can,\n' +
  871. ' propertz: first_token_should_never_wrap +\n' +
  872. ' !but_this_can,\n' +
  873. ' proper: "first_token_should_never_wrap" +\n' +
  874. ' "but_this_can"\n' +
  875. ' }\n'+
  876. '}')
  877. self.options.preserve_newlines = True
  878. self.options.wrap_line_length = 0
  879. #..............---------1---------2---------3---------4---------5---------6---------7
  880. #..............1234567890123456789012345678901234567890123456789012345678901234567890
  881. test_fragment(wrap_input_1,
  882. # expected #
  883. 'foo.bar().baz().cucumber((fat && "sassy") || (leans && mean));\n' +
  884. 'Test_very_long_variable_name_this_should_never_wrap\n' +
  885. ' .but_this_can\n' +
  886. 'return between_return_and_expression_should_never_wrap.but_this_can\n' +
  887. 'throw between_throw_and_expression_should_never_wrap.but_this_can\n' +
  888. 'if (wraps_can_occur && inside_an_if_block) that_is_\n' +
  889. ' .okay();\n' +
  890. 'object_literal = {\n' +
  891. ' propertx: first_token + 12345678.99999E-6,\n' +
  892. ' property: first_token_should_never_wrap + but_this_can,\n' +
  893. ' propertz: first_token_should_never_wrap + !but_this_can,\n' +
  894. ' proper: "first_token_should_never_wrap" + "but_this_can"\n' +
  895. '}')
  896. self.options.wrap_line_length = 70
  897. #..............---------1---------2---------3---------4---------5---------6---------7
  898. #..............1234567890123456789012345678901234567890123456789012345678901234567890
  899. test_fragment(wrap_input_1,
  900. # expected #
  901. 'foo.bar().baz().cucumber((fat && "sassy") || (leans && mean));\n' +
  902. 'Test_very_long_variable_name_this_should_never_wrap\n' +
  903. ' .but_this_can\n' +
  904. 'return between_return_and_expression_should_never_wrap.but_this_can\n' +
  905. 'throw between_throw_and_expression_should_never_wrap.but_this_can\n' +
  906. 'if (wraps_can_occur && inside_an_if_block) that_is_\n' +
  907. ' .okay();\n' +
  908. 'object_literal = {\n' +
  909. ' propertx: first_token + 12345678.99999E-6,\n' +
  910. ' property: first_token_should_never_wrap + but_this_can,\n' +
  911. ' propertz: first_token_should_never_wrap + !but_this_can,\n' +
  912. ' proper: "first_token_should_never_wrap" + "but_this_can"\n' +
  913. '}')
  914. self.options.wrap_line_length = 40
  915. #..............---------1---------2---------3---------4---------5---------6---------7
  916. #..............1234567890123456789012345678901234567890123456789012345678901234567890
  917. test_fragment(wrap_input_1,
  918. # expected #
  919. 'foo.bar().baz().cucumber((fat &&\n' +
  920. ' "sassy") || (leans && mean));\n' +
  921. 'Test_very_long_variable_name_this_should_never_wrap\n' +
  922. ' .but_this_can\n' +
  923. 'return between_return_and_expression_should_never_wrap\n' +
  924. ' .but_this_can\n' +
  925. 'throw between_throw_and_expression_should_never_wrap\n' +
  926. ' .but_this_can\n' +
  927. 'if (wraps_can_occur &&\n' +
  928. ' inside_an_if_block) that_is_\n' +
  929. ' .okay();\n' +
  930. 'object_literal = {\n' +
  931. ' propertx: first_token +\n' +
  932. ' 12345678.99999E-6,\n' +
  933. ' property: first_token_should_never_wrap +\n' +
  934. ' but_this_can,\n' +
  935. ' propertz: first_token_should_never_wrap +\n' +
  936. ' !but_this_can,\n' +
  937. ' proper: "first_token_should_never_wrap" +\n' +
  938. ' "but_this_can"\n' +
  939. '}')
  940. self.options.wrap_line_length = 41
  941. # NOTE: wrap is only best effort - line continues until next wrap point is found.
  942. #..............---------1---------2---------3---------4---------5---------6---------7
  943. #..............1234567890123456789012345678901234567890123456789012345678901234567890
  944. test_fragment(wrap_input_1,
  945. # expected #
  946. 'foo.bar().baz().cucumber((fat && "sassy") ||\n' +
  947. ' (leans && mean));\n' +
  948. 'Test_very_long_variable_name_this_should_never_wrap\n' +
  949. ' .but_this_can\n' +
  950. 'return between_return_and_expression_should_never_wrap\n' +
  951. ' .but_this_can\n' +
  952. 'throw between_throw_and_expression_should_never_wrap\n' +
  953. ' .but_this_can\n' +
  954. 'if (wraps_can_occur &&\n' +
  955. ' inside_an_if_block) that_is_\n' +
  956. ' .okay();\n' +
  957. 'object_literal = {\n' +
  958. ' propertx: first_token +\n' +
  959. ' 1234…

Large files files are truncated, but you can click here to view the full file