1 33 34 package edu.rice.cs.drjava.model.definitions.reducedmodel; 35 36 import junit.framework.*; 37 38 42 public final class BackSlashTest extends BraceReductionTestCase 43 implements ReducedModelStates 44 { 45 46 protected ReducedModelControl model0; 47 protected ReducedModelControl model1; 48 protected ReducedModelControl model2; 49 50 53 protected void setUp() throws Exception { 54 super.setUp(); 55 model0 = new ReducedModelControl(); 56 model1 = new ReducedModelControl(); 57 model2 = new ReducedModelControl(); 58 } 59 60 64 public static Test suite() { 65 return new TestSuite(BackSlashTest.class); 66 } 67 68 73 protected void insertGap(BraceReduction model, int size) { 74 for (int i = 0; i < size; i++) { 75 model.insertChar(' '); 76 } 77 } 78 79 83 public void testInsideQuotePrevious() { 84 model1.insertChar('\"'); 85 model1.insertChar('\\'); 86 model1.insertChar('\"'); 87 model1.move(-2); 88 assertEquals("#0.0", "\\\"", model1.currentToken().getType()); 90 assertEquals("#0.1", INSIDE_DOUBLE_QUOTE, stateOfCurrentToken(model1)); 91 model1.move(2); 92 model1.insertChar('\"'); 93 model1.move(-1); 94 assertEquals("#1.0", "\"", model1.currentToken().getType()); 96 assertEquals("#1.1", FREE, stateOfCurrentToken(model1)); 97 assertTrue("#1.2", model1.currentToken().isClosed()); 98 model1.move(1); 99 model1.insertChar('\"'); 100 model1.insertChar('\\'); 101 model1.insertChar('\\'); 102 model1.move(-2); 103 assertEquals("#2.0", "\\\\", model1.currentToken().getType()); 105 assertEquals("#2.1", INSIDE_DOUBLE_QUOTE, stateOfCurrentToken(model1)); 106 model1.move(2); 107 model1.insertChar('\\'); 108 model1.move(-1); 109 assertEquals("#3.0", "\\", model1.currentToken().getType()); 111 assertEquals("#3.1", INSIDE_DOUBLE_QUOTE, stateOfCurrentToken(model1)); 112 model1.move(1); 113 model1.insertChar('\"'); 114 model1.move(-1); 115 assertEquals("#4.0", "\\\"", model1.currentToken().getType()); 117 assertEquals("#4.1", INSIDE_DOUBLE_QUOTE, stateOfCurrentToken(model1)); 118 } 119 120 125 public void testInsideQuoteNext() { 126 model1.insertChar('\"'); 127 model1.insertChar('\"'); 128 model1.move(-1); 129 model1.insertChar('\\'); 130 assertEquals("#0.0", "\\\"", model1.currentToken().getType()); 131 assertEquals("#0.1", INSIDE_DOUBLE_QUOTE, stateOfCurrentToken(model1)); 132 assertEquals("#0.2", 1, model1.getBlockOffset()); 133 model1.move(1); 134 model1.insertChar('\"'); 135 model1.move(-1); 136 assertEquals("#1.0", "\"", model1.currentToken().getType()); 137 assertEquals("#1.1", FREE, stateOfCurrentToken(model1)); 138 assertTrue("#1.2", model1.currentToken().isClosed()); 139 model1.move(1); 140 model1.insertChar('\"'); 141 model1.insertChar('\\'); 142 model1.move(-1); 143 model1.insertChar('\\'); 144 assertEquals("#2.0", "\\\\", model1.currentToken().getType()); 145 assertEquals("#2.1", INSIDE_DOUBLE_QUOTE, stateOfCurrentToken(model1)); 146 assertEquals("#2.2", 6, model1.absOffset()); 147 model1.move(-2); 148 model1.insertChar('{'); 149 model1.move(-1); 150 assertEquals("#3.0", "{", model1.currentToken().getType()); 151 assertEquals("#3.1", FREE, stateOfCurrentToken(model1)); 152 model1.move(1); 153 model1.move(3); 154 model1.insertChar('\"'); 155 model1.move(-1); 156 assertEquals("#4.0", "\"", model1.currentToken().getType()); 157 assertEquals("#4.1", FREE, stateOfCurrentToken(model1)); 158 assertTrue("#4.2", model1.currentToken().isClosed()); 159 model1.insertChar('\\'); 160 assertEquals("#5.0", "\\\"", model1.currentToken().getType()); 161 assertEquals("#5.1", INSIDE_DOUBLE_QUOTE, stateOfCurrentToken(model1)); 162 assertEquals("#5.2", 1, model1.getBlockOffset()); 163 } 164 165 170 public void testBackSlashBeforeDoubleEscape() { 171 model1.insertChar('\\'); 172 model1.insertChar('\\'); 173 model1.move(-2); 174 model1.insertChar('\\'); 175 assertEquals("#0.0", "\\\\", model1.currentToken().getType()); 176 assertEquals("#0.1", 2, model1.currentToken().getSize()); 177 model1.move(1); 178 assertEquals("#0.2", "\\", model1.currentToken().getType()); 179 model2.insertChar('\\'); 180 model2.insertChar('\"'); 181 model2.move(-2); 182 model2.insertChar('\\'); 183 assertEquals("#1.0", "\\\\", model2.currentToken().getType()); 184 assertEquals("#1.1", 1, model2.absOffset()); 185 model2.move(1); 186 assertEquals("#1.2", "\"", model2.currentToken().getType()); 187 } 188 189 194 public void testInsertBetweenDoubleEscape() { 195 model1.insertChar('\\'); 196 model1.insertChar('\\'); 197 model1.move(-1); 198 model1.insertChar('\\'); 199 model1.move(-2); 200 assertEquals("#0.0", "\\\\", model1.currentToken().getType()); 201 model1.move(2); 202 assertEquals("#0.1", "\\", model1.currentToken().getType()); 203 model2.insertChar('\\'); 204 model2.insertChar('\"'); 205 model2.move(-1); 206 model2.insertChar('\\'); 207 model2.move(-2); 208 assertEquals("#1.0", "\\\\", model2.currentToken().getType()); 209 model2.move(2); 210 assertEquals("#1.1", "\"", model2.currentToken().getType()); 211 model0.insertChar('\\'); 212 model0.insertChar('\\'); 213 model0.move(-1); 214 model0.insertChar(')'); 215 model0.move(-2); 216 assertEquals("#2.0", "\\", model0.currentToken().getType()); 217 model0.move(1); 218 assertEquals("#2.1", ")", model0.currentToken().getType()); 219 model0.move(1); 220 assertEquals("#2.2", "\\", model0.currentToken().getType()); 221 model0.move(1); 222 model0.delete(-3); 223 model0.insertChar('\\'); 224 model0.insertChar('\"'); 225 model0.move(-1); 226 model0.insertChar(')'); 227 model0.move(-2); 228 assertEquals("#3.0", "\\", model0.currentToken().getType()); 229 model0.move(1); 230 assertEquals("#3.1", ")", model0.currentToken().getType()); 231 model0.move(1); 232 assertEquals("#3.2", "\"", model0.currentToken().getType()); 233 } 234 235 240 public void testDeleteAndCombine() { 241 model0.insertChar('\\'); 242 insertGap(model0, 2); 243 model0.insertChar('\"'); 244 model0.move(-1); 245 assertEquals("#0.0", "\"", model0.currentToken().getType()); 246 model0.delete(-2); 247 assertEquals("#1.0", "\\\"", model0.currentToken().getType()); 248 assertEquals("#1.1", 1, model0.absOffset()); 249 model0.delete(1); 250 insertGap(model0, 2); 251 model0.insertChar('\\'); 252 model0.move(-1); 253 assertEquals("#2.0", "\\", model0.currentToken().getType()); 254 model0.delete(-2); 255 assertEquals("#3.0", "\\\\", model0.currentToken().getType()); 256 assertEquals("#3.1", 2, model0.currentToken().getSize()); 257 } 258 259 262 public void testDeleteAndCombine2() { 263 model0.insertChar('\\'); 264 model0.insertChar('\"'); 265 model0.move(-1); 266 model0.delete(-1); 267 assertEquals("#0.0", "\"", model0.currentToken().getType()); 268 assertEquals("#0.1", FREE, model0.getStateAtCurrent()); 269 model1.insertChar('\\'); 270 model1.insertChar('\\'); 271 model1.delete(-1); 272 model1.move(-1); 273 assertEquals("#1.0", "\\", model1.currentToken().getType()); 274 model1.move(1); 275 model1.insertChar('\\'); 276 model1.move(-1); 277 model1.delete(-1); 278 assertEquals("#2.0", "\\", model1.currentToken().getType()); 279 } 280 281 284 public void testDeleteAndCombine3() { 285 model0.insertChar('\\'); 286 model0.insertChar('\\'); 287 insertGap(model0, 3); 288 model0.insertChar('\\'); 289 model0.move(-1); 290 model0.delete(-4); 291 assertEquals("#0.0", "\\\\", model0.currentToken().getType()); 292 assertEquals("#0.1", 1, model0.absOffset()); 293 model1.insertChar('\\'); 294 insertGap(model1, 3); 295 model1.insertChar('\\'); 296 model1.insertChar('\"'); 297 model1.move(-1); 298 model1.delete(-4); 299 assertEquals("#1.0", "\\\"", model1.currentToken().getType()); 300 assertEquals("#1.1", 1, model1.absOffset()); 301 } 302 303 307 public void testChainEffect() { 308 model0.insertChar('\"'); 309 model0.insertChar('\\'); 310 model0.insertChar('\"'); 311 model0.insertChar('\"'); 312 model0.insertChar('\"'); 313 model0.insertChar('\\'); 314 model0.insertChar('\"'); 315 model0.insertChar('\"'); 316 model0.insertChar('\"'); 317 model0.insertChar('\\'); 318 model0.insertChar('\"'); 319 model0.insertChar('\"'); 320 model0.move(-1); 322 assertEquals("#0.0", "\"", model0.currentToken().getType()); 323 assertTrue("#0.1", model0.currentToken().isClosed()); 324 model0.move(-2); 325 assertEquals("#1.0", "\\\"", model0.currentToken().getType()); 327 assertEquals("#1.1", INSIDE_DOUBLE_QUOTE, stateOfCurrentToken(model0)); 328 model0.move(-1); 329 assertEquals("#1.2", "\"", model0.currentToken().getType()); 330 assertEquals("#1.3", FREE, stateOfCurrentToken(model0)); 331 assertTrue("#1.4", model0.currentToken().isOpen()); 332 model0.move(1); 333 model0.insertChar('\\'); 334 assertEquals("#2.0", "\\\\", model0.currentToken().getType()); 336 assertEquals("#2.1", INSIDE_DOUBLE_QUOTE, stateOfCurrentToken(model0)); 337 assertEquals("#2.2", 10, model0.absOffset()); 338 model0.move(-2); 339 assertEquals("#2.3", "\"", model0.currentToken().getType()); 340 assertEquals("#2.4", FREE, stateOfCurrentToken(model0)); 341 assertTrue("#2.5", model0.currentToken().isOpen()); 342 model0.move(3); 343 assertEquals("#2.6", "\"", model0.currentToken().getType()); 344 assertEquals("#2.7", FREE, stateOfCurrentToken(model0)); 345 assertTrue("#2.8", model0.currentToken().isClosed()); 346 model0.move(-1); 347 model0.insertChar('\"'); 348 assertEquals("#3.0", "\\\"", model0.currentToken().getType()); 350 assertEquals("#3.1", INSIDE_DOUBLE_QUOTE, stateOfCurrentToken(model0)); 351 assertEquals("#3.2", 11, model0.absOffset()); 352 model0.move(-2); 353 assertEquals("#3.3", "\\\"", model0.currentToken().getType()); 354 assertEquals("#3.4", INSIDE_DOUBLE_QUOTE, stateOfCurrentToken(model0)); 355 model0.move(4); 356 assertEquals("#3.5", "\"", model0.currentToken().getType()); 357 assertEquals("#3.6", FREE, stateOfCurrentToken(model0)); 358 assertTrue("#3.7", model0.currentToken().isClosed()); 359 model0.move(-12); 360 model0.delete(1); 362 model0.move(-1); 364 assertEquals("#4.0", "\"", model0.currentToken().getType()); 366 assertTrue("#4.1", model0.currentToken().isOpen()); 367 assertEquals("#4.2", FREE, stateOfCurrentToken(model0)); 368 model0.move(1); 369 assertEquals("#4.3", "\"", model0.currentToken().getType()); 371 assertTrue("#4.4", model0.currentToken().isClosed()); 372 assertEquals("#4.5", FREE, stateOfCurrentToken(model0)); 373 model0.move(1); 374 assertEquals("#5.0", "\"", model0.currentToken().getType()); 376 assertTrue("#5.1", model0.currentToken().isOpen()); 377 assertEquals("#5.2", FREE, stateOfCurrentToken(model0)); 378 model0.move(1); 379 assertEquals("#5.3", "\"", model0.currentToken().getType()); 381 assertTrue("#5.4", model0.currentToken().isClosed()); 382 assertEquals("#5.5", FREE, stateOfCurrentToken(model0)); 383 model0.move(1); 384 assertEquals("#5.6", "\\\"", model0.currentToken().getType()); 386 assertEquals("#5.7", FREE, stateOfCurrentToken(model0)); 387 model0.move(2); 388 assertEquals("#6.0", "\"", model0.currentToken().getType()); 390 assertTrue("#6.1", model0.currentToken().isOpen()); 391 assertEquals("#6.2", FREE, stateOfCurrentToken(model0)); 392 model0.move(1); 393 assertEquals("#6.3", "\"", model0.currentToken().getType()); 395 assertTrue("#6.4", model0.currentToken().isClosed()); 396 assertEquals("#6.5", FREE, stateOfCurrentToken(model0)); 397 model0.move(1); 398 assertEquals("#6.6", "\\\"", model0.currentToken().getType()); 400 assertEquals("#6.7", FREE, stateOfCurrentToken(model0)); 401 model0.move(2); 402 assertEquals("#6.0", "\\\"", model0.currentToken().getType()); 404 assertEquals("#6.1", FREE, stateOfCurrentToken(model0)); 405 model0.move(2); 406 assertEquals("#6.2", "\"", model0.currentToken().getType()); 408 assertTrue("#6.3", model0.currentToken().isOpen()); 409 assertEquals("#6.4", FREE, stateOfCurrentToken(model0)); 410 } 411 } 412 413 414 415 | Popular Tags |