KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > edu > rice > cs > drjava > model > definitions > IndentTest


1 /*BEGIN_COPYRIGHT_BLOCK
2  *
3  * This file is part of DrJava. Download the current version of this project from http://www.drjava.org/
4  * or http://sourceforge.net/projects/drjava/
5  *
6  * DrJava Open Source License
7  *
8  * Copyright (C) 2001-2006 JavaPLT group at Rice University (javaplt@rice.edu). All rights reserved.
9  *
10  * Developed by: Java Programming Languages Team, Rice University, http://www.cs.rice.edu/~javaplt/
11  *
12  * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
13  * documentation files (the "Software"), to deal with the Software without restriction, including without limitation
14  * the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and
15  * to permit persons to whom the Software is furnished to do so, subject to the following conditions:
16  *
17  * - Redistributions of source code must retain the above copyright notice, this list of conditions and the
18  * following disclaimers.
19  * - Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the
20  * following disclaimers in the documentation and/or other materials provided with the distribution.
21  * - Neither the names of DrJava, the JavaPLT, Rice University, nor the names of its contributors may be used to
22  * endorse or promote products derived from this Software without specific prior written permission.
23  * - Products derived from this software may not be called "DrJava" nor use the term "DrJava" as part of their
24  * names without prior written permission from the JavaPLT group. For permission, write to javaplt@rice.edu.
25  *
26  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO
27  * THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
28  * CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
29  * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
30  * WITH THE SOFTWARE.
31  *
32  *END_COPYRIGHT_BLOCK*/

33
34 package edu.rice.cs.drjava.model.definitions;
35
36 import junit.framework.*;
37 import javax.swing.text.BadLocationException JavaDoc;
38 //import java.io.File;
39
//import java.io.FileReader;
40
//import java.io.BufferedReader;
41
//import java.io.IOException;
42

43 import edu.rice.cs.drjava.DrJava;
44 import edu.rice.cs.drjava.DrJavaTestCase;
45 import edu.rice.cs.drjava.model.DJDocument;
46 import edu.rice.cs.drjava.model.definitions.reducedmodel.*;
47 import edu.rice.cs.drjava.config.*;
48 import edu.rice.cs.drjava.model.definitions.indent.*;
49 import edu.rice.cs.drjava.model.GlobalEventNotifier;
50 //import edu.rice.cs.util.FileOps;
51
import edu.rice.cs.util.swing.Utilities;
52
53 /**
54  * Test the tab/enter/squiggly indenting functionality.
55  * @version $Id: IndentTest.java 3901 2006-06-30 05:28:11Z rcartwright $
56  */

57 public final class IndentTest extends DrJavaTestCase {
58   protected DefinitionsDocument doc;
59
60   static String JavaDoc noBrace = IndentInfo.noBrace;
61   static String JavaDoc openSquiggly = IndentInfo.openSquiggly;
62   static String JavaDoc openParen = IndentInfo.openParen;
63   static String JavaDoc openBracket = IndentInfo.openBracket;
64   private Integer JavaDoc indentLevel = new Integer JavaDoc(2);
65   private GlobalEventNotifier _notifier;
66
67   /**
68    * Tests the indent operation.
69    * @param name {@inheritDoc}
70    */

71   public IndentTest(String JavaDoc name) { super(name); }
72
73   /** Sets up the member bindings common to all tests. */
74   public void setUp() throws Exception JavaDoc {
75     super.setUp();
76     DrJava.getConfig().resetToDefaults();
77     _notifier = new GlobalEventNotifier();
78     doc = new DefinitionsDocument(_notifier);
79     DrJava.getConfig().setSetting(OptionConstants.INDENT_LEVEL,indentLevel);
80   }
81   
82   /** Builds the suite of tests for Indent.class.
83    * @return the suite.
84    */

85   public static Test suite() { return new TestSuite(IndentTest.class); }
86
87   /** Regression test for comment portion of indent tree. */
88   public void testIndentComments() throws BadLocationException JavaDoc {
89     String JavaDoc text =
90       " foo();\n" +
91       " // foo\n" +
92       "/**\n" +
93       "\n" +
94       "* Comment\n" +
95       " * More comment\n" +
96       "code;\n" +
97       "* More comment\n" +
98       "\n" +
99       "*/\n" +
100       "\n";
101
102     String JavaDoc indented =
103       " foo();\n" + // (skip this line)
104
" // foo\n" + // align to start of statement
105
" /**\n" + // start of statement
106
" * \n" + // add a star after first line
107
" * Comment\n" + // align to star
108
" * More comment\n" + // align to star
109
" code;\n" + // align commented code to stars
110
" * More comment\n" + // align star after commented code
111
" * \n" + // add a star after line with star
112
" */\n" + // align star
113
" \n"; // align close comment to prev statement
114

115     doc.insertString(0, text, null);
116     _assertContents(text, doc);
117     doc.indentLines(9, doc.getLength());
118     _assertContents(indented, doc);
119   }
120
121   /** Test case for SourceForge bug# 681203. */
122   public void testMultiLineStarInsertFirstLine() throws BadLocationException JavaDoc {
123     String JavaDoc text =
124       "/**\n" +
125       "comments here blah blah\n" +
126       " */";
127
128     String JavaDoc noStarAdded =
129       "/**\n" +
130       " comments here blah blah\n" +
131       " */";
132
133     String JavaDoc starAdded =
134       "/**\n" +
135       " * comments here blah blah\n" +
136       " */";
137
138     doc.insertString(0, text, null);
139     _assertContents(text, doc);
140     doc.gotoLine(2);
141     /* First test that indentation caused not by an enter press inserts no star */
142     doc._indentLine(Indenter.OTHER);
143     _assertContents(noStarAdded, doc);
144     /* Now test that indentation caused by an enter press does insert a star */
145     doc._indentLine(Indenter.ENTER_KEY_PRESS);
146     _assertContents(starAdded, doc);
147   }
148
149   /** Test case for SourceForge bug# 681203. */
150   public void testMultiLineStarInsertLaterLine() throws BadLocationException JavaDoc {
151
152     String JavaDoc text =
153       "/**\n" +
154       " * other comments\n" +
155       "comments here blah blah\n" +
156       " */";
157
158     String JavaDoc noStarAdded =
159       "/**\n" +
160       " * other comments\n" +
161       " comments here blah blah\n" +
162       " */";
163
164     String JavaDoc starAdded =
165       "/**\n" +
166       " * other comments\n" +
167       " * comments here blah blah\n" +
168       " */";
169
170     doc.insertString(0, text, null);
171     _assertContents(text, doc);
172     doc.gotoLine(3);
173     /* First test that indentation caused not by an enter press inserts no star */
174     doc._indentLine(Indenter.OTHER);
175     _assertContents(noStarAdded, doc);
176     /* Now test that indentation caused by an enter press does insert a star */
177     doc._indentLine(Indenter.ENTER_KEY_PRESS);
178     _assertContents(starAdded, doc);
179   }
180
181   /**
182    * Regression test for paren phrases.
183    */

184   public void testIndentParenPhrases() throws BadLocationException JavaDoc {
185     String JavaDoc text =
186       "foo(i,\n" +
187       "j.\n" +
188       "bar().\n" +
189       "// foo();\n" +
190       "baz(),\n" +
191       "cond1 ||\n" +
192       "cond2);\n" +
193       "i = myArray[x *\n" +
194       "y.\n" +
195       "foo() +\n" +
196       "z\n" +
197       "];\n";
198
199     String JavaDoc indented =
200       "foo(i,\n" +
201       " j.\n" + // new paren phrase
202
" bar().\n" + // not new paren phrase
203
"// foo();\n" + // not new
204
" baz(),\n" + // not new (after comment)
205
" cond1 ||\n" + // new
206
" cond2);\n" + // new (after operator)
207
"i = myArray[x *\n" + // new statement
208
" y.\n" + // new phrase
209
" foo() +\n" + // not new phrase
210
" z\n" + // new phrase
211
" ];\n"; // not new phrase (debatable)
212

213     doc.insertString(0, text, null);
214     _assertContents(text, doc);
215     doc.indentLines(0, doc.getLength());
216     _assertContents(indented, doc);
217   }
218
219   /**
220    * Regression test for braces.
221    */

222  public void testIndentBraces() throws BadLocationException JavaDoc {
223    String JavaDoc text =
224      "{\n" +
225      "class Foo\n" +
226      "extends F {\n" +
227      "int i; \n" +
228      "void foo() {\n" +
229      "if (true) {\n" +
230      "bar();\n" +
231      "}\n" +
232      "}\n" +
233      "/* comment */ }\n" +
234      "class Bar {\n" +
235      "/* comment\n" +
236      "*/ }\n" +
237      "int i;\n" +
238      "}\n";
239
240    String JavaDoc indented =
241      "{\n" +
242      " class Foo\n" + // After open brace
243
" extends F {\n" + // Not new statement
244
" int i; \n" + // After open brace
245
" void foo() {\n" + // After statement
246
" if (true) {\n" + // Nested brace
247
" bar();\n" + // Nested brace
248
" }\n" + // Close nested brace
249
" }\n" + // Close nested brace
250
" /* comment */ }\n" + // Close brace after comment
251
" class Bar {\n" + // After close brace
252
" /* comment\n" + // After open brace
253
" */ }\n" + // In comment
254
" int i;\n" + // After close brace
255
"}\n";
256
257
258    doc.insertString(0, text, null);
259    _assertContents(text, doc);
260    doc.indentLines(0, doc.getLength());
261    _assertContents(indented, doc);
262  }
263
264   /**
265    * Regression test for arrays.
266    */

267  public void testIndentArray() throws BadLocationException JavaDoc {
268    String JavaDoc text =
269      "int[2][] a ={\n" +
270      "{\n" +
271      "1,\n" +
272      "2,\n" +
273      "3},\n" +
274      "{\n" +
275      "4,\n" +
276      "5}\n" +
277      "};\n";
278
279    String JavaDoc indented =
280      "int[2][] a ={\n" +
281      " {\n" +
282      " 1,\n" +
283      " 2,\n" +
284      " 3},\n" +
285      " {\n" +
286      " 4,\n" +
287      " 5}\n" +
288      "};\n";
289
290
291
292
293    doc.insertString(0, text, null);
294    _assertContents(text, doc);
295    doc.indentLines(0, doc.getLength());
296    _assertContents(indented, doc);
297  }
298
299   /**
300    * Regression test for common cases.
301    */

302   public void testIndentCommonCases() throws BadLocationException JavaDoc {
303     String JavaDoc text =
304       "int x;\n" +
305       " int y;\n" +
306       " class Foo\n" +
307       " extends F\n" +
308       " {\n" +
309       " }";
310
311     String JavaDoc indented =
312       "int x;\n" +
313       "int y;\n" +
314       "class Foo\n" +
315       " extends F\n" +
316       "{\n" +
317       "}";
318
319     doc.insertString(0, text, null);
320     _assertContents(text, doc);
321     doc.indentLines(0, doc.getLength());
322     _assertContents(indented, doc);
323   }
324
325   /**
326    * Regression test for switch statements.
327    */

328   public void testIndentSwitch() throws BadLocationException JavaDoc {
329     String JavaDoc text =
330       "switch (x) {\n" +
331       "case 1:\n" +
332       "foo();\n" +
333       "break;\n" +
334       "case 2: case 3:\n" +
335       "case 4: case 5:\n" +
336       "bar();\n" +
337       "break;\n" +
338       "}\n";
339
340     String JavaDoc indented =
341       "switch (x) {\n" +
342       " case 1:\n" + // Starting new statement after brace
343
" foo();\n" + // Not new statement
344
" break;\n" + // Indent to prev statement
345
" case 2: case 3:\n" + // Case (indent to stmt of brace)
346
" case 4: case 5:\n" + // Case (not new stmt)
347
" bar();\n" + // Not new stmt
348
" break;\n" + // Indent to prev stmt
349
"}\n"; // Close brace
350

351
352     doc.insertString(0, text, null);
353     _assertContents(text, doc);
354     doc.indentLines(0, doc.getLength());
355     _assertContents(indented, doc);
356   }
357
358   /**
359    * Regression test for ternary operators.
360    */

361   public void testIndentTernary() throws BadLocationException JavaDoc {
362     String JavaDoc text =
363       "test1 = x ? y : z;\n" +
364       "test2 = x ? y :\n" +
365       "z;\n" +
366       "foo();\n" +
367       "test3 =\n" +
368       "x ?\n" +
369       "y :\n" +
370       "z;\n" +
371       "bar();\n" +
372       "test4 = (x ?\n" +
373       "y :\n" +
374       "z);\n";
375
376     String JavaDoc indented =
377       "test1 = x ? y : z;\n" + // ternary on one line
378
"test2 = x ? y :\n" + // ? and : on one line
379
" z;\n" + // unfinished ternary
380
"foo();\n" + // new stmt
381
"test3 =\n" + // new stmt
382
" x ?\n" + // not new stmt
383
" y :\n" + // : with ? in stmt
384
" z;\n" + // in ternary op
385
"bar();\n" + // new stmt
386
"test4 = (x ?\n" + // ternary in paren
387
" y :\n" + // : with ? in paren stmt
388
" z);\n"; // in ternary in paren
389

390
391     doc.insertString(0, text, null);
392     _assertContents(text, doc);
393     doc.indentLines(0, doc.getLength());
394     _assertContents(indented, doc);
395   }
396
397   /**
398    * put your documentation comment here
399    * @exception BadLocationException
400    */

401   public void testIndentInfoSquiggly() throws BadLocationException JavaDoc {
402     //empty document
403
BraceReduction _reduced = doc.getReduced();
404     IndentInfo ii = _reduced.getIndentInformation();
405     _assertIndentInfo(ii, noBrace, -1, -1, -1);
406     //single newline
407
doc.insertString(0, "\n", null);
408     _assertContents("\n", doc);
409     ii = _reduced.getIndentInformation();
410     _assertIndentInfo(ii, noBrace, -1, -1, 0);
411     //single layer brace
412
doc.insertString(0, "{\n\n", null);
413     // {\n\n#\n
414
_assertContents("{\n\n\n", doc);
415     ii = _reduced.getIndentInformation();
416     _assertIndentInfo(ii, openSquiggly, -1, 3, 0);
417     //another squiggly
418
doc.insertString(3, "{\n\n", null);
419     // {\n\n{\n\n#\n
420
_assertContents("{\n\n{\n\n\n", doc);
421     ii = _reduced.getIndentInformation();
422     _assertIndentInfo(ii, openSquiggly, 3, 3, 0);
423     //brace with whitespace
424
doc.insertString(6, " {\n\n", null);
425     // {\n\n{\n\n {\n\n#\n
426
_assertContents("{\n\n{\n\n {\n\n\n", doc);
427     ii = _reduced.getIndentInformation();
428     _assertIndentInfo(ii, openSquiggly, 5, 3, 0);
429   }
430
431   /**
432    * put your documentation comment here
433    * @exception BadLocationException
434    */

435   public void testIndentInfoParen() throws BadLocationException JavaDoc {
436     // just paren
437
BraceReduction _reduced = doc.getReduced();
438     doc.insertString(0, "\n(\n", null);
439     IndentInfo ii = _reduced.getIndentInformation();
440     _assertIndentInfo(ii, openParen, 2, 2, 0);
441     // paren with stuff in front
442
doc.insertString(1, " helo ", null);
443     doc.move(2);
444     // \n helo (\n#
445
_assertContents("\n helo (\n", doc);
446     ii = _reduced.getIndentInformation();
447     _assertIndentInfo(ii, openParen, 9, 2, 0);
448     //single layer brace
449
doc.move(-1);
450     doc.insertString(9, " (", null);
451     doc.move(1);
452     // \n helo ( (\n#
453
_assertContents("\n helo ( (\n", doc);
454     ii = _reduced.getIndentInformation();
455     _assertIndentInfo(ii, openParen, 11, 2, 0);
456   }
457
458   /**
459    * put your documentation comment here
460    * @exception BadLocationException
461    */

462   public void testIndentInfoBracket() throws BadLocationException JavaDoc {
463     // just bracket
464
BraceReduction _reduced = doc.getReduced();
465     doc.insertString(0, "\n[\n", null);
466     IndentInfo ii = _reduced.getIndentInformation();
467     _assertIndentInfo(ii, openBracket, 2, 2, 0);
468     // bracket with stuff in front
469
doc.insertString(1, " helo ", null);
470     doc.move(2);
471     // \n helo (\n#
472
_assertContents("\n helo [\n", doc);
473     ii = _reduced.getIndentInformation();
474     _assertIndentInfo(ii, openBracket, 9, 2, 0);
475     //single layer brace
476
doc.move(-1);
477     doc.insertString(9, " [", null);
478     doc.move(1);
479     // \n helo ( (\n#
480
_assertContents("\n helo [ [\n", doc);
481     ii = _reduced.getIndentInformation();
482     _assertIndentInfo(ii, openBracket, 11, 2, 0);
483   }
484
485   /**
486    * put your documentation comment here
487    * @exception BadLocationException
488    */

489   public void testIndentInfoPrevNewline () throws BadLocationException JavaDoc {
490     BraceReduction _reduced = doc.getReduced();
491     doc.insertString(0, "{\n {\nhello", null);
492     // {\n {\nhello#
493
IndentInfo ii = _reduced.getIndentInformation();
494     _assertIndentInfo(ii, openSquiggly, 9, 7, 5);
495   }
496
497   /**
498    * put your documentation comment here
499    * @exception BadLocationException
500    */

501   public void testEndOfBlockComment () throws BadLocationException JavaDoc {
502     doc.insertString(0, "\n{\n hello;\n /*\n hello\n */", null);
503     doc.indentLines(doc.getCurrentLocation(), doc.getCurrentLocation());
504     _assertContents("\n{\n hello;\n /*\n hello\n */", doc);
505   }
506
507   /**
508    * put your documentation comment here
509    * @exception BadLocationException
510    */

511   public void testAfterBlockComment () throws BadLocationException JavaDoc {
512     doc.insertString(0, "\n{\n hello;\n /*\n hello\n */\nhello", null);
513     doc.indentLines(doc.getCurrentLocation(), doc.getCurrentLocation());
514     _assertContents("\n{\n hello;\n /*\n hello\n */\n hello", doc);
515   }
516
517   /**
518    * put your documentation comment here
519    * @exception BadLocationException
520    */

521   public void testAfterBlockComment3 () throws BadLocationException JavaDoc {
522     doc.insertString(0, "\n{\n hello;\n /*\n hello\n grr*/\nhello", null);
523     doc.indentLines(doc.getCurrentLocation(), doc.getCurrentLocation());
524     _assertContents("\n{\n hello;\n /*\n hello\n grr*/\n hello", doc);
525   }
526
527   /**
528    * put your documentation comment here
529    * @exception BadLocationException
530    */

531   public void testAfterBlockComment4 () throws BadLocationException JavaDoc {
532     doc.insertString(0, "\n{\n hello;\n /*\n hello\n */ hello", null);
533     doc.indentLines(doc.getCurrentLocation(), doc.getCurrentLocation());
534     _assertContents("\n{\n hello;\n /*\n hello\n */ hello", doc);
535   }
536
537   /**
538    * put your documentation comment here
539    * @exception BadLocationException
540    */

541   public void testAfterBlockComment2 () throws BadLocationException JavaDoc {
542     doc.insertString(0, "\n{\n hello;\n /*\n hello\n */ (\nhello", null);
543     doc.indentLines(doc.getCurrentLocation(), doc.getCurrentLocation());
544     _assertContents("\n{\n hello;\n /*\n hello\n */ (\n hello", doc);
545   }
546
547   /**
548    * put your documentation comment here
549    * @exception BadLocationException
550    */

551   public void testIndentInfoBlockComments () throws BadLocationException JavaDoc {
552     BraceReduction _reduced = doc.getReduced();
553     doc.insertString(0, "(\n /*\n*\n", null);
554     // (\n/*\n*#\n
555
_reduced.move(-1);
556     IndentInfo ii = _reduced.getIndentInformation();
557     _assertIndentInfo(ii, openParen, -1, 7, 1);
558   }
559
560   /**
561    * put your documentation comment here
562    * @exception BadLocationException
563    */

564   public void testIndentInfoBlockComments2 () throws BadLocationException JavaDoc {
565     BraceReduction _reduced = doc.getReduced();
566     doc.insertString(0, "\n(\n /*\n*\n", null);
567     // \n(\n/*\n*#\n
568
_reduced.move(-1);
569     IndentInfo ii = _reduced.getIndentInformation();
570     _assertIndentInfo(ii, openParen, 7, 7, 1);
571   }
572
573   /**
574    * put your documentation comment here
575    * @exception BadLocationException
576    */

577   public void testIndentInfoBlockComments3 () throws BadLocationException JavaDoc {
578     BraceReduction _reduced = doc.getReduced();
579     doc.insertString(0, "{\n /*\n*\n", null);
580     // (\n/*\n*#\n
581
_reduced.move(-1);
582     IndentInfo ii = _reduced.getIndentInformation();
583     _assertIndentInfo(ii, openSquiggly, -1, 8, 1);
584   }
585
586   /**
587    * put your documentation comment here
588    * @exception BadLocationException
589    */

590   public void testIndentInfoBlockComments4 () throws BadLocationException JavaDoc {
591     BraceReduction _reduced = doc.getReduced();
592     doc.insertString(0, "\n{\n /*\n*\n", null);
593     // \n(\n/*\n*#\n
594
_reduced.move(-1);
595     IndentInfo ii = _reduced.getIndentInformation();
596     _assertIndentInfo(ii, openSquiggly, 8, 8, 1);
597   }
598
599   /**
600    * put your documentation comment here
601    * @exception BadLocationException
602    */

603   public void testSkippingBraces () throws BadLocationException JavaDoc {
604     BraceReduction _reduced = doc.getReduced();
605     doc.insertString(0, "\n{\n { ()}\n}", null);
606     IndentInfo ii = _reduced.getIndentInformation();
607     _assertIndentInfo(ii, openSquiggly, 12, 12, 1);
608   }
609
610   /**
611    * put your documentation comment here
612    * @exception BadLocationException
613    */

614   public void testSkippingComments () throws BadLocationException JavaDoc {
615     // just paren
616
BraceReduction _reduced = doc.getReduced();
617     doc.insertString(0, "\n{\n //{ ()\n}", null);
618     IndentInfo ii = _reduced.getIndentInformation();
619     _assertIndentInfo(ii, openSquiggly, 13, 13, 1);
620   }
621
622   /**
623    * put your documentation comment here
624    * @exception BadLocationException
625    */

626   public void testSkippingCommentsBraceAtBeginning () throws BadLocationException JavaDoc {
627     // just paren
628
BraceReduction _reduced = doc.getReduced();
629     doc.insertString(0, "{\n //{ ()}{", null);
630     IndentInfo ii = _reduced.getIndentInformation();
631     _assertIndentInfo(ii, openSquiggly, -1, 13, 11);
632   }
633
634   /**
635    * put your documentation comment here
636    * @exception BadLocationException
637    */

638   public void testNothingToIndentOn () throws BadLocationException JavaDoc {
639     // just paren
640
BraceReduction _reduced = doc.getReduced();
641     doc.insertString(0, " //{ ()}{", null);
642     IndentInfo ii = _reduced.getIndentInformation();
643     _assertIndentInfo(ii, noBrace, -1, -1, -1);
644   }
645
646   /**
647    * put your documentation comment here
648    * @exception BadLocationException
649    */

650   public void testStartSimple () throws BadLocationException JavaDoc {
651     // just paren
652
doc.insertString(0, "abcde", null);
653     doc.indentLines(doc.getCurrentLocation(), doc.getCurrentLocation());
654     _assertContents("abcde", doc);
655   }
656
657   /**
658    * put your documentation comment here
659    * @exception BadLocationException
660    */

661   public void testStartSpaceIndent () throws BadLocationException JavaDoc {
662     // just paren
663
doc.insertString(0, " abcde", null);
664     doc.indentLines(doc.getCurrentLocation(), doc.getCurrentLocation());
665     _assertContents("abcde", doc);
666   }
667
668   /**
669    * put your documentation comment here
670    * @exception BadLocationException
671    */

672   public void testStartBrace () throws BadLocationException JavaDoc {
673     // just paren
674
doc.insertString(0, "public class temp \n {", null);
675     doc.indentLines(doc.getCurrentLocation(), doc.getCurrentLocation());
676     _assertContents("public class temp \n{", doc);
677   }
678
679   /**
680    * put your documentation comment here
681    * @exception BadLocationException
682    */

683   public void testEndBrace () throws BadLocationException JavaDoc {
684     // just paren
685
doc.insertString(0, "public class temp \n{ \n }", null);
686     doc.indentLines(doc.getCurrentLocation(), doc.getCurrentLocation());
687     _assertContents("public class temp \n{ \n}", doc);
688   }
689
690   /**
691    * put your documentation comment here
692    * @exception BadLocationException
693    */

694   public void testInsideClass () throws BadLocationException JavaDoc {
695     // just paren
696
doc.insertString(0, "public class temp \n{ \ntext here", null);
697     doc.indentLines(doc.getCurrentLocation(), doc.getCurrentLocation());
698     _assertContents("public class temp \n{ \n text here", doc);
699   }
700
701   /**
702    * put your documentation comment here
703    * @exception BadLocationException
704    */

705   public void testInsideClassWithBraceSets () throws BadLocationException JavaDoc {
706     // just paren
707
doc.insertString(0, "public class temp \n{ ()\ntext here", null);
708     doc.indentLines(doc.getCurrentLocation(), doc.getCurrentLocation());
709     _assertContents("public class temp \n{ ()\n text here", doc);
710   }
711
712   /**
713    * put your documentation comment here
714    * @exception BadLocationException
715    */

716   public void testIgnoreBraceOnSameLine () throws BadLocationException JavaDoc {
717     // just paren
718
doc.insertString(0, "public class temp \n{ ()\n{text here", null);
719     doc.indentLines(doc.getCurrentLocation(), doc.getCurrentLocation());
720     _assertContents("public class temp \n{ ()\n {text here", doc);
721   }
722
723   /**
724    * Not supported any more.
725    *
726   public void testLargerIndent () throws BadLocationException {
727     // just paren
728     BraceReduction rm = doc.getReduced();
729     doc.insertString(0, "public class temp \n { ()\n { text here", null);
730     doc.indentLines(doc.getCurrentLocation(), doc.getCurrentLocation());
731     _assertContents("public class temp \n { ()\n { text here", doc);
732   }*/

733
734   /**
735    * put your documentation comment here
736    * @exception BadLocationException
737    */

738   public void testWeird () throws BadLocationException JavaDoc {
739     // just paren
740
doc.insertString(0, "hello\n", null);
741     doc.indentLines(doc.getCurrentLocation(), doc.getCurrentLocation());
742     _assertContents("hello\n ", doc);
743   }
744
745   /**
746    * put your documentation comment here
747    * @exception BadLocationException
748    */

749   public void testWierd2 () throws BadLocationException JavaDoc {
750     // just paren
751
doc.insertString(0, "hello", null);
752     doc.indentLines(doc.getCurrentLocation(), doc.getCurrentLocation());
753     _assertContents("hello", doc);
754   }
755
756   /**
757    * put your documentation comment here
758    * @exception BadLocationException
759    */

760   public void testMotion () throws BadLocationException JavaDoc {
761     // just paren
762
doc.insertString(0, "hes{\n{abcde", null);
763     doc.insertString(11, "\n{", null);
764     // hes{\n{abcde\n{#
765
doc.move(-8);
766     // hes{\n#{abcde\n{
767
doc.indentLines(doc.getCurrentLocation(), doc.getCurrentLocation());
768     // hes{\n #{abcde\n{
769
_assertContents("hes{\n {abcde\n{", doc);
770   }
771
772   /**
773    * put your documentation comment here
774    * @exception BadLocationException
775    */

776   public void testNextCharIsNewline () throws BadLocationException JavaDoc {
777     // just paren
778
doc.insertString(0, "hes{\n{abcde", null);
779     doc.insertString(11, "\n{", null);
780     // hes{\n{abcde\n{#
781
doc.move(-2);
782     // hes{\n{abcde#\n{
783
doc.indentLines(doc.getCurrentLocation(), doc.getCurrentLocation());
784     // hes{\n {abcde#\n{
785
_assertContents("hes{\n {abcde\n{", doc);
786   }
787
788   /**
789    * put your documentation comment here
790    * @exception BadLocationException
791    */

792   public void testFor () throws BadLocationException JavaDoc {
793     // just paren
794
doc.insertString(0, "for(;;)\n", null);
795     doc.indentLines(doc.getCurrentLocation(), doc.getCurrentLocation());
796     _assertContents("for(;;)\n ", doc);
797   }
798
799   /**
800    * put your documentation comment here
801    * @exception BadLocationException
802    */

803   public void testFor2 () throws BadLocationException JavaDoc {
804     // just paren
805
doc.insertString(0, "{\n for(;;)\n", null);
806     doc.indentLines(doc.getCurrentLocation(), doc.getCurrentLocation());
807     _assertContents("{\n for(;;)\n ", doc);
808   }
809
810   /**
811    * put your documentation comment here
812    * @exception BadLocationException
813    */

814   public void testOpenParen () throws BadLocationException JavaDoc {
815     // just paren
816
doc.insertString(0, "hello(\n", null);
817     doc.indentLines(doc.getCurrentLocation(), doc.getCurrentLocation());
818     _assertContents("hello(\n ", doc);
819   }
820
821   /**
822    * put your documentation comment here
823    * @exception BadLocationException
824    */

825   public void testPrintString () throws BadLocationException JavaDoc {
826     // just paren
827
doc.insertString(0, "Sys.out(\"hello\"\n", null);
828     doc.indentLines(doc.getCurrentLocation(), doc.getCurrentLocation());
829     _assertContents("Sys.out(\"hello\"\n ", doc);
830   }
831
832   /**
833    * put your documentation comment here
834    * @exception BadLocationException
835    */

836   public void testOpenBracket () throws BadLocationException JavaDoc {
837     // just paren
838
doc.insertString(0, "hello[\n", null);
839     doc.indentLines(doc.getCurrentLocation(), doc.getCurrentLocation());
840     _assertContents("hello[\n ", doc);
841   }
842
843   /**
844    * put your documentation comment here
845    * @exception BadLocationException
846    */

847   public void testSquigglyAlignment () throws BadLocationException JavaDoc {
848     // just paren
849
doc.insertString(0, "{\n }", null);
850     doc.indentLines(doc.getCurrentLocation(), doc.getCurrentLocation());
851     _assertContents("{\n}", doc);
852   }
853
854   /**
855    * put your documentation comment here
856    * @exception BadLocationException
857    */

858   public void testSpaceBrace () throws BadLocationException JavaDoc {
859     // just paren
860
doc.insertString(0, " {\n", null);
861     doc.indentLines(doc.getCurrentLocation(), doc.getCurrentLocation());
862     _assertContents(" {\n ", doc);
863   }
864
865   /**
866    * Cascading indent is not used anymore.
867    *
868   public void testOpenSquigglyCascade () throws BadLocationException {
869     // just paren
870     BraceReduction rm = doc.getReduced();
871     doc.insertString(0, "if\n if\n if\n{", null);
872     doc.indentLines(doc.getCurrentLocation(), doc.getCurrentLocation());
873     _assertContents("if\n if\n if\n {", doc);
874   }*/

875
876   /**
877    * Cascading indent is not used anymore.
878    *
879   public void testOpenSquigglyCascade2 () throws BadLocationException {
880     // just paren
881     BraceReduction rm = doc.getReduced();
882     doc.insertString(0, "{\n if\n if\n if\n{", null);
883     doc.indentLines(doc.getCurrentLocation(), doc.getCurrentLocation());
884     _assertContents("{\n if\n if\n if\n {", doc);
885   }*/

886
887   /**
888    * put your documentation comment here
889    * @exception BadLocationException
890    */

891   public void testEnter () throws BadLocationException JavaDoc {
892     // just paren
893
doc.insertString(0, "\n\n", null);
894     doc.indentLines(doc.getCurrentLocation(), doc.getCurrentLocation());
895     _assertContents("\n\n", doc);
896   }
897
898   /**
899    * put your documentation comment here
900    * @exception BadLocationException
901    */

902   public void testEnter2 () throws BadLocationException JavaDoc {
903     // just paren
904
doc.insertString(0, "\n", null);
905     doc.indentLines(doc.getCurrentLocation(), doc.getCurrentLocation());
906     _assertContents("\n", doc);
907   }
908
909   /**
910    * put your documentation comment here
911    * @exception BadLocationException
912    */

913   public void testNotRecognizeComments () throws BadLocationException JavaDoc {
914     // just paren
915
doc.insertString(0, "\nhello //bal;\n", null);
916     doc.indentLines(doc.getCurrentLocation(), doc.getCurrentLocation());
917     _assertContents("\nhello //bal;\n ", doc);
918   }
919
920   /**
921    * put your documentation comment here
922    * @exception BadLocationException
923    */

924   public void testNotRecognizeComments2 () throws BadLocationException JavaDoc {
925     // just paren
926
doc.insertString(0, "\nhello; /*bal*/\n ", null);
927     doc.indentLines(doc.getCurrentLocation(), doc.getCurrentLocation());
928     _assertContents("\nhello; /*bal*/\n", doc);
929   }
930
931   /**
932    * put your documentation comment here
933    * @exception BadLocationException
934    */

935   public void testBlockIndent () throws BadLocationException JavaDoc {
936     // just paren
937
doc.insertString(0, "hello\n{\n{\n {", null);
938     doc.indentLines(8, 13);
939     _assertContents("hello\n{\n {\n {", doc);
940   }
941
942   /**
943    * Regression test for bug in drjava-20010802-1020:
944    * Indent block on a file containing just " x;\n y;\n" would throw an
945    * exception.
946    * @exception BadLocationException
947    */

948   public void testBlockIndent2 () throws BadLocationException JavaDoc {
949     doc.insertString(0, " x;\n y;\n", null);
950     doc.indentLines(0, doc.getLength());
951     _assertContents("x;\ny;\n", doc);
952   }
953
954   /**
955    * put your documentation comment here
956    * @exception BadLocationException
957    */

958   public void testIndentInsideCommentBlock () throws BadLocationException JavaDoc {
959     doc.insertString(0, "hello\n{\n/*{\n{\n*/\nhehe", null);
960     doc.indentLines(0, 21);
961     _assertContents("hello\n{\n /*{\n {\n */\n hehe", doc);
962   }
963
964   /**
965    * put your documentation comment here
966    * @exception BadLocationException
967    */

968   public void testSecondLineProblem () throws BadLocationException JavaDoc {
969     // just paren
970
doc.insertString(0, "\n", null);
971     doc.indentLines(doc.getCurrentLocation(), doc.getCurrentLocation());
972     _assertContents("\n", doc);
973   }
974
975   /**
976    * put your documentation comment here
977    * @exception BadLocationException
978    */

979   public void testSecondLineProblem2 () throws BadLocationException JavaDoc {
980     // just paren
981
doc.insertString(0, "a\n", null);
982     doc.indentLines(doc.getCurrentLocation(), doc.getCurrentLocation());
983     _assertContents("a\n ", doc);
984   }
985
986   /**
987    * put your documentation comment here
988    * @exception BadLocationException
989    */

990   public void testSmallFileProblem () throws BadLocationException JavaDoc {
991     // just paren
992
doc.insertString(0, "\n\n", null);
993     doc.indentLines(doc.getCurrentLocation(), doc.getCurrentLocation());
994     _assertContents("\n\n", doc);
995   }
996
997   /**
998    * Regression test for arrays.
999    */

1000  public void testAnonymousInnerClass() throws BadLocationException JavaDoc {
1001    String JavaDoc text =
1002      "addWindowListener(new WindowAdapter() {\n" +
1003      "public void windowClosing(WindowEvent e) {\n" +
1004      "dispose();\n" +
1005      "}\n" +
1006      "void x() {\n" +
1007      "\n" +
1008      "}\n" +
1009      "\n" +
1010      "}\n" +
1011      ");\n";
1012    String JavaDoc indented =
1013      "addWindowListener(new WindowAdapter() {\n" +
1014      " public void windowClosing(WindowEvent e) {\n" +
1015      " dispose();\n" +
1016      " }\n" +
1017      " void x() {\n" +
1018      " \n" +
1019      " }\n" +
1020      " \n" +
1021      "}\n" +
1022      ");\n";
1023
1024
1025    doc.insertString(0, text, null);
1026    _assertContents(text, doc);
1027    doc.indentLines(0, doc.getLength());
1028    _assertContents(indented, doc);
1029  }
1030
1031
1032// /** Regression test for Bug #627753. Uncomment when it is fixed.
1033
// */
1034
// public void testNestedUnbracedFor() throws BadLocationException {
1035
// String text =
1036
// "for (int a =0; a < 5; a++)\n" +
1037
// "for (int b = 0; b < 5; b++) {\n" +
1038
// "System.out.println(a + b);";
1039
// String indented =
1040
// "for (int a =0; a < 5; a++)\n" +
1041
// " for (int b = 0; b < 5; b++) {\n" +
1042
// " System.out.println(a + b);";
1043
// doc.insertString(0, text, null);
1044
// _assertContents(text, doc);
1045
// doc.indentLines(0, doc.getLength());
1046
// _assertContents(indented, doc);
1047
// doc.remove(0,doc.getLength() - 1);
1048
//
1049
// text =
1050
// "if (true)\n" +
1051
// "if (true)\n" +
1052
// "System.out.println(\"Hello\");";
1053
// indented =
1054
// "if (true)\n" +
1055
// " if (true)\n" +
1056
// " System.out.println(\"Hello\");";
1057
// doc.insertString(0, text, null);
1058
// _assertContents(text, doc);
1059
// doc.indentLines(0, doc.getLength());
1060
// _assertContents(indented, doc);
1061
// doc.remove(0,doc.getLength() - 1);
1062
//
1063
// text =
1064
// "{\n" +
1065
// "while (a < 5)\n" +
1066
// "while (b < 5) {\n" +
1067
// "System.out.println(a + b);";
1068
// indented =
1069
// "{\n" +
1070
// " while (a < 5)\n" +
1071
// " while (b < 5) {\n" +
1072
// " System.out.println(a + b);";
1073
// doc.insertString(0, text, null);
1074
// _assertContents(text, doc);
1075
// doc.indentLines(0, doc.getLength());
1076
// _assertContents(indented, doc);
1077
// doc.remove(0,doc.getLength() - 1);
1078
//
1079
// text =
1080
// "while (a < 5)\n" +
1081
// "while (b < 5);\n" +
1082
// "System.out.println(a + b);";
1083
// indented =
1084
// "while (a < 5)\n" +
1085
// " while (b < 5);\n" +
1086
// "System.out.println(a + b);";
1087
// doc.insertString(0, text, null);
1088
// _assertContents(text, doc);
1089
// doc.indentLines(0, doc.getLength());
1090
// _assertContents(indented, doc);
1091
// doc.remove(0,doc.getLength() - 1);
1092
//
1093
// text =
1094
// "do\n" +
1095
// "do\n" +
1096
// "x=5;\n" +
1097
// "while(false);\n" +
1098
// "while(false);\n";
1099
// indented =
1100
// "do\n" +
1101
// " do\n" +
1102
// " x=5;\n" +
1103
// " while(false);\n" +
1104
// "while(false);\n";
1105
// doc.insertString(0, text, null);
1106
// _assertContents(text, doc);
1107
// doc.indentLines(0, doc.getLength());
1108
// _assertContents(indented, doc);
1109
// doc.remove(0,doc.getLength() - 1);
1110
// }
1111

1112  public void testLiveUpdateOfIndentLevel() throws BadLocationException JavaDoc {
1113
1114    String JavaDoc text =
1115      "int[2][] a ={\n" +
1116      "{\n" +
1117      "1,\n" +
1118      "2,\n" +
1119      "3},\n" +
1120      "{\n" +
1121      "4,\n" +
1122      "5}\n" +
1123      "};\n";
1124
1125    String JavaDoc indentedBefore =
1126      "int[2][] a ={\n" +
1127      " {\n" +
1128      " 1,\n" +
1129      " 2,\n" +
1130      " 3},\n" +
1131      " {\n" +
1132      " 4,\n" +
1133      " 5}\n" +
1134      "};\n";
1135
1136    String JavaDoc indentedAfter =
1137      "int[2][] a ={\n" +
1138      " {\n" +
1139      " 1,\n" +
1140      " 2,\n" +
1141      " 3},\n" +
1142      " {\n" +
1143      " 4,\n" +
1144      " 5}\n" +
1145      "};\n";
1146
1147    doc.insertString(0, text, null);
1148
1149    _assertContents(text, doc);
1150    doc.indentLines(0, doc.getLength());
1151    _assertContents(indentedBefore, doc);
1152    DrJava.getConfig().setSetting(OptionConstants.INDENT_LEVEL, new Integer JavaDoc(8));
1153    
1154    Utilities.clearEventQueue();
1155    doc.indentLines(0, doc.getLength());
1156    _assertContents(indentedAfter, doc);
1157  }
1158
1159  /**
1160   * tests that an if statment nested in a switch will be indented properly
1161   * @throws BadLocationException
1162   */

1163  public void testNestedIfInSwitch() throws BadLocationException JavaDoc {
1164    String JavaDoc text =
1165      "switch(cond) {\n" +
1166      "case 1:\n" +
1167      "object.doStuff();\n" +
1168      "if(object.hasDoneStuff()) {\n" +
1169      "thingy.doOtherStuff();\n" +
1170      "lion.roar(\"raaargh\");\n" +
1171      "}\n" +
1172      "break;\n" +
1173      "}\n";
1174
1175    String JavaDoc indented =
1176      "switch(cond) {\n" +
1177      " case 1:\n" +
1178      " object.doStuff();\n" +
1179      " if(object.hasDoneStuff()) {\n" +
1180      " thingy.doOtherStuff();\n" +
1181      " lion.roar(\"raaargh\");\n" +
1182      " }\n" +
1183      " break;\n" +
1184      "}\n";
1185
1186    doc.insertString(0, text, null);
1187    _assertContents(text, doc);
1188    doc.indentLines(0, doc.getLength());
1189    _assertContents(indented, doc);
1190  }
1191
1192// Commented out because reference files are missing!
1193
// /** Tests a list of files when indented match their correct indentations */
1194
// public void testIndentationFromFile() throws IOException {
1195
// File directory = new File("testFiles");
1196
//
1197
// File[] unindentedFiles = {new File(directory, "IndentSuccesses.indent")
1198
// /*, new File(directory, "IndentProblems.indent")*/};
1199
// File[] correctFiles = {new File(directory, "IndentSuccessesCorrect.indent")
1200
// /*, new File(directory, "IndentProblemsCorrect.indent")*/};
1201
//
1202
// for (int x = 0; x < correctFiles.length; x++) {
1203
// _indentAndCompare(unindentedFiles[x], correctFiles[x]);
1204
// }
1205
//
1206
// //We know the following test file should (currently) fail, so we assert that it will fail to check
1207
// //our _indentAndCompare(...) function
1208
// boolean threwAFE = false;
1209
// try {
1210
// _indentAndCompare(new File(directory, "IndentProblems.indent"),
1211
// new File(directory, "IndentProblemsCorrect.indent"));
1212
// }
1213
// catch(AssertionFailedError afe) {
1214
// threwAFE = true;
1215
// }
1216
// if (!threwAFE) {
1217
// fail("_indentAndCompare should have failed for IndentProblems.indent");
1218
// }
1219
// }
1220

1221  public void testIndentingCorrectLine() throws BadLocationException JavaDoc {
1222    String JavaDoc test1 =
1223      "class A {\n" +
1224      " int a = 5;\n" +
1225      " }";
1226    
1227    String JavaDoc test1Correct =
1228      "class A {\n" +
1229      " int a = 5;\n" +
1230      "}";
1231    
1232    String JavaDoc test2 =
1233      " {\n" +
1234      " int a = 5;\n" +
1235      " }\n";
1236    
1237    String JavaDoc test2Correct =
1238      "{\n" +
1239      " int a = 5;\n" +
1240      " }\n";
1241    
1242    doc.insertString(0, test1, null);
1243    _assertContents(test1, doc);
1244    doc.setCurrentLocation(20);
1245    doc.indentLines(20,20);
1246// System.out.println("test1 = \n" + test1 + "\n length = " + test1.length());
1247
// System.out.println("test1 = \n" + doc.getText() + "\n length = " + doc.getLength());
1248
_assertContents(test1, doc);
1249    
1250    doc = new DefinitionsDocument(_notifier);
1251    
1252    doc.insertString(0, test1, null);
1253    _assertContents(test1, doc);
1254    doc.indentLines(28,28);
1255    _assertContents(test1Correct, doc);
1256    
1257    doc = new DefinitionsDocument(_notifier);
1258    
1259    doc.insertString(0, test2, null);
1260    _assertContents(test2, doc);
1261    doc.setCurrentLocation(5);
1262    doc.indentLines(5,5);
1263    _assertContents(test2Correct, doc);
1264  }
1265
1266  /**
1267   * tests that an if statment nested in a switch will be indented properly
1268   * this, as opposed to the previous test, does not have any code in that case
1269   * except the if statement
1270   * @throws BadLocationException
1271   */

1272/* public void testNestedIfInSwitch2() throws BadLocationException {
1273    String text =
1274      "switch(c) {\n" +
1275      "case 2:\n" +
1276      "break;\n" +
1277      "case 3:\n" +
1278      "if(owner.command() == ROLL_OVER) {\n" +
1279      "dog.rollOver();\n" +
1280      "}\n" +
1281      "break;\n" +
1282      "}\n";
1283
1284    String indented =
1285      "switch(c) {\n" +
1286      " case 2:\n" +
1287      " break;\n" +
1288      " case 3:\n" +
1289      " if(owner.command() == ROLL_OVER) {\n" +
1290      " dog.rollOver();\n" +
1291      " }\n" +
1292      " break;\n" +
1293      "}\n";
1294
1295    doc.insertString(0, text, null);
1296    _assertContents(text, doc);
1297    doc.indentLines(0, doc.getLength());
1298    _assertContents(indented, doc);
1299  }
1300*/

1301  private void _assertContents(String JavaDoc expected, DJDocument document) throws BadLocationException JavaDoc {
1302    assertEquals("document contents", expected, document.getText());
1303  }
1304
1305  private void _assertIndentInfo(IndentInfo ii, String JavaDoc braceType, int distToNewline, int distToBrace, int distToPrevNewline) {
1306    assertEquals("indent info: brace type", braceType, ii.braceType);
1307    assertEquals("indent info: dist to new line", distToNewline, ii.distToNewline);
1308    assertEquals("indent info: dist to brace", distToBrace, ii.distToBrace);
1309    assertEquals("indent info: dist to prev new line", distToPrevNewline, ii.distToPrevNewline);
1310  }
1311
1312// /** Copies fromFile to toFile, assuming both files exist. */
1313
// private void _copyFile(File fromFile, File toFile) throws IOException {
1314
// String text = FileOps.readFileAsString(fromFile);
1315
// FileOps.writeStringToFile(toFile, text);
1316
// String newText = FileOps.readFileAsString(toFile);
1317
// assertEquals("File copy verify", text, newText);
1318
// }
1319

1320// /**
1321
// * indents one file, compares it to the other, reindents and recompares
1322
// * to make sure indent(x) = indent(indent(x))
1323
// */
1324
// private void _indentAndCompare(File unindented, File correct)
1325
// throws IOException
1326
// {
1327
// File test = null;
1328
// try {
1329
// test = File.createTempFile("test", ".java");
1330
// _copyFile(unindented, test);
1331
// test.deleteOnExit();
1332
// IndentFiles.main(new String[] {"-silent", test.toString()});
1333
// _fileCompare(test, correct);
1334
// IndentFiles.main(new String[] {"-silent", test.toString()});
1335
// _fileCompare(test, correct);
1336
// }
1337
// finally {
1338
// if (test != null) {
1339
// test.delete();
1340
// }
1341
// }
1342
//
1343
// }
1344

1345// /**
1346
// * @throws AssertionFailedError if the files are not identical
1347
// */
1348
// private void _fileCompare(File test, File correct) throws IOException {
1349
// FileReader fr = new FileReader(correct);
1350
// FileReader fr2 = new FileReader(test);
1351
// BufferedReader correctBufferedReader = new BufferedReader(fr);
1352
// BufferedReader testBufferedReader = new BufferedReader(fr2);
1353
//
1354
// String correctString = correctBufferedReader.readLine();
1355
// String testString = testBufferedReader.readLine();
1356
// int lineNo = 1;
1357
// while (correctString != null && testString != null) {
1358
// assertEquals("File: " + correct + " line: " + lineNo, correctString, testString);
1359
// correctString = correctBufferedReader.readLine();
1360
// testString = testBufferedReader.readLine();
1361
// lineNo++;
1362
// }
1363
// assertTrue("Indented file longer than expected", correctString == null);
1364
// assertTrue("Indented file shorter than expected", testString == null);
1365
//
1366
// testBufferedReader.close();
1367
// correctBufferedReader.close();
1368
// fr.close();
1369
// fr2.close();
1370
// }
1371

1372/*
1373  public void testNoParameters() throws BadLocationException
1374  {
1375    IndentRuleAction _action = new ActionBracePlus("");
1376
1377    String _text =
1378      "method(\n"+
1379      ")\n";
1380
1381    String _aligned =
1382      "method(\n"+
1383      " )\n";
1384
1385    doc.insertString(0, _text, null);
1386    _action.indentLine(doc, 0); // Does nothing.
1387    assertEquals("START has no brace.", _text.length(), doc.getLength());
1388    doc.indentLines(0, 7); // Does nothing.
1389    assertEquals("START has no brace.", _text.length(), doc.getLength());
1390
1391    doc.indentLines(0, doc.getLength()); // Aligns second line, a second time.
1392    System.out.println(doc.getText());
1393    _assertContents(_aligned, doc);
1394    assertEquals("Line aligned to open paren.", _aligned.length(), doc.getLength());
1395  }
1396*/

1397/*
1398  public void testArrayInit() throws BadLocationException
1399  {
1400    IndentRuleAction _action = new ActionBracePlus("");
1401
1402    String _text =
1403      "int[] ar = new int[] {\n"+
1404      "1,1,1,1,1,1,1,1,1 };";
1405
1406    String _aligned =
1407      "int[] ar = new int[] {\n"+
1408      " 1,1,1,1,1,1,1,1,1 };";
1409
1410    doc.insertString(0, _text, null);
1411    _action.indentLine(doc, 0); // Does nothing.
1412    assertEquals("START has no brace.", _text.length(), doc.getLength());
1413    doc.indentLines(0, 7); // Does nothing.
1414    assertEquals("START has no brace.", _text.length(), doc.getLength());
1415
1416    doc.indentLines(0, doc.getLength()); // Aligns second line, a second time.
1417    System.out.println(doc.getText());
1418    _assertContents(_aligned, doc);
1419    assertEquals("Line aligned to open paren.", _aligned.length(), doc.getLength());
1420  }
1421*/

1422/*
1423  public void testArrayInitNewline() throws BadLocationException
1424  {
1425    IndentRuleAction _action = new ActionBracePlus("");
1426
1427    String _text =
1428      "int[] ar = new int[] { 1,1,1,\n"+
1429      "1,1,1,1,1,1 };";
1430
1431    String _aligned =
1432      "int[] ar = new int[] { 1,1,1,\n"+
1433      " 1,1,1,1,1,1 };";
1434
1435    doc.insertString(0, _text, null);
1436    _action.indentLine(doc, 0); // Does nothing.
1437    assertEquals("START has no brace.", _text.length(), doc.getLength());
1438    doc.indentLines(0, 7); // Does nothing.
1439    assertEquals("START has no brace.", _text.length(), doc.getLength());
1440
1441    doc.indentLines(0, doc.getLength()); // Aligns second line, a second time.
1442    System.out.println(doc.getText());
1443    _assertContents(_aligned, doc);
1444    assertEquals("Line aligned to open paren.", _aligned.length(), doc.getLength());
1445  }
1446*/

1447/*
1448  public void testArrayInitBraceNewline() throws BadLocationException
1449  {
1450    IndentRuleAction _action = new ActionBracePlus("");
1451
1452    String _text =
1453      "int[] blah = new int[] {1, 2, 3\n"+
1454      "};";
1455
1456    String _aligned =
1457      "int[] blah = new int[] {1, 2, 3\n"+
1458      " };";
1459
1460    doc.insertString(0, _text, null);
1461    _action.indentLine(doc, 0); // Does nothing.
1462    assertEquals("START has no brace.", _text.length(), doc.getLength());
1463    doc.indentLines(0, 7); // Does nothing.
1464    assertEquals("START has no brace.", _text.length(), doc.getLength());
1465
1466    doc.indentLines(0, doc.getLength()); // Aligns second line, a second time.
1467    System.out.println(doc.getText());
1468    _assertContents(_aligned, doc);
1469    assertEquals("Line aligned to open paren.", _aligned.length(), doc.getLength());
1470  }
1471*/

1472/*
1473  public void testArrayInitAllNewline() throws BadLocationException
1474  {
1475    IndentRuleAction _action = new ActionBracePlus("");
1476
1477    String _text =
1478      "int[] blah = new int[]\n"+
1479      "{4, 5, 6};";
1480
1481    String _aligned =
1482      "int[] blah = new int[]\n"+
1483      " {4, 5, 6};";
1484
1485    doc.insertString(0, _text, null);
1486    _action.indentLine(doc, 0); // Does nothing.
1487    assertEquals("START has no brace.", _text.length(), doc.getLength());
1488    doc.indentLines(0, 7); // Does nothing.
1489    assertEquals("START has no brace.", _text.length(), doc.getLength());
1490
1491    doc.indentLines(0, doc.getLength()); // Aligns second line, a second time.
1492    System.out.println(doc.getText());
1493    _assertContents(_aligned, doc);
1494    assertEquals("Line aligned to open paren.", _aligned.length(), doc.getLength());
1495  }
1496*/

1497}
1498
Popular Tags