Completed
Pull Request — master (#177)
by Mathias
12:52
created

TextLineTest::examples()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 10
rs 9.9332
c 0
b 0
f 0
cc 1
nc 1
nop 0
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);
0 ignored issues
show
Bug introduced by
The method assertParses() does not exist on Tests\Behat\Parsica\TextLineTest. Did you maybe mean assertParse()?

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.

Loading history...
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