1 33 34 package edu.rice.cs.drjava.model.definitions.reducedmodel; 35 36 40 public final class SingleQuoteTest extends BraceReductionTestCase 41 implements ReducedModelStates 42 { 43 47 public void testInsideQuotePrevious() { 48 model1.insertChar('\''); 49 model1.insertChar('\\'); 50 model1.insertChar('\''); 51 model1.move(-2); 52 assertEquals("#0.0", "\\'", model1.currentToken().getType()); 54 assertEquals("#0.1", INSIDE_SINGLE_QUOTE, stateOfCurrentToken(model1)); 55 model1.move(2); 56 model1.insertChar('\''); 57 model1.move(-1); 58 assertEquals("#1.0", "\'", model1.currentToken().getType()); 60 assertEquals("#1.1", FREE, stateOfCurrentToken(model1)); 61 assertTrue("#1.2", model1.currentToken().isClosed()); 62 model1.move(1); 63 model1.insertChar('\''); 64 model1.insertChar('\\'); 65 model1.insertChar('\\'); 66 model1.move(-2); 67 assertEquals("#2.0", "\\\\", model1.currentToken().getType()); 69 assertEquals("#2.1", INSIDE_SINGLE_QUOTE, stateOfCurrentToken(model1)); 70 model1.move(2); 71 model1.insertChar('\\'); 72 model1.move(-1); 73 assertEquals("#3.0", "\\", model1.currentToken().getType()); 75 assertEquals("#3.1", INSIDE_SINGLE_QUOTE, stateOfCurrentToken(model1)); 76 model1.move(1); 77 model1.insertChar('\''); 78 model1.move(-1); 79 assertEquals("#4.0", "\\'", model1.currentToken().getType()); 81 assertEquals("#4.1", INSIDE_SINGLE_QUOTE, stateOfCurrentToken(model1)); 82 } 83 84 89 public void testInsideQuoteNext() { 90 model1.insertChar('\''); 91 model1.insertChar('\''); 92 model1.move(-1); 93 model1.insertChar('\\'); 94 assertEquals("#0.0", "\\'", model1.currentToken().getType()); 95 assertEquals("#0.1", INSIDE_SINGLE_QUOTE, stateOfCurrentToken(model1)); 96 assertEquals("#0.2", 1, model1.getBlockOffset()); 97 model1.move(1); 98 model1.insertChar('\''); 99 model1.move(-1); 100 assertEquals("#1.0", "\'", model1.currentToken().getType()); 101 assertEquals("#1.1", FREE, stateOfCurrentToken(model1)); 102 assertTrue("#1.2", model1.currentToken().isClosed()); 103 model1.move(1); 104 model1.insertChar('\''); 105 model1.insertChar('\\'); 106 model1.move(-1); 107 model1.insertChar('\\'); 108 assertEquals("#2.0", "\\\\", model1.currentToken().getType()); 109 assertEquals("#2.1", INSIDE_SINGLE_QUOTE, stateOfCurrentToken(model1)); 110 assertEquals("#2.2", 6, model1.absOffset()); 111 model1.move(-2); 112 model1.insertChar('{'); 113 model1.move(-1); 114 assertEquals("#3.0", "{", model1.currentToken().getType()); 115 assertEquals("#3.1", FREE, stateOfCurrentToken(model1)); 116 model1.move(1); 117 model1.move(3); 118 model1.insertChar('\''); 119 model1.move(-1); 120 assertEquals("#4.0", "\'", model1.currentToken().getType()); 121 assertEquals("#4.1", FREE, stateOfCurrentToken(model1)); 122 assertTrue("#4.2", model1.currentToken().isClosed()); 123 model1.insertChar('\\'); 124 assertEquals("#5.0", "\\'", model1.currentToken().getType()); 125 assertEquals("#5.1", INSIDE_SINGLE_QUOTE, stateOfCurrentToken(model1)); 126 assertEquals("#5.2", 1, model1.getBlockOffset()); 127 } 128 129 134 public void testBackSlashBeforeDoubleEscape() { 135 model1.insertChar('\\'); 136 model1.insertChar('\\'); 137 model1.move(-2); 138 model1.insertChar('\\'); 139 assertEquals("#0.0", "\\\\", model1.currentToken().getType()); 140 assertEquals("#0.1", 2, model1.currentToken().getSize()); 141 model1.move(1); 142 assertEquals("#0.2", "\\", model1.currentToken().getType()); 143 model2.insertChar('\\'); 144 model2.insertChar('\''); 145 model2.move(-2); 146 model2.insertChar('\\'); 147 assertEquals("#1.0", "\\\\", model2.currentToken().getType()); 148 assertEquals("#1.1", 1, model2.absOffset()); 149 model2.move(1); 150 assertEquals("#1.2", "'", model2.currentToken().getType()); 151 } 152 153 158 public void testInsertBetweenDoubleEscape() { 159 model1.insertChar('\\'); 160 model1.insertChar('\\'); 161 model1.move(-1); 162 model1.insertChar('\\'); 163 model1.move(-2); 164 assertEquals("#0.0", "\\\\", model1.currentToken().getType()); 165 model1.move(2); 166 assertEquals("#0.1", "\\", model1.currentToken().getType()); 167 model2.insertChar('\\'); 168 model2.insertChar('\''); 169 model2.move(-1); 170 model2.insertChar('\\'); 171 model2.move(-2); 172 assertEquals("#1.0", "\\\\", model2.currentToken().getType()); 173 model2.move(2); 174 assertEquals("#1.1", "\'", model2.currentToken().getType()); 175 model0.insertChar('\\'); 176 model0.insertChar('\\'); 177 model0.move(-1); 178 model0.insertChar(')'); 179 model0.move(-2); 180 assertEquals("#2.0", "\\", model0.currentToken().getType()); 181 model0.move(1); 182 assertEquals("#2.1", ")", model0.currentToken().getType()); 183 model0.move(1); 184 assertEquals("#2.2", "\\", model0.currentToken().getType()); 185 model0.move(1); 186 model0.delete(-3); 187 model0.insertChar('\\'); 188 model0.insertChar('\''); 189 model0.move(-1); 190 model0.insertChar(')'); 191 model0.move(-2); 192 assertEquals("#3.0", "\\", model0.currentToken().getType()); 193 model0.move(1); 194 assertEquals("#3.1", ")", model0.currentToken().getType()); 195 model0.move(1); 196 assertEquals("#3.2", "'", model0.currentToken().getType()); 197 } 198 199 204 public void testDeleteAndCombine() { 205 model0.insertChar('\\'); 206 insertGap(model0, 2); 207 model0.insertChar('\''); 208 model0.move(-1); 209 assertEquals("#0.0", "\'", model0.currentToken().getType()); 210 model0.delete(-2); 211 assertEquals("#1.0", "\\'", model0.currentToken().getType()); 212 assertEquals("#1.1", 1, model0.absOffset()); 213 model0.delete(1); 214 insertGap(model0, 2); 215 model0.insertChar('\\'); 216 model0.move(-1); 217 assertEquals("#2.0", "\\", model0.currentToken().getType()); 218 model0.delete(-2); 219 assertEquals("#3.0", "\\\\", model0.currentToken().getType()); 220 assertEquals("#3.1", 2, model0.currentToken().getSize()); 221 } 222 223 226 public void testDeleteAndCombine2() { 227 model0.insertChar('\\'); 228 model0.insertChar('\''); 229 model0.move(-1); 230 model0.delete(-1); 231 assertEquals("#0.0", "\'", model0.currentToken().getType()); 232 assertEquals("#0.1", FREE, model0.getStateAtCurrent()); 233 model1.insertChar('\\'); 234 model1.insertChar('\\'); 235 model1.delete(-1); 236 model1.move(-1); 237 assertEquals("#1.0", "\\", model1.currentToken().getType()); 238 model1.move(1); 239 model1.insertChar('\\'); 240 model1.move(-1); 241 model1.delete(-1); 242 assertEquals("#2.0", "\\", model1.currentToken().getType()); 243 } 244 245 248 public void testDeleteAndCombine3() { 249 model0.insertChar('\\'); 250 model0.insertChar('\\'); 251 insertGap(model0, 3); 252 model0.insertChar('\\'); 253 model0.move(-1); 254 model0.delete(-4); 255 assertEquals("#0.0", "\\\\", model0.currentToken().getType()); 256 assertEquals("#0.1", 1, model0.absOffset()); 257 model1.insertChar('\\'); 258 insertGap(model1, 3); 259 model1.insertChar('\\'); 260 model1.insertChar('\''); 261 model1.move(-1); 262 model1.delete(-4); 263 assertEquals("#1.0", "\\\'", model1.currentToken().getType()); 264 assertEquals("#1.1", 1, model1.absOffset()); 265 } 266 267 271 public void testChainEffect() { 272 model0.insertChar('\''); 273 model0.insertChar('\\'); 274 model0.insertChar('\''); 275 model0.insertChar('\''); 276 model0.insertChar('\''); 277 model0.insertChar('\\'); 278 model0.insertChar('\''); 279 model0.insertChar('\''); 280 model0.insertChar('\''); 281 model0.insertChar('\\'); 282 model0.insertChar('\''); 283 model0.insertChar('\''); 284 model0.move(-1); 286 assertEquals("#0.0", "\'", model0.currentToken().getType()); 287 assertTrue("#0.1", model0.currentToken().isClosed()); 288 model0.move(-2); 289 assertEquals("#1.0", "\\'", model0.currentToken().getType()); 291 assertEquals("#1.1", INSIDE_SINGLE_QUOTE, stateOfCurrentToken(model0)); 292 model0.move(-1); 293 assertEquals("#1.2", "'", model0.currentToken().getType()); 294 assertEquals("#1.3", FREE, stateOfCurrentToken(model0)); 295 assertTrue("#1.4", model0.currentToken().isOpen()); 296 model0.move(1); 297 model0.insertChar('\\'); 298 assertEquals("#2.0", "\\\\", model0.currentToken().getType()); 300 assertEquals("#2.1", INSIDE_SINGLE_QUOTE, stateOfCurrentToken(model0)); 301 assertEquals("#2.2", 10, model0.absOffset()); 302 model0.move(-2); 303 assertEquals("#2.3", "'", model0.currentToken().getType()); 304 assertEquals("#2.4", FREE, stateOfCurrentToken(model0)); 305 assertTrue("#2.5", model0.currentToken().isOpen()); 306 model0.move(3); 307 assertEquals("#2.6", "'", model0.currentToken().getType()); 308 assertEquals("#2.7", FREE, stateOfCurrentToken(model0)); 309 assertTrue("#2.8", model0.currentToken().isClosed()); 310 model0.move(-1); 311 model0.insertChar('\''); 312 assertEquals("#3.0", "\\'", model0.currentToken().getType()); 314 assertEquals("#3.1", INSIDE_SINGLE_QUOTE, stateOfCurrentToken(model0)); 315 assertEquals("#3.2", 11, model0.absOffset()); 316 model0.move(-2); 317 assertEquals("#3.3", "\\'", model0.currentToken().getType()); 318 assertEquals("#3.4", INSIDE_SINGLE_QUOTE, stateOfCurrentToken(model0)); 319 model0.move(4); 320 assertEquals("#3.5", "'", model0.currentToken().getType()); 321 assertEquals("#3.6", FREE, stateOfCurrentToken(model0)); 322 assertTrue("#3.7", model0.currentToken().isClosed()); 323 model0.move(-12); 324 model0.delete(1); 326 model0.move(-1); 328 assertEquals("#4.0", "'", model0.currentToken().getType()); 330 assertTrue("#4.1", model0.currentToken().isOpen()); 331 assertEquals("#4.2", FREE, stateOfCurrentToken(model0)); 332 model0.move(1); 333 assertEquals("#4.3", "'", model0.currentToken().getType()); 335 assertTrue("#4.4", model0.currentToken().isClosed()); 336 assertEquals("#4.5", FREE, stateOfCurrentToken(model0)); 337 model0.move(1); 338 assertEquals("#5.0", "'", model0.currentToken().getType()); 340 assertTrue("#5.1", model0.currentToken().isOpen()); 341 assertEquals("#5.2", FREE, stateOfCurrentToken(model0)); 342 model0.move(1); 343 assertEquals("#5.3", "'", model0.currentToken().getType()); 345 assertTrue("#5.4", model0.currentToken().isClosed()); 346 assertEquals("#5.5", FREE, stateOfCurrentToken(model0)); 347 model0.move(1); 348 assertEquals("#5.6", "\\'", model0.currentToken().getType()); 350 assertEquals("#5.7", FREE, stateOfCurrentToken(model0)); 351 model0.move(2); 352 assertEquals("#6.0", "'", model0.currentToken().getType()); 354 assertTrue("#6.1", model0.currentToken().isOpen()); 355 assertEquals("#6.2", FREE, stateOfCurrentToken(model0)); 356 model0.move(1); 357 assertEquals("#6.3", "'", model0.currentToken().getType()); 359 assertTrue("#6.4", model0.currentToken().isClosed()); 360 assertEquals("#6.5", FREE, stateOfCurrentToken(model0)); 361 model0.move(1); 362 assertEquals("#6.6", "\\'", model0.currentToken().getType()); 364 assertEquals("#6.7", FREE, stateOfCurrentToken(model0)); 365 model0.move(2); 366 assertEquals("#6.0", "\\'", model0.currentToken().getType()); 368 assertEquals("#6.1", FREE, stateOfCurrentToken(model0)); 369 model0.move(2); 370 assertEquals("#6.2", "'", model0.currentToken().getType()); 372 assertTrue("#6.3", model0.currentToken().isOpen()); 373 assertEquals("#6.4", FREE, stateOfCurrentToken(model0)); 374 } 375 } 376 | Popular Tags |