| | 200 | |
| | 201 | /** |
| | 202 | * @ticket 22692 |
| | 203 | */ |
| | 204 | function test_spaces_around_quotes() { |
| | 205 | $nbsp = "\xC2\xA0"; |
| | 206 | $pi = "\xCE\xA0"; |
| | 207 | |
| | 208 | // This should never happen, even if the desired output changes some day. |
| | 209 | |
| | 210 | $problem_input = "$nbsp\"A"; |
| | 211 | $problem_output = "$nbsp”A"; |
| | 212 | |
| | 213 | $this->assertNotEquals( $problem_output, wptexturize( $problem_input ) ); |
| | 214 | |
| | 215 | // These are desirable outputs for the current design. |
| | 216 | |
| | 217 | $input = array(); |
| | 218 | $output = array(); |
| | 219 | |
| | 220 | $input[] = "stop. $nbsp\"A quote after 2 spaces.\""; |
| | 221 | $output[] = "stop. $nbsp“A quote after 2 spaces.”"; |
| | 222 | |
| | 223 | $input[] = "stop.$nbsp$nbsp\"A quote after 2 spaces.\""; |
| | 224 | $output[] = "stop.$nbsp$nbsp“A quote after 2 spaces.”"; |
| | 225 | |
| | 226 | $input[] = "stop. $nbsp'A quote after 2 spaces.'"; |
| | 227 | $output[] = "stop. $nbsp‘A quote after 2 spaces.’"; |
| | 228 | |
| | 229 | $input[] = "stop.$nbsp$nbsp'A quote after 2 spaces.'"; |
| | 230 | $output[] = "stop.$nbsp$nbsp‘A quote after 2 spaces.’"; |
| | 231 | |
| | 232 | $input[] = "stop. \"A quote after 2 spaces.\""; |
| | 233 | $output[] = "stop. “A quote after 2 spaces.”"; |
| | 234 | |
| | 235 | $input[] = "stop. \"A quote after 2 spaces.\""; |
| | 236 | $output[] = "stop. “A quote after 2 spaces.”"; |
| | 237 | |
| | 238 | $input[] = "stop. 'A quote after 2 spaces.'"; |
| | 239 | $output[] = "stop. ‘A quote after 2 spaces.’"; |
| | 240 | |
| | 241 | $input[] = "stop. 'A quote after 2 spaces.'"; |
| | 242 | $output[] = "stop. ‘A quote after 2 spaces.’"; |
| | 243 | |
| | 244 | $input[] = "Contraction: $pi's"; |
| | 245 | $output[] = "Contraction: $pi’s"; |
| | 246 | |
| | 247 | foreach($input as $key => $in) { |
| | 248 | $this->assertEquals( $output[$key], wptexturize( $in ) ); |
| | 249 | } |
| | 250 | } |
| | 251 | |
| | 252 | /** |
| | 253 | * Check all baseline patterns. If anything ever changes in wptexturize(), these tests may fail. |
| | 254 | * |
| | 255 | * @ticket 22692 |
| | 256 | */ |
| | 257 | function test_all_regexp_behaviors() { |
| | 258 | $input = array(); |
| | 259 | $output = array(); |
| | 260 | |
| | 261 | // Apostrophe before a number always becomes ’ (apos); |
| | 262 | |
| | 263 | $input[] = "word '99 word"; |
| | 264 | $output[] = "word ’99 word"; |
| | 265 | |
| | 266 | $input[] = "word'99 word"; |
| | 267 | $output[] = "word’99 word"; |
| | 268 | |
| | 269 | $input[] = "word '99word"; |
| | 270 | $output[] = "word ’99word"; |
| | 271 | |
| | 272 | $input[] = "word'99word"; |
| | 273 | $output[] = "word’99word"; |
| | 274 | |
| | 275 | $input[] = "word '99’s word"; // Appears as a separate but logically superfluous pattern in 3.8. |
| | 276 | $output[] = "word ’99’s word"; |
| | 277 | |
| | 278 | $input[] = "word '99's word"; // Due to the logic error, second apos becomes a prime. See ticket #22823 |
| | 279 | $output[] = "word ’99′s word"; |
| | 280 | |
| | 281 | $input[] = "word '99'samsonite"; |
| | 282 | $output[] = "word ’99′samsonite"; |
| | 283 | |
| | 284 | $input[] = "according to our source, '33% of all students scored less than 50' on the test."; // Apostrophes and primes have priority over quotes |
| | 285 | $output[] = "according to our source, ’33% of all students scored less than 50′ on the test."; |
| | 286 | |
| | 287 | $input[] = "word '99' word"; // See ticket #8775 |
| | 288 | $output[] = "word ’99′ word"; |
| | 289 | |
| | 290 | // Apostrophe after a space or ([{<" becomes ‘ (opening_single_quote) |
| | 291 | |
| | 292 | $input[] = "word 'word word"; |
| | 293 | $output[] = "word ‘word word"; |
| | 294 | |
| | 295 | $input[] = "word ('word word"; |
| | 296 | $output[] = "word (‘word word"; |
| | 297 | |
| | 298 | $input[] = "word ['word word"; |
| | 299 | $output[] = "word [‘word word"; |
| | 300 | |
| | 301 | $input[] = "word <'word word"; // Invalid HTML input? |
| | 302 | $output[] = "word <‘word word"; |
| | 303 | |
| | 304 | $input[] = "word <'word word"; // Valid HTML input triggers the apos in a word pattern |
| | 305 | $output[] = "word <’word word"; |
| | 306 | |
| | 307 | $input[] = "word {'word word"; |
| | 308 | $output[] = "word {‘word word"; |
| | 309 | |
| | 310 | $input[] = "word \"'word word"; |
| | 311 | $output[] = "word “‘word word"; // Two opening quotes |
| | 312 | |
| | 313 | $input[] = "'word word"; |
| | 314 | $output[] = "‘word word"; |
| | 315 | |
| | 316 | $input[] = "word('word word"; |
| | 317 | $output[] = "word(‘word word"; |
| | 318 | |
| | 319 | $input[] = "word['word word"; |
| | 320 | $output[] = "word[‘word word"; |
| | 321 | |
| | 322 | $input[] = "word<'word word"; |
| | 323 | $output[] = "word<‘word word"; |
| | 324 | |
| | 325 | $input[] = "word<'word word"; |
| | 326 | $output[] = "word<’word word"; |
| | 327 | |
| | 328 | $input[] = "word{'word word"; |
| | 329 | $output[] = "word{‘word word"; |
| | 330 | |
| | 331 | $input[] = "word\"'word word"; |
| | 332 | $output[] = "word”‘word word"; // Closing quote, then opening quote |
| | 333 | |
| | 334 | $input[] = "word ' word word"; |
| | 335 | $output[] = "word ‘ word word"; |
| | 336 | |
| | 337 | $input[] = "word (' word word"; |
| | 338 | $output[] = "word (‘ word word"; |
| | 339 | |
| | 340 | $input[] = "word [' word word"; |
| | 341 | $output[] = "word [‘ word word"; |
| | 342 | |
| | 343 | $input[] = "word <' word word"; // Invalid HTML input? |
| | 344 | $output[] = "word <‘ word word"; |
| | 345 | |
| | 346 | $input[] = "word <' word word"; // Valid HTML input triggers the closing single quote here |
| | 347 | $output[] = "word <’ word word"; |
| | 348 | |
| | 349 | $input[] = "word {' word word"; |
| | 350 | $output[] = "word {‘ word word"; |
| | 351 | |
| | 352 | $input[] = "word \"' word word"; |
| | 353 | $output[] = "word “‘ word word"; // Two opening quotes |
| | 354 | |
| | 355 | $input[] = "' word word"; |
| | 356 | $output[] = "‘ word word"; |
| | 357 | |
| | 358 | $input[] = "word(' word word"; |
| | 359 | $output[] = "word(‘ word word"; |
| | 360 | |
| | 361 | $input[] = "word[' word word"; |
| | 362 | $output[] = "word[‘ word word"; |
| | 363 | |
| | 364 | $input[] = "word<' word word"; |
| | 365 | $output[] = "word<‘ word word"; |
| | 366 | |
| | 367 | $input[] = "word<' word word"; |
| | 368 | $output[] = "word<’ word word"; |
| | 369 | |
| | 370 | $input[] = "word{' word word"; |
| | 371 | $output[] = "word{‘ word word"; |
| | 372 | |
| | 373 | $input[] = "word\"' word word"; |
| | 374 | $output[] = "word”‘ word word"; // Closing quote, then opening quote |
| | 375 | |
| | 376 | // Double quote after a number becomes ″ (double_prime) |
| | 377 | |
| | 378 | $input[] = 'word 99" word'; |
| | 379 | $output[] = 'word 99″ word'; |
| | 380 | |
| | 381 | $input[] = 'word 99"word'; |
| | 382 | $output[] = 'word 99″word'; |
| | 383 | |
| | 384 | $input[] = 'word99" word'; |
| | 385 | $output[] = 'word99″ word'; |
| | 386 | |
| | 387 | $input[] = 'word99"word'; |
| | 388 | $output[] = 'word99″word'; |
| | 389 | |
| | 390 | // Apostrophe after a number becomes ′ (prime) |
| | 391 | |
| | 392 | $input[] = "word 99' word"; |
| | 393 | $output[] = "word 99′ word"; |
| | 394 | |
| | 395 | $input[] = "word 99'word"; |
| | 396 | $output[] = "word 99′word"; |
| | 397 | |
| | 398 | $input[] = "word99' word"; |
| | 399 | $output[] = "word99′ word"; |
| | 400 | |
| | 401 | $input[] = "word99'word"; |
| | 402 | $output[] = "word99′word"; |
| | 403 | |
| | 404 | // Apostrophe "in a word" becomes ’ (apos) |
| | 405 | |
| | 406 | $input[] = "word word's word"; |
| | 407 | $output[] = "word word’s word"; |
| | 408 | |
| | 409 | $input[] = "word ]'. word"; // Quotes wrapped in braces could end with apostrophes instead of closing quotes (may affect i18n) |
| | 410 | $output[] = "word ]’. word"; |
| | 411 | |
| | 412 | $input[] = "word )'. word"; |
| | 413 | $output[] = "word )’. word"; |
| | 414 | |
| | 415 | $input[] = "word }'. word"; |
| | 416 | $output[] = "word }’. word"; |
| | 417 | |
| | 418 | $input[] = "word >'. word"; // Not tested |
| | 419 | $output[] = "word >’. word"; |
| | 420 | |
| | 421 | $input[] = "word >'. word"; |
| | 422 | $output[] = "word >’. word"; |
| | 423 | |
| | 424 | // Double quote after a space or ([{< becomes “ (opening_quote) if not followed by spaces |
| | 425 | |
| | 426 | $input[] = 'word "word word'; |
| | 427 | $output[] = 'word “word word'; |
| | 428 | |
| | 429 | $input[] = 'word ("word word'; |
| | 430 | $output[] = 'word (“word word'; |
| | 431 | |
| | 432 | $input[] = 'word ["word word'; |
| | 433 | $output[] = 'word [“word word'; |
| | 434 | |
| | 435 | $input[] = 'word <"word word'; // Invalid HTML input? |
| | 436 | $output[] = 'word <“word word'; |
| | 437 | |
| | 438 | $input[] = 'word <"word word'; // Valid HTML input triggers the closing quote pattern |
| | 439 | $output[] = 'word <”word word'; |
| | 440 | |
| | 441 | $input[] = 'word {"word word'; |
| | 442 | $output[] = 'word {“word word'; |
| | 443 | |
| | 444 | $input[] = '"word word'; |
| | 445 | $output[] = '“word word'; |
| | 446 | |
| | 447 | $input[] = 'word("word word'; |
| | 448 | $output[] = 'word(“word word'; |
| | 449 | |
| | 450 | $input[] = 'word["word word'; |
| | 451 | $output[] = 'word[“word word'; |
| | 452 | |
| | 453 | $input[] = 'word<"word word'; // Invalid HTML input? |
| | 454 | $output[] = 'word<“word word'; |
| | 455 | |
| | 456 | $input[] = 'word<"word word'; // Valid HTML input triggers the closing quote pattern |
| | 457 | $output[] = 'word<”word word'; |
| | 458 | |
| | 459 | $input[] = 'word{"word word'; |
| | 460 | $output[] = 'word{“word word'; |
| | 461 | |
| | 462 | $input[] = 'word "99 word'; |
| | 463 | $output[] = 'word “99 word'; |
| | 464 | |
| | 465 | // Double quote becomes ” (closing_quote) unless it is already converted to double_prime or opening_quote. |
| | 466 | |
| | 467 | $input[] = 'word word" word'; |
| | 468 | $output[] = 'word word” word'; |
| | 469 | |
| | 470 | $input[] = 'word word") word'; |
| | 471 | $output[] = 'word word”) word'; |
| | 472 | |
| | 473 | $input[] = 'word word"] word'; |
| | 474 | $output[] = 'word word”] word'; |
| | 475 | |
| | 476 | $input[] = 'word word"} word'; |
| | 477 | $output[] = 'word word”} word'; |
| | 478 | |
| | 479 | $input[] = 'word word"> word'; // Invalid HTML input? |
| | 480 | $output[] = 'word word”> word'; |
| | 481 | |
| | 482 | $input[] = 'word word"> word'; // Valid HTML should work |
| | 483 | $output[] = 'word word”> word'; |
| | 484 | |
| | 485 | $input[] = 'word word"'; |
| | 486 | $output[] = 'word word”'; |
| | 487 | |
| | 488 | $input[] = 'word word"word'; |
| | 489 | $output[] = 'word word”word'; |
| | 490 | |
| | 491 | $input[] = 'word"word"word'; |
| | 492 | $output[] = 'word”word”word'; |
| | 493 | |
| | 494 | $input[] = 'test sentence".'; |
| | 495 | $output[] = 'test sentence”.'; |
| | 496 | |
| | 497 | $input[] = 'test sentence."'; |
| | 498 | $output[] = 'test sentence.”'; |
| | 499 | |
| | 500 | $input[] = 'test sentence". word'; |
| | 501 | $output[] = 'test sentence”. word'; |
| | 502 | |
| | 503 | $input[] = 'test sentence." word'; |
| | 504 | $output[] = 'test sentence.” word'; |
| | 505 | |
| | 506 | // Single quote followed by a space or a period becomes ’ (closing_single_quote) |
| | 507 | |
| | 508 | $input[] = "word word' word"; |
| | 509 | $output[] = "word word’ word"; |
| | 510 | |
| | 511 | $input[] = "word word'. word"; |
| | 512 | $output[] = "word word’. word"; |
| | 513 | |
| | 514 | $input[] = "word word'.word"; |
| | 515 | $output[] = "word word’.word"; |
| | 516 | |
| | 517 | $input[] = "word word'"; |
| | 518 | $output[] = "word word’"; |
| | 519 | |
| | 520 | $input[] = "test sentence'."; |
| | 521 | $output[] = "test sentence’."; |
| | 522 | |
| | 523 | $input[] = "test sentence.'"; |
| | 524 | $output[] = "test sentence.’"; |
| | 525 | |
| | 526 | $input[] = "test sentence'. word"; |
| | 527 | $output[] = "test sentence’. word"; |
| | 528 | |
| | 529 | $input[] = "test sentence.' word"; |
| | 530 | $output[] = "test sentence.’ word"; |
| | 531 | |
| | 532 | // 9x9 becomes 9×9 |
| | 533 | |
| | 534 | $input[] = "9x9"; |
| | 535 | $output[] = "9×9"; |
| | 536 | |
| | 537 | $input[] = "12x34"; |
| | 538 | $output[] = "12×34"; |
| | 539 | |
| | 540 | $input[] = "9 x 9"; |
| | 541 | $output[] = "9 x 9"; |
| | 542 | |
| | 543 | // & always becomes & unless it is followed by # or ; |
| | 544 | |
| | 545 | $input[] = "word & word"; |
| | 546 | $output[] = "word & word"; |
| | 547 | |
| | 548 | $input[] = "word&word"; |
| | 549 | $output[] = "word&word"; |
| | 550 | |
| | 551 | $input[] = "word word"; |
| | 552 | $output[] = "word word"; |
| | 553 | |
| | 554 | $input[] = "word & word"; |
| | 555 | $output[] = "word & word"; |
| | 556 | |
| | 557 | $input[] = "word &# word"; |
| | 558 | $output[] = "word &# word"; // invalid output? |
| | 559 | |
| | 560 | $input[] = "word &44; word"; |
| | 561 | $output[] = "word &44; word"; |
| | 562 | |
| | 563 | |
| | 564 | foreach($input as $key => $in) { |
| | 565 | $this->assertEquals( $output[$key], wptexturize( $in ) ); |
| | 566 | } |
| | 567 | } |
| | 568 | |
| | 569 | |
| | 570 | |
| | 571 | /** |
| | 572 | * Check all baseline patterns. If anything ever changes in wptexturize(), these tests may fail. |
| | 573 | * |
| | 574 | * @ticket 22692 |
| | 575 | */ |
| | 576 | function test_all_static_behaviors() { |
| | 577 | $input = array(); |
| | 578 | $output = array(); |
| | 579 | |
| | 580 | // "cockney" phrases begin with apos instead of opening_single_quote. |
| | 581 | |
| | 582 | $input[] = "word 'tain't word"; |
| | 583 | $output[] = "word ’tain’t word"; |
| | 584 | |
| | 585 | $input[] = "word 'twere word"; |
| | 586 | $output[] = "word ’twere word"; |
| | 587 | |
| | 588 | $input[] = "word 'twas word"; |
| | 589 | $output[] = "word ’twas word"; |
| | 590 | |
| | 591 | $input[] = "word 'tis word"; |
| | 592 | $output[] = "word ’tis word"; |
| | 593 | |
| | 594 | $input[] = "word 'twill word"; |
| | 595 | $output[] = "word ’twill word"; |
| | 596 | |
| | 597 | $input[] = "word 'til word"; |
| | 598 | $output[] = "word ’til word"; |
| | 599 | |
| | 600 | $input[] = "word 'bout word"; |
| | 601 | $output[] = "word ’bout word"; |
| | 602 | |
| | 603 | $input[] = "word 'nuff word"; |
| | 604 | $output[] = "word ’nuff word"; |
| | 605 | |
| | 606 | $input[] = "word 'round word"; |
| | 607 | $output[] = "word ’round word"; |
| | 608 | |
| | 609 | $input[] = "word 'cause word"; |
| | 610 | $output[] = "word ’cause word"; |
| | 611 | |
| | 612 | $input[] = "word 'em word"; |
| | 613 | $output[] = "word ‘em word"; |
| | 614 | |
| | 615 | // Smart dashes, etc |
| | 616 | |
| | 617 | $input[] = "word --- word"; |
| | 618 | $output[] = "word — word"; |
| | 619 | |
| | 620 | $input[] = "word---word"; |
| | 621 | $output[] = "word—word"; |
| | 622 | |
| | 623 | $input[] = "word -- word"; |
| | 624 | $output[] = "word — word"; |
| | 625 | |
| | 626 | $input[] = "word--word"; |
| | 627 | $output[] = "word–word"; |
| | 628 | |
| | 629 | $input[] = "word - word"; |
| | 630 | $output[] = "word – word"; |
| | 631 | |
| | 632 | $input[] = "word-word"; |
| | 633 | $output[] = "word-word"; |
| | 634 | |
| | 635 | $input[] = "word xn– word"; |
| | 636 | $output[] = "word xn-- word"; |
| | 637 | |
| | 638 | $input[] = "wordxn–word"; |
| | 639 | $output[] = "wordxn--word"; |
| | 640 | |
| | 641 | $input[] = "word ... word"; |
| | 642 | $output[] = "word … word"; |
| | 643 | |
| | 644 | $input[] = "word...word"; |
| | 645 | $output[] = "word…word"; |
| | 646 | |
| | 647 | $input[] = "word `` word"; |
| | 648 | $output[] = "word “ word"; |
| | 649 | |
| | 650 | $input[] = "word``word"; |
| | 651 | $output[] = "word“word"; |
| | 652 | |
| | 653 | $input[] = "word '' word"; |
| | 654 | $output[] = "word ” word"; |
| | 655 | |
| | 656 | $input[] = "word''word"; |
| | 657 | $output[] = "word”word"; |
| | 658 | |
| | 659 | $input[] = "word (tm) word"; |
| | 660 | $output[] = "word ™ word"; |
| | 661 | |
| | 662 | $input[] = "word (tm)word"; |
| | 663 | $output[] = "word ™word"; |
| | 664 | |
| | 665 | $input[] = "word(tm) word"; |
| | 666 | $output[] = "word(tm) word"; |
| | 667 | |
| | 668 | $input[] = "word(tm)word"; |
| | 669 | $output[] = "word(tm)word"; |
| | 670 | |
| | 671 | foreach($input as $key => $in) { |
| | 672 | $this->assertEquals( $output[$key], wptexturize( $in ) ); |
| | 673 | } |
| | 674 | } |