You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
80 lines
2.8 KiB
80 lines
2.8 KiB
import unittest
|
|
|
|
from nginxfmt import *
|
|
|
|
|
|
class TestFormatter(unittest.TestCase):
|
|
def _check_formatting(self, original_text, formatted_text):
|
|
self.assertEqual(formatted_text, format_config_file(original_text))
|
|
|
|
def test_join_opening_parenthesis(self):
|
|
self.assertEqual(["foo", "bar {", "johan {", "tee", "ka", "}"],
|
|
join_opening_parenthesis(("foo", "bar {", "johan", "{", "tee", "ka", "}")))
|
|
|
|
def test_clear_lines(self):
|
|
self.assertEqual(["ala", "ma", "{", "kota", "}", "to;", "", "ook"],
|
|
clean_lines(("ala", "ma {", "kota", "}", "to;", "", "ook")))
|
|
|
|
self.assertEqual(["ala", "ma", "{", "{", "kota", "}", "to", "}", "ook"],
|
|
clean_lines(("ala", "ma {{", "kota", "}", "to}", "ook")))
|
|
|
|
self.assertEqual(["{", "ala", "ma", "{", "{", "kota", "}", "to", "}"],
|
|
clean_lines(("{", "ala ", "ma {{", " kota ", "}", " to} ")))
|
|
|
|
def test_perform_indentation(self):
|
|
self.assertEqual([
|
|
"foo bar {",
|
|
" fizz bazz;",
|
|
"}"], perform_indentation(("foo bar {", "fizz bazz;", "}")))
|
|
|
|
self.assertEqual([
|
|
"foo bar {",
|
|
" fizz bazz {",
|
|
" lorem ipsum;",
|
|
" asdf asdf;",
|
|
" }",
|
|
"}"], perform_indentation(("foo bar {", "fizz bazz {", "lorem ipsum;", "asdf asdf;", "}", "}")))
|
|
|
|
self.assertEqual([
|
|
"foo bar {",
|
|
" fizz bazz {",
|
|
" lorem ipsum;",
|
|
" }",
|
|
"}",
|
|
"}",
|
|
"foo {"], perform_indentation(("foo bar {", "fizz bazz {", "lorem ipsum;", "}", "}", "}", "foo {")))
|
|
|
|
def test_strip_line(self):
|
|
self.assertEqual("foo", strip_line(" foo "))
|
|
self.assertEqual("bar foo", strip_line(" bar foo "))
|
|
self.assertEqual("bar foo", strip_line(" bar \t foo "))
|
|
self.assertEqual('lorem ipsum " foo bar zip "', strip_line(' lorem ipsum " foo bar zip " '))
|
|
self.assertEqual('lorem ipsum " foo bar zip " or " dd aa " mi',
|
|
strip_line(' lorem ipsum " foo bar zip " or \t " dd aa " mi'))
|
|
|
|
def test_indentation(self):
|
|
self._check_formatting(
|
|
" foo bar {\n" +
|
|
" lorem ipsum;\n" +
|
|
"}",
|
|
"foo bar {\n" +
|
|
" lorem ipsum;\n" +
|
|
"}\n")
|
|
|
|
self._check_formatting(
|
|
" foo bar {\n" +
|
|
" lorem ipsum;\n" +
|
|
" kee {\n" +
|
|
"caak; \n" +
|
|
"}}",
|
|
"foo bar {\n" +
|
|
" lorem ipsum;\n" +
|
|
" kee {\n" +
|
|
" caak;\n" +
|
|
" }\n" +
|
|
"}\n")
|
|
|
|
|
|
if __name__ == '__main__':
|
|
unittest.main()
|