1 33 34 package edu.rice.cs.drjava.model.definitions.indent; 35 36 import javax.swing.text.BadLocationException ; 37 38 43 public final class ActionStartStmtOfBracePlusTest extends IndentRulesTestCase { 44 45 46 49 public void testSingleLineContract() throws BadLocationException { 50 IndentRuleAction rule1 = new ActionStartStmtOfBracePlus(""); 51 IndentRuleAction rule2 = new ActionStartStmtOfBracePlus(" "); 53 String text = "public void foo() {\nbar();"; 54 String aligned1 = text; 55 String aligned2 = "public void foo() {\n bar();"; 56 57 _setDocText(text); 58 rule1.indentLine(_doc, 20, Indenter.OTHER); 59 assertEquals("single line contract, no indent, no suffix", 60 aligned1, _doc.getText()); 61 62 _setDocText(text); 63 rule2.indentLine(_doc, 20, Indenter.OTHER); 64 assertEquals("single line contract, no indent, with suffix", 65 aligned2, _doc.getText()); 66 } 67 68 71 public void testIndentedSingleLineContract() throws BadLocationException { 72 IndentRuleAction rule1 = new ActionStartStmtOfBracePlus(""); 73 IndentRuleAction rule2 = new ActionStartStmtOfBracePlus(" "); 75 String text = " y = new Foo() {\nbar();"; 76 String aligned1 = " y = new Foo() {\n bar();"; 77 String aligned2 = " y = new Foo() {\n bar();"; 78 79 _setDocText(text); 80 rule1.indentLine(_doc, 20, Indenter.OTHER); 81 assertEquals("single line contract, with indent, no suffix", 82 aligned1, _doc.getText()); 83 84 _setDocText(text); 85 rule2.indentLine(_doc, 20, Indenter.OTHER); 86 assertEquals("single line contract, with indent, with suffix", 87 aligned2, _doc.getText()); 88 } 89 90 93 public void testMultiLineContract() throws BadLocationException { 94 IndentRuleAction rule1 = new ActionStartStmtOfBracePlus(""); 95 IndentRuleAction rule2 = new ActionStartStmtOfBracePlus(" "); 97 String text = " foobar();\n" + 98 " int foo(int x,\n" + 99 " int y) {\n" + 100 "bar();"; 101 String aligned1 = " foobar();\n" + 102 " int foo(int x,\n" + 103 " int y) {\n" + 104 " bar();"; 105 String aligned2 = " foobar();\n" + 106 " int foo(int x,\n" + 107 " int y) {\n" + 108 " bar();"; 109 110 _setDocText(text); 111 rule1.indentLine(_doc, 56, Indenter.OTHER); 112 assertEquals("multi line contract, with indent, no suffix", 113 aligned1, _doc.getText()); 114 115 _setDocText(text); 116 rule2.indentLine(_doc, 56, Indenter.OTHER); 117 assertEquals("multi line contract, with indent, with suffix", 118 aligned2, _doc.getText()); 119 } 120 121 124 public void testForStatement() throws BadLocationException { 125 IndentRuleAction rule1 = new ActionStartStmtOfBracePlus(""); 126 IndentRuleAction rule2 = new ActionStartStmtOfBracePlus(" "); 128 String text = " for (int i=0; i<j; i++) {\nbar();"; 129 String aligned1 = " for (int i=0; i<j; i++) {\n bar();"; 130 String aligned2 = " for (int i=0; i<j; i++) {\n bar();"; 131 132 _setDocText(text); 133 rule1.indentLine(_doc, 28, Indenter.OTHER); 134 assertEquals("for statement, with indent, no suffix", 135 aligned1, _doc.getText()); 136 137 _setDocText(text); 138 rule2.indentLine(_doc, 28, Indenter.OTHER); 139 assertEquals("for statement, with indent, with suffix", 140 aligned2, _doc.getText()); 141 } 142 143 146 public void testMultiLineForStatement() throws BadLocationException { 147 IndentRuleAction rule1 = new ActionStartStmtOfBracePlus(""); 148 IndentRuleAction rule2 = new ActionStartStmtOfBracePlus(" "); 150 String text = " for (int i=0;\n" + 151 " i<j;\n" + 152 " i++)\n" + 153 " {\n" + 154 "bar();"; 155 String aligned1 = " for (int i=0;\n" + 156 " i<j;\n" + 157 " i++)\n" + 158 " {\n" + 159 " bar();"; 160 String aligned2 = " for (int i=0;\n" + 161 " i<j;\n" + 162 " i++)\n" + 163 " {\n" + 164 " bar();"; 165 166 _setDocText(text); 167 rule1.indentLine(_doc, 44, Indenter.OTHER); 168 assertEquals("multi-line for statement, with indent, no suffix", 169 aligned1, _doc.getText()); 170 171 _setDocText(text); 172 rule2.indentLine(_doc, 44, Indenter.OTHER); 173 assertEquals("multi-line for statement, with indent, with suffix", 174 aligned2, _doc.getText()); 175 } 176 177 209 210 213 public void testCommentedBrace() throws BadLocationException { 214 IndentRuleAction rule1 = new ActionStartStmtOfBracePlus(""); 215 IndentRuleAction rule2 = new ActionStartStmtOfBracePlus(" "); 217 String text = " void foo()\n" + 218 " {\n" + 219 " // {\n" + 220 "foo();\n"; 221 String aligned1 = " void foo()\n" + 222 " {\n" + 223 " // {\n" + 224 " foo();\n"; 225 String aligned2 = " void foo()\n" + 226 " {\n" + 227 " // {\n" + 228 " foo();\n"; 229 230 _setDocText(text); 231 rule1.indentLine(_doc, 30, Indenter.OTHER); 232 assertEquals("commented brace, no suffix", 233 aligned1, _doc.getText()); 234 235 _setDocText(text); 236 rule2.indentLine(_doc, 30, Indenter.OTHER); 237 assertEquals("commented brace, with suffix", 238 aligned2, _doc.getText()); 239 } 240 241 273 274 277 public void testNoBrace() throws BadLocationException { 278 IndentRuleAction rule1 = new ActionStartStmtOfBracePlus(""); 279 IndentRuleAction rule2 = new ActionStartStmtOfBracePlus(" "); 281 String text = "package foo;\n" + 282 "import bar.*;\n"; 283 String aligned1 = "package foo;\n" + 284 "import bar.*;\n"; 285 String aligned2 = "package foo;\n" + 286 " import bar.*;\n"; 287 288 _setDocText(text); 289 rule1.indentLine(_doc, 13, Indenter.OTHER); 290 assertEquals("no brace, no suffix", 291 aligned1, _doc.getText()); 292 293 _setDocText(text); 294 rule2.indentLine(_doc, 13, Indenter.OTHER); 295 assertEquals("no brace, with suffix", 296 aligned2, _doc.getText()); 297 } 298 } 299 300 301 302 | Popular Tags |