use of org.python.pydev.parser.jython.ast.FunctionDef in project Pydev by fabioz.
the class FastDefinitionsParserTest method testDefinitionsParser20.
public void testDefinitionsParser20() {
Module m = (Module) FastDefinitionsParser.parse("def methodempty():\n" + " pass\n" + "\n" + "if a:\n" + " def method():\n" + " a = 10\n" + "else:\n" + " def method2():\n" + " bar = 10\n" + "");
assertEquals(3, m.body.length);
FunctionDef d = (FunctionDef) m.body[1];
assertEquals("method", NodeUtils.getRepresentationString(d.name));
assertNull(d.body);
d = (FunctionDef) m.body[2];
assertEquals("method2", NodeUtils.getRepresentationString(d.name));
assertNull(d.body);
}
use of org.python.pydev.parser.jython.ast.FunctionDef in project Pydev by fabioz.
the class FastDefinitionsParserTest method testMixSpacesAndTabs.
/**
* A tab must be counted as 8 spaces!
*/
public void testMixSpacesAndTabs() {
Module m = (Module) FastDefinitionsParser.parse("" + "def method():\n" + "\n" + "\tfor remainder in match_1.remainders:\n" + "\t a_2 = remainder.a\n" + " c_2 = remainder.c\n" + " match = a\n" + " if not match.isError():\n" + " return Match()\n" + " return Error(\"\")");
assertEquals(1, m.body.length);
assertEquals("method", NodeUtils.getRepresentationString(((FunctionDef) m.body[0]).name));
}
use of org.python.pydev.parser.jython.ast.FunctionDef in project Pydev by fabioz.
the class FastDefinitionsParserTest method testAttributes5.
public void testAttributes5() {
Module m = (Module) FastDefinitionsParser.parse("class Bar:\n" + " def m1(self):\n" + // local scope: get it because of self.
" self.ATTRIBUTE0 = 10\n" + // local scope: get it because of self.
" self.ATTRIBUTE1 = 10\n" + // local scope: get it because of self.
" self.ATTRIBUTE2 = = 10\n" + "\n" + "");
assertEquals(1, m.body.length);
ClassDef classDef = ((ClassDef) m.body[0]);
assertEquals("Bar", ((NameTok) classDef.name).id);
// method
assertEquals(1, classDef.body.length);
FunctionDef funcDef = (FunctionDef) classDef.body[0];
assertEquals("m1", ((NameTok) funcDef.name).id);
for (int i = 0; i < 3; i++) {
Assign assign = (Assign) funcDef.body[i];
assertEquals(1, assign.targets.length);
Attribute attribute = (Attribute) assign.targets[0];
NameTok attr = (NameTok) attribute.attr;
assertEquals("ATTRIBUTE" + i, attr.id.toString());
}
assertEquals(3, funcDef.body.length);
}
use of org.python.pydev.parser.jython.ast.FunctionDef in project Pydev by fabioz.
the class FastDefinitionsParserTest method testDefinitionsParser14.
public void testDefinitionsParser14() {
Module m = (Module) FastDefinitionsParser.parse("\n" + "def method():\n" + " a = 10\n" + "class F:\n" + " def method2(self):\n" + " self.bar = 10\n" + "def another():\n" + " b = 20\n" + "");
assertEquals(3, m.body.length);
FunctionDef d = (FunctionDef) m.body[0];
assertEquals("method", NodeUtils.getRepresentationString(d.name));
assertNull(d.body);
ClassDef cd = (ClassDef) m.body[1];
assertEquals("F", NodeUtils.getRepresentationString(cd.name));
assertEquals(1, cd.body.length);
d = (FunctionDef) m.body[2];
assertEquals("another", NodeUtils.getRepresentationString(d.name));
}
use of org.python.pydev.parser.jython.ast.FunctionDef in project Pydev by fabioz.
the class FastDefinitionsParserTest method testDefinitionsParser6.
public void testDefinitionsParser6() {
Module m = (Module) FastDefinitionsParser.parse("class Bar(object):\n" + " class Zoo(object):\n" + " def m1(self):pass\n" + "def m2(self):pass\n");
assertEquals(2, m.body.length);
ClassDef classDefBar = (ClassDef) m.body[0];
assertEquals(1, classDefBar.beginColumn);
assertEquals(1, classDefBar.beginLine);
assertEquals("Bar", ((NameTok) classDefBar.name).id);
ClassDef classDefZoo = (ClassDef) classDefBar.body[0];
assertEquals("Zoo", ((NameTok) classDefZoo.name).id);
assertEquals("m1", ((NameTok) ((FunctionDef) classDefZoo.body[0]).name).id);
assertEquals("m2", ((NameTok) ((FunctionDef) m.body[1]).name).id);
}
Aggregations