KickJava   Java API By Example, From Geeks To Geeks.

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


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

45
46 package edu.rice.cs.drjava.model.definitions.indent;
47
48 import javax.swing.text.BadLocationException JavaDoc;
49
50 /**
51  * Tests ActionStartPrevLinePlusMultilinePreserve(String,int,int,int,int).
52  * It specifically tests the behavior of the auto-closing comments feature.
53  * This means it tests cases where the user has just hit ENTER somewhere
54  * on the opening line of a block comment.
55  *
56  * @version $Id: ActionStartPrevLinePlusMultilinePreserveTest.java 3490 2006-01-07 19:22:33Z dlsmith $
57  */

58 public class ActionStartPrevLinePlusMultilinePreserveTest extends IndentRulesTestCase {
59   
60   /**
61    * This is a clever (IMHO) factory trick to reuse these methods in TestCases
62    * for logically similar IndentActions.
63    * @see ActionStartPrevLinePlusMultilinePreserve#ActionStartPrevLinePlusMultilinePreserve(String[], int, int, int, int)
64    */

65   private IndentRuleAction makeAction(String JavaDoc[] suffices,
66                                       int cursorLine, int cursorPos,
67                                       int psrvLine, int psrvPos) {
68     return new ActionStartPrevLinePlusMultilinePreserve(suffices,
69                                                         cursorLine, cursorPos,
70                                                         psrvLine, psrvPos);
71   }
72   
73   /**
74    * This method abstracts the common processes of the tests so that the tests
75    * themselves may only contain information about original conditions and
76    * expected results.
77    * @param start The text that should be in the document at time rule is called
78    * @param loc the location of the cursor when rule is called
79    * @param endLoc the expected final size of the document
80    * @param finish the text string that remaining after the rule is called
81    */

82   public void helperCommentTest(String JavaDoc start, int loc, int endLoc, String JavaDoc finish) throws
83     BadLocationException JavaDoc {
84       _setDocText(start);
85       _doc.setCurrentLocation(loc);
86       makeAction(new String JavaDoc[]{" * \n", " */"},0,3,0,3).indentLine(_doc, Indenter.ENTER_KEY_PRESS);
87       assertEquals(endLoc, _doc.getCurrentLocation());
88       //assertEquals(finish.length(), _doc.getLength());
89
assertEquals(finish, _doc.getText());
90   }
91
92   public void test1() throws BadLocationException JavaDoc {
93     helperCommentTest("/**\n",
94                       4, 7,
95                       "/**\n * \n */");
96   }
97
98   public void test2() throws BadLocationException JavaDoc {
99     helperCommentTest(" /**\n",
100                       7, 13,
101                       " /**\n * \n */");
102   }
103
104   public void test3() throws BadLocationException JavaDoc {
105     helperCommentTest("/* abc\ndefg\n hijklmnop",
106                       7, 10,
107                       "/* abc\n * defg\n */\n hijklmnop");
108   }
109
110   public void test4() throws BadLocationException JavaDoc {
111     helperCommentTest("/* \nThis is a comment */",
112                       4, 7,
113                       "/* \n * This is a comment */\n */");
114   }
115
116   public void test5() throws BadLocationException JavaDoc {
117     helperCommentTest("/* This is code\n and more */",
118                       16, 19,
119                       "/* This is code\n * and more */\n */");
120   }
121
122   public void test6() throws BadLocationException JavaDoc {
123 ///* This |is a comment block
124
// That is already closed */
125
//---------------------------------
126
///* This
127
// * |is a comment block
128
// */
129
// That is already closed */
130
//---------------------------------
131
//// (After undo command)
132
//
133
///* This
134
// * |is a comment block
135
// That is already closed */
136
helperCommentTest("/* This \nis a comment block\n That is already closed */",
137                       9, 12,
138                       "/* This \n * is a comment block\n */\n That is already closed */");
139   }
140   
141   public void test7() throws BadLocationException JavaDoc {
142 ///* This |is a comment block
143
// * That is already closed
144
// */
145
//
146
//---------------------------------
147
///* This
148
// * |is a comment block
149
// */
150
// * That is already closed
151
// */
152
//---------------------------------
153
//(after undo command)
154
///* This
155
// * |is a comment block
156
// * That is already closed
157
// */
158
helperCommentTest("/* This \nis a comment block\n * That is already closed \n */",
159                       9, 12,
160                       "/* This \n * is a comment block\n */\n * That is already closed \n */");
161   }
162   
163   public void xtest8() throws BadLocationException JavaDoc {
164 ///* ABC | */
165
//
166
//---------------------------------
167
///* ABC
168
// * |
169
// */
170
helperCommentTest("/* ABC \n */",
171                       8, 11,
172                       "/* ABC \n * */\n */");
173   }
174   
175   public void xtest9() throws BadLocationException JavaDoc {
176 ///**|
177
// * Text
178
// */
179
//---------------------------------
180
///**
181
// * |
182
// * Text
183
// */
184
helperCommentTest("/**\n * Text\n */",
185                       4, 7,
186                       "/**\n * \n * Text\n */");
187   }
188   
189   public void test10() throws BadLocationException JavaDoc {
190 ///** This is |bad */ **/
191
//
192
//---------------------------------
193
///** This is
194
// * bad */ **/
195
// */
196

197     helperCommentTest("/** This is \nbad */ **/",
198                       13, 16,
199                       "/** This is \n * bad */ **/\n */");
200   }
201
202   public void xtest11() throws BadLocationException JavaDoc {
203 ///** ABC **/ | /** ABC **/
204
//
205
//---------------------------------
206
///** ABC **/
207
//|/** ABC **/
208

209     helperCommentTest("/** ABC **/ \n /** ABC **/",
210                       13, 13,
211                       "/** ABC **/ \n/** ABC **/");
212   }
213   
214 }
Popular Tags