KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > edu > rice > cs > drjava > model > definitions > indent > QuestionHasCharPrecedingOpenBraceTest


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.indent;
35
36 import javax.swing.text.BadLocationException JavaDoc;
37
38 /**
39  * Test class according to the JUnit protocol. Tests the proper functionality
40  * of the class QuestionHasCharPrecedingOpenBrace.
41  * @version $Id: QuestionHasCharPrecedingOpenBraceTest.java 3901 2006-06-30 05:28:11Z rcartwright $
42  */

43 public final class QuestionHasCharPrecedingOpenBraceTest extends IndentRulesTestCase
44 {
45   private String JavaDoc _text;
46     
47 // private IndentRuleQuestion _rule;
48

49   public void testIsIn1DArray() throws BadLocationException JavaDoc
50   { //01234567890123456789012345
51
_text =
52       "int[2][] a = \n" + /* 0 */
53       "{ \n" + /* 25 */
54       " a, // line comment \n" + /* 50 */
55       " int b, \n" + /* 75 */
56       " /** \n" + /* 100 */
57       " * javadoc comment \n" + /* 125 */
58       " */ \n" + /* 150 */
59       " START \n" + /* 175 */
60       " }, \n" + /* 200 */
61       " { \n" + /* 225 */
62       " /* { multi line \n" + /* 250 */
63       " comment } \n" + /* 275 */
64       " boolean method() \n" + /* 300 */
65       " { \n" + /* 325 */
66       " } \n" + /* 350 */
67       " */} \n" + /* 375 */
68       "}"; /* 400 */
69
70     _setDocText(_text);
71     
72     char [] chars = {'='};
73     IndentRuleQuestion rule = new QuestionHasCharPrecedingOpenBrace(chars, null, null);
74
75     assertTrue("At DOCSTART.", ! rule.applyRule(_doc, 0, Indenter.OTHER));
76     assertTrue("At identifier.", ! rule.applyRule(_doc, 10, Indenter.OTHER));
77     assertTrue("At start of array.", !rule.applyRule(_doc, 25, Indenter.OTHER));
78     assertTrue("START starts one-line comment.", rule.applyRule(_doc, 54, Indenter.OTHER));
79     assertTrue("START starts one-line comment.", rule.applyRule(_doc, 60, Indenter.OTHER));
80     assertTrue("START starts javadoc comment.", rule.applyRule(_doc, 104, Indenter.OTHER));
81     assertTrue("START starts javadoc comment.", rule.applyRule(_doc, 110, Indenter.OTHER));
82     assertTrue("Line inside javadoc comment.", rule.applyRule(_doc, 130, Indenter.OTHER));
83     assertTrue("Line closes javadoc comment.", rule.applyRule(_doc, 150, Indenter.OTHER));
84     assertTrue("START is stil in first.", rule.applyRule(_doc, 180, Indenter.OTHER));
85     assertTrue("Second pseudo array element.", ! rule.applyRule(_doc, 230, Indenter.OTHER));
86     assertTrue("Start of multi-line comment.", !rule.applyRule(_doc, 260, Indenter.OTHER));
87     assertTrue("Line inside multi-line comment.", !rule.applyRule(_doc, 275, Indenter.OTHER));
88     assertTrue("Line inside multi-line comment.", !rule.applyRule(_doc, 300, Indenter.OTHER));
89     assertTrue("Line closes multi-line comment.", !rule.applyRule(_doc, 399, Indenter.OTHER));
90     assertTrue("Last close brace", !rule.applyRule(_doc, 400, Indenter.OTHER));
91     assertTrue("At end of document.", !rule.applyRule(_doc, 401, Indenter.OTHER));
92   }
93   public void testIsIn2DArray() throws BadLocationException JavaDoc
94   { //01234567890123456789012345
95
_text =
96       "int[2][] a = \n" + /* 0 */
97       "{ \n" + /* 25 */
98       " { \n" + /* 50 */
99       " a, // line comment \n" + /* 75 */
100       " int b, \n" + /* 100 */
101       " /** \n" + /* 125 */
102       " */ \n" + /* 150 */
103       " START \n" + /* 175 */
104       " }, \n" + /* 200 */
105       " { \n" + /* 225 */
106       " /* = { multi line \n" + /* 250 */
107       " comment } \n" + /* 275 */
108       " boolean method() \n" + /* 300 */
109       " { \n" + /* 325 */
110       " } \n" + /* 350 */
111       " */} \n" + /* 375 */
112       "}" + /* 400 */
113       "";
114
115     _setDocText(_text);
116     
117     char [] chars = {'='};
118     IndentRuleQuestion rule = new QuestionHasCharPrecedingOpenBrace(chars, null, null);
119
120     assertTrue("At DOCSTART.", ! rule.applyRule(_doc, 0, Indenter.OTHER));
121     assertTrue("At identifier.", ! rule.applyRule(_doc, 10, Indenter.OTHER));
122     assertTrue("At start of outer array", !rule.applyRule(_doc, 25, Indenter.OTHER));
123
124     assertTrue("Before start of inner array", rule.applyRule(_doc, 50, Indenter.OTHER));
125
126     assertTrue("Same line as inner {.", rule.applyRule(_doc, 54, Indenter.OTHER));
127     assertTrue("Line after inner {.", !rule.applyRule(_doc, 75, Indenter.OTHER));
128     assertTrue("START is stil in first.", !rule.applyRule(_doc, 180, Indenter.OTHER));
129
130     assertTrue("Second pseudo array element.", rule.applyRule(_doc, 230, Indenter.OTHER));
131     assertTrue("In multi-line comment.", ! rule.applyRule(_doc, 260, Indenter.OTHER));
132
133     assertTrue("multi-line comment w/ = {.", ! rule.applyRule(_doc, 275, Indenter.OTHER));
134
135     assertTrue("Line inside multi-line comment.", !rule.applyRule(_doc, 300, Indenter.OTHER));
136     assertTrue("Line closes multi-line comment.", !rule.applyRule(_doc, 399, Indenter.OTHER));
137
138     assertTrue("Last close brace", rule.applyRule(_doc, 400, Indenter.OTHER));
139     assertTrue("At end of document.", rule.applyRule(_doc, 401, Indenter.OTHER));
140   }
141   public void testNoEquals() throws BadLocationException JavaDoc
142   { //01234567890123456789012345
143
_text =
144       "int[2][] a \n" + /* 0 */
145       "{ \n" + /* 25 */
146       " { \n" + /* 50 */
147       " a, // line comment \n" + /* 75 */
148       " int b, \n" + /* 100 */
149       " /** \n" + /* 125 */
150       " */ \n" + /* 150 */
151       " START \n" + /* 175 */
152       " }, \n" + /* 200 */
153       " { \n" + /* 225 */
154       " /* = { multi line \n" + /* 250 */
155       " comment } \n" + /* 275 */
156       " boolean method() \n" + /* 300 */
157       " { \n" + /* 325 */
158       " } \n" + /* 350 */
159       " */} \n" + /* 375 */
160       "}" + /* 400 */
161       "";
162
163     _setDocText(_text);
164     
165     char [] chars = {'='};
166     IndentRuleQuestion rule = new QuestionHasCharPrecedingOpenBrace(chars, null, null);
167
168     assertTrue("At DOCSTART.", ! rule.applyRule(_doc, 0, Indenter.OTHER));
169     assertTrue("At identifier.", ! rule.applyRule(_doc, 10, Indenter.OTHER));
170     assertTrue("At start of outer array", !rule.applyRule(_doc, 25, Indenter.OTHER));
171
172     assertTrue("Before start of inner array", ! rule.applyRule(_doc, 50, Indenter.OTHER));
173     assertTrue("Same line as inner {.", !rule.applyRule(_doc, 54, Indenter.OTHER));
174     assertTrue("Line after inner {.", !rule.applyRule(_doc, 75, Indenter.OTHER));
175     assertTrue("START is stil in first.", !rule.applyRule(_doc, 180, Indenter.OTHER));
176
177   }
178 }
179
Popular Tags