Fix error with brackets in comments.

pull/12/head
Michał Słomkowski 9 years ago
parent 73f01a74ec
commit 0c28d599c0

@ -34,6 +34,9 @@ def clean_lines(orig_lines):
if line == "":
cleaned_lines.append("")
continue
else:
if line.startswith("#"):
cleaned_lines.append(line)
else:
cleaned_lines.extend([l.strip() for l in re.split("([\\{\\}])", line) if l != ""])
@ -56,12 +59,12 @@ def perform_indentation(lines):
indented_lines = []
current_indent = 0
for line in lines:
if line.endswith('}') and current_indent > 0:
if not line.startswith("#") and line.endswith('}') and current_indent > 0:
current_indent -= 1
indented_lines.append(current_indent * INDENTATION + line)
if line.endswith('{'):
if not line.startswith("#") and line.endswith('{'):
current_indent += 1
return indented_lines

@ -26,6 +26,9 @@ class TestFormatter(unittest.TestCase):
self.assertEqual(["{", "ala", "ma", "{", "{", "kota", "}", "to", "}"],
clean_lines(("{", "ala ", "ma {{", " kota ", "}", " to} ")))
self.assertEqual(["{", "ala", "# ma {{", "kota", "}", "to", "}", "# }"],
clean_lines(("{", "ala ", "# ma {{", " kota ", "}", " to} ", "# }")))
def test_perform_indentation(self):
self.assertEqual([
"foo bar {",
@ -40,6 +43,16 @@ class TestFormatter(unittest.TestCase):
" }",
"}"], 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 {")))
self.assertEqual([
"foo bar {",
" fizz bazz {",

Loading…
Cancel
Save