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 whether the previous line starts the comment containing the cursor.
040: * @version $Id: QuestionPrevLineStartsCommentTest.java 4255 2007-08-28 19:17:37Z mgricken $
041: */
042: public final class QuestionPrevLineStartsCommentTest extends
043: IndentRulesTestCase {
044:
045: static IndentRuleQuestion rule2 = new QuestionPrevLineStartsComment(
046: null, null);
047: private static String example1 = "/*\nfoo\nbar\n*/";
048: // . .
049: // /*
050: // foo
051: // bar
052: // */
053: private static String example2 = "foo /* bar\nblah\nmoo\n*/";
054: // . .
055: // foo /* bar
056: // blah
057: // moo
058: // */
059: private static String example3 = "/*\nfoo\n// /*\nbar\n*/";
060:
061: // . . .
062: // /*
063: // foo
064: // // /*
065: // bar
066: // */
067:
068: public void testSimpleFirstLine()
069: throws javax.swing.text.BadLocationException {
070: _setDocText(example1);
071: assertEquals(true, rule2.applyRule(_doc, 3,
072: Indenter.IndentReason.OTHER));
073: }
074:
075: public void testSimpleSecondLine()
076: throws javax.swing.text.BadLocationException {
077: _setDocText(example1);
078: assertEquals(false, rule2.applyRule(_doc, 7,
079: Indenter.IndentReason.OTHER));
080: }
081:
082: public void testSlashStarMidLineFirstLine()
083: throws javax.swing.text.BadLocationException {
084: _setDocText(example2);
085: assertEquals(true, rule2.applyRule(_doc, 11,
086: Indenter.IndentReason.OTHER));
087: }
088:
089: public void testSlashStarMidLineSecondLine()
090: throws javax.swing.text.BadLocationException {
091: _setDocText(example2);
092: assertEquals(false, rule2.applyRule(_doc, 16,
093: Indenter.IndentReason.OTHER));
094: }
095:
096: public void testCommentedOutSlashStarBefore()
097: throws javax.swing.text.BadLocationException {
098: _setDocText(example3);
099: assertEquals(true, rule2.applyRule(_doc, 3,
100: Indenter.IndentReason.OTHER));
101: }
102:
103: public void testCommentedOutSlashStarAt()
104: throws javax.swing.text.BadLocationException {
105: _setDocText(example3);
106: assertEquals(false, rule2.applyRule(_doc, 7,
107: Indenter.IndentReason.OTHER));
108: }
109:
110: public void testCommentedOutSlashStarAfter()
111: throws javax.swing.text.BadLocationException {
112: _setDocText(example3);
113: assertEquals(false, rule2.applyRule(_doc, 13,
114: Indenter.IndentReason.OTHER));
115: }
116: }
|