<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[27839] trunk: Texturize: Massive performance improvements (~600% faster); better handling of nbsp, double, and weird spaces; 136 new unit tests.</title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://core.trac.wordpress.org/changeset/27839">27839</a></dd>
<dt>Author</dt> <dd>nacin</dd>
<dt>Date</dt> <dd>2014-03-29 07:15:33 +0000 (Sat, 29 Mar 2014)</dd>
</dl>

<h3>Log Message</h3>
<pre>Texturize: Massive performance improvements (~600% faster); better handling of nbsp, double, and weird spaces; 136 new unit tests.

big props miqrogroove.
fixes <a href="http://core.trac.wordpress.org/ticket/22692">#22692</a>.</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunksrcwpincludesformattingphp">trunk/src/wp-includes/formatting.php</a></li>
<li><a href="#trunktestsphpunittestsformattingWPTexturizephp">trunk/tests/phpunit/tests/formatting/WPTexturize.php</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunksrcwpincludesformattingphp"></a>
<div class="modfile"><h4>Modified: trunk/src/wp-includes/formatting.php (27838 => 27839)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/src/wp-includes/formatting.php     2014-03-29 06:22:46 UTC (rev 27838)
+++ trunk/src/wp-includes/formatting.php        2014-03-29 07:15:33 UTC (rev 27839)
</span><span class="lines">@@ -73,28 +73,51 @@
</span><span class="cx">          $static_characters = array_merge( array( '---', ' -- ', '--', ' - ', 'xn&#8211;', '...', '``', '\'\'', ' (tm)' ), $cockney );
</span><span class="cx">          $static_replacements = array_merge( array( $em_dash, ' ' . $em_dash . ' ', $en_dash, ' ' . $en_dash . ' ', 'xn--', '&#8230;', $opening_quote, $closing_quote, ' &#8482;' ), $cockneyreplace );
</span><span class="cx"> 
</span><ins>+               /*
+                * Regex for common whitespace characters.
+                *
+                * By default, spaces include new lines, tabs, nbsp entities, and the UTF-8 nbsp.
+                * This is designed to replace the PCRE \s sequence.  In #WP22692, that sequence
+                * was found to be unreliable due to random inclusion of the A0 byte.
+                */
+               $spaces = '[\r\n\t ]|\xC2\xA0|&nbsp;';
+
+
+               // Pattern-based replacements of characters.
</ins><span class="cx">           $dynamic = array();
</span><del>-               if ( "'" != $apos ) {
-                       $dynamic[ '/\'(\d\d(?:&#8217;|\')?s)/' ] = $apos . '$1'; // '99's
-                       $dynamic[ '/\'(\d)/'                   ] = $apos . '$1'; // '99
-               }
</del><ins>+
+               // '99 '99s '99's (apostrophe)
+               if ( "'" != $apos )
+                       $dynamic[ '/\'(?=\d)/' ] = $apos;
+
+               // Single quote at start, or preceded by (, {, <, [, ", or spaces.
</ins><span class="cx">           if ( "'" != $opening_single_quote )
</span><del>-                       $dynamic[ '/(\s|\A|[([{<]|")\'/'       ] = '$1' . $opening_single_quote; // opening single quote, even after (, {, <, [
</del><ins>+                        $dynamic[ '/(?<=\A|[([{<"]|' . $spaces . ')\'/' ] = $opening_single_quote;
+
+               // 9" (double prime)
</ins><span class="cx">           if ( '"' != $double_prime )
</span><del>-                       $dynamic[ '/(\d)"/'                    ] = '$1' . $double_prime; // 9" (double prime)
</del><ins>+                        $dynamic[ '/(?<=\d)"/' ] = $double_prime;
+
+               // 9' (prime)
</ins><span class="cx">           if ( "'" != $prime )
</span><del>-                       $dynamic[ '/(\d)\'/'                   ] = '$1' . $prime; // 9' (prime)
</del><ins>+                        $dynamic[ '/(?<=\d)\'/' ] = $prime;
+
+               // Apostrophe in a word.  No spaces or double primes.
</ins><span class="cx">           if ( "'" != $apos )
</span><del>-                       $dynamic[ '/(\S)\'([^\'\s])/'          ] = '$1' . $apos . '$2'; // apostrophe in a word
</del><ins>+                        $dynamic[ '/(?<!' . $spaces . ')\'(?!\'|' . $spaces . ')/' ] = $apos;
+
+               // Double quote at start, or preceded by (, {, <, [, or spaces, and not followed by spaces.
</ins><span class="cx">           if ( '"' != $opening_quote )
</span><del>-                       $dynamic[ '/(\s|\A|[([{<])"(?!\s)/'    ] = '$1' . $opening_quote . '$2'; // opening double quote, even after (, {, <, [
</del><ins>+                        $dynamic[ '/(?<=\A|[([{<]|' . $spaces . ')"(?!' . $spaces . ')/' ] = $opening_quote;
+
+               // Any remaining double quotes.
</ins><span class="cx">           if ( '"' != $closing_quote )
</span><del>-                       $dynamic[ '/"(\s|\S|\Z)/'              ] = $closing_quote . '$1'; // closing double quote
</del><ins>+                        $dynamic[ '/"/' ] = $closing_quote;
+
+               // Single quotes followed by spaces or a period.
</ins><span class="cx">           if ( "'" != $closing_single_quote )
</span><del>-                       $dynamic[ '/\'([\s.]|\Z)/'             ] = $closing_single_quote . '$1'; // closing single quote
</del><ins>+                        $dynamic[ '/\'(?=\Z|\.|' . $spaces . ')/' ] = $closing_single_quote; 
</ins><span class="cx"> 
</span><del>-               $dynamic[ '/\b(\d+)x(\d+)\b/'              ] = '$1&#215;$2'; // 9x9 (times)
-
</del><span class="cx">           $dynamic_characters = array_keys( $dynamic );
</span><span class="cx">          $dynamic_replacements = array_values( $dynamic );
</span><span class="cx">  }
</span><span class="lines">@@ -134,11 +157,21 @@
</span><span class="cx">          } elseif ( '[' === $first ) {
</span><span class="cx">                  _wptexturize_pushpop_element($curl, $no_texturize_shortcodes_stack, $no_texturize_shortcodes, '[', ']');
</span><span class="cx">          } elseif ( empty($no_texturize_shortcodes_stack) && empty($no_texturize_tags_stack) ) {
</span><ins>+
</ins><span class="cx">                   // This is not a tag, nor is the texturization disabled static strings
</span><span class="cx">                  $curl = str_replace($static_characters, $static_replacements, $curl);
</span><ins>+
</ins><span class="cx">                   // regular expressions
</span><span class="cx">                  $curl = preg_replace($dynamic_characters, $dynamic_replacements, $curl);
</span><ins>+
+                       // 9x9 (times)
+                       if ( 1 === preg_match( '/(?<=\d)x\d/', $text ) ) {
+                               // Searching for a digit is 10 times more expensive than for the x, so we avoid doing this one!
+                               $curl = preg_replace( '/\b(\d+)x(\d+)\b/', '$1&#215;$2', $curl );
+                       }
</ins><span class="cx">           }
</span><ins>+
+               // Replace each & with &#038; unless it already looks like an entity.
</ins><span class="cx">           $curl = preg_replace('/&([^#])(?![a-zA-Z1-4]{1,8};)/', '&#038;$1', $curl);
</span><span class="cx">  }
</span><span class="cx">  return implode( '', $textarr );
</span></span></pre></div>
<a id="trunktestsphpunittestsformattingWPTexturizephp"></a>
<div class="modfile"><h4>Modified: trunk/tests/phpunit/tests/formatting/WPTexturize.php (27838 => 27839)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/tests/phpunit/tests/formatting/WPTexturize.php     2014-03-29 06:22:46 UTC (rev 27838)
+++ trunk/tests/phpunit/tests/formatting/WPTexturize.php        2014-03-29 07:15:33 UTC (rev 27839)
</span><span class="lines">@@ -14,7 +14,11 @@
</span><span class="cx">          $this->assertEquals('[a]a&#8211;b[code]---[/code]a&#8211;b[/a]', wptexturize('[a]a--b[code]---[/code]a--b[/a]'));
</span><span class="cx">          $this->assertEquals('<pre><code></code>--</pre>', wptexturize('<pre><code></code>--</pre>'));
</span><span class="cx"> 
</span><del>-               $this->assertEquals('<code>---</code>', wptexturize('<code>---</code>'));
</del><ins>+                $this->assertEquals( '<code>---</code>',     wptexturize( '<code>---</code>'     ) );
+               $this->assertEquals( '<kbd>---</kbd>',       wptexturize( '<kbd>---</kbd>'       ) );
+               $this->assertEquals( '<style>---</style>',   wptexturize( '<style>---</style>'   ) );
+               $this->assertEquals( '<script>---</script>', wptexturize( '<script>---</script>' ) );
+               $this->assertEquals( '<tt>---</tt>',         wptexturize( '<tt>---</tt>'         ) );
</ins><span class="cx"> 
</span><span class="cx">          $this->assertEquals('<code>href="baba"</code> &#8220;baba&#8221;', wptexturize('<code>href="baba"</code> "baba"'));
</span><span class="cx"> 
</span><span class="lines">@@ -44,7 +48,6 @@
</span><span class="cx">  //WP Ticket #4539
</span><span class="cx">  function test_basic_quotes() {
</span><span class="cx">          $this->assertEquals('test&#8217;s', wptexturize('test\'s'));
</span><del>-               $this->assertEquals('test&#8217;s', wptexturize('test\'s'));
</del><span class="cx"> 
</span><span class="cx">          $this->assertEquals('&#8216;quoted&#8217;', wptexturize('\'quoted\''));
</span><span class="cx">          $this->assertEquals('&#8220;quoted&#8221;', wptexturize('"quoted"'));
</span><span class="lines">@@ -194,4 +197,801 @@
</span><span class="cx">          $this->assertEquals( ' &#8212;&nbsp;', wptexturize( ' --&nbsp;' ) );
</span><span class="cx">          $this->assertEquals( '&nbsp;&#8212; ', wptexturize( '&nbsp;-- ') );
</span><span class="cx">  }
</span><ins>+
+       /**
+        * Test spaces around quotes.
+        *
+        * These should never happen, even if the desired output changes some day.
+        *
+        * @ticket 22692
+        */
+       function test_spaces_around_quotes_never() {
+               $nbsp = "\xC2\xA0";
+
+               $problem_input  = "$nbsp\"A";
+               $problem_output = "$nbsp&#8221;A";
+
+               $this->assertNotEquals( $problem_output, wptexturize( $problem_input ) );
+       }
+
+       /**
+        * Test spaces around quotes.
+        *
+        * These are desirable outputs for the current design.
+        *
+        * @ticket 22692
+        * @dataProvider data_spaces_around_quotes
+        */
+       function test_spaces_around_quotes( $input, $output ) {
+               return $this->assertEquals( $output, wptexturize( $input ) );
+       }
+
+       function data_spaces_around_quotes() {
+               $nbsp = "\xC2\xA0";
+               $pi   = "\xCE\xA0";
+
+               return array(
+                       array(
+                               "stop. $nbsp\"A quote after 2 spaces.\"",
+                               "stop. $nbsp&#8220;A quote after 2 spaces.&#8221;",
+                       ),
+                       array(
+                               "stop.$nbsp$nbsp\"A quote after 2 spaces.\"",
+                               "stop.$nbsp$nbsp&#8220;A quote after 2 spaces.&#8221;",
+                       ),
+                       array(
+                               "stop. $nbsp'A quote after 2 spaces.'",
+                               "stop. $nbsp&#8216;A quote after 2 spaces.&#8217;",
+                       ),
+                       array(
+                               "stop.$nbsp$nbsp'A quote after 2 spaces.'",
+                               "stop.$nbsp$nbsp&#8216;A quote after 2 spaces.&#8217;",
+                       ),
+                       array(
+                               "stop. &nbsp;\"A quote after 2 spaces.\"",
+                               "stop. &nbsp;&#8220;A quote after 2 spaces.&#8221;",
+                       ),
+                       array(
+                               "stop.&nbsp;&nbsp;\"A quote after 2 spaces.\"",
+                               "stop.&nbsp;&nbsp;&#8220;A quote after 2 spaces.&#8221;",
+                       ),
+                       array(
+                               "stop. &nbsp;'A quote after 2 spaces.'",
+                               "stop. &nbsp;&#8216;A quote after 2 spaces.&#8217;",
+                       ),
+                       array(
+                               "stop.&nbsp;&nbsp;'A quote after 2 spaces.'",
+                               "stop.&nbsp;&nbsp;&#8216;A quote after 2 spaces.&#8217;",
+                       ),
+                       array(
+                               "Contraction: $pi's",
+                               "Contraction: $pi&#8217;s",
+                       ),
+               );
+       }
+
+       /**
+        * Apostrophe before a number always becomes &#8217 (apos);
+        *
+        * Checks all baseline patterns. If anything ever changes in wptexturize(), these tests may fail.
+        *
+        * @ticket 22692
+        * @dataProvider data_apos_before_digits
+        */
+       function test_apos_before_digits( $input, $output ) {
+               return $this->assertEquals( $output, wptexturize( $input ) );
+       }
+
+       function data_apos_before_digits() {
+               return array(
+                       array(
+                               "word '99 word",
+                               "word &#8217;99 word",
+                       ),
+                       array(
+                               "word'99 word",
+                               "word&#8217;99 word",
+                       ),
+                       array(
+                               "word '99word",
+                               "word &#8217;99word",
+                       ),
+                       array(
+                               "word'99word",
+                               "word&#8217;99word",
+                       ),
+                       array(
+                               "word '99&#8217;s word", // Appears as a separate but logically superfluous pattern in 3.8.
+                               "word &#8217;99&#8217;s word",
+                       ),
+                       array(
+                               "word '99's word", // Due to the logic error, second apos becomes a prime.  See ticket #22823
+                               "word &#8217;99&#8242;s word",
+                       ),
+                       array(
+                               "word '99'samsonite",
+                               "word &#8217;99&#8242;samsonite",
+                       ),
+                       array(
+                               "according to our source, '33% of all students scored less than 50' on the test.", // Apostrophes and primes have priority over quotes
+                               "according to our source, &#8217;33% of all students scored less than 50&#8242; on the test.",
+                       ),
+                       array(
+                               "word '99' word", // See ticket #8775
+                               "word &#8217;99&#8242; word",
+                       ),
+               );
+       }
+
+       /**
+        * Apostrophe after a space or ([{<" becomes &#8216; (opening_single_quote)
+        *
+        * Checks all baseline patterns. If anything ever changes in wptexturize(), these tests may fail.
+        *
+        * @ticket 22692
+        * @dataProvider data_opening_single_quote
+        */
+       function test_opening_single_quote( $input, $output ) {
+               return $this->assertEquals( $output, wptexturize( $input ) );
+       }
+
+       function data_opening_single_quote() {
+               return array(
+                       array(
+                               "word 'word word",
+                               "word &#8216;word word",
+                       ),
+                       array(
+                               "word ('word word",
+                               "word (&#8216;word word",
+                       ),
+                       array(
+                               "word ['word word",
+                               "word [&#8216;word word",
+                       ),
+                       array(
+                               "word <'word word", // Invalid HTML input?
+                               "word <&#8216;word word",
+                       ),
+                       array(
+                               "word &lt;'word word", // Valid HTML input triggers the apos in a word pattern
+                               "word &lt;&#8217;word word",
+                       ),
+                       array(
+                               "word {'word word",
+                               "word {&#8216;word word",
+                       ),
+                       array(
+                               "word \"'word word",
+                               "word &#8220;&#8216;word word", // Two opening quotes
+                       ),
+                       array(
+                               "'word word",
+                               "&#8216;word word",
+                       ),
+                       array(
+                               "word('word word",
+                               "word(&#8216;word word",
+                       ),
+                       array(
+                               "word['word word",
+                               "word[&#8216;word word",
+                       ),
+                       array(
+                               "word<'word word",
+                               "word<&#8216;word word",
+                       ),
+                       array(
+                               "word&lt;'word word",
+                               "word&lt;&#8217;word word",
+                       ),
+                       array(
+                               "word{'word word",
+                               "word{&#8216;word word",
+                       ),
+                       array(
+                               "word\"'word word",
+                               "word&#8221;&#8216;word word", // Closing quote, then opening quote
+                       ),
+                       array(
+                               "word ' word word",
+                               "word &#8216; word word",
+                       ),
+                       array(
+                               "word (' word word",
+                               "word (&#8216; word word",
+                       ),
+                       array(
+                               "word [' word word",
+                               "word [&#8216; word word",
+                       ),
+                       array(
+                               "word <' word word", // Invalid HTML input?
+                               "word <&#8216; word word",
+                       ),
+                       array(
+                               "word &lt;' word word", // Valid HTML input triggers the closing single quote here
+                               "word &lt;&#8217; word word",
+                       ),
+                       array(
+                               "word {' word word",
+                               "word {&#8216; word word",
+                       ),
+                       array(
+                               "word \"' word word",
+                               "word &#8220;&#8216; word word", // Two opening quotes
+                       ),
+                       array(
+                               "' word word",
+                               "&#8216; word word",
+                       ),
+                       array(
+                               "word(' word word",
+                               "word(&#8216; word word",
+                       ),
+                       array(
+                               "word[' word word",
+                               "word[&#8216; word word",
+                       ),
+                       array(
+                               "word<' word word",
+                               "word<&#8216; word word",
+                       ),
+                       array(
+                               "word&lt;' word word",
+                               "word&lt;&#8217; word word",
+                       ),
+                       array(
+                               "word{' word word",
+                               "word{&#8216; word word",
+                       ),
+                       array(
+                               "word\"' word word",
+                               "word&#8221;&#8216; word word", // Closing quote, then opening quote
+                       ),
+               );
+       }
+
+       /**
+        * Double quote after a number becomes &#8243; (double_prime)
+        *
+        * Checks all baseline patterns. If anything ever changes in wptexturize(), these tests may fail.
+        *
+        * @ticket 22692
+        * @dataProvider data_double_prime
+        */
+       function test_double_prime( $input, $output ) {
+               return $this->assertEquals( $output, wptexturize( $input ) );
+       }
+
+       function data_double_prime() {
+               return array(
+                       array(
+                               'word 99" word',
+                               'word 99&#8243; word',
+                       ),
+                       array(
+                               'word 99"word',
+                               'word 99&#8243;word',
+                       ),
+                       array(
+                               'word99" word',
+                               'word99&#8243; word',
+                       ),
+                       array(
+                               'word99"word',
+                               'word99&#8243;word',
+                       ),
+               );
+       }
+
+       /**
+        * Apostrophe after a number becomes &#8242; (prime)
+        *
+        * Checks all baseline patterns. If anything ever changes in wptexturize(), these tests may fail.
+        *
+        * @ticket 22692
+        * @dataProvider data_single_prime
+        */
+       function test_single_prime( $input, $output ) {
+               return $this->assertEquals( $output, wptexturize( $input ) );
+       }
+
+       function data_single_prime() {
+               return array(
+                       array(
+                               "word 99' word",
+                               "word 99&#8242; word",
+                       ),
+                       array(
+                               "word 99'word",
+                               "word 99&#8242;word",
+                       ),
+                       array(
+                               "word99' word",
+                               "word99&#8242; word",
+                       ),
+                       array(
+                               "word99'word",
+                               "word99&#8242;word",
+                       ),
+               );
+       }
+
+       /**
+        * Apostrophe "in a word" becomes &#8217; (apos)
+        *
+        * Checks all baseline patterns. If anything ever changes in wptexturize(), these tests may fail.
+        *
+        * @ticket 22692
+        * @dataProvider data_contractions
+        */
+       function test_contractions( $input, $output ) {
+               return $this->assertEquals( $output, wptexturize( $input ) );
+       }
+
+       function data_contractions() {
+               return array(
+                       array(
+                               "word word's word",
+                               "word word&#8217;s word",
+                       ),
+                       array(
+                               "word word'. word", // Quotes with outside punctuation could end with apostrophes instead of closing quotes (may affect i18n)
+                               "word word&#8217;. word",
+                       ),
+                       array(
+                               "word ]'. word",
+                               "word ]&#8217;. word",
+                       ),
+                       array(
+                               "word )'. word",
+                               "word )&#8217;. word",
+                       ),
+                       array(
+                               "word }'. word",
+                               "word }&#8217;. word",
+                       ),
+                       array(
+                               "word >'. word", // Not tested
+                               "word >&#8217;. word",
+                       ),
+                       array(
+                               "word &gt;'. word",
+                               "word &gt;&#8217;. word",
+                       ),
+               );
+       }
+
+       /**
+        * Double quote after a space or ([{< becomes &#8220; (opening_quote) if not followed by spaces
+        *
+        * Checks all baseline patterns. If anything ever changes in wptexturize(), these tests may fail.
+        *
+        * @ticket 22692
+        * @dataProvider data_opening_quote
+        */
+       function test_opening_quote( $input, $output ) {
+               return $this->assertEquals( $output, wptexturize( $input ) );
+       }
+
+       function data_opening_quote() {
+               return array(
+                       array(
+                               'word "word word',
+                               'word &#8220;word word',
+                       ),
+                       array(
+                               'word ("word word',
+                               'word (&#8220;word word',
+                       ),
+                       array(
+                               'word ["word word',
+                               'word [&#8220;word word',
+                       ),
+                       array(
+                               'word <"word word', // Invalid HTML input?
+                               'word <&#8220;word word',
+                       ),
+                       array(
+                               'word &lt;"word word', // Valid HTML input triggers the closing quote pattern
+                               'word &lt;&#8221;word word',
+                       ),
+                       array(
+                               'word {"word word',
+                               'word {&#8220;word word',
+                       ),
+                       array(
+                               '"word word',
+                               '&#8220;word word',
+                       ),
+                       array(
+                               'word("word word',
+                               'word(&#8220;word word',
+                       ),
+                       array(
+                               'word["word word',
+                               'word[&#8220;word word',
+                       ),
+                       array(
+                               'word<"word word', // Invalid HTML input?
+                               'word<&#8220;word word',
+                       ),
+                       array(
+                               'word&lt;"word word', // Valid HTML input triggers the closing quote pattern
+                               'word&lt;&#8221;word word',
+                       ),
+                       array(
+                               'word{"word word',
+                               'word{&#8220;word word',
+                       ),
+                       array(
+                               'word "99 word',
+                               'word &#8220;99 word',
+                       ),
+               );
+       }
+
+       /**
+        * Double quote becomes &#8221; (closing_quote) unless it is already converted to double_prime or opening_quote.
+        *
+        * Checks all baseline patterns. If anything ever changes in wptexturize(), these tests may fail.
+        *
+        * @ticket 22692
+        * @dataProvider data_closing_quote
+        */
+       function test_closing_quote( $input, $output ) {
+               return $this->assertEquals( $output, wptexturize( $input ) );
+       }
+
+       function data_closing_quote() {
+               return array(
+                       array(
+                               'word word" word',
+                               'word word&#8221; word',
+                       ),
+                       array(
+                               'word word") word',
+                               'word word&#8221;) word',
+                       ),
+                       array(
+                               'word word"] word',
+                               'word word&#8221;] word',
+                       ),
+                       array(
+                               'word word"} word',
+                               'word word&#8221;} word',
+                       ),
+                       array(
+                               'word word"> word', // Invalid HTML input?
+                               'word word&#8221;> word',
+                       ),
+                       array(
+                               'word word"&gt; word', // Valid HTML should work
+                               'word word&#8221;&gt; word',
+                       ),
+                       array(
+                               'word word"',
+                               'word word&#8221;',
+                       ),
+                       array(
+                               'word word"word',
+                               'word word&#8221;word',
+                       ),
+                       array(
+                               'word"word"word',
+                               'word&#8221;word&#8221;word',
+                       ),
+                       array(
+                               'test sentence".',
+                               'test sentence&#8221;.',
+                       ),
+                       array(
+                               'test sentence."',
+                               'test sentence.&#8221;',
+                       ),
+                       array(
+                               'test sentence". word',
+                               'test sentence&#8221;. word',
+                       ),
+                       array(
+                               'test sentence." word',
+                               'test sentence.&#8221; word',
+                       ),
+               );
+       }
+
+       /**
+        * Test that single quotes followed by a space or a period become &#8217; (closing_single_quote)
+        *
+        * Checks all baseline patterns. If anything ever changes in wptexturize(), these tests may fail.
+        *
+        * @ticket 22692
+        * @dataProvider data_closing_single_quote
+        */
+       function test_closing_single_quote( $input, $output ) {
+               return $this->assertEquals( $output, wptexturize( $input ) );
+       }
+
+       function data_closing_single_quote() {
+               return array(
+                       array(
+                               "word word' word",
+                               "word word&#8217; word",
+                       ),
+                       array(
+                               "word word'. word",
+                               "word word&#8217;. word",
+                       ),
+                       array(
+                               "word word'.word",
+                               "word word&#8217;.word",
+                       ),
+                       array(
+                               "word word'",
+                               "word word&#8217;",
+                       ),
+                       array(
+                               "test sentence'.",
+                               "test sentence&#8217;.",
+                       ),
+                       array(
+                               "test sentence.'",
+                               "test sentence.&#8217;",
+                       ),
+                       array(
+                               "test sentence'. word",
+                               "test sentence&#8217;. word",
+                       ),
+                       array(
+                               "test sentence.' word",
+                               "test sentence.&#8217; word",
+                       ),
+               );
+       }
+
+       /**
+        * Tests multiplication.
+        *
+        * Checks all baseline patterns. If anything ever changes in wptexturize(), these tests may fail.
+        *
+        * @ticket 22692
+        * @dataProvider data_multiplication
+        */
+       function test_multiplication( $input, $output ) {
+               return $this->assertEquals( $output, wptexturize( $input ) );
+       }
+
+       function data_multiplication() {
+               return array(
+                       array(
+                               "9x9",
+                               "9&#215;9",
+                       ),
+                       array(
+                               "12x34",
+                               "12&#215;34",
+                       ),
+                       array(
+                               "9 x 9",
+                               "9 x 9",
+                       ),
+               );
+       }
+
+       /**
+        * Test ampersands. & always becomes &#038; unless it is followed by # or ;
+        *
+        * Checks all baseline patterns. If anything ever changes in wptexturize(), these tests may fail.
+        *
+        * @ticket 22692
+        * @dataProvider data_ampersand
+        */
+       function test_ampersand( $input, $output ) {
+               return $this->assertEquals( $output, wptexturize( $input ) );
+       }
+
+       function data_ampersand() {
+               return array(
+                       array(
+                               "word & word",
+                               "word &#038; word",
+                       ),
+                       array(
+                               "word&word",
+                               "word&#038;word",
+                       ),
+                       array(
+                               "word &nbsp; word",
+                               "word &nbsp; word",
+                       ),
+                       array(
+                               "word &#038; word",
+                               "word &#038; word",
+                       ),
+                       array(
+                               "word &# word",
+                               "word &# word", // invalid output?
+                       ),
+                       array(
+                               "word &44; word",
+                               "word &44; word",
+                       ),
+                       array(
+                               "word &&amp; word",
+                               "word &&amp; word",
+                       ),
+                       array(
+                               "word &!amp; word",
+                               "word &!amp; word",
+                       ),
+               );
+       }
+
+       /**
+        * Test "cockney" phrases, which begin with an apostrophe instead of an opening single quote.
+        *
+        * Checks all baseline patterns. If anything ever changes in wptexturize(), these tests may fail.
+        *
+        * @ticket 22692
+        * @dataProvider data_cockney
+        */
+       function test_cockney( $input, $output ) {
+               return $this->assertEquals( $output, wptexturize( $input ) );
+       }
+
+       function data_cockney() {
+               return array(
+                       array(
+                               "word 'tain't word",
+                               "word &#8217;tain&#8217;t word",
+                       ),
+                       array(
+                               "word 'twere word",
+                               "word &#8217;twere word",
+                       ),
+                       array(
+                               "word 'twas word",
+                               "word &#8217;twas word",
+                       ),
+                       array(
+                               "word 'tis word",
+                               "word &#8217;tis word",
+                       ),
+                       array(
+                               "word 'twill word",
+                               "word &#8217;twill word",
+                       ),
+                       array(
+                               "word 'til word",
+                               "word &#8217;til word",
+                       ),
+                       array(
+                               "word 'bout word",
+                               "word &#8217;bout word",
+                       ),
+                       array(
+                               "word 'nuff word",
+                               "word &#8217;nuff word",
+                       ),
+                       array(
+                               "word 'round word",
+                               "word &#8217;round word",
+                       ),
+                       array(
+                               "word 'cause word",
+                               "word &#8217;cause word",
+                       ),
+                       array(
+                               "word 'em word",
+                               "word &#8216;em word",
+                       ),
+               );
+       }
+
+       /**
+        * Test smart dashes.
+        *
+        * Checks all baseline patterns. If anything ever changes in wptexturize(), these tests may fail.
+        *
+        * @ticket 22692
+        * @dataProvider data_smart_dashes
+        */
+       function test_smart_dashes( $input, $output ) {
+               return $this->assertEquals( $output, wptexturize( $input ) );
+       }
+
+       function data_smart_dashes() {
+               return array(
+                       array(
+                               "word --- word",
+                               "word &#8212; word",
+                       ),
+                       array(
+                               "word---word",
+                               "word&#8212;word",
+                       ),
+                       array(
+                               "word -- word",
+                               "word &#8212; word",
+                       ),
+                       array(
+                               "word--word",
+                               "word&#8211;word",
+                       ),
+                       array(
+                               "word - word",
+                               "word &#8211; word",
+                       ),
+                       array(
+                               "word-word",
+                               "word-word",
+                       ),
+                       array(
+                               "word xn&#8211; word",
+                               "word xn-- word",
+                       ),
+                       array(
+                               "wordxn&#8211;word",
+                               "wordxn--word",
+                       ),
+               );
+       }
+
+       /**
+        * Test miscellaneous static replacements.
+        *
+        * Checks all baseline patterns. If anything ever changes in wptexturize(), these tests may fail.
+        *
+        * @ticket 22692
+        * @dataProvider data_misc_static_replacements
+        */
+       function test_misc_static_replacements( $input, $output ) {
+               return $this->assertEquals( $output, wptexturize( $input ) );
+       }
+
+       function data_misc_static_replacements() {
+               return array(
+                       array(
+                               "word ... word",
+                               "word &#8230; word",
+                       ),
+                       array(
+                               "word...word",
+                               "word&#8230;word",
+                       ),
+                       array(
+                               "word `` word",
+                               "word &#8220; word",
+                       ),
+                       array(
+                               "word``word",
+                               "word&#8220;word",
+                       ),
+                       array(
+                               "word '' word",
+                               "word &#8221; word",
+                       ),
+                       array(
+                               "word''word",
+                               "word&#8221;word",
+                       ),
+                       array(
+                               "word (tm) word",
+                               "word &#8482; word",
+                       ),
+                       array(
+                               "word (tm)word",
+                               "word &#8482;word",
+                       ),
+                       array(
+                               "word(tm) word",
+                               "word(tm) word",
+                       ),
+                       array(
+                               "word(tm)word",
+                               "word(tm)word",
+                       ),
+               );
+       }
</ins><span class="cx"> }
</span></span></pre>
</div>
</div>

</body>
</html>