KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > edu > rice > cs > drjava > model > definitions > reducedmodel > IndentInfoTest


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-2005 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.reducedmodel;
35
36 import edu.rice.cs.drjava.DrJavaTestCase;
37 import edu.rice.cs.drjava.model.AbstractDJDocument;
38 import edu.rice.cs.drjava.model.DJDocument;
39 import edu.rice.cs.drjava.model.definitions.indent.Indenter;
40
41 import javax.swing.text.AbstractDocument JavaDoc;
42 import javax.swing.text.BadLocationException JavaDoc;
43 //import edu.rice.cs.drjava.model.definitions.DefinitionsDocument;
44

45 /**
46  *
47  * @version $Id: IndentInfoTest.java 4026 2006-10-31 15:50:16Z rcartwright $
48  */

49 public final class IndentInfoTest extends DrJavaTestCase {
50   private String JavaDoc _text;
51   //private DefinitionsDocument _document;
52
//private BraceReduction _reduced;
53
private IndentInfo _info;
54   //private GlobalEventNotifier _notifier;
55
private DJDocument _document;
56   
57   
58   public void setUp() throws Exception JavaDoc {
59     super.setUp();
60     //_notifier = new GlobalEventNotifier();
61
// _document = new DefinitionsDocument(_notifier);
62
_document = new AbstractDJDocument() {
63       protected int startCompoundEdit() {
64         //Do nothing
65
return 0;
66       }
67       protected void endCompoundEdit(int key) { /* Do nothing. */ }
68       protected void endLastCompoundEdit() { /* Do nothing. */ }
69       protected void addUndoRedo(AbstractDocument.DefaultDocumentEvent JavaDoc chng, Runnable JavaDoc undoCommand, Runnable JavaDoc doCommand) {
70         /* Do nothing */
71       }
72       protected void _styleChanged() { /* Do nothing. */ }
73       protected Indenter makeNewIndenter(int indentLevel) { return new Indenter(indentLevel); }
74     };
75   }
76   
77   private void _infoTestHelper(int location, String JavaDoc message,
78                                int expDistToPrevNewline, int expDistToBrace,
79                                int expDistToNewline, int expDistToBraceCurrent,
80                                int expDistToNewlineCurrent)
81   {
82     _document.setCurrentLocation(location);
83     //_reduced = _document.getReduced();
84
_info = _document.getIndentInformation();
85     
86     assertEquals(message + " -- distToPrevNewline", expDistToPrevNewline, _info.distToPrevNewline);
87     assertEquals(message + " -- distToBrace", expDistToBrace, _info.distToBrace);
88     assertEquals(message + " -- distToNewline", expDistToNewline, _info.distToNewline);
89     assertEquals(message + " -- distToBraceCurrent", expDistToBraceCurrent, _info.distToBraceCurrent);
90     assertEquals(message + " -- distToNewlineCurrent", expDistToNewlineCurrent, _info.distToNewlineCurrent);
91   }
92   
93   public void testFieldsForCurrentLocation() throws BadLocationException JavaDoc {
94     
95     _text = "foo {\nvoid m1(int a,\nint b) {\n}\n}";
96     // . . .. . .. . . . . ... .
97
// | | | |
98
// 0 10 20 30
99

100     _document.clear();
101     _document.insertString(0, _text, null);
102     
103     _infoTestHelper(0, "DOCSTART -- no brace or newline", -1, -1, -1, -1, -1);
104     _infoTestHelper(4, "Location has no brace or newline", -1, -1, -1, -1, -1);
105     _infoTestHelper(5, "Location has a brace but no newline", -1, -1, -1, 1, -1);
106     _infoTestHelper(6, "Location has a brace and a newline", 0, 2, -1, 2, -1);
107     _infoTestHelper(10, "Location has a brace and a newline", 4, 6, -1, 6, -1);
108     _infoTestHelper(13, "Location has a brace and a newline", 7, 9, -1, 9, -1);
109     _infoTestHelper(14, "Location has a brace and a newline", 8, 10, -1, 1, 8);
110     _infoTestHelper(20, "At \\n within parens", 14, 16, -1, 7, 14);
111     _infoTestHelper(21, "Second line within parens", 0, 8, 15, 8, 15);
112     _infoTestHelper(26, "On close paren", 5, 13, 20, 13, 20);
113     _infoTestHelper(28, "On second open brace", 7, 15, 22, 24, -1);
114     _infoTestHelper(29, "On \\n in second set of braces", 8, 16, 23, 1, 8);
115     _infoTestHelper(30, "Close brace of method declaration", 0, 2, 9, 2, 9);
116     _infoTestHelper(31, "Last \\n", 1, 3, 10, 27, -1);
117     _infoTestHelper(32, "Final close brace", 0, 28, -1, 28, -1);
118   }
119 }
120
Popular Tags