Fix indent calculation with tabs when computing prefixes (#595)
Closes #262
This commit is contained in:
parent
f6643c4f0c
commit
66aa676278
@ -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
|
||||||
|
@ -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 = []
|
||||||
|
Loading…
Reference in New Issue
Block a user