mirror of
https://github.com/danielstjules/Stringy.git
synced 2025-08-28 15:29:58 +02:00
Added indexOf and indexOfLast
This commit is contained in:
committed by
Daniel St. Jules
parent
3cf18e9e42
commit
9a5601efef
@@ -14,6 +14,26 @@ abstract class CommonTest extends PHPUnit_Framework_TestCase
|
||||
$this->assertInstanceOf('Stringy\Stringy', $actual);
|
||||
}
|
||||
|
||||
public function indexOfProvider()
|
||||
{
|
||||
return array(
|
||||
array(2, 'This is the string', 'is'),
|
||||
array(2, 'This is the string', 'is', 0, 'UTF-8'),
|
||||
array(false, 'This is the string', 'not-found', 0, 'UTF-8'),
|
||||
array(32, 'This is the string... and there is another thing', 'is', 10, 'UTF-8'),
|
||||
);
|
||||
}
|
||||
|
||||
public function indexOfLastProvider()
|
||||
{
|
||||
return array(
|
||||
array(5, 'This is the string', 'is'),
|
||||
array(5, 'This is the string', 'is', 0, 'UTF-8'),
|
||||
array(false, 'This is the string', 'not-found', 0, 'UTF-8'),
|
||||
array(32, 'This is the string... and there is another thing', 'is', 0, 'UTF-8'),
|
||||
);
|
||||
}
|
||||
|
||||
public function charsProvider()
|
||||
{
|
||||
return array(
|
||||
@@ -1023,4 +1043,5 @@ abstract class CommonTest extends PHPUnit_Framework_TestCase
|
||||
array('fòô', 'bàř', '[[:alpha:]]{3}', 'fòô', 'msr', 'UTF-8')
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -6,6 +6,24 @@ use Stringy\StaticStringy as S;
|
||||
|
||||
class StaticStringyTestCase extends CommonTest
|
||||
{
|
||||
/**
|
||||
* @dataProvider indexOfProvider()
|
||||
*/
|
||||
public function testIndexOf($expected, $str, $subStr, $offset = 0, $encoding = null)
|
||||
{
|
||||
$result = S::indexOf($str, $subStr, $offset, $encoding);
|
||||
$this->assertEquals($expected, $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider indexOfLastProvider()
|
||||
*/
|
||||
public function testIndexOfLast($expected, $str, $subStr, $offset = 0, $encoding = null)
|
||||
{
|
||||
$result = S::indexOfLast($str, $subStr, $offset, $encoding);
|
||||
$this->assertEquals($expected, $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider charsProvider()
|
||||
*/
|
||||
@@ -647,4 +665,5 @@ class StaticStringyTestCase extends CommonTest
|
||||
$this->assertInternalType('string', $result);
|
||||
$this->assertEquals($expected, $result);
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -153,6 +153,24 @@ class StringyTestCase extends CommonTest
|
||||
unset($stringy[1]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider indexOfProvider()
|
||||
*/
|
||||
public function testIndexOf($expected, $str, $subStr, $offset = 0, $encoding = null)
|
||||
{
|
||||
$result = S::create($str, $encoding)->indexOf($subStr, $offset);
|
||||
$this->assertEquals($expected, $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider indexOfLastProvider()
|
||||
*/
|
||||
public function testIndexOfLast($expected, $str, $subStr, $offset = 0, $encoding = null)
|
||||
{
|
||||
$result = S::create($str, $encoding)->indexOfLast($subStr, $offset);
|
||||
$this->assertEquals($expected, $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider charsProvider()
|
||||
*/
|
||||
@@ -911,4 +929,5 @@ class StringyTestCase extends CommonTest
|
||||
$this->assertEquals($expected, $result);
|
||||
$this->assertEquals($str, $stringy);
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user