PY-33656 Properly align f-string nodes joined using backslashes

This commit is contained in:
Mikhail Golubev
2019-04-08 19:45:24 +03:00
parent ccb55ad2d7
commit 69be665e77
5 changed files with 12 additions and 3 deletions
@@ -295,7 +295,7 @@ public class PyBlock implements ASTBlock {
}
}
else if (parentType == PyElementTypes.STRING_LITERAL_EXPRESSION) {
if (PyTokenTypes.STRING_NODES.contains(childType)) {
if (PyTokenTypes.STRING_NODES.contains(childType) || childType == PyElementTypes.FSTRING_NODE) {
childAlignment = getAlignmentForChildren();
}
}
@@ -0,0 +1,2 @@
string_literal = f'foo' \
f'bar'
@@ -0,0 +1,2 @@
string_literal = f'foo' \
f'bar'
@@ -126,13 +126,13 @@ public class PyEditingTest extends PyTestCase {
public void testEnterInFStringTextPart() {
doTestEnter("f'foo<caret>bar'", "f'foo' \\\n" +
" f'bar'");
"f'bar'");
}
// PY-31984
public void testEnterInFStringRightBeforeFragment() {
doTestEnter("f'foo<caret>{42}bar'", "f'foo' \\\n" +
" f'{42}bar'");
"f'{42}bar'");
}
// PY-32918
@@ -931,6 +931,11 @@ public class PyFormatterTest extends PyTestCase {
runWithLanguageLevel(LanguageLevel.PYTHON36, this::doTest);
}
// PY-33656
public void testBackslashGluedFStringNodesAlignment() {
doTest();
}
// PY-31991
public void testSpacesAroundFStringFragmentExpressionStripped() {
runWithLanguageLevel(LanguageLevel.PYTHON36, this::doTest);