1/* 2 * Copyright 2001-2008 Artima, Inc. 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16package org.scalatest.matchers 17 18import org.scalatest._ 19import org.scalatest.prop.Checkers 20import org.scalacheck._ 21import Arbitrary._ 22import Prop._ 23 24class ShouldEndWithRegexSpec extends Spec with ShouldMatchers with Checkers with ReturnsNormallyThrowsAssertion { 25 26/* 27s should include substring t 28s should include regex t 29s should endWith substring t 30s should endWith regex t 31s should endWith substring t 32s should endWith regex t 33s should fullyMatch regex t 34*/ 35 36 describe("The endWith regex syntax") { 37 38 val decimal = """(-)?(\d+)(\.\d*)?""" 39 val decimalRegex = """(-)?(\d+)(\.\d*)?""".r 40 41 describe("(when the regex is specified by a string)") { 42 43 it("should do nothing if the string ends with substring that matched the regular expression specified as a string") { 44 45 "1.78" should endWith regex (".78") 46 "1.7" should endWith regex (decimal) 47 "21.7" should endWith regex (decimal) 48 "1.78" should endWith regex (decimal) 49 "x8" should endWith regex (decimal) 50 "x1." should endWith regex (decimal) 51 52 // The remaining are full matches, which should also work with "endWith" 53 "1.7" should endWith regex ("1.7") 54 "1.7" should endWith regex (decimal) 55 "-1.8" should endWith regex (decimal) 56 "8" should endWith regex (decimal) 57 "1." should endWith regex (decimal) 58 } 59 60 it("should do nothing if the string does not end with a substring that matched the regular expression specified as a string when used with not") { 61 62 "eight" should not { endWith regex (decimal) } 63 "one.eight" should not { endWith regex (decimal) } 64 65 "eight" should not endWith regex (decimal) 66 "one.eight" should not endWith regex (decimal) 67 } 68 69 it("should do nothing if the string does not end with a substring that matched the regular expression specified as a string when used in a logical-and expression") { 70 71 "b1.7" should (endWith regex (decimal) and (endWith regex (decimal))) 72 "b1.7" should ((endWith regex (decimal)) and (endWith regex (decimal))) 73 "b1.7" should (endWith regex (decimal) and endWith regex (decimal)) 74 75 "1.7" should (endWith regex (decimal) and (endWith regex (decimal))) 76 "1.7" should ((endWith regex (decimal)) and (endWith regex (decimal))) 77 "1.7" should (endWith regex (decimal) and endWith regex (decimal)) 78 } 79 80 it("should do nothing if the string does not end with a substring that matched the regular expression specified as a string when used in a logical-or expression") { 81 82 "b1.7" should (endWith regex ("hello") or (endWith regex (decimal))) 83 "b1.7" should ((endWith regex ("hello")) or (endWith regex (decimal))) 84 "b1.7" should (endWith regex ("hello") or endWith regex (decimal)) 85 86 "1.7" should (endWith regex ("hello") or (endWith regex (decimal))) 87 "1.7" should ((endWith regex ("hello")) or (endWith regex (decimal))) 88 "1.7" should (endWith regex ("hello") or endWith regex (decimal)) 89 } 90 91 it("should do nothing if the string does not end with a substring that matched the regular expression specified as a string when used in a logical-and expression with not") { 92 "fred" should (not (endWith regex ("bob")) and not (endWith regex (decimal))) 93 "fred" should ((not endWith regex ("bob")) and (not endWith regex (decimal))) 94 "fred" should (not endWith regex ("bob") and not endWith regex (decimal)) 95 } 96 97 it("should do nothing if the string does not end with a substring that matched the regular expression specified as a string when used in a logical-or expression with not") { 98 "fred" should (not (endWith regex ("fred")) or not (endWith regex (decimal))) 99 "fred" should ((not endWith regex ("fred")) or (not endWith regex (decimal))) 100 "fred" should (not endWith regex ("fred") or not endWith regex (decimal)) 101 } 102 103 it("should throw TestFailedException if the string does not match substring that matched the regular expression specified as a string") { 104 105 val caught1 = intercept[TestFailedException] { 106 "1.7" should endWith regex ("1.78") 107 } 108 assert(caught1.getMessage === "\"1.7\" did not end with a substring that matched the regular expression 1.78") 109 110 val caught2 = intercept[TestFailedException] { 111 "1.7" should endWith regex ("21.7") 112 } 113 assert(caught2.getMessage === "\"1.7\" did not end with a substring that matched the regular expression 21.7") 114 115 val caught3 = intercept[TestFailedException] { 116 "-one.eight" should endWith regex (decimal) 117 } 118 assert(caught3.getMessage === "\"-one.eight\" did not end with a substring that matched the regular expression (-)?(\\d+)(\\.\\d*)?") 119 120 val caught6 = intercept[TestFailedException] { 121 "eight" should endWith regex (decimal) 122 } 123 assert(caught6.getMessage === "\"eight\" did not end with a substring that matched the regular expression (-)?(\\d+)(\\.\\d*)?") 124 125 val caught7 = intercept[TestFailedException] { 126 "1.eight" should endWith regex (decimal) 127 } 128 assert(caught7.getMessage === "\"1.eight\" did not end with a substring that matched the regular expression (-)?(\\d+)(\\.\\d*)?") 129 130 val caught8 = intercept[TestFailedException] { 131 "onedoteight" should endWith regex (decimal) 132 } 133 assert(caught8.getMessage === "\"onedoteight\" did not end with a substring that matched the regular expression (-)?(\\d+)(\\.\\d*)?") 134 135 val caught9 = intercept[TestFailedException] { 136 "***" should endWith regex (decimal) 137 } 138 assert(caught9.getMessage === "\"***\" did not end with a substring that matched the regular expression (-)?(\\d+)(\\.\\d*)?") 139 } 140 141 it("should throw TestFailedException if the string does matches substring that matched the regular expression specified as a string when used with not") { 142 143 val caught1 = intercept[TestFailedException] { 144 "1.7" should not { endWith regex ("1.7") } 145 } 146 assert(caught1.getMessage === "\"1.7\" ended with a substring that matched the regular expression 1.7") 147 148 val caught2 = intercept[TestFailedException] { 149 "1.7" should not { endWith regex (decimal) } 150 } 151 assert(caught2.getMessage === "\"1.7\" ended with a substring that matched the regular expression (-)?(\\d+)(\\.\\d*)?") 152 153 val caught3 = intercept[TestFailedException] { 154 "-1.8" should not { endWith regex (decimal) } 155 } 156 assert(caught3.getMessage === "\"-1.8\" ended with a substring that matched the regular expression (-)?(\\d+)(\\.\\d*)?") 157 158 val caught4 = intercept[TestFailedException] { 159 "8" should not { endWith regex (decimal) } 160 } 161 assert(caught4.getMessage === "\"8\" ended with a substring that matched the regular expression (-)?(\\d+)(\\.\\d*)?") 162 163 val caught5 = intercept[TestFailedException] { 164 "1." should not { endWith regex (decimal) } 165 } 166 assert(caught5.getMessage === "\"1.\" ended with a substring that matched the regular expression (-)?(\\d+)(\\.\\d*)?") 167 168 val caught11 = intercept[TestFailedException] { 169 "1.7" should not endWith regex ("1.7") 170 } 171 assert(caught11.getMessage === "\"1.7\" ended with a substring that matched the regular expression 1.7") 172 173 val caught12 = intercept[TestFailedException] { 174 "1.7" should not endWith regex (decimal) 175 } 176 assert(caught12.getMessage === "\"1.7\" ended with a substring that matched the regular expression (-)?(\\d+)(\\.\\d*)?") 177 178 val caught13 = intercept[TestFailedException] { 179 "-1.8" should not endWith regex (decimal) 180 } 181 assert(caught13.getMessage === "\"-1.8\" ended with a substring that matched the regular expression (-)?(\\d+)(\\.\\d*)?") 182 183 val caught14 = intercept[TestFailedException] { 184 "8" should not endWith regex (decimal) 185 } 186 assert(caught14.getMessage === "\"8\" ended with a substring that matched the regular expression (-)?(\\d+)(\\.\\d*)?") 187 188 val caught15 = intercept[TestFailedException] { 189 "1." should not endWith regex (decimal) 190 } 191 assert(caught15.getMessage === "\"1.\" ended with a substring that matched the regular expression (-)?(\\d+)(\\.\\d*)?") 192 193 // The rest are non-exact matches 194 val caught21 = intercept[TestFailedException] { 195 "a1.7" should not { endWith regex ("1.7") } 196 } 197 assert(caught21.getMessage === "\"a1.7\" ended with a substring that matched the regular expression 1.7") 198 199 val caught22 = intercept[TestFailedException] { 200 "b1.7" should not { endWith regex (decimal) } 201 } 202 assert(caught22.getMessage === "\"b1.7\" ended with a substring that matched the regular expression (-)?(\\d+)(\\.\\d*)?") 203 204 val caught23 = intercept[TestFailedException] { 205 "b-1.8" should not { endWith regex (decimal) } 206 } 207 assert(caught23.getMessage === "\"b-1.8\" ended with a substring that matched the regular expression (-)?(\\d+)(\\.\\d*)?") 208 } 209 210 it("should throw TestFailedException if the string ends with substring that matched the regular expression specified as a string when used in a logical-and expression") { 211 212 val caught1 = intercept[TestFailedException] { 213 "1.7" should (endWith regex (decimal) and (endWith regex ("1.8"))) 214 } 215 assert(caught1.getMessage === "\"1.7\" ended with a substring that matched the regular expression (-)?(\\d+)(\\.\\d*)?, but \"1.7\" did not end with a substring that matched the regular expression 1.8") 216 217 val caught2 = intercept[TestFailedException] { 218 "1.7" should ((endWith regex (decimal)) and (endWith regex ("1.8"))) 219 } 220 assert(caught2.getMessage === "\"1.7\" ended with a substring that matched the regular expression (-)?(\\d+)(\\.\\d*)?, but \"1.7\" did not end with a substring that matched the regular expression 1.8") 221 222 val caught3 = intercept[TestFailedException] { 223 "1.7" should (endWith regex (decimal) and endWith regex ("1.8")) 224 } 225 assert(caught3.getMessage === "\"1.7\" ended with a substring that matched the regular expression (-)?(\\d+)(\\.\\d*)?, but \"1.7\" did not end with a substring that matched the regular expression 1.8") 226 227 // Check to make sure the error message "short circuits" (i.e., just reports the left side's failure) 228 val caught4 = intercept[TestFailedException] { 229 "1.eight" should (endWith regex (decimal) and (endWith regex ("1.8"))) 230 } 231 assert(caught4.getMessage === "\"1.eight\" did not end with a substring that matched the regular expression (-)?(\\d+)(\\.\\d*)?") 232 233 val caught5 = intercept[TestFailedException] { 234 "1.eight" should ((endWith regex (decimal)) and (endWith regex ("1.8"))) 235 } 236 assert(caught5.getMessage === "\"1.eight\" did not end with a substring that matched the regular expression (-)?(\\d+)(\\.\\d*)?") 237 238 val caught6 = intercept[TestFailedException] { 239 "1.eight" should (endWith regex (decimal) and endWith regex ("1.8")) 240 } 241 assert(caught6.getMessage === "\"1.eight\" did not end with a substring that matched the regular expression (-)?(\\d+)(\\.\\d*)?") 242 } 243 244 it("should throw TestFailedException if the string ends with substring that matched the regular expression specified as a string when used in a logical-or expression") { 245 246 val caught1 = intercept[TestFailedException] { 247 "1.seven" should (endWith regex (decimal) or (endWith regex ("1.8"))) 248 } 249 assert(caught1.getMessage === "\"1.seven\" did not end with a substring that matched the regular expression (-)?(\\d+)(\\.\\d*)?, and \"1.seven\" did not end with a substring that matched the regular expression 1.8") 250 251 val caught2 = intercept[TestFailedException] { 252 "1.seven" should ((endWith regex (decimal)) or (endWith regex ("1.8"))) 253 } 254 assert(caught2.getMessage === "\"1.seven\" did not end with a substring that matched the regular expression (-)?(\\d+)(\\.\\d*)?, and \"1.seven\" did not end with a substring that matched the regular expression 1.8") 255 256 val caught3 = intercept[TestFailedException] { 257 "1.seven" should (endWith regex (decimal) or endWith regex ("1.8")) 258 } 259 assert(caught3.getMessage === "\"1.seven\" did not end with a substring that matched the regular expression (-)?(\\d+)(\\.\\d*)?, and \"1.seven\" did not end with a substring that matched the regular expression 1.8") 260 } 261 262 it("should throw TestFailedException if the string ends with substring that matched the regular expression specified as a string when used in a logical-and expression used with not") { 263 264 val caught1 = intercept[TestFailedException] { 265 "1.7" should (not endWith regex ("1.8") and (not endWith regex (decimal))) 266 } 267 assert(caught1.getMessage === "\"1.7\" did not end with a substring that matched the regular expression 1.8, but \"1.7\" ended with a substring that matched the regular expression (-)?(\\d+)(\\.\\d*)?") 268 269 val caught2 = intercept[TestFailedException] { 270 "1.7" should ((not endWith regex ("1.8")) and (not endWith regex (decimal))) 271 } 272 assert(caught2.getMessage === "\"1.7\" did not end with a substring that matched the regular expression 1.8, but \"1.7\" ended with a substring that matched the regular expression (-)?(\\d+)(\\.\\d*)?") 273 274 val caught3 = intercept[TestFailedException] { 275 "1.7" should (not endWith regex ("1.8") and not endWith regex (decimal)) 276 } 277 assert(caught3.getMessage === "\"1.7\" did not end with a substring that matched the regular expression 1.8, but \"1.7\" ended with a substring that matched the regular expression (-)?(\\d+)(\\.\\d*)?") 278 279 val caught4 = intercept[TestFailedException] { 280 "a1.7" should (not endWith regex ("1.8") and (not endWith regex (decimal))) 281 } 282 assert(caught4.getMessage === "\"a1.7\" did not end with a substring that matched the regular expression 1.8, but \"a1.7\" ended with a substring that matched the regular expression (-)?(\\d+)(\\.\\d*)?") 283 284 val caught5 = intercept[TestFailedException] { 285 "1.7" should ((not endWith regex ("1.8")) and (not endWith regex (decimal))) 286 } 287 assert(caught5.getMessage === "\"1.7\" did not end with a substring that matched the regular expression 1.8, but \"1.7\" ended with a substring that matched the regular expression (-)?(\\d+)(\\.\\d*)?") 288 } 289 290 it("should throw TestFailedException if the string ends with substring that matched the regular expression specified as a string when used in a logical-or expression used with not") { 291 292 val caught1 = intercept[TestFailedException] { 293 "1.7" should (not endWith regex (decimal) or (not endWith regex ("1.7"))) 294 } 295 assert(caught1.getMessage === "\"1.7\" ended with a substring that matched the regular expression (-)?(\\d+)(\\.\\d*)?, and \"1.7\" ended with a substring that matched the regular expression 1.7") 296 297 val caught2 = intercept[TestFailedException] { 298 "1.7" should ((not endWith regex (decimal)) or (not endWith regex ("1.7"))) 299 } 300 assert(caught2.getMessage === "\"1.7\" ended with a substring that matched the regular expression (-)?(\\d+)(\\.\\d*)?, and \"1.7\" ended with a substring that matched the regular expression 1.7") 301 302 val caught3 = intercept[TestFailedException] { 303 "1.7" should (not endWith regex (decimal) or not endWith regex ("1.7")) 304 } 305 assert(caught3.getMessage === "\"1.7\" ended with a substring that matched the regular expression (-)?(\\d+)(\\.\\d*)?, and \"1.7\" ended with a substring that matched the regular expression 1.7") 306 307 val caught4 = intercept[TestFailedException] { 308 "1.7" should (not (endWith regex (decimal)) or not (endWith regex ("1.7"))) 309 } 310 assert(caught4.getMessage === "\"1.7\" ended with a substring that matched the regular expression (-)?(\\d+)(\\.\\d*)?, and \"1.7\" ended with a substring that matched the regular expression 1.7") 311 312 val caught5 = intercept[TestFailedException] { 313 "a1.7" should (not endWith regex (decimal) or (not endWith regex ("1.7"))) 314 } 315 assert(caught5.getMessage === "\"a1.7\" ended with a substring that matched the regular expression (-)?(\\d+)(\\.\\d*)?, and \"a1.7\" ended with a substring that matched the regular expression 1.7") 316 } 317 } 318 319 describe("(when the regex is specified by an actual Regex)") { 320 321 it("should do nothing if the string ends with substring that matched the regular expression specified as a string") { 322 323 "1.78" should endWith regex (".78") 324 "1.7" should endWith regex (decimalRegex) 325 "21.7" should endWith regex (decimalRegex) 326 "1.78" should endWith regex (decimalRegex) 327 "x8" should endWith regex (decimalRegex) 328 "x1." should endWith regex (decimalRegex) 329 330 // The remaining are full matches, which should also work with "endWith" 331 "1.7" should endWith regex ("1.7") 332 "1.7" should endWith regex (decimalRegex) 333 "-1.8" should endWith regex (decimalRegex) 334 "8" should endWith regex (decimalRegex) 335 "1." should endWith regex (decimalRegex) 336 } 337 338 it("should do nothing if the string does not end with a substring that matched the regular expression specified as a string when used with not") { 339 340 "eight" should not { endWith regex (decimalRegex) } 341 "one.eight" should not { endWith regex (decimalRegex) } 342 343 "eight" should not endWith regex (decimalRegex) 344 "one.eight" should not endWith regex (decimalRegex) 345 } 346 347 it("should do nothing if the string does not end with a substring that matched the regular expression specified as a string when used in a logical-and expression") { 348 349 "b1.7" should (endWith regex (decimalRegex) and (endWith regex (decimalRegex))) 350 "b1.7" should ((endWith regex (decimalRegex)) and (endWith regex (decimalRegex))) 351 "b1.7" should (endWith regex (decimalRegex) and endWith regex (decimalRegex)) 352 353 "1.7" should (endWith regex (decimalRegex) and (endWith regex (decimalRegex))) 354 "1.7" should ((endWith regex (decimalRegex)) and (endWith regex (decimalRegex))) 355 "1.7" should (endWith regex (decimalRegex) and endWith regex (decimalRegex)) 356 } 357 358 it("should do nothing if the string does not end with a substring that matched the regular expression specified as a string when used in a logical-or expression") { 359 360 "b1.7" should (endWith regex ("hello") or (endWith regex (decimalRegex))) 361 "b1.7" should ((endWith regex ("hello")) or (endWith regex (decimalRegex))) 362 "b1.7" should (endWith regex ("hello") or endWith regex (decimalRegex)) 363 364 "1.7" should (endWith regex ("hello") or (endWith regex (decimalRegex))) 365 "1.7" should ((endWith regex ("hello")) or (endWith regex (decimalRegex))) 366 "1.7" should (endWith regex ("hello") or endWith regex (decimalRegex)) 367 } 368 369 it("should do nothing if the string does not end with a substring that matched the regular expression specified as a string when used in a logical-and expression with not") { 370 "fred" should (not (endWith regex ("bob")) and not (endWith regex (decimalRegex))) 371 "fred" should ((not endWith regex ("bob")) and (not endWith regex (decimalRegex))) 372 "fred" should (not endWith regex ("bob") and not endWith regex (decimalRegex)) 373 } 374 375 it("should do nothing if the string does not end with a substring that matched the regular expression specified as a string when used in a logical-or expression with not") { 376 "fred" should (not (endWith regex ("fred")) or not (endWith regex (decimalRegex))) 377 "fred" should ((not endWith regex ("fred")) or (not endWith regex (decimalRegex))) 378 "fred" should (not endWith regex ("fred") or not endWith regex (decimalRegex)) 379 } 380 381 it("should throw TestFailedException if the string does not match substring that matched the regular expression specified as a string") { 382 383 val caught1 = intercept[TestFailedException] { 384 "1.7" should endWith regex ("1.78") 385 } 386 assert(caught1.getMessage === "\"1.7\" did not end with a substring that matched the regular expression 1.78") 387 388 val caught2 = intercept[TestFailedException] { 389 "1.7" should endWith regex ("21.7") 390 } 391 assert(caught2.getMessage === "\"1.7\" did not end with a substring that matched the regular expression 21.7") 392 393 val caught3 = intercept[TestFailedException] { 394 "-one.eight" should endWith regex (decimalRegex) 395 } 396 assert(caught3.getMessage === "\"-one.eight\" did not end with a substring that matched the regular expression (-)?(\\d+)(\\.\\d*)?") 397 398 val caught6 = intercept[TestFailedException] { 399 "eight" should endWith regex (decimalRegex) 400 } 401 assert(caught6.getMessage === "\"eight\" did not end with a substring that matched the regular expression (-)?(\\d+)(\\.\\d*)?") 402 403 val caught7 = intercept[TestFailedException] { 404 "1.eight" should endWith regex (decimalRegex) 405 } 406 assert(caught7.getMessage === "\"1.eight\" did not end with a substring that matched the regular expression (-)?(\\d+)(\\.\\d*)?") 407 408 val caught8 = intercept[TestFailedException] { 409 "onedoteight" should endWith regex (decimalRegex) 410 } 411 assert(caught8.getMessage === "\"onedoteight\" did not end with a substring that matched the regular expression (-)?(\\d+)(\\.\\d*)?") 412 413 val caught9 = intercept[TestFailedException] { 414 "***" should endWith regex (decimalRegex) 415 } 416 assert(caught9.getMessage === "\"***\" did not end with a substring that matched the regular expression (-)?(\\d+)(\\.\\d*)?") 417 } 418 419 it("should throw TestFailedException if the string does matches substring that matched the regular expression specified as a string when used with not") { 420 421 val caught1 = intercept[TestFailedException] { 422 "1.7" should not { endWith regex ("1.7") } 423 } 424 assert(caught1.getMessage === "\"1.7\" ended with a substring that matched the regular expression 1.7") 425 426 val caught2 = intercept[TestFailedException] { 427 "1.7" should not { endWith regex (decimalRegex) } 428 } 429 assert(caught2.getMessage === "\"1.7\" ended with a substring that matched the regular expression (-)?(\\d+)(\\.\\d*)?") 430 431 val caught3 = intercept[TestFailedException] { 432 "-1.8" should not { endWith regex (decimalRegex) } 433 } 434 assert(caught3.getMessage === "\"-1.8\" ended with a substring that matched the regular expression (-)?(\\d+)(\\.\\d*)?") 435 436 val caught4 = intercept[TestFailedException] { 437 "8" should not { endWith regex (decimalRegex) } 438 } 439 assert(caught4.getMessage === "\"8\" ended with a substring that matched the regular expression (-)?(\\d+)(\\.\\d*)?") 440 441 val caught5 = intercept[TestFailedException] { 442 "1." should not { endWith regex (decimalRegex) } 443 } 444 assert(caught5.getMessage === "\"1.\" ended with a substring that matched the regular expression (-)?(\\d+)(\\.\\d*)?") 445 446 val caught11 = intercept[TestFailedException] { 447 "1.7" should not endWith regex ("1.7") 448 } 449 assert(caught11.getMessage === "\"1.7\" ended with a substring that matched the regular expression 1.7") 450 451 val caught12 = intercept[TestFailedException] { 452 "1.7" should not endWith regex (decimalRegex) 453 } 454 assert(caught12.getMessage === "\"1.7\" ended with a substring that matched the regular expression (-)?(\\d+)(\\.\\d*)?") 455 456 val caught13 = intercept[TestFailedException] { 457 "-1.8" should not endWith regex (decimalRegex) 458 } 459 assert(caught13.getMessage === "\"-1.8\" ended with a substring that matched the regular expression (-)?(\\d+)(\\.\\d*)?") 460 461 val caught14 = intercept[TestFailedException] { 462 "8" should not endWith regex (decimalRegex) 463 } 464 assert(caught14.getMessage === "\"8\" ended with a substring that matched the regular expression (-)?(\\d+)(\\.\\d*)?") 465 466 val caught15 = intercept[TestFailedException] { 467 "1." should not endWith regex (decimalRegex) 468 } 469 assert(caught15.getMessage === "\"1.\" ended with a substring that matched the regular expression (-)?(\\d+)(\\.\\d*)?") 470 471 // The rest are non-exact matches 472 val caught21 = intercept[TestFailedException] { 473 "a1.7" should not { endWith regex ("1.7") } 474 } 475 assert(caught21.getMessage === "\"a1.7\" ended with a substring that matched the regular expression 1.7") 476 477 val caught22 = intercept[TestFailedException] { 478 "b1.7" should not { endWith regex (decimalRegex) } 479 } 480 assert(caught22.getMessage === "\"b1.7\" ended with a substring that matched the regular expression (-)?(\\d+)(\\.\\d*)?") 481 482 val caught23 = intercept[TestFailedException] { 483 "b-1.8" should not { endWith regex (decimalRegex) } 484 } 485 assert(caught23.getMessage === "\"b-1.8\" ended with a substring that matched the regular expression (-)?(\\d+)(\\.\\d*)?") 486 } 487 488 it("should throw TestFailedException if the string ends with substring that matched the regular expression specified as a string when used in a logical-and expression") { 489 490 val caught1 = intercept[TestFailedException] { 491 "1.7" should (endWith regex (decimalRegex) and (endWith regex ("1.8"))) 492 } 493 assert(caught1.getMessage === "\"1.7\" ended with a substring that matched the regular expression (-)?(\\d+)(\\.\\d*)?, but \"1.7\" did not end with a substring that matched the regular expression 1.8") 494 495 val caught2 = intercept[TestFailedException] { 496 "1.7" should ((endWith regex (decimalRegex)) and (endWith regex ("1.8"))) 497 } 498 assert(caught2.getMessage === "\"1.7\" ended with a substring that matched the regular expression (-)?(\\d+)(\\.\\d*)?, but \"1.7\" did not end with a substring that matched the regular expression 1.8") 499 500 val caught3 = intercept[TestFailedException] { 501 "1.7" should (endWith regex (decimalRegex) and endWith regex ("1.8")) 502 } 503 assert(caught3.getMessage === "\"1.7\" ended with a substring that matched the regular expression (-)?(\\d+)(\\.\\d*)?, but \"1.7\" did not end with a substring that matched the regular expression 1.8") 504 505 // Check to make sure the error message "short circuits" (i.e., just reports the left side's failure) 506 val caught4 = intercept[TestFailedException] { 507 "1.eight" should (endWith regex (decimalRegex) and (endWith regex ("1.8"))) 508 } 509 assert(caught4.getMessage === "\"1.eight\" did not end with a substring that matched the regular expression (-)?(\\d+)(\\.\\d*)?") 510 511 val caught5 = intercept[TestFailedException] { 512 "1.eight" should ((endWith regex (decimalRegex)) and (endWith regex ("1.8"))) 513 } 514 assert(caught5.getMessage === "\"1.eight\" did not end with a substring that matched the regular expression (-)?(\\d+)(\\.\\d*)?") 515 516 val caught6 = intercept[TestFailedException] { 517 "1.eight" should (endWith regex (decimalRegex) and endWith regex ("1.8")) 518 } 519 assert(caught6.getMessage === "\"1.eight\" did not end with a substring that matched the regular expression (-)?(\\d+)(\\.\\d*)?") 520 } 521 522 it("should throw TestFailedException if the string ends with substring that matched the regular expression specified as a string when used in a logical-or expression") { 523 524 val caught1 = intercept[TestFailedException] { 525 "1.seven" should (endWith regex (decimalRegex) or (endWith regex ("1.8"))) 526 } 527 assert(caught1.getMessage === "\"1.seven\" did not end with a substring that matched the regular expression (-)?(\\d+)(\\.\\d*)?, and \"1.seven\" did not end with a substring that matched the regular expression 1.8") 528 529 val caught2 = intercept[TestFailedException] { 530 "1.seven" should ((endWith regex (decimalRegex)) or (endWith regex ("1.8"))) 531 } 532 assert(caught2.getMessage === "\"1.seven\" did not end with a substring that matched the regular expression (-)?(\\d+)(\\.\\d*)?, and \"1.seven\" did not end with a substring that matched the regular expression 1.8") 533 534 val caught3 = intercept[TestFailedException] { 535 "1.seven" should (endWith regex (decimalRegex) or endWith regex ("1.8")) 536 } 537 assert(caught3.getMessage === "\"1.seven\" did not end with a substring that matched the regular expression (-)?(\\d+)(\\.\\d*)?, and \"1.seven\" did not end with a substring that matched the regular expression 1.8") 538 } 539 540 it("should throw TestFailedException if the string ends with substring that matched the regular expression specified as a string when used in a logical-and expression used with not") { 541 542 val caught1 = intercept[TestFailedException] { 543 "1.7" should (not endWith regex ("1.8") and (not endWith regex (decimalRegex))) 544 } 545 assert(caught1.getMessage === "\"1.7\" did not end with a substring that matched the regular expression 1.8, but \"1.7\" ended with a substring that matched the regular expression (-)?(\\d+)(\\.\\d*)?") 546 547 val caught2 = intercept[TestFailedException] { 548 "1.7" should ((not endWith regex ("1.8")) and (not endWith regex (decimalRegex))) 549 } 550 assert(caught2.getMessage === "\"1.7\" did not end with a substring that matched the regular expression 1.8, but \"1.7\" ended with a substring that matched the regular expression (-)?(\\d+)(\\.\\d*)?") 551 552 val caught3 = intercept[TestFailedException] { 553 "1.7" should (not endWith regex ("1.8") and not endWith regex (decimalRegex)) 554 } 555 assert(caught3.getMessage === "\"1.7\" did not end with a substring that matched the regular expression 1.8, but \"1.7\" ended with a substring that matched the regular expression (-)?(\\d+)(\\.\\d*)?") 556 557 val caught4 = intercept[TestFailedException] { 558 "a1.7" should (not endWith regex ("1.8") and (not endWith regex (decimalRegex))) 559 } 560 assert(caught4.getMessage === "\"a1.7\" did not end with a substring that matched the regular expression 1.8, but \"a1.7\" ended with a substring that matched the regular expression (-)?(\\d+)(\\.\\d*)?") 561 562 val caught5 = intercept[TestFailedException] { 563 "1.7" should ((not endWith regex ("1.8")) and (not endWith regex (decimalRegex))) 564 } 565 assert(caught5.getMessage === "\"1.7\" did not end with a substring that matched the regular expression 1.8, but \"1.7\" ended with a substring that matched the regular expression (-)?(\\d+)(\\.\\d*)?") 566 } 567 568 it("should throw TestFailedException if the string ends with substring that matched the regular expression specified as a string when used in a logical-or expression used with not") { 569 570 val caught1 = intercept[TestFailedException] { 571 "1.7" should (not endWith regex (decimalRegex) or (not endWith regex ("1.7"))) 572 } 573 assert(caught1.getMessage === "\"1.7\" ended with a substring that matched the regular expression (-)?(\\d+)(\\.\\d*)?, and \"1.7\" ended with a substring that matched the regular expression 1.7") 574 575 val caught2 = intercept[TestFailedException] { 576 "1.7" should ((not endWith regex (decimalRegex)) or (not endWith regex ("1.7"))) 577 } 578 assert(caught2.getMessage === "\"1.7\" ended with a substring that matched the regular expression (-)?(\\d+)(\\.\\d*)?, and \"1.7\" ended with a substring that matched the regular expression 1.7") 579 580 val caught3 = intercept[TestFailedException] { 581 "1.7" should (not endWith regex (decimalRegex) or not endWith regex ("1.7")) 582 } 583 assert(caught3.getMessage === "\"1.7\" ended with a substring that matched the regular expression (-)?(\\d+)(\\.\\d*)?, and \"1.7\" ended with a substring that matched the regular expression 1.7") 584 585 val caught4 = intercept[TestFailedException] { 586 "1.7" should (not (endWith regex (decimalRegex)) or not (endWith regex ("1.7"))) 587 } 588 assert(caught4.getMessage === "\"1.7\" ended with a substring that matched the regular expression (-)?(\\d+)(\\.\\d*)?, and \"1.7\" ended with a substring that matched the regular expression 1.7") 589 590 val caught5 = intercept[TestFailedException] { 591 "a1.7" should (not endWith regex (decimalRegex) or (not endWith regex ("1.7"))) 592 } 593 assert(caught5.getMessage === "\"a1.7\" ended with a substring that matched the regular expression (-)?(\\d+)(\\.\\d*)?, and \"a1.7\" ended with a substring that matched the regular expression 1.7") 594 } 595 } 596 } 597} 598 599