1 33 34 package edu.rice.cs.drjava.model.definitions.indent; 35 36 import javax.swing.text.BadLocationException ; 37 38 46 public final class ActionBracePlusTest extends IndentRulesTestCase { 47 private String _text, _aligned; 48 49 private IndentRuleAction _action; 50 51 public void testNoSuffix() throws BadLocationException { 52 _action = new ActionBracePlus(""); 53 54 56 _text = 57 "method(\n"+ 58 ")\n"; 59 60 _aligned = 61 "method(\n"+ 62 " )\n"; 63 64 _setDocText(_text); 65 _action.indentLine(_doc, 0, Indenter.OTHER); assertEquals("START has no brace.", _text.length(), _doc.getLength()); 67 _action.indentLine(_doc, 7, Indenter.OTHER); assertEquals("START has no brace.", _text.length(), _doc.getLength()); 69 _action.indentLine(_doc, 8, Indenter.OTHER); assertEquals("Line aligned to open paren.", _aligned.length(), _doc.getLength()); 71 assertEquals("Line aligned to open paren.", _aligned, _doc.getText()); 72 } 73 74 75 public void testSpaceSuffix() throws BadLocationException 76 { 77 _action = new ActionBracePlus(" "); 78 79 81 _text = 82 "var = method(arg1,\n"+ 83 " arg2, arg3) + 4;"; 84 85 _aligned = 86 "var = method(arg1,\n"+ 87 " arg2, arg3) + 4;"; 88 89 _setDocText(_text); 90 _action.indentLine(_doc, 0, Indenter.OTHER); assertEquals("START has no brace.", _text.length(), _doc.getLength()); 92 _action.indentLine(_doc, 18, Indenter.OTHER); assertEquals("START has no brace.", _text.length(), _doc.getLength()); 94 _action.indentLine(_doc, 20, Indenter.OTHER); assertEquals("Line aligned to open paren.", _aligned.length(), _doc.getLength()); 96 assertEquals("Line aligned to open paren.", _aligned, _doc.getText()); 97 98 100 _text = 101 "boolean method(\n"+ 102 "int[] a, String b)\n"+ 103 "{}"; 104 _aligned = 105 "boolean method(\n"+ 106 " int[] a, String b)\n"+ 107 "{}"; 108 109 _setDocText(_text); 110 _action.indentLine(_doc, 0, Indenter.OTHER); assertEquals("START has no brace.", _text.length(), _doc.getLength()); 112 _action.indentLine(_doc, 15, Indenter.OTHER); assertEquals("START has no brace.", _text.length(), _doc.getLength()); 114 _action.indentLine(_doc, 16, Indenter.OTHER); assertEquals("Line aligned to open paren.", _aligned.length(), _doc.getLength()); 116 assertEquals("Line aligned to open paren.", _aligned, _doc.getText()); 117 118 120 _text = 121 "boolean method(\n"+ 122 "int[] a,\n"+ 123 " String b)\n"+ 124 "{}"; 125 _aligned = 126 "boolean method(\n"+ 127 " int[] a,\n"+ 128 " String b)\n"+ 129 "{}"; 130 131 _setDocText(_text); 132 _action.indentLine(_doc, 0, Indenter.OTHER); assertEquals("START has no brace.", _text.length(), _doc.getLength()); 134 _action.indentLine(_doc, 15, Indenter.OTHER); assertEquals("START has no brace.", _text.length(), _doc.getLength()); 136 _action.indentLine(_doc, 20, Indenter.OTHER); assertEquals("Line aligned to open paren.", _aligned, _doc.getText()); 138 139 141 _text = 142 "array[\n"+ 143 " new Listener() {\n"+ 144 " method() {\n"+ 145 " }\n"+ 146 " }]"; 147 _aligned = 148 "array[\n"+ 149 " new Listener() {\n"+ 150 " method() {\n"+ 151 " }\n"+ 152 " }]"; 153 154 _setDocText(_text); 155 _action.indentLine(_doc, 0, Indenter.OTHER); assertEquals("START has no brace.", _text.length(), _doc.getLength()); 157 _action.indentLine(_doc, 6, Indenter.OTHER); assertEquals("START has no brace.", _text.length(), _doc.getLength()); 159 _action.indentLine(_doc, 10, Indenter.OTHER); assertEquals("Line aligned to open bracket.", _aligned, _doc.getText()); 161 162 } 163 164 public void testLargeSuffix() throws BadLocationException 165 { 166 _action = new ActionBracePlus(" " + " "); 167 168 170 _text = 171 "var = method(foo.\n"+ 172 " bar(), arg3) + 4;"; 173 174 _aligned = 175 "var = method(foo.\n"+ 176 " bar(), arg3) + 4;"; 177 178 _setDocText(_text); 179 _action.indentLine(_doc, 0, Indenter.OTHER); assertEquals("START has no brace.", _text.length(), _doc.getLength()); 181 _action.indentLine(_doc, 17, Indenter.OTHER); assertEquals("START has no brace.", _text.length(), _doc.getLength()); 183 _action.indentLine(_doc, 25, Indenter.OTHER); assertEquals("Line aligned to open paren.", _aligned.length(), _doc.getLength()); 185 assertEquals("Line aligned to open paren.", _aligned, _doc.getText()); 186 } 187 188 public void testComment() throws BadLocationException 189 { 190 _action = new ActionBracePlus(" " + " "); 191 192 194 _text = 195 "foo(i,\n"+ 196 " j.\n" + 197 "bar().\n" + 198 "// bar();\n" + 199 "baz(),\n" + 200 " k);"; 201 202 _aligned = 203 "foo(i,\n"+ 204 " j.\n" + 205 " bar().\n" + 206 " // bar();\n" + 207 " baz(),\n" + 208 " k);"; 209 210 _setDocText(_text); 211 _action.indentLine(_doc, 14, Indenter.OTHER); _action.indentLine(_doc, 27, Indenter.OTHER); _action.indentLine(_doc, 43, Indenter.OTHER); assertEquals("Lines aligned plus one level.", 215 _aligned, _doc.getText()); 216 217 _action.indentLine(_doc, 54, Indenter.OTHER); assertEquals("Cursor after baz().", _aligned, _doc.getText()); 219 } 220 } 221 | Popular Tags |