1
0
mirror of https://github.com/danielstjules/Stringy.git synced 2025-08-12 08:14:06 +02:00

Add truncate() and a couple small fixes

This commit is contained in:
Daniel St. Jules
2013-07-23 00:46:51 -04:00
parent ca4a924ba9
commit 1e2f49128b
3 changed files with 92 additions and 10 deletions

View File

@@ -575,6 +575,43 @@ class StringyTestCase extends PHPUnit_Framework_TestCase {
return $testData;
}
/**
* @dataProvider stringsForTruncate
*/
public function testTruncate($expected, $string, $length, $substring = '',
$encoding = null) {
$result = S::truncate($string, $length, $substring, $encoding);
$this->assertEquals($expected, $result);
}
public function stringsForTruncate() {
$testData = array(
array('Test foo bar', 'Test foo bar', 12),
array('Test foo', 'Test foo bar', 11),
array('Test foo', 'Test foo bar', 8),
array('Test', 'Test foo bar', 7),
array('Test', 'Test foo bar', 4),
array('Test foo bar', 'Test foo bar', 12, '...'),
array('Test foo...', 'Test foo bar', 11, '...'),
array('Test...', 'Test foo bar', 8, '...'),
array('Test...', 'Test foo bar', 7, '...'),
array('...', 'Test foo bar', 4, '...'),
array('Test....', 'Test foo bar', 11, '....'),
array('Test fòô bàř', 'Test fòô bàř', 12, '', 'UTF-8'),
array('Test fòô', 'Test fòô bàř', 11, '', 'UTF-8'),
array('Test fòô', 'Test fòô bàř', 8, '', 'UTF-8'),
array('Test', 'Test fòô bàř', 7, '', 'UTF-8'),
array('Test', 'Test fòô bàř', 4, '', 'UTF-8'),
array('Test fòô bàř', 'Test fòô bàř', 12, 'ϰϰ', 'UTF-8'),
array('Test fòôϰϰ', 'Test fòô bàř', 11, 'ϰϰ', 'UTF-8'),
array('Testϰϰ', 'Test fòô bàř', 8, 'ϰϰ', 'UTF-8'),
array('Testϰϰ', 'Test fòô bàř', 7, 'ϰϰ', 'UTF-8'),
array('ϰϰ', 'Test fòô bàř', 4, 'ϰϰ', 'UTF-8')
);
return $testData;
}
}
?>