Created
February 22, 2012 22:49
-
-
Save proudlygeek/1888108 to your computer and use it in GitHub Desktop.
decamelize
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function decamelize($string) { | |
$matches = array(); | |
preg_match("/.*(?=([A-Z].*))/", $string, $matches); | |
return $matches; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
require_once 'decamelize.php'; | |
class TestDecamelize extends PHPUnit_Framework_TestCase | |
{ | |
public function testOneCamel() | |
{ | |
$rs = decamelize("camelCase"); | |
$this->assertEquals($rs[0], "camel"); | |
$this->assertEquals($rs[1], "Case"); | |
} | |
public function testTwoCamel() | |
{ | |
$rs = decamelize("camelCaseAgain"); | |
$this->assertEquals($rs, array( | |
"camelCase", | |
"Again" | |
)); | |
} | |
public function testOneThousandCamel() | |
{ | |
$camelString = "camel"; | |
for ($i = 0; $i < 999; $i++) { | |
$camelString .= "Case"; | |
} | |
$rs = decamelize($camelString . "Case"); | |
$this->assertEquals(2, count($rs)); | |
$this->assertEquals($rs, array( | |
$camelString, | |
"Case" | |
)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Cool !!!!!