Fix error with brackets in comments.

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

@ -35,7 +35,10 @@ def clean_lines(orig_lines):
cleaned_lines.append("")
continue
else:
cleaned_lines.extend([l.strip() for l in re.split("([\\{\\}])", line) if l != ""])
if line.startswith("#"):
cleaned_lines.append(line)
else:
cleaned_lines.extend([l.strip() for l in re.split("([\\{\\}])", line) if l != ""])
return cleaned_lines
@ -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