@@ -110,7 +110,7 @@ public partial class RegexParserTests
110
110
[ InlineData ( @"(?P<a>.)(?P<a>.)" , RegexOptions . None , RegexParseError . InvalidGroupingConstruct , 3 ) ]
111
111
[ InlineData ( @"[a-\A]" , RegexOptions . None , RegexParseError . UnrecognizedEscape , 5 ) ]
112
112
[ InlineData ( @"[a-\z]" , RegexOptions . None , RegexParseError . UnrecognizedEscape , 5 ) ]
113
- [ InlineData ( @"[a-\b]" , RegexOptions . None , RegexParseError . ReversedCharacterRange , 5 ) ]
113
+ [ InlineData ( @"[a-\b]" , RegexOptions . None , RegexParseError . ReversedCharacterRange , 5 ) ] // Nim: not an error
114
114
[ InlineData ( @"[a-\-]" , RegexOptions . None , RegexParseError . ReversedCharacterRange , 5 ) ]
115
115
[ InlineData ( @"[a-\-b]" , RegexOptions . None , RegexParseError . ReversedCharacterRange , 5 ) ]
116
116
[ InlineData ( @"[a-\-\-b]" , RegexOptions . None , RegexParseError . ReversedCharacterRange , 5 ) ]
@@ -127,6 +127,115 @@ public partial class RegexParserTests
127
127
[ InlineData ( @"[a-[:lower:]]" , RegexOptions . None , null ) ] // errors in rust: range_end_no_class
128
128
// End of Rust parser tests ==============
129
129
130
+ // Following are borrowed from Nim tests
131
+ // https://github.com/nitely/nim-regex/blob/eeefb4f51264ff3bc3b36caf55672a74f52f5ef5/tests/tests.nim
132
+ [ InlineData ( @"?" , RegexOptions . None , RegexParseError . QuantifierAfterNothing , 1 ) ]
133
+ [ InlineData ( @"?|?" , RegexOptions . None , RegexParseError . QuantifierAfterNothing , 1 ) ]
134
+ [ InlineData ( @"?abc" , RegexOptions . None , RegexParseError . QuantifierAfterNothing , 1 ) ]
135
+ [ InlineData ( @"(?P<abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-_>abc" , RegexOptions . None , RegexParseError . InvalidGroupingConstruct , 3 ) ] // Nim: not an error
136
+ [ InlineData ( @"(?Pabc" , RegexOptions . None , RegexParseError . InvalidGroupingConstruct , 3 ) ]
137
+ [ InlineData ( @"(?u-q)" , RegexOptions . None , RegexParseError . InvalidGroupingConstruct , 3 ) ]
138
+ [ InlineData ( @"(?uq)" , RegexOptions . None , RegexParseError . InvalidGroupingConstruct , 3 ) ]
139
+ [ InlineData ( @"(\b)" , RegexOptions . None , null ) ]
140
+ [ InlineData ( @"(+)" , RegexOptions . None , RegexParseError . QuantifierAfterNothing , 2 ) ]
141
+ [ InlineData ( @"(a)b)" , RegexOptions . None , RegexParseError . InsufficientOpeningParentheses , 5 ) ]
142
+ [ InlineData ( @"(b(a)" , RegexOptions . None , RegexParseError . InsufficientClosingParentheses , 5 ) ]
143
+ [ InlineData ( @"[-" , RegexOptions . None , RegexParseError . UnterminatedBracket , 2 ) ]
144
+ [ InlineData ( @"[-a" , RegexOptions . None , RegexParseError . UnterminatedBracket , 3 ) ]
145
+ [ InlineData ( @"[[:abc:]]" , RegexOptions . None , null ) ] // Nim: "Invalid ascii set. `abc` is not a valid name"
146
+ [ InlineData ( @"[[:alnum:" , RegexOptions . None , RegexParseError . UnterminatedBracket , 9 ) ]
147
+ [ InlineData ( @"[[:alnum]]" , RegexOptions . None , null ) ] // Nim: "Invalid ascii set. Expected [:name:]"
148
+ [ InlineData ( @"[]" , RegexOptions . None , RegexParseError . UnterminatedBracket , 2 ) ]
149
+ [ InlineData ( @"[]a" , RegexOptions . None , RegexParseError . UnterminatedBracket , 3 ) ]
150
+ [ InlineData ( @"[]abc" , RegexOptions . None , RegexParseError . UnterminatedBracket , 5 ) ]
151
+ [ InlineData ( @"[\\" , RegexOptions . None , RegexParseError . UnterminatedBracket , 3 ) ]
152
+ [ InlineData ( @"[^]" , RegexOptions . None , RegexParseError . UnterminatedBracket , 3 ) ]
153
+ [ InlineData ( @"[a-" , RegexOptions . None , RegexParseError . UnterminatedBracket , 3 ) ]
154
+ [ InlineData ( @"[a-\w]" , RegexOptions . None , RegexParseError . ShorthandClassInCharacterRange , 5 ) ]
155
+ [ InlineData ( @"[a" , RegexOptions . None , RegexParseError . UnterminatedBracket , 2 ) ]
156
+ [ InlineData ( @"[abc" , RegexOptions . None , RegexParseError . UnterminatedBracket , 4 ) ]
157
+ [ InlineData ( @"[d-c]" , RegexOptions . None , RegexParseError . ReversedCharacterRange , 4 ) ]
158
+ [ InlineData ( @"[z-[:alnum:]]" , RegexOptions . None , null ) ] // Nim: "Invalid set range. Start must be lesser than end"
159
+ [ InlineData ( @"{10}" , RegexOptions . None , RegexParseError . QuantifierAfterNothing , 1 ) ]
160
+ [ InlineData ( @"*abc" , RegexOptions . None , RegexParseError . QuantifierAfterNothing , 1 ) ]
161
+ [ InlineData ( @"\12" , RegexOptions . None , null ) ] // Nim: "Invalid octal literal. Expected 3 octal digits, but found 2"
162
+ [ InlineData ( @"\12@" , RegexOptions . None , null ) ] // Nim: "Invalid octal literal. Expected octal digit, but found @"
163
+ [ InlineData ( @"\b?" , RegexOptions . None , null ) ]
164
+ [ InlineData ( @"\b*" , RegexOptions . None , null ) ]
165
+ [ InlineData ( @"\b+" , RegexOptions . None , null ) ]
166
+ [ InlineData ( @"\p{11" , RegexOptions . None , RegexParseError . InvalidUnicodePropertyEscape , 5 ) ]
167
+ [ InlineData ( @"\p{11}" , RegexOptions . None , RegexParseError . UnrecognizedUnicodeProperty , 6 ) ]
168
+ [ InlineData ( @"\p{Bb}" , RegexOptions . None , RegexParseError . UnrecognizedUnicodeProperty , 6 ) ]
169
+ [ InlineData ( @"\p11" , RegexOptions . None , RegexParseError . InvalidUnicodePropertyEscape , 2 ) ]
170
+ [ InlineData ( @"\pB" , RegexOptions . None , RegexParseError . InvalidUnicodePropertyEscape , 2 ) ]
171
+ [ InlineData ( @"\u123" , RegexOptions . None , RegexParseError . InsufficientOrInvalidHexDigits , 2 ) ]
172
+ [ InlineData ( @"\U123" , RegexOptions . None , RegexParseError . UnrecognizedEscape , 2 ) ]
173
+ [ InlineData ( @"\U123@a" , RegexOptions . None , RegexParseError . UnrecognizedEscape , 2 ) ]
174
+ [ InlineData ( @"\u123@abc" , RegexOptions . None , RegexParseError . InsufficientOrInvalidHexDigits , 6 ) ]
175
+ [ InlineData ( @"\UFFFFFFFF" , RegexOptions . None , RegexParseError . UnrecognizedEscape , 2 ) ]
176
+ [ InlineData ( @"\x{00000000A}" , RegexOptions . None , RegexParseError . InsufficientOrInvalidHexDigits , 3 ) ]
177
+ [ InlineData ( @"\x{2f894" , RegexOptions . None , RegexParseError . InsufficientOrInvalidHexDigits , 3 ) ]
178
+ [ InlineData ( @"\x{61@}" , RegexOptions . None , RegexParseError . InsufficientOrInvalidHexDigits , 3 ) ]
179
+ [ InlineData ( @"\x{7fffffff}" , RegexOptions . None , RegexParseError . InsufficientOrInvalidHexDigits , 3 ) ] // Nim: not an error (supports Unicode beyond basic multilingual plane)
180
+ [ InlineData ( @"\x{FFFFFFFF}" , RegexOptions . None , RegexParseError . InsufficientOrInvalidHexDigits , 3 ) ]
181
+ [ InlineData ( @"+" , RegexOptions . None , RegexParseError . QuantifierAfterNothing , 1 ) ]
182
+ [ InlineData ( @"+abc" , RegexOptions . None , RegexParseError . QuantifierAfterNothing , 1 ) ]
183
+ [ InlineData ( @"a???" , RegexOptions . None , RegexParseError . NestedQuantifiersNotParenthesized , 4 ) ]
184
+ [ InlineData ( @"a??*" , RegexOptions . None , RegexParseError . NestedQuantifiersNotParenthesized , 4 ) ]
185
+ [ InlineData ( @"a??+" , RegexOptions . None , RegexParseError . NestedQuantifiersNotParenthesized , 4 ) ]
186
+ [ InlineData ( @"a?*" , RegexOptions . None , RegexParseError . NestedQuantifiersNotParenthesized , 3 ) ]
187
+ [ InlineData ( @"a?+" , RegexOptions . None , RegexParseError . NestedQuantifiersNotParenthesized , 3 ) ]
188
+ [ InlineData ( @"a(?P<>abc)" , RegexOptions . None , RegexParseError . InvalidGroupingConstruct , 4 ) ]
189
+ [ InlineData ( @"a(?P<asd)" , RegexOptions . None , RegexParseError . InvalidGroupingConstruct , 4 ) ]
190
+ [ InlineData ( @"a{,}" , RegexOptions . None , null ) ] // Nim error
191
+ [ InlineData ( @"a{,1}" , RegexOptions . None , null ) ] // Nim error
192
+ [ InlineData ( @"a{0,101}" , RegexOptions . None , null ) ] // Nim error: "Invalid repetition range. Expected 100 repetitions or less, but found: 101"
193
+ [ InlineData ( @"a{0,a}" , RegexOptions . None , null ) ] // Nim error
194
+ [ InlineData ( @"a{0,bad}" , RegexOptions . None , null ) ] // Nim error: "Invalid repetition range. Range can only contain digits"
195
+ [ InlineData ( @"a{1,,,2}" , RegexOptions . None , null ) ] // Nim error
196
+ [ InlineData ( @"a{1,,}" , RegexOptions . None , null ) ] // Nim error
197
+ [ InlineData ( @"a{1,,2}" , RegexOptions . None , null ) ] // Nim error
198
+ [ InlineData ( @"a{1," , RegexOptions . None , null ) ] // Nim error
199
+ [ InlineData ( @"a{1,}??" , RegexOptions . None , RegexParseError . NestedQuantifiersNotParenthesized , 7 ) ]
200
+ [ InlineData ( @"a{1,}?" , RegexOptions . None , null ) ]
201
+ [ InlineData ( @"a{1,}*" , RegexOptions . None , RegexParseError . NestedQuantifiersNotParenthesized , 6 ) ]
202
+ [ InlineData ( @"a{1,}+" , RegexOptions . None , RegexParseError . NestedQuantifiersNotParenthesized , 6 ) ]
203
+ [ InlineData ( @"a{1,101}" , RegexOptions . None , null ) ]
204
+ [ InlineData ( @"a{1,x}" , RegexOptions . None , null ) ] // Nim error
205
+ [ InlineData ( @"a{1" , RegexOptions . None , null ) ] // Nim error
206
+ [ InlineData ( @"a{1}??" , RegexOptions . None , RegexParseError . NestedQuantifiersNotParenthesized , 6 ) ]
207
+ [ InlineData ( @"a{1}?" , RegexOptions . None , null ) ]
208
+ [ InlineData ( @"a{1}*" , RegexOptions . None , RegexParseError . NestedQuantifiersNotParenthesized , 5 ) ]
209
+ [ InlineData ( @"a{1}+" , RegexOptions . None , RegexParseError . NestedQuantifiersNotParenthesized , 5 ) ]
210
+ [ InlineData ( @"a{1111111111}" , RegexOptions . None , null ) ] // Nim error: "Invalid repetition range. Max value is 32767."
211
+ [ InlineData ( @"a{1x}" , RegexOptions . None , null ) ] // Nim error
212
+ [ InlineData ( @"a*??" , RegexOptions . None , RegexParseError . NestedQuantifiersNotParenthesized , 4 ) ]
213
+ [ InlineData ( @"a*{,}" , RegexOptions . None , null ) ] // Nim error
214
+ [ InlineData ( @"a*{0}" , RegexOptions . None , RegexParseError . NestedQuantifiersNotParenthesized , 3 ) ]
215
+ [ InlineData ( @"a*{1}" , RegexOptions . None , RegexParseError . NestedQuantifiersNotParenthesized , 3 ) ]
216
+ [ InlineData ( @"a**" , RegexOptions . None , RegexParseError . NestedQuantifiersNotParenthesized , 3 ) ]
217
+ [ InlineData ( @"a*****" , RegexOptions . None , RegexParseError . NestedQuantifiersNotParenthesized , 3 ) ]
218
+ [ InlineData ( @"a*+" , RegexOptions . None , RegexParseError . NestedQuantifiersNotParenthesized , 3 ) ]
219
+ [ InlineData ( @"a+??" , RegexOptions . None , RegexParseError . NestedQuantifiersNotParenthesized , 4 ) ]
220
+ [ InlineData ( @"a+*" , RegexOptions . None , RegexParseError . NestedQuantifiersNotParenthesized , 3 ) ]
221
+ [ InlineData ( @"a++" , RegexOptions . None , RegexParseError . NestedQuantifiersNotParenthesized , 3 ) ]
222
+ [ InlineData ( @"a|?" , RegexOptions . None , RegexParseError . QuantifierAfterNothing , 3 ) ]
223
+ [ InlineData ( @"a|?b" , RegexOptions . None , RegexParseError . QuantifierAfterNothing , 3 ) ]
224
+ [ InlineData ( @"a|*" , RegexOptions . None , RegexParseError . QuantifierAfterNothing , 3 ) ]
225
+ [ InlineData ( @"a|*b" , RegexOptions . None , RegexParseError . QuantifierAfterNothing , 3 ) ]
226
+ [ InlineData ( @"a|+" , RegexOptions . None , RegexParseError . QuantifierAfterNothing , 3 ) ]
227
+ [ InlineData ( @"a|+b" , RegexOptions . None , RegexParseError . QuantifierAfterNothing , 3 ) ]
228
+ [ InlineData ( @"aaa(?Pabc" , RegexOptions . None , RegexParseError . InvalidGroupingConstruct , 6 ) ]
229
+ [ InlineData ( @"abc(?P<abc" , RegexOptions . None , RegexParseError . InvalidGroupingConstruct , 6 ) ]
230
+ [ InlineData ( @"abc(?Pabc)" , RegexOptions . None , RegexParseError . InvalidGroupingConstruct , 6 ) ]
231
+ [ InlineData ( @"abc(?q)" , RegexOptions . None , RegexParseError . InvalidGroupingConstruct , 6 ) ]
232
+ [ InlineData ( @"abc[]" , RegexOptions . None , RegexParseError . UnterminatedBracket , 5 ) ]
233
+ [ InlineData ( @"abc\A{10}" , RegexOptions . None , null ) ] // Nim error: "Invalid repetition range, either char, shorthand (i.e: \\w), group, or set expected before repetition range"
234
+ [ InlineData ( @"\uD87E\uDC94(?Pabc" , RegexOptions . None , RegexParseError . InvalidGroupingConstruct , 15 ) ]
235
+ [ InlineData ( @"\uD87E\uDC94aaa(?Pabc" , RegexOptions . None , RegexParseError . InvalidGroupingConstruct , 18 ) ]
236
+ [ InlineData ( @"\uD87E\uDC94\uD87E\uDC94\uD87E\uDC94(?Pabc" , RegexOptions . None , RegexParseError . InvalidGroupingConstruct , 39 ) ]
237
+ // End of Nim parser tests ==============
238
+
130
239
[ SkipOnTargetFramework ( TargetFrameworkMonikers . NetFramework ) ]
131
240
public void Parse_Netcoreapp ( string pattern , RegexOptions options , RegexParseError ? error , int offset = - 1 )
132
241
{
@@ -157,7 +266,7 @@ public void RegexParseException_Serializes()
157
266
/// </summary>
158
267
/// <param name="error">The expected parse error</param>
159
268
/// <param name="action">The action to invoke.</param>
160
- static partial void Throws ( RegexParseError error , int offset , Action action )
269
+ static partial void Throws ( string pattern , RegexOptions options , RegexParseError error , int offset , Action action )
161
270
{
162
271
try
163
272
{
@@ -171,16 +280,19 @@ static partial void Throws(RegexParseError error, int offset, Action action)
171
280
if ( error == regexParseError )
172
281
{
173
282
Assert . Equal ( offset , e . Offset ) ;
283
+ LogActual ( pattern , options , regexParseError , e . Offset ) ;
174
284
return ;
175
285
}
176
286
287
+ LogActual ( pattern , options , regexParseError , e . Offset ) ;
177
288
throw new XunitException ( $ "Expected RegexParseException with error { error } offset { offset } -> Actual error: { regexParseError } offset { e . Offset } )") ;
178
289
}
179
290
catch ( Exception e )
180
291
{
181
- throw new XunitException ( $ "Expected RegexParseException -> Actual: ({ e } )") ;
292
+ throw new XunitException ( $ "Expected RegexParseException for pattern ' { pattern } ' -> Actual: ({ e } )") ;
182
293
}
183
294
295
+ LogActual ( pattern , options , RegexParseError . Unknown , - 1 ) ;
184
296
throw new XunitException ( $ "Expected RegexParseException with error: ({ error } ) -> Actual: No exception thrown") ;
185
297
}
186
298
0 commit comments