1
0
mirror of https://github.com/danielstjules/Stringy.git synced 2025-08-24 13:53:08 +02:00

Added ensureLeft() and ensureRight()

This commit is contained in:
Daniel St. Jules
2013-07-27 16:33:27 -04:00
parent 4828811a48
commit 6d927fbf5d
6 changed files with 156 additions and 14 deletions

View File

@@ -633,6 +633,42 @@ class CommonTest extends PHPUnit_Framework_TestCase
return $testData;
}
public function stringsForEnsureLeft()
{
$testData = array(
array('foobar', 'foobar', 'f'),
array('foobar', 'foobar', 'foo'),
array('foo/foobar', 'foobar', 'foo/'),
array('http://foobar', 'foobar', 'http://'),
array('http://foobar', 'http://foobar', 'http://'),
array('fòôbàř', 'fòôbàř', 'f', 'UTF-8'),
array('fòôbàř', 'fòôbàř', 'fòô', 'UTF-8'),
array('fòô/fòôbàř', 'fòôbàř', 'fòô/', 'UTF-8'),
array('http://fòôbàř', 'fòôbàř', 'http://', 'UTF-8'),
array('http://fòôbàř', 'http://fòôbàř', 'http://', 'UTF-8'),
);
return $testData;
}
public function stringsForEnsureRight()
{
$testData = array(
array('foobar', 'foobar', 'r'),
array('foobar', 'foobar', 'bar'),
array('foobar/bar', 'foobar', '/bar'),
array('foobar.com/', 'foobar', '.com/'),
array('foobar.com/', 'foobar.com/', '.com/'),
array('fòôbàř', 'fòôbàř', 'ř', 'UTF-8'),
array('fòôbàř', 'fòôbàř', 'bàř', 'UTF-8'),
array('fòôbàř/bàř', 'fòôbàř', '/bàř', 'UTF-8'),
array('fòôbàř.com/', 'fòôbàř', '.com/', 'UTF-8'),
array('fòôbàř.com/', 'fòôbàř.com/', '.com/', '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() {

View File

@@ -354,4 +354,22 @@ class StaticStringyTestCase extends CommonTest
$result = S::last($str, $n, $encoding);
$this->assertEquals($expected, $result);
}
/**
* @dataProvider stringsForEnsureLeft
*/
public function testEnsureLeft($expected, $str, $substring, $encoding = null)
{
$result = S::ensureLeft($str, $substring, $encoding);
$this->assertEquals($expected, $result);
}
/**
* @dataProvider stringsForEnsureRight
*/
public function testEnsureRight($expected, $str, $substring, $encoding = null)
{
$result = S::ensureRight($str, $substring, $encoding);
$this->assertEquals($expected, $result);
}
}

View File

@@ -336,4 +336,22 @@ class StringyTestCase extends CommonTest
$result = S::create($str, $encoding)->last($n);
$this->assertEquals($expected, $result);
}
/**
* @dataProvider stringsForEnsureLeft
*/
public function testEnsureLeft($expected, $str, $substring, $encoding = null)
{
$result = S::create($str, $encoding)->ensureLeft($substring);
$this->assertEquals($expected, $result);
}
/**
* @dataProvider stringsForEnsureRight
*/
public function testEnsureRight($expected, $str, $substring, $encoding = null)
{
$result = S::create($str, $encoding)->ensureRight($substring);
$this->assertEquals($expected, $result);
}
}