mirror of
https://github.com/danielstjules/Stringy.git
synced 2025-08-12 16:24:00 +02:00
Added regexReplace()
This commit is contained in:
@@ -939,4 +939,19 @@ abstract class CommonTest extends PHPUnit_Framework_TestCase
|
||||
|
||||
return $testData;
|
||||
}
|
||||
|
||||
public function stringsForRegexReplace()
|
||||
{
|
||||
$testData = array(
|
||||
array('', '', '', ''),
|
||||
array('bar', 'foo', 'f[o]+', 'bar'),
|
||||
array('bar', 'foo bar', 'f[O]+\s', '', 'i'),
|
||||
array('foo', 'bar', '[[:alpha:]]{3}', 'foo'),
|
||||
array('', '', '', '', 'msr', 'UTF-8'),
|
||||
array('bàř', 'fòô ', 'f[òô]+\s', 'bàř', 'msr', 'UTF-8'),
|
||||
array('fòô', 'bàř', '[[:alpha:]]{3}', 'fòô', 'msr', 'UTF-8')
|
||||
);
|
||||
|
||||
return $testData;
|
||||
}
|
||||
}
|
||||
|
@@ -572,4 +572,15 @@ class StaticStringyTestCase extends CommonTest
|
||||
$this->assertInternalType('string', $result);
|
||||
$this->assertEquals($expected, $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider stringsForRegexReplace
|
||||
*/
|
||||
public function testRegexReplace($expected, $str, $pattern, $replacement,
|
||||
$options = 'msr', $encoding = null)
|
||||
{
|
||||
$result = S::regexReplace($str, $pattern, $replacement, $options, $encoding);
|
||||
$this->assertInternalType('string', $result);
|
||||
$this->assertEquals($expected, $result);
|
||||
}
|
||||
}
|
||||
|
@@ -675,4 +675,17 @@ class StringyTestCase extends CommonTest
|
||||
$this->assertEquals($expected, $result);
|
||||
$this->assertEquals($str, $stringy);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider stringsForRegexReplace
|
||||
*/
|
||||
public function testregexReplace($expected, $str, $pattern, $replacement,
|
||||
$options = 'msr', $encoding = null)
|
||||
{
|
||||
$stringy = S::create($str, $encoding);
|
||||
$result = $stringy->regexReplace($pattern, $replacement, $options);
|
||||
$this->assertInstanceOf('Stringy\Stringy', $result);
|
||||
$this->assertEquals($expected, $result);
|
||||
$this->assertEquals($str, $stringy);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user