KickJava   Java API By Example, From Geeks To Geeks.

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


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 /** Tests ActionStartPrevLinePlus(String)
37   * @version $Id: ActionStartPrevLinePlusTest.java 3901 2006-06-30 05:28:11Z rcartwright $
38   */

39 public class ActionStartPrevLinePlusTest extends IndentRulesTestCase {
40   
41   /** This is a clever (IMHO) factory trick to reuse these methods in TestCases for logically similar IndentActions.
42     * @param suffix the text to be added by this rule after indent padding
43     * @see ActionStartPrevLinePlus#ActionStartPrevLinePlus(String)
44     */

45   private IndentRuleAction makeAction(String JavaDoc suffix) { return new ActionStartPrevLinePlus(suffix); }
46
47   public void testLeaveBe() throws javax.swing.text.BadLocationException JavaDoc {
48     _setDocText("foo\nbar");
49     _doc.setCurrentLocation(4);
50     makeAction("").indentLine(_doc, Indenter.OTHER);
51     assertEquals(7, _doc.getLength());
52     assertEquals("foo\nbar", _doc.getText());
53   }
54   public void testLeaveBeMidLine() throws javax.swing.text.BadLocationException JavaDoc {
55     _setDocText("foo\nbar");
56     _doc.setCurrentLocation(6);
57     makeAction("").indentLine(_doc, Indenter.OTHER);
58     assertEquals(7, _doc.getLength());
59     assertEquals("foo\nbar", _doc.getText());
60   }
61   public void testAddSpaces() throws javax.swing.text.BadLocationException JavaDoc {
62     _setDocText("foo\nbar");
63     _doc.setCurrentLocation(4);
64     makeAction(" ").indentLine(_doc, Indenter.OTHER); // three spaces
65
assertEquals(10, _doc.getLength());
66     assertEquals("foo\n bar", _doc.getText());
67   }
68   public void testAddSpacesMidLine() throws javax.swing.text.BadLocationException JavaDoc {
69     _setDocText("foo\nbar");
70     _doc.setCurrentLocation(6);
71     makeAction(" ").indentLine(_doc, Indenter.OTHER); // three spaces
72
assertEquals(10, _doc.getLength());
73     assertEquals("foo\n bar", _doc.getText());
74   }
75   public void testBothIndented() throws javax.swing.text.BadLocationException JavaDoc {
76     _setDocText(" foo\n bar");
77     _doc.setCurrentLocation(9);
78     makeAction("").indentLine(_doc, Indenter.OTHER);
79     assertEquals(11, _doc.getLength());
80     assertEquals(" foo\n bar", _doc.getText());
81   }
82   public void testBothIndentedAddSpaces() throws javax.swing.text.BadLocationException JavaDoc {
83     _setDocText(" foo\n bar");
84     _doc.setCurrentLocation(9);
85     makeAction(" ").indentLine(_doc, Indenter.OTHER);
86     assertEquals(14, _doc.getLength());
87     assertEquals(" foo\n bar", _doc.getText());
88   }
89   public void testBothIndentedAddStuff() throws javax.swing.text.BadLocationException JavaDoc {
90     _setDocText(" foo\n bar");
91     _doc.setCurrentLocation(9);
92     makeAction("abc").indentLine(_doc, Indenter.OTHER);
93     assertEquals(14, _doc.getLength());
94     assertEquals(" foo\n abcbar", _doc.getText());
95   }
96   public void testSecondLineMisindented() throws javax.swing.text.BadLocationException JavaDoc {
97     _setDocText(" foo\n bar");
98     _doc.setCurrentLocation(9);
99     makeAction("abc").indentLine(_doc, Indenter.OTHER);
100     assertEquals(14, _doc.getLength());
101     assertEquals(" foo\n abcbar", _doc.getText());
102   }
103   public void testLeavesOtherLinesAlone() throws javax.swing.text.BadLocationException JavaDoc {
104     _setDocText("foo\nbar\nblah");
105     _doc.setCurrentLocation(10);
106     makeAction(" ").indentLine(_doc, Indenter.OTHER); // three spaces
107
assertEquals(15, _doc.getLength());
108     assertEquals("foo\nbar\n blah", _doc.getText());
109   }
110   public void testOtherLinesIndented() throws javax.swing.text.BadLocationException JavaDoc {
111     _setDocText(" foo\n bar\n blah");
112     _doc.setCurrentLocation(15);
113     makeAction(" ").indentLine(_doc, Indenter.OTHER); // three spaces
114
assertEquals(20, _doc.getLength());
115     assertEquals(" foo\n bar\n blah", _doc.getText());
116   }
117 }
118
Popular Tags