1 33 34 package edu.rice.cs.drjava.model.definitions.indent; 35 36 import javax.swing.text.BadLocationException ; 37 38 43 public final class QuestionPrevLineStartsWithTest extends IndentRulesTestCase { 44 45 46 public void testNoPrefix() throws BadLocationException { 47 IndentRuleQuestion rule = new QuestionPrevLineStartsWith("{", null, null); 48 49 _setDocText("}\nfoo();\n}\n"); 51 assertTrue("line after close brace (no open brace)", !rule.applyRule(_doc, 2, Indenter.OTHER)); 52 assertTrue("line after text (no open brace)", !rule.applyRule(_doc, 9, Indenter.OTHER)); 53 assertTrue("line after text (no open brace)", !rule.applyRule(_doc, 10, Indenter.OTHER)); 54 55 rule = new QuestionPrevLineStartsWith("*", null, null); 57 _setDocText("{\nfoo();"); 58 assertTrue("no star", !rule.applyRule(_doc, 6, Indenter.OTHER)); 59 60 } 61 62 63 public void testStartOfDocument() throws BadLocationException { 64 IndentRuleQuestion rule = new QuestionPrevLineStartsWith("{", null, null); 65 66 _setDocText("\nfoo();"); 68 assertTrue("first line", !rule.applyRule(_doc, 0, Indenter.OTHER)); 69 assertTrue("second line", !rule.applyRule(_doc, 2, Indenter.OTHER)); 70 } 71 72 73 public void testPrefixOnCurrLine() throws BadLocationException { 74 IndentRuleQuestion rule = new QuestionPrevLineStartsWith("}", null, null); 75 76 _setDocText("} foo();"); 78 assertTrue("before brace", !rule.applyRule(_doc, 0, Indenter.OTHER)); 79 assertTrue("after brace", !rule.applyRule(_doc, 2, Indenter.OTHER)); 80 81 _setDocText("foo();\n bar(); } foo();"); 83 assertTrue("before brace", !rule.applyRule(_doc, 7, Indenter.OTHER)); 84 assertTrue("after brace", !rule.applyRule(_doc, 18, Indenter.OTHER)); 85 } 86 87 88 public void testStartsWithPrefixWithText() throws BadLocationException { 89 IndentRuleQuestion rule = new QuestionPrevLineStartsWith("}", null, null); 90 91 _setDocText("}bar();\nfoo();\nbar();"); 93 assertTrue("line of brace (no space)", !rule.applyRule(_doc, 2, Indenter.OTHER)); 94 assertTrue("line after brace (no space)", rule.applyRule(_doc, 8, Indenter.OTHER)); 95 assertTrue("two lines after brace (no space)", !rule.applyRule(_doc, 16, Indenter.OTHER)); 96 97 rule = new QuestionPrevLineStartsWith("*", null, null); 99 _setDocText("foo\n * comment\nbar"); 100 assertTrue("just before star (with space)", !rule.applyRule(_doc, 4, Indenter.OTHER)); 101 assertTrue("just after star (with space)", !rule.applyRule(_doc, 6, Indenter.OTHER)); 102 assertTrue("line after star (with space)", rule.applyRule(_doc, 16, Indenter.OTHER)); 103 } 104 105 106 public void testStartsWithPrefixNoText() throws BadLocationException { 107 IndentRuleQuestion rule = new QuestionPrevLineStartsWith("*", null, null); 108 109 _setDocText("foo();\n*\nbar();\n}"); 111 assertTrue("line of star (no space)", !rule.applyRule(_doc, 8, Indenter.OTHER)); 112 assertTrue("line after star (no space)", rule.applyRule(_doc, 10, Indenter.OTHER)); 113 assertTrue("two lines after star (no space)", !rule.applyRule(_doc, 16, Indenter.OTHER)); 114 115 _setDocText("foo();\n * \nbar();\n{"); 117 assertTrue("line of star (with space)", !rule.applyRule(_doc, 7, Indenter.OTHER)); 118 assertTrue("just after star (with space)", !rule.applyRule(_doc, 11, Indenter.OTHER)); 119 assertTrue("line after star (with space)", rule.applyRule(_doc, 13, Indenter.OTHER)); 120 } 121 122 123 public void testMultipleCharPrefix() throws BadLocationException { 124 IndentRuleQuestion rule = new QuestionPrevLineStartsWith("* ", null, null); 125 126 _setDocText("*\n *\n * \n * foo\nbar"); 128 assertTrue("star", !rule.applyRule(_doc, 2, Indenter.OTHER)); 129 assertTrue("space star", !rule.applyRule(_doc, 5, Indenter.OTHER)); 130 assertTrue("space star space", rule.applyRule(_doc, 11, Indenter.OTHER)); 131 assertTrue("space star space text", rule.applyRule(_doc, 16, Indenter.OTHER)); 132 } 133 134 135 public void testCommentedPrefix() throws BadLocationException { 136 IndentRuleQuestion rule = new QuestionPrevLineStartsWith("*", null, null); 137 138 _setDocText("/**\n* \ncomment\n*/"); 140 assertTrue("just before star", !rule.applyRule(_doc, 4, Indenter.OTHER)); 141 assertTrue("just after star", !rule.applyRule(_doc, 6, Indenter.OTHER)); 142 assertTrue("line after star", rule.applyRule(_doc, 7, Indenter.OTHER)); 143 assertTrue("line after star", !rule.applyRule(_doc, 15, Indenter.OTHER)); 144 } 145 146 147 public void testCommentPrefix() throws BadLocationException { 148 IndentRuleQuestion rule = new QuestionPrevLineStartsWith("/**", null, null); 149 150 _setDocText("/**\n* \ncomment\n*/"); 152 assertTrue("just before star", rule.applyRule(_doc, 4, Indenter.OTHER)); 153 assertTrue("just after star", rule.applyRule(_doc, 6, Indenter.OTHER)); 154 assertTrue("line after star", !rule.applyRule(_doc, 7, Indenter.OTHER)); 155 assertTrue("line after star", !rule.applyRule(_doc, 15, Indenter.OTHER)); 156 } 157 158 159 public void testDoesNotStartWithPrefix() throws BadLocationException { 160 IndentRuleQuestion rule = new QuestionPrevLineStartsWith("*", null, null); 161 162 _setDocText("foo(); *\nbar();\n"); 164 assertTrue("line after star", !rule.applyRule(_doc, 10, Indenter.OTHER)); 165 } 166 167 168 } 169 | Popular Tags |