[Pydev-cvs] org.python.pydev/tests/org/python/pydev/editor/actions PyFormatStdTest.java, 1.12, 1.13
Brought to you by:
fabioz
From: Fabio Z. <fa...@us...> - 2008-07-19 19:53:24
|
Update of /cvsroot/pydev/org.python.pydev/tests/org/python/pydev/editor/actions In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv28692/tests/org/python/pydev/editor/actions Modified Files: PyFormatStdTest.java Log Message: - Improved code formatter to deal with operators (+, -, *, etc) - Improved code formatter to handle '=' differently inside function calls / keyword args Index: PyFormatStdTest.java =================================================================== RCS file: /cvsroot/pydev/org.python.pydev/tests/org/python/pydev/editor/actions/PyFormatStdTest.java,v retrieving revision 1.12 retrieving revision 1.13 diff -C2 -d -r1.12 -r1.13 *** PyFormatStdTest.java 19 Jul 2008 11:57:58 -0000 1.12 --- PyFormatStdTest.java 19 Jul 2008 19:53:31 -0000 1.13 *************** *** 17,20 **** --- 17,22 ---- private FormatStd std; + + private static boolean DEBUG = false; public static void main(String[] args) { *************** *** 22,26 **** PyFormatStdTest n = new PyFormatStdTest(); n.setUp(); ! n.testFormatNotLinesOnlyWithParentesis(); n.tearDown(); --- 24,29 ---- PyFormatStdTest n = new PyFormatStdTest(); n.setUp(); ! // DEBUG = true; ! n.testDontDisturbWildImport(); n.tearDown(); *************** *** 39,42 **** --- 42,103 ---- super.setUp(); std = new PyFormatStd.FormatStd(); + std.operatorsWithSpace = true; + } + + public void testNoCloseList(){ + + std.operatorsWithSpace = true; + std.assignWithSpaceInsideParens = true; + std.spaceAfterComma = true; + std.parametersWithSpace = false; + + String s = ""+ + "constants = [\n"+ + " (qt.Qt.Key_Escape, ''), \n"+ + " (qt.Qt.Key_Tab, '\t'), \n"+ + "\n"; + + String s1 = ""+ + "constants = [\n"+ + " (qt.Qt.Key_Escape, ''),\n"+ + " (qt.Qt.Key_Tab, '\t'),\n"+ + "\n"; + + checkFormatResults(s, s1); + } + + public void testDontDisturbWildImport(){ + std.operatorsWithSpace = true; + std.assignWithSpaceInsideParens = true; + std.spaceAfterComma = true; + std.parametersWithSpace = false; + + checkFormatResults("from x import *\n\n"); + } + + public void testDontDisturbWildImport2(){ + std.operatorsWithSpace = true; + std.assignWithSpaceInsideParens = true; + std.spaceAfterComma = true; + std.parametersWithSpace = false; + + checkFormatResults("import *"); + } + + public void testDontDisturbVarArgsAndKwArgs(){ + std.operatorsWithSpace = true; + std.assignWithSpaceInsideParens = true; + std.spaceAfterComma = true; + std.parametersWithSpace = false; + + String s = ""+ + "def a( a,b, *args, **kwargs ):\n"+ + " call( *args, **kwargs)\n"; + + String s1 = ""+ + "def a(a, b, *args, **kwargs):\n"+ + " call(*args, **kwargs)\n"; + + checkFormatResults(s, s1); } *************** *** 164,167 **** --- 225,229 ---- std.spaceAfterComma = true; std.parametersWithSpace = false; + std.operatorsWithSpace = true; String s = ""+ *************** *** 171,175 **** String s1 = ""+ "def a(a, b):\n"+ ! " return ((a+b) + (a+b)) \n"; checkFormatResults(s, s1); --- 233,237 ---- String s1 = ""+ "def a(a, b):\n"+ ! " return ((a + b) + (a + b)) \n"; checkFormatResults(s, s1); *************** *** 179,183 **** String s2 = ""+ "def a( a, b ):\n"+ ! " return ( ( a+b ) + ( a+b ) ) \n"; checkFormatResults(s, s2); --- 241,245 ---- String s2 = ""+ "def a( a, b ):\n"+ ! " return ( ( a + b ) + ( a + b ) ) \n"; checkFormatResults(s, s2); *************** *** 187,190 **** --- 249,253 ---- std.spaceAfterComma = true; std.parametersWithSpace = true; + std.operatorsWithSpace = false; String s = ""+ *************** *** 194,198 **** String s1 = ""+ "def a( a, b ):\n"+ ! " return ( callA() + callB( b+b ) ) \n"; checkFormatResults(s, s1); --- 257,261 ---- String s1 = ""+ "def a( a, b ):\n"+ ! " return ( callA()+callB( b+b ) ) \n"; checkFormatResults(s, s1); *************** *** 249,252 **** --- 312,316 ---- std.spaceAfterComma = true; std.parametersWithSpace = true; + std.operatorsWithSpace = true; String s = ""+ *************** *** 260,264 **** "nothing 'changes() ((aa) )\n"+ "'''\n" + ! "thisChanges( a+b + ( a+b ) )"; checkFormatResults(s, s2); --- 324,328 ---- "nothing 'changes() ((aa) )\n"+ "'''\n" + ! "thisChanges( a + b + ( a + b ) )"; checkFormatResults(s, s2); *************** *** 332,339 **** "methodCall(a,b,c))\n"; - checkFormatResults(s, "methodCall(a, b, c))\n"); } /** --- 396,569 ---- "methodCall(a,b,c))\n"; checkFormatResults(s, "methodCall(a, b, c))\n"); } + public void testOperators(){ + std.spaceAfterComma = true; + std.parametersWithSpace = false; + std.operatorsWithSpace = true; + + String s = "" + + "i=i+1\n" + + "submitted +=1\n" + + "x = x*2 - 1\n" + + "hypot2 = x*x + y*y\n" + + "c = (a+b) * (a-b)\n" + + ""; + + String s1 = "" + + "i = i + 1\n" + + "submitted += 1\n" + + "x = x * 2 - 1\n" + + "hypot2 = x * x + y * y\n" + + "c = (a + b) * (a - b)\n" + + ""; + + checkFormatResults(s, s1); + + } + + + public void testEqualsWithSpaceInFunctionCall(){ + std.spaceAfterComma = true; + std.parametersWithSpace = false; + std.assignWithSpaceInsideParens = true; + std.operatorsWithSpace = true; + + + + String s = "" + + "a(xxx=10)\n" + + "call(yyy = 20)\n"; + + String s1 = "" + + "a(xxx = 10)\n" + + "call(yyy = 20)\n"; + + checkFormatResults(s, s1); + + s1 = "" + + "a(xxx = 10)\n" + + "call(yyy = 20)\n"; + checkFormatResults(StringUtils.replaceAll(s, "=", "!="), StringUtils.replaceAll(s1, "=", "!=")); + checkFormatResults(StringUtils.replaceAll(s, "=", "<="), StringUtils.replaceAll(s1, "=", "<=")); + + std.assignWithSpaceInsideParens = false; + s1 = "" + + "a(xxx=10)\n" + + "call(yyy=20)\n"; + + checkFormatResults(s, s1); + + s1 = "" + + "a(xxx = 10)\n" + + "call(yyy = 20)\n"; + checkFormatResults(StringUtils.replaceAll(s, "=", "!="), StringUtils.replaceAll(s1, "=", "!=")); + checkFormatResults(StringUtils.replaceAll(s, "=", "<="), StringUtils.replaceAll(s1, "=", "<=")); + } + + public void testNotValidCode(){ + //should not crash in these tests + std.spaceAfterComma = true; + std.parametersWithSpace = false; + std.operatorsWithSpace = false; + + checkFormatResults("=", "="); + checkFormatResults("==", "=="); + checkFormatResults("!", "!"); + checkFormatResults("!=", "!="); + } + + public void testCompare(){ + std.spaceAfterComma = true; + std.parametersWithSpace = false; + std.operatorsWithSpace = true; + + String s = "" + + "a==10\n" + + "b== 20\n" + + "c = 30\n" + + "d ==+1\n" + + "e !=+1\n" + + "e //=+1\n" + + ""; + + String s1 = "" + + "a == 10\n" + + "b == 20\n" + + "c = 30\n" + + "d == + 1\n" + + "e != + 1\n" + + "e //= + 1\n" + + ""; + + checkFormatResults(s, s1); + } + + + public void testEqualsWithSpace(){ + std.spaceAfterComma = true; + std.parametersWithSpace = false; + std.operatorsWithSpace = true; + + + String s = "" + + "a=10\n" + + "b= 20\n" + + "c = 30"; + + String s1 = "" + + "a = 10\n" + + "b = 20\n" + + "c = 30"; + + checkFormatResults(s, s1); + checkFormatResults(StringUtils.replaceAll(s, "=", "!="), StringUtils.replaceAll(s1, "=", "!=")); + checkFormatResults(StringUtils.replaceAll(s, "=", "<="), StringUtils.replaceAll(s1, "=", "<=")); + + s = "" + + "a=\\n10\n" + + "b= 20\n" + + "c = 30"; + + s1 = "" + + "a = \\n10\n" + + "b = 20\n" + + "c = 30"; + + checkFormatResults(s, s1); + checkFormatResults(StringUtils.replaceAll(s, "=", "!="), StringUtils.replaceAll(s1, "=", "!=")); + checkFormatResults(StringUtils.replaceAll(s, "=", "<="), StringUtils.replaceAll(s1, "=", "<=")); + + s = "" + + "a=10\n" + + "b= 20\n" + + "c = 30"; + + s1 = "" + + "a=10\n" + + "b=20\n" + + "c=30"; + + std.operatorsWithSpace = false; + checkFormatResults(s, s1); + checkFormatResults(StringUtils.replaceAll(s, "=", ">="), StringUtils.replaceAll(s1, "=", ">=")); + checkFormatResults(StringUtils.replaceAll(s, "=", "+="), StringUtils.replaceAll(s1, "=", "+=")); + + s = "" + + "a=\\n" + + "10\n" + + "b= 20\n" + + "c = 30"; + + s1 = "" + + "a=\\n" + + "10\n" + + "b=20\n" + + "c=30"; + + checkFormatResults(s, s1); + } + /** *************** *** 356,359 **** --- 586,594 ---- //default check (defined with \n) String formatStr = new PyFormatStd().formatStr(s, std); + + if(DEBUG){ + System.out.println(">>"+s+"<<"); + System.out.println(">>"+formatStr+"<<"); + } assertEquals(expected, formatStr); |