PageRenderTime 38ms CodeModel.GetById 10ms RepoModel.GetById 0ms app.codeStats 0ms

/python/jsbeautifier/tests/testindentation.py

http://github.com/einars/js-beautify
Python | 48 lines | 37 code | 11 blank | 0 comment | 2 complexity | e207a4ca0d5abe9a86c19dcef239f103 MD5 | raw file
  1. import re
  2. import unittest
  3. import jsbeautifier
  4. class TestJSBeautifierIndentation(unittest.TestCase):
  5. def test_tabs(self):
  6. test_fragment = self.decodesto
  7. self.options.indent_with_tabs = 1
  8. test_fragment('{tabs()}', "{\n\ttabs()\n}")
  9. def test_function_indent(self):
  10. test_fragment = self.decodesto
  11. self.options.indent_with_tabs = 1
  12. self.options.keep_function_indentation = 1
  13. test_fragment(
  14. 'var foo = function(){ bar() }();',
  15. "var foo = function() {\n\tbar()\n}();")
  16. self.options.tabs = 1
  17. self.options.keep_function_indentation = 0
  18. test_fragment(
  19. 'var foo = function(){ baz() }();',
  20. "var foo = function() {\n\tbaz()\n}();")
  21. def decodesto(self, input, expectation=None):
  22. self.assertEqual(
  23. jsbeautifier.beautify(input, self.options), expectation or input)
  24. @classmethod
  25. def setUpClass(cls):
  26. options = jsbeautifier.default_options()
  27. options.indent_size = 4
  28. options.indent_char = ' '
  29. options.preserve_newlines = True
  30. options.jslint_happy = False
  31. options.keep_array_indentation = False
  32. options.brace_style = 'collapse'
  33. options.indent_level = 0
  34. cls.options = options
  35. cls.wrapregex = re.compile('^(.+)$', re.MULTILINE)
  36. if __name__ == '__main__':
  37. unittest.main()