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

Added at()

This commit is contained in:
Daniel St. Jules
2013-07-27 13:57:30 -04:00
parent d757ce38de
commit f3ac2bf1f3
6 changed files with 75 additions and 3 deletions

View File

@@ -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() {

View File

@@ -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);
}
}

View File

@@ -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);
}
}