Browse Source

[Locale] adjust to new quoting format, some tests failing

Igor Wiedler 14 years ago
parent
commit
a883a3f62a

+ 3 - 2
src/Symfony/Component/Locale/Stub/StubIntlDateFormatter.php

@@ -55,14 +55,15 @@ class StubIntlDateFormatter
         $specialCharsMatch = implode('|', array_map(function($char) {
             return $char . '+';
         }, $specialCharsArray));
-        $regExp = "/('($specialCharsMatch|[^$specialChars])|$specialCharsMatch)/";
+        $quoteMatch = "'(?>(?>[^']+|'{2}+|)?)'";
+        $regExp = "/($quoteMatch|$specialCharsMatch)/";
 
         $callback = function($matches) use ($dateTime) {
             $pattern = $matches[0];
             $length = strlen($pattern);
 
             if ("'" === $pattern[0]) {
-                return substr($pattern, 1);
+                return preg_replace("/'{2}/", "'", substr($pattern, 1, -1));
             }
 
             switch ($pattern[0]) {

+ 5 - 34
tests/Symfony/Tests/Component/Locale/Stub/StubIntlDateFormatterTest.php

@@ -19,12 +19,14 @@ class StubIntlDateFormatterTest extends \PHPUnit_Framework_TestCase
     public function formatProvider()
     {
         return array(
+            /* general */
             array('y-M-d', 0, '1970-1-1'),
+            array("yyyy.MM.dd G 'at' HH:mm:ss zzz", 0, '1970.01.01 AD at 00:00:00 GMT+00:00'),
 
             /* escaping */
-            array("'M", 0, 'M'),
-            array("'yy", 0, 'yy'),
-            array("'''yy", 0, "'yy"),
+            array("'M'", 0, 'M'),
+            array("'yy'", 0, 'yy'),
+            array("'''yy'", 0, "'yy"),
             array("''y", 0, "'1970"),
             array("''yy", 0, "'70"),
 
@@ -217,21 +219,6 @@ class StubIntlDateFormatterTest extends \PHPUnit_Framework_TestCase
         );
     }
 
-    /**
-    * provides data for cases that are broken in icu/intl
-    */
-    public function brokenFormatProvider()
-    {
-        return array(
-            /* escaping */
-            array("'y-'M-'d", 0, 'y-M-d'),
-
-            /* weird bugs */
-            array("WTF 'y-'M", 0, '0T1 y-M'),
-            array("n-'M", 0, 'n-M'),
-        );
-    }
-
     /**
      * @expectedException InvalidArgumentException
      */
@@ -276,22 +263,6 @@ class StubIntlDateFormatterTest extends \PHPUnit_Framework_TestCase
         }
     }
 
-    /**
-    * @dataProvider brokenFormatProvider
-    */
-    public function testBrokenFormat($pattern, $timestamp, $expected)
-    {
-        $this->markTestSkipped('icu/intl has some bugs, thus skipping.');
-
-        $formatter = new StubIntlDateFormatter('en', StubIntlDateFormatter::MEDIUM, StubIntlDateFormatter::SHORT, 'UTC', StubIntlDateFormatter::GREGORIAN, $pattern);
-        $this->assertSame($expected, $formatter->format($timestamp), 'Check date format with stub implementation.');
-
-        if (extension_loaded('intl')) {
-            $formatter = new \IntlDateFormatter('en', \IntlDateFormatter::MEDIUM, \IntlDateFormatter::SHORT, 'UTC', \IntlDateFormatter::GREGORIAN, $pattern);
-            $this->assertSame($expected, $formatter->format($timestamp), 'Check date format with intl extension.');
-        }
-    }
-
     /**
      * @expectedException RuntimeException
      */