Search in sources :

Example 6 with PyBlockEvaluator

use of com.jetbrains.python.psi.impl.blockEvaluator.PyBlockEvaluator in project intellij-community by JetBrains.

the class PyBlockEvaluatorTest method testFunction.

public void testFunction() {
    PyBlockEvaluator eval = new PyBlockEvaluator();
    PyFile file = (PyFile) PsiFileFactory.getInstance(myFixture.getProject()).createFileFromText("a.py", PythonFileType.INSTANCE, "def foo(): return 'a'");
    PyFunction foo = file.findTopLevelFunction("foo");
    eval.evaluate(foo);
    assertEquals("a", eval.getReturnValue());
}
Also used : PyFunction(com.jetbrains.python.psi.PyFunction) PyBlockEvaluator(com.jetbrains.python.psi.impl.blockEvaluator.PyBlockEvaluator) PyFile(com.jetbrains.python.psi.PyFile)

Example 7 with PyBlockEvaluator

use of com.jetbrains.python.psi.impl.blockEvaluator.PyBlockEvaluator in project intellij-community by JetBrains.

the class PyBlockEvaluatorTest method testDictNoEvaluate.

public void testDictNoEvaluate() {
    PyBlockEvaluator eval = doEvaluate("a={'b': 'c'}", true);
    Map map = (Map) eval.getValue("a");
    assertEquals(1, map.size());
    assertTrue(map.get("b") instanceof PyStringLiteralExpression);
}
Also used : PyStringLiteralExpression(com.jetbrains.python.psi.PyStringLiteralExpression) PyBlockEvaluator(com.jetbrains.python.psi.impl.blockEvaluator.PyBlockEvaluator) Map(java.util.Map)

Example 8 with PyBlockEvaluator

use of com.jetbrains.python.psi.impl.blockEvaluator.PyBlockEvaluator in project intellij-community by JetBrains.

the class PyBlockEvaluatorTest method testVar.

public void testVar() {
    PyBlockEvaluator eval = doEvaluate("a='b'\nc='d'\ne=a+c");
    assertEquals("bd", eval.getValue("e"));
}
Also used : PyBlockEvaluator(com.jetbrains.python.psi.impl.blockEvaluator.PyBlockEvaluator)

Example 9 with PyBlockEvaluator

use of com.jetbrains.python.psi.impl.blockEvaluator.PyBlockEvaluator in project intellij-community by JetBrains.

the class PyBlockEvaluatorTest method testAugAssign.

public void testAugAssign() {
    PyBlockEvaluator eval = doEvaluate("a='b'\na+='c'");
    assertEquals("bc", eval.getValue("a"));
}
Also used : PyBlockEvaluator(com.jetbrains.python.psi.impl.blockEvaluator.PyBlockEvaluator)

Example 10 with PyBlockEvaluator

use of com.jetbrains.python.psi.impl.blockEvaluator.PyBlockEvaluator in project intellij-community by JetBrains.

the class PyBlockEvaluatorTest method testDictUpdate.

public void testDictUpdate() {
    PyBlockEvaluator eval = doEvaluate("a={}\na.update({'b': 'c'})");
    Map map = (Map) eval.getValue("a");
    assertEquals(1, map.size());
    assertEquals("c", map.get("b"));
}
Also used : PyBlockEvaluator(com.jetbrains.python.psi.impl.blockEvaluator.PyBlockEvaluator) Map(java.util.Map)

Aggregations

PyBlockEvaluator (com.jetbrains.python.psi.impl.blockEvaluator.PyBlockEvaluator)13 Map (java.util.Map)5 PyFile (com.jetbrains.python.psi.PyFile)3 PyStringLiteralExpression (com.jetbrains.python.psi.PyStringLiteralExpression)2 PyFunction (com.jetbrains.python.psi.PyFunction)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1