mirror of
https://github.com/danielstjules/Stringy.git
synced 2025-08-21 04:21:25 +02:00
Add removeLeft() and removeRight()
This commit is contained in:
@@ -669,6 +669,42 @@ class CommonTest extends PHPUnit_Framework_TestCase
|
||||
return $testData;
|
||||
}
|
||||
|
||||
public function stringsForRemoveLeft()
|
||||
{
|
||||
$testData = array(
|
||||
array('foo bar', 'foo bar', ''),
|
||||
array('oo bar', 'foo bar', 'f'),
|
||||
array('bar', 'foo bar', 'foo '),
|
||||
array('foo bar', 'foo bar', 'oo'),
|
||||
array('foo bar', 'foo bar', 'oo bar'),
|
||||
array('fòô bàř', 'fòô bàř', '', 'UTF-8'),
|
||||
array('òô bàř', 'fòô bàř', 'f', 'UTF-8'),
|
||||
array('bàř', 'fòô bàř', 'fòô ', 'UTF-8'),
|
||||
array('fòô bàř', 'fòô bàř', 'òô', 'UTF-8'),
|
||||
array('fòô bàř', 'fòô bàř', 'òô bàř', 'UTF-8')
|
||||
);
|
||||
|
||||
return $testData;
|
||||
}
|
||||
|
||||
public function stringsForRemoveRight()
|
||||
{
|
||||
$testData = array(
|
||||
array('foo bar', 'foo bar', ''),
|
||||
array('foo ba', 'foo bar', 'r'),
|
||||
array('foo', 'foo bar', ' bar'),
|
||||
array('foo bar', 'foo bar', 'ba'),
|
||||
array('foo bar', 'foo bar', 'foo ba'),
|
||||
array('fòô bàř', 'fòô bàř', '', 'UTF-8'),
|
||||
array('fòô bà', 'fòô bàř', 'ř', 'UTF-8'),
|
||||
array('fòô', 'fòô bàř', ' bàř', 'UTF-8'),
|
||||
array('fòô bàř', 'fòô bàř', 'bà', 'UTF-8'),
|
||||
array('fòô bàř', 'fòô bàř', 'fòô bà', 'UTF-8')
|
||||
);
|
||||
|
||||
return $testData;
|
||||
}
|
||||
|
||||
// A test is required so as not to throw an error
|
||||
// This is a lot cleaner than using PHPUnit's mocks to spy
|
||||
public function test() {
|
||||
|
@@ -372,4 +372,22 @@ class StaticStringyTestCase extends CommonTest
|
||||
$result = S::ensureRight($str, $substring, $encoding);
|
||||
$this->assertEquals($expected, $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider stringsForRemoveLeft
|
||||
*/
|
||||
public function testRemoveLeft($expected, $str, $substring, $encoding = null)
|
||||
{
|
||||
$result = S::removeLeft($str, $substring, $encoding);
|
||||
$this->assertEquals($expected, $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider stringsForRemoveRight
|
||||
*/
|
||||
public function testRemoveRight($expected, $str, $substring, $encoding = null)
|
||||
{
|
||||
$result = S::removeRight($str, $substring, $encoding);
|
||||
$this->assertEquals($expected, $result);
|
||||
}
|
||||
}
|
||||
|
@@ -354,4 +354,22 @@ class StringyTestCase extends CommonTest
|
||||
$result = S::create($str, $encoding)->ensureRight($substring);
|
||||
$this->assertEquals($expected, $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider stringsForRemoveLeft
|
||||
*/
|
||||
public function testRemoveLeft($expected, $str, $substring, $encoding = null)
|
||||
{
|
||||
$result = S::create($str, $encoding)->removeLeft($substring);
|
||||
$this->assertEquals($expected, $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider stringsForRemoveRight
|
||||
*/
|
||||
public function testRemoveRight($expected, $str, $substring, $encoding = null)
|
||||
{
|
||||
$result = S::create($str, $encoding)->removeRight($substring);
|
||||
$this->assertEquals($expected, $result);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user