PY-31442 Properly complete triple quotes in f-strings

This commit is contained in:
Mikhail Golubev
2018-10-01 12:46:47 +03:00
parent 1841956e1e
commit dff836aa29
2 changed files with 10 additions and 1 deletions
@@ -22,7 +22,8 @@ import com.jetbrains.python.PyTokenTypes;
* @author traff
*/
public class PythonQuoteHandler extends BaseQuoteHandler {
private static final TokenSet APPLICABLE_TOKENS = TokenSet.orSet(PyTokenTypes.STRING_NODES, TokenSet.create(PyTokenTypes.FSTRING_START));
private static final TokenSet APPLICABLE_TOKENS = TokenSet.orSet(PyTokenTypes.STRING_NODES,
TokenSet.create(PyTokenTypes.FSTRING_START, PyTokenTypes.FSTRING_END));
public PythonQuoteHandler() {
super(APPLICABLE_TOKENS, new char[]{'}', ']', ')', ',', ':', ';', ' ', '\t', '\n'});
@@ -96,6 +96,7 @@ public class PyEditingTest extends PyTestCase {
assertEquals("rf''", doTestTyping("rf", 2, '\''));
assertEquals("fr''", doTestTyping("fr", 2, '\''));
assertEquals("fr''''''", doTestTyping("fr''", 4, '\''));
assertEquals("fr''''''", doTestTyping("fr''", 3, "''"));
}
public void testFStringFragmentBraces() {
@@ -505,6 +506,13 @@ public class PyEditingTest extends PyTestCase {
return myFixture.getDocument(file).getText();
}
private String doTestTyping(final String text, final int offset, final String characters) {
final PsiFile file = myFixture.configureByText(PythonFileType.INSTANCE, text);
myFixture.getEditor().getCaretModel().moveToOffset(offset);
myFixture.type(characters);
return myFixture.getDocument(file).getText();
}
private void doTypingTest(final char character) {
final String testName = "editing/" + getTestName(true);
myFixture.configureByFile(testName + ".py");