Fix indent calculation with tabs when computing prefixes (#595)

Closes #262
This commit is contained in:
Samuel Cormier-Iijima 2019-02-04 21:55:01 -05:00 committed by Jelle Zijlstra
parent f6643c4f0c
commit 66aa676278
2 changed files with 14 additions and 3 deletions

View File

@ -131,10 +131,8 @@ def _partially_consume_prefix(self, prefix, column):
current_line = "" current_line = ""
current_column = 0 current_column = 0
wait_for_nl = False wait_for_nl = False
elif char == ' ': elif char in ' \t':
current_column += 1 current_column += 1
elif char == '\t':
current_column += 4
elif char == '\n': elif char == '\n':
# unexpected empty line # unexpected empty line
current_column = 0 current_column = 0

View File

@ -509,6 +509,19 @@ def test_bracket_match(self) -> None:
black.assert_equivalent(source, actual) black.assert_equivalent(source, actual)
black.assert_stable(source, actual, line_length=ll) black.assert_stable(source, actual, line_length=ll)
def test_comment_indentation(self) -> None:
contents_tab = "if 1:\n\tif 2:\n\t\tpass\n\t# comment\n\tpass\n"
contents_spc = "if 1:\n if 2:\n pass\n # comment\n pass\n"
self.assertFormatEqual(fs(contents_spc), contents_spc)
self.assertFormatEqual(fs(contents_tab), contents_spc)
contents_tab = "if 1:\n\tif 2:\n\t\tpass\n\t\t# comment\n\tpass\n"
contents_spc = "if 1:\n if 2:\n pass\n # comment\n pass\n"
self.assertFormatEqual(fs(contents_tab), contents_spc)
self.assertFormatEqual(fs(contents_spc), contents_spc)
def test_report_verbose(self) -> None: def test_report_verbose(self) -> None:
report = black.Report(verbose=True) report = black.Report(verbose=True)
out_lines = [] out_lines = []