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

Added isAlpha(), isAlphanumeric(), isBlank(), isLowerCase() and isUpperCase()

This commit is contained in:
Daniel St. Jules
2013-07-27 23:56:07 -04:00
parent 013e42dfce
commit 88b8a8a6ef
6 changed files with 381 additions and 10 deletions

View File

@@ -705,6 +705,97 @@ class CommonTest extends PHPUnit_Framework_TestCase
return $testData;
}
public function stringsForIsAlpha()
{
$testData = array(
array(true, ''),
array(true, 'foobar'),
array(false, 'foo bar'),
array(false, 'foobar2'),
array(true, 'fòôbàř', 'UTF-8'),
array(false, 'fòô bàř', 'UTF-8'),
array(false, 'fòôbàř2', 'UTF-8'),
array(true, 'ҠѨњфгШ', 'UTF-8'),
array(false, 'ҠѨњ¨ˆфгШ', 'UTF-8'),
array(true, '丹尼爾', 'UTF-8')
);
return $testData;
}
public function stringsForIsAlphanumeric()
{
$testData = array(
array(true, ''),
array(true, 'foobar1'),
array(false, 'foo bar'),
array(false, 'foobar2"'),
array(false, "\nfoobar\n"),
array(true, 'fòôbàř1', 'UTF-8'),
array(false, 'fòô bàř', 'UTF-8'),
array(false, 'fòôbàř2"', 'UTF-8'),
array(true, 'ҠѨњфгШ', 'UTF-8'),
array(false, 'ҠѨњ¨ˆфгШ', 'UTF-8'),
array(true, '丹尼爾111', 'UTF-8'),
array(true, انيال1', 'UTF-8'),
array(false, انيال1 ', 'UTF-8')
);
return $testData;
}
public function stringsForIsBlank()
{
$testData = array(
array(true, ''),
array(true, ' '),
array(true, "\n\t "),
array(true, "\n\t \v\f"),
array(false, "\n\t a \v\f"),
array(false, "\n\t ' \v\f"),
array(false, "\n\t 2 \v\f"),
array(true, '', 'UTF-8'),
array(true, ' ', 'UTF-8'), // thin space
array(true, '  ', 'UTF-8'), // ideographic spaces
array(false, ' z', 'UTF-8'),
array(false, ' 1', 'UTF-8'),
);
return $testData;
}
public function stringsForIsLowerCase()
{
$testData = array(
array(true, ''),
array(true, 'foobar'),
array(false, 'foo bar'),
array(false, 'Foobar'),
array(true, 'fòôbàř', 'UTF-8'),
array(false, 'fòôbàř2', 'UTF-8'),
array(false, 'fòô bàř', 'UTF-8'),
array(false, 'fòôbÀŘ', 'UTF-8'),
);
return $testData;
}
public function stringsForIsUpperCase()
{
$testData = array(
array(true, ''),
array(true, 'FOOBAR'),
array(false, 'FOO BAR'),
array(false, 'fOOBAR'),
array(true, 'FÒÔBÀŘ', 'UTF-8'),
array(false, 'FÒÔBÀŘ2', 'UTF-8'),
array(false, 'FÒÔ BÀŘ', 'UTF-8'),
array(false, 'FÒÔBàř', '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

@@ -390,4 +390,49 @@ class StaticStringyTestCase extends CommonTest
$result = S::removeRight($str, $substring, $encoding);
$this->assertEquals($expected, $result);
}
/**
* @dataProvider stringsForIsAlpha
*/
public function testIsAlpha($expected, $str, $encoding = null)
{
$result = S::isAlpha($str, $encoding);
$this->assertEquals($expected, $result);
}
/**
* @dataProvider stringsForIsAlphanumeric
*/
public function testIsAlphanumeric($expected, $str, $encoding = null)
{
$result = S::isAlphanumeric($str, $encoding);
$this->assertEquals($expected, $result);
}
/**
* @dataProvider stringsForIsBlank
*/
public function testIsBlank($expected, $str, $encoding = null)
{
$result = S::isBlank($str, $encoding);
$this->assertEquals($expected, $result);
}
/**
* @dataProvider stringsForIsLowerCase
*/
public function testIsLowerCase($expected, $str, $encoding = null)
{
$result = S::isLowerCase($str, $encoding);
$this->assertEquals($expected, $result);
}
/**
* @dataProvider stringsForIsUpperCase
*/
public function testIsUpperCase($expected, $str, $encoding = null)
{
$result = S::isUpperCase($str, $encoding);
$this->assertEquals($expected, $result);
}
}

View File

@@ -372,4 +372,49 @@ class StringyTestCase extends CommonTest
$result = S::create($str, $encoding)->removeRight($substring);
$this->assertEquals($expected, $result);
}
/**
* @dataProvider stringsForIsAlpha
*/
public function testIsAlpha($expected, $str, $encoding = null)
{
$result = S::create($str, $encoding)->isAlpha();
$this->assertEquals($expected, $result);
}
/**
* @dataProvider stringsForIsAlphanumeric
*/
public function testIsAlphanumeric($expected, $str, $encoding = null)
{
$result = S::create($str, $encoding)->isAlphanumeric();
$this->assertEquals($expected, $result);
}
/**
* @dataProvider stringsForIsBlank
*/
public function testIsBlank($expected, $str, $encoding = null)
{
$result = S::create($str, $encoding)->isBlank();
$this->assertEquals($expected, $result);
}
/**
* @dataProvider stringsForIsLowerCase
*/
public function testIsLowerCase($expected, $str, $encoding = null)
{
$result = S::create($str, $encoding)->isLowerCase();
$this->assertEquals($expected, $result);
}
/**
* @dataProvider stringsForIsUpperCase
*/
public function testIsUpperCase($expected, $str, $encoding = null)
{
$result = S::create($str, $encoding)->isUpperCase();
$this->assertEquals($expected, $result);
}
}