Search in sources :

Example 6 with PyAssignmentStatement

use of com.jetbrains.python.psi.PyAssignmentStatement in project intellij-community by JetBrains.

the class PyAssignmentMappingTest method testSubscribedTarget.

public void testSubscribedTarget() throws Exception {
    Map<String, PsiElement> marks = loadTest();
    Assert.assertEquals(2, marks.size());
    // const -> expr;
    PsiElement src = marks.get("<src>").getParent();
    // ident -> target expr
    PsiElement dst = marks.get("<dst>").getParent().getParent();
    Assert.assertTrue(dst instanceof PySubscriptionExpression);
    PyAssignmentStatement stmt = (PyAssignmentStatement) src.getParent();
    List<Pair<PyExpression, PyExpression>> mapping = stmt.getTargetsToValuesMapping();
    Assert.assertEquals(1, mapping.size());
    Pair<PyExpression, PyExpression> pair = mapping.get(0);
    Assert.assertEquals(dst, pair.getFirst());
    Assert.assertEquals(src, pair.getSecond());
}
Also used : PyExpression(com.jetbrains.python.psi.PyExpression) PySubscriptionExpression(com.jetbrains.python.psi.PySubscriptionExpression) PyAssignmentStatement(com.jetbrains.python.psi.PyAssignmentStatement) PsiElement(com.intellij.psi.PsiElement) Pair(com.intellij.openapi.util.Pair)

Example 7 with PyAssignmentStatement

use of com.jetbrains.python.psi.PyAssignmentStatement in project intellij-community by JetBrains.

the class PyAssignmentMappingTest method testSimple.

public void testSimple() throws Exception {
    Map<String, PsiElement> marks = loadTest();
    Assert.assertEquals(2, marks.size());
    // const -> expr;
    PsiElement src = marks.get("<src>").getParent();
    // ident -> target expr
    PsiElement dst = marks.get("<dst>").getParent();
    Assert.assertTrue(dst instanceof PyTargetExpression);
    PyAssignmentStatement stmt = (PyAssignmentStatement) dst.getParent();
    List<Pair<PyExpression, PyExpression>> mapping = stmt.getTargetsToValuesMapping();
    Assert.assertEquals(1, mapping.size());
    Pair<PyExpression, PyExpression> pair = mapping.get(0);
    Assert.assertEquals(dst, pair.getFirst());
    Assert.assertEquals(src, pair.getSecond());
}
Also used : PyTargetExpression(com.jetbrains.python.psi.PyTargetExpression) PyExpression(com.jetbrains.python.psi.PyExpression) PyAssignmentStatement(com.jetbrains.python.psi.PyAssignmentStatement) PsiElement(com.intellij.psi.PsiElement) Pair(com.intellij.openapi.util.Pair)

Example 8 with PyAssignmentStatement

use of com.jetbrains.python.psi.PyAssignmentStatement in project intellij-community by JetBrains.

the class PyAssignmentMappingTest method testMultiple.

public void testMultiple() throws Exception {
    Map<String, PsiElement> marks = loadTest();
    final int TARGET_NUM = 3;
    Assert.assertEquals(TARGET_NUM + 1, marks.size());
    // const -> expr;
    PsiElement src = marks.get("<src>").getParent();
    PsiElement[] dsts = new PsiElement[TARGET_NUM];
    for (int i = 0; i < TARGET_NUM; i += 1) {
        // ident -> target expr
        PsiElement dst = marks.get("<dst" + String.valueOf(i + 1) + ">").getParent();
        Assert.assertTrue(dst instanceof PyTargetExpression);
        dsts[i] = dst;
    }
    PyAssignmentStatement stmt = (PyAssignmentStatement) src.getParent();
    List<Pair<PyExpression, PyExpression>> mapping = stmt.getTargetsToValuesMapping();
    Assert.assertEquals(TARGET_NUM, mapping.size());
    for (int i = 0; i < TARGET_NUM; i += 1) {
        Pair<PyExpression, PyExpression> pair = mapping.get(i);
        Assert.assertEquals(dsts[i], pair.getFirst());
        Assert.assertEquals(src, pair.getSecond());
    }
}
Also used : PyTargetExpression(com.jetbrains.python.psi.PyTargetExpression) PyExpression(com.jetbrains.python.psi.PyExpression) PyAssignmentStatement(com.jetbrains.python.psi.PyAssignmentStatement) PsiElement(com.intellij.psi.PsiElement) Pair(com.intellij.openapi.util.Pair)

Aggregations

Pair (com.intellij.openapi.util.Pair)8 PsiElement (com.intellij.psi.PsiElement)8 PyAssignmentStatement (com.jetbrains.python.psi.PyAssignmentStatement)8 PyExpression (com.jetbrains.python.psi.PyExpression)8 PyTargetExpression (com.jetbrains.python.psi.PyTargetExpression)6 PySubscriptionExpression (com.jetbrains.python.psi.PySubscriptionExpression)1