// The .NET Foundation licenses this file to you under the MIT license.
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
+ public partial 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.None, null)]
[InlineData("(?# )", RegexOptions.None, null)]
- [InlineData("(?#", RegexOptions.None, RegexParseError.UnterminatedComment)]
- [InlineData("(?# ", RegexOptions.None, RegexParseError.UnterminatedComment)]
+ [InlineData("(?#", RegexOptions.None, RegexParseError.UnterminatedComment, 3)]
+ [InlineData("(?# ", RegexOptions.None, RegexParseError.UnterminatedComment, 4)]
[InlineData("(?#)(?#)", RegexOptions.None, null)]
[InlineData("(?#)(?#)", RegexOptions.IgnorePatternWhitespace, null)]
[InlineData("(?#) (?#)", 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("(?", RegexOptions.None, RegexParseError.InvalidGroupingConstruct, 2)]
+ [InlineData("(?", RegexOptions.IgnorePatternWhitespace, RegexParseError.InvalidGroupingConstruct, 2)]
+ [InlineData("(? ", RegexOptions.None, RegexParseError.InvalidGroupingConstruct, 3)]
+ [InlineData("(? ", RegexOptions.IgnorePatternWhitespace, RegexParseError.InvalidGroupingConstruct, 3)]
[InlineData("(?i)", RegexOptions.None, null)]
[InlineData("(?im)", RegexOptions.None, null)]
[InlineData("(?im-x)", RegexOptions.None, 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("(?-x", RegexOptions.IgnorePatternWhitespace, RegexParseError.InvalidGroupingConstruct, 4)]
+ [InlineData("(?-x ", RegexOptions.IgnorePatternWhitespace, RegexParseError.InvalidGroupingConstruct, 5)]
+ [InlineData("(?-x :", RegexOptions.IgnorePatternWhitespace, RegexParseError.InvalidGroupingConstruct, 5)]
+ [InlineData("(?-x )", RegexOptions.IgnorePatternWhitespace, RegexParseError.InvalidGroupingConstruct, 5)]
+ [InlineData("(?-x :)", RegexOptions.IgnorePatternWhitespace, RegexParseError.InvalidGroupingConstruct, 5)]
+ [InlineData(")", RegexOptions.None, RegexParseError.InsufficientOpeningParentheses, 1)]
[InlineData("a", RegexOptions.None, null)]
[InlineData("ab", 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, RegexParseError.InsufficientClosingParentheses, 1)]
+ [InlineData("(a", RegexOptions.None, RegexParseError.InsufficientClosingParentheses, 2)]
[InlineData("|", RegexOptions.None, 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{1,0}", RegexOptions.None, RegexParseError.ReversedQuantifierRange, 6)]
[InlineData("a{0}?", RegexOptions.None, null)]
[InlineData("a{0,}?", RegexOptions.None, null)]
[InlineData("a{0,1}?", RegexOptions.None, 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("*", RegexOptions.None, RegexParseError.QuantifierAfterNothing, 1)]
+ [InlineData("(*)", RegexOptions.None, RegexParseError.QuantifierAfterNothing, 2)]
+ [InlineData("a**", RegexOptions.None, RegexParseError.NestedQuantifiersNotParenthesized, 3)]
+ [InlineData("+", RegexOptions.None, RegexParseError.QuantifierAfterNothing, 1)]
+ [InlineData("(+)", RegexOptions.None, RegexParseError.QuantifierAfterNothing, 2)]
+ [InlineData("a*+", RegexOptions.None, RegexParseError.NestedQuantifiersNotParenthesized, 3)]
+ [InlineData("?", RegexOptions.None, RegexParseError.QuantifierAfterNothing, 1)]
+ [InlineData("(?)", RegexOptions.None, RegexParseError.QuantifierAfterNothing, 2)]
+ [InlineData("a*??", RegexOptions.None, RegexParseError.NestedQuantifiersNotParenthesized, 4)]
+ [InlineData("{0}", RegexOptions.None, RegexParseError.QuantifierAfterNothing, 1)]
+ [InlineData("({0})", RegexOptions.None, RegexParseError.QuantifierAfterNothing, 2)]
+ [InlineData("a*{0}", RegexOptions.None, RegexParseError.NestedQuantifiersNotParenthesized, 3)]
[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(@"\c", RegexOptions.None, RegexParseError.MissingControlCharacter, 2)]
+ [InlineData(@"\c<", RegexOptions.None, RegexParseError.UnrecognizedControlCharacter, 3)]
[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 A", RegexOptions.None, RegexParseError.UnrecognizedControlCharacter, 3)]
+ [InlineData(@"\c(a)", RegexOptions.None, RegexParseError.UnrecognizedControlCharacter, 3)]
+ [InlineData(@"\c>", RegexOptions.None, RegexParseError.UnrecognizedControlCharacter, 3)]
+ [InlineData(@"\c?", RegexOptions.None, RegexParseError.UnrecognizedControlCharacter, 3)]
[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(@"\c`", RegexOptions.None, RegexParseError.UnrecognizedControlCharacter, 3)]
+ [InlineData(@"\c{", RegexOptions.None, RegexParseError.UnrecognizedControlCharacter, 3)]
[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(@"\m", RegexOptions.None, RegexParseError.UnrecognizedEscape, 2)]
+ [InlineData(@"\x", RegexOptions.None, RegexParseError.InsufficientOrInvalidHexDigits, 2)]
+ [InlineData(@"\x ", RegexOptions.None, RegexParseError.InsufficientOrInvalidHexDigits, 2)]
+ [InlineData(@"\x0", RegexOptions.None, RegexParseError.InsufficientOrInvalidHexDigits, 2)]
+ [InlineData(@"\x0 ", RegexOptions.None, RegexParseError.InsufficientOrInvalidHexDigits, 4)]
[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(@"\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(@"\xgg", RegexOptions.None, RegexParseError.InsufficientOrInvalidHexDigits, 3)]
+ [InlineData(@"\m ", RegexOptions.None, RegexParseError.UnrecognizedEscape, 2)]
+ [InlineData(@"\u", RegexOptions.None, RegexParseError.InsufficientOrInvalidHexDigits, 2)]
+ [InlineData(@"\u0", RegexOptions.None, RegexParseError.InsufficientOrInvalidHexDigits, 2)]
+ [InlineData(@"\u00", RegexOptions.None, RegexParseError.InsufficientOrInvalidHexDigits, 2)]
+ [InlineData(@"\u000", RegexOptions.None, RegexParseError.InsufficientOrInvalidHexDigits, 2)]
[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(@"\u ", RegexOptions.None, RegexParseError.InsufficientOrInvalidHexDigits, 2)]
+ [InlineData(@"\u0 ", RegexOptions.None, RegexParseError.InsufficientOrInvalidHexDigits, 2)]
+ [InlineData(@"\ugggg", RegexOptions.None, RegexParseError.InsufficientOrInvalidHexDigits, 3)]
[InlineData(@"\0", RegexOptions.None, null)]
[InlineData(@"\0 ", RegexOptions.None, null)]
[InlineData(@"\00", 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(@"\7", RegexOptions.None, RegexParseError.UndefinedNumberedReference, 2)]
[InlineData(@"\78", RegexOptions.None, null)]
- [InlineData(@"\8", RegexOptions.None, RegexParseError.UndefinedBackref)]
+ [InlineData(@"\8", RegexOptions.None, RegexParseError.UndefinedNumberedReference, 2)]
[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", RegexOptions.None, RegexParseError.MalformedNamedReference, 1)]
+ [InlineData(@"\k ", RegexOptions.None, RegexParseError.MalformedNamedReference, 3)]
+ [InlineData(@"\k<", RegexOptions.None, RegexParseError.MalformedNamedReference, 3)]
+ [InlineData(@"\k< ", RegexOptions.None, RegexParseError.UnrecognizedEscape, 2)]
+ [InlineData(@"\k<0", RegexOptions.None, RegexParseError.UnrecognizedEscape, 2)]
+ [InlineData(@"\k<0 ", RegexOptions.None, RegexParseError.UnrecognizedEscape, 2)]
[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(@"\k<a> ", RegexOptions.None, RegexParseError.UndefinedNamedReference, 5)]
[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, RegexParseError.MalformedNamedReference, 1)]
+ [InlineData(@"\k ", RegexOptions.ECMAScript, RegexParseError.MalformedNamedReference, 3)]
+ [InlineData(@"\k<", RegexOptions.ECMAScript, RegexParseError.MalformedNamedReference, 3)]
[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'", RegexOptions.None, RegexParseError.MalformedNamedReference, 3)]
+ [InlineData(@"\k' ", RegexOptions.None, RegexParseError.UnrecognizedEscape, 2)]
+ [InlineData(@"\k'0", RegexOptions.None, RegexParseError.UnrecognizedEscape, 2)]
+ [InlineData(@"\k'0 ", RegexOptions.None, RegexParseError.UnrecognizedEscape, 2)]
[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(@"\k'a' ", RegexOptions.None, RegexParseError.UndefinedNamedReference, 5)]
[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(@"\k<0' ", RegexOptions.None, RegexParseError.UnrecognizedEscape, 2)]
+ [InlineData(@"\k'0> ", RegexOptions.None, RegexParseError.UnrecognizedEscape, 2)]
+ [InlineData(@"\", RegexOptions.None, RegexParseError.UnescapedEndingBackslash, 1)]
[InlineData(@"\ ", RegexOptions.None, null)]
[InlineData(@"\<", RegexOptions.None, null)]
[InlineData(@"\< ", 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> ", RegexOptions.None, RegexParseError.UndefinedNamedReference, 4)]
[InlineData(@"(?<a>)\<a> ", RegexOptions.None, null)]
- [InlineData(@"\", RegexOptions.ECMAScript, RegexParseError.IllegalEndEscape)]
+ [InlineData(@"\", RegexOptions.ECMAScript, RegexParseError.UnescapedEndingBackslash, 1)]
[InlineData(@"\ ", RegexOptions.ECMAScript, null)]
[InlineData(@"\<", RegexOptions.ECMAScript, null)]
[InlineData(@"\< ", RegexOptions.ECMAScript, null)]
[InlineData(@"\'0'", RegexOptions.None, null)]
[InlineData(@"\'0' ", RegexOptions.None, null)]
[InlineData(@"\'00' ", RegexOptions.None, null)]
- [InlineData(@"\'a' ", RegexOptions.None, RegexParseError.UndefinedNameRef)]
+ [InlineData(@"\'a' ", RegexOptions.None, RegexParseError.UndefinedNamedReference, 4)]
[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{ Cc }", RegexOptions.None, RegexParseError.InvalidUnicodePropertyEscape, 4)]
+ [InlineData("\\p{ Cc }", RegexOptions.IgnorePatternWhitespace, RegexParseError.InvalidUnicodePropertyEscape, 4)]
+ [InlineData("\\p {Cc}", RegexOptions.IgnorePatternWhitespace, RegexParseError.MalformedUnicodePropertyEscape, 3)]
+ [InlineData("\\p{xxx}", RegexOptions.None, RegexParseError.UnrecognizedUnicodeProperty, 7)]
+ [InlineData("\\p", RegexOptions.None, RegexParseError.InvalidUnicodePropertyEscape, 2)]
+ [InlineData("\\p{", RegexOptions.None, RegexParseError.InvalidUnicodePropertyEscape, 2)]
+ [InlineData("\\p{}", RegexOptions.None, RegexParseError.InvalidUnicodePropertyEscape, 2)]
+ [InlineData("\\p{} ", RegexOptions.None, RegexParseError.UnrecognizedUnicodeProperty, 4)]
+ [InlineData("\\p {} ", RegexOptions.None, RegexParseError.MalformedUnicodePropertyEscape, 3)]
+ [InlineData("\\p{Cc ", RegexOptions.None, RegexParseError.InvalidUnicodePropertyEscape, 6)]
[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, RegexParseError.InsufficientClosingParentheses, 3)]
+ [InlineData("(?: ", RegexOptions.IgnorePatternWhitespace, RegexParseError.InsufficientClosingParentheses, 4)]
[InlineData("(?=)", RegexOptions.None, null)]
[InlineData("(?=a)", RegexOptions.None, null)]
- [InlineData("(?=", RegexOptions.None, RegexParseError.NotEnoughParentheses)]
- [InlineData("(?= ", RegexOptions.IgnorePatternWhitespace, RegexParseError.NotEnoughParentheses)]
+ [InlineData("(?=", RegexOptions.None, RegexParseError.InsufficientClosingParentheses, 3)]
+ [InlineData("(?= ", RegexOptions.IgnorePatternWhitespace, RegexParseError.InsufficientClosingParentheses, 4)]
[InlineData("(?!)", RegexOptions.None, null)]
[InlineData("(?!a)", RegexOptions.None, null)]
- [InlineData("(?!", RegexOptions.None, RegexParseError.NotEnoughParentheses)]
- [InlineData("(?! ", RegexOptions.IgnorePatternWhitespace, RegexParseError.NotEnoughParentheses)]
+ [InlineData("(?!", RegexOptions.None, RegexParseError.InsufficientClosingParentheses, 3)]
+ [InlineData("(?! ", RegexOptions.IgnorePatternWhitespace, RegexParseError.InsufficientClosingParentheses, 4)]
[InlineData("(?>)", RegexOptions.None, null)]
[InlineData("(?>a)", RegexOptions.None, null)]
- [InlineData("(?>", RegexOptions.None, RegexParseError.NotEnoughParentheses)]
- [InlineData("(?> ", RegexOptions.IgnorePatternWhitespace, RegexParseError.NotEnoughParentheses)]
+ [InlineData("(?>", RegexOptions.None, RegexParseError.InsufficientClosingParentheses, 3)]
+ [InlineData("(?> ", RegexOptions.IgnorePatternWhitespace, RegexParseError.InsufficientClosingParentheses, 4)]
[InlineData("(?<=)", RegexOptions.None, null)]
[InlineData("(?<=a)", RegexOptions.None, null)]
- [InlineData("(?<=", RegexOptions.None, RegexParseError.NotEnoughParentheses)]
- [InlineData("(?<= ", RegexOptions.IgnorePatternWhitespace, RegexParseError.NotEnoughParentheses)]
+ [InlineData("(?<=", RegexOptions.None, RegexParseError.InsufficientClosingParentheses, 4)]
+ [InlineData("(?<= ", RegexOptions.IgnorePatternWhitespace, RegexParseError.InsufficientClosingParentheses, 5)]
[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("(?<!", RegexOptions.None, RegexParseError.InsufficientClosingParentheses,4)]
+ [InlineData("(?<! ", RegexOptions.IgnorePatternWhitespace, RegexParseError.InsufficientClosingParentheses, 5)]
+ [InlineData("(?<", RegexOptions.IgnorePatternWhitespace, RegexParseError.InvalidGroupingConstruct, 3)]
+ [InlineData("(?<>", RegexOptions.IgnorePatternWhitespace, RegexParseError.CaptureGroupNameInvalid, 3)]
+ [InlineData("(?<a", RegexOptions.IgnorePatternWhitespace, RegexParseError.InvalidGroupingConstruct, 4)]
+ [InlineData("(?<a>", RegexOptions.IgnorePatternWhitespace, RegexParseError.InsufficientClosingParentheses, 5)]
+ [InlineData("(?<a>a", RegexOptions.IgnorePatternWhitespace, RegexParseError.InsufficientClosingParentheses, 6)]
[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("(?<a >a)", RegexOptions.None, RegexParseError.CaptureGroupNameInvalid, 4)]
+ [InlineData("(?<a >a)", RegexOptions.IgnorePatternWhitespace, RegexParseError.CaptureGroupNameInvalid, 4)]
+ [InlineData("(?< a>a)", RegexOptions.None, RegexParseError.CaptureGroupNameInvalid, 3)]
+ [InlineData("(?< a>a)", RegexOptions.IgnorePatternWhitespace, RegexParseError.CaptureGroupNameInvalid, 3)]
+ [InlineData("(?< a >a)", RegexOptions.None, RegexParseError.CaptureGroupNameInvalid, 3)]
+ [InlineData("(?< a >a)", RegexOptions.IgnorePatternWhitespace, RegexParseError.CaptureGroupNameInvalid, 3)]
[InlineData("(?<ab>a)", RegexOptions.IgnorePatternWhitespace, null)]
- [InlineData("(?<0>a)", RegexOptions.IgnorePatternWhitespace, RegexParseError.CapnumNotZero)]
+ [InlineData("(?<0>a)", RegexOptions.IgnorePatternWhitespace, RegexParseError.CaptureGroupOfZero, 4)]
[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("(?(", RegexOptions.IgnorePatternWhitespace, RegexParseError.InsufficientClosingParentheses, 3)]
+ [InlineData("(?(0", RegexOptions.IgnorePatternWhitespace, RegexParseError.AlternationHasMalformedReference, 4)]
+ [InlineData("(?(0)", RegexOptions.IgnorePatternWhitespace, RegexParseError.InsufficientClosingParentheses, 5)]
[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("(?(0)a|b|)", RegexOptions.IgnorePatternWhitespace, RegexParseError.AlternationHasTooManyConditions, 10)]
+ [InlineData("(?(0)a|b|c)", RegexOptions.IgnorePatternWhitespace, RegexParseError.AlternationHasTooManyConditions, 11)]
+ [InlineData("(?(0 )", RegexOptions.IgnorePatternWhitespace, RegexParseError.AlternationHasMalformedReference, 5)]
+ [InlineData("(?(1))", RegexOptions.IgnorePatternWhitespace, RegexParseError.AlternationHasUndefinedReference, 5)]
[InlineData("(?(00))", RegexOptions.IgnorePatternWhitespace, null)]
[InlineData("(?(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, RegexParseError.AlternationHasNamedCapture, 2)]
+ [InlineData("(?(?'x'))", RegexOptions.IgnorePatternWhitespace, RegexParseError.AlternationHasNamedCapture, 2)]
+ [InlineData("(?(?#", RegexOptions.IgnorePatternWhitespace, RegexParseError.UnterminatedComment, 5)]
+ [InlineData("(?(?#)", RegexOptions.IgnorePatternWhitespace, RegexParseError.AlternationHasComment, 2)]
+ [InlineData("(?(?#))", RegexOptions.IgnorePatternWhitespace, RegexParseError.AlternationHasComment, 2)]
+ [InlineData("(?(?<", RegexOptions.IgnorePatternWhitespace, RegexParseError.InvalidGroupingConstruct, 5)]
+ [InlineData("(?(?<a", RegexOptions.IgnorePatternWhitespace, RegexParseError.AlternationHasNamedCapture, 2)]
+ [InlineData("(?(?<a>", RegexOptions.IgnorePatternWhitespace, RegexParseError.AlternationHasNamedCapture, 2)]
+ [InlineData("(?(?<a>)", RegexOptions.IgnorePatternWhitespace, RegexParseError.AlternationHasNamedCapture, 2)]
+ [InlineData("(?(?<a>))", RegexOptions.IgnorePatternWhitespace, RegexParseError.AlternationHasNamedCapture, 2)]
[InlineData("(?(?<=))", RegexOptions.IgnorePatternWhitespace, null)]
[InlineData("(?(?<!))", RegexOptions.IgnorePatternWhitespace, null)]
- [InlineData(@"\1", RegexOptions.None, RegexParseError.UndefinedBackref)]
- [InlineData(@"\1 ", RegexOptions.None, RegexParseError.UndefinedBackref)]
+ [InlineData(@"\1", RegexOptions.None, RegexParseError.UndefinedNumberedReference, 2)]
+ [InlineData(@"\1 ", RegexOptions.None, RegexParseError.UndefinedNumberedReference, 2)]
[InlineData(@"()\1", RegexOptions.None, null)]
[InlineData(@"()\1 ", RegexOptions.None, null)]
[InlineData(@"()\10 ", RegexOptions.None, 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(@"[", RegexOptions.None, RegexParseError.UnterminatedBracket, 1)]
+ [InlineData(@"[ ", RegexOptions.None, RegexParseError.UnterminatedBracket, 2)]
+ [InlineData(@"[]", RegexOptions.None, RegexParseError.UnterminatedBracket, 2)]
+ [InlineData(@"[] ", RegexOptions.None, RegexParseError.UnterminatedBracket, 3)]
[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, RegexParseError.UnterminatedBracket, 3)]
+ [InlineData(@"[a- ", RegexOptions.None, RegexParseError.UnterminatedBracket, 4)]
[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]-c] ", RegexOptions.None, RegexParseError.ExclusionGroupNotLast, 6)]
+ [InlineData(@"[a-z-[b]12]", RegexOptions.None, RegexParseError.ExclusionGroupNotLast, 8)]
[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(@"[a-\w] ", RegexOptions.None, RegexParseError.ShorthandClassInCharacterRange, 5)]
+ [InlineData(@"[\p{llll}-a] ", RegexOptions.None, RegexParseError.UnrecognizedUnicodeProperty, 9)]
[InlineData(@"[\p{Lu}-a] ", RegexOptions.None, null)]
- [InlineData(@"[a-\p{Lu}] ", RegexOptions.None, RegexParseError.BadClassInCharRange)]
+ [InlineData(@"[a-\p{Lu}] ", RegexOptions.None, RegexParseError.ShorthandClassInCharacterRange, 5)]
[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(@"[a-[:", RegexOptions.None, RegexParseError.UnterminatedBracket, 5)]
+ [InlineData(@"[a-[:L", RegexOptions.None, RegexParseError.UnterminatedBracket, 6)]
+ [InlineData(@"[a-[:L:", RegexOptions.None, RegexParseError.UnterminatedBracket, 7)]
+ [InlineData(@"[a-[:L:]", RegexOptions.None, RegexParseError.UnterminatedBracket, 8)]
[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, RegexParseError.UnterminatedBracket, 5)]
[InlineData(@"[--b] ", RegexOptions.None, null)]
- [InlineData(@"[--[b ", RegexOptions.None, RegexParseError.UnterminatedBracket)]
- [InlineData(@"[--[b] ", RegexOptions.None, RegexParseError.SubtractionMustBeLast)]
+ [InlineData(@"[--[b ", RegexOptions.None, RegexParseError.UnterminatedBracket, 6)]
+ [InlineData(@"[--[b] ", RegexOptions.None, RegexParseError.ExclusionGroupNotLast, 6)]
[InlineData(@"[--[b]] ", RegexOptions.None, null)]
- [InlineData(@"[a--[b ", RegexOptions.None, RegexParseError.UnterminatedBracket)]
+ [InlineData(@"[a--[b ", RegexOptions.None, RegexParseError.UnterminatedBracket, 7)]
[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(@"[\c<-\c>]", RegexOptions.None, RegexParseError.UnrecognizedControlCharacter, 4)]
+ [InlineData(@"[\c>-\c<]", RegexOptions.None, RegexParseError.UnrecognizedControlCharacter, 4)]
+ [InlineData(@"[\c>-a]", RegexOptions.None, RegexParseError.UnrecognizedControlCharacter, 4)]
+ [InlineData(@"[a-\c>]", RegexOptions.None, RegexParseError.UnrecognizedControlCharacter, 6)]
+ [InlineData(@"[a--]", RegexOptions.None, RegexParseError.ReversedCharacterRange, 4)]
[InlineData(@"[--a]", RegexOptions.None, null)]
[InlineData(@"[\--a]", RegexOptions.None, null)]
[InlineData(@"[\0-\1]", RegexOptions.None, null)]
- [InlineData(@"[\1-\0]", RegexOptions.None, RegexParseError.ReversedCharRange)]
+ [InlineData(@"[\1-\0]", RegexOptions.None, RegexParseError.ReversedCharacterRange, 6)]
[InlineData(@"[\0-\01]", RegexOptions.None, null)]
- [InlineData(@"[\01-\0]", RegexOptions.None, RegexParseError.ReversedCharRange)]
+ [InlineData(@"[\01-\0]", RegexOptions.None, RegexParseError.ReversedCharacterRange, 7)]
[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-\0]", RegexOptions.None, RegexParseError.ReversedCharacterRange, 7)]
[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(@"[\u0-\u1]", RegexOptions.None, RegexParseError.InsufficientOrInvalidHexDigits, 5)]
+ [InlineData(@"[\u1-\u0]", RegexOptions.None, RegexParseError.InsufficientOrInvalidHexDigits, 5)]
[InlineData(@"[\u0000-\u0000]", RegexOptions.None, null)]
[InlineData(@"[\u0000-\u0001]", RegexOptions.None, null)]
- [InlineData(@"[\u0001-\u0000]", RegexOptions.None, RegexParseError.ReversedCharRange)]
+ [InlineData(@"[\u0001-\u0000]", RegexOptions.None, RegexParseError.ReversedCharacterRange, 14)]
[InlineData(@"[\u0001-a]", RegexOptions.None, null)]
- [InlineData(@"[a-\u0001]", RegexOptions.None, RegexParseError.ReversedCharRange)]
+ [InlineData(@"[a-\u0001]", RegexOptions.None, RegexParseError.ReversedCharacterRange, 9)]
[InlineData(@"[a-a]", RegexOptions.None, null)]
- [InlineData(@"[a-A]", RegexOptions.None, RegexParseError.ReversedCharRange)]
+ [InlineData(@"[a-A]", RegexOptions.None, RegexParseError.ReversedCharacterRange, 4)]
[InlineData(@"[A-a]", RegexOptions.None, null)]
[InlineData(@"[a-a]", RegexOptions.IgnoreCase, null)]
- [InlineData(@"[a-A]", RegexOptions.IgnoreCase, RegexParseError.ReversedCharRange)]
+ [InlineData(@"[a-A]", RegexOptions.IgnoreCase, RegexParseError.ReversedCharacterRange, 4)]
[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-\x60]", RegexOptions.None, RegexParseError.ReversedCharacterRange, 7)]
+ [InlineData(@"[\x62-a]", RegexOptions.None, RegexParseError.ReversedCharacterRange, 7)]
[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-\2]", RegexOptions.None, RegexParseError.ReversedCharacterRange, 7)]
+ [InlineData(@"[\4-\cc]", RegexOptions.None, RegexParseError.ReversedCharacterRange, 7)]
[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(@"[\cb-\ca]", RegexOptions.None, RegexParseError.ReversedCharacterRange, 8)]
+ [InlineData(@"[\cb-\cA]", RegexOptions.None, RegexParseError.ReversedCharacterRange, 8)]
+ [InlineData(@"[\cB-\ca]", RegexOptions.None, RegexParseError.ReversedCharacterRange, 8)]
+ [InlineData(@"[\cB-\cA]", RegexOptions.None, RegexParseError.ReversedCharacterRange, 8)]
[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(@"[b-\-a]", RegexOptions.None, RegexParseError.ReversedCharacterRange, 5)]
+ [InlineData(@"[b-\-\-a]", RegexOptions.None, RegexParseError.ReversedCharacterRange, 5)]
+ [InlineData(@"()\2", RegexOptions.None, RegexParseError.UndefinedNumberedReference, 4)]
[InlineData(@"()()\2", RegexOptions.None, null)]
- [InlineData(@"()\1", RegexOptions.ExplicitCapture, RegexParseError.UndefinedBackref)]
- [InlineData(@"()\2", RegexOptions.ExplicitCapture, RegexParseError.UndefinedBackref)]
- [InlineData(@"()()\2", RegexOptions.ExplicitCapture, RegexParseError.UndefinedBackref)]
+ [InlineData(@"()\1", RegexOptions.ExplicitCapture, RegexParseError.UndefinedNumberedReference, 4)]
+ [InlineData(@"()\2", RegexOptions.ExplicitCapture, RegexParseError.UndefinedNumberedReference, 4)]
+ [InlineData(@"()()\2", RegexOptions.ExplicitCapture, RegexParseError.UndefinedNumberedReference, 6)]
[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, RegexParseError.UndefinedNumberedReference, 12)]
+ [InlineData(@"(?n)()()\1\2", RegexOptions.None, RegexParseError.UndefinedNumberedReference, 10)]
+ [InlineData(@"()()(?n)\1\2", RegexOptions.ExplicitCapture, RegexParseError.UndefinedNumberedReference, 10)]
+ [InlineData(@"()(?n)()\1\2", RegexOptions.ExplicitCapture, RegexParseError.UndefinedNumberedReference, 10)]
+ [InlineData(@"(?n)()()\1\2", RegexOptions.ExplicitCapture, RegexParseError.UndefinedNumberedReference, 10)]
[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, RegexParseError.UndefinedNumberedReference, 11)]
+ [InlineData(@"()(?-n)()\1\2", RegexOptions.ExplicitCapture, RegexParseError.UndefinedNumberedReference, 13)]
[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.ExplicitCapture, RegexParseError.UndefinedNumberedReference, 10)]
[InlineData(@"()()(?-n:\1\2)", RegexOptions.None, null)]
- [InlineData(@"()()(?-n:\1\2)", RegexOptions.ExplicitCapture, RegexParseError.UndefinedBackref)]
+ [InlineData(@"()()(?-n:\1\2)", RegexOptions.ExplicitCapture, RegexParseError.UndefinedNumberedReference, 11)]
[InlineData(@"(?n:)()()\1\2", RegexOptions.None, null)]
- [InlineData(@"(?n:)()()\1\2", RegexOptions.ExplicitCapture, RegexParseError.UndefinedBackref)]
+ [InlineData(@"(?n:)()()\1\2", RegexOptions.ExplicitCapture, RegexParseError.UndefinedNumberedReference, 11)]
[InlineData(@"(?-n:)()()\1\2", RegexOptions.None, null)]
- [InlineData(@"(?-n:)()()\1\2", RegexOptions.ExplicitCapture, RegexParseError.UndefinedBackref)]
+ [InlineData(@"(?-n:)()()\1\2", RegexOptions.ExplicitCapture, RegexParseError.UndefinedNumberedReference, 12)]
[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)]
+ [InlineData(@"(?-n)(?n)()()\1\2", RegexOptions.None, RegexParseError.UndefinedNumberedReference, 15)]
+ [InlineData(@"(?-n)(?n)()()\1\2", RegexOptions.ExplicitCapture, RegexParseError.UndefinedNumberedReference, 15)]
// References
[InlineData(@"[aeiou]", RegexOptions.None, null)]
[InlineData(@"(?<duplicateWord>\w+)\s\k<duplicateWord>\W(?<nextWord>\w+)", 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(@"((\w+(\s?)){2,}", RegexOptions.None, RegexParseError.InsufficientClosingParentheses, 15)]
[InlineData(@"[a-z-[djp]]", RegexOptions.None, null)]
[InlineData(@"(\w)\1+.\b", RegexOptions.None, null)]
[InlineData(@"\d{4}\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)
+ public void Parse(string pattern, RegexOptions options, object errorObj, int offset = -1)
{
RegexParseError? error = (RegexParseError?)errorObj;
+ Assert.True(error == null || offset > 0, "All tests must be given positive offsets, or null if no offset should be tested.");
+
// Parse the main tree and if parsing fails check if the supplied error matches.
- ParseTree(pattern, options, error);
+ ParseTree(pattern, options, error, offset);
// 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);
- }
-
- [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsBinaryFormatterSupported))]
- [SkipOnTargetFramework(TargetFrameworkMonikers.NetFramework)]
- public void RegexParseException_Serializes()
+ // Negative tests
+ [InlineData(@"cat([a-\d]*)dog", RegexOptions.None, RegexParseError.ShorthandClassInCharacterRange, 9)]
+ [InlineData(@"\k<1", RegexOptions.None, RegexParseError.UnrecognizedEscape, 2)]
+ [InlineData(@"(?')", RegexOptions.None, RegexParseError.CaptureGroupNameInvalid, 3)]
+ [InlineData(@"(?<)", RegexOptions.None, RegexParseError.CaptureGroupNameInvalid, 3)]
+ [InlineData(@"(?imn )", RegexOptions.None, RegexParseError.InvalidGroupingConstruct, 6)]
+ [InlineData(@"(?imn", RegexOptions.None, RegexParseError.InvalidGroupingConstruct, 5)]
+ [InlineData(@"(?'cat'", RegexOptions.None, RegexParseError.InsufficientClosingParentheses, 7)]
+ [InlineData(@"(?'", RegexOptions.None, RegexParseError.InvalidGroupingConstruct, 3)]
+ [InlineData(@"(?'=)", RegexOptions.None, RegexParseError.InvalidGroupingConstruct, 4)]
+ [InlineData(@"(?'!)", RegexOptions.None, RegexParseError.InvalidGroupingConstruct, 4)]
+ [InlineData(@"[^", RegexOptions.None, RegexParseError.UnterminatedBracket, 2)]
+ [InlineData(@"[cat", RegexOptions.None, RegexParseError.UnterminatedBracket, 4)]
+ [InlineData(@"[^cat", RegexOptions.None, RegexParseError.UnterminatedBracket, 5)]
+ [InlineData(@"\p{cat", RegexOptions.None, RegexParseError.InvalidUnicodePropertyEscape, 6)]
+ [InlineData(@"\k<cat", RegexOptions.None, RegexParseError.UnrecognizedEscape, 2)]
+ [InlineData(@"\p{cat}", RegexOptions.None, RegexParseError.UnrecognizedUnicodeProperty, 7)]
+ [InlineData(@"\P{cat", RegexOptions.None, RegexParseError.InvalidUnicodePropertyEscape, 6)]
+ [InlineData(@"\P{cat}", RegexOptions.None, RegexParseError.UnrecognizedUnicodeProperty, 7)]
+ [InlineData(@"(?<cat>", RegexOptions.None, RegexParseError.InsufficientClosingParentheses, 7)]
+ [InlineData(@"\P{", RegexOptions.None, RegexParseError.InvalidUnicodePropertyEscape, 2)]
+ [InlineData(@"\k<>", RegexOptions.None, RegexParseError.UnrecognizedEscape, 2)]
+ [InlineData(@"(?(", RegexOptions.None, RegexParseError.InsufficientClosingParentheses, 3)]
+ [InlineData(@"(?()|", RegexOptions.None, RegexParseError.InsufficientClosingParentheses, 5)]
+ [InlineData(@"?(a|b)", RegexOptions.None, RegexParseError.QuantifierAfterNothing, 1)]
+ [InlineData(@"?((a)", RegexOptions.None, RegexParseError.QuantifierAfterNothing, 1)]
+ [InlineData(@"?((a)a", RegexOptions.None, RegexParseError.QuantifierAfterNothing, 1)]
+ [InlineData(@"?((a)a|", RegexOptions.None, RegexParseError.QuantifierAfterNothing, 1)]
+ [InlineData(@"?((a)a|b", RegexOptions.None, RegexParseError.QuantifierAfterNothing, 1)]
+ [InlineData(@"?(a)", RegexOptions.None, RegexParseError.QuantifierAfterNothing, 1)]
+ [InlineData(@"[a", RegexOptions.None, RegexParseError.UnterminatedBracket, 2)]
+ [InlineData(@"?(a:b)", RegexOptions.None, RegexParseError.QuantifierAfterNothing, 1)]
+ [InlineData(@"(?(?", RegexOptions.None, RegexParseError.InvalidGroupingConstruct, 4)]
+ [InlineData(@"(?(cat", RegexOptions.None, RegexParseError.InsufficientClosingParentheses, 6)]
+ [InlineData(@"(?(cat)|", RegexOptions.None, RegexParseError.InsufficientClosingParentheses, 8)]
+ [InlineData(@"foo(?<0>bar)", RegexOptions.None, RegexParseError.CaptureGroupOfZero, 7)]
+ [InlineData(@"foo(?'0'bar)", RegexOptions.None, RegexParseError.CaptureGroupOfZero, 7)]
+ [InlineData(@"foo(?<1bar)", RegexOptions.None, RegexParseError.CaptureGroupNameInvalid, 7)]
+ [InlineData(@"foo(?'1bar)", RegexOptions.None, RegexParseError.CaptureGroupNameInvalid, 7)]
+ [InlineData(@"\p{klsak", RegexOptions.None, RegexParseError.InvalidUnicodePropertyEscape, 8)]
+ [InlineData(@"(?c:cat)", RegexOptions.None, RegexParseError.InvalidGroupingConstruct, 3)]
+ [InlineData(@"(??e:cat)", RegexOptions.None, RegexParseError.InvalidGroupingConstruct, 3)]
+ [InlineData(@"[a-f-[]]+", RegexOptions.None, RegexParseError.UnterminatedBracket, 9)]
+ [InlineData(@"[A-[]+", RegexOptions.None, RegexParseError.UnterminatedBracket, 6)]
+ [InlineData(@"(?(?e))", RegexOptions.None, RegexParseError.InvalidGroupingConstruct, 5)]
+ [InlineData(@"(?(?a)", RegexOptions.None, RegexParseError.InvalidGroupingConstruct, 5)]
+ [InlineData(@"(?r:cat)", RegexOptions.None, RegexParseError.InvalidGroupingConstruct, 3)]
+ [InlineData(@"\x2", RegexOptions.None, RegexParseError.InsufficientOrInvalidHexDigits, 2)]
+ [InlineData(@"(cat) (?#cat) \s+ (?#followed by 1 or more whitespace", RegexOptions.IgnorePatternWhitespace, RegexParseError.UnterminatedComment, 56)]
+ [InlineData(@"cat(?(?afdcat)dog)", RegexOptions.None, RegexParseError.InvalidGroupingConstruct, 8)]
+ [InlineData(@"cat(?(?<cat>cat)dog)", RegexOptions.None, RegexParseError.AlternationHasNamedCapture, 5)]
+ [InlineData(@"cat(?(?'cat'cat)dog)", RegexOptions.None, RegexParseError.AlternationHasNamedCapture, 5)]
+ [InlineData(@"cat(?(?#COMMENT)cat)", RegexOptions.None, RegexParseError.AlternationHasComment, 5)]
+ [InlineData(@"cat(?<>dog)", RegexOptions.None, RegexParseError.CaptureGroupNameInvalid, 6)]
+ [InlineData(@"cat(?<dog<>)_*>dog)", RegexOptions.None, RegexParseError.CaptureGroupNameInvalid, 9)]
+ [InlineData(@"cat(?<dog >)_*>dog)", RegexOptions.None, RegexParseError.CaptureGroupNameInvalid, 9)]
+ [InlineData(@"cat(?<dog!>)_*>dog)", RegexOptions.None, RegexParseError.CaptureGroupNameInvalid, 9)]
+ [InlineData(@"cat(?<dog)_*>dog)", RegexOptions.None, RegexParseError.CaptureGroupNameInvalid, 9)]
+ [InlineData(@"cat(?<1dog>dog)", RegexOptions.None, RegexParseError.CaptureGroupNameInvalid, 7)]
+ [InlineData(@"cat(?<0>dog)", RegexOptions.None, RegexParseError.CaptureGroupOfZero, 7)]
+ [InlineData(@"([5-\D]*)dog", RegexOptions.None, RegexParseError.ShorthandClassInCharacterRange, 6)]
+ [InlineData(@"cat([6-\s]*)dog", RegexOptions.None, RegexParseError.ShorthandClassInCharacterRange, 9)]
+ [InlineData(@"cat([c-\S]*)", RegexOptions.None, RegexParseError.ShorthandClassInCharacterRange, 9)]
+ [InlineData(@"cat([7-\w]*)", RegexOptions.None, RegexParseError.ShorthandClassInCharacterRange, 9)]
+ [InlineData(@"cat([a-\W]*)dog", RegexOptions.None, RegexParseError.ShorthandClassInCharacterRange, 9)]
+ [InlineData(@"([f-\p{Lu}]\w*)\s([\p{Lu}]\w*)", RegexOptions.None, RegexParseError.ShorthandClassInCharacterRange, 6)]
+ [InlineData(@"(cat) (?#cat) \s+ (?#followed by 1 or more whitespace", RegexOptions.None, RegexParseError.UnterminatedComment, 56)]
+ [InlineData(@"([1-\P{Ll}][\p{Ll}]*)\s([\P{Ll}][\p{Ll}]*)", RegexOptions.None, RegexParseError.ShorthandClassInCharacterRange, 6)]
+ [InlineData(@"[\P]", RegexOptions.None, RegexParseError.InvalidUnicodePropertyEscape, 3)]
+ [InlineData(@"([\pcat])", RegexOptions.None, RegexParseError.MalformedUnicodePropertyEscape, 5)]
+ [InlineData(@"([\Pcat])", RegexOptions.None, RegexParseError.MalformedUnicodePropertyEscape, 5)]
+ [InlineData(@"(\p{", RegexOptions.None, RegexParseError.InvalidUnicodePropertyEscape, 3)]
+ [InlineData(@"(\p{Ll", RegexOptions.None, RegexParseError.InvalidUnicodePropertyEscape, 6)]
+ [InlineData(@"(cat)([\o]*)(dog)", RegexOptions.None, RegexParseError.UnrecognizedEscape, 9)]
+ [InlineData(@"[\p]", RegexOptions.None, RegexParseError.InvalidUnicodePropertyEscape, 3)]
+ [InlineData(@"(?<cat>cat)\s+(?<dog>dog)\kcat", RegexOptions.None, RegexParseError.MalformedNamedReference, 28)]
+ [InlineData(@"(?<cat>cat)\s+(?<dog>dog)\k<cat2>", RegexOptions.None, RegexParseError.UndefinedNamedReference, 33)]
+ [InlineData(@"(?<cat>cat)\s+(?<dog>dog)\k<8>cat", RegexOptions.None, RegexParseError.UndefinedNumberedReference, 30)]
+ [InlineData(@"^[abcd]{1}?*$", RegexOptions.None, RegexParseError.NestedQuantifiersNotParenthesized, 12)]
+ [InlineData(@"^[abcd]*+$", RegexOptions.None, RegexParseError.NestedQuantifiersNotParenthesized, 9)]
+ [InlineData(@"^[abcd]+*$", RegexOptions.None, RegexParseError.NestedQuantifiersNotParenthesized, 9)]
+ [InlineData(@"^[abcd]?*$", RegexOptions.None, RegexParseError.NestedQuantifiersNotParenthesized, 9)]
+ [InlineData(@"^[abcd]*?+$", RegexOptions.None, RegexParseError.NestedQuantifiersNotParenthesized, 10)]
+ [InlineData(@"^[abcd]+?*$", RegexOptions.None, RegexParseError.NestedQuantifiersNotParenthesized, 10)]
+ [InlineData(@"^[abcd]{1,}?*$", RegexOptions.None, RegexParseError.NestedQuantifiersNotParenthesized, 13)]
+ [InlineData(@"^[abcd]??*$", RegexOptions.None, RegexParseError.NestedQuantifiersNotParenthesized, 10)]
+ [InlineData(@"^[abcd]+{0,5}$", RegexOptions.None, RegexParseError.NestedQuantifiersNotParenthesized, 9)]
+ [InlineData(@"^[abcd]?{0,5}$", RegexOptions.None, RegexParseError.NestedQuantifiersNotParenthesized, 9)]
+ [InlineData(@"\ua", RegexOptions.None, RegexParseError.InsufficientOrInvalidHexDigits, 2)]
+ [InlineData(@"^[abcd]*{0,5}$", RegexOptions.None, RegexParseError.NestedQuantifiersNotParenthesized, 9)]
+ [InlineData(@"^[abcd]{0,16}?*$", RegexOptions.None, RegexParseError.NestedQuantifiersNotParenthesized, 15)]
+ [InlineData(@"^[abcd]{1,}*$", RegexOptions.None, RegexParseError.NestedQuantifiersNotParenthesized, 12)]
+ [InlineData(@"(?<cat>cat)\s+(?<dog>dog)\k<8>cat", RegexOptions.ECMAScript, RegexParseError.UndefinedNumberedReference, 30)]
+ [InlineData(@"(?<cat>cat)\s+(?<dog>dog)\k8", RegexOptions.None, RegexParseError.MalformedNamedReference, 28)]
+ [InlineData(@"(?<cat>cat)\s+(?<dog>dog)\k8", RegexOptions.ECMAScript, RegexParseError.MalformedNamedReference, 28)]
+ [InlineData(@"(cat)(\7)", RegexOptions.None, RegexParseError.UndefinedNumberedReference, 8)]
+ [InlineData(@"(cat)\s+(?<2147483648>dog)", RegexOptions.None, RegexParseError.QuantifierOrCaptureGroupOutOfRange, 21)]
+ [InlineData(@"(cat)\s+(?<21474836481097>dog)", RegexOptions.None, RegexParseError.QuantifierOrCaptureGroupOutOfRange, 21)]
+ [InlineData(@"^[abcd]{1}*$", RegexOptions.None, RegexParseError.NestedQuantifiersNotParenthesized, 11)]
+ [InlineData(@"(cat)(\c*)(dog)", RegexOptions.None, RegexParseError.UnrecognizedControlCharacter, 9)]
+ [InlineData(@"(cat)(\c *)(dog)", RegexOptions.None, RegexParseError.UnrecognizedControlCharacter, 9)]
+ [InlineData(@"(cat)(\c?*)(dog)", RegexOptions.None, RegexParseError.UnrecognizedControlCharacter, 9)]
+ [InlineData(@"(cat)(\c`*)(dog)", RegexOptions.None, RegexParseError.UnrecognizedControlCharacter, 9)]
+ [InlineData(@"(cat)(\c\|*)(dog)", RegexOptions.None, RegexParseError.QuantifierAfterNothing, 11)]
+ [InlineData(@"^[abcd]{0,16}*$", RegexOptions.None, RegexParseError.NestedQuantifiersNotParenthesized, 14)]
+ [InlineData(@"(cat)\c", RegexOptions.None, RegexParseError.MissingControlCharacter, 7)]
+ // Deep recursion
+ [InlineData(@"((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((" +
+"(((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((" +
+"(((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((" +
+"(((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((" +
+"(((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((" +
+"(((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((" +
+"(((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((" +
+"(((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((" +
+"(((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((" +
+"(((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((" +
+"(((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((" +
+"(((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((", RegexOptions.None, RegexParseError.InsufficientClosingParentheses, 1183)]
+ // Scan control
+ [InlineData("(cat)(\\c\0*)(dog)", RegexOptions.None, RegexParseError.UnrecognizedControlCharacter, 9)]
+ [InlineData(@"(cat)(\c\[*)(dog)", RegexOptions.None, RegexParseError.UnterminatedBracket, 17)]
+ // Invalid grouping constructs
+ [InlineData("(?<", RegexOptions.None, RegexParseError.InvalidGroupingConstruct, 3)]
+ [InlineData("(?>-", RegexOptions.None, RegexParseError.InsufficientClosingParentheses, 4)]
+ // Testgroup with options
+ [InlineData("())", RegexOptions.None, RegexParseError.InsufficientOpeningParentheses, 3)]
+ [InlineData("[a-z-[aeiuo]", RegexOptions.None, RegexParseError.UnterminatedBracket, 12)]
+ [InlineData("[a-z-[aeiuo", RegexOptions.None, RegexParseError.UnterminatedBracket, 11)]
+ [InlineData("[a-z-[b]", RegexOptions.None, RegexParseError.UnterminatedBracket, 8)]
+ [InlineData("[a-z-[b", RegexOptions.None, RegexParseError.UnterminatedBracket, 7)]
+ [InlineData("[b-a]", RegexOptions.None, RegexParseError.ReversedCharacterRange, 4)]
+ [InlineData(@"[a-c]{2,1}", RegexOptions.None, RegexParseError.ReversedQuantifierRange, 10)]
+ [InlineData(@"\d{2147483648}", RegexOptions.None, RegexParseError.QuantifierOrCaptureGroupOutOfRange, 13)]
+ [InlineData("[a-z-[b][", RegexOptions.None, RegexParseError.UnterminatedBracket, 9)]
+ [InlineData("(?()|||||)", RegexOptions.None, RegexParseError.AlternationHasTooManyConditions, 10)]
+ [InlineData("[^]", RegexOptions.None, RegexParseError.UnterminatedBracket, 3)]
+ [InlineData("\\", RegexOptions.None, RegexParseError.UnescapedEndingBackslash, 1)]
+ [InlineData("??", RegexOptions.None, RegexParseError.QuantifierAfterNothing, 1)]
+ [InlineData("(?=*)", RegexOptions.None, RegexParseError.QuantifierAfterNothing, 4)]
+ [InlineData("((((((*))))))", RegexOptions.None, RegexParseError.QuantifierAfterNothing, 7)]
+ public void ParseCheckOffset(string pattern, RegexOptions options, object errorObj, int offset)
{
-#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
+ RegexParseError? error = (RegexParseError?)errorObj;
- var bf = new BinaryFormatter();
- var s = new MemoryStream();
- bf.Serialize(s, e);
- s.Position = 0;
+ // Parse the main tree and if parsing fails check if the supplied error matches.
+ ParseTree(pattern, options, error, offset);
- ArgumentException e2 = (ArgumentException)bf.Deserialize(s);
- Assert.Equal(e.Message, e2.Message);
+ // Assert that only ArgumentException might be thrown during parsing.
+ ParseSubTrees(pattern, options);
}
+
private static void ParseSubTrees(string pattern, RegexOptions options)
{
// Trim the input from the right and make sure tree invariants hold
}
}
- private static void ParseTree(string pattern, RegexOptions options, RegexParseError? error)
+ static void ParseTree(string pattern, RegexOptions options, RegexParseError? error, int offset)
{
if (error != null)
{
- Throws(error.Value, () => new Regex(pattern, options));
+ Throws(error.Value, offset, () => new Regex(pattern, options));
return;
}
}
}
- /// <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");
- }
+ static partial void Throws(RegexParseError error, int offset, Action action);
}
}