-
Notifications
You must be signed in to change notification settings - Fork 152
Expand file tree
/
Copy pathParserStateTest.php
More file actions
100 lines (93 loc) · 3.24 KB
/
Copy pathParserStateTest.php
File metadata and controls
100 lines (93 loc) · 3.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
<?php
declare(strict_types=1);
namespace Sabberworm\CSS\Tests\Unit\Parsing;
use PHPUnit\Framework\TestCase;
use Sabberworm\CSS\Comment\Comment;
use Sabberworm\CSS\Parsing\ParserState;
use Sabberworm\CSS\Settings;
/**
* @covers \Sabberworm\CSS\Parsing\ParserState
*/
final class ParserStateTest extends TestCase
{
/**
* @return array<
* string,
* array{
* text: non-empty-string,
* stopCharacter: non-empty-string,
* expectedConsumedText: non-empty-string,
* expectedComments: non-empty-list<non-empty-string>
* }
* >
*/
public static function provideTextForConsumptionWithComments(): array
{
return [
'comment at start' => [
'text' => '/*comment*/hello{',
'stopCharacter' => '{',
'expectedConsumedText' => 'hello',
'expectedComments' => ['comment'],
],
'comment at end' => [
'text' => 'hello/*comment*/{',
'stopCharacter' => '{',
'expectedConsumedText' => 'hello',
'expectedComments' => ['comment'],
],
'comment in middle' => [
'text' => 'hell/*comment*/o{',
'stopCharacter' => '{',
'expectedConsumedText' => 'hello',
'expectedComments' => ['comment'],
],
'two comments at start' => [
'text' => '/*comment1*//*comment2*/hello{',
'stopCharacter' => '{',
'expectedConsumedText' => 'hello',
'expectedComments' => ['comment1', 'comment2'],
],
'two comments at end' => [
'text' => 'hello/*comment1*//*comment2*/{',
'stopCharacter' => '{',
'expectedConsumedText' => 'hello',
'expectedComments' => ['comment1', 'comment2'],
],
'two comments interspersed' => [
'text' => 'he/*comment1*/ll/*comment2*/o{',
'stopCharacter' => '{',
'expectedConsumedText' => 'hello',
'expectedComments' => ['comment1', 'comment2'],
],
];
}
/**
* @test
*
* @param non-empty-string $text
* @param non-empty-string $stopCharacter
* @param non-empty-string $expectedConsumedText
* @param non-empty-list<non-empty-string> $expectedComments
*
* @dataProvider provideTextForConsumptionWithComments
*/
public function consumeUntilExtractsComments(
string $text,
string $stopCharacter,
string $expectedConsumedText,
array $expectedComments
): void {
$subject = new ParserState($text, Settings::create());
$comments = [];
$result = $subject->consumeUntil($stopCharacter, false, false, $comments);
self::assertSame($expectedConsumedText, $result);
$commentsAsText = \array_map(
static function (Comment $comment): string {
return $comment->getComment();
},
$comments
);
self::assertSame($expectedComments, $commentsAsText);
}
}