PY-9176 Converting % to format() doesn't handle multiline string literals

This commit is contained in:
Mikhail Golubev
2014-07-22 13:48:03 +04:00
parent 3d377d95c2
commit b1b8116a76
4 changed files with 13 additions and 1 deletions
@@ -290,7 +290,10 @@ public class ConvertFormatOperatorToMethodIntention extends BaseIntentionAction
}
}
else target.append("(").append(paramText).append(")"); // tuple is ok as is
element.replace(elementGenerator.createExpressionFromText(LanguageLevel.forElement(element), target.toString()));
// Correctly handle multiline implicitly concatenated string literals (PY-9176)
target.insert(0, '(').append(')');
final PyExpression parenthesized = elementGenerator.createExpressionFromText(LanguageLevel.forElement(element), target.toString());
element.replace(sure(((PyParenthesizedExpression)parenthesized).getContainedExpression()));
}
private static String getSeparator(PyStringLiteralExpression leftExpression) {
@@ -0,0 +1,2 @@
print('<caret>%(quantity)s pounds of '
'%(type)s' % dict(quantity=42, type='spam'))
@@ -0,0 +1,2 @@
print('{quantity:s} pounds of '
'{type:s}'.format(quantity=42, type='spam'))
@@ -38,4 +38,9 @@ public class PyConvertFormatOperatorToMethodIntentionTest extends PyIntentionTes
public void testUnicode() {
doTest(PyBundle.message("INTN.replace.with.method"), LanguageLevel.PYTHON26);
}
// PY-9176
public void testConcatenated() {
doTest(PyBundle.message("INTN.replace.with.method"), LanguageLevel.PYTHON26);
}
}