1 33 34 package edu.rice.cs.drjava.model.definitions.reducedmodel; 35 36 40 public final class ReducedModelDeleteTest extends BraceReductionTestCase 41 implements ReducedModelStates 42 { 43 46 public void testHalfLineComment() { 47 model1.insertChar('/'); 48 model1.insertChar('/'); 49 model1.move(-2); 50 assertEquals("#0.0", "//", model1.currentToken().getType()); 51 assertEquals("#0.1", 0, model1.absOffset()); 52 model1.delete(1); 53 assertEquals("#1.0", "/", model1.currentToken().getType()); 54 assertEquals("#1.1", 0, model1.absOffset()); 55 model1.insertChar('/'); 56 model1.delete(1); assertEquals("#2.0", 1, model1.absOffset()); 58 model1.move(-1); 59 assertEquals("#2.1", 0, model1.absOffset()); 60 assertEquals("#2.2", "/", model1.currentToken().getType()); 61 model1.delete(1); 62 assertEquals("#3.0", 0, model1.absOffset()); 63 } 64 65 68 public void testInnerGapDelete() { 69 insertGap(model1, 8); 70 assertEquals("#0.0", 8, model1.absOffset()); 71 model1.move(-6); 72 assertEquals("#0.0", 2, model1.absOffset()); 73 model1.delete(3); 74 assertEquals("#1.0", 2, model1.absOffset()); 75 assertEquals("#1.1", 5, model1.currentToken().getSize()); 76 model1.move(3); 77 assertEquals("#2.0", 5, model1.absOffset()); 78 } 79 80 83 public void testDeleteAndMergeTwoGaps() { 84 insertGap(model1, 5); 85 model1.insertChar('/'); 86 assertEquals("#1.0", 6, model1.absOffset()); 87 model1.insertChar('*'); 88 assertEquals("#2.0", 7, model1.absOffset()); 89 insertGap(model1, 6); 90 assertEquals("#3.0", 13, model1.absOffset()); 91 model1.move(-9); 92 assertEquals("#4.0", 4, model1.absOffset()); 93 assertTrue("#4.1", model1.currentToken().isGap()); 94 assertEquals("#4.2", 5, model1.currentToken().getSize()); 95 model1.move(2); 96 assertEquals("#5.0", 6, model1.absOffset()); 97 assertEquals("#5.2", "/*", model1.currentToken().getType()); 98 model1.move(-2); 99 model1.delete(5); 100 assertEquals("#6.0", 4, model1.absOffset()); 101 assertTrue("#6.1", model1.currentToken().isGap()); 102 assertEquals("#6.2", 8, model1.currentToken().getSize()); 103 } 104 105 public void testDeleteBlockCommentMakesLineComment() { 106 model1.insertChar('/'); 107 assertEquals("#0.0", 1, model1.absOffset()); 108 assertEquals("#0.1", FREE, model1.getStateAtCurrent()); 109 model1.insertChar('*'); 110 assertEquals("#1.0", 2, model1.absOffset()); 111 assertEquals("#1.1", INSIDE_BLOCK_COMMENT, model1.getStateAtCurrent()); 112 insertGap(model1, 2); 113 assertEquals("#2.0", 4, model1.absOffset()); 114 assertEquals("#2.1", INSIDE_BLOCK_COMMENT, model1.getStateAtCurrent()); 115 model1.insertChar('*'); 116 assertEquals("#3.0", 5, model1.absOffset()); 117 assertEquals("#3.1", INSIDE_BLOCK_COMMENT, model1.getStateAtCurrent()); 118 model1.insertChar('/'); 119 assertEquals("#4.0", 6, model1.absOffset()); 120 assertEquals("#4.1", FREE, model1.getStateAtCurrent()); 121 insertGap(model1, 1); 122 assertEquals("#5.0", 7, model1.absOffset()); 123 assertEquals("#5.1", FREE, model1.getStateAtCurrent()); 124 model1.move(-6); 126 assertEquals("#6.0", 1, model1.absOffset()); 127 model1.delete(4); 128 assertEquals("#7.0", 1, model1.absOffset()); 129 assertEquals("#7.1", "//", model1.currentToken().getType()); 130 assertEquals("#7.3", FREE, model1.getStateAtCurrent()); 131 model1.move(1); 132 assertEquals("#7.0", 2, model1.absOffset()); 133 assertTrue("#7.1", model1.currentToken().isGap()); 134 assertEquals("#7.2", 1, model1.currentToken().getSize()); 135 assertEquals("#7.3", INSIDE_LINE_COMMENT, model1.getStateAtCurrent()); 136 } 137 138 public void testLineCommentStealsBlockCommentSlash() { 139 model1.insertChar('/'); 140 assertEquals("#0.0", 1, model1.absOffset()); 141 insertGap(model1, 2); 142 assertEquals("#1.0", 3, model1.absOffset()); 143 model1.insertChar('/'); 144 assertEquals("#2.0", 4, model1.absOffset()); 145 model1.insertChar('*'); 146 assertEquals("#3.0", 5, model1.absOffset()); 147 assertEquals("#3.1", INSIDE_BLOCK_COMMENT, model1.getStateAtCurrent()); 148 model1.move(-4); 149 model1.delete(2); 150 assertEquals("#4.0", 1, model1.absOffset()); 151 assertEquals("#4.1", "//", model1.currentToken().getType()); 152 assertEquals("#4.2", FREE, model1.getStateAtCurrent()); 153 model1.move(1); 154 assertEquals("#5.0", 2, model1.absOffset()); 155 assertEquals("#5.1", "*", model1.currentToken().getType()); 156 assertEquals("#5.2", INSIDE_LINE_COMMENT, model1.getStateAtCurrent()); 157 assertEquals("#5.3", INSIDE_LINE_COMMENT, model1.currentToken().getState()); 158 } 159 160 public void testLineCommentStealsLineCommentSlash() { 161 model1.insertChar('/'); 162 assertEquals("#0.0", 1, model1.absOffset()); 163 insertGap(model1, 2); 164 assertEquals("#1.0", 3, model1.absOffset()); 165 model1.insertChar('/'); 166 assertEquals("#2.0", 4, model1.absOffset()); 167 model1.insertChar('/'); 168 assertEquals("#3.0", 5, model1.absOffset()); 169 assertEquals("#3.1", INSIDE_LINE_COMMENT, model1.getStateAtCurrent()); 170 model1.move(-4); 171 model1.delete(2); 172 assertEquals("#4.0", 1, model1.absOffset()); 173 assertEquals("#4.1", "//", model1.currentToken().getType()); 174 assertEquals("#4.2", FREE, model1.getStateAtCurrent()); 175 model1.move(1); 176 assertEquals("#5.0", 2, model1.absOffset()); 177 assertEquals("#5.1", "/", model1.currentToken().getType()); 178 assertEquals("#5.2", INSIDE_LINE_COMMENT, model1.getStateAtCurrent()); 179 assertEquals("#5.3", INSIDE_LINE_COMMENT, model1.currentToken().getState()); 180 } 181 182 public void testDeleteNewlineAndShadowBlockCommentStart() { 183 model1.insertChar('/'); 184 assertEquals("#0.0", 1, model1.absOffset()); 185 assertEquals("#0.1", FREE, model1.getStateAtCurrent()); 186 model1.insertChar('/'); 187 assertEquals("#1.0", 2, model1.absOffset()); 188 assertEquals("#1.1", INSIDE_LINE_COMMENT, model1.getStateAtCurrent()); 189 model1.insertChar('*'); 190 assertEquals("#2.0", 3, model1.absOffset()); 191 assertEquals("#2.1", INSIDE_LINE_COMMENT, model1.getStateAtCurrent()); 192 model1.insertChar('\n'); 193 assertEquals("#3.0", 4, model1.absOffset()); 194 assertEquals("#3.1", FREE, model1.getStateAtCurrent()); 195 model1.insertChar('/'); 196 assertEquals("#4.0", 5, model1.absOffset()); 197 assertEquals("#4.1", FREE, model1.getStateAtCurrent()); 198 model1.insertChar('*'); 199 assertEquals("#5.0", 6, model1.absOffset()); 200 assertEquals("#5.1", INSIDE_BLOCK_COMMENT, model1.getStateAtCurrent()); 201 model1.move(-3); 202 assertEquals("#6.0", 3, model1.absOffset()); 203 model1.delete(1); 204 assertEquals("#7.0", 3, model1.absOffset()); 205 assertEquals("#7.1", "/", model1.currentToken().getType()); 206 assertEquals("#7.2", INSIDE_LINE_COMMENT, model1.currentToken().getState()); 207 model1.move(-1); 208 assertEquals("#8.0", 2, model1.absOffset()); 209 assertEquals("#8.1", "*", model1.currentToken().getType()); 210 assertEquals("#8.2", INSIDE_LINE_COMMENT, model1.currentToken().getState()); 211 model1.move(2); 212 assertEquals("#9.0", 4, model1.absOffset()); 213 assertEquals("#9.1", "*", model1.currentToken().getType()); 214 assertEquals("#9.2", INSIDE_LINE_COMMENT, model1.currentToken().getState()); 215 } 216 217 public void testBlockCommentStartEatsEnd() { 218 model1.insertChar('/'); 219 assertEquals("#0.0", 1, model1.absOffset()); 220 assertEquals("#0.1", FREE, model1.getStateAtCurrent()); 221 model1.insertChar('*'); 222 assertEquals("#1.0", 2, model1.absOffset()); 223 assertEquals("#1.1", INSIDE_BLOCK_COMMENT, model1.getStateAtCurrent()); 224 insertGap(model1, 2); 225 assertEquals("#2.0", 4, model1.absOffset()); 226 assertEquals("#2.1", INSIDE_BLOCK_COMMENT, model1.getStateAtCurrent()); 227 model1.insertChar('*'); 228 assertEquals("#3.0", 5, model1.absOffset()); 229 assertEquals("#3.1", INSIDE_BLOCK_COMMENT, model1.getStateAtCurrent()); 230 model1.insertChar('/'); 231 assertEquals("#4.0", 6, model1.absOffset()); 232 assertEquals("#4.1", FREE, model1.getStateAtCurrent()); 233 model1.move(-5); 234 assertEquals("#4.0", 1, model1.absOffset()); 235 assertEquals("#4.1", "/*", model1.currentToken().getType()); 236 assertEquals("#4.1", FREE, model1.getStateAtCurrent()); 237 model1.delete(3); 238 assertEquals("#5.0", 1, model1.absOffset()); 239 assertEquals("#5.1", "/*", model1.currentToken().getType()); 240 model1.move(1); 241 assertEquals("#6.0", 2, model1.absOffset()); 242 assertEquals("#6.1", "/", model1.currentToken().getType()); 243 assertEquals("#6.2", INSIDE_BLOCK_COMMENT, model1.getStateAtCurrent()); 244 assertEquals("#6.3", INSIDE_BLOCK_COMMENT, model1.currentToken().getState()); 245 model1.move(1); 246 assertEquals("#7.0", 3, model1.absOffset()); 247 assertEquals("#7.1", INSIDE_BLOCK_COMMENT, model1.getStateAtCurrent()); 248 } 249 250 public void deleteLineCommentSlashOpensBlockComment() { 251 model1.insertChar('/'); 252 model1.insertChar('/'); 253 model1.insertChar('*'); 254 model1.insertChar('\n'); 255 insertGap(model1, 2); 256 model1.insertChar('('); 257 model1.insertChar('*'); 258 model1.insertChar('/'); 259 assertEquals("#0.0", 9, model1.absOffset()); 260 assertEquals("#0.1", FREE, model1.getStateAtCurrent()); 261 model1.move(-1); 262 assertEquals("#1.0", 8, model1.absOffset()); 263 assertEquals("#1.1", FREE, model1.getStateAtCurrent()); 264 assertEquals("#1.2", "/", model1.currentToken().getType()); 265 model1.move(-1); 266 assertEquals("#2.0", 7, model1.absOffset()); 267 assertEquals("#2.1", FREE, model1.getStateAtCurrent()); 268 assertEquals("#2.2", "*", model1.currentToken().getType()); 269 model1.move(-1); 270 assertEquals("#3.0", 6, model1.absOffset()); 271 assertEquals("#3.1", FREE, model1.getStateAtCurrent()); 272 assertEquals("#3.2", "(", model1.currentToken().getType()); 273 model1.move(-2); 274 assertEquals("#4.0", 4, model1.absOffset()); 275 assertEquals("#4.1", FREE, model1.getStateAtCurrent()); 276 assertTrue("#4.2", model1.currentToken().isGap()); 277 assertEquals("#4.3", 2, model1.currentToken().getSize()); 278 model1.move(-1); 279 assertEquals("#5.0", 3, model1.absOffset()); 280 assertEquals("#5.1", INSIDE_LINE_COMMENT, model1.getStateAtCurrent()); 281 assertEquals("#5.2", "\n", model1.currentToken().getType()); 282 model1.move(-1); 283 assertEquals("#6.0", 2, model1.absOffset()); 284 assertEquals("#6.1", INSIDE_LINE_COMMENT, model1.getStateAtCurrent()); 285 assertEquals("#6.2", "*", model1.currentToken().getType()); 286 model1.move(-1); 287 assertEquals("#7.0", 1, model1.absOffset()); 288 assertEquals("#7.1", FREE, model1.getStateAtCurrent()); 289 assertEquals("#7.2", "//", model1.currentToken().getType()); 290 model1.delete(-1); 291 assertEquals("#8.0", 0, model1.absOffset()); 292 assertEquals("#8.1", FREE, model1.getStateAtCurrent()); 293 assertEquals("#8.2", "/*", model1.currentToken().getType()); 294 model1.move(7); 295 assertEquals("#8.0", 7, model1.absOffset()); 296 assertEquals("#8.1", INSIDE_BLOCK_COMMENT, model1.getStateAtCurrent()); 297 assertEquals("#8.2", "*/", model1.currentToken().getType()); 298 } 299 300 public void testStartDeleteGap() { 301 model1.insertChar('/'); 302 model1.insertChar('*'); 303 insertGap(model1, 2); 304 model1.insertChar('*'); 305 model1.insertChar('/'); 306 model1.move(-4); 307 model1.delete(2); 308 assertEquals("#0.0", 2, model1.absOffset()); 309 assertEquals("#0.1", "*/", model1.currentToken().getType()); 310 assertEquals("#0.2", INSIDE_BLOCK_COMMENT, model1.getStateAtCurrent()); 311 model1.move(-2); 312 assertEquals("#1.0", 0, model1.absOffset()); 313 assertEquals("#1.1", "/*", model1.currentToken().getType()); 314 assertEquals("#1.2", FREE, model1.getStateAtCurrent()); 315 } 316 317 public void testDeleteFreesBlockCommentEnd() { 318 model1.insertChar('/'); 319 model1.insertChar('*'); 320 assertEquals("#0.0", 2, model1.absOffset()); 321 322 insertGap(model1, 2); 323 assertEquals("#0.1", 4, model1.absOffset()); 324 325 model1.insertChar('*'); 326 model1.insertChar('/'); 327 assertEquals("#0.2", 6, model1.absOffset()); 328 329 model1.move(-6); 330 assertEquals("#0.3", 0, model1.absOffset()); 331 332 model1.delete(4); 333 assertEquals("#0.4", 0, model1.absOffset()); 334 assertEquals("#0.5", "*", model1.currentToken().getType()); 335 assertEquals("#0.6", FREE, model1.currentToken().getState()); 336 assertEquals("#0.7", FREE, model1.getStateAtCurrent()); 337 338 model1.move(1); 339 assertEquals("#1.0", 1, model1.absOffset()); 340 assertEquals("#1.1", "/", model1.currentToken().getType()); 341 assertEquals("#1.2", FREE, model1.currentToken().getState()); 342 assertEquals("#1.3", FREE, model1.getStateAtCurrent()); 343 } 344 345 public void testUnmaskBlockCommentedLineComment() { 346 model1.insertChar('/'); 347 model1.insertChar('*'); 348 insertGap(model1, 2); 349 model1.insertChar('/'); 350 model1.insertChar('/'); 351 model1.move(-1); 352 assertEquals("#0.0", 5, model1.absOffset()); 353 assertEquals("#0.1", "/", model1.currentToken().getType()); 354 assertEquals("#0.2", INSIDE_BLOCK_COMMENT, model1.currentToken().getState()); 355 assertEquals("#0.3", INSIDE_BLOCK_COMMENT, model1.getStateAtCurrent()); 356 model1.move(-1); 357 assertEquals("#0.0", 4, model1.absOffset()); 358 assertEquals("#0.1", "/", model1.currentToken().getType()); 359 assertEquals("#0.2", INSIDE_BLOCK_COMMENT, model1.currentToken().getState()); 360 assertEquals("#0.3", INSIDE_BLOCK_COMMENT, model1.getStateAtCurrent()); 361 model1.move(-4); 362 model1.delete(4); 363 assertEquals("#2.0", 0, model1.absOffset()); 364 assertEquals("#2.1", "//", model1.currentToken().getType()); 365 assertEquals("#2.2", FREE, model1.currentToken().getState()); 366 assertEquals("#2.3", FREE, model1.getStateAtCurrent()); 367 model1.move(2); 368 assertEquals("#3.0", 2, model1.absOffset()); 369 assertEquals("#3.1", INSIDE_LINE_COMMENT, model1.getStateAtCurrent()); 370 } 371 372 public void testCrazyDelete() { 373 model1.insertChar('/'); 374 model1.insertChar('/'); 375 model1.insertChar('*'); 376 insertGap(model1, 2); 377 model1.insertChar('\n'); 378 model1.insertChar('/'); 379 model1.insertChar('/'); 380 assertEquals("#0.0", 8, model1.absOffset()); 381 assertEquals("#0.1", INSIDE_LINE_COMMENT, model1.getStateAtCurrent()); 382 model1.move(-2); 383 assertEquals("#1.0", 6, model1.absOffset()); 384 assertEquals("#1.1", FREE, model1.getStateAtCurrent()); 385 assertEquals("#1.2", "//", model1.currentToken().getType()); 386 assertEquals("#1.3", FREE, model1.currentToken().getState()); 387 model1.move(-4); 388 model1.delete(4); 389 assertEquals("#2.0", 2, model1.absOffset()); 390 assertEquals("#2.1", "/", model1.currentToken().getType()); 391 assertEquals("#2.2", INSIDE_LINE_COMMENT, model1.currentToken().getState()); 392 model1.move(1); 393 assertEquals("#3.0", 3, model1.absOffset()); 394 assertEquals("#3.1", "/", model1.currentToken().getType()); 395 assertEquals("#3.2", INSIDE_LINE_COMMENT, model1.currentToken().getState()); 396 } 397 } 398 | Popular Tags |