mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
Fix for try/catch statement (PY-20616)
This commit is contained in:
@@ -32,6 +32,7 @@ import com.intellij.util.DocumentUtil
|
||||
import com.jetbrains.python.PyTokenTypes
|
||||
import com.jetbrains.python.psi.PyStatementListContainer
|
||||
import com.jetbrains.python.psi.PyStringLiteralExpression
|
||||
import com.jetbrains.python.psi.PyTryPart
|
||||
import com.jetbrains.python.psi.impl.PyPsiUtils
|
||||
import com.jetbrains.python.psi.impl.PyStringLiteralExpressionImpl
|
||||
|
||||
@@ -82,11 +83,11 @@ class PyConsoleEnterHandler {
|
||||
}
|
||||
|
||||
private fun checkComplete(el: PsiElement): Boolean {
|
||||
if (!el.isValid) return false
|
||||
val compoundStatement = PsiTreeUtil.getParentOfType(el, PyStatementListContainer::class.java)
|
||||
if (compoundStatement != null) {
|
||||
if (compoundStatement != null && compoundStatement !is PyTryPart) {
|
||||
return compoundStatement.statementList.statements.size != 0
|
||||
}
|
||||
if (el.parent == null) return false
|
||||
val topLevel = PyPsiUtils.getParentRightBefore(el, el.containingFile)
|
||||
return topLevel != null && !PsiTreeUtil.hasErrorElements(topLevel)
|
||||
}
|
||||
|
||||
@@ -121,6 +121,57 @@ class PyConsoleEnterHandlerTest : PyTestCase() {
|
||||
assertTrue(push(""))
|
||||
}
|
||||
|
||||
fun testTryExcept() {
|
||||
assertFalse(push("try:"))
|
||||
assertFalse(push(""))
|
||||
assertFalse(push(""))
|
||||
assertFalse(push("\ta = 1"))
|
||||
assertFalse(push(""))
|
||||
assertFalse(push(""))
|
||||
assertFalse(push("except:"))
|
||||
assertFalse(push(""))
|
||||
assertFalse(push(""))
|
||||
assertFalse(push("\tprint('hi!')"))
|
||||
assertTrue(push(""))
|
||||
}
|
||||
|
||||
fun testBackSlash() {
|
||||
assertFalse(push("if True and \\"))
|
||||
assertFalse(push("\tTrue:"))
|
||||
assertFalse(push("\ta = 1"))
|
||||
assertTrue(push(""))
|
||||
}
|
||||
|
||||
fun testMultipleBackSlash() {
|
||||
assertFalse(push("if\\"))
|
||||
assertFalse(push("\tTrue\\"))
|
||||
assertFalse(push("\t:\\"))
|
||||
assertFalse(push(""))
|
||||
assertFalse(push("\ta = \\"))
|
||||
assertFalse(push("\t1"))
|
||||
assertTrue(push(""))
|
||||
}
|
||||
|
||||
fun testDocstringDouble() {
|
||||
assertFalse(push("a = \"\"\"test"))
|
||||
assertFalse(push("second"))
|
||||
assertTrue(push("third\"\"\""))
|
||||
}
|
||||
|
||||
fun testDocstring() {
|
||||
assertFalse(push("a = '''test"))
|
||||
assertFalse(push("second"))
|
||||
assertTrue(push("third'''"))
|
||||
}
|
||||
|
||||
fun testFunction() {
|
||||
assertFalse(push("def foo():"))
|
||||
assertFalse(push(""))
|
||||
assertFalse(push("\ta = 1"))
|
||||
assertFalse(push("\treturn 'hi!'"))
|
||||
assertTrue(push(""))
|
||||
}
|
||||
|
||||
override fun tearDown() {
|
||||
Disposer.dispose(testRootDisposable)
|
||||
super.tearDown()
|
||||
|
||||
Reference in New Issue
Block a user