1
0
mirror of https://github.com/danielstjules/Stringy.git synced 2025-08-16 02:04:09 +02:00

Added slice

This commit is contained in:
Daniel St. Jules
2015-07-25 12:59:23 -07:00
parent 342ef7c3dd
commit 5e3ac6231c
3 changed files with 74 additions and 0 deletions

View File

@@ -1593,6 +1593,41 @@ class StringyTestCase extends PHPUnit_Framework_TestCase
);
}
/**
* @dataProvider sliceProvider()
*/
public function testSlice($expected, $str, $start, $end = null,
$encoding = null)
{
$stringy = S::create($str, $encoding);
$result = $stringy->slice($start, $end);
$this->assertStringy($result);
$this->assertEquals($expected, $result);
$this->assertEquals($str, $stringy);
}
public function sliceProvider()
{
return array(
array('foobar', 'foobar', 0),
array('foobar', 'foobar', 0, null),
array('foobar', 'foobar', 0, 6),
array('fooba', 'foobar', 0, 5),
array('', 'foobar', 3, 0),
array('', 'foobar', 3, 2),
array('ba', 'foobar', 3, 5),
array('ba', 'foobar', 3, -1),
array('fòôbàř', 'fòôbàř', 0, null, 'UTF-8'),
array('fòôbàř', 'fòôbàř', 0, null),
array('fòôbàř', 'fòôbàř', 0, 6, 'UTF-8'),
array('fòôbà', 'fòôbàř', 0, 5, 'UTF-8'),
array('', 'fòôbàř', 3, 0, 'UTF-8'),
array('', 'fòôbàř', 3, 2, 'UTF-8'),
array('bà', 'fòôbàř', 3, 5, 'UTF-8'),
array('bà', 'fòôbàř', 3, -1, 'UTF-8')
);
}
/**
* @dataProvider substrProvider()
*/