| 1 |
<?php |
| 2 |
namespace ExecWithFallback\Tests; |
| 3 |
|
| 4 |
use PHPUnit\Framework\TestCase; |
| 5 |
|
| 6 |
class LineSplittingTest extends TestCase |
| 7 |
{ |
| 8 |
|
| 9 |
public function splitLines($text) |
| 10 |
{ |
| 11 |
//return preg_split('/\r\n|\r|\n/', $text); |
| 12 |
//return preg_split("/\\n\\r|\\r\\n|\\n|\\r/", $text); |
| 13 |
//return preg_split('/\n\r|\r\n|\n|\r/', $text); |
| 14 |
return preg_split('/\r\n|\n\r|\n|\r/', $text); |
| 15 |
} |
| 16 |
|
| 17 |
public function splitLinesNoEmpty($text) |
| 18 |
{ |
| 19 |
//return preg_split('/\r\n|\r|\n/', $text); |
| 20 |
//return preg_split("/\\n\\r|\\r\\n|\\n|\\r/", $text); |
| 21 |
//return preg_split('/\n\r|\r\n|\n|\r/', $text); |
| 22 |
return preg_split('/[\r\n]+/', $text); |
| 23 |
} |
| 24 |
|
| 25 |
|
| 26 |
public function testLineSplitting() |
| 27 |
{ |
| 28 |
$this->assertEquals(['one', 'two', 'three'], $this->splitLines("one\r\ntwo\r\nthree")); |
| 29 |
$this->assertEquals(['one', 'two', 'three'], $this->splitLines("one\ntwo\nthree")); |
| 30 |
$this->assertEquals(['one', 'two', 'three'], $this->splitLines("one\rtwo\rthree")); |
| 31 |
$this->assertEquals(['one', '', 'two', 'three'], $this->splitLines("one\n\ntwo\nthree")); |
| 32 |
$this->assertEquals(['one', '', 'two', '', 'three'], $this->splitLines("one\r\n\ntwo\n\r\nthree")); |
| 33 |
|
| 34 |
// the unusual \n\r sequence |
| 35 |
$this->assertEquals(['one', 'two', 'three'], $this->splitLines("one\n\rtwo\n\rthree")); |
| 36 |
$this->assertEquals(['one', '', 'two', '', 'three'], $this->splitLines("one\n\r\ntwo\n\n\rthree")); |
| 37 |
} |
| 38 |
|
| 39 |
public function testLineSplittingNoEmpty() |
| 40 |
{ |
| 41 |
$this->assertEquals(['one', 'two', 'three'], $this->splitLinesNoEmpty("one\r\ntwo\r\nthree")); |
| 42 |
$this->assertEquals(['one', 'two', 'three'], $this->splitLinesNoEmpty("one\ntwo\nthree")); |
| 43 |
$this->assertEquals(['one', 'two', 'three'], $this->splitLinesNoEmpty("one\rtwo\rthree")); |
| 44 |
$this->assertEquals(['one', 'two', 'three'], $this->splitLinesNoEmpty("one\n\ntwo\nthree")); |
| 45 |
$this->assertEquals(['one', 'two', 'three'], $this->splitLinesNoEmpty("one\r\n\ntwo\n\r\nthree")); |
| 46 |
|
| 47 |
// the unusual \n\r sequence |
| 48 |
$this->assertEquals(['one', 'two', 'three'], $this->splitLinesNoEmpty("one\n\rtwo\n\rthree")); |
| 49 |
$this->assertEquals(['one', 'two', 'three'], $this->splitLinesNoEmpty("one\n\r\ntwo\n\n\rthree")); |
| 50 |
} |
| 51 |
} |
| 52 |
|