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 PHPUnit\Framework\TestCase; |
9
|
|
|
use Verraes\Parsica\PHPUnit\ParserAssertions; |
10
|
|
|
use Verraes\Parsica\StringStream; |
11
|
|
|
use function Behat\Gherkin\Parsica\textLine; |
12
|
|
|
|
13
|
|
|
class TextLineTest extends TestCase |
14
|
|
|
{ |
15
|
|
|
use ParserAssertions; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* @test |
19
|
|
|
* @dataProvider examples |
20
|
|
|
*/ |
21
|
|
|
public function it_parses_textlines(string $input, string $expected, string $expectedRemainder) |
22
|
|
|
{ |
23
|
|
|
$parser = textLine(); |
24
|
|
|
|
25
|
|
|
$this->assertParses($input, $parser, $expected); |
|
|
|
|
26
|
|
|
|
27
|
|
|
$remainder = (string)$parser->tryString($input)->remainder(); |
28
|
|
|
$this->assertEquals($expectedRemainder, $remainder); |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
public static function examples() : iterable |
32
|
|
|
{ |
33
|
|
|
yield 'empty' => ['', '', '']; |
34
|
|
|
yield 'without whitespace' => ['blah blah', 'blah blah', '']; |
35
|
|
|
yield 'whitespace only' => [" \t ", '', '']; |
36
|
|
|
yield 'leading whitespace' => [' blah blah', 'blah blah', '']; |
37
|
|
|
yield 'trailing whitespace' => ['blah blah ', 'blah blah', '']; |
38
|
|
|
yield 'with linebreak' => ["blah blah blah \t \n", "blah blah blah", '']; |
39
|
|
|
yield 'with linebreak and following text' => ["blah blah blah \t \nfoo", "blah blah blah", 'foo']; |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* @test |
44
|
|
|
* @dataProvider badExamples |
45
|
|
|
* @dataProvider notSupportedYetExamples |
46
|
|
|
*/ |
47
|
|
|
public function it_fails_on_bad_textlines(string $input) |
48
|
|
|
{ |
49
|
|
|
$parser = textLine(); |
50
|
|
|
|
51
|
|
|
$result = $parser->run(new StringStream($input)); |
52
|
|
|
|
53
|
|
|
$this->assertTrue($result->isFail()); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
public static function badExamples() : iterable |
57
|
|
|
{ |
58
|
|
|
yield 'with null byte' => ["blah blah blah \0 "]; |
59
|
|
|
yield 'with vertical tab' => ["blah blah blah \x0B "]; |
60
|
|
|
yield 'with non-breaking space' => ["blah blah blah \xA0 "]; |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
/** @todo make this work */ |
64
|
|
|
public static function notSupportedYetExamples() : iterable |
65
|
|
|
{ |
66
|
|
|
yield 'with 🥰 and text' => ["blah 🥰 blah"]; |
67
|
|
|
} |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
|
This check marks calls to methods that do not seem to exist on an object.
This is most likely the result of a method being renamed without all references to it being renamed likewise.