Skip to content

Instantly share code, notes, and snippets.

@wouterj
Created January 6, 2014 10:01
Show Gist options
  • Save wouterj/8280619 to your computer and use it in GitHub Desktop.
Save wouterj/8280619 to your computer and use it in GitHub Desktop.
<?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;
}
}
<?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