1 33 34 package edu.rice.cs.drjava.model.definitions.indent; 35 36 import javax.swing.text.BadLocationException ; 37 38 43 public final class QuestionCurrLineStartsWithSkipCommentsTest extends IndentRulesTestCase 44 { 45 private String _text; 46 47 private IndentRuleQuestion _rule; 48 49 public void testNoPrefix() throws BadLocationException 50 { 51 _text = 52 "class A \n" + 53 "{ \n" + 54 " // one line comment \n" + 55 " int method1 \n" + 56 " /** \n" + 57 " * javadoc comment \n" + 58 " */ \n" + 59 " int method() \n" + 60 " { \n" + 61 " } \n" + 62 " /* multi line \n" + 63 " comment \n" + 64 " boolean method() \n" + 65 " { \n" + 66 " } \n" + 67 " */ \n" + 68 "}"; 69 70 _setDocText(_text); 71 72 IndentRuleQuestion rule = new QuestionCurrLineStartsWithSkipComments("", null, null); 73 74 76 assertTrue("At DOCSTART.", rule.applyRule(_doc, 0, Indenter.OTHER)); 77 assertTrue("At start of block.", rule.applyRule(_doc, 25, Indenter.OTHER)); 78 assertTrue("START starts one-line comment.", rule.applyRule(_doc, 54, Indenter.OTHER)); 79 assertTrue("START starts one-line comment.", rule.applyRule(_doc, 60, Indenter.OTHER)); 80 assertTrue("START starts javadoc comment.", rule.applyRule(_doc, 104, Indenter.OTHER)); 81 assertTrue("START starts javadoc comment.", rule.applyRule(_doc, 110, Indenter.OTHER)); 82 assertTrue("Line inside javadoc comment.", !rule.applyRule(_doc, 130, Indenter.OTHER)); 83 assertTrue("Line closes javadoc comment.", rule.applyRule(_doc, 150, Indenter.OTHER)); 84 assertTrue("START is free.", rule.applyRule(_doc, 180, Indenter.OTHER)); 85 assertTrue("START is free.", rule.applyRule(_doc, 230, Indenter.OTHER)); 86 assertTrue("START starts multi-line comment.", rule.applyRule(_doc, 260, Indenter.OTHER)); 87 assertTrue("Line inside multi-line comment.", !rule.applyRule(_doc, 275, Indenter.OTHER)); 88 assertTrue("Line inside multi-line comment.", !rule.applyRule(_doc, 300, Indenter.OTHER)); 89 assertTrue("Line closes multi-line comment.", rule.applyRule(_doc, 399, Indenter.OTHER)); 90 assertTrue("START is free.", rule.applyRule(_doc, 400, Indenter.OTHER)); 91 assertTrue("At end of document.", rule.applyRule(_doc, 401, Indenter.OTHER)); 92 } 93 94 public void testOpenBracePrefix() throws BadLocationException 95 { 96 _text = 97 "class A extends \n" + 98 "B { \n" + 99 " // { } \n" + 100 " int field; \n" + 101 " /** \n" + 102 " * { } \n" + 103 " */ \n" + 104 " int method() /* \n" + 105 " */ { \n" + 106 " } \n" + 107 " /* multi line \n" + 108 " comment \n" + 109 " boolean method() \n" + 110 "/**stuff*/ { // stuff\n" + 111 " } \n" + 112 " \n" + 113 "}"; 114 115 _setDocText(_text); 116 117 _rule = new QuestionCurrLineStartsWithSkipComments("{", null, null); 118 119 assertTrue("At DOCSTART - line doesn't start with an open brace.", !_rule.applyRule(_doc, 0, Indenter.OTHER)); 120 assertTrue("Line starts a block, but not the start of the line.", !_rule.applyRule(_doc, 25, Indenter.OTHER)); 121 assertTrue("Inside block - line starts with an alphanumeric character.",!_rule.applyRule(_doc, 30, Indenter.OTHER)); 122 assertTrue("Line starts a one-line comment.", !_rule.applyRule(_doc, 54, Indenter.OTHER)); 123 assertTrue("Line starts a one-line comment.", !_rule.applyRule(_doc, 60, Indenter.OTHER)); 124 assertTrue("Line starts with alphanumeric character.", !_rule.applyRule(_doc, 80, Indenter.OTHER)); 125 assertTrue("Line starts a javadoc comment.", !_rule.applyRule(_doc, 104, Indenter.OTHER)); 126 assertTrue("Line starts a javadoc comment.", !_rule.applyRule(_doc, 110, Indenter.OTHER)); 127 assertTrue("Line inside javadoc comment.", !_rule.applyRule(_doc, 130, Indenter.OTHER)); 128 assertTrue("Line starts with alphanumeric character.", !_rule.applyRule(_doc, 180, Indenter.OTHER)); 129 assertTrue("Line closes comment. It follows an open brace.", _rule.applyRule(_doc, 201, Indenter.OTHER)); 130 assertTrue("Line closes comment. It follows an open brace.", _rule.applyRule(_doc, 221, Indenter.OTHER)); 131 assertTrue("At end of block - line starts with a close brace.", !_rule.applyRule(_doc, 225, Indenter.OTHER)); 132 assertTrue("Line starts a multi-line comment.", !_rule.applyRule(_doc, 260, Indenter.OTHER)); 133 assertTrue("Line inside multi-line comment.", !_rule.applyRule(_doc, 275, Indenter.OTHER)); 134 assertTrue("Line inside multi-line comment.", !_rule.applyRule(_doc, 300, Indenter.OTHER)); 135 assertTrue("Line closes comment. It follows an open brace.", _rule.applyRule(_doc, 325, Indenter.OTHER)); 136 assertTrue("Line starts with a close brace.", !_rule.applyRule(_doc, 355, Indenter.OTHER)); 137 assertTrue("Empty line.", !_rule.applyRule(_doc, 390, Indenter.OTHER)); 138 assertTrue("At last character - line starts with a close brace.", !_rule.applyRule(_doc, 400, Indenter.OTHER)); 139 assertTrue("At end of document - line starts with a close brace.", !_rule.applyRule(_doc, 401, Indenter.OTHER)); 140 } 141 142 public void testCloseBracePrefix() throws BadLocationException 143 { 144 _text = 145 "class A \n" + 146 "{ \n" + 147 " // } } \n" + 148 " int field; \n" + 149 " /** \n" + 150 " * javadoc comment \n" + 151 " */ } \n" + 152 " int method() \n" + 153 "/**/} \n" + 154 "/ * } \n" + 155 " /* multi line \n" + 156 " comment \n" + 157 " boolean method() \n" + 158 " { \n" + 159 "*/ / } \n" + 160 " * } \n" + 161 "}"; 162 163 _setDocText(_text); 164 165 _rule = new QuestionCurrLineStartsWithSkipComments("}", null, null); 166 167 assertTrue("At DOCSTART - line doesn't start with a close brace.", !_rule.applyRule(_doc, 0, Indenter.OTHER)); 168 assertTrue("At start of block - line starts with an open brace.", !_rule.applyRule(_doc, 25, Indenter.OTHER)); 169 assertTrue("Inside block - line starts with an open brace.", !_rule.applyRule(_doc, 30, Indenter.OTHER)); 170 assertTrue("Line starts a one-line comment.", !_rule.applyRule(_doc, 54, Indenter.OTHER)); 171 assertTrue("Line starts a one-line comment.", !_rule.applyRule(_doc, 60, Indenter.OTHER)); 172 assertTrue("Line starts with alphanumeric character.", !_rule.applyRule(_doc, 80, Indenter.OTHER)); 173 assertTrue("Line starts a javadoc comment.", !_rule.applyRule(_doc, 104, Indenter.OTHER)); 174 assertTrue("Line starts a javadoc comment.", !_rule.applyRule(_doc, 110, Indenter.OTHER)); 175 assertTrue("Line inside javadoc comment.", !_rule.applyRule(_doc, 130, Indenter.OTHER)); 176 assertTrue("Line closes multi-line comment, it follows a close brace.", _rule.applyRule(_doc, 150, Indenter.OTHER)); 177 assertTrue("Line starts with alphanumeric character.", !_rule.applyRule(_doc, 180, Indenter.OTHER)); 178 assertTrue("Line starts with a comment, it follows a close brace.", _rule.applyRule(_doc, 221, Indenter.OTHER)); 179 assertTrue("At end of block - line starts with a slash.", !_rule.applyRule(_doc, 225, Indenter.OTHER)); 180 assertTrue("Line starts a multi-line comment.", !_rule.applyRule(_doc, 260, Indenter.OTHER)); 181 assertTrue("Line inside multi-line comment.", !_rule.applyRule(_doc, 275, Indenter.OTHER)); 182 assertTrue("Line inside multi-line comment.", !_rule.applyRule(_doc, 300, Indenter.OTHER)); 183 assertTrue("Line inside multi-line comment.", !_rule.applyRule(_doc, 325, Indenter.OTHER)); 184 assertTrue("Line closes multi-line comment, it follows a slash.", !_rule.applyRule(_doc, 355, Indenter.OTHER)); 185 assertTrue("Line starts with a star.", !_rule.applyRule(_doc, 376, Indenter.OTHER)); 186 assertTrue("At last character - line starts with a close brace.", _rule.applyRule(_doc, 400, Indenter.OTHER)); 187 assertTrue("At end of document - line starts with a close brace.", _rule.applyRule(_doc, 401, Indenter.OTHER)); 188 } 189 } 190 | Popular Tags |