Welcome to mirror list, hosted at ThFree Co, Russian Federation.

RegexParserTests.cs « tests « System.Text.RegularExpressions « libraries « src - github.com/dotnet/runtime.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: fde04d1e05c26213e64e9a5fd9917da22ff210f2 (plain)
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using System.IO;
using System.Reflection;
using System.Runtime.Serialization.Formatters.Binary;
using Xunit;
using Xunit.Sdk;

namespace System.Text.RegularExpressions.Tests
{
    public class RegexParserTests
    {
        private static readonly Type s_parseExceptionType;
        private static readonly FieldInfo s_parseErrorField;

        static RegexParserTests()
        {
            if (!PlatformDetection.IsNetFramework)
            {
                s_parseExceptionType = typeof(Regex).Assembly.GetType("System.Text.RegularExpressions.RegexParseException", true);
                s_parseErrorField = s_parseExceptionType.GetField("_error", BindingFlags.NonPublic | BindingFlags.Instance);
            }
        }

        [Theory]
        // Basic
        [InlineData("", RegexOptions.None, null)]
        [InlineData(" ", RegexOptions.IgnorePatternWhitespace, null)]
        [InlineData("  ", RegexOptions.IgnorePatternWhitespace, null)]
        [InlineData("(?#)", RegexOptions.None, null)]
        [InlineData("(?# )", RegexOptions.None, null)]
        [InlineData("(?#", RegexOptions.None, RegexParseError.UnterminatedComment)]
        [InlineData("(?# ", RegexOptions.None, RegexParseError.UnterminatedComment)]
        [InlineData("(?#)(?#)", RegexOptions.None, null)]
        [InlineData("(?#)(?#)", RegexOptions.IgnorePatternWhitespace, null)]
        [InlineData("(?#) (?#)", RegexOptions.None, null)]
        [InlineData("(?#) (?#)", RegexOptions.IgnorePatternWhitespace, null)]
        [InlineData(@"[a\p{Lu}(?#)b]", RegexOptions.None, null)]
        [InlineData(@"[a\0(?#)b]", RegexOptions.None, null)]
        [InlineData(@"[a\a(?#)b]", RegexOptions.None, null)]
        [InlineData(@"[a\x00(?#)b]", RegexOptions.None, null)]
        [InlineData(@"[a\u0000(?#)b]", RegexOptions.None, null)]
        [InlineData(@"[a\](?#)b]", RegexOptions.None, null)]
        [InlineData("(?", RegexOptions.None, RegexParseError.UnrecognizedGrouping)]
        [InlineData("(?", RegexOptions.IgnorePatternWhitespace, RegexParseError.UnrecognizedGrouping)]
        [InlineData("(? ", RegexOptions.None, RegexParseError.UnrecognizedGrouping)]
        [InlineData("(? ", RegexOptions.IgnorePatternWhitespace, RegexParseError.UnrecognizedGrouping)]
        [InlineData("(?i)", RegexOptions.None, null)]
        [InlineData("(?im)", RegexOptions.None, null)]
        [InlineData("(?im-x)", RegexOptions.None, null)]
        [InlineData("(?im-x+n)", RegexOptions.None, null)]
        [InlineData("(?i) ", RegexOptions.None, null)]
        [InlineData("(?x) ", RegexOptions.None, null)]
        [InlineData(" (?x) ", RegexOptions.None, null)]
        [InlineData(" (?-x) ", RegexOptions.IgnorePatternWhitespace, null)]
        [InlineData(" ( (?-x) ) ", RegexOptions.IgnorePatternWhitespace, null)]
        [InlineData(" (?-x:) ", RegexOptions.IgnorePatternWhitespace, null)]
        [InlineData(" (?-x: ) ", RegexOptions.IgnorePatternWhitespace, null)]
        [InlineData(" (?-x: (?+x: ) ) ", RegexOptions.IgnorePatternWhitespace, null)]
        [InlineData("(?-x", RegexOptions.IgnorePatternWhitespace, RegexParseError.UnrecognizedGrouping)]
        [InlineData("(?-x ", RegexOptions.IgnorePatternWhitespace, RegexParseError.UnrecognizedGrouping)]
        [InlineData("(?-x :", RegexOptions.IgnorePatternWhitespace, RegexParseError.UnrecognizedGrouping)]
        [InlineData("(?-x )", RegexOptions.IgnorePatternWhitespace, RegexParseError.UnrecognizedGrouping)]
        [InlineData("(?-x :)", RegexOptions.IgnorePatternWhitespace, RegexParseError.UnrecognizedGrouping)]
        [InlineData(")", RegexOptions.None, RegexParseError.TooManyParentheses)]
        [InlineData("a", RegexOptions.None, null)]
        [InlineData("ab", RegexOptions.None, null)]
        [InlineData("a*", RegexOptions.None, null)]
        [InlineData("a*?", RegexOptions.None, null)]
        [InlineData("a+", RegexOptions.None, null)]
        [InlineData("a+?", RegexOptions.None, null)]
        [InlineData("a?", RegexOptions.None, null)]
        [InlineData("a??", RegexOptions.None, null)]
        [InlineData("()", RegexOptions.None, null)]
        [InlineData("(a)", RegexOptions.None, null)]
        [InlineData("(", RegexOptions.None, RegexParseError.NotEnoughParentheses)]
        [InlineData("(a", RegexOptions.None, RegexParseError.NotEnoughParentheses)]
        [InlineData("|", RegexOptions.None, null)]
        [InlineData(" |", RegexOptions.None, null)]
        [InlineData("| ", RegexOptions.None, null)]
        [InlineData(" | ", RegexOptions.None, null)]
        [InlineData("|", RegexOptions.IgnorePatternWhitespace, null)]
        [InlineData(" |", RegexOptions.IgnorePatternWhitespace, null)]
        [InlineData("| ", RegexOptions.IgnorePatternWhitespace, null)]
        [InlineData(" | ", RegexOptions.IgnorePatternWhitespace, null)]
        [InlineData("||", RegexOptions.None, null)]
        [InlineData("(|)", RegexOptions.None, null)]
        [InlineData("a{0}", RegexOptions.None, null)]
        [InlineData("a{0,}", RegexOptions.None, null)]
        [InlineData("a{0,1}", RegexOptions.None, null)]
        [InlineData("a{1,0}", RegexOptions.None, RegexParseError.IllegalRange)]
        [InlineData("a{0}?", RegexOptions.None, null)]
        [InlineData("a{0,}?", RegexOptions.None, null)]
        [InlineData("a{0,1}?", RegexOptions.None, null)]
        [InlineData("a{", RegexOptions.None, null)]
        [InlineData("a{0", RegexOptions.None, null)]
        [InlineData("a{0,", RegexOptions.None, null)]
        [InlineData("a{0,1", RegexOptions.None, null)]
        [InlineData("a{0 }", RegexOptions.IgnorePatternWhitespace, null)]
        [InlineData("a{0, }", RegexOptions.IgnorePatternWhitespace, null)]
        [InlineData("a{0 ,}", RegexOptions.IgnorePatternWhitespace, null)]
        [InlineData("a{0 ,1}", RegexOptions.IgnorePatternWhitespace, null)]
        [InlineData("a{0, 1}", RegexOptions.IgnorePatternWhitespace, null)]
        [InlineData("a{0,1 }", RegexOptions.IgnorePatternWhitespace, null)]
        [InlineData("a* ?", RegexOptions.IgnorePatternWhitespace, null)]
        [InlineData("a* ?", RegexOptions.None, null)]
        [InlineData("*", RegexOptions.None, RegexParseError.QuantifyAfterNothing)]
        [InlineData("(*)", RegexOptions.None, RegexParseError.QuantifyAfterNothing)]
        [InlineData("a**", RegexOptions.None, RegexParseError.NestedQuantify)]
        [InlineData("+", RegexOptions.None, RegexParseError.QuantifyAfterNothing)]
        [InlineData("(+)", RegexOptions.None, RegexParseError.QuantifyAfterNothing)]
        [InlineData("a*+", RegexOptions.None, RegexParseError.NestedQuantify)]
        [InlineData("?", RegexOptions.None, RegexParseError.QuantifyAfterNothing)]
        [InlineData("(?)", RegexOptions.None, RegexParseError.QuantifyAfterNothing)]
        [InlineData("a*??", RegexOptions.None, RegexParseError.NestedQuantify)]
        [InlineData("{0}", RegexOptions.None, RegexParseError.QuantifyAfterNothing)]
        [InlineData("({0})", RegexOptions.None, RegexParseError.QuantifyAfterNothing)]
        [InlineData("a*{0}", RegexOptions.None, RegexParseError.NestedQuantify)]
        [InlineData("{0", RegexOptions.None, null)]
        [InlineData("({0)", RegexOptions.None, null)]
        [InlineData("a*{0", RegexOptions.None, null)]
        [InlineData(@"\w", RegexOptions.None, null)]
        [InlineData(@"\b\B\A\G\Z\z\w\W\s\W\s\S\d\D", RegexOptions.None, null)]
        [InlineData(@"\c", RegexOptions.None, RegexParseError.MissingControl)]
        [InlineData(@"\c<", RegexOptions.None, RegexParseError.UnrecognizedControl)]
        [InlineData(@"\ca", RegexOptions.None, null)]
        [InlineData(@"\cA", RegexOptions.None, null)]
        [InlineData(@"\c A", RegexOptions.None, RegexParseError.UnrecognizedControl)]
        [InlineData(@"\c(a)", RegexOptions.None, RegexParseError.UnrecognizedControl)]
        [InlineData(@"\c>", RegexOptions.None, RegexParseError.UnrecognizedControl)]
        [InlineData(@"\c?", RegexOptions.None, RegexParseError.UnrecognizedControl)]
        [InlineData(@"\c@", RegexOptions.None, null)]
        [InlineData(@"\c^", RegexOptions.None, null)]
        [InlineData(@"\c_", RegexOptions.None, null)]
        [InlineData(@"\c`", RegexOptions.None, RegexParseError.UnrecognizedControl)]
        [InlineData(@"\c{", RegexOptions.None, RegexParseError.UnrecognizedControl)]
        [InlineData(@"\cz", RegexOptions.None, null)]
        [InlineData(@"\cZ", RegexOptions.None, null)]
        [InlineData(@"\m", RegexOptions.None, RegexParseError.UnrecognizedEscape)]
        [InlineData(@"\x", RegexOptions.None, RegexParseError.TooFewHex)]
        [InlineData(@"\x ", RegexOptions.None, RegexParseError.TooFewHex)]
        [InlineData(@"\x0", RegexOptions.None, RegexParseError.TooFewHex)]
        [InlineData(@"\x0 ", RegexOptions.None, RegexParseError.TooFewHex)]
        [InlineData(@"\x00", RegexOptions.None, null)]
        [InlineData(@"\x00 ", RegexOptions.None, null)]
        [InlineData(@"\x000", RegexOptions.None, null)]
        [InlineData(@"\xff", RegexOptions.None, null)]
        [InlineData(@"\xFF", RegexOptions.None, null)]
        [InlineData(@"\xfF", RegexOptions.None, null)]
        [InlineData(@"\xfff", RegexOptions.None, null)]
        [InlineData(@"\xgg", RegexOptions.None, RegexParseError.TooFewHex)]
        [InlineData(@"\m ", RegexOptions.None, RegexParseError.UnrecognizedEscape)]
        [InlineData(@"\u", RegexOptions.None, RegexParseError.TooFewHex)]
        [InlineData(@"\u0", RegexOptions.None, RegexParseError.TooFewHex)]
        [InlineData(@"\u00", RegexOptions.None, RegexParseError.TooFewHex)]
        [InlineData(@"\u000", RegexOptions.None, RegexParseError.TooFewHex)]
        [InlineData(@"\u0000", RegexOptions.None, null)]
        [InlineData(@"\u0000 ", RegexOptions.None, null)]
        [InlineData(@"\u ", RegexOptions.None, RegexParseError.TooFewHex)]
        [InlineData(@"\u0 ", RegexOptions.None, RegexParseError.TooFewHex)]
        [InlineData(@"\ugggg", RegexOptions.None, RegexParseError.TooFewHex)]
        [InlineData(@"\0", RegexOptions.None, null)]
        [InlineData(@"\0 ", RegexOptions.None, null)]
        [InlineData(@"\00", RegexOptions.None, null)]
        [InlineData(@"\00 ", RegexOptions.None, null)]
        [InlineData(@"\000", RegexOptions.None, null)]
        [InlineData(@"\000 ", RegexOptions.None, null)]
        [InlineData(@"\0000", RegexOptions.None, null)]
        [InlineData(@"\0000 ", RegexOptions.None, null)]
        [InlineData(@"\7", RegexOptions.None, RegexParseError.UndefinedBackref)]
        [InlineData(@"\78", RegexOptions.None, null)]
        [InlineData(@"\8", RegexOptions.None, RegexParseError.UndefinedBackref)]
        [InlineData(@"\40", RegexOptions.ECMAScript, null)]
        [InlineData(@"\401", RegexOptions.ECMAScript, null)]
        [InlineData(@"\37", RegexOptions.ECMAScript, null)]
        [InlineData(@"\371", RegexOptions.ECMAScript, null)]
        [InlineData(@"\0000", RegexOptions.ECMAScript, null)]
        [InlineData(@"\k", RegexOptions.None, RegexParseError.MalformedNameRef)]
        [InlineData(@"\k ", RegexOptions.None, RegexParseError.MalformedNameRef)]
        [InlineData(@"\k<", RegexOptions.None, RegexParseError.MalformedNameRef)]
        [InlineData(@"\k< ", RegexOptions.None, RegexParseError.UnrecognizedEscape)]
        [InlineData(@"\k<0", RegexOptions.None, RegexParseError.UnrecognizedEscape)]
        [InlineData(@"\k<0 ", RegexOptions.None, RegexParseError.UnrecognizedEscape)]
        [InlineData(@"\k<0>", RegexOptions.None, null)]
        [InlineData(@"\k<0> ", RegexOptions.None, null)]
        [InlineData(@"\k<00> ", RegexOptions.None, null)]
        [InlineData(@"\k<a> ", RegexOptions.None, RegexParseError.UndefinedNameRef)]
        [InlineData(@"(?<a>)\k<a> ", RegexOptions.None, null)]
        [InlineData(@"\k", RegexOptions.ECMAScript, RegexParseError.MalformedNameRef)]
        [InlineData(@"\k ", RegexOptions.ECMAScript, RegexParseError.MalformedNameRef)]
        [InlineData(@"\k<", RegexOptions.ECMAScript, RegexParseError.MalformedNameRef)]
        [InlineData(@"\k< ", RegexOptions.ECMAScript, null)]
        [InlineData(@"\k<0", RegexOptions.ECMAScript, null)]
        [InlineData(@"\k<0 ", RegexOptions.ECMAScript, null)]
        [InlineData(@"\k<0>", RegexOptions.ECMAScript, null)]
        [InlineData(@"\k<0> ", RegexOptions.ECMAScript, null)]
        [InlineData(@"\k'", RegexOptions.None, RegexParseError.MalformedNameRef)]
        [InlineData(@"\k' ", RegexOptions.None, RegexParseError.UnrecognizedEscape)]
        [InlineData(@"\k'0", RegexOptions.None, RegexParseError.UnrecognizedEscape)]
        [InlineData(@"\k'0 ", RegexOptions.None, RegexParseError.UnrecognizedEscape)]
        [InlineData(@"\k'0'", RegexOptions.None, null)]
        [InlineData(@"\k'0' ", RegexOptions.None, null)]
        [InlineData(@"\k'00' ", RegexOptions.None, null)]
        [InlineData(@"\k'a' ", RegexOptions.None, RegexParseError.UndefinedNameRef)]
        [InlineData(@"(?<a>)\k'a' ", RegexOptions.None, null)]
        [InlineData(@"\k<0' ", RegexOptions.None, RegexParseError.UnrecognizedEscape)]
        [InlineData(@"\k'0> ", RegexOptions.None, RegexParseError.UnrecognizedEscape)]
        [InlineData(@"\", RegexOptions.None, RegexParseError.IllegalEndEscape)]
        [InlineData(@"\ ", RegexOptions.None, null)]
        [InlineData(@"\<", RegexOptions.None, null)]
        [InlineData(@"\< ", RegexOptions.None, null)]
        [InlineData(@"\<0", RegexOptions.None, null)]
        [InlineData(@"\<0 ", RegexOptions.None, null)]
        [InlineData(@"\<0>", RegexOptions.None, null)]
        [InlineData(@"\<0> ", RegexOptions.None, null)]
        [InlineData(@"\<00> ", RegexOptions.None, null)]
        [InlineData(@"\<a> ", RegexOptions.None, RegexParseError.UndefinedNameRef)]
        [InlineData(@"(?<a>)\<a> ", RegexOptions.None, null)]
        [InlineData(@"\", RegexOptions.ECMAScript, RegexParseError.IllegalEndEscape)]
        [InlineData(@"\ ", RegexOptions.ECMAScript, null)]
        [InlineData(@"\<", RegexOptions.ECMAScript, null)]
        [InlineData(@"\< ", RegexOptions.ECMAScript, null)]
        [InlineData(@"\<0", RegexOptions.ECMAScript, null)]
        [InlineData(@"\<0 ", RegexOptions.ECMAScript, null)]
        [InlineData(@"\<0>", RegexOptions.ECMAScript, null)]
        [InlineData(@"\<0> ", RegexOptions.ECMAScript, null)]
        [InlineData(@"\'", RegexOptions.None, null)]
        [InlineData(@"\' ", RegexOptions.None, null)]
        [InlineData(@"\'0", RegexOptions.None, null)]
        [InlineData(@"\'0 ", RegexOptions.None, null)]
        [InlineData(@"\'0'", RegexOptions.None, null)]
        [InlineData(@"\'0' ", RegexOptions.None, null)]
        [InlineData(@"\'00' ", RegexOptions.None, null)]
        [InlineData(@"\'a' ", RegexOptions.None, RegexParseError.UndefinedNameRef)]
        [InlineData(@"(?<a>)\'a' ", RegexOptions.None, null)]
        [InlineData(@"\<0' ", RegexOptions.None, null)]
        [InlineData(@"\'0> ", RegexOptions.None, null)]
        [InlineData("\\p{Cc}", RegexOptions.None, null)]
        [InlineData("\\p{ Cc }", RegexOptions.None, RegexParseError.IncompleteSlashP)]
        [InlineData("\\p{ Cc }", RegexOptions.IgnorePatternWhitespace, RegexParseError.IncompleteSlashP)]
        [InlineData("\\p {Cc}", RegexOptions.IgnorePatternWhitespace, RegexParseError.MalformedSlashP)]
        [InlineData("\\p{xxx}", RegexOptions.None, RegexParseError.UnknownUnicodeProperty)]
        [InlineData("\\p", RegexOptions.None, RegexParseError.IncompleteSlashP)]
        [InlineData("\\p{", RegexOptions.None, RegexParseError.IncompleteSlashP)]
        [InlineData("\\p{}", RegexOptions.None, RegexParseError.IncompleteSlashP)]
        [InlineData("\\p{} ", RegexOptions.None, RegexParseError.UnknownUnicodeProperty)]
        [InlineData("\\p {} ", RegexOptions.None, RegexParseError.MalformedSlashP)]
        [InlineData("\\p{Cc ", RegexOptions.None, RegexParseError.IncompleteSlashP)]
        [InlineData("\\p{IsArabicPresentationForms-A}", RegexOptions.None, null)]
        [InlineData("(?:)", RegexOptions.None, null)]
        [InlineData("(?:a)", RegexOptions.None, null)]
        [InlineData("(?:", RegexOptions.None, RegexParseError.NotEnoughParentheses)]
        [InlineData("(?: ", RegexOptions.IgnorePatternWhitespace, RegexParseError.NotEnoughParentheses)]
        [InlineData("(?=)", RegexOptions.None, null)]
        [InlineData("(?=a)", RegexOptions.None, null)]
        [InlineData("(?=", RegexOptions.None, RegexParseError.NotEnoughParentheses)]
        [InlineData("(?= ", RegexOptions.IgnorePatternWhitespace, RegexParseError.NotEnoughParentheses)]
        [InlineData("(?!)", RegexOptions.None, null)]
        [InlineData("(?!a)", RegexOptions.None, null)]
        [InlineData("(?!", RegexOptions.None, RegexParseError.NotEnoughParentheses)]
        [InlineData("(?! ", RegexOptions.IgnorePatternWhitespace, RegexParseError.NotEnoughParentheses)]
        [InlineData("(?>)", RegexOptions.None, null)]
        [InlineData("(?>a)", RegexOptions.None, null)]
        [InlineData("(?>", RegexOptions.None, RegexParseError.NotEnoughParentheses)]
        [InlineData("(?> ", RegexOptions.IgnorePatternWhitespace, RegexParseError.NotEnoughParentheses)]
        [InlineData("(?<=)", RegexOptions.None, null)]
        [InlineData("(?<=a)", RegexOptions.None, null)]
        [InlineData("(?<=", RegexOptions.None, RegexParseError.NotEnoughParentheses)]
        [InlineData("(?<= ", RegexOptions.IgnorePatternWhitespace, RegexParseError.NotEnoughParentheses)]
        [InlineData("(?<!)", RegexOptions.None, null)]
        [InlineData("(?<!a)", RegexOptions.None, null)]
        [InlineData("(?<!", RegexOptions.None, RegexParseError.NotEnoughParentheses)]
        [InlineData("(?<! ", RegexOptions.IgnorePatternWhitespace, RegexParseError.NotEnoughParentheses)]
        [InlineData("(?<", RegexOptions.IgnorePatternWhitespace, RegexParseError.UnrecognizedGrouping)]
        [InlineData("(?<>", RegexOptions.IgnorePatternWhitespace, RegexParseError.InvalidGroupName)]
        [InlineData("(?<a", RegexOptions.IgnorePatternWhitespace, RegexParseError.UnrecognizedGrouping)]
        [InlineData("(?<a>", RegexOptions.IgnorePatternWhitespace, RegexParseError.NotEnoughParentheses)]
        [InlineData("(?<a>a", RegexOptions.IgnorePatternWhitespace, RegexParseError.NotEnoughParentheses)]
        [InlineData("(?<a>a)", RegexOptions.IgnorePatternWhitespace, null)]
        [InlineData("(?<a >a)", RegexOptions.None, RegexParseError.InvalidGroupName)]
        [InlineData("(?<a >a)", RegexOptions.IgnorePatternWhitespace, RegexParseError.InvalidGroupName)]
        [InlineData("(?< a>a)", RegexOptions.None, RegexParseError.InvalidGroupName)]
        [InlineData("(?< a>a)", RegexOptions.IgnorePatternWhitespace, RegexParseError.InvalidGroupName)]
        [InlineData("(?< a >a)", RegexOptions.None, RegexParseError.InvalidGroupName)]
        [InlineData("(?< a >a)", RegexOptions.IgnorePatternWhitespace, RegexParseError.InvalidGroupName)]
        [InlineData("(?<ab>a)", RegexOptions.IgnorePatternWhitespace, null)]
        [InlineData("(?<0>a)", RegexOptions.IgnorePatternWhitespace, RegexParseError.CapnumNotZero)]
        [InlineData("(?<1>a)", RegexOptions.IgnorePatternWhitespace, null)]
        [InlineData("(?<10>a)", RegexOptions.IgnorePatternWhitespace, null)]
        [InlineData("(?<1>)", RegexOptions.None, null)]
        [InlineData("(?<1> )", RegexOptions.None, null)]
        [InlineData("(?<1> )", RegexOptions.IgnorePatternWhitespace, null)]
        [InlineData("(?'a')", RegexOptions.IgnorePatternWhitespace, null)]
        [InlineData("(?(", RegexOptions.IgnorePatternWhitespace, RegexParseError.NotEnoughParentheses)]
        [InlineData("(?(0", RegexOptions.IgnorePatternWhitespace, RegexParseError.MalformedReference)]
        [InlineData("(?(0)", RegexOptions.IgnorePatternWhitespace, RegexParseError.NotEnoughParentheses)]
        [InlineData("(?(0))", RegexOptions.IgnorePatternWhitespace, null)]
        [InlineData("(?(0)a)", RegexOptions.IgnorePatternWhitespace, null)]
        [InlineData("(?(0)a|)", RegexOptions.IgnorePatternWhitespace, null)]
        [InlineData("(?(0)a|b)", RegexOptions.IgnorePatternWhitespace, null)]
        [InlineData("(?(0)a|b|)", RegexOptions.IgnorePatternWhitespace, RegexParseError.TooManyAlternates)]
        [InlineData("(?(0)a|b|c)", RegexOptions.IgnorePatternWhitespace, RegexParseError.TooManyAlternates)]
        [InlineData("(?(0 )", RegexOptions.IgnorePatternWhitespace, RegexParseError.MalformedReference)]
        [InlineData("(?(1))", RegexOptions.IgnorePatternWhitespace, RegexParseError.UndefinedReference)]
        [InlineData("(?(00))", RegexOptions.IgnorePatternWhitespace, null)]
        [InlineData("(?(a))", RegexOptions.IgnorePatternWhitespace, null)]
        [InlineData("(?<a>)(?(a))", RegexOptions.IgnorePatternWhitespace, null)]
        [InlineData("(?<a>)(?(a ))", RegexOptions.IgnorePatternWhitespace, null)]
        [InlineData("(?<a>)(?( a))", RegexOptions.IgnorePatternWhitespace, null)]
        [InlineData("(?(()a()))", RegexOptions.None, null)]
        [InlineData("(?((?<x>)a(?<y>)))", RegexOptions.None, null)]
        [InlineData("(?(?'", RegexOptions.IgnorePatternWhitespace, RegexParseError.AlternationCantCapture)]
        [InlineData("(?(?'x'))", RegexOptions.IgnorePatternWhitespace, RegexParseError.AlternationCantCapture)]
        [InlineData("(?(?#", RegexOptions.IgnorePatternWhitespace, RegexParseError.UnterminatedComment)]
        [InlineData("(?(?#)", RegexOptions.IgnorePatternWhitespace, RegexParseError.AlternationCantHaveComment)]
        [InlineData("(?(?#))", RegexOptions.IgnorePatternWhitespace, RegexParseError.AlternationCantHaveComment)]
        [InlineData("(?(?<", RegexOptions.IgnorePatternWhitespace, RegexParseError.UnrecognizedGrouping)]
        [InlineData("(?(?<a", RegexOptions.IgnorePatternWhitespace, RegexParseError.AlternationCantCapture)]
        [InlineData("(?(?<a>", RegexOptions.IgnorePatternWhitespace, RegexParseError.AlternationCantCapture)]
        [InlineData("(?(?<a>)", RegexOptions.IgnorePatternWhitespace, RegexParseError.AlternationCantCapture)]
        [InlineData("(?(?<a>))", RegexOptions.IgnorePatternWhitespace, RegexParseError.AlternationCantCapture)]
        [InlineData("(?(?<=))", RegexOptions.IgnorePatternWhitespace, null)]
        [InlineData("(?(?<!))", RegexOptions.IgnorePatternWhitespace, null)]
        [InlineData(@"\1", RegexOptions.None, RegexParseError.UndefinedBackref)]
        [InlineData(@"\1 ", RegexOptions.None, RegexParseError.UndefinedBackref)]
        [InlineData(@"()\1", RegexOptions.None, null)]
        [InlineData(@"()\1 ", RegexOptions.None, null)]
        [InlineData(@"()\10 ", RegexOptions.None, null)]
        [InlineData(@"\1", RegexOptions.ECMAScript, null)]
        [InlineData(@"\1 ", RegexOptions.ECMAScript, null)]
        [InlineData(@"()\1", RegexOptions.ECMAScript, null)]
        [InlineData(@"()\1 ", RegexOptions.ECMAScript, null)]
        [InlineData(@"()\10 ", RegexOptions.ECMAScript, null)]
        [InlineData(@"()()()()()()()()()()\10 ", RegexOptions.ECMAScript, null)]
        [InlineData(@"[", RegexOptions.None, RegexParseError.UnterminatedBracket)]
        [InlineData(@"[ ", RegexOptions.None, RegexParseError.UnterminatedBracket)]
        [InlineData(@"[]", RegexOptions.None, RegexParseError.UnterminatedBracket)]
        [InlineData(@"[] ", RegexOptions.None, RegexParseError.UnterminatedBracket)]
        [InlineData(@"[a]", RegexOptions.None, null)]
        [InlineData(@"[a] ", RegexOptions.None, null)]
        [InlineData(@"[a-", RegexOptions.None, RegexParseError.UnterminatedBracket)]
        [InlineData(@"[a- ", RegexOptions.None, RegexParseError.UnterminatedBracket)]
        [InlineData(@"[a-]", RegexOptions.None, null)]
        [InlineData(@"[a-] ", RegexOptions.None, null)]
        [InlineData(@"[a-b]", RegexOptions.None, null)]
        [InlineData(@"[a-b] ", RegexOptions.None, null)]
        [InlineData(@"[a-[b]] ", RegexOptions.None, null)]
        [InlineData(@"[a-b-[c]] ", RegexOptions.None, null)]
        [InlineData(@"[a-[b]-c] ", RegexOptions.None, RegexParseError.SubtractionMustBeLast)]
        [InlineData(@"[a-z-[b]12]", RegexOptions.None, RegexParseError.SubtractionMustBeLast)]
        [InlineData(@"[[a]-b] ", RegexOptions.None, null)]
        [InlineData(@"[[a]-[b]] ", RegexOptions.None, null)]
        [InlineData(@"[\w-a] ", RegexOptions.None, null)]
        [InlineData(@"[a-\w] ", RegexOptions.None, RegexParseError.BadClassInCharRange)]
        [InlineData(@"[\p{llll}-a] ", RegexOptions.None, RegexParseError.UnknownUnicodeProperty)]
        [InlineData(@"[\p{Lu}-a] ", RegexOptions.None, null)]
        [InlineData(@"[a-\p{Lu}] ", RegexOptions.None, RegexParseError.BadClassInCharRange)]
        [InlineData(@"[a-[:Ll:]] ", RegexOptions.None, null)]
        [InlineData(@"[a-[:Ll]] ", RegexOptions.None, null)]
        [InlineData(@"[a-[:", RegexOptions.None, RegexParseError.UnterminatedBracket)]
        [InlineData(@"[a-[:L", RegexOptions.None, RegexParseError.UnterminatedBracket)]
        [InlineData(@"[a-[:L:", RegexOptions.None, RegexParseError.UnterminatedBracket)]
        [InlineData(@"[a-[:L:]", RegexOptions.None, RegexParseError.UnterminatedBracket)]
        [InlineData(@"[\-]", RegexOptions.None, null)]
        [InlineData(@"[a-b-c] ", RegexOptions.None, null)]
        [InlineData(@"[-b-c] ", RegexOptions.None, null)]
        [InlineData(@"[-[b] ", RegexOptions.None, null)]
        [InlineData(@"[-[b]] ", RegexOptions.None, null)]
        [InlineData(@"[--b ", RegexOptions.None, RegexParseError.UnterminatedBracket)]
        [InlineData(@"[--b] ", RegexOptions.None, null)]
        [InlineData(@"[--[b ", RegexOptions.None, RegexParseError.UnterminatedBracket)]
        [InlineData(@"[--[b] ", RegexOptions.None, RegexParseError.SubtractionMustBeLast)]
        [InlineData(@"[--[b]] ", RegexOptions.None, null)]
        [InlineData(@"[a--[b ", RegexOptions.None, RegexParseError.UnterminatedBracket)]
        [InlineData(@"[,--[a] ", RegexOptions.None, null)]
        [InlineData(@"[,--[a]] ", RegexOptions.None, null)]
        [InlineData(@"[\s-a]", RegexOptions.None, null)]
        [InlineData(@"[\p{Lu}-a]", RegexOptions.None, null)]
        [InlineData(@"[\c<-\c>]", RegexOptions.None, RegexParseError.UnrecognizedControl)]
        [InlineData(@"[\c>-\c<]", RegexOptions.None, RegexParseError.UnrecognizedControl)]
        [InlineData(@"[\c>-a]", RegexOptions.None, RegexParseError.UnrecognizedControl)]
        [InlineData(@"[a-\c>]", RegexOptions.None, RegexParseError.UnrecognizedControl)]
        [InlineData(@"[a--]", RegexOptions.None, RegexParseError.ReversedCharRange)]
        [InlineData(@"[--a]", RegexOptions.None, null)]
        [InlineData(@"[\--a]", RegexOptions.None, null)]
        [InlineData(@"[\0-\1]", RegexOptions.None, null)]
        [InlineData(@"[\1-\0]", RegexOptions.None, RegexParseError.ReversedCharRange)]
        [InlineData(@"[\0-\01]", RegexOptions.None, null)]
        [InlineData(@"[\01-\0]", RegexOptions.None, RegexParseError.ReversedCharRange)]
        [InlineData(@"[[:x:]-a]", RegexOptions.None, null)]
        [InlineData(@"[a-[:x:]]", RegexOptions.None, null)]
        [InlineData(@"[\0-\ca]", RegexOptions.None, null)]
        [InlineData(@"[\ca-\0]", RegexOptions.None, RegexParseError.ReversedCharRange)]
        [InlineData(@"[\ca-\cA]", RegexOptions.None, null)]
        [InlineData(@"[\cA-\ca]", RegexOptions.None, null)]
        [InlineData(@"[\u0-\u1]", RegexOptions.None, RegexParseError.TooFewHex)]
        [InlineData(@"[\u1-\u0]", RegexOptions.None, RegexParseError.TooFewHex)]
        [InlineData(@"[\u0000-\u0000]", RegexOptions.None, null)]
        [InlineData(@"[\u0000-\u0001]", RegexOptions.None, null)]
        [InlineData(@"[\u0001-\u0000]", RegexOptions.None, RegexParseError.ReversedCharRange)]
        [InlineData(@"[\u0001-a]", RegexOptions.None, null)]
        [InlineData(@"[a-\u0001]", RegexOptions.None, RegexParseError.ReversedCharRange)]
        [InlineData(@"[a-a]", RegexOptions.None, null)]
        [InlineData(@"[a-A]", RegexOptions.None, RegexParseError.ReversedCharRange)]
        [InlineData(@"[A-a]", RegexOptions.None, null)]
        [InlineData(@"[a-a]", RegexOptions.IgnoreCase, null)]
        [InlineData(@"[a-A]", RegexOptions.IgnoreCase, RegexParseError.ReversedCharRange)]
        [InlineData(@"[A-a]", RegexOptions.IgnoreCase, null)]
        [InlineData(@"[a-\x61]", RegexOptions.None, null)]
        [InlineData(@"[\x61-a]", RegexOptions.None, null)]
        [InlineData(@"[a-\x60]", RegexOptions.None, RegexParseError.ReversedCharRange)]
        [InlineData(@"[\x62-a]", RegexOptions.None, RegexParseError.ReversedCharRange)]
        [InlineData(@"[a-\x62]", RegexOptions.None, null)]
        [InlineData(@"[\3-\cc]", RegexOptions.None, null)]
        [InlineData(@"[\cc-\3]", RegexOptions.None, null)]
        [InlineData(@"[\2-\cc]", RegexOptions.None, null)]
        [InlineData(@"[\cc-\2]", RegexOptions.None, RegexParseError.ReversedCharRange)]
        [InlineData(@"[\4-\cc]", RegexOptions.None, RegexParseError.ReversedCharRange)]
        [InlineData(@"[\cc-\4]", RegexOptions.None, null)]
        [InlineData(@"[\ca-\cb]", RegexOptions.None, null)]
        [InlineData(@"[\ca-\cB]", RegexOptions.None, null)]
        [InlineData(@"[\cA-\cb]", RegexOptions.None, null)]
        [InlineData(@"[\cA-\cB]", RegexOptions.None, null)]
        [InlineData(@"[\cb-\ca]", RegexOptions.None, RegexParseError.ReversedCharRange)]
        [InlineData(@"[\cb-\cA]", RegexOptions.None, RegexParseError.ReversedCharRange)]
        [InlineData(@"[\cB-\ca]", RegexOptions.None, RegexParseError.ReversedCharRange)]
        [InlineData(@"[\cB-\cA]", RegexOptions.None, RegexParseError.ReversedCharRange)]
        [InlineData(@"[\--#]", RegexOptions.None, null)]
        [InlineData(@"[b-\-a]", RegexOptions.None, RegexParseError.ReversedCharRange)]
        [InlineData(@"[b-\-\-a]", RegexOptions.None, RegexParseError.ReversedCharRange)]
        [InlineData(@"()\2", RegexOptions.None, RegexParseError.UndefinedBackref)]
        [InlineData(@"()()\2", RegexOptions.None, null)]
        [InlineData(@"()\1", RegexOptions.ExplicitCapture, RegexParseError.UndefinedBackref)]
        [InlineData(@"()\2", RegexOptions.ExplicitCapture, RegexParseError.UndefinedBackref)]
        [InlineData(@"()()\2", RegexOptions.ExplicitCapture, RegexParseError.UndefinedBackref)]
        [InlineData(@"()()(?n)\1\2", RegexOptions.None, null)]
        [InlineData(@"()(?n)()\1\2", RegexOptions.None, RegexParseError.UndefinedBackref)]
        [InlineData(@"(?n)()()\1\2", RegexOptions.None, RegexParseError.UndefinedBackref)]
        [InlineData(@"()()(?n)\1\2", RegexOptions.ExplicitCapture, RegexParseError.UndefinedBackref)]
        [InlineData(@"()(?n)()\1\2", RegexOptions.ExplicitCapture, RegexParseError.UndefinedBackref)]
        [InlineData(@"(?n)()()\1\2", RegexOptions.ExplicitCapture, RegexParseError.UndefinedBackref)]
        [InlineData(@"()()(?-n)\1\2", RegexOptions.None, null)]
        [InlineData(@"()(?-n)()\1\2", RegexOptions.None, null)]
        [InlineData(@"(?-n)()()\1\2", RegexOptions.None, null)]
        [InlineData(@"()()(?-n)\1\2", RegexOptions.ExplicitCapture, RegexParseError.UndefinedBackref)]
        [InlineData(@"()(?-n)()\1\2", RegexOptions.ExplicitCapture, RegexParseError.UndefinedBackref)]
        [InlineData(@"(?-n)()()\1\2", RegexOptions.ExplicitCapture, null)]
        [InlineData(@"()()(?n:\1\2)", RegexOptions.None, null)]
        [InlineData(@"()()(?n:\1\2)", RegexOptions.ExplicitCapture, RegexParseError.UndefinedBackref)]
        [InlineData(@"()()(?-n:\1\2)", RegexOptions.None, null)]
        [InlineData(@"()()(?-n:\1\2)", RegexOptions.ExplicitCapture, RegexParseError.UndefinedBackref)]
        [InlineData(@"(?n:)()()\1\2", RegexOptions.None, null)]
        [InlineData(@"(?n:)()()\1\2", RegexOptions.ExplicitCapture, RegexParseError.UndefinedBackref)]
        [InlineData(@"(?-n:)()()\1\2", RegexOptions.None, null)]
        [InlineData(@"(?-n:)()()\1\2", RegexOptions.ExplicitCapture, RegexParseError.UndefinedBackref)]
        [InlineData(@"(?n)(?-n)()()\1\2", RegexOptions.None, null)]
        [InlineData(@"(?n)(?-n)()()\1\2", RegexOptions.ExplicitCapture, null)]
        [InlineData(@"(?-n)(?n)()()\1\2", RegexOptions.None, RegexParseError.UndefinedBackref)]
        [InlineData(@"(?-n)(?n)()()\1\2", RegexOptions.ExplicitCapture, RegexParseError.UndefinedBackref)]
        // References
        [InlineData(@"[aeiou]", RegexOptions.None, null)]
        [InlineData(@"(?<duplicateWord>\w+)\s\k<duplicateWord>\W(?<nextWord>\w+)", RegexOptions.None, null)]
        [InlineData(@"((?<One>abc)\d+)?(?<Two>xyz)(.*)", RegexOptions.None, null)]
        [InlineData(@"(\w+)\s(\1)", RegexOptions.None, null)]
        [InlineData(@"\Bqu\w+", RegexOptions.None, null)]
        [InlineData(@"\bare\w*\b", RegexOptions.None, null)]
        [InlineData(@"\G(\w+\s?\w*),?", RegexOptions.None, null)]
        [InlineData(@"\D+(?<digit>\d+)\D+(?<digit>\d+)?", RegexOptions.None, null)]
        [InlineData(@"(\s\d{4}(-(\d{4}&#124;present))?,?)+", RegexOptions.None, null)]
        [InlineData(@"^((\w+(\s?)){2,}),\s(\w+\s\w+),(\s\d{4}(-(\d{4}|present))?,?)+", RegexOptions.None, null)]
        [InlineData(@"^[0-9-[2468]]+$", RegexOptions.None, null)]
        [InlineData(@"[a-z-[0-9]]", RegexOptions.None, null)]
        [InlineData(@"[\p{IsBasicLatin}-[\x00-\x7F]]", RegexOptions.None, null)]
        [InlineData(@"[\u0000-\uFFFF-[\s\p{P}\p{IsGreek}\x85]]", RegexOptions.None, null)]
        [InlineData(@"[a-z-[d-w-[m-o]]]", RegexOptions.None, null)]
        [InlineData(@"((\w+(\s?)){2,}", RegexOptions.None, RegexParseError.NotEnoughParentheses)]
        [InlineData(@"[a-z-[djp]]", RegexOptions.None, null)]
        [InlineData(@"(\w)\1+.\b", RegexOptions.None, null)]
        [InlineData(@"\d{4}\b", RegexOptions.None, null)]
        [InlineData(@"\d{1,2},", RegexOptions.None, null)]
        [InlineData(@"(?<!(Saturday|Sunday) )\b\w+ \d{1,2}, \d{4}\b", RegexOptions.None, null)]
        [InlineData(@"(?<=\b20)\d{2}\b", RegexOptions.None, null)]
        [InlineData(@"\b\w+\b(?!\p{P})", RegexOptions.None, null)]
        [InlineData(@"\b(?!un)\w+\b", RegexOptions.None, null)]
        [InlineData(@"\b(?ix: d \w+)\s", RegexOptions.None, null)]
        [InlineData(@"(?:\w+)", RegexOptions.None, null)]
        [InlineData(@"(?:\b(?:\w+)\W*)+", RegexOptions.None, null)]
        [InlineData(@"(?:\b(?:\w+)\W*)+\.", RegexOptions.None, null)]
        [InlineData(@"[^<>]*", RegexOptions.None, null)]
        [InlineData(@"\b\w+(?=\sis\b)", RegexOptions.None, null)]
        [InlineData(@"[a-z-[m]]", RegexOptions.None, null)]
        [InlineData(@"^\D\d{1,5}\D*$", RegexOptions.None, null)]
        [InlineData(@"[^0-9]", RegexOptions.None, null)]
        [InlineData(@"(\p{IsGreek}+(\s)?)+", RegexOptions.None, null)]
        [InlineData(@"\b(\p{IsGreek}+(\s)?)+\p{Pd}\s(\p{IsBasicLatin}+(\s)?)+", RegexOptions.None, null)]
        [InlineData(@"\b.*[.?!;:](\s|\z)", RegexOptions.None, null)]
        [InlineData(@"^.+", RegexOptions.None, null)]
        [InlineData(@"[^o]", RegexOptions.None, null)]
        [InlineData(@"\bth[^o]\w+\b", RegexOptions.None, null)]
        [InlineData(@"(\P{Sc})+", RegexOptions.None, null)]
        [InlineData(@"[^\p{P}\d]", RegexOptions.None, null)]
        [InlineData(@"\b[A-Z]\w*\b", RegexOptions.None, null)]
        [InlineData(@"\S+?", RegexOptions.None, null)]
        [InlineData(@"y\s", RegexOptions.None, null)]
        [InlineData(@"gr[ae]y\s\S+?[\s\p{P}]", RegexOptions.None, null)]
        [InlineData(@"[\s\p{P}]", RegexOptions.None, null)]
        [InlineData(@"[\p{P}\d]", RegexOptions.None, null)]
        [InlineData(@"[^aeiou]", RegexOptions.None, null)]
        [InlineData(@"(\w)\1", RegexOptions.None, null)]
        [InlineData(@"[^\p{Ll}\p{Lu}\p{Lt}\p{Lo}\p{Nd}\p{Pc}\p{Lm}] ", RegexOptions.None, null)]
        [InlineData(@"[^a-zA-Z_0-9]", RegexOptions.None, null)]
        [InlineData(@"\P{Nd}", RegexOptions.None, null)]
        [InlineData(@"(\(?\d{3}\)?[\s-])?", RegexOptions.None, null)]
        [InlineData(@"^(\(?\d{3}\)?[\s-])?\d{3}-\d{4}$", RegexOptions.None, null)]
        [InlineData(@"[0-9]", RegexOptions.None, null)]
        [InlineData(@"\p{Nd}", RegexOptions.None, null)]
        [InlineData(@"\b(\S+)\s?", RegexOptions.None, null)]
        [InlineData(@"[^ \f\n\r\t\v]", RegexOptions.None, null)]
        [InlineData(@"[^\f\n\r\t\v\x85\p{Z}]", RegexOptions.None, null)]
        [InlineData(@"(\s|$)", RegexOptions.None, null)]
        [InlineData(@"\b\w+(e)?s(\s|$)", RegexOptions.None, null)]
        [InlineData(@"[ \f\n\r\t\v]", RegexOptions.None, null)]
        [InlineData(@"(\W){1,2}", RegexOptions.None, null)]
        [InlineData(@"(\w+)", RegexOptions.None, null)]
        [InlineData(@"\b", RegexOptions.None, null)]
        [InlineData(@"\b(\w+)(\W){1,2}", RegexOptions.None, null)]
        [InlineData(@"(?>(\w)\1+).\b", RegexOptions.None, null)]
        [InlineData(@"(\b(\w+)\W+)+", RegexOptions.None, null)]
        [InlineData(@"\p{Sc}*(\s?\d+[.,]?\d*)\p{Sc}*", RegexOptions.None, null)]
        [InlineData(@"p{Sc}*(?<amount>\s?\d+[.,]?\d*)\p{Sc}*", RegexOptions.None, null)]
        [InlineData(@"^(\w+\s?)+$", RegexOptions.None, null)]
        [InlineData(@"(?ix) d \w+ \s", RegexOptions.None, null)]
        [InlineData(@"\bthe\w*\b", RegexOptions.None, null)]
        [InlineData(@"\b(?i:t)he\w*\b", RegexOptions.None, null)]
        [InlineData(@"^(\w+)\s(\d+)$", RegexOptions.None, null)]
        [InlineData(@"^(\w+)\s(\d+)\r*$", RegexOptions.Multiline, null)]
        [InlineData(@"(?m)^(\w+)\s(\d+)\r*$", RegexOptions.Multiline, null)]
        [InlineData(@"(?s)^.+", RegexOptions.None, null)]
        [InlineData(@"\b(\d{2}-)*(?(1)\d{7}|\d{3}-\d{2}-\d{4})\b", RegexOptions.None, null)]
        [InlineData(@"\b\(?((\w+),?\s?)+[\.!?]\)?", RegexOptions.None, null)]
        [InlineData(@"(?n)\b\(?((?>\w+),?\s?)+[\.!?]\)?", RegexOptions.None, null)]
        [InlineData(@"\b\(?(?n:(?>\w+),?\s?)+[\.!?]\)?", RegexOptions.None, null)]
        [InlineData(@"\b\(?((?>\w+),?\s?)+[\.!?]\)?", RegexOptions.IgnorePatternWhitespace, null)]
        [InlineData(@"(?x)\b \(? ( (?>\w+) ,?\s? )+  [\.!?] \)? # Matches an entire sentence.", RegexOptions.None, null)]
        [InlineData(@"\bb\w+\s", RegexOptions.RightToLeft, null)]
        [InlineData(@"(?<=\d{1,2}\s)\w+,?\s\d{4}", RegexOptions.RightToLeft, null)]
        [InlineData(@"\b(\w+\s*)+", RegexOptions.ECMAScript, null)]
        [InlineData(@"((a+)(\1) ?)+", RegexOptions.ECMAScript, null)]
        [InlineData(@"\b(D\w+)\s(d\w+)\b", RegexOptions.None, null)]
        [InlineData(@"\b(D\w+)(?ixn) \s (d\w+) \b", RegexOptions.None, null)]
        [InlineData(@"\b((?# case-sensitive comparison)D\w+)\s((?#case-insensitive comparison)d\w+)\b", RegexOptions.None, null)]
        [InlineData(@"\b\(?((?>\w+),?\s?)+[\.!?]\)?", RegexOptions.None, null)]
        [InlineData(@"\b(?<n2>\d{2}-)*(?(n2)\d{7}|\d{3}-\d{2}-\d{4})\b", RegexOptions.None, null)]
        [InlineData(@"\b(\d{2}-\d{7}|\d{3}-\d{2}-\d{4})\b", RegexOptions.None, null)]
        [InlineData(@"\bgr(a|e)y\b", RegexOptions.None, null)]
        [InlineData(@"\b91*9*\b", RegexOptions.None, null)]
        [InlineData(@"\ban+\w*?\b", RegexOptions.None, null)]
        [InlineData(@"\ban?\b", RegexOptions.None, null)]
        [InlineData(@"\b\d+\,\d{3}\b", RegexOptions.None, null)]
        [InlineData(@"\b\d{2,}\b\D+", RegexOptions.None, null)]
        [InlineData(@"(00\s){2,4}", RegexOptions.None, null)]
        [InlineData(@"\b\w*?oo\w*?\b", RegexOptions.None, null)]
        [InlineData(@"\b\w+?\b", RegexOptions.None, null)]
        [InlineData(@"^\s*(System.)??Console.Write(Line)??\(??", RegexOptions.None, null)]
        [InlineData(@"(System.)??", RegexOptions.None, null)]
        [InlineData(@"\b(\w{3,}?\.){2}?\w{3,}?\b", RegexOptions.None, null)]
        [InlineData(@"\b[A-Z](\w*?\s*?){1,10}[.!?]", RegexOptions.None, null)]
        [InlineData(@"b.*([0-9]{4})\b", RegexOptions.None, null)]
        [InlineData(@"\b.*?([0-9]{4})\b", RegexOptions.None, null)]
        [InlineData(@"(a?)*", RegexOptions.None, null)]
        [InlineData(@"(a\1|(?(1)\1)){0,2}", RegexOptions.None, null)]
        [InlineData(@"(a\1|(?(1)\1)){2}", RegexOptions.None, null)]
        [InlineData(@"(?<char>\w)\k<char>", RegexOptions.None, null)]
        [InlineData(@"(?<2>\w)\k<2>", RegexOptions.None, null)]
        [InlineData(@"(?<1>a)(?<1>\1b)*", RegexOptions.None, null)]
        [InlineData(@"\b(\p{Lu}{2})(\d{2})?(\p{Lu}{2})\b", RegexOptions.None, null)]
        [InlineData(@"\bgr[ae]y\b", RegexOptions.None, null)]
        [InlineData(@"\b((?# case sensitive comparison)D\w+)\s(?ixn)((?#case insensitive comparison)d\w+)\b", RegexOptions.None, null)]
        [InlineData(@"\{\d+(,-*\d+)*(\:\w{1,4}?)*\}(?x) # Looks for a composite format item.", RegexOptions.None, null)]
        // Negative tests
        [InlineData(@"cat([a-\d]*)dog", RegexOptions.None, RegexParseError.BadClassInCharRange)]
        [InlineData(@"\k<1", RegexOptions.None, RegexParseError.UnrecognizedEscape)]
        [InlineData(@"(?')", RegexOptions.None, RegexParseError.InvalidGroupName)]
        [InlineData(@"(?<)", RegexOptions.None, RegexParseError.InvalidGroupName)]
        [InlineData(@"(?imn )", RegexOptions.None, RegexParseError.UnrecognizedGrouping)]
        [InlineData(@"(?imn", RegexOptions.None, RegexParseError.UnrecognizedGrouping)]
        [InlineData(@"(?'cat'", RegexOptions.None, RegexParseError.NotEnoughParentheses)]
        [InlineData(@"(?'", RegexOptions.None, RegexParseError.UnrecognizedGrouping)]
        [InlineData(@"(?'=)", RegexOptions.None, RegexParseError.UnrecognizedGrouping)]
        [InlineData(@"(?'!)", RegexOptions.None, RegexParseError.UnrecognizedGrouping)]
        [InlineData(@"[^", RegexOptions.None, RegexParseError.UnterminatedBracket)]
        [InlineData(@"[cat", RegexOptions.None, RegexParseError.UnterminatedBracket)]
        [InlineData(@"[^cat", RegexOptions.None, RegexParseError.UnterminatedBracket)]
        [InlineData(@"\p{cat", RegexOptions.None, RegexParseError.IncompleteSlashP)]
        [InlineData(@"\k<cat", RegexOptions.None, RegexParseError.UnrecognizedEscape)]
        [InlineData(@"\p{cat}", RegexOptions.None, RegexParseError.UnknownUnicodeProperty)]
        [InlineData(@"\P{cat", RegexOptions.None, RegexParseError.IncompleteSlashP)]
        [InlineData(@"\P{cat}", RegexOptions.None, RegexParseError.UnknownUnicodeProperty)]
        [InlineData(@"(?<cat>", RegexOptions.None, RegexParseError.NotEnoughParentheses)]
        [InlineData(@"\P{", RegexOptions.None, RegexParseError.IncompleteSlashP)]
        [InlineData(@"\k<>", RegexOptions.None, RegexParseError.UnrecognizedEscape)]
        [InlineData(@"(?(", RegexOptions.None, RegexParseError.NotEnoughParentheses)]
        [InlineData(@"(?()|", RegexOptions.None, RegexParseError.NotEnoughParentheses)]
        [InlineData(@"?(a|b)", RegexOptions.None, RegexParseError.QuantifyAfterNothing)]
        [InlineData(@"?((a)", RegexOptions.None, RegexParseError.QuantifyAfterNothing)]
        [InlineData(@"?((a)a", RegexOptions.None, RegexParseError.QuantifyAfterNothing)]
        [InlineData(@"?((a)a|", RegexOptions.None, RegexParseError.QuantifyAfterNothing)]
        [InlineData(@"?((a)a|b", RegexOptions.None, RegexParseError.QuantifyAfterNothing)]
        [InlineData(@"?(a)", RegexOptions.None, RegexParseError.QuantifyAfterNothing)]
        [InlineData(@"[a", RegexOptions.None, RegexParseError.UnterminatedBracket)]
        [InlineData(@"?(a:b)", RegexOptions.None, RegexParseError.QuantifyAfterNothing)]
        [InlineData(@"(?(?", RegexOptions.None, RegexParseError.UnrecognizedGrouping)]
        [InlineData(@"(?(cat", RegexOptions.None, RegexParseError.NotEnoughParentheses)]
        [InlineData(@"(?(cat)|", RegexOptions.None, RegexParseError.NotEnoughParentheses)]
        [InlineData(@"foo(?<0>bar)", RegexOptions.None, RegexParseError.CapnumNotZero)]
        [InlineData(@"foo(?'0'bar)", RegexOptions.None, RegexParseError.CapnumNotZero)]
        [InlineData(@"foo(?<1bar)", RegexOptions.None, RegexParseError.InvalidGroupName)]
        [InlineData(@"foo(?'1bar)", RegexOptions.None, RegexParseError.InvalidGroupName)]
        [InlineData(@"\p{klsak", RegexOptions.None, RegexParseError.IncompleteSlashP)]
        [InlineData(@"(?c:cat)", RegexOptions.None, RegexParseError.UnrecognizedGrouping)]
        [InlineData(@"(??e:cat)", RegexOptions.None, RegexParseError.UnrecognizedGrouping)]
        [InlineData(@"[a-f-[]]+", RegexOptions.None, RegexParseError.UnterminatedBracket)]
        [InlineData(@"[A-[]+", RegexOptions.None, RegexParseError.UnterminatedBracket)]
        [InlineData(@"(?(?e))", RegexOptions.None, RegexParseError.UnrecognizedGrouping)]
        [InlineData(@"(?(?a)", RegexOptions.None, RegexParseError.UnrecognizedGrouping)]
        [InlineData(@"(?r:cat)", RegexOptions.None, RegexParseError.UnrecognizedGrouping)]
        [InlineData(@"\x2", RegexOptions.None, RegexParseError.TooFewHex)]
        [InlineData(@"(cat) (?#cat)    \s+ (?#followed by 1 or more whitespace", RegexOptions.IgnorePatternWhitespace, RegexParseError.UnterminatedComment)]
        [InlineData(@"cat(?(?afdcat)dog)", RegexOptions.None, RegexParseError.UnrecognizedGrouping)]
        [InlineData(@"cat(?(?<cat>cat)dog)", RegexOptions.None, RegexParseError.AlternationCantCapture)]
        [InlineData(@"cat(?(?'cat'cat)dog)", RegexOptions.None, RegexParseError.AlternationCantCapture)]
        [InlineData(@"cat(?(?#COMMENT)cat)", RegexOptions.None, RegexParseError.AlternationCantHaveComment)]
        [InlineData(@"cat(?<>dog)", RegexOptions.None, RegexParseError.InvalidGroupName)]
        [InlineData(@"cat(?<dog<>)_*>dog)", RegexOptions.None, RegexParseError.InvalidGroupName)]
        [InlineData(@"cat(?<dog >)_*>dog)", RegexOptions.None, RegexParseError.InvalidGroupName)]
        [InlineData(@"cat(?<dog!>)_*>dog)", RegexOptions.None, RegexParseError.InvalidGroupName)]
        [InlineData(@"cat(?<dog)_*>dog)", RegexOptions.None, RegexParseError.InvalidGroupName)]
        [InlineData(@"cat(?<1dog>dog)", RegexOptions.None, RegexParseError.InvalidGroupName)]
        [InlineData(@"cat(?<0>dog)", RegexOptions.None, RegexParseError.CapnumNotZero)]
        [InlineData(@"([5-\D]*)dog", RegexOptions.None, RegexParseError.BadClassInCharRange)]
        [InlineData(@"cat([6-\s]*)dog", RegexOptions.None, RegexParseError.BadClassInCharRange)]
        [InlineData(@"cat([c-\S]*)", RegexOptions.None, RegexParseError.BadClassInCharRange)]
        [InlineData(@"cat([7-\w]*)", RegexOptions.None, RegexParseError.BadClassInCharRange)]
        [InlineData(@"cat([a-\W]*)dog", RegexOptions.None, RegexParseError.BadClassInCharRange)]
        [InlineData(@"([f-\p{Lu}]\w*)\s([\p{Lu}]\w*)", RegexOptions.None, RegexParseError.BadClassInCharRange)]
        [InlineData(@"(cat) (?#cat)    \s+ (?#followed by 1 or more whitespace", RegexOptions.None, RegexParseError.UnterminatedComment)]
        [InlineData(@"([1-\P{Ll}][\p{Ll}]*)\s([\P{Ll}][\p{Ll}]*)", RegexOptions.None, RegexParseError.BadClassInCharRange)]
        [InlineData(@"[\P]", RegexOptions.None, RegexParseError.IncompleteSlashP)]
        [InlineData(@"([\pcat])", RegexOptions.None, RegexParseError.MalformedSlashP)]
        [InlineData(@"([\Pcat])", RegexOptions.None, RegexParseError.MalformedSlashP)]
        [InlineData(@"(\p{", RegexOptions.None, RegexParseError.IncompleteSlashP)]
        [InlineData(@"(\p{Ll", RegexOptions.None, RegexParseError.IncompleteSlashP)]
        [InlineData(@"(cat)([\o]*)(dog)", RegexOptions.None, RegexParseError.UnrecognizedEscape)]
        [InlineData(@"[\p]", RegexOptions.None, RegexParseError.IncompleteSlashP)]
        [InlineData(@"(?<cat>cat)\s+(?<dog>dog)\kcat", RegexOptions.None, RegexParseError.MalformedNameRef)]
        [InlineData(@"(?<cat>cat)\s+(?<dog>dog)\k<cat2>", RegexOptions.None, RegexParseError.UndefinedNameRef)]
        [InlineData(@"(?<cat>cat)\s+(?<dog>dog)\k<8>cat", RegexOptions.None, RegexParseError.UndefinedBackref)]
        [InlineData(@"^[abcd]{1}?*$", RegexOptions.None, RegexParseError.NestedQuantify)]
        [InlineData(@"^[abcd]*+$", RegexOptions.None, RegexParseError.NestedQuantify)]
        [InlineData(@"^[abcd]+*$", RegexOptions.None, RegexParseError.NestedQuantify)]
        [InlineData(@"^[abcd]?*$", RegexOptions.None, RegexParseError.NestedQuantify)]
        [InlineData(@"^[abcd]*?+$", RegexOptions.None, RegexParseError.NestedQuantify)]
        [InlineData(@"^[abcd]+?*$", RegexOptions.None, RegexParseError.NestedQuantify)]
        [InlineData(@"^[abcd]{1,}?*$", RegexOptions.None, RegexParseError.NestedQuantify)]
        [InlineData(@"^[abcd]??*$", RegexOptions.None, RegexParseError.NestedQuantify)]
        [InlineData(@"^[abcd]+{0,5}$", RegexOptions.None, RegexParseError.NestedQuantify)]
        [InlineData(@"^[abcd]?{0,5}$", RegexOptions.None, RegexParseError.NestedQuantify)]
        [InlineData(@"\ua", RegexOptions.None, RegexParseError.TooFewHex)]
        [InlineData(@"^[abcd]*{0,5}$", RegexOptions.None, RegexParseError.NestedQuantify)]
        [InlineData(@"^[abcd]{0,16}?*$", RegexOptions.None, RegexParseError.NestedQuantify)]
        [InlineData(@"^[abcd]{1,}*$", RegexOptions.None, RegexParseError.NestedQuantify)]
        [InlineData(@"(?<cat>cat)\s+(?<dog>dog)\k<8>cat", RegexOptions.ECMAScript, RegexParseError.UndefinedBackref)]
        [InlineData(@"(?<cat>cat)\s+(?<dog>dog)\k8", RegexOptions.None, RegexParseError.MalformedNameRef)]
        [InlineData(@"(?<cat>cat)\s+(?<dog>dog)\k8", RegexOptions.ECMAScript, RegexParseError.MalformedNameRef)]
        [InlineData(@"(cat)(\7)", RegexOptions.None, RegexParseError.UndefinedBackref)]
        [InlineData(@"(cat)\s+(?<2147483648>dog)", RegexOptions.None, RegexParseError.CaptureGroupOutOfRange)]
        [InlineData(@"(cat)\s+(?<21474836481097>dog)", RegexOptions.None, RegexParseError.CaptureGroupOutOfRange)]
        [InlineData(@"^[abcd]{1}*$", RegexOptions.None, RegexParseError.NestedQuantify)]
        [InlineData(@"(cat)(\c*)(dog)", RegexOptions.None, RegexParseError.UnrecognizedControl)]
        [InlineData(@"(cat)(\c *)(dog)", RegexOptions.None, RegexParseError.UnrecognizedControl)]
        [InlineData(@"(cat)(\c?*)(dog)", RegexOptions.None, RegexParseError.UnrecognizedControl)]
        [InlineData(@"(cat)(\c`*)(dog)", RegexOptions.None, RegexParseError.UnrecognizedControl)]
        [InlineData(@"(cat)(\c\|*)(dog)", RegexOptions.None, RegexParseError.QuantifyAfterNothing)]
        [InlineData(@"^[abcd]{0,16}*$", RegexOptions.None, RegexParseError.NestedQuantify)]
        [InlineData(@"(cat)\c", RegexOptions.None, RegexParseError.MissingControl)]
        // Deep recursion
        [InlineData(@"@""((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((
(((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((
(((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((
(((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((
(((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((
(((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((
(((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((
(((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((
(((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((
(((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((
(((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((
(((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((""", RegexOptions.None, RegexParseError.NotEnoughParentheses)]
        // Scan control
        [InlineData("(cat)(\\c\0*)(dog)", RegexOptions.None, RegexParseError.UnrecognizedControl)]
        [InlineData(@"(cat)(\c\[*)(dog)", RegexOptions.None, RegexParseError.UnterminatedBracket)]
        // Invalid grouping constructs
        [InlineData("(?<", RegexOptions.None, RegexParseError.UnrecognizedGrouping)]
        [InlineData("(?>-", RegexOptions.None, RegexParseError.NotEnoughParentheses)]
        // Testgroup with options
        [InlineData("())", RegexOptions.None, RegexParseError.TooManyParentheses)]
        [InlineData("[a-z-[aeiuo]", RegexOptions.None, RegexParseError.UnterminatedBracket)]
        [InlineData("[a-z-[aeiuo", RegexOptions.None, RegexParseError.UnterminatedBracket)]
        [InlineData("[a-z-[b]", RegexOptions.None, RegexParseError.UnterminatedBracket)]
        [InlineData("[a-z-[b", RegexOptions.None, RegexParseError.UnterminatedBracket)]
        [InlineData("[b-a]", RegexOptions.None, RegexParseError.ReversedCharRange)]
        [InlineData(@"[a-c]{2,1}", RegexOptions.None, RegexParseError.IllegalRange)]
        [InlineData(@"\d{2147483648}", RegexOptions.None, RegexParseError.CaptureGroupOutOfRange)]
        [InlineData("[a-z-[b][", RegexOptions.None, RegexParseError.UnterminatedBracket)]
        [InlineData("(?()|||||)", RegexOptions.None, RegexParseError.TooManyAlternates)]
        [InlineData("[^]", RegexOptions.None, RegexParseError.UnterminatedBracket)]
        public void Parse(string pattern, RegexOptions options, object errorObj)
        {
            RegexParseError? error = (RegexParseError?)errorObj;

            // Parse the main tree and if parsing fails check if the supplied error matches.
            ParseTree(pattern, options, error);

            // Assert that only ArgumentException might be thrown during parsing.
            ParseSubTrees(pattern, options);
        }

        [Theory]
        [InlineData(@"[a-\-]", RegexOptions.None, RegexParseError.ReversedCharRange)]
        [InlineData(@"[a-\-b]", RegexOptions.None, RegexParseError.ReversedCharRange)]
        [InlineData(@"[a-\-\-b]", RegexOptions.None, RegexParseError.ReversedCharRange)]
        [InlineData(@"[a-\-\D]", RegexOptions.None, RegexParseError.ReversedCharRange)]
        [InlineData(@"[a-\-\-\D]", RegexOptions.None, RegexParseError.ReversedCharRange)]
        [InlineData(@"[a -\-\b]", RegexOptions.None, null)]
        // OutOfMemoryException
        [InlineData("a{2147483647}", RegexOptions.None, null)]
        [InlineData("a{2147483647,}", RegexOptions.None, null)]
        [InlineData(@"(?(?N))", RegexOptions.None, RegexParseError.UnrecognizedGrouping)]
        [InlineData(@"(?(?i))", RegexOptions.None, RegexParseError.UnrecognizedGrouping)]
        [InlineData(@"(?(?I))", RegexOptions.None, RegexParseError.UnrecognizedGrouping)]
        [InlineData(@"(?(?M))", RegexOptions.None, RegexParseError.UnrecognizedGrouping)]
        [InlineData(@"(?(?s))", RegexOptions.None, RegexParseError.UnrecognizedGrouping)]
        [InlineData(@"(?(?S))", RegexOptions.None, RegexParseError.UnrecognizedGrouping)]
        [InlineData(@"(?(?x))", RegexOptions.None, RegexParseError.UnrecognizedGrouping)]
        [InlineData(@"(?(?X))", RegexOptions.None, RegexParseError.UnrecognizedGrouping)]
        [InlineData(@"(?(?n))", RegexOptions.None, RegexParseError.UnrecognizedGrouping)]
        [InlineData(" (?(?n))", RegexOptions.None, RegexParseError.UnrecognizedGrouping)]
        [InlineData(@"(?(?m))", RegexOptions.None, RegexParseError.UnrecognizedGrouping)]
        // IndexOutOfRangeException
        [InlineData("(?<-", RegexOptions.None, RegexParseError.UnrecognizedGrouping)]
        [InlineData("(?<-", RegexOptions.IgnorePatternWhitespace, RegexParseError.UnrecognizedGrouping)]
        [InlineData(@"^[^<>]*(((?'Open'<)[^<>]*)+((?'Close-Open'>)[^<>]*)+)*(?(Open)(?!))$", RegexOptions.None, null)]
        [InlineData(@"((?'Close-Open'>)[^<>]*)+", RegexOptions.None, RegexParseError.UndefinedNameRef)]
        [InlineData(@"(((?'Open'<)[^<>]*)+((?'Close-Open'>)[^<>]*)+)*", RegexOptions.None, null)]
        [InlineData(@"(?'Close-Open'>)", RegexOptions.None, RegexParseError.UndefinedNameRef)]
        [InlineData("(?<a-00>)", RegexOptions.IgnorePatternWhitespace, null)]
        [InlineData("(?<a>)()(?<-0>)(?<-1>)(?<-2>)(?<-3>)", RegexOptions.IgnorePatternWhitespace, RegexParseError.UndefinedBackref)]
        [InlineData("()(?<a>)(?<-0>)(?<-1>)(?<-2>)(?<-3>)", RegexOptions.IgnorePatternWhitespace, RegexParseError.UndefinedBackref)]
        [InlineData("()()(?<-0>)(?<-1>)(?<-2>)(?<-3>)", RegexOptions.IgnorePatternWhitespace, RegexParseError.UndefinedBackref)]
        [InlineData("(?<a>)(?<b>)(?<-1>)(?<-2>)", RegexOptions.IgnorePatternWhitespace, null)]
        [InlineData("(?<-4>)(?<4>)", RegexOptions.IgnorePatternWhitespace, null)]
        [InlineData("(?<4>)(?<-4>)", RegexOptions.IgnorePatternWhitespace, null)]
        [InlineData("(?<a>)(?<-a>)", RegexOptions.IgnorePatternWhitespace, null)]
        [InlineData("(?<-a>)(?<a>)", RegexOptions.IgnorePatternWhitespace, null)]
        [InlineData("(?<a-0>", RegexOptions.IgnorePatternWhitespace, RegexParseError.NotEnoughParentheses)]
        [InlineData("(?<a-0>)", RegexOptions.IgnorePatternWhitespace, null)]
        [InlineData("(?<a-0 >)", RegexOptions.IgnorePatternWhitespace, RegexParseError.InvalidGroupName)]
        [InlineData("(?<a- 0 >)", RegexOptions.IgnorePatternWhitespace, RegexParseError.InvalidGroupName)]
        [InlineData("(?<a- 0>)", RegexOptions.IgnorePatternWhitespace, RegexParseError.InvalidGroupName)]
        [InlineData("(?<-1>)", RegexOptions.IgnorePatternWhitespace, RegexParseError.UndefinedBackref)]
        [InlineData("()(?<-1>)", RegexOptions.IgnorePatternWhitespace, null)]
        [InlineData("(?<-1>)()", RegexOptions.IgnorePatternWhitespace, null)]
        [InlineData("(?<-00>)", RegexOptions.IgnorePatternWhitespace, null)]
        [InlineData("(?<a-", RegexOptions.IgnorePatternWhitespace, RegexParseError.UnrecognizedGrouping)]
        [InlineData("(?<a-0", RegexOptions.IgnorePatternWhitespace, RegexParseError.UnrecognizedGrouping)]
        [InlineData("(?<a-0)", RegexOptions.IgnorePatternWhitespace, RegexParseError.InvalidGroupName)]
        [InlineData("(?<a>)(?<b>)(?<-0>)(?<-1>)(?<-2>)(?<-3>)", RegexOptions.IgnorePatternWhitespace, RegexParseError.UndefinedBackref)]
        [InlineData("(?<-0>)(?<-1>)(?<-2>)(?<-3>)()()", RegexOptions.IgnorePatternWhitespace, RegexParseError.UndefinedBackref)]
        [InlineData("(?<-0>)(?<-1>)(?<-2>)(?<-3>)()(?", RegexOptions.IgnorePatternWhitespace, RegexParseError.UndefinedBackref)]
        [InlineData("(?<-0>)(?<-1>)(?<-2>)(?<-3>)()(?<a>)", RegexOptions.IgnorePatternWhitespace, RegexParseError.UndefinedBackref)]
        [InlineData("(?<-0>)(?<-1>)(?<-2>)(?<-3>)(?<a>)()", RegexOptions.IgnorePatternWhitespace, RegexParseError.UndefinedBackref)]
        [InlineData("(?<-0>)(?<-1>)(?<-2>)(?<-3>)(?<a>)(?", RegexOptions.IgnorePatternWhitespace, RegexParseError.UndefinedBackref)]
        [InlineData("(?<-0>)(?<-1>)(?<-2>)(?<-3>)(?<a>)(?<b>)", RegexOptions.IgnorePatternWhitespace, RegexParseError.UndefinedBackref)]
        [InlineData("(?<a-0>)(?<b-a>)", RegexOptions.IgnorePatternWhitespace, null)]
        [InlineData("(?<a-0>)(?<-a>)", RegexOptions.IgnorePatternWhitespace, null)]
        [InlineData("(?<a-a>)", RegexOptions.IgnorePatternWhitespace, null)]
        [InlineData("(?<-0>)", RegexOptions.IgnorePatternWhitespace, null)]
        [InlineData("(?<-0 >)", RegexOptions.IgnorePatternWhitespace, RegexParseError.InvalidGroupName)]
        [InlineData("(?<- 0 >)", RegexOptions.IgnorePatternWhitespace, RegexParseError.InvalidGroupName)]
        [InlineData("(?<- 0>)", RegexOptions.IgnorePatternWhitespace, RegexParseError.InvalidGroupName)]
        [InlineData("(?<a-0')", RegexOptions.IgnorePatternWhitespace, RegexParseError.InvalidGroupName)]
        [InlineData("(?'a-0>)", RegexOptions.IgnorePatternWhitespace, RegexParseError.InvalidGroupName)]
        [InlineData("(?'-0')", RegexOptions.IgnorePatternWhitespace, null)]
        [InlineData("(?'a-0')", RegexOptions.IgnorePatternWhitespace, null)]
        [InlineData("(?<-0", RegexOptions.IgnorePatternWhitespace, RegexParseError.UnrecognizedGrouping)]
        [InlineData("(?<-0)", RegexOptions.IgnorePatternWhitespace, RegexParseError.InvalidGroupName)]
        [InlineData("(?<-0>", RegexOptions.IgnorePatternWhitespace, RegexParseError.NotEnoughParentheses)]
        [InlineData(@"(?<cat>cat)\w+(?<dog-()*!@>dog)", RegexOptions.None, RegexParseError.InvalidGroupName)]
        [InlineData(@"(?<cat>cat)\w+(?<dog-catdog>dog)", RegexOptions.None, RegexParseError.UndefinedNameRef)]
        [InlineData(@"(?<cat>cat)\w+(?<dog-1uosn>dog)", RegexOptions.None, RegexParseError.InvalidGroupName)]
        [InlineData(@"(?<cat>cat)\w+(?<dog-16>dog)", RegexOptions.None, RegexParseError.UndefinedBackref)]
        [InlineData(@"cat(?<->dog)", RegexOptions.None, RegexParseError.InvalidGroupName)]
        [InlineData("a{2147483648}", RegexOptions.None, RegexParseError.CaptureGroupOutOfRange)]
        [InlineData("a{2147483648,}", RegexOptions.None, RegexParseError.CaptureGroupOutOfRange)]
        [InlineData("a{0,2147483647}", RegexOptions.None, null)]
        [InlineData("a{0,2147483648}", RegexOptions.None, RegexParseError.CaptureGroupOutOfRange)]
        // Surrogate pair which is parsed as [char,char-char,char] as we operate on UTF-16 code units.
        [InlineData("[\uD82F\uDCA0-\uD82F\uDCA3]", RegexOptions.IgnoreCase, RegexParseError.ReversedCharRange)]
        [SkipOnTargetFramework(TargetFrameworkMonikers.NetFramework)]
        public void Parse_NotNetFramework(string pattern, RegexOptions options, object error)
        {
            Parse(pattern, options, error);
        }

        [Fact]
        [SkipOnTargetFramework(TargetFrameworkMonikers.NetFramework)]
        public void RegexParseException_Serializes()
        {
#pragma warning disable RE0001 // Regex issue: Not enough )'s
            ArgumentException e = Assert.ThrowsAny<ArgumentException>(() => new Regex("(abc|def"));
#pragma warning restore RE0001 // Regex issue: Not enough )'s

            var bf = new BinaryFormatter();
            var s = new MemoryStream();
            bf.Serialize(s, e);
            s.Position = 0;

            ArgumentException e2 = (ArgumentException)bf.Deserialize(s);
            Assert.Equal(e.Message, e2.Message);
        }

        private static void ParseSubTrees(string pattern, RegexOptions options)
        {
            // Trim the input from the right and make sure tree invariants hold
            for (int i = pattern.Length - 1; i > 0; i--)
            {
                ParseSubTree(pattern.Substring(0, i), options);
            }

            // Trim the input from the left and make sure tree invariants hold
            for (int i = 1; i < pattern.Length; i++)
            {
                ParseSubTree(pattern.Substring(i), options);
            }

            // Skip middles
            for (int i = 1; i < pattern.Length; i++)
            {
                ParseSubTree(pattern.Substring(0, i) + pattern.Substring(i + 1), options);
            }
        }

        private static void ParseTree(string pattern, RegexOptions options, RegexParseError? error)
        {
            if (error != null)
            {
                Throws(error.Value, () => new Regex(pattern, options));
                return;
            }

            // Nothing to assert here without having access to internals.
            new Regex(pattern, options);
        }

        private static void ParseSubTree(string pattern, RegexOptions options)
        {
            try
            {
                new Regex(pattern, options);
            }
            catch (ArgumentException)
            {
                // We are fine with ArgumentExceptions being thrown during sub expression parsing.
            }
        }

        /// <summary>
        /// Checks if action throws either a RegexParseException or an ArgumentException depending on the
        /// environment and the supplied error.
        /// </summary>
        /// <param name="error">The expected parse error</param>
        /// <param name="action">The action to invoke.</param>
        private static void Throws(RegexParseError error, Action action)
        {
            // If no specific error is supplied, or we are running on .NET Framework where RegexParseException doesn't exist
            // we expect an ArgumentException.
            if (PlatformDetection.IsNetFramework)
            {
                Assert.ThrowsAny<ArgumentException>(action);
                return;
            }

            try
            {
                action();
            }
            catch (ArgumentException e)
            {
                // We use reflection to check if the exception is an internal RegexParseException
                // and extract its error property and compare with the given one.
                if (e.GetType() == s_parseExceptionType)
                {
                    RegexParseError regexParseError = (RegexParseError)s_parseErrorField.GetValue(e);

                    // Success if provided error matches.
                    if (error == regexParseError)
                        return;

                    throw new XunitException($"Expected RegexParseException with error: ({error}) -> Actual error: {regexParseError})");
                }

                throw new XunitException($"Expected RegexParseException -> Actual: ({e.GetType()})");
            }

            throw new XunitException($"Expected RegexParseException with error: ({error}) -> Actual: No exception thrown");
        }
    }
}