4
4
5
5
use gapple \StructuredFields \ParsingInput ;
6
6
use PHPUnit \Framework \Attributes \DataProvider ;
7
+ use PHPUnit \Framework \Attributes \RequiresSetting ;
7
8
use PHPUnit \Framework \TestCase ;
8
9
9
10
class ParsingInputTest extends TestCase
@@ -21,6 +22,7 @@ public function testGetEmptyChar(): void
21
22
public static function trimProvider (): array
22
23
{
23
24
return [
25
+ // [input string, trim optional white space, expected remaining string]
24
26
'space ' => [' test ' , false , 'test ' ],
25
27
'ows ' => [" \t test " , true , 'test ' ],
26
28
'non-ows ' => [" \t test " , false , "\t test " ],
@@ -51,4 +53,37 @@ public function testConsumeNotMatched(): void
51
53
$ this ->expectExceptionMessage ('Unexpected character ' );
52
54
$ input ->consumeString ('foo ' );
53
55
}
56
+
57
+ /**
58
+ * @return array<string, array{string, bool}>
59
+ */
60
+ public static function regexProvider (): array
61
+ {
62
+ return [
63
+ 'Valid ' => ['/^test/ ' , true ],
64
+ 'Valid with modifier ' => ['/^test/i ' , true ],
65
+ 'Missing start anchor ' => ['/test/ ' , false ],
66
+ 'End anchor ' => ['/test$/ ' , false ],
67
+ 'End anchor and modifier ' => ['/test$/i ' , false ],
68
+ ];
69
+ }
70
+
71
+ #[RequiresSetting('zend.assertions ' , '1 ' )]
72
+ #[DataProvider('regexProvider ' )]
73
+ public function testConsumeRegex (string $ regex , bool $ expected ): void
74
+ {
75
+ try {
76
+ $ input = new ParsingInput ('test ' );
77
+ $ input ->consumeRegex ($ regex );
78
+
79
+ if (!$ expected ) {
80
+ $ this ->fail ('Expression should not have passed assertions ' );
81
+ }
82
+ } catch (\AssertionError $ e ) {
83
+ if ($ expected ) {
84
+ $ this ->fail ('Expression failed assertion: ' . $ e ->getMessage ());
85
+ }
86
+ }
87
+ $ this ->addToAssertionCount (1 );
88
+ }
54
89
}
0 commit comments