📄 prettyprintertest.java
字号:
}
public void testExec() throws Exception {
String s = "exec cmd in globals,locals\n"+
"";
checkPrettyPrintEqual(s);
}
public void testTryExcept8() throws Exception {
String s = ""+
"try:\n" +
" try:\n" +
" pass\n" +
" except BdbQuit:\n" +
" pass\n" +
"finally:\n" +
" self.quitting = 1\n" +
" sys.settrace(None)\n" +
"";
checkPrettyPrintEqual(s);
}
public void testDecorator() throws Exception {
String s = ""+
"@decorator1\n" +
"def m1():\n" +
" pass\n" +
"";
checkPrettyPrintEqual(s);
}
public void testDecorator3() throws Exception {
String s = ""+
"@decorator1\n" +
"@decorator2\n" +
"def m1():\n" +
" pass\n" +
"";
checkPrettyPrintEqual(s);
}
public void testDecorator2() throws Exception {
String s = ""+
"@decorator1(1,*args,**kwargs)\n" +
"def m1():\n" +
" pass\n" +
"";
checkPrettyPrintEqual(s);
}
public void testComment() throws Exception {
String s = ""+
"# comment1\n" +
"# comment2\n" +
"# comment3\n" +
"# comment4\n" +
"'''str'''\n" +
"";
checkPrettyPrintEqual(s);
}
public void testStarArgs() throws Exception {
String s = ""+
"def recv(self,*args):\n" +
" pass\n" +
"";
checkPrettyPrintEqual(s);
}
public void testListComp() throws Exception {
String s = ""+
"print [x for x in tbinfo]\n" +
"";
checkPrettyPrintEqual(s);
}
public void testSub() throws Exception {
String s = ""+
"print tbinfo[-1]\n" +
"";
checkPrettyPrintEqual(s);
}
public void testDel() throws Exception {
String s = ""+
"del foo\n" +
"";
checkPrettyPrintEqual(s);
}
public void testPar2() throws Exception {
String s = ""+
"def log(self,message):\n" +
" sys.stderr.write('log: %s' % str(message))\n" +
"";
checkPrettyPrintEqual(s);
}
public void testPar() throws Exception {
String s = ""+
"print (not connected)\n" +
"";
checkPrettyPrintEqual(s);
}
public void testSimpleFunc() throws Exception {
String s = ""+
"def a():\n" +
" pass\n" +
"";
checkPrettyPrintEqual(s);
}
public void testReturn2() throws Exception {
String s = ""+
"def writable():\n" +
" return (not connected) or len(foo)\n" +
"";
checkPrettyPrintEqual(s);
}
public void testSubs() throws Exception {
String s = ""+
"print num_sent[:512]\n" +
"";
checkPrettyPrintEqual(s);
}
public void testNot() throws Exception {
String s = ""+
"def recv(self,buffer_size):\n" +
" data = self.socket.recv(buffer_size)\n" +
" if not data:\n" +
" pass\n" +
"";
checkPrettyPrintEqual(s);
}
public void testIfAnd() throws Exception {
String s = ""+
"if aaa and bbb:\n" +
" pass\n" +
"";
checkPrettyPrintEqual(s);
}
public void testAnd() throws Exception {
String s = ""+
"def listen(self,num):\n" +
" self.accepting = True\n" +
" if os.name == 'nt' and num > 5:\n" +
" num = 1\n" +
" return self.socket.listen(num)\n" +
"";
checkPrettyPrintEqual(s);
}
public void testTryExcept7() throws Exception {
String s = ""+
"try:\n" +
" pass\n" +
"except select.error,err:\n" +
" if False:\n" +
" raise \n" +
" else:\n" +
" return \n" +
"";
checkPrettyPrintEqual(s);
}
public void testIf4() throws Exception {
String s = ""+
"if map:\n" +
" if True:\n" +
" time.sleep(timeout)\n" +
" else:\n" +
" pass\n" +
"";
checkPrettyPrintEqual(s);
}
public void testIf3() throws Exception {
String s = ""+
"if aaa or bbb:\n" +
" pass\n" +
"";
checkPrettyPrintEqual(s);
}
public void testEq() throws Exception {
String s = ""+
"if [] == r == w == e:\n" +
" time.sleep(timeout)\n" +
"";
checkPrettyPrintEqual(s);
}
public void testImportAs() throws Exception {
String s = ""+
"import foo as bla\n" +
"";
checkPrettyPrintEqual(s);
}
public void testImportAs2() throws Exception {
String s = ""+
"from a import foo as bla\n" +
"";
checkPrettyPrintEqual(s);
}
public void testIf2() throws Exception {
String s = ""+
"def readwrite():\n" +
" if True:\n" +
" a.b()\n" +
" if False:\n" +
" pass\n" +
"";
checkPrettyPrintEqual(s);
}
public void testBreak() throws Exception {
String s = ""+
"for a in b:\n" +
" if True:\n" +
" break\n" +
"";
checkPrettyPrintEqual(s);
}
public void testContinue() throws Exception {
String s = ""+
"for a in b:\n" +
" if True:\n" +
" continue\n" +
"";
checkPrettyPrintEqual(s);
}
public void testBreak2() throws Exception {
String s = ""+
"for a in b:\n" +
" if True:\n" +
" break#comment\n" +
"";
checkPrettyPrintEqual(s);
}
public void testBreak3() throws Exception {
String s = ""+
"for a in b:\n" +
" if True:\n" +
" #comment1\n" +
" break#comment2\n" +
"";
checkPrettyPrintEqual(s);
}
public void testReturn() throws Exception {
String s = ""+
"def a():\n" +
" return 0\n" +
"";
checkPrettyPrintEqual(s);
}
public void testImport2() throws Exception {
String s = ""+
"import foo.bla#comment\n" +
"";
checkPrettyPrintEqual(s);
}
public void testImport3() throws Exception {
String s = ""+
"from foo.bla import bla1#comment\n" +
"";
checkPrettyPrintEqual(s);
}
public void testImport4() throws Exception {
String s = ""+
"from foo.bla import bla1\n" +
"import foo\n" +
"from bla import (a,b,c)\n";
checkPrettyPrintEqual(s);
}
public void testFor() throws Exception {
String s = "" +
"for a in b:\n" +
" print a\n" +
"";
checkPrettyPrintEqual(s);
}
public void testForElse() throws Exception {
String s = "" +
"for a in b:\n" +
" print a\n" +
"else:\n" +
" pass\n" +
"";
checkPrettyPrintEqual(s);
}
public void testWhile() throws Exception {
String s = ""+
"while True:\n" +
" pass\n" +
"";
checkPrettyPrintEqual(s);
}
public void testWhile2() throws Exception {
String s = ""+
"while ((a + 1 < 0)):#comment\n" +
" pass\n" +
"";
checkPrettyPrintEqual(s);
}
public void testWhileElse() throws Exception {
String s = ""+
"while True:\n" +
" pass\n" +
"else:\n" +
" pass\n" +
"";
checkPrettyPrintEqual(s);
}
public void testTryExceptRaise() throws Exception {
String s = ""+
"try:\n" +
" print 'foo'\n" +
"except:\n" +
" raise \n" +
"";
checkPrettyPrintEqual(s);
}
public void testTryExcept() throws Exception {
String s = ""+
"try:\n" +
" print 'foo'\n" +
"except:\n" +
" pass\n" +
"";
checkPrettyPrintEqual(s);
}
public void testTryExcept2() throws Exception {
String s = ""+
"try:\n" +
" socket_map\n" +
"except NameError:\n" +
" socket_map = {}\n" +
"";
checkPrettyPrintEqual(s);
}
public void testTryExcept3() throws Exception {
String s = ""+
"try:\n" +
" print 'foo'\n" +
"except (NameError,e):\n" +
" print 'err'\n" +
"";
checkPrettyPrintEqual(s);
}
public void testTryExcept4() throws Exception {
String s = ""+
"try:\n" +
" print 'foo'\n" +
"except (NameError,e):\n" +
" print 'err'\n" +
"else:\n" +
" print 'else'\n" +
"";
checkPrettyPrintEqual(s);
}
public void testTryExcept5() throws Exception {
String s = ""+
"try:\n" +
" print 'foo'\n" +
"except (NameError,e):\n" +
" print 'name'\n" +
"except (TypeError,e2):\n" +
" print 'type'\n" +
"else:\n" +
" print 'else'\n" +
"";
checkPrettyPrintEqual(s);
}
public void testTryExcept6() throws Exception {
String s = ""+
"def read(obj):\n" +
" try:\n" +
" obj.handle_read_event()\n" +
" except:\n" +
" obj.handle_error()\n" +
"";
checkPrettyPrintEqual(s);
}
public void testCall() throws Exception {
String s = ""+
"callIt(1)\n" +
"";
checkPrettyPrintEqual(s);
}
public void testCall2() throws Exception {
String s = ""+
"callIt(1#param1\n" +
")\n" +
"";
checkPrettyPrintEqual(s);
}
public void testCall3() throws Exception {
String s = ""+
"callIt(a=2)\n" +
"";
checkPrettyPrintEqual(s);
}
public void testCall4() throws Exception {
String s = ""+
"callIt(a=2,*args,**kwargs)\n" +
"";
checkPrettyPrintEqual(s);
}
public void testCall5() throws Exception {
String s = ""+
"m1(a,#d1\n" +
" b,#d2\n" +
" c#d3\n" +
")\n" +
"";
checkPrettyPrintEqual(s);
}
public void testIf() throws Exception {
String s = ""+
"if i % target == 0:\n"+
" pass\n" +
"";
checkPrettyPrintEqual(s);
}
public void testIfElse() throws Exception {
String s = ""+
"if True:\n" +
" if foo:\n" +
" pass\n" +
" else:\n" +
" pass\n" +
"";
checkPrettyPrintEqual(s);
}
public void testListDict() throws Exception {
String s = ""+
"a = [1,#this is 1\n" +
" 2]\n" +
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -