Created
January 6, 2014 10:01
-
-
Save wouterj/8280619 to your computer and use it in GitHub Desktop.
This file contains 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 | |
namespace Wj\Stoffer\Scissors; | |
class Line | |
{ | |
private $input; | |
public function __construct($input) | |
{ | |
$this->input = $input; | |
} | |
public function getSnippets() | |
{ | |
$snippets = preg_split('/(\R)/', $this->input, -1, \PREG_SPLIT_DELIM_CAPTURE); | |
$return = array(); | |
do { | |
$return[] = current($snippets).next($snippets); | |
} while (false !== next($snippets)); | |
return $return; | |
} | |
} |
This file contains 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 | |
namespace spec\Wj\Stoffer\Scissors; | |
use PhpSpec\ObjectBehavior; | |
class LineSpec extends ObjectBehavior | |
{ | |
function it_is_initializable() | |
{ | |
$this->shouldHaveType('Wj\Stoffer\Scissors'); | |
} | |
function it_cuts_a_string_in_lines() | |
{ | |
$this->beConstructedWith("Hello World\nLorem\nIpsum\nDolor"); | |
$this->getSnippets()->shouldBe(array( | |
"Hello World\n", | |
"Lorem\n", | |
"Ipsum\n", | |
"Dolor" | |
)); | |
} | |
function it_returns_empty_lines() | |
{ | |
$this->getSnippets("Hello\n\nWorld")->shouldBe(array( | |
"Hello\n", | |
"\n", | |
"World" | |
)); | |
} | |
function it_returns_trailing_new_lines() | |
{ | |
$this->getSnippets("Hello\nWorld\n")->shouldBe(array( | |
"Hello\n", | |
"World\n", | |
"" | |
)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment