Completed
Pull Request — master (#177)
by Ciaran
11:55 queued 01:37
created

TextLineTest::it_parses_textlines()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 9
rs 9.9666
c 0
b 0
f 0
cc 1
nc 1
nop 3
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
require_once('Asserts.php');
12
13
class TextLineTest extends \PHPUnit_Framework_TestCase
14
{
15
    use Asserts;
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->assertParse($expected, $parser, $input);
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