use of org.python.pydev.shared_core.string.ICoreTextSelection in project Pydev by fabioz.
the class PyCreateMethodTest method testPyCreateMethodGlobalParams.
public void testPyCreateMethodGlobalParams() {
PyCreateMethodOrField pyCreateMethod = new PyCreateMethodOrField();
String source = "MyMethod(a, b())";
IDocument document = new Document(source);
ICoreTextSelection selection = new CoreTextSelection(document, 0, 0);
RefactoringInfo info = new RefactoringInfo(document, selection, PY_27_ONLY_GRAMMAR_VERSION_PROVIDER);
pyCreateMethod.execute(info, AbstractPyCreateAction.LOCATION_STRATEGY_BEFORE_CURRENT);
assertContentsEqual("" + "def MyMethod(${a}, ${b}):\n" + " ${pass}${cursor}\n" + "\n" + "\n" + "MyMethod(a, b())" + "", document.get());
}
use of org.python.pydev.shared_core.string.ICoreTextSelection in project Pydev by fabioz.
the class PyCreateMethodTest method testPyCreateMethodInClass.
public void testPyCreateMethodInClass() {
PyCreateMethodOrField pyCreateMethod = new PyCreateMethodOrField();
String source = "" + "class A(object):\n" + " '''comment'''\n" + "\n" + "A.MyMethod(a, b())";
IDocument document = new Document(source);
ICoreTextSelection selection = new CoreTextSelection(document, document.getLength() - "hod(a, b())".length(), 0);
RefactoringInfo info = new RefactoringInfo(document, selection, PY_27_ONLY_GRAMMAR_VERSION_PROVIDER);
pyCreateMethod.setCreateInClass("A");
pyCreateMethod.setCreateAs(PyCreateMethodOrField.CLASSMETHOD);
pyCreateMethod.execute(info, AbstractPyCreateAction.LOCATION_STRATEGY_END);
assertContentsEqual("" + "" + "class A(object):\n" + " '''comment'''\n" + "\n" + " \n" + " @classmethod\n" + " def MyMethod(cls, ${a}, ${b}):\n" + " ${pass}${cursor}\n" + " \n" + " \n" + "\n" + "A.MyMethod(a, b())" + "", document.get());
}
use of org.python.pydev.shared_core.string.ICoreTextSelection in project Pydev by fabioz.
the class PyCreateMethodTest method testPyCreateMethodWithTabs.
public void testPyCreateMethodWithTabs() {
PyCreateMethodOrField pyCreateMethod = new PyCreateMethodOrField();
String source = "" + "class A(object):\n" + "\n" + "\n" + "\n" + "\tdef m1(self):\n" + "\t\tself.m2()";
IDocument document = new Document(source);
ICoreTextSelection selection = new CoreTextSelection(document, document.getLength() - "2()".length(), 0);
RefactoringInfo info = new RefactoringInfo(document, selection, PY_27_ONLY_GRAMMAR_VERSION_PROVIDER);
pyCreateMethod.setCreateInClass("A");
pyCreateMethod.setCreateAs(PyCreateMethodOrField.BOUND_METHOD);
pyCreateMethod.execute(info, AbstractPyCreateAction.LOCATION_STRATEGY_BEFORE_CURRENT);
String expected = "" + "class A(object):\n" + "\n" + "\n" + "\n" + "\tdef m2(self):\n" + "\t\t${pass}${cursor}\n" + "\t\n" + "\t\n" + "\tdef m1(self):\n" + "\t\tself.m2()";
assertContentsEqual(expected, document.get());
}
use of org.python.pydev.shared_core.string.ICoreTextSelection in project Pydev by fabioz.
the class PyCreateMethodTest method testPyCreateMethod.
public void testPyCreateMethod() {
PyCreateMethodOrField pyCreateMethod = new PyCreateMethodOrField();
String source = "" + "class A(object):\n" + "\n" + "\n" + "\n" + " def m1(self):\n" + " self.m2()";
IDocument document = new Document(source);
ICoreTextSelection selection = new CoreTextSelection(document, document.getLength() - "2()".length(), 0);
RefactoringInfo info = new RefactoringInfo(document, selection, PY_27_ONLY_GRAMMAR_VERSION_PROVIDER);
pyCreateMethod.setCreateInClass("A");
pyCreateMethod.setCreateAs(PyCreateMethodOrField.BOUND_METHOD);
pyCreateMethod.execute(info, AbstractPyCreateAction.LOCATION_STRATEGY_BEFORE_CURRENT);
String expected = "" + "class A(object):\n" + "\n" + "\n" + "\n" + " def m2(self):\n" + " ${pass}${cursor}\n" + " \n" + " \n" + " def m1(self):\n" + " self.m2()";
assertContentsEqual(expected, document.get());
}
use of org.python.pydev.shared_core.string.ICoreTextSelection in project Pydev by fabioz.
the class PyCreateClassTest method testPyCreateClassInSameModule5.
public void testPyCreateClassInSameModule5() throws Exception {
PyCreateClass pyCreateClass = new PyCreateClass();
String source = "" + "a = 10\n" + "#=============\n" + "#Comment\n" + "#=============\n" + "class Existing(object):\n" + " pass\n" + "\n" + "MyClass()";
IDocument document = new Document(source);
ICoreTextSelection selection = new CoreTextSelection(document, document.getLength() - 5, 0);
RefactoringInfo info = new RefactoringInfo(document, selection, PY_27_ONLY_GRAMMAR_VERSION_PROVIDER);
pyCreateClass.execute(info, PyCreateClass.LOCATION_STRATEGY_BEFORE_CURRENT);
assertContentsEqual("" + "a = 10\n" + "#=============\n" + "#Comment\n" + "#=============\n" + "class Existing(object):\n" + " pass\n" + "\n" + "\n" + "class MyClass(${object}):\n" + " ${pass}${cursor}\n" + "\n" + "\n" + "MyClass()" + "", document.get());
}
Aggregations