PY-18972 Automatically close quotes for f-string literals

This commit is contained in:
Mikhail Golubev
2016-09-16 08:16:26 +03:00
parent d50db53561
commit aaa2389549
2 changed files with 12 additions and 8 deletions
@@ -88,15 +88,11 @@ public class BaseQuoteHandler extends SimpleTokenSetQuoteHandler implements Mult
}
private static int getLiteralStartOffset(CharSequence text, int start) {
char c = Character.toUpperCase(text.charAt(start));
if (c == 'U' || c == 'B') {
start++;
c = Character.toUpperCase(text.charAt(start));
int index = start;
while (index < start + 2 && "URBF".indexOf(Character.toUpperCase(text.charAt(index))) >= 0) {
index++;
}
if (c == 'R') {
start++;
}
return start;
return index;
}
@Override
@@ -87,6 +87,14 @@ public class PyEditingTest extends PyTestCase {
assertEquals("'''docstring'''", doTestTyping("'''docstring''", 14, '\''));
}
// PY-18972
public void testFString() throws Exception {
assertEquals("f''", doTestTyping("f", 1, '\''));
assertEquals("rf''", doTestTyping("rf", 2, '\''));
assertEquals("fr''", doTestTyping("fr", 2, '\''));
assertEquals("fr''''''", doTestTyping("fr''", 4, '\''));
}
public void testOvertypeFromInside() {
assertEquals("''", doTestTyping("''", 1, '\''));
}