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: /** Tests ActionStartPrevLinePlus(String)
040: * @version $Id: ActionStartPrevLinePlusTest.java 4255 2007-08-28 19:17:37Z mgricken $
041: */
042: public class ActionStartPrevLinePlusTest extends IndentRulesTestCase {
043:
044: /** This is a clever (IMHO) factory trick to reuse these methods in TestCases for logically similar IndentActions.
045: * @param suffix the text to be added by this rule after indent padding
046: * @see ActionStartPrevLinePlus#ActionStartPrevLinePlus(String)
047: */
048: private IndentRuleAction makeAction(String suffix) {
049: return new ActionStartPrevLinePlus(suffix);
050: }
051:
052: public void testLeaveBe()
053: throws javax.swing.text.BadLocationException {
054: _setDocText("foo\nbar");
055: _doc.setCurrentLocation(4);
056: makeAction("").indentLine(_doc, Indenter.IndentReason.OTHER);
057: assertEquals(7, _doc.getLength());
058: assertEquals("foo\nbar", _doc.getText());
059: }
060:
061: public void testLeaveBeMidLine()
062: throws javax.swing.text.BadLocationException {
063: _setDocText("foo\nbar");
064: _doc.setCurrentLocation(6);
065: makeAction("").indentLine(_doc, Indenter.IndentReason.OTHER);
066: assertEquals(7, _doc.getLength());
067: assertEquals("foo\nbar", _doc.getText());
068: }
069:
070: public void testAddSpaces()
071: throws javax.swing.text.BadLocationException {
072: _setDocText("foo\nbar");
073: _doc.setCurrentLocation(4);
074: makeAction(" ").indentLine(_doc, Indenter.IndentReason.OTHER); // three spaces
075: assertEquals(10, _doc.getLength());
076: assertEquals("foo\n bar", _doc.getText());
077: }
078:
079: public void testAddSpacesMidLine()
080: throws javax.swing.text.BadLocationException {
081: _setDocText("foo\nbar");
082: _doc.setCurrentLocation(6);
083: makeAction(" ").indentLine(_doc, Indenter.IndentReason.OTHER); // three spaces
084: assertEquals(10, _doc.getLength());
085: assertEquals("foo\n bar", _doc.getText());
086: }
087:
088: public void testBothIndented()
089: throws javax.swing.text.BadLocationException {
090: _setDocText(" foo\n bar");
091: _doc.setCurrentLocation(9);
092: makeAction("").indentLine(_doc, Indenter.IndentReason.OTHER);
093: assertEquals(11, _doc.getLength());
094: assertEquals(" foo\n bar", _doc.getText());
095: }
096:
097: public void testBothIndentedAddSpaces()
098: throws javax.swing.text.BadLocationException {
099: _setDocText(" foo\n bar");
100: _doc.setCurrentLocation(9);
101: makeAction(" ").indentLine(_doc, Indenter.IndentReason.OTHER);
102: assertEquals(14, _doc.getLength());
103: assertEquals(" foo\n bar", _doc.getText());
104: }
105:
106: public void testBothIndentedAddStuff()
107: throws javax.swing.text.BadLocationException {
108: _setDocText(" foo\n bar");
109: _doc.setCurrentLocation(9);
110: makeAction("abc").indentLine(_doc, Indenter.IndentReason.OTHER);
111: assertEquals(14, _doc.getLength());
112: assertEquals(" foo\n abcbar", _doc.getText());
113: }
114:
115: public void testSecondLineMisindented()
116: throws javax.swing.text.BadLocationException {
117: _setDocText(" foo\n bar");
118: _doc.setCurrentLocation(9);
119: makeAction("abc").indentLine(_doc, Indenter.IndentReason.OTHER);
120: assertEquals(14, _doc.getLength());
121: assertEquals(" foo\n abcbar", _doc.getText());
122: }
123:
124: public void testLeavesOtherLinesAlone()
125: throws javax.swing.text.BadLocationException {
126: _setDocText("foo\nbar\nblah");
127: _doc.setCurrentLocation(10);
128: makeAction(" ").indentLine(_doc, Indenter.IndentReason.OTHER); // three spaces
129: assertEquals(15, _doc.getLength());
130: assertEquals("foo\nbar\n blah", _doc.getText());
131: }
132:
133: public void testOtherLinesIndented()
134: throws javax.swing.text.BadLocationException {
135: _setDocText(" foo\n bar\n blah");
136: _doc.setCurrentLocation(15);
137: makeAction(" ").indentLine(_doc, Indenter.IndentReason.OTHER); // three spaces
138: assertEquals(20, _doc.getLength());
139: assertEquals(" foo\n bar\n blah", _doc.getText());
140: }
141: }
|