KickJava   Java API By Example, From Geeks To Geeks.

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


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 QuestionCurrLineStartsWithSkipComments.
41  * @version $Id: QuestionCurrLineStartsWithSkipCommentsTest.java 3901 2006-06-30 05:28:11Z rcartwright $
42  */

43 public final class QuestionCurrLineStartsWithSkipCommentsTest extends IndentRulesTestCase
44 {
45   private String JavaDoc _text;
46     
47   private IndentRuleQuestion _rule;
48   
49   public void testNoPrefix() throws BadLocationException JavaDoc
50   {
51     _text =
52       "class A \n" + /* 0 */
53       "{ \n" + /* 25 */
54       " // one line comment \n" + /* 50 */
55       " int method1 \n" + /* 75 */
56       " /** \n" + /* 100 */
57       " * javadoc comment \n" + /* 125 */
58       " */ \n" + /* 150 */
59       " int method() \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     IndentRuleQuestion rule = new QuestionCurrLineStartsWithSkipComments("", null, null);
73
74     // This rule should always apply, unless the entire line is inside a comment.
75

76     assertTrue("At DOCSTART.", rule.applyRule(_doc, 0, Indenter.OTHER));
77     assertTrue("At start of block.", 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 free.", rule.applyRule(_doc, 180, Indenter.OTHER));
85     assertTrue("START is free.", rule.applyRule(_doc, 230, Indenter.OTHER));
86     assertTrue("START starts 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("START is free.", rule.applyRule(_doc, 400, Indenter.OTHER));
91     assertTrue("At end of document.", rule.applyRule(_doc, 401, Indenter.OTHER));
92   }
93
94   public void testOpenBracePrefix() throws BadLocationException JavaDoc
95   {
96     _text =
97       "class A extends \n" + /* 0 */
98       "B { \n" + /* 25 */
99       " // { } \n" + /* 50 */
100       " int field; \n" + /* 75 */
101       " /** \n" + /* 100 */
102       " * { } \n" + /* 125 */
103       " */ \n" + /* 150 */
104       " int method() /* \n" + /* 175 */
105       " */ { \n" + /* 200 */
106       " } \n" + /* 225 */
107       " /* multi line \n" + /* 250 */
108       " comment \n" + /* 275 */
109       " boolean method() \n" + /* 300 */
110       "/**stuff*/ { // stuff\n" + /* 325 */
111       " } \n" + /* 350 */
112       " \n" + /* 375 */
113       "}"; /* 400 */
114
115     _setDocText(_text);
116
117     _rule = new QuestionCurrLineStartsWithSkipComments("{", null, null);
118
119     assertTrue("At DOCSTART - line doesn't start with an open brace.", !_rule.applyRule(_doc, 0, Indenter.OTHER));
120     assertTrue("Line starts a block, but not the start of the line.", !_rule.applyRule(_doc, 25, Indenter.OTHER));
121     assertTrue("Inside block - line starts with an alphanumeric character.",!_rule.applyRule(_doc, 30, Indenter.OTHER));
122     assertTrue("Line starts a one-line comment.", !_rule.applyRule(_doc, 54, Indenter.OTHER));
123     assertTrue("Line starts a one-line comment.", !_rule.applyRule(_doc, 60, Indenter.OTHER));
124     assertTrue("Line starts with alphanumeric character.", !_rule.applyRule(_doc, 80, Indenter.OTHER));
125     assertTrue("Line starts a javadoc comment.", !_rule.applyRule(_doc, 104, Indenter.OTHER));
126     assertTrue("Line starts a javadoc comment.", !_rule.applyRule(_doc, 110, Indenter.OTHER));
127     assertTrue("Line inside javadoc comment.", !_rule.applyRule(_doc, 130, Indenter.OTHER));
128     assertTrue("Line starts with alphanumeric character.", !_rule.applyRule(_doc, 180, Indenter.OTHER));
129     assertTrue("Line closes comment. It follows an open brace.", _rule.applyRule(_doc, 201, Indenter.OTHER));
130     assertTrue("Line closes comment. It follows an open brace.", _rule.applyRule(_doc, 221, Indenter.OTHER));
131     assertTrue("At end of block - line starts with a close brace.", !_rule.applyRule(_doc, 225, Indenter.OTHER));
132     assertTrue("Line starts a multi-line comment.", !_rule.applyRule(_doc, 260, Indenter.OTHER));
133     assertTrue("Line inside multi-line comment.", !_rule.applyRule(_doc, 275, Indenter.OTHER));
134     assertTrue("Line inside multi-line comment.", !_rule.applyRule(_doc, 300, Indenter.OTHER));
135     assertTrue("Line closes comment. It follows an open brace.", _rule.applyRule(_doc, 325, Indenter.OTHER));
136     assertTrue("Line starts with a close brace.", !_rule.applyRule(_doc, 355, Indenter.OTHER));
137     assertTrue("Empty line.", !_rule.applyRule(_doc, 390, Indenter.OTHER));
138     assertTrue("At last character - line starts with a close brace.", !_rule.applyRule(_doc, 400, Indenter.OTHER));
139     assertTrue("At end of document - line starts with a close brace.", !_rule.applyRule(_doc, 401, Indenter.OTHER));
140   }
141     
142   public void testCloseBracePrefix() throws BadLocationException JavaDoc
143   {
144     _text =
145       "class A \n" + /* 0 */
146       "{ \n" + /* 25 */
147       " // } } \n" + /* 50 */
148       " int field; \n" + /* 75 */
149       " /** \n" + /* 100 */
150       " * javadoc comment \n" + /* 125 */
151       " */ } \n" + /* 150 */
152       " int method() \n" + /* 175 */
153       "/**/} \n" + /* 200 */
154       "/ * } \n" + /* 225 */
155       " /* multi line \n" + /* 250 */
156       " comment \n" + /* 275 */
157       " boolean method() \n" + /* 300 */
158       " { \n" + /* 325 */
159       "*/ / } \n" + /* 350 */
160       " * } \n" + /* 375 */
161       "}"; /* 400 */
162
163     _setDocText(_text);
164     
165     _rule = new QuestionCurrLineStartsWithSkipComments("}", null, null);
166
167     assertTrue("At DOCSTART - line doesn't start with a close brace.", !_rule.applyRule(_doc, 0, Indenter.OTHER));
168     assertTrue("At start of block - line starts with an open brace.", !_rule.applyRule(_doc, 25, Indenter.OTHER));
169     assertTrue("Inside block - line starts with an open brace.", !_rule.applyRule(_doc, 30, Indenter.OTHER));
170     assertTrue("Line starts a one-line comment.", !_rule.applyRule(_doc, 54, Indenter.OTHER));
171     assertTrue("Line starts a one-line comment.", !_rule.applyRule(_doc, 60, Indenter.OTHER));
172     assertTrue("Line starts with alphanumeric character.", !_rule.applyRule(_doc, 80, Indenter.OTHER));
173     assertTrue("Line starts a javadoc comment.", !_rule.applyRule(_doc, 104, Indenter.OTHER));
174     assertTrue("Line starts a javadoc comment.", !_rule.applyRule(_doc, 110, Indenter.OTHER));
175     assertTrue("Line inside javadoc comment.", !_rule.applyRule(_doc, 130, Indenter.OTHER));
176     assertTrue("Line closes multi-line comment, it follows a close brace.", _rule.applyRule(_doc, 150, Indenter.OTHER));
177     assertTrue("Line starts with alphanumeric character.", !_rule.applyRule(_doc, 180, Indenter.OTHER));
178     assertTrue("Line starts with a comment, it follows a close brace.", _rule.applyRule(_doc, 221, Indenter.OTHER));
179     assertTrue("At end of block - line starts with a slash.", !_rule.applyRule(_doc, 225, Indenter.OTHER));
180     assertTrue("Line starts a multi-line comment.", !_rule.applyRule(_doc, 260, Indenter.OTHER));
181     assertTrue("Line inside multi-line comment.", !_rule.applyRule(_doc, 275, Indenter.OTHER));
182     assertTrue("Line inside multi-line comment.", !_rule.applyRule(_doc, 300, Indenter.OTHER));
183     assertTrue("Line inside multi-line comment.", !_rule.applyRule(_doc, 325, Indenter.OTHER));
184     assertTrue("Line closes multi-line comment, it follows a slash.", !_rule.applyRule(_doc, 355, Indenter.OTHER));
185     assertTrue("Line starts with a star.", !_rule.applyRule(_doc, 376, Indenter.OTHER));
186     assertTrue("At last character - line starts with a close brace.", _rule.applyRule(_doc, 400, Indenter.OTHER));
187     assertTrue("At end of document - line starts with a close brace.", _rule.applyRule(_doc, 401, Indenter.OTHER));
188   }
189 }
190
Popular Tags