From 669cff70426447a479e15cc849ff47ef7b0d8854 Mon Sep 17 00:00:00 2001 From: "Ilya.Kazakevich" Date: Fri, 7 Feb 2014 17:38:54 +0400 Subject: [PATCH] Cython and Python parsers should never create functions with out of statements even if code is bad --- .../jetbrains/python/PythonParsingTest.java | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/python/testSrc/com/jetbrains/python/PythonParsingTest.java b/python/testSrc/com/jetbrains/python/PythonParsingTest.java index 82146a20f14e..f50257cfe0f1 100644 --- a/python/testSrc/com/jetbrains/python/PythonParsingTest.java +++ b/python/testSrc/com/jetbrains/python/PythonParsingTest.java @@ -16,10 +16,15 @@ package com.jetbrains.python; import com.intellij.psi.PsiFile; +import com.intellij.psi.util.PsiTreeUtil; import com.intellij.testFramework.ParsingTestCase; import com.intellij.testFramework.TestDataPath; import com.jetbrains.python.fixtures.PyTestCase; import com.jetbrains.python.psi.LanguageLevel; +import com.jetbrains.python.psi.PyFunction; +import org.jetbrains.annotations.NotNull; + +import java.util.Collection; /** * @author yole @@ -220,7 +225,7 @@ public class PythonParsingTest extends ParsingTestCase { } public void testTrailingSemicolon() { // PY-363 - doTest(); + doTest(); } public void testStarExpression() { // PEP-3132 @@ -322,7 +327,7 @@ public class PythonParsingTest extends ParsingTestCase { public void testIncompleteFor() { // PY-3792 doTest(); } - + public void testCallInAssignment() { // PY-5062 doTest(); } @@ -451,6 +456,7 @@ public class PythonParsingTest extends ParsingTestCase { finally { myLanguageLevel = prev; } + ensureEachFunctionHasStatementList(myFile, PyFunction.class); } @Override @@ -459,4 +465,13 @@ public class PythonParsingTest extends ParsingTestCase { file.getVirtualFile().putUserData(LanguageLevel.KEY, myLanguageLevel); return file; } + + public static void ensureEachFunctionHasStatementList( + @NotNull PsiFile parentFile, + @NotNull Class functionType) { + Collection functions = PsiTreeUtil.findChildrenOfType(parentFile, functionType); + for (T functionToCheck : functions) { + functionToCheck.getStatementList(); //To make sure each function has statement list (does not throw exception) + } + } }