use of com.jetbrains.python.psi.PyExpression in project intellij-community by JetBrains.
the class Py3TypeTest method doTest.
private void doTest(final String expectedType, final String text) {
myFixture.configureByText(PythonFileType.INSTANCE, text);
final PyExpression expr = myFixture.findElementByText("expr", PyExpression.class);
final Project project = expr.getProject();
final PsiFile containingFile = expr.getContainingFile();
assertType(expectedType, expr, TypeEvalContext.codeAnalysis(project, containingFile));
assertType(expectedType, expr, TypeEvalContext.userInitiated(project, containingFile));
}
use of com.jetbrains.python.psi.PyExpression in project intellij-community by JetBrains.
the class PyAssignmentMappingTest method testTupleMapped.
public void testTupleMapped() throws Exception {
Map<String, PsiElement> marks = loadTest();
final int PAIR_NUM = 2;
Assert.assertEquals(PAIR_NUM * 2, marks.size());
PsiElement[] srcs = new PsiElement[PAIR_NUM];
PsiElement[] dsts = new PsiElement[PAIR_NUM];
for (int i = 0; i < PAIR_NUM; i += 1) {
// ident -> target expr
PsiElement dst = marks.get("<dst" + String.valueOf(i + 1) + ">").getParent();
Assert.assertTrue(dst instanceof PyTargetExpression);
dsts[i] = dst;
// ident -> target expr
PsiElement src = marks.get("<src" + String.valueOf(i + 1) + ">").getParent();
Assert.assertTrue(src instanceof PyExpression);
srcs[i] = src;
}
// tuple expr -> assignment
PyAssignmentStatement stmt = (PyAssignmentStatement) srcs[0].getParent().getParent();
List<Pair<PyExpression, PyExpression>> mapping = stmt.getTargetsToValuesMapping();
Assert.assertEquals(PAIR_NUM, mapping.size());
for (int i = 0; i < PAIR_NUM; i += 1) {
Pair<PyExpression, PyExpression> pair = mapping.get(i);
Assert.assertEquals(dsts[i], pair.getFirst());
Assert.assertEquals(srcs[i], pair.getSecond());
}
}
use of com.jetbrains.python.psi.PyExpression in project intellij-community by JetBrains.
the class PyAssignmentMappingTest method testTuplePack.
public void testTuplePack() throws Exception {
Map<String, PsiElement> marks = loadTest();
final int SRC_NUM = 2;
Assert.assertEquals(SRC_NUM + 1, marks.size());
PsiElement[] srcs = new PsiElement[SRC_NUM];
for (int i = 0; i < SRC_NUM; i += 1) {
// ident -> target expr
PsiElement src = marks.get("<src" + String.valueOf(i + 1) + ">").getParent();
Assert.assertTrue(src instanceof PyExpression);
srcs[i] = src;
}
// ident -> target expr
PsiElement dst = marks.get("<dst>").getParent();
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());
for (PsiElement src : srcs) {
// numeric expr -> tuple
Assert.assertEquals(src.getParent(), pair.getSecond());
}
}
use of com.jetbrains.python.psi.PyExpression in project intellij-community by JetBrains.
the class PyAssignmentMappingTest method testParenthesizedTuple.
public void testParenthesizedTuple() throws Exception {
//PY-2648
Map<String, PsiElement> marks = loadTest();
final int PAIR_NUM = 2;
Assert.assertEquals(PAIR_NUM * 2, marks.size());
PsiElement[] srcs = new PsiElement[PAIR_NUM];
PsiElement[] dsts = new PsiElement[PAIR_NUM];
for (int i = 0; i < PAIR_NUM; i += 1) {
// ident -> target expr
PsiElement dst = marks.get("<dst" + String.valueOf(i + 1) + ">").getParent();
Assert.assertTrue(dst instanceof PyTargetExpression);
dsts[i] = dst;
// ident -> target expr
PsiElement src = marks.get("<src" + String.valueOf(i + 1) + ">").getParent();
Assert.assertTrue(src instanceof PyExpression);
srcs[i] = src;
}
// tuple expr -> assignment
PyAssignmentStatement stmt = (PyAssignmentStatement) srcs[0].getParent().getParent().getParent();
List<Pair<PyExpression, PyExpression>> mapping = stmt.getTargetsToValuesMapping();
Assert.assertEquals(PAIR_NUM, mapping.size());
for (int i = 0; i < PAIR_NUM; i += 1) {
Pair<PyExpression, PyExpression> pair = mapping.get(i);
Assert.assertEquals(dsts[i], pair.getFirst());
Assert.assertEquals(srcs[i], pair.getSecond());
}
}
use of com.jetbrains.python.psi.PyExpression in project intellij-community by JetBrains.
the class PyAssignmentMappingTest method testTupleUnpack.
public void testTupleUnpack() throws Exception {
Map<String, PsiElement> marks = loadTest();
final int DST_NUM = 2;
Assert.assertEquals(DST_NUM + 3, marks.size());
PsiElement[] dsts = new PsiElement[DST_NUM];
for (int i = 0; i < DST_NUM; i += 1) {
// ident -> target expr
PsiElement dst = marks.get("<dst" + String.valueOf(i + 1) + ">").getParent();
Assert.assertTrue(dst instanceof PyTargetExpression);
dsts[i] = dst;
}
PsiElement[] srcs = new PsiElement[DST_NUM];
for (int i = 0; i < DST_NUM; i += 1) {
// ident -> target expr
PsiElement src = marks.get("<src" + String.valueOf(i + 1) + ">").getParent().getParent().getParent();
Assert.assertTrue(src instanceof PyExpression);
srcs[i] = src;
}
// ident -> target expr
PsiElement src = marks.get("<src>").getParent();
PyAssignmentStatement stmt = (PyAssignmentStatement) src.getParent().getParent();
List<Pair<PyExpression, PyExpression>> mapping = stmt.getTargetsToValuesMapping();
Assert.assertEquals(DST_NUM, mapping.size());
for (int i = 0; i < DST_NUM; i += 1) {
Pair<PyExpression, PyExpression> pair = mapping.get(i);
Assert.assertEquals(dsts[i], pair.getFirst());
Assert.assertEquals(srcs[i].getText(), pair.getSecond().getText());
}
}
Aggregations