@@ -51,5 +51,135 @@ public function provideTestCases(): Generator
51
51
],
52
52
new Node \RootNode ('/ ' , [new Node \SubPattern ([new Node \LiteralCharacters ('ab ' )], true , new Node \SubPattern \Name ('?P< ' , 'foo ' ))], '' ),
53
53
];
54
+
55
+ yield 'Named back reference with \g{ notation ' => [
56
+ '/(?P<foo>ab)=\g{foo}/ ' ,
57
+ [
58
+ Token \Delimiter::create ('/ ' ),
59
+ Token \SubPattern \Start::create (),
60
+ Token \SubPattern \Named::fromName ('?P<foo> ' ),
61
+ Token \LiteralCharacters::create ('ab ' ),
62
+ Token \SubPattern \End::create (),
63
+ Token \LiteralCharacters::create ('= ' ),
64
+ Token \SubPattern \Reference::create ('g{foo} ' ),
65
+ Token \Delimiter::create ('/ ' ),
66
+ ],
67
+ new Node \RootNode ('/ ' , [
68
+ new Node \SubPattern (
69
+ [
70
+ new Node \LiteralCharacters ('ab ' ),
71
+ ],
72
+ true ,
73
+ new Node \SubPattern \Name ('?P< ' , 'foo ' )
74
+ ),
75
+ new Node \LiteralCharacters ('= ' ),
76
+ new Node \SubPattern \Reference ('\g{ ' , 'foo ' ),
77
+ ], '' ),
78
+ ['ab=ab ' ],
79
+ ];
80
+
81
+ yield 'Named back reference with \k{ notation ' => [
82
+ '/(?P<foo>ab)=\k{foo}/ ' ,
83
+ [
84
+ Token \Delimiter::create ('/ ' ),
85
+ Token \SubPattern \Start::create (),
86
+ Token \SubPattern \Named::fromName ('?P<foo> ' ),
87
+ Token \LiteralCharacters::create ('ab ' ),
88
+ Token \SubPattern \End::create (),
89
+ Token \LiteralCharacters::create ('= ' ),
90
+ Token \SubPattern \Reference::create ('k{foo} ' ),
91
+ Token \Delimiter::create ('/ ' ),
92
+ ],
93
+ new Node \RootNode ('/ ' , [
94
+ new Node \SubPattern (
95
+ [
96
+ new Node \LiteralCharacters ('ab ' ),
97
+ ],
98
+ true ,
99
+ new Node \SubPattern \Name ('?P< ' , 'foo ' )
100
+ ),
101
+ new Node \LiteralCharacters ('= ' ),
102
+ new Node \SubPattern \Reference ('\k{ ' , 'foo ' ),
103
+ ], '' ),
104
+ ['ab=ab ' ],
105
+ ];
106
+
107
+ yield 'Named back reference with \k \' notation ' => [
108
+ '/(?P<foo>ab)=\k \'foo \'/ ' ,
109
+ [
110
+ Token \Delimiter::create ('/ ' ),
111
+ Token \SubPattern \Start::create (),
112
+ Token \SubPattern \Named::fromName ('?P<foo> ' ),
113
+ Token \LiteralCharacters::create ('ab ' ),
114
+ Token \SubPattern \End::create (),
115
+ Token \LiteralCharacters::create ('= ' ),
116
+ Token \SubPattern \Reference::create ('k \'foo \'' ),
117
+ Token \Delimiter::create ('/ ' ),
118
+ ],
119
+ new Node \RootNode ('/ ' , [
120
+ new Node \SubPattern (
121
+ [
122
+ new Node \LiteralCharacters ('ab ' ),
123
+ ],
124
+ true ,
125
+ new Node \SubPattern \Name ('?P< ' , 'foo ' )
126
+ ),
127
+ new Node \LiteralCharacters ('= ' ),
128
+ new Node \SubPattern \Reference ('\k \'' , 'foo ' ),
129
+ ], '' ),
130
+ ['ab=ab ' ],
131
+ ];
132
+
133
+ yield 'Named back reference with \k< notation ' => [
134
+ '/(?P<foo>ab)=\k<foo>/ ' ,
135
+ [
136
+ Token \Delimiter::create ('/ ' ),
137
+ Token \SubPattern \Start::create (),
138
+ Token \SubPattern \Named::fromName ('?P<foo> ' ),
139
+ Token \LiteralCharacters::create ('ab ' ),
140
+ Token \SubPattern \End::create (),
141
+ Token \LiteralCharacters::create ('= ' ),
142
+ Token \SubPattern \Reference::create ('k<foo> ' ),
143
+ Token \Delimiter::create ('/ ' ),
144
+ ],
145
+ new Node \RootNode ('/ ' , [
146
+ new Node \SubPattern (
147
+ [
148
+ new Node \LiteralCharacters ('ab ' ),
149
+ ],
150
+ true ,
151
+ new Node \SubPattern \Name ('?P< ' , 'foo ' )
152
+ ),
153
+ new Node \LiteralCharacters ('= ' ),
154
+ new Node \SubPattern \Reference ('\k< ' , 'foo ' ),
155
+ ], '' ),
156
+ ['ab=ab ' ],
157
+ ];
158
+
159
+ yield 'Named back reference with (?P=) notation ' => [
160
+ '/(?P<foo>ab)=(?P=foo)/ ' ,
161
+ [
162
+ Token \Delimiter::create ('/ ' ),
163
+ Token \SubPattern \Start::create (),
164
+ Token \SubPattern \Named::fromName ('?P<foo> ' ),
165
+ Token \LiteralCharacters::create ('ab ' ),
166
+ Token \SubPattern \End::create (),
167
+ Token \LiteralCharacters::create ('= ' ),
168
+ Token \SubPattern \Reference::forPNotation ('?P=foo) ' ),
169
+ Token \Delimiter::create ('/ ' ),
170
+ ],
171
+ new Node \RootNode ('/ ' , [
172
+ new Node \SubPattern (
173
+ [
174
+ new Node \LiteralCharacters ('ab ' ),
175
+ ],
176
+ true ,
177
+ new Node \SubPattern \Name ('?P< ' , 'foo ' )
178
+ ),
179
+ new Node \LiteralCharacters ('= ' ),
180
+ new Node \SubPattern \Reference ('(?P= ' , 'foo ' ),
181
+ ], '' ),
182
+ ['ab=ab ' ],
183
+ ];
54
184
}
55
185
}
0 commit comments