1 33 34 package edu.rice.cs.drjava.model.definitions.indent; 35 36 import javax.swing.text.BadLocationException ; 37 38 43 public final class QuestionHasCharPrecedingOpenBraceTest extends IndentRulesTestCase 44 { 45 private String _text; 46 47 49 public void testIsIn1DArray() throws BadLocationException 50 { _text = 52 "int[2][] a = \n" + 53 "{ \n" + 54 " a, // line comment \n" + 55 " int b, \n" + 56 " /** \n" + 57 " * javadoc comment \n" + 58 " */ \n" + 59 " START \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 char [] chars = {'='}; 73 IndentRuleQuestion rule = new QuestionHasCharPrecedingOpenBrace(chars, null, null); 74 75 assertTrue("At DOCSTART.", ! rule.applyRule(_doc, 0, Indenter.OTHER)); 76 assertTrue("At identifier.", ! rule.applyRule(_doc, 10, Indenter.OTHER)); 77 assertTrue("At start of array.", !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 stil in first.", rule.applyRule(_doc, 180, Indenter.OTHER)); 85 assertTrue("Second pseudo array element.", ! rule.applyRule(_doc, 230, Indenter.OTHER)); 86 assertTrue("Start of 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("Last close brace", !rule.applyRule(_doc, 400, Indenter.OTHER)); 91 assertTrue("At end of document.", !rule.applyRule(_doc, 401, Indenter.OTHER)); 92 } 93 public void testIsIn2DArray() throws BadLocationException 94 { _text = 96 "int[2][] a = \n" + 97 "{ \n" + 98 " { \n" + 99 " a, // line comment \n" + 100 " int b, \n" + 101 " /** \n" + 102 " */ \n" + 103 " START \n" + 104 " }, \n" + 105 " { \n" + 106 " /* = { multi line \n" + 107 " comment } \n" + 108 " boolean method() \n" + 109 " { \n" + 110 " } \n" + 111 " */} \n" + 112 "}" + 113 ""; 114 115 _setDocText(_text); 116 117 char [] chars = {'='}; 118 IndentRuleQuestion rule = new QuestionHasCharPrecedingOpenBrace(chars, null, null); 119 120 assertTrue("At DOCSTART.", ! rule.applyRule(_doc, 0, Indenter.OTHER)); 121 assertTrue("At identifier.", ! rule.applyRule(_doc, 10, Indenter.OTHER)); 122 assertTrue("At start of outer array", !rule.applyRule(_doc, 25, Indenter.OTHER)); 123 124 assertTrue("Before start of inner array", rule.applyRule(_doc, 50, Indenter.OTHER)); 125 126 assertTrue("Same line as inner {.", rule.applyRule(_doc, 54, Indenter.OTHER)); 127 assertTrue("Line after inner {.", !rule.applyRule(_doc, 75, Indenter.OTHER)); 128 assertTrue("START is stil in first.", !rule.applyRule(_doc, 180, Indenter.OTHER)); 129 130 assertTrue("Second pseudo array element.", rule.applyRule(_doc, 230, Indenter.OTHER)); 131 assertTrue("In multi-line comment.", ! rule.applyRule(_doc, 260, Indenter.OTHER)); 132 133 assertTrue("multi-line comment w/ = {.", ! rule.applyRule(_doc, 275, Indenter.OTHER)); 134 135 assertTrue("Line inside multi-line comment.", !rule.applyRule(_doc, 300, Indenter.OTHER)); 136 assertTrue("Line closes multi-line comment.", !rule.applyRule(_doc, 399, Indenter.OTHER)); 137 138 assertTrue("Last close brace", rule.applyRule(_doc, 400, Indenter.OTHER)); 139 assertTrue("At end of document.", rule.applyRule(_doc, 401, Indenter.OTHER)); 140 } 141 public void testNoEquals() throws BadLocationException 142 { _text = 144 "int[2][] a \n" + 145 "{ \n" + 146 " { \n" + 147 " a, // line comment \n" + 148 " int b, \n" + 149 " /** \n" + 150 " */ \n" + 151 " START \n" + 152 " }, \n" + 153 " { \n" + 154 " /* = { multi line \n" + 155 " comment } \n" + 156 " boolean method() \n" + 157 " { \n" + 158 " } \n" + 159 " */} \n" + 160 "}" + 161 ""; 162 163 _setDocText(_text); 164 165 char [] chars = {'='}; 166 IndentRuleQuestion rule = new QuestionHasCharPrecedingOpenBrace(chars, null, null); 167 168 assertTrue("At DOCSTART.", ! rule.applyRule(_doc, 0, Indenter.OTHER)); 169 assertTrue("At identifier.", ! rule.applyRule(_doc, 10, Indenter.OTHER)); 170 assertTrue("At start of outer array", !rule.applyRule(_doc, 25, Indenter.OTHER)); 171 172 assertTrue("Before start of inner array", ! rule.applyRule(_doc, 50, Indenter.OTHER)); 173 assertTrue("Same line as inner {.", !rule.applyRule(_doc, 54, Indenter.OTHER)); 174 assertTrue("Line after inner {.", !rule.applyRule(_doc, 75, Indenter.OTHER)); 175 assertTrue("START is stil in first.", !rule.applyRule(_doc, 180, Indenter.OTHER)); 176 177 } 178 } 179 | Popular Tags |