[Pydev-cvs] org.python.pydev/doc/test PyConvertTabToSpaceTest.java,NONE,1.1 PyAddBlockCommentTest.ja
Brought to you by:
fabioz
From: Aleksandar T. <at...@us...> - 2004-07-02 02:50:46
|
Update of /cvsroot/pydev/org.python.pydev/doc/test In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv18059/doc/test Added Files: PyConvertTabToSpaceTest.java PyAddBlockCommentTest.java AllTests.java PyStripTrailingWhitespaceTest.java PyConvertSpaceToTabTest.java PyUncommentTest.java PyRemoveBlockCommentTest.java PyCommentTest.java Log Message: 3.0 port --- NEW FILE: PyConvertTabToSpaceTest.java --- /* * Created on Jun 21, 2004 * * To change the template for this generated file go to * Window>Preferences>Java>Code Generation>Code and Comments */ package test; import org.eclipse.jface.text.Document; import org.eclipse.jface.text.IDocument; import org.python.pydev.editor.actions.PyConvertTabToSpace; import org.python.pydev.editor.actions.PySelection; import org.python.pydev.editor.actions.PyStripTrailingWhitespace; import junit.framework.TestCase; /** * @author Dreamer * * Tests the 'Convert Tab to Space' editor feature. It performs 3 checks. * * The first fakes a selection of a couple lines in a fake document, and checks * to see that the proper tabs are converted to spaces. * * The second fakes a selection but stops in the middle of a line, to make sure that the * whole line is considered. * * The third selects nothing, and makes sure that the whole document is affected by * the conversion. */ public class PyConvertTabToSpaceTest extends TestCase { /* The document that will fake an editor environment */ IDocument document; /* Lines of 'code' in the fake document */ String [] documentLines; /* For my own debugging edification, to output the name later */ static final String TestFileName = "PyConvertTabToSpaceTest"; /** * Constructor for PyConvertTabToSpaceTest. * @param arg0 */ public PyConvertTabToSpaceTest(String arg0) { super(arg0); } /* * Sets up the document 'code' and adds it to the document. * * @see TestCase#setUp() */ protected void setUp() throws Exception { super.setUp(); int i = -1; int length = 7; documentLines = new String[length]; // The X will be used to interchange tabs/spaces documentLines[++i] = "def bar ( self ):"; documentLines[++i] = "X" + "print \"foo1\"X "; documentLines[++i] = "X" + "print \"bar1\""; documentLines[++i] = "X "; documentLines[++i] = "def foo ( self ):X"; documentLines[++i] = "X" + "print \"foo2\"X "; documentLines[++i] = "X" + "print \"bar2\" "; StringBuffer doc = new StringBuffer ( ); for ( i = 0; i < documentLines.length; i++ ) { doc.append ( documentLines[i] + ( i < documentLines.length - 1 ? "\n" : "" ) ); } document = new Document ( doc.toString ( ) ); } /* * @see TestCase#tearDown() */ protected void tearDown() throws Exception { super.tearDown(); } /* * Just for this and the vice versa case, to make things easier * * @return String Space string */ public String from ( ) { return "\t"; } /* * Just for this and the vice versa case, to make things easier * * @return String Tab string */ public String to ( ) { return PyConvertTabToSpace.getTabSpace ( ); } /* * Just to shorten the lines in the later tests, this calls the action's get tab width * function * * @return int Tab width */ public int getTabWidth ( ) { return PyConvertTabToSpace.getTabWidth ( ); } /* * Just to shorten the lines in the later tests, this calls the action's trim function * * @param in Line of 'code' to be stripped * @return String Stripped 'code' line */ public String callTrim ( String in ) { return PyStripTrailingWhitespace.trimTrailingWhitespace ( in ); } /* * Checks multiple-line selection. */ public void testPerform1 ( ) { StringBuffer result = new StringBuffer ( ); int i = -1; int startLineIndex = 0; int endLineIndex = 0; int selBegin = 0; int selLength = 0; // 'Select' the entire last def String [] strArr = document.get ( ).replaceAll ( "X", from ( ) ).split ( "\n" ); int len = 0; len += strArr[++i].length ( ) + 1; // "def bar ( self ):\n" len += strArr[++i].length ( ) + 1; // "\tprint \"foo1\"\t \n" len += strArr[++i].length ( ) + 1; // "\tprint \"bar1\"\n" len += strArr[++i].length ( ) + 1; // "\n \n" startLineIndex = i + 1; selBegin = len; len += strArr[++i].length ( ) + 1; // "def foo ( self ): len += strArr[++i].length ( ) + 1; // "\tprint \"foo2\"\t \n" len += strArr[++i].length ( ); // "\tprint \"bar2\" \n" endLineIndex = i; selLength = len - selBegin; // Create result document i = -1; result.append ( documentLines[++i].replaceAll ( "X", from ( ) ) + "\n" ); result.append ( documentLines[++i].replaceAll ( "X", from ( ) ) + "\n" ); result.append ( documentLines[++i].replaceAll ( "X", from ( ) ) + "\n" ); result.append ( documentLines[++i].replaceAll ( "X", from ( ) ) + "\n" ); result.append ( documentLines[++i].replaceAll ( "X", to ( ) ) + "\n" ); result.append ( documentLines[++i].replaceAll ( "X", to ( ) ) + "\n" ); result.append ( documentLines[++i].replaceAll ( "X", to ( ) ) ); // Our expected result IDocument resultDoc = new Document ( result.toString ( ) ); // For timing data document.set ( document.get ( ).replaceAll ( "X", from ( ) ) ); long begin = System.currentTimeMillis ( ); PySelection ps = new PySelection ( document, startLineIndex, endLineIndex, selLength, true ); PyConvertTabToSpace.perform ( ps ); long end = System.currentTimeMillis ( ); // Timing result System.err.print ( TestFileName + " :: " ); System.err.println ( "testPerform1: " + ( end - begin ) + "ms" ); // Document affected properly? assertEquals ( document.get ( ), resultDoc.get ( ) ); } /* * Checks multiple-line selection with the last line partially selected. */ public void testPerform2 ( ) { StringBuffer result = new StringBuffer ( ); int i = -1; int startLineIndex = 0; int endLineIndex = 0; int selBegin = 0; int selLength = 0; // 'Select' the entire last def String [] strArr = document.get ( ).replaceAll ( "X", from ( ) ).split ( "\n" ); int len = 0; len += strArr[++i].length ( ) + 1; // "def bar ( self ):\n" len += strArr[++i].length ( ) + 1; // "\tprint \"foo1\"\t \n" len += strArr[++i].length ( ) + 1; // "\tprint \"bar1\"\n" len += strArr[++i].length ( ) + 1; // "\n \n" startLineIndex = i + 1; selBegin = len; len += strArr[++i].length ( ) + 1; // "def foo ( self ): len += strArr[++i].length ( ) + 1; // "\tprint \"foo2\"\t \n" len += strArr[++i].length ( ); // "\tprint \"bar2\" \n" endLineIndex = i; selLength = len - selBegin - 6; // Create result document i = -1; result.append ( documentLines[++i].replaceAll ( "X", from ( ) ) + "\n" ); result.append ( documentLines[++i].replaceAll ( "X", from ( ) ) + "\n" ); result.append ( documentLines[++i].replaceAll ( "X", from ( ) ) + "\n" ); result.append ( documentLines[++i].replaceAll ( "X", from ( ) ) + "\n" ); result.append ( documentLines[++i].replaceAll ( "X", to ( ) ) + "\n" ); result.append ( documentLines[++i].replaceAll ( "X", to ( ) ) + "\n" ); result.append ( documentLines[++i].replaceAll ( "X", to ( ) ) ); // Our expected result IDocument resultDoc = new Document ( result.toString ( ) ); // For timing data document.set ( document.get ( ).replaceAll ( "X", from ( ) ) ); long begin = System.currentTimeMillis ( ); PySelection ps = new PySelection ( document, startLineIndex, endLineIndex, selLength, true ); PyConvertTabToSpace.perform ( ps ); long end = System.currentTimeMillis ( ); // Timing result System.err.print ( TestFileName + " :: " ); System.err.println ( "testPerform2: " + ( end - begin ) + "ms" ); // Document affected properly? assertEquals ( document.get ( ), resultDoc.get ( ) ); } /* * Checks empty selection to affect cursor line. */ public void testPerform3 ( ) { StringBuffer result = new StringBuffer ( ); int i = -1; int startLineIndex = 0; int endLineIndex = 0; int selBegin = 0; int selLength = 0; // 'Select' the entire last def startLineIndex = endLineIndex = 1; selBegin = 1; selLength = 0; // Our expected result IDocument resultDoc = new Document ( document.get ( ).toString ( ).replaceAll ( "X", to ( ) ) ); // For timing data document.set ( document.get ( ).replaceAll ( "X", from ( ) ) ); long begin = System.currentTimeMillis ( ); PySelection ps = new PySelection ( document, startLineIndex, endLineIndex, selLength, true ); PyConvertTabToSpace.perform ( ps ); long end = System.currentTimeMillis ( ); // Timing result System.err.print ( TestFileName + " :: " ); System.err.println ( "testPerform3: " + ( end - begin ) + "ms" ); // Document affected properly? assertEquals ( document.get ( ), resultDoc.get ( ) ); } } --- NEW FILE: PyStripTrailingWhitespaceTest.java --- /* * Created on Jun 16, 2004 * * To change the template for this generated file go to * Window>Preferences>Java>Code Generation>Code and Comments */ package test; import org.eclipse.jface.text.Document; import org.eclipse.jface.text.IDocument; import org.python.pydev.editor.actions.PySelection; import org.python.pydev.editor.actions.PyStripTrailingWhitespace; import junit.framework.TestCase; /** * @author Dreamer * * Tests the 'Strip Trailing Whitespace' editor feature. It performs 4 checks. * * The first checks to see if the simple String-input 'trim' feature works properly. * * The other 3 are code-based checks. * * The first fakes a selection of a couple lines in a fake document, and checks * to see that the proper whitespace is removed. * * The second fakes a selection but stops in the * middle of a line, to make sure that the Whitespace handler doesn't just strip whitespace from * the partial selection unless that line has whitespace to be stripped. * * The third selects * nothing, and makes sure that the whole document is affected by whitespace stripping. */ public class PyStripTrailingWhitespaceTest extends TestCase { /* The document that will fake an editor environment */ IDocument document; /* Lines of 'code' in the fake document */ String [] documentLines; /* For my own debugging edification, to output the name later */ static final String TestFileName = "PyStripTrailingWhitespaceTest"; /** * Constructor for PyStripTrailingWhitespaceTest. * @param arg0 */ public PyStripTrailingWhitespaceTest(String arg0) { super(arg0); } /* * Sets up the document 'code' and adds it to the document. * * @see TestCase#setUp() */ protected void setUp() throws Exception { super.setUp(); int i = -1; int length = 7; documentLines = new String[length]; documentLines[++i] = "def bar ( self ):"; documentLines[++i] = "\tprint \"foo1\"\t "; documentLines[++i] = "\tprint \"bar1\""; documentLines[++i] = "\t "; documentLines[++i] = "def foo ( self ): "; documentLines[++i] = "\tprint \"foo2\"\t "; documentLines[++i] = "\tprint \"bar2\" "; StringBuffer doc = new StringBuffer ( ); for ( i = 0; i < documentLines.length; i++ ) { doc.append ( documentLines[i] + ( i < documentLines.length - 1 ? "\n" : "" ) ); } document = new Document ( doc.toString ( ) ); } /* * @see TestCase#tearDown() */ protected void tearDown() throws Exception { super.tearDown(); } /* * Just to shorten the lines in the later tests, this calls the action's trim function * * @param in Line of 'code' to be stripped * @return String Stripped 'code' line */ public String callTrim ( String in ) { return PyStripTrailingWhitespace.trimTrailingWhitespace ( in ); } /* * Checks single-line trimming. */ public void testTrimTrailingWhitespace ( ) { // Preserves everything but last whitespace assertEquals ( "\tprint \"foo\"", callTrim ( "\tprint \"foo\"\t" ) ); // Ditto, without tab in front assertEquals ( "print \"foo\"", callTrim ( "print \"foo\" \t" ) ); // Full line blank assertEquals ( "", callTrim ( "\t \t" ) ); // Null input assertEquals ( "", callTrim ( null ) ); } /* * Checks multiple-line selection. */ public void testPerform1 ( ) { StringBuffer result = new StringBuffer ( ); int i = -1; int startLineIndex = 0; int endLineIndex = 0; int selBegin = 0; int selLength = 0; // 'Select' the entire last def result.append ( documentLines[++i] + "\n" ); // "def bar ( self ):\n" result.append ( documentLines[++i] + "\n" ); // "\tprint \"foo1\"\t \n" result.append ( documentLines[++i] + "\n" ); // "\tprint \"bar1\"\n" result.append ( documentLines[++i] + "\n" ); // "\n \n" startLineIndex = i + 1; selBegin = result.toString ( ).length ( ); result.append ( callTrim ( documentLines[++i] ) + "\n" ); // "def foo ( self ): \n" result.append ( callTrim ( documentLines[++i] ) + "\n" ); // "\tprint \"foo2\"\t \n" result.append ( callTrim ( documentLines[++i] ) ); // "\tprint \"bar2\" \n" endLineIndex = i; selLength = document.get ( ).length ( ) - selBegin; // Our expected result IDocument resultDoc = new Document ( result.toString ( ) ); // For timing data long begin = System.currentTimeMillis ( ); PySelection ps = new PySelection ( document, startLineIndex, endLineIndex, selLength, true ); PyStripTrailingWhitespace.perform ( ps ); long end = System.currentTimeMillis ( ); // Timing result System.err.print ( TestFileName + " :: " ); System.err.println ( "testPerform1: " + ( end - begin ) + "ms" ); // Document affected properly? assertEquals ( document.get ( ), resultDoc.get ( ) ); } /* * Checks multiple-line selection with the last line partially selected. */ public void testPerform2 ( ) { StringBuffer result = new StringBuffer ( ); int i = -1; int startLineIndex = 0; int endLineIndex = 0; int selBegin = 0; int selLength = 0; // 'Select' part of the last def result.append ( documentLines[++i] + "\n" ); // "def bar ( self ):\n" result.append ( documentLines[++i] + "\n" ); // "\tprint \"foo1\"\t \n" result.append ( documentLines[++i] + "\n" ); // "\tprint \"bar1\"\n" result.append ( documentLines[++i] + "\n" ); // "\n \n" startLineIndex = i + 1; selBegin = result.toString ( ).length ( ); result.append ( callTrim ( documentLines[++i] ) + "\n" ); // "def foo ( self ): \n" result.append ( callTrim ( documentLines[++i] ) + "\n" ); // "\tprint \"foo2\"\t \n" result.append ( documentLines[++i] ); // "\tprint \"bar2\" \n" endLineIndex = i; selLength = document.get ( ).length ( ) - selBegin - 6; // Our expected result IDocument resultDoc = new Document ( result.toString ( ) ); // For timing data long begin = System.currentTimeMillis ( ); PySelection ps = new PySelection ( document, startLineIndex, endLineIndex, selLength, true ); PyStripTrailingWhitespace.perform ( ps ); long end = System.currentTimeMillis ( ); // Timing result System.err.print ( TestFileName + " :: " ); System.err.println ( "testPerform2: " + ( end - begin ) + "ms" ); // Document affected properly? assertEquals ( document.get ( ), resultDoc.get ( ) ); } /* * Checks empty selection to affect cursor line. */ public void testPerform3 ( ) { StringBuffer result = new StringBuffer ( ); int i = -1; int startLineIndex = 0; int endLineIndex = 0; int selBegin = 0; int selLength = 0; // 'Select' nothing, which should call action on the whole thing result.append ( callTrim ( documentLines[++i] ) + "\n" ); // "def bar ( self ):\n" result.append ( callTrim ( documentLines[++i] ) + "\n" ); // "\tprint \"foo1\"\t \n" result.append ( callTrim ( documentLines[++i] ) + "\n" ); // "\tprint \"bar1\"\n" result.append ( callTrim ( documentLines[++i] ) + "\n" ); // "\n \n" result.append ( callTrim ( documentLines[++i] ) + "\n" ); // "def foo ( self ): \n" result.append ( callTrim ( documentLines[++i] ) + "\n" ); // "\tprint \"foo2\"\t \n" result.append ( callTrim ( documentLines[++i] ) ); // "\tprint \"bar2\" \n" endLineIndex = i; // Our expected result IDocument resultDoc = new Document ( result.toString ( ) ); // For timing data long begin = System.currentTimeMillis ( ); PySelection ps = new PySelection ( document, startLineIndex, endLineIndex, selLength, true ); PyStripTrailingWhitespace.perform ( ps ); long end = System.currentTimeMillis ( ); // Timing result System.err.print ( TestFileName + " :: " ); System.err.println ( "testPerform3: " + ( end - begin ) + "ms" ); // Document affected properly? assertEquals ( document.get ( ), resultDoc.get ( ) ); } } --- NEW FILE: PyCommentTest.java --- /* * Created on Jun 17, 2004 * * To change the template for this generated file go to * Window>Preferences>Java>Code Generation>Code and Comments */ package test; import org.eclipse.jface.text.Document; import org.eclipse.jface.text.IDocument; import org.python.pydev.editor.actions.PyComment; import org.python.pydev.editor.actions.PySelection; import junit.framework.TestCase; /** * @author Dreamer * * Tests the 'Comment' editor feature. It performs 3 checks. * * The first fakes a selection of a couple lines in a fake document, and checks to see that the * code is properly commented. * * The second fakes a selection but stops in the middle of a line, to make sure that the proper * lines are commented, including the beginning of partial lines. * * The third selects nothing, and makes sure that the only line affected is the one the cursor * is on. */ public class PyCommentTest extends TestCase { /* The document that will fake an editor environment */ IDocument document; /* Lines of 'code' in the fake document */ String [] documentLines; /* For my own debugging edification, to output the name later */ static final String TestFileName = "PyCommentTest"; /** * Constructor for PyCommentTest. * @param arg0 */ public PyCommentTest(String arg0) { super(arg0); } /* * Sets up the document 'code' and adds it to the document. * * @see TestCase#setUp() */ protected void setUp() throws Exception { super.setUp(); int i = -1; int length = 7; documentLines = new String[length]; documentLines[++i] = "def bar ( self ):"; documentLines[++i] = "\tprint \"foo1\"\t "; documentLines[++i] = "\tprint \"bar1\""; documentLines[++i] = "\t "; documentLines[++i] = "def foo ( self ): "; documentLines[++i] = "\tprint \"foo2\"\t "; documentLines[++i] = "\tprint \"bar2\" "; StringBuffer doc = new StringBuffer ( ); for ( i = 0; i < documentLines.length; i++ ) { doc.append ( documentLines[i] + ( i < documentLines.length - 1 ? "\n" : "" ) ); } document = new Document ( doc.toString ( ) ); } /* * @see TestCase#tearDown() */ protected void tearDown() throws Exception { super.tearDown(); } /* * Just to shorten the lines in the later tests, this calls the action's comment function * * @param in Line of 'code' to be commented * @return String Commented 'code' line */ public boolean callComment ( PySelection ps ) { return PyComment.perform ( ps ); } /* * Checks multiple-line selection. */ public void testPerform1 ( ) { StringBuffer result = new StringBuffer ( ); int i = -1; int startLineIndex = 0; int endLineIndex = 0; int selBegin = 0; int selLength = 0; // 'Select' the entire last def result.append ( documentLines[++i] + "\n" ); // "def bar ( self ):\n" result.append ( documentLines[++i] + "\n" ); // "\tprint \"foo1\"\t \n" result.append ( documentLines[++i] + "\n" ); // "\tprint \"bar1\"\n" result.append ( documentLines[++i] + "\n" ); // "\n \n" startLineIndex = i + 1; selBegin = result.toString ( ).length ( ); result.append ( "#" + documentLines[++i] + "\n" ); // "def foo ( self ): \n" result.append ( "#" + documentLines[++i] + "\n" ); // "\tprint \"foo2\"\t \n" result.append ( "#" + documentLines[++i] ); // "\tprint \"bar2\" \n" endLineIndex = i; selLength = document.get ( ).length ( ) - selBegin; // Our expected result IDocument resultDoc = new Document ( result.toString ( ) ); // For timing data long begin = System.currentTimeMillis ( ); PySelection ps = new PySelection ( document, startLineIndex, endLineIndex, selLength, false ); PyComment.perform ( ps ); long end = System.currentTimeMillis ( ); // Timing result System.err.print ( TestFileName + " :: " ); System.err.println ( "testPerform1: " + ( end - begin ) + "ms" ); // Document affected properly? assertEquals ( document.get ( ), resultDoc.get ( ) ); } /* * Checks multiple-line selection with the last line partially selected. */ public void testPerform2 ( ) { StringBuffer result = new StringBuffer ( ); int i = -1; int startLineIndex = 0; int endLineIndex = 0; int selBegin = 0; int selLength = 0; // 'Select' part of the last def result.append ( documentLines[++i] + "\n" ); // "def bar ( self ):\n" result.append ( documentLines[++i] + "\n" ); // "\tprint \"foo1\"\t \n" result.append ( documentLines[++i] + "\n" ); // "\tprint \"bar1\"\n" result.append ( documentLines[++i] + "\n" ); // "\n \n" startLineIndex = i + 1; selBegin = result.toString ( ).length ( ); result.append ( "#" + documentLines[++i] + "\n" ); // "def foo ( self ): \n" result.append ( "#" + documentLines[++i] + "\n" ); // "\tprint \"foo2\"\t \n" result.append ( "#" + documentLines[++i] ); // "\tprint \"bar2\" \n" endLineIndex = i; selLength = document.get ( ).length ( ) - selBegin - 6; // Our expected result IDocument resultDoc = new Document ( result.toString ( ) ); // For timing data long begin = System.currentTimeMillis ( ); PySelection ps = new PySelection ( document, startLineIndex, endLineIndex, selLength, false ); PyComment.perform ( ps ); long end = System.currentTimeMillis ( ); // Timing result System.err.print ( TestFileName + " :: " ); System.err.println ( "testPerform2: " + ( end - begin ) + "ms" ); // Document affected properly? assertEquals ( document.get ( ), resultDoc.get ( ) ); } /* * Checks empty selection to affect cursor line. */ public void testPerform3 ( ) { StringBuffer result = new StringBuffer ( ); int i = -1; int startLineIndex = 0; int endLineIndex = 0; int selBegin = 0; int selLength = 0; // 'Select' in middle of one line, show that it blocks that whole line only result.append ( documentLines[++i] + "\n" ); // "def bar ( self ):\n" result.append ( documentLines[++i] + "\n" ); // "\tprint \"foo1\"\t \n" result.append ( documentLines[++i] + "\n" ); // "\tprint \"bar1\"\n" result.append ( documentLines[++i] + "\n" ); // "\n \n" result.append ( documentLines[++i] + "\n" ); // "def foo ( self ): \n" selBegin = result.toString ( ).length ( ) + 5; result.append ( "#" + documentLines[++i] + "\n" ); // "\tprint \"foo2\"\t \n" startLineIndex = i; endLineIndex = startLineIndex; result.append ( documentLines[++i] ); // "\tprint \"bar2\" \n" // Our expected result IDocument resultDoc = new Document ( result.toString ( ) ); // For timing data long begin = System.currentTimeMillis ( ); PySelection ps = new PySelection ( document, startLineIndex, endLineIndex, selLength, false ); PyComment.perform ( ps ); long end = System.currentTimeMillis ( ); // Timing result System.err.print ( TestFileName + " :: " ); System.err.println ( "testPerform3: " + ( end - begin ) + "ms" ); // Document affected properly? assertEquals ( document.get ( ), resultDoc.get ( ) ); } } --- NEW FILE: PyRemoveBlockCommentTest.java --- /* * Created on Jun 17, 2004 * * To change the template for this generated file go to * Window>Preferences>Java>Code Generation>Code and Comments */ package test; import org.eclipse.jface.text.Document; import org.eclipse.jface.text.IDocument; import org.python.pydev.editor.actions.PyAddBlockComment; import org.python.pydev.editor.actions.PyRemoveBlockComment; import org.python.pydev.editor.actions.PySelection; import junit.framework.TestCase; /** * @author Dreamer * * Tests the 'Remove Block Comment' editor feature. It performs 3 checks. * * The first fakes a selection of a couple lines in a fake document, and checks to see that the * code is properly un-commented. * * The second fakes a selection but stops in the middle of a line, to make sure that the proper * lines are un-commented, including the beginning of partial lines. * * The third selects nothing, and makes sure that the no lines are otherwise affected. * TODO Maybe in the future, selecting anything within a comment block and calling the action will remove the entire surrounding block comment */ public class PyRemoveBlockCommentTest extends TestCase { /* The document that will fake an editor environment */ IDocument document; /* Lines of 'code' in the fake document */ String [] documentLines; /* For my own debugging edification, to output the name later */ static final String TestFileName = "PyRemoveBlockCommentTest"; /** * Constructor for PyAddBlockCommentTest. * @param arg0 */ public PyRemoveBlockCommentTest(String arg0) { super(arg0); } /* * Sets up the document 'code' and adds it to the document. * * @see TestCase#setUp() */ protected void setUp() throws Exception { super.setUp(); int i = -1; int length = 7; documentLines = new String[length]; documentLines[++i] = "def bar ( self ):"; documentLines[++i] = "\tprint \"foo1\"\t "; documentLines[++i] = "\tprint \"bar1\""; documentLines[++i] = "\t "; documentLines[++i] = "def foo ( self ): "; documentLines[++i] = "\tprint \"foo2\"\t "; documentLines[++i] = "\tprint \"bar2\" "; StringBuffer doc = new StringBuffer ( ); for ( i = 0; i < documentLines.length; i++ ) { doc.append ( documentLines[i] + ( i < documentLines.length - 1 ? "\n" : "" ) ); } document = new Document ( doc.toString ( ) ); } /* * @see TestCase#tearDown() */ protected void tearDown() throws Exception { super.tearDown(); } /* * Just to shorten the lines in the later tests, this calls the action's get comment line * function * * @return String Comment line */ public String getFullCommentLine ( ) { return PyAddBlockComment.getFullCommentLine ( ); } /* * Just to shorten the lines in the later tests, this calls the action's comment function * * @param in Line of 'code' to be commented * @return String Commented 'code' line */ public boolean callComment ( PySelection ps ) { return PyRemoveBlockComment.perform ( ps ); } /* * Checks multiple-line selection. */ public void testPerform1 ( ) { StringBuffer result = new StringBuffer ( ); int i = -1; int startLineIndex = 0; int endLineIndex = 0; int selBegin = 0; int selLength = 0; // 'Select' the entire last def result.append ( documentLines[++i] + "\n" ); // "def bar ( self ):\n" result.append ( documentLines[++i] + "\n" ); // "\tprint \"foo1\"\t \n" result.append ( documentLines[++i] + "\n" ); // "\tprint \"bar1\"\n" result.append ( documentLines[++i] + "\n" ); // "\n \n" startLineIndex = i + 1; selBegin = result.toString ( ).length ( ); result.append ( "#" + getFullCommentLine ( ) + "\n" ); result.append ( "#" + documentLines[++i] + "\n" ); // "def foo ( self ): \n" result.append ( "#" + documentLines[++i] + "\n" ); // "\tprint \"foo2\"\t \n" result.append ( "#" + documentLines[++i] + "\n" ); // "\tprint \"bar2\" \n" result.append ( "#" + getFullCommentLine ( ) ); endLineIndex = i + 2; selLength = result.toString ( ).length ( ) - selBegin; // Our expected result IDocument resultDoc = new Document ( result.toString ( ) ); // For timing data long begin = System.currentTimeMillis ( ); PySelection ps = new PySelection ( resultDoc, startLineIndex, endLineIndex, selLength, false ); PyRemoveBlockComment.perform ( ps ); long end = System.currentTimeMillis ( ); // Timing result System.err.print ( TestFileName + " :: " ); System.err.println ( "testPerform1: " + ( end - begin ) + "ms" ); // Document affected properly? assertEquals ( document.get ( ), resultDoc.get ( ) ); } /* * Checks multiple-line selection with the last line partially selected. */ public void testPerform2 ( ) { StringBuffer result = new StringBuffer ( ); int i = -1; int startLineIndex = 0; int endLineIndex = 0; int selBegin = 0; int selLength = 0; // 'Select' part of the last def result.append ( documentLines[++i] + "\n" ); // "def bar ( self ):\n" result.append ( documentLines[++i] + "\n" ); // "\tprint \"foo1\"\t \n" result.append ( documentLines[++i] + "\n" ); // "\tprint \"bar1\"\n" result.append ( documentLines[++i] + "\n" ); // "\n \n" startLineIndex = i + 1; selBegin = result.toString ( ).length ( ); result.append ( "#" + getFullCommentLine ( ) + "\n" ); result.append ( "#" + documentLines[++i] + "\n" ); // "def foo ( self ): \n" result.append ( "#" + documentLines[++i] + "\n" ); // "\tprint \"foo2\"\t \n" result.append ( "#" + documentLines[++i] + "\n" ); // "\tprint \"bar2\" \n" result.append ( "#" + getFullCommentLine ( ) ); endLineIndex = i + 2; selLength = result.toString ( ).length ( ) - selBegin - 6; // Our expected result IDocument resultDoc = new Document ( result.toString ( ) ); // For timing data long begin = System.currentTimeMillis ( ); PySelection ps = new PySelection ( resultDoc, startLineIndex, endLineIndex, selLength, false ); PyRemoveBlockComment.perform ( ps ); long end = System.currentTimeMillis ( ); // Timing result System.err.print ( TestFileName + " :: " ); System.err.println ( "testPerform2: " + ( end - begin ) + "ms" ); // Document affected properly? assertEquals ( document.get ( ), resultDoc.get ( ) ); } /* * Checks multiple-line selection with the last line partially selected. */ public void testPerform3 ( ) { StringBuffer result = new StringBuffer ( ); int i = -1; int startLineIndex = 0; int endLineIndex = 0; int selBegin = 0; int selLength = 0; // 'Select' in middle of one line, show that it blocks that whole line result.append ( documentLines[++i] + "\n" ); // "def bar ( self ):\n" result.append ( documentLines[++i] + "\n" ); // "\tprint \"foo1\"\t \n" result.append ( documentLines[++i] + "\n" ); // "\tprint \"bar1\"\n" result.append ( documentLines[++i] + "\n" ); // "\n \n" result.append ( documentLines[++i] + "\n" ); // "def foo ( self ): \n" selBegin = result.toString ( ).length ( ) + 5; result.append ( "#" + getFullCommentLine ( ) + "\n" ); result.append ( "#" + documentLines[++i] + "\n" ); // "\tprint \"foo2\"\t \n" startLineIndex = i + 1; endLineIndex = startLineIndex; result.append ( "#" + getFullCommentLine ( ) + "\n" ); result.append ( documentLines[++i] ); // "\tprint \"bar2\" \n" // Our expected result IDocument resultDoc = new Document ( result.toString ( ) ); // For timing data long begin = System.currentTimeMillis ( ); PySelection ps = new PySelection ( resultDoc, startLineIndex, endLineIndex, selLength, false ); PyRemoveBlockComment.perform ( ps ); long end = System.currentTimeMillis ( ); // Timing result System.err.print ( TestFileName + " :: " ); System.err.println ( "testPerform3: " + ( end - begin ) + "ms" ); // Document affected properly? assertEquals ( result.toString ( ), resultDoc.get ( ) ); } } --- NEW FILE: AllTests.java --- /* * Created on Jun 17, 2004 * * To change the template for this generated file go to * Window>Preferences>Java>Code Generation>Code and Comments */ package test; import junit.framework.Test; import junit.framework.TestSuite; /** * @author Dreamer * * To change the template for this generated type comment go to * Window>Preferences>Java>Code Generation>Code and Comments */ public class AllTests { public static String TestFileName = "Editor.Actions"; public static Test suite() { TestSuite suite = new TestSuite("Test for org.python.pydev.editor.actions"); //$JUnit-BEGIN$ suite.addTest(new TestSuite(PyCommentTest.class)); suite.addTest(new TestSuite(PyUncommentTest.class)); suite.addTest(new TestSuite(PyAddBlockCommentTest.class)); suite.addTest(new TestSuite(PyRemoveBlockCommentTest.class)); suite.addTest(new TestSuite(PyStripTrailingWhitespaceTest.class)); suite.addTest(new TestSuite(PyConvertSpaceToTabTest.class)); suite.addTest(new TestSuite(PyConvertTabToSpaceTest.class)); //$JUnit-END$ System.out.println ( "Running Test Suite '" + TestFileName + "'..." ); return suite; } } --- NEW FILE: PyUncommentTest.java --- /* * Created on Jun 17, 2004 * * To change the template for this generated file go to * Window>Preferences>Java>Code Generation>Code and Comments */ package test; import org.eclipse.jface.text.Document; import org.eclipse.jface.text.IDocument; import org.python.pydev.editor.actions.PySelection; import org.python.pydev.editor.actions.PyUncomment; import junit.framework.TestCase; /** * @author Dreamer * * Tests the 'Uncomment' editor feature. It performs 3 checks. * * The first fakes a selection of a couple lines in a fake document, and checks to see that the * code is properly un-commented. * * The second fakes a selection but stops in the middle of a line, to make sure that the proper * lines are un-commented, including the beginning of partial lines. * * The third selects nothing, and makes sure that the only line affected is the one the cursor * is on. */ public class PyUncommentTest extends TestCase { /* The document that will fake an editor environment */ IDocument document; /* Lines of 'code' in the fake document */ String [] documentLines; /* For my own debugging edification, to output the name later */ static final String TestFileName = "PyUncommentTest"; /** * Constructor for PyUncommentTest. * @param arg0 */ public PyUncommentTest(String arg0) { super(arg0); } /* * Sets up the document 'code' and adds it to the document. * * @see TestCase#setUp() */ protected void setUp() throws Exception { super.setUp(); int i = -1; int length = 7; documentLines = new String[length]; documentLines[++i] = "def bar ( self ):"; documentLines[++i] = "\tprint \"foo1\"\t "; documentLines[++i] = "\tprint \"bar1\""; documentLines[++i] = "\t "; documentLines[++i] = "def foo ( self ): "; documentLines[++i] = "\tprint \"foo2\"\t "; documentLines[++i] = "\tprint \"bar2\" "; StringBuffer doc = new StringBuffer ( ); for ( i = 0; i < documentLines.length; i++ ) { doc.append ( documentLines[i] + ( i < documentLines.length - 1 ? "\n" : "" ) ); } document = new Document ( doc.toString ( ) ); } /* * @see TestCase#tearDown() */ protected void tearDown() throws Exception { super.tearDown(); } /* * Just to shorten the lines in the later tests, this calls the action's uncomment function * * @param in Line of 'code' to be commented * @return String Commented 'code' line */ public boolean callComment ( PySelection ps ) { return PyUncomment.perform ( ps ); } /* * Checks multiple-line selection. */ public void testPerform1 ( ) { StringBuffer result = new StringBuffer ( ); int i = -1; int startLineIndex = 0; int endLineIndex = 0; int selBegin = 0; int selLength = 0; // 'Select' the entire last def result.append ( documentLines[++i] + "\n" ); // "def bar ( self ):\n" result.append ( documentLines[++i] + "\n" ); // "\tprint \"foo1\"\t \n" result.append ( documentLines[++i] + "\n" ); // "\tprint \"bar1\"\n" result.append ( documentLines[++i] + "\n" ); // "\n \n" startLineIndex = i + 1; selBegin = result.toString ( ).length ( ); result.append ( "#" + documentLines[++i] + "\n" ); // "def foo ( self ): \n" result.append ( "#" + documentLines[++i] + "\n" ); // "\tprint \"foo2\"\t \n" result.append ( "#" + documentLines[++i] ); // "\tprint \"bar2\" \n" endLineIndex = i; selLength = document.get ( ).length ( ) - selBegin; // Our expected result IDocument resultDoc = new Document ( result.toString ( ) ); // For timing data long begin = System.currentTimeMillis ( ); PySelection ps = new PySelection ( resultDoc, startLineIndex, endLineIndex, selLength, false ); PyUncomment.perform ( ps ); long end = System.currentTimeMillis ( ); // Timing result System.err.print ( TestFileName + " :: " ); System.err.println ( "testPerform1: " + ( end - begin ) + "ms" ); // Document affected properly? assertEquals ( document.get ( ), resultDoc.get ( ) ); } /* * Checks multiple-line selection with the last line partially selected. */ public void testPerform2 ( ) { StringBuffer result = new StringBuffer ( ); int i = -1; int startLineIndex = 0; int endLineIndex = 0; int selBegin = 0; int selLength = 0; // 'Select' part of the last def result.append ( documentLines[++i] + "\n" ); // "def bar ( self ):\n" result.append ( documentLines[++i] + "\n" ); // "\tprint \"foo1\"\t \n" result.append ( documentLines[++i] + "\n" ); // "\tprint \"bar1\"\n" result.append ( documentLines[++i] + "\n" ); // "\n \n" startLineIndex = i + 1; selBegin = result.toString ( ).length ( ); result.append ( "#" + documentLines[++i] + "\n" ); // "def foo ( self ): \n" result.append ( "#" + documentLines[++i] + "\n" ); // "\tprint \"foo2\"\t \n" result.append ( "#" + documentLines[++i] ); // "\tprint \"bar2\" \n" endLineIndex = i; selLength = document.get ( ).length ( ) - selBegin - 6; // Our expected result IDocument resultDoc = new Document ( result.toString ( ) ); // For timing data long begin = System.currentTimeMillis ( ); PySelection ps = new PySelection ( resultDoc, startLineIndex, endLineIndex, selLength, false ); PyUncomment.perform ( ps ); long end = System.currentTimeMillis ( ); // Timing result System.err.print ( TestFileName + " :: " ); System.err.println ( "testPerform2: " + ( end - begin ) + "ms" ); // Document affected properly? assertEquals ( document.get ( ), resultDoc.get ( ) ); } /* * Checks empty selection to affect cursor line. */ public void testPerform3 ( ) { StringBuffer result = new StringBuffer ( ); int i = -1; int startLineIndex = 0; int endLineIndex = 0; int selBegin = 0; int selLength = 0; // 'Select' in middle of one line, show that it blocks that whole line only result.append ( documentLines[++i] + "\n" ); // "def bar ( self ):\n" result.append ( documentLines[++i] + "\n" ); // "\tprint \"foo1\"\t \n" result.append ( documentLines[++i] + "\n" ); // "\tprint \"bar1\"\n" result.append ( documentLines[++i] + "\n" ); // "\n \n" result.append ( documentLines[++i] + "\n" ); // "def foo ( self ): \n" selBegin = result.toString ( ).length ( ) + 5; result.append ( "#" + documentLines[++i] + "\n" ); // "\tprint \"foo2\"\t \n" startLineIndex = i; endLineIndex = startLineIndex; result.append ( documentLines[++i] ); // "\tprint \"bar2\" \n" // Our expected result IDocument resultDoc = new Document ( result.toString ( ) ); // For timing data long begin = System.currentTimeMillis ( ); PySelection ps = new PySelection ( resultDoc, startLineIndex, endLineIndex, selLength, false ); PyUncomment.perform ( ps ); long end = System.currentTimeMillis ( ); // Timing result System.err.print ( TestFileName + " :: " ); System.err.println ( "testPerform3: " + ( end - begin ) + "ms" ); // Document affected properly? assertEquals ( document.get ( ), resultDoc.get ( ) ); } } --- NEW FILE: PyAddBlockCommentTest.java --- /* * Created on Jun 17, 2004 * * To change the template for this generated file go to * Window>Preferences>Java>Code Generation>Code and Comments */ package test; import org.eclipse.jface.text.Document; import org.eclipse.jface.text.IDocument; import org.python.pydev.editor.actions.PyAddBlockComment; import org.python.pydev.editor.actions.PySelection; import junit.framework.TestCase; /** * @author Dreamer * * Tests the 'Block Comment' editor feature. It performs 3 checks. * * The first fakes a selection of a couple lines in a fake document, and checks to see that the * code is properly commented. * * The second fakes a selection but stops in the middle of a line, to make sure that the proper * lines are commented, including the beginning of partial lines. * * The third selects nothing, and makes sure that the only line affected is the one the cursor * is on. */ public class PyAddBlockCommentTest extends TestCase { /* The document that will fake an editor environment */ IDocument document; /* Lines of 'code' in the fake document */ String [] documentLines; /* For my own debugging edification, to output the name later */ static final String TestFileName = "PyAddBlockCommentTest"; /** * Constructor for PyAddBlockCommentTest. * @param arg0 */ public PyAddBlockCommentTest(String arg0) { super(arg0); } /* * Sets up the document 'code' and adds it to the document. * * @see TestCase#setUp() */ protected void setUp() throws Exception { super.setUp(); int i = -1; int length = 7; documentLines = new String[length]; documentLines[++i] = "def bar ( self ):"; documentLines[++i] = "\tprint \"foo1\"\t "; documentLines[++i] = "\tprint \"bar1\""; documentLines[++i] = "\t "; documentLines[++i] = "def foo ( self ): "; documentLines[++i] = "\tprint \"foo2\"\t "; documentLines[++i] = "\tprint \"bar2\" "; StringBuffer doc = new StringBuffer ( ); for ( i = 0; i < documentLines.length; i++ ) { doc.append ( documentLines[i] + ( i < documentLines.length - 1 ? "\n" : "" ) ); } document = new Document ( doc.toString ( ) ); } /* * @see TestCase#tearDown() */ protected void tearDown() throws Exception { super.tearDown(); } /* * Just to shorten the lines in the later tests, this calls the action's get comment line * function * * @return String Comment line */ public String getFullCommentLine ( ) { return PyAddBlockComment.getFullCommentLine ( ); } /* * Just to shorten the lines in the later tests, this calls the action's comment function * * @param in Line of 'code' to be commented * @return String Commented 'code' line */ public boolean callComment ( PySelection ps ) { return PyAddBlockComment.perform ( ps ); } /* * Checks multiple-line selection. */ public void testPerform1 ( ) { StringBuffer result = new StringBuffer ( ); int i = -1; int startLineIndex = 0; int endLineIndex = 0; int selBegin = 0; int selLength = 0; // 'Select' the entire last def result.append ( documentLines[++i] + "\n" ); // "def bar ( self ):\n" result.append ( documentLines[++i] + "\n" ); // "\tprint \"foo1\"\t \n" result.append ( documentLines[++i] + "\n" ); // "\tprint \"bar1\"\n" result.append ( documentLines[++i] + "\n" ); // "\n \n" startLineIndex = i + 1; selBegin = result.toString ( ).length ( ); result.append ( "#" + getFullCommentLine ( ) + "\n" ); result.append ( "#" + documentLines[++i] + "\n" ); // "def foo ( self ): \n" result.append ( "#" + documentLines[++i] + "\n" ); // "\tprint \"foo2\"\t \n" result.append ( "#" + documentLines[++i] + "\n" ); // "\tprint \"bar2\" \n" result.append ( "#" + getFullCommentLine ( ) ); endLineIndex = i; selLength = document.get ( ).length ( ) - selBegin; // Our expected result IDocument resultDoc = new Document ( result.toString ( ) ); // For timing data long begin = System.currentTimeMillis ( ); PySelection ps = new PySelection ( document, startLineIndex, endLineIndex, selLength, false ); PyAddBlockComment.perform ( ps ); long end = System.currentTimeMillis ( ); // Timing result System.err.print ( TestFileName + " :: " ); System.err.println ( "testPerform1: " + ( end - begin ) + "ms" ); // Document affected properly? assertEquals ( document.get ( ), resultDoc.get ( ) ); } /* * Checks multiple-line selection with the last line partially selected. */ public void testPerform2 ( ) { StringBuffer result = new StringBuffer ( ); int i = -1; int startLineIndex = 0; int endLineIndex = 0; int selBegin = 0; int selLength = 0; // 'Select' part of the last def result.append ( documentLines[++i] + "\n" ); // "def bar ( self ):\n" result.append ( documentLines[++i] + "\n" ); // "\tprint \"foo1\"\t \n" result.append ( documentLines[++i] + "\n" ); // "\tprint \"bar1\"\n" result.append ( documentLines[++i] + "\n" ); // "\n \n" startLineIndex = i + 1; selBegin = result.toString ( ).length ( ); result.append ( "#" + getFullCommentLine ( ) + "\n" ); result.append ( "#" + documentLines[++i] + "\n" ); // "def foo ( self ): \n" result.append ( "#" + documentLines[++i] + "\n" ); // "\tprint \"foo2\"\t \n" result.append ( "#" + documentLines[++i] + "\n" ); // "\tprint \"bar2\" \n" result.append ( "#" + getFullCommentLine ( ) ); endLineIndex = i; selLength = document.get ( ).length ( ) - selBegin - 6; // Our expected result IDocument resultDoc = new Document ( result.toString ( ) ); // For timing data long begin = System.currentTimeMillis ( ); PySelection ps = new PySelection ( document, startLineIndex, endLineIndex, selLength, false ); PyAddBlockComment.perform ( ps ); long end = System.currentTimeMillis ( ); // Timing result System.err.print ( TestFileName + " :: " ); System.err.println ( "testPerform2: " + ( end - begin ) + "ms" ); // Document affected properly? assertEquals ( document.get ( ), resultDoc.get ( ) ); } /* * Checks multiple-line selection with the last line partially selected. */ public void testPerform3 ( ) { StringBuffer result = new StringBuffer ( ); int i = -1; int startLineIndex = 0; int endLineIndex = 0; int selBegin = 0; int selLength = 0; // 'Select' in middle of one line, show that it blocks that whole line result.append ( documentLines[++i] + "\n" ); // "def bar ( self ):\n" result.append ( documentLines[++i] + "\n" ); // "\tprint \"foo1\"\t \n" result.append ( documentLines[++i] + "\n" ); // "\tprint \"bar1\"\n" result.append ( documentLines[++i] + "\n" ); // "\n \n" result.append ( documentLines[++i] + "\n" ); // "def foo ( self ): \n" selBegin = result.toString ( ).length ( ) + 5; result.append ( "#" + getFullCommentLine ( ) + "\n" ); result.append ( "#" + documentLines[++i] + "\n" ); // "\tprint \"foo2\"\t \n" startLineIndex = i; endLineIndex = startLineIndex; result.append ( "#" + getFullCommentLine ( ) + "\n" ); result.append ( documentLines[++i] ); // "\tprint \"bar2\" \n" // Our expected result IDocument resultDoc = new Document ( result.toString ( ) ); // For timing data long begin = System.currentTimeMillis ( ); PySelection ps = new PySelection ( document, startLineIndex, endLineIndex, selLength, false ); PyAddBlockComment.perform ( ps ); long end = System.currentTimeMillis ( ); // Timing result System.err.print ( TestFileName + " :: " ); System.err.println ( "testPerform3: " + ( end - begin ) + "ms" ); // Document affected properly? assertEquals ( document.get ( ), resultDoc.get ( ) ); } } --- NEW FILE: PyConvertSpaceToTabTest.java --- /* * Created on Jun 21, 2004 * * To change the template for this generated file go to * Window>Preferences>Java>Code Generation>Code and Comments */ package test; import org.eclipse.jface.text.Document; import org.eclipse.jface.text.IDocument; import org.python.pydev.editor.actions.PyConvertSpaceToTab; import org.python.pydev.editor.actions.PySelection; import org.python.pydev.editor.actions.PyStripTrailingWhitespace; import junit.framework.TestCase; /** * @author Dreamer * * Tests the 'Convert Space To Tab' editor feature. It performs 3 checks. * * The first fakes a selection of a couple lines in a fake document, and checks * to see that the proper spaces are converted to tabs. * * The second fakes a selection but stops in the middle of a line, to make sure that the * whole line is considered. * * The third selects nothing, and makes sure that the whole document is affected by * the conversion. */ public class PyConvertSpaceToTabTest extends TestCase { /* The document that will fake an editor environment */ IDocument document; /* Lines of 'code' in the fake document */ String [] documentLines; /* For my own debugging edification, to output the name later */ static final String TestFileName = "PyConvertSpaceToTabTest"; /** * Constructor for PyConvertSpaceToTabTest. * @param arg0 */ public PyConvertSpaceToTabTest(String arg0) { super(arg0); } /* * Sets up the document 'code' and adds it to the document. * * @see TestCase#setUp() */ protected void setUp() throws Exception { super.setUp(); int i = -1; int length = 7; documentLines = new String[length]; // The X will be used to interchange tabs/spaces documentLines[++i] = "def bar ( self ):"; documentLines[++i] = "X" + "print \"foo1\"X "; documentLines[++i] = "X" + "print \"bar1\""; documentLines[++i] = "X "; documentLines[++i] = "def foo ( self ):X"; documentLines[++i] = "X" + "print \"foo2\"X "; documentLines[++i] = "X" + "print \"bar2\" "; StringBuffer doc = new StringBuffer ( ); for ( i = 0; i < documentLines.length; i++ ) { doc.append ( documentLines[i] + ( i < documentLines.length - 1 ? "\n" : "" ) ); } document = new Document ( doc.toString ( ) ); } /* * @see TestCase#tearDown() */ protected void tearDown() throws Exception { super.tearDown(); } /* * Just for this and the vice versa case, to make things easier * * @return String Space string */ public String from ( ) { return PyConvertSpaceToTab.getTabSpace ( ); } /* * Just for this and the vice versa case, to make things easier * * @return String Tab string */ public String to ( ) { return "\t"; } /* * Just to shorten the lines in the later tests, this calls the action's get tab width * function * * @return int Tab width */ public int getTabWidth ( ) { return PyConvertSpaceToTab.getTabWidth ( ); } /* * Just to shorten the lines in the later tests, this calls the action's trim function * * @param in Line of 'code' to be stripped * @return String Stripped 'code' line */ public String callTrim ( String in ) { return PyStripTrailingWhitespace.trimTrailingWhitespace ( in ); } /* * Checks multiple-line selection. */ public void testPerform1 ( ) { StringBuffer result = new StringBuffer ( ); int i = -1; int startLineIndex = 0; int endLineIndex = 0; int selBegin = 0; int selLength = 0; // 'Select' the entire last def String [] strArr = document.get ( ).replaceAll ( "X", from ( ) ).split ( "\n" ); int len = 0; len += strArr[++i].length ( ) + 1; // "def bar ( self ):\n" len += strArr[++i].length ( ) + 1; // "\tprint \"foo1\"\t \n" len += strArr[++i].length ( ) + 1; // "\tprint \"bar1\"\n" len += strArr[++i].length ( ) + 1; // "\n \n" startLineIndex = i + 1; selBegin = len; len += strArr[++i].length ( ) + 1; // "def foo ( self ): len += strArr[++i].length ( ) + 1; // "\tprint \"foo2\"\t \n" len += strArr[++i].length ( ); // "\tprint \"bar2\" \n" endLineIndex = i; selLength = len - selBegin; // Create result document i = -1; result.append ( documentLines[++i].replaceAll ( "X", from ( ) ) + "\n" ); result.append ( documentLines[++i].replaceAll ( "X", from ( ) ) + "\n" ); result.append ( documentLines[++i].replaceAll ( "X", from ( ) ) + "\n" ); result.append ( documentLines[++i].replaceAll ( "X", from ( ) ) + "\n" ); result.append ( documentLines[++i].replaceAll ( "X", to ( ) ) + "\n" ); result.append ( documentLines[++i].replaceAll ( "X", to ( ) ) + "\n" ); result.append ( documentLines[++i].replaceAll ( "X", to ( ) ) ); // Our expected result IDocument resultDoc = new Document ( result.toString ( ) ); // For timing data document.set ( document.get ( ).replaceAll ( "X", from ( ) ) ); long begin = System.currentTimeMillis ( ); PySelection ps = new PySelection ( document, startLineIndex, endLineIndex, selLength, true ); PyConvertSpaceToTab.perform ( ps ); long end = System.currentTimeMillis ( ); // Timing result System.err.print ( TestFileName + " :: " ); System.err.println ( "testPerform1: " + ( end - begin ) + "ms" ); // Document affected properly? assertEquals ( document.get ( ), resultDoc.get ( ) ); } /* * Checks multiple-line selection with the last line partially selected. */ public void testPerform2 ( ) { StringBuffer result = new StringBuffer ( ); int i = -1; int startLineIndex = 0; int endLineIndex = 0; int selBegin = 0; int selLength = 0; // 'Select' the entire last def String [] strArr = document.get ( ).replaceAll ( "X", from ( ) ).split ( "\n" ); int len = 0; len += strArr[++i].length ( ) + 1; // "def bar ( self ):\n" len += strArr[++i].length ( ) + 1; // "\tprint \"foo1\"\t \n" len += strArr[++i].length ( ) + 1; // "\tprint \"bar1\"\n" len += strArr[++i].length ( ) + 1; // "\n \n" startLineIndex = i + 1; selBegin = len; len += strArr[++i].length ( ) + 1; // "def foo ( self ): len += strArr[++i].length ( ) + 1; // "\tprint \"foo2\"\t \n" len += strArr[++i].length ( ); // "\tprint \"bar2\" \n" endLineIndex = i; selLength = len - selBegin - 6; // Create result document i = -1; result.append ( documentLines[++i].replaceAll ( "X", from ( ) ) + "\n" ); result.append ( documentLines[++i].replaceAll ( "X", from ( ) ) + "\n" ); result.append ( documentLines[++i].replaceAll ( "X", from ( ) ) + "\n" ); result.append ( documentLines[++i].replaceAll ( "X", from ( ) ) + "\n" ); result.append ( documentLines[++i].replaceAll ( "X", to ( ) ) + "\n" ); result.append ( documentLines[++i].replaceAll ( "X", to ( ) ) + "\n" ); result.append ( documentLines[++i].replaceAll ( "X", to ( ) ) ); // Our expected result IDocument resultDoc = new Document ( result.toString ( ) ); // For timing data document.set ( document.get ( ).replaceAll ( "X", from ( ) ) ); long begin = System.currentTimeMillis ( ); PySelection ps = new PySelection ( document, startLineIndex, endLineIndex, selLength, true ); PyConvertSpaceToTab.perform ( ps ); long end = System.currentTimeMillis ( ); // Timing result System.err.print ( TestFileName + " :: " ); System.err.println ( "testPerform2: " + ( end - begin ) + "ms" ); // Document affected properly? assertEquals ( document.get ( ), resultDoc.get ( ) ); } /* * Checks empty selection to affect cursor line. */ public void testPerform3 ( ) { StringBuffer result = new StringBuffer ( ); int i = -1; int startLineIndex = 0; int endLineIndex = 0; int selBegin = 0; int selLength = 0; // 'Select' the entire last def startLineIndex = endLineIndex = 1; selBegin = 1; selLength = 0; // Our expected result IDocument resultDoc = new Document ( document.get ( ).toString ( ).replaceAll ( "X", to ( ) ) ); // For timing data document.set ( document.get ( ).replaceAll ( "X", from ( ) ) ); long begin = System.currentTimeMillis ( ); PySelection ps = new PySelection ( document, startLineIndex, endLineIndex, selLength, true ); PyConvertSpaceToTab.perform ( ps ); long end = System.currentTimeMillis ( ); // Timing result System.err.print ( TestFileName + " :: " ); System.err.println ( "testPerform3: " + ( end - begin ) + "ms" ); // Document affected properly? assertEquals ( document.get ( ), resultDoc.get ( ) ); } } |