Skip to content

Commit 12f9cb6

Browse files
committed
[String] Added test for replaceMatches
1 parent d8597f4 commit 12f9cb6

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
lines changed

Tests/AbstractAsciiTestCase.php

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -787,6 +787,34 @@ public static function provideReplace()
787787
];
788788
}
789789

790+
/**
791+
* @dataProvider provideReplaceMatches
792+
*/
793+
public function testReplaceMatches(string $expectedString, string $origin, string $fromRegexp, $to)
794+
{
795+
$origin = static::createFromString($origin);
796+
$result = $origin->replaceMatches($fromRegexp, $to);
797+
798+
$this->assertEquals(static::createFromString($expectedString), $result);
799+
}
800+
801+
public static function provideReplaceMatches()
802+
{
803+
return [
804+
['April,15,2003', 'April 15, 2003', '/(\w+) (\d+), (\d+)/i', '${1},$2,$3'],
805+
['5/27/1999', '1999-5-27', '/(19|20)(\d{2})-(\d{1,2})-(\d{1,2})/', '\3/\4/\1\2'],
806+
['Copyright 2000', 'Copyright 1999', '([0-9]+)', '2000'],
807+
['hello world! this is a test', 'HELLO WORLD! THIS is a test', '/\b([A-Z]+)\b/', function ($word) {
808+
return strtolower($word[1]);
809+
}],
810+
['COPYRIGHT 1999', 'Copyright 1999', '/[a-z]/', function ($matches) {
811+
foreach ($matches as $match) {
812+
return strtoupper($match);
813+
}
814+
}],
815+
];
816+
}
817+
790818
/**
791819
* @dataProvider provideReplaceIgnoreCase
792820
*/

Tests/AbstractUnicodeTestCase.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -405,6 +405,16 @@ public static function provideReplace(): array
405405
);
406406
}
407407

408+
public static function provideReplaceMatches(): array
409+
{
410+
return array_merge(
411+
parent::provideReplaceMatches(),
412+
[
413+
['This is a dj-vu situation!', 'This is a déjà-vu situation!', '/([à-ú])/', ''],
414+
]
415+
);
416+
}
417+
408418
public static function provideReplaceIgnoreCase(): array
409419
{
410420
return array_merge(

0 commit comments

Comments
 (0)