failing test for PY-10319

This commit is contained in:
Dmitry Jemerov
2013-11-06 19:17:43 +01:00
parent dd3f3fa7d0
commit 38f058d76f
4 changed files with 25 additions and 2 deletions
@@ -152,7 +152,7 @@ public class PyBlock implements ASTBlock {
if (ourListElementTypes.contains(parentType)) {
// wrapping in non-parenthesized tuple expression is not allowed (PY-1792)
if ((parentType != PyElementTypes.TUPLE_EXPRESSION || grandparentType == PyElementTypes.PARENTHESIZED_EXPRESSION) &&
!ourBrackets.contains(childType) && childType != PyTokenTypes.COMMA && !isSliceOperand(child)) {
!ourBrackets.contains(childType) && childType != PyTokenTypes.COMMA && !isSliceOperand(child) /*&& !isSubscriptionOperand(child)*/) {
wrap = Wrap.createWrap(WrapType.NORMAL, true);
}
if (needListAlignment(child) && !isEmptyList(_node.getPsi())) {
@@ -257,6 +257,11 @@ public class PyBlock implements ASTBlock {
return new PyBlock(this, child, childAlignment, childIndent, wrap, myContext);
}
private static boolean isSubscriptionOperand(ASTNode child) {
return child.getTreeParent().getElementType() == PyElementTypes.SUBSCRIPTION_EXPRESSION &&
child.getPsi() == ((PySubscriptionExpression) child.getTreeParent().getPsi()).getOperand();
}
private boolean isInControlStatement() {
return PsiTreeUtil.getParentOfType(_node.getPsi(), PyStatementPart.class, false, PyStatementList.class) != null ||
PsiTreeUtil.getParentOfType(_node.getPsi(), PyWithItem.class) != null;
@@ -0,0 +1 @@
id = 1 if looooooooooooooooooooooooong_vaaaaaaaaaaaaaaaar == 'loooooooooooooooong_vaaaaaaaaaaaaaaaaaaaaaaaaaalue' else list('foo')[0]
@@ -0,0 +1,2 @@
id = 1 if looooooooooooooooooooooooong_vaaaaaaaaaaaaaaaar == 'loooooooooooooooong_vaaaaaaaaaaaaaaaaaaaaaaaaaalue' else list(
'foo')[0]
@@ -337,12 +337,27 @@ public class PyFormatterTest extends PyTestCase {
doTest();
}
public void _testWrapBeforeElse() { // PY-10319
doTest(true);
}
private void doTest() {
doTest(false);
}
private void doTest(final boolean reformatText) {
myFixture.configureByFile("formatter/" + getTestName(true) + ".py");
ApplicationManager.getApplication().runWriteAction(new Runnable() {
@Override
public void run() {
CodeStyleManager.getInstance(myFixture.getProject()).reformat(myFixture.getFile());
CodeStyleManager codeStyleManager = CodeStyleManager.getInstance(myFixture.getProject());
PsiFile file = myFixture.getFile();
if (reformatText) {
codeStyleManager.reformatText(file, 0, file.getTextLength());
}
else {
codeStyleManager.reformat(file);
}
}
});
myFixture.checkResultByFile("formatter/" + getTestName(true) + "_after.py");