1
|
|
|
<?php |
2
|
|
|
declare(strict_types=1); |
3
|
|
|
|
4
|
|
|
namespace Tests\Behat\Parsica; |
5
|
|
|
|
6
|
|
|
use Behat\Gherkin\Parsica\Asserts; |
7
|
|
|
use Behat\Parsica; |
8
|
|
|
use Verraes\Parsica\StringStream; |
9
|
|
|
use function Behat\Gherkin\Parsica\textLine; |
10
|
|
|
|
11
|
|
|
|
12
|
|
|
require_once('functions.php'); |
13
|
|
|
require_once('Asserts.php'); |
14
|
|
|
|
15
|
|
|
|
16
|
|
|
class TextLineTest extends \PHPUnit_Framework_TestCase |
17
|
|
|
{ |
18
|
|
|
use Asserts; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* @test |
22
|
|
|
* @dataProvider examples |
23
|
|
|
*/ |
24
|
|
|
public function it_parses_textlines(string $input, string $expected, string $expectedRemainder) |
25
|
|
|
{ |
26
|
|
|
$parser = textLine(); |
27
|
|
|
|
28
|
|
|
$this->assertParse($expected, $parser, $input); |
29
|
|
|
|
30
|
|
|
$remainder = (string)$parser->tryString($input)->remainder(); |
31
|
|
|
$this->assertEquals($expectedRemainder, $remainder); |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
public static function examples() : iterable |
35
|
|
|
{ |
36
|
|
|
yield 'empty' => ['', '', '']; |
37
|
|
|
yield 'without whitespace' => ['blah blah', 'blah blah', '']; |
38
|
|
|
yield 'whitespace only' => [" \t ", '', '']; |
39
|
|
|
yield 'leading whitespace' => [' blah blah', 'blah blah', '']; |
40
|
|
|
yield 'trailing whitespace' => ['blah blah ', 'blah blah', '']; |
41
|
|
|
yield 'with linebreak' => ["blah blah blah \t \n", "blah blah blah", '']; |
42
|
|
|
yield 'with linebreak and following text' => ["blah blah blah \t \nfoo", "blah blah blah", 'foo']; |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* @test |
47
|
|
|
* @dataProvider badExamples |
48
|
|
|
* @dataProvider notSupportedYetExamples |
49
|
|
|
*/ |
50
|
|
|
public function it_fails_on_bad_textlines(string $input) |
51
|
|
|
{ |
52
|
|
|
$parser = textLine(); |
53
|
|
|
|
54
|
|
|
$result = $parser->run(new StringStream($input)); |
55
|
|
|
|
56
|
|
|
$this->assertTrue($result->isFail()); |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
public static function badExamples() : iterable |
60
|
|
|
{ |
61
|
|
|
yield 'with null byte' => ["blah blah blah \0 "]; |
62
|
|
|
yield 'with vertical tab' => ["blah blah blah \x0B "]; |
63
|
|
|
yield 'with non-breaking space' => ["blah blah blah \xA0 "]; |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
/** @todo make this work */ |
67
|
|
|
public static function notSupportedYetExamples() : iterable |
68
|
|
|
{ |
69
|
|
|
yield 'with 🥰 and text' => ["blah 🥰 blah"]; |
70
|
|
|
} |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
|