001: /*BEGIN_COPYRIGHT_BLOCK
002: *
003: * Copyright (c) 2001-2007, JavaPLT group at Rice University (javaplt@rice.edu)
004: * All rights reserved.
005: *
006: * Redistribution and use in source and binary forms, with or without
007: * modification, are permitted provided that the following conditions are met:
008: * * Redistributions of source code must retain the above copyright
009: * notice, this list of conditions and the following disclaimer.
010: * * Redistributions in binary form must reproduce the above copyright
011: * notice, this list of conditions and the following disclaimer in the
012: * documentation and/or other materials provided with the distribution.
013: * * Neither the names of DrJava, the JavaPLT group, Rice University, nor the
014: * names of its contributors may be used to endorse or promote products
015: * derived from this software without specific prior written permission.
016: *
017: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
018: * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
019: * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
020: * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
021: * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
022: * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
023: * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
024: * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
025: * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
026: * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
027: * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
028: *
029: * This software is Open Source Initiative approved Open Source Software.
030: * Open Source Initative Approved is a trademark of the Open Source Initiative.
031: *
032: * This file is part of DrJava. Download the current version of this project
033: * from http://www.drjava.org/ or http://sourceforge.net/projects/drjava/
034: *
035: * END_COPYRIGHT_BLOCK*/
036:
037: package edu.rice.cs.drjava.model.definitions.indent;
038:
039: import javax.swing.text.BadLocationException;
040:
041: /**
042: * Tests ActionStartPrevLinePlusMultilinePreserve(String,int,int,int,int).
043: * It specifically tests the behavior of the auto-closing comments feature.
044: * This means it tests cases where the user has just hit ENTER somewhere
045: * on the opening line of a block comment.
046: *
047: * @version $Id: ActionStartPrevLinePlusMultilinePreserveTest.java 4255 2007-08-28 19:17:37Z mgricken $
048: */
049: public class ActionStartPrevLinePlusMultilinePreserveTest extends
050: IndentRulesTestCase {
051:
052: /**
053: * This is a clever (IMHO) factory trick to reuse these methods in TestCases
054: * for logically similar IndentActions.
055: * @see ActionStartPrevLinePlusMultilinePreserve#ActionStartPrevLinePlusMultilinePreserve(String[], int, int, int, int)
056: */
057: private IndentRuleAction makeAction(String[] suffices,
058: int cursorLine, int cursorPos, int psrvLine, int psrvPos) {
059: return new ActionStartPrevLinePlusMultilinePreserve(suffices,
060: cursorLine, cursorPos, psrvLine, psrvPos);
061: }
062:
063: /**
064: * This method abstracts the common processes of the tests so that the tests
065: * themselves may only contain information about original conditions and
066: * expected results.
067: * @param start The text that should be in the document at time rule is called
068: * @param loc the location of the cursor when rule is called
069: * @param endLoc the expected final size of the document
070: * @param finish the text string that remaining after the rule is called
071: */
072: public void helperCommentTest(String start, int loc, int endLoc,
073: String finish) throws BadLocationException {
074: _setDocText(start);
075: _doc.setCurrentLocation(loc);
076: makeAction(new String[] { " * \n", " */" }, 0, 3, 0, 3)
077: .indentLine(_doc, Indenter.IndentReason.ENTER_KEY_PRESS);
078: assertEquals(endLoc, _doc.getCurrentLocation());
079: //assertEquals(finish.length(), _doc.getLength());
080: assertEquals(finish, _doc.getText());
081: }
082:
083: public void test1() throws BadLocationException {
084: helperCommentTest("/**\n", 4, 7, "/**\n * \n */");
085: }
086:
087: public void test2() throws BadLocationException {
088: helperCommentTest(" /**\n", 7, 13, " /**\n * \n */");
089: }
090:
091: public void test3() throws BadLocationException {
092: helperCommentTest("/* abc\ndefg\n hijklmnop", 7, 10,
093: "/* abc\n * defg\n */\n hijklmnop");
094: }
095:
096: public void test4() throws BadLocationException {
097: helperCommentTest("/* \nThis is a comment */", 4, 7,
098: "/* \n * This is a comment */\n */");
099: }
100:
101: public void test5() throws BadLocationException {
102: helperCommentTest("/* This is code\n and more */", 16, 19,
103: "/* This is code\n * and more */\n */");
104: }
105:
106: public void test6() throws BadLocationException {
107: ///* This |is a comment block
108: // That is already closed */
109: //---------------------------------
110: ///* This
111: // * |is a comment block
112: // */
113: // That is already closed */
114: //---------------------------------
115: //// (After undo command)
116: //
117: ///* This
118: // * |is a comment block
119: // That is already closed */
120: helperCommentTest(
121: "/* This \nis a comment block\n That is already closed */",
122: 9, 12,
123: "/* This \n * is a comment block\n */\n That is already closed */");
124: }
125:
126: public void test7() throws BadLocationException {
127: ///* This |is a comment block
128: // * That is already closed
129: // */
130: //
131: //---------------------------------
132: ///* This
133: // * |is a comment block
134: // */
135: // * That is already closed
136: // */
137: //---------------------------------
138: //(after undo command)
139: ///* This
140: // * |is a comment block
141: // * That is already closed
142: // */
143: helperCommentTest(
144: "/* This \nis a comment block\n * That is already closed \n */",
145: 9, 12,
146: "/* This \n * is a comment block\n */\n * That is already closed \n */");
147: }
148:
149: public void xtest8() throws BadLocationException {
150: ///* ABC | */
151: //
152: //---------------------------------
153: ///* ABC
154: // * |
155: // */
156: helperCommentTest("/* ABC \n */", 8, 11, "/* ABC \n * */\n */");
157: }
158:
159: public void xtest9() throws BadLocationException {
160: ///**|
161: // * Text
162: // */
163: //---------------------------------
164: ///**
165: // * |
166: // * Text
167: // */
168: helperCommentTest("/**\n * Text\n */", 4, 7,
169: "/**\n * \n * Text\n */");
170: }
171:
172: public void test10() throws BadLocationException {
173: ///** This is |bad */ **/
174: //
175: //---------------------------------
176: ///** This is
177: // * bad */ **/
178: // */
179:
180: helperCommentTest("/** This is \nbad */ **/", 13, 16,
181: "/** This is \n * bad */ **/\n */");
182: }
183:
184: public void xtest11() throws BadLocationException {
185: ///** ABC **/ | /** ABC **/
186: //
187: //---------------------------------
188: ///** ABC **/
189: //|/** ABC **/
190:
191: helperCommentTest("/** ABC **/ \n /** ABC **/", 13, 13,
192: "/** ABC **/ \n/** ABC **/");
193: }
194:
195: }
|