| | 197 | |
| | 198 | /** |
| | 199 | * @ticket 22692 |
| | 200 | */ |
| | 201 | function test_spaces_around_quotes() { |
| | 202 | $nbsp = "\xC2\xA0"; |
| | 203 | $pi = "\xCE\xA0"; |
| | 204 | |
| | 205 | // This should never happen, even if the desired output changes some day. |
| | 206 | |
| | 207 | $problem_input = "$nbsp\"A"; |
| | 208 | $problem_output = "$nbsp”A"; |
| | 209 | |
| | 210 | $this->assertNotEquals( $problem_output, wptexturize( $problem_input ) ); |
| | 211 | |
| | 212 | // These are desirable outputs for the current design. |
| | 213 | |
| | 214 | $input = array(); |
| | 215 | $output = array(); |
| | 216 | |
| | 217 | $input[] = "stop. $nbsp\"A quote after 2 spaces.\""; |
| | 218 | $output[] = "stop. $nbsp“A quote after 2 spaces.”"; |
| | 219 | |
| | 220 | $input[] = "stop.$nbsp$nbsp\"A quote after 2 spaces.\""; |
| | 221 | $output[] = "stop.$nbsp$nbsp“A quote after 2 spaces.”"; |
| | 222 | |
| | 223 | $input[] = "stop. $nbsp'A quote after 2 spaces.'"; |
| | 224 | $output[] = "stop. $nbsp‘A quote after 2 spaces.’"; |
| | 225 | |
| | 226 | $input[] = "stop.$nbsp$nbsp'A quote after 2 spaces.'"; |
| | 227 | $output[] = "stop.$nbsp$nbsp‘A quote after 2 spaces.’"; |
| | 228 | |
| | 229 | $input[] = "stop. \"A quote after 2 spaces.\""; |
| | 230 | $output[] = "stop. “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[] = "Contraction: $pi's"; |
| | 242 | $output[] = "Contraction: $pi’s"; |
| | 243 | |
| | 244 | foreach($input as $key => $in) { |
| | 245 | $this->assertEquals( $output[$key], wptexturize( $in ) ); |
| | 246 | } |
| | 247 | } |
| | 248 | |
| | 249 | /** |
| | 250 | * Check all baseline patterns. If anything ever changes in wptexturize(), these tests may fail. |
| | 251 | * |
| | 252 | * @ticket 22692 |
| | 253 | */ |
| | 254 | function test_all_current_behaviors() { |
| | 255 | $input = array(); |
| | 256 | $output = array(); |
| | 257 | |
| | 258 | // Apostrophe before a number always becomes ’ (apos); |
| | 259 | |
| | 260 | $input[] = "word '99 word"; |
| | 261 | $output[] = "word ’99 word"; |
| | 262 | |
| | 263 | $input[] = "word'99 word"; |
| | 264 | $output[] = "word’99 word"; |
| | 265 | |
| | 266 | $input[] = "word '99word"; |
| | 267 | $output[] = "word ’99word"; |
| | 268 | |
| | 269 | $input[] = "word'99word"; |
| | 270 | $output[] = "word’99word"; |
| | 271 | |
| | 272 | $input[] = "word '99’s word"; // Appears as a separate but logically superfluous pattern in 3.8. |
| | 273 | $output[] = "word ’99’s word"; |
| | 274 | |
| | 275 | $input[] = "word '99's word"; // Due to the logic error, second apos becomes a prime. See ticket #22823 |
| | 276 | $output[] = "word ’99′s word"; |
| | 277 | |
| | 278 | $input[] = "word '99'samsonite"; |
| | 279 | $output[] = "word ’99′samsonite"; |
| | 280 | |
| | 281 | $input[] = "according to our source, '33% of all students scored less than 50' on the test."; // Apostrophes and primes have priority over quotes |
| | 282 | $output[] = "according to our source, ’33% of all students scored less than 50′ on the test."; |
| | 283 | |
| | 284 | $input[] = "word '99' word"; // See ticket #8775 |
| | 285 | $output[] = "word ’99′ word"; |
| | 286 | |
| | 287 | // Apostrophe after a space or ([{<" becomes ‘ (opening_single_quote) |
| | 288 | |
| | 289 | $input[] = "word 'word word"; |
| | 290 | $output[] = "word ‘word word"; |
| | 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"; // Invalid HTML input? |
| | 299 | $output[] = "word <‘word word"; |
| | 300 | |
| | 301 | $input[] = "word <'word word"; // Valid HTML input triggers the apos in a word pattern |
| | 302 | $output[] = "word <’word word"; |
| | 303 | |
| | 304 | $input[] = "word {'word word"; |
| | 305 | $output[] = "word {‘word word"; |
| | 306 | |
| | 307 | $input[] = "word \"'word word"; |
| | 308 | $output[] = "word “‘word word"; // Two opening quotes |
| | 309 | |
| | 310 | $input[] = "'word word"; |
| | 311 | $output[] = "‘word word"; |
| | 312 | |
| | 313 | $input[] = "word('word word"; |
| | 314 | $output[] = "word(‘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"; // Closing quote, then opening quote |
| | 330 | |
| | 331 | $input[] = "word ' word word"; |
| | 332 | $output[] = "word ‘ word word"; |
| | 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"; // Invalid HTML input? |
| | 341 | $output[] = "word <‘ word word"; |
| | 342 | |
| | 343 | $input[] = "word <' word word"; // Valid HTML input triggers the closing single quote here |
| | 344 | $output[] = "word <’ word word"; |
| | 345 | |
| | 346 | $input[] = "word {' word word"; |
| | 347 | $output[] = "word {‘ word word"; |
| | 348 | |
| | 349 | $input[] = "word \"' word word"; |
| | 350 | $output[] = "word “‘ word word"; // Two opening quotes |
| | 351 | |
| | 352 | $input[] = "' word word"; |
| | 353 | $output[] = "‘ word word"; |
| | 354 | |
| | 355 | $input[] = "word(' word word"; |
| | 356 | $output[] = "word(‘ 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"; // Closing quote, then opening quote |
| | 372 | |
| | 373 | // Double quote after a number becomes ″ (double_prime) |
| | 374 | |
| | 375 | $input[] = 'word 99" word'; |
| | 376 | $output[] = 'word 99″ word'; |
| | 377 | |
| | 378 | $input[] = 'word 99"word'; |
| | 379 | $output[] = 'word 99″word'; |
| | 380 | |
| | 381 | $input[] = 'word99" word'; |
| | 382 | $output[] = 'word99″ word'; |
| | 383 | |
| | 384 | $input[] = 'word99"word'; |
| | 385 | $output[] = 'word99″word'; |
| | 386 | |
| | 387 | // Apostrophe after a number becomes ′ (prime) |
| | 388 | |
| | 389 | $input[] = "word 99' word"; |
| | 390 | $output[] = "word 99′ word"; |
| | 391 | |
| | 392 | $input[] = "word 99'word"; |
| | 393 | $output[] = "word 99′word"; |
| | 394 | |
| | 395 | $input[] = "word99' word"; |
| | 396 | $output[] = "word99′ word"; |
| | 397 | |
| | 398 | $input[] = "word99'word"; |
| | 399 | $output[] = "word99′word"; |
| | 400 | |
| | 401 | // Apostrophe "in a word" becomes ’ (apos) |
| | 402 | |
| | 403 | $input[] = "word word's word"; |
| | 404 | $output[] = "word word’s word"; |
| | 405 | |
| | 406 | $input[] = "word ]'. word"; // Quotes wrapped in braces could end with apostrophes instead of closing quotes (may affect i18n) |
| | 407 | $output[] = "word ]’. word"; |
| | 408 | |
| | 409 | $input[] = "word )'. word"; |
| | 410 | $output[] = "word )’. word"; |
| | 411 | |
| | 412 | $input[] = "word }'. word"; |
| | 413 | $output[] = "word }’. word"; |
| | 414 | |
| | 415 | $input[] = "word >'. word"; // Not tested |
| | 416 | $output[] = "word >’. word"; |
| | 417 | |
| | 418 | $input[] = "word >'. word"; |
| | 419 | $output[] = "word >’. word"; |
| | 420 | |
| | 421 | // Double quote after a space or ([{< becomes “ (opening_quote) if not followed by spaces |
| | 422 | |
| | 423 | $input[] = 'word "word word'; |
| | 424 | $output[] = 'word “word word'; |
| | 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'; // Invalid HTML input? |
| | 433 | $output[] = 'word <“word word'; |
| | 434 | |
| | 435 | $input[] = 'word <"word word'; // Valid HTML input triggers the closing quote pattern |
| | 436 | $output[] = 'word <”word word'; |
| | 437 | |
| | 438 | $input[] = 'word {"word word'; |
| | 439 | $output[] = 'word {“word word'; |
| | 440 | |
| | 441 | $input[] = '"word word'; |
| | 442 | $output[] = '“word word'; |
| | 443 | |
| | 444 | $input[] = 'word("word word'; |
| | 445 | $output[] = 'word(“word word'; |
| | 446 | |
| | 447 | $input[] = 'word["word word'; |
| | 448 | $output[] = 'word[“word word'; |
| | 449 | |
| | 450 | $input[] = 'word<"word word'; // Invalid HTML input? |
| | 451 | $output[] = 'word<“word word'; |
| | 452 | |
| | 453 | $input[] = 'word<"word word'; // Valid HTML input triggers the closing quote pattern |
| | 454 | $output[] = 'word<”word word'; |
| | 455 | |
| | 456 | $input[] = 'word{"word word'; |
| | 457 | $output[] = 'word{“word word'; |
| | 458 | |
| | 459 | $input[] = 'word "99 word'; |
| | 460 | $output[] = 'word “99 word'; |
| | 461 | |
| | 462 | // Double quote becomes ” (closing_quote) unless it is already converted to double_prime or opening_quote. |
| | 463 | |
| | 464 | $input[] = 'word word" word'; |
| | 465 | $output[] = 'word word” word'; |
| | 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'; // Invalid HTML input? |
| | 477 | $output[] = 'word word”> word'; |
| | 478 | |
| | 479 | $input[] = 'word word"> word'; // Valid HTML should work |
| | 480 | $output[] = 'word word”> word'; |
| | 481 | |
| | 482 | $input[] = 'word word"'; |
| | 483 | $output[] = 'word word”'; |
| | 484 | |
| | 485 | $input[] = 'word word"word'; |
| | 486 | $output[] = 'word word”word'; |
| | 487 | |
| | 488 | $input[] = 'word"word"word'; |
| | 489 | $output[] = 'word”word”word'; |
| | 490 | |
| | 491 | $input[] = 'test sentence".'; |
| | 492 | $output[] = 'test sentence”.'; |
| | 493 | |
| | 494 | $input[] = 'test sentence."'; |
| | 495 | $output[] = 'test sentence.”'; |
| | 496 | |
| | 497 | $input[] = 'test sentence". word'; |
| | 498 | $output[] = 'test sentence”. word'; |
| | 499 | |
| | 500 | $input[] = 'test sentence." word'; |
| | 501 | $output[] = 'test sentence.” word'; |
| | 502 | |
| | 503 | // Single quote followed by a space or a period becomes ’ (closing_single_quote) |
| | 504 | |
| | 505 | $input[] = "word word' word"; |
| | 506 | $output[] = "word word’ word"; |
| | 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'"; |
| | 515 | $output[] = "word word’"; |
| | 516 | |
| | 517 | $input[] = "test sentence'."; |
| | 518 | $output[] = "test sentence’."; |
| | 519 | |
| | 520 | $input[] = "test sentence.'"; |
| | 521 | $output[] = "test sentence.’"; |
| | 522 | |
| | 523 | $input[] = "test sentence'. word"; |
| | 524 | $output[] = "test sentence’. word"; |
| | 525 | |
| | 526 | $input[] = "test sentence.' word"; |
| | 527 | $output[] = "test sentence.’ word"; |
| | 528 | |
| | 529 | // 9x9 becomes 9×9 |
| | 530 | |
| | 531 | $input[] = "9x9"; |
| | 532 | $output[] = "9×9"; |
| | 533 | |
| | 534 | $input[] = "12x34"; |
| | 535 | $output[] = "12×34"; |
| | 536 | |
| | 537 | $input[] = "9 x 9"; |
| | 538 | $output[] = "9 x 9"; |
| | 539 | |
| | 540 | foreach($input as $key => $in) { |
| | 541 | $this->assertEquals( $output[$key], wptexturize( $in ) ); |
| | 542 | } |
| | 543 | } |