mirror of
https://github.com/danielstjules/Stringy.git
synced 2025-08-12 16:24:00 +02:00
Added truncate()
This commit is contained in:
@@ -394,6 +394,36 @@ class CommonTest extends PHPUnit_Framework_TestCase
|
||||
return $testData;
|
||||
}
|
||||
|
||||
public function stringsForTruncate()
|
||||
{
|
||||
$testData = array(
|
||||
array('Test foo bar', 'Test foo bar', 12),
|
||||
array('Test foo ba', 'Test foo bar', 11),
|
||||
array('Test foo', 'Test foo bar', 8),
|
||||
array('Test fo', '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('T...', 'Test foo bar', 4, '...'),
|
||||
array('Test fo....', 'Test foo bar', 11, '....'),
|
||||
array('Test fòô bàř', 'Test fòô bàř', 12, '', 'UTF-8'),
|
||||
array('Test fòô bà', 'Test fòô bàř', 11, '', 'UTF-8'),
|
||||
array('Test fòô', 'Test fòô bàř', 8, '', 'UTF-8'),
|
||||
array('Test fò', '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 fϰϰ', 'Test fòô bàř', 8, 'ϰϰ', 'UTF-8'),
|
||||
array('Test ϰϰ', 'Test fòô bàř', 7, 'ϰϰ', 'UTF-8'),
|
||||
array('Teϰϰ', 'Test fòô bàř', 4, 'ϰϰ', 'UTF-8'),
|
||||
array('What are your pl...', 'What are your plans today?', 19, '...')
|
||||
);
|
||||
|
||||
return $testData;
|
||||
}
|
||||
|
||||
public function stringsForSafeTruncate()
|
||||
{
|
||||
$testData = array(
|
||||
@@ -417,7 +447,8 @@ class CommonTest extends PHPUnit_Framework_TestCase
|
||||
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')
|
||||
array('ϰϰ', 'Test fòô bàř', 4, 'ϰϰ', 'UTF-8'),
|
||||
array('What are your plans...', 'What are your plans today?', 22, '...')
|
||||
);
|
||||
|
||||
return $testData;
|
||||
|
@@ -231,6 +231,16 @@ class StaticStringyTestCase extends CommonTest
|
||||
$this->assertEquals($expected, $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider stringsForTruncate
|
||||
*/
|
||||
public function testTruncate($expected, $str, $length, $substring = '',
|
||||
$encoding = null)
|
||||
{
|
||||
$result = S::truncate($str, $length, $substring, $encoding);
|
||||
$this->assertEquals($expected, $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider stringsForSafeTruncate
|
||||
*/
|
||||
|
@@ -232,12 +232,12 @@ class StringyTestCase extends CommonTest
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider stringsForSafeTruncate
|
||||
* @dataProvider stringsForTruncate
|
||||
*/
|
||||
public function testSafeTruncate($expected, $str, $length, $substring = '',
|
||||
$encoding = null)
|
||||
public function testTruncate($expected, $str, $length, $substring = '',
|
||||
$encoding = null)
|
||||
{
|
||||
$result = S::create($str, $encoding)->safeTruncate($length, $substring);
|
||||
$result = S::create($str, $encoding)->truncate($length, $substring);
|
||||
$this->assertEquals($expected, $result);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user