KickJava   Java API By Example, From Geeks To Geeks.

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


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 /*BEGIN_COPYRIGHT_BLOCK
35  *
36  * This file is a part of DrJava. Current versions of this project are available
37  * at http://sourceforge.net/projects/drjava
38  *
39  * Copyright (C) 2001-2002 JavaPLT group at Rice University (javaplt@rice.edu)
40  *
41  * DrJava is free software; you can redistribute it and/or modify
42  * it under the terms of the GNU General Public License as published by
43  * the Free Software Foundation; either version 2 of the License, or
44  * (at your option) any later version.
45  *
46  * DrJava is distributed in the hope that it will be useful,
47  * but WITHOUT ANY WARRANTY; without even the implied warranty of
48  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
49  * GNU General Public License for more details.
50  *
51  * You should have received a copy of the GNU General Public License
52  * along with this program; if not, write to the Free Software
53  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
54  * or see http://www.gnu.org/licenses/gpl.html
55  *
56  * In addition, as a special exception, the JavaPLT group at Rice University
57  * (javaplt@rice.edu) gives permission to link the code of DrJava with
58  * the classes in the gj.util package, even if they are provided in binary-only
59  * form, and distribute linked combinations including the DrJava and the
60  * gj.util package. You must obey the GNU General Public License in all
61  * respects for all of the code used other than these classes in the gj.util
62  * package: Dictionary, HashtableEntry, ValueEnumerator, Enumeration,
63  * KeyEnumerator, Vector, Hashtable, Stack, VectorEnumerator.
64  *
65  * If you modify this file, you may extend this exception to your version of the
66  * file, but you are not obligated to do so. If you do not wish to
67  * do so, delete this exception statement from your version. (However, the
68  * present version of DrJava depends on these classes, so you'd want to
69  * remove the dependency first!)
70  *
71 END_COPYRIGHT_BLOCK*/

72
73 package edu.rice.cs.drjava.model.definitions.indent;
74
75 /** Tests visitor class that determines whether the current line is a wing comment.
76  *
77  * @version $Id: QuestionCurrLineIsWingCommentTest.java 3901 2006-06-30 05:28:11Z rcartwright $
78  */

79 public final class QuestionCurrLineIsWingCommentTest extends IndentRulesTestCase {
80
81   static IndentRuleQuestion _rule = new QuestionCurrLineIsWingComment(null, null);
82
83   public void testWingComment() throws javax.swing.text.BadLocationException JavaDoc {
84     _setDocText("// This is a wing comment");
85     assertTrue("A valid wing comment 1", _rule.applyRule(_doc, 0, Indenter.OTHER));
86     assertTrue("A valid wing comment 2", _rule.applyRule(_doc, 4, Indenter.OTHER));
87     assertTrue("A valid wing comment 3", _rule.applyRule(_doc, 10, Indenter.OTHER));
88   }
89   public void testSpaces() throws javax.swing.text.BadLocationException JavaDoc {
90     _setDocText("/*\n \n*/");
91     assertFalse("A block comment 1", _rule.applyRule(_doc, 0, Indenter.OTHER));
92     assertFalse("A block comment 2", _rule.applyRule(_doc, 3, Indenter.OTHER));
93     assertFalse("A block comment 3", _rule.applyRule(_doc, 5, Indenter.OTHER));
94   }
95   
96   static String JavaDoc cornerCase = " //\n";
97   
98   public void testCornerCase() throws javax.swing.text.BadLocationException JavaDoc {
99     _setDocText(cornerCase);
100     assertFalse("Corner Case 1", _rule.applyRule(_doc, 0, Indenter.OTHER));
101     assertFalse("Corner Case 2", _rule.applyRule(_doc, 1, Indenter.OTHER));
102     assertFalse("Corner Case 3", _rule.applyRule(_doc, 2, Indenter.OTHER));
103     assertFalse("Corner Case 4", _rule.applyRule(_doc, 3, Indenter.OTHER));
104   }
105    
106   public void testWingInsideBlock() throws javax.swing.text.BadLocationException JavaDoc {
107     _setDocText("/*//\n \n */");
108     assertFalse("Wing Inside BlockComment 1", _rule.applyRule(_doc, Indenter.OTHER));
109     assertFalse("Wing Inside BlockComment 2", _rule.applyRule(_doc, 2, Indenter.OTHER));
110   }
111 }
112
Popular Tags