KickJava   Java API By Example, From Geeks To Geeks.

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


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 the action rules for code in the indentation decision tree.
40  * The implementation relies heavily on functions which are fully
41  * tested in IndentHelpersTest.
42  *
43  * @version $Id: ActionStartPrevStmtPlusTest.java 3901 2006-06-30 05:28:11Z rcartwright $
44  */

45 public final class ActionStartPrevStmtPlusTest extends IndentRulesTestCase {
46   
47   public void testNoPrevStmt() throws BadLocationException JavaDoc {
48     IndentRuleAction rule1 = new ActionStartPrevStmtPlus("", true);
49     IndentRuleAction rule2 = new ActionStartPrevStmtPlus(" ", true);
50
51     _setDocText("foo();\n");
52     rule1.indentLine(_doc, 2, Indenter.OTHER);
53     assertEquals("no prev stmt, no suffix",
54                  "foo();\n",
55                  _doc.getText());
56     
57     _setDocText("foo();\n");
58     rule2.indentLine(_doc, 2, Indenter.OTHER);
59     assertEquals("no prev stmt, suffix two spaces",
60                  " foo();\n",
61                  _doc.getText());
62   }
63   
64   public void testPrevStmtPrevLine() throws BadLocationException JavaDoc {
65     IndentRuleAction rule1 = new ActionStartPrevStmtPlus("", true);
66     IndentRuleAction rule2 = new ActionStartPrevStmtPlus(" ", true);
67
68     _setDocText(" foo().\n//boo();\n/*y=x+1;\nfoo(){}*/\nbar();\nbiz();\n");
69     rule1.indentLine(_doc, 44, Indenter.OTHER);
70     assertEquals("prev stmt on prev line, no suffix",
71                  " foo().\n//boo();\n/*y=x+1;\nfoo(){}*/\nbar();\n biz();\n",
72                  _doc.getText());
73     
74     _setDocText(" foo().\n//boo();\n/*y=x+1;\nfoo(){}*/\nbar();\nbiz();\n");
75     rule2.indentLine(_doc, 44, Indenter.OTHER);
76     assertEquals("prev stmt on prev line, suffix two spaces",
77                  " foo().\n//boo();\n/*y=x+1;\nfoo(){}*/\nbar();\n biz();\n",
78                  _doc.getText());
79   }
80
81   public void testPrevStmtSeveralLinesBeforeCurrLocation() throws BadLocationException JavaDoc {
82     IndentRuleAction rule1 = new ActionStartPrevStmtPlus("", true);
83     IndentRuleAction rule2 = new ActionStartPrevStmtPlus(" ", true);
84     
85     _setDocText(" foo();\n//y=x+1;\n/*void blah {\n}*/\n ';' + blah.\n//foo\nx;\n");
86     rule1.indentLine(_doc, 56, Indenter.OTHER);
87     assertEquals("prev stmt serveral lines before, no suffix",
88                  " foo();\n//y=x+1;\n/*void blah {\n}*/\n ';' + blah.\n//foo\n x;\n",
89                  _doc.getText());
90     
91     _setDocText(" foo();\n//y=x+1;\n/*void blah {\n}*/\n ';' + blah.\n//foo\nx;\n");
92     rule2.indentLine(_doc, 56, Indenter.OTHER);
93     assertEquals("prev stmt serveral lines before, suffix two spaces",
94                  " foo();\n//y=x+1;\n/*void blah {\n}*/\n ';' + blah.\n//foo\n x;\n",
95                  _doc.getText());
96   }
97   
98   public void testColonNotDelim() throws BadLocationException JavaDoc {
99     IndentRuleAction rule = new ActionStartPrevStmtPlus("", false);
100     
101     _setDocText("test2 = x ? y :\n" + // ? and : on one line
102
" z;\n" + // unfinished ternary
103
"foo();\n"); // new stmt
104
rule.indentLine(_doc, 21, Indenter.OTHER);
105     assertEquals("Colon is not a delimiter",
106                  "test2 = x ? y :\n" + // ? and : on one line
107
" z;\n" + // unfinished ternary
108
"foo();\n",
109                  _doc.getText());
110   }
111
112
113   public void testAfterArrayAssign() throws BadLocationException JavaDoc {
114     IndentRuleAction rule = new ActionStartPrevStmtPlus("", false);
115     
116     _setDocText("a = {\n" +
117                 " b,c,d\n" +
118                 "};\n" +
119                 " a;"); // new stmt
120
//rule.indentLine(_doc, 8);
121
rule.indentLine(_doc, 17, Indenter.OTHER);
122     assertEquals("After array assignment",
123                  "a = {\n" +
124                  " b,c,d\n" +
125                  "};\n" +
126                  "a;",
127                  _doc.getText());
128   }
129   public void testAfterArrayAssignMultiSemi() throws BadLocationException JavaDoc {
130     IndentRuleAction rule = new ActionStartPrevStmtPlus("", false);
131     
132     _setDocText("a = {\n" +
133                 " b,c,d\n" +
134                 "};;;\n" +
135                 " a;"); // new stmt
136
//rule.indentLine(_doc, 8);
137
rule.indentLine(_doc, 19, Indenter.OTHER);
138     assertEquals("After array assignment multi semi colons",
139                  "a = {\n" +
140                  " b,c,d\n" +
141                  "};;;\n" +
142                  "a;",
143                  _doc.getText());
144   }
145
146   /**
147    * not currently supported
148    * currently assuming single stmt per line
149    */

150   /*
151   public void testAfterArrayAssignMultiSemiAndStmt() throws BadLocationException {
152     IndentRuleAction rule = new ActionStartPrevStmtPlus("", false);
153     
154     _setDocText("a = {\n" +
155                 " b,c,d\n" +
156                 "};b;;\n" +
157                 " a;"); // new stmt
158     //rule.indentLine(_doc, 8);
159     rule.indentLine(_doc, 20);
160     assertEquals("After array assignment multi semi colons and embedded stmt",
161                  "a = {\n" +
162                  " b,c,d\n" +
163                  "};b;;\n" +
164                  "a;",
165                  _doc.getText());
166   }
167   */

168 }
169
170
171
172
Popular Tags