mirror of
https://github.com/danielstjules/Stringy.git
synced 2025-08-13 00:34:11 +02:00
Added at()
This commit is contained in:
@@ -546,6 +546,22 @@ class CommonTest extends PHPUnit_Framework_TestCase
|
||||
return $testData;
|
||||
}
|
||||
|
||||
public function stringsForAt()
|
||||
{
|
||||
$testData = array(
|
||||
array('f', 'foo bar', 0),
|
||||
array('o', 'foo bar', 1),
|
||||
array('r', 'foo bar', 6),
|
||||
array('', 'foo bar', 7),
|
||||
array('f', 'fòô bàř', 0, 'UTF-8'),
|
||||
array('ò', 'fòô bàř', 1, 'UTF-8'),
|
||||
array('ř', 'fòô bàř', 6, 'UTF-8'),
|
||||
array('', 'fòô bàř', 7, '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() {
|
||||
|
@@ -317,4 +317,13 @@ class StaticStringyTestCase extends CommonTest
|
||||
$result = S::substr($str, $start, $length, $encoding);
|
||||
$this->assertEquals($expected, $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider stringsForAt
|
||||
*/
|
||||
public function testAt($expected, $str, $index, $encoding = null)
|
||||
{
|
||||
$result = S::at($str, $index, $encoding);
|
||||
$this->assertEquals($expected, $result);
|
||||
}
|
||||
}
|
||||
|
@@ -309,4 +309,13 @@ class StringyTestCase extends CommonTest
|
||||
$result = S::create($str, $encoding)->substr($start, $length);
|
||||
$this->assertEquals($expected, $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider stringsForAt
|
||||
*/
|
||||
public function testAt($expected, $str, $index, $encoding = null)
|
||||
{
|
||||
$result = S::create($str, $encoding)->at($index);
|
||||
$this->assertEquals($expected, $result);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user