You've already forked linux-packaging-mono
Imported Upstream version 5.4.0.167
Former-commit-id: 5624ac747d633e885131e8349322922b6a59baaa
This commit is contained in:
parent
e49d6f06c0
commit
536cd135cc
@@ -2,7 +2,8 @@
|
||||
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<Import Project="..\dir.props" />
|
||||
<PropertyGroup>
|
||||
<AssemblyVersion>4.2.0.0</AssemblyVersion>
|
||||
<AssemblyVersion>4.2.1.0</AssemblyVersion>
|
||||
<AssemblyKey>MSFT</AssemblyKey>
|
||||
<IsNETCoreApp>true</IsNETCoreApp>
|
||||
<IsUAP>true</IsUAP>
|
||||
</PropertyGroup>
|
||||
|
||||
@@ -139,26 +139,12 @@ namespace System.Text.RegularExpressions
|
||||
protected Regex(SerializationInfo info, StreamingContext context)
|
||||
: this(info.GetString("pattern"), (RegexOptions)info.GetInt32("options"))
|
||||
{
|
||||
try
|
||||
{
|
||||
long timeoutTicks = info.GetInt64("matchTimeout");
|
||||
TimeSpan timeout = new TimeSpan(timeoutTicks);
|
||||
ValidateMatchTimeout(timeout);
|
||||
internalMatchTimeout = timeout;
|
||||
}
|
||||
catch (SerializationException)
|
||||
{
|
||||
// If this occurs, then assume that this object was serialized using a version
|
||||
// before timeout was added. In that case just do not set a timeout
|
||||
// (keep default value)
|
||||
}
|
||||
throw new PlatformNotSupportedException();
|
||||
}
|
||||
|
||||
void ISerializable.GetObjectData(SerializationInfo si, StreamingContext context)
|
||||
{
|
||||
si.AddValue("pattern", ToString());
|
||||
si.AddValue("options", Options);
|
||||
si.AddValue("matchTimeout", MatchTimeout.Ticks);
|
||||
throw new PlatformNotSupportedException();
|
||||
}
|
||||
|
||||
private Regex(string pattern, RegexOptions options, TimeSpan matchTimeout, bool useCache)
|
||||
|
||||
@@ -102,20 +102,5 @@ namespace System.Text.RegularExpressions
|
||||
return _text.Substring(_index + _length, _text.Length - _index - _length);
|
||||
}
|
||||
|
||||
#if DEBUG
|
||||
internal virtual string Description()
|
||||
{
|
||||
StringBuilder Sb = new StringBuilder();
|
||||
|
||||
Sb.Append("(I = ");
|
||||
Sb.Append(_index);
|
||||
Sb.Append(", L = ");
|
||||
Sb.Append(_length);
|
||||
Sb.Append("): ");
|
||||
Sb.Append(_text, _index, _length);
|
||||
|
||||
return Sb.ToString();
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
@@ -53,17 +53,12 @@ namespace System.Text.RegularExpressions
|
||||
protected RegexMatchTimeoutException(SerializationInfo info, StreamingContext context)
|
||||
: base(info, context)
|
||||
{
|
||||
Input = info.GetString("regexInput");
|
||||
Pattern = info.GetString("regexPattern");
|
||||
MatchTimeout = new TimeSpan(info.GetInt64("timeoutTicks"));
|
||||
throw new PlatformNotSupportedException();
|
||||
}
|
||||
|
||||
void ISerializable.GetObjectData(SerializationInfo info, StreamingContext context)
|
||||
{
|
||||
base.GetObjectData(info, context);
|
||||
info.AddValue("regexInput", Input);
|
||||
info.AddValue("regexPattern", Pattern);
|
||||
info.AddValue("timeoutTicks", MatchTimeout.Ticks);
|
||||
}
|
||||
|
||||
public string Input { get; } = string.Empty;
|
||||
|
||||
@@ -63,8 +63,8 @@ namespace System.Text.RegularExpressions.Tests
|
||||
Regex regex = new Regex(@"(?<A1>a*)(?<A2>b*)(?<A3>c*)");
|
||||
CaptureCollection captures = regex.Match("aaabbccccccccccaaaabc").Captures;
|
||||
|
||||
Assert.Throws<ArgumentOutOfRangeException>("i", () => captures[-1]);
|
||||
Assert.Throws<ArgumentOutOfRangeException>("i", () => captures[captures.Count]);
|
||||
AssertExtensions.Throws<ArgumentOutOfRangeException>("i", () => captures[-1]);
|
||||
AssertExtensions.Throws<ArgumentOutOfRangeException>("i", () => captures[captures.Count]);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -108,14 +108,17 @@ namespace System.Text.RegularExpressions.Tests
|
||||
ICollection collection = regex.Match("aaabbccccccccccaaaabc").Captures;
|
||||
|
||||
// Array is null
|
||||
Assert.Throws<ArgumentNullException>("array", () => collection.CopyTo(null, 0));
|
||||
AssertExtensions.Throws<ArgumentNullException>("array", () => collection.CopyTo(null, 0));
|
||||
|
||||
// Array is multidimensional
|
||||
Assert.Throws<ArgumentException>(null, () => collection.CopyTo(new object[10, 10], 0));
|
||||
AssertExtensions.Throws<ArgumentException>(null, () => collection.CopyTo(new object[10, 10], 0));
|
||||
|
||||
// Array has a non-zero lower bound
|
||||
Array o = Array.CreateInstance(typeof(object), new int[] { 10 }, new int[] { 10 });
|
||||
Assert.Throws<IndexOutOfRangeException>(() => collection.CopyTo(o, 0));
|
||||
if (PlatformDetection.IsNonZeroLowerBoundArraySupported)
|
||||
{
|
||||
// Array has a non-zero lower bound
|
||||
Array o = Array.CreateInstance(typeof(object), new int[] { 10 }, new int[] { 10 });
|
||||
Assert.Throws<IndexOutOfRangeException>(() => collection.CopyTo(o, 0));
|
||||
}
|
||||
|
||||
// Index < 0
|
||||
Assert.Throws<IndexOutOfRangeException>(() => collection.CopyTo(new object[collection.Count], -1));
|
||||
|
||||
@@ -128,11 +128,11 @@ namespace System.Text.RegularExpressions.Tests
|
||||
public static void ICollectionOfT_CopyTo_Invalid()
|
||||
{
|
||||
ICollection<Capture> collection = CreateCollection();
|
||||
Assert.Throws<ArgumentNullException>("array", () => collection.CopyTo((Capture[])null, 0));
|
||||
Assert.Throws<ArgumentOutOfRangeException>("arrayIndex", () => collection.CopyTo(new Capture[1], -1));
|
||||
AssertExtensions.Throws<ArgumentNullException>("array", () => collection.CopyTo((Capture[])null, 0));
|
||||
AssertExtensions.Throws<ArgumentOutOfRangeException>("arrayIndex", () => collection.CopyTo(new Capture[1], -1));
|
||||
Assert.Throws<ArgumentException>(() => collection.CopyTo(new Capture[1], 0));
|
||||
Assert.Throws<ArgumentException>(() => collection.CopyTo(new Capture[1], 1));
|
||||
Assert.Throws<ArgumentOutOfRangeException>("arrayIndex", () => collection.CopyTo(new Capture[1], 2));
|
||||
AssertExtensions.Throws<ArgumentOutOfRangeException>("arrayIndex", () => collection.CopyTo(new Capture[1], 2));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
||||
@@ -111,14 +111,17 @@ namespace System.Text.RegularExpressions.Tests
|
||||
ICollection collection = regex.Match("aaabbccccccccccaaaabc").Groups;
|
||||
|
||||
// Array is null
|
||||
Assert.Throws<ArgumentNullException>("array", () => collection.CopyTo(null, 0));
|
||||
AssertExtensions.Throws<ArgumentNullException>("array", () => collection.CopyTo(null, 0));
|
||||
|
||||
// Array is multidimensional
|
||||
Assert.Throws<ArgumentException>(null, () => collection.CopyTo(new object[10, 10], 0));
|
||||
AssertExtensions.Throws<ArgumentException>(null, () => collection.CopyTo(new object[10, 10], 0));
|
||||
|
||||
// Array has a non-zero lower bound
|
||||
Array o = Array.CreateInstance(typeof(object), new int[] { 10 }, new int[] { 10 });
|
||||
Assert.Throws<IndexOutOfRangeException>(() => collection.CopyTo(o, 0));
|
||||
if (PlatformDetection.IsNonZeroLowerBoundArraySupported)
|
||||
{
|
||||
// Array has a non-zero lower bound
|
||||
Array o = Array.CreateInstance(typeof(object), new int[] { 10 }, new int[] { 10 });
|
||||
Assert.Throws<IndexOutOfRangeException>(() => collection.CopyTo(o, 0));
|
||||
}
|
||||
|
||||
// Index < 0
|
||||
Assert.Throws<IndexOutOfRangeException>(() => collection.CopyTo(new object[collection.Count], -1));
|
||||
|
||||
@@ -125,11 +125,11 @@ namespace System.Text.RegularExpressions.Tests
|
||||
public static void ICollectionOfT_CopyTo_Invalid()
|
||||
{
|
||||
ICollection<Group> collection = CreateCollection();
|
||||
Assert.Throws<ArgumentNullException>("array", () => collection.CopyTo(null, 0));
|
||||
Assert.Throws<ArgumentOutOfRangeException>("arrayIndex", () => collection.CopyTo(new Group[1], -1));
|
||||
AssertExtensions.Throws<ArgumentNullException>("array", () => collection.CopyTo(null, 0));
|
||||
AssertExtensions.Throws<ArgumentOutOfRangeException>("arrayIndex", () => collection.CopyTo(new Group[1], -1));
|
||||
Assert.Throws<ArgumentException>(() => collection.CopyTo(new Group[1], 0));
|
||||
Assert.Throws<ArgumentException>(() => collection.CopyTo(new Group[1], 1));
|
||||
Assert.Throws<ArgumentOutOfRangeException>("arrayIndex", () => collection.CopyTo(new Group[1], 2));
|
||||
AssertExtensions.Throws<ArgumentOutOfRangeException>("arrayIndex", () => collection.CopyTo(new Group[1], 2));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
||||
@@ -60,8 +60,8 @@ namespace System.Text.RegularExpressions.Tests
|
||||
{
|
||||
Regex regex = new Regex("e");
|
||||
MatchCollection matches = regex.Matches("dotnet");
|
||||
Assert.Throws<ArgumentOutOfRangeException>("i", () => matches[-1]);
|
||||
Assert.Throws<ArgumentOutOfRangeException>("i", () => matches[matches.Count]);
|
||||
AssertExtensions.Throws<ArgumentOutOfRangeException>("i", () => matches[-1]);
|
||||
AssertExtensions.Throws<ArgumentOutOfRangeException>("i", () => matches[matches.Count]);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -108,11 +108,14 @@ namespace System.Text.RegularExpressions.Tests
|
||||
AssertExtensions.Throws<ArgumentNullException>("destinationArray", "dest", () => collection.CopyTo(null, 0));
|
||||
|
||||
// Array is multidimensional
|
||||
Assert.Throws<ArgumentException>(null, () => collection.CopyTo(new object[10, 10], 0));
|
||||
AssertExtensions.Throws<ArgumentException>(null, () => collection.CopyTo(new object[10, 10], 0));
|
||||
|
||||
// Array has a non-zero lower bound
|
||||
Array o = Array.CreateInstance(typeof(object), new int[] { 10 }, new int[] { 10 });
|
||||
AssertExtensions.Throws<ArgumentOutOfRangeException>("destinationIndex", "dstIndex", () => collection.CopyTo(o, 0));
|
||||
if (PlatformDetection.IsNonZeroLowerBoundArraySupported)
|
||||
{
|
||||
// Array has a non-zero lower bound
|
||||
Array o = Array.CreateInstance(typeof(object), new int[] { 10 }, new int[] { 10 });
|
||||
AssertExtensions.Throws<ArgumentOutOfRangeException>("destinationIndex", "dstIndex", () => collection.CopyTo(o, 0));
|
||||
}
|
||||
|
||||
// Index < 0
|
||||
AssertExtensions.Throws<ArgumentOutOfRangeException>("destinationIndex", "dstIndex", () => collection.CopyTo(new object[collection.Count], -1));
|
||||
|
||||
@@ -53,26 +53,26 @@ namespace System.Text.RegularExpressions.Tests
|
||||
public static void Ctor_Invalid()
|
||||
{
|
||||
// Pattern is null
|
||||
Assert.Throws<ArgumentNullException>("pattern", () => new Regex(null));
|
||||
Assert.Throws<ArgumentNullException>("pattern", () => new Regex(null, RegexOptions.None));
|
||||
Assert.Throws<ArgumentNullException>("pattern", () => new Regex(null, RegexOptions.None, new TimeSpan()));
|
||||
AssertExtensions.Throws<ArgumentNullException>("pattern", () => new Regex(null));
|
||||
AssertExtensions.Throws<ArgumentNullException>("pattern", () => new Regex(null, RegexOptions.None));
|
||||
AssertExtensions.Throws<ArgumentNullException>("pattern", () => new Regex(null, RegexOptions.None, new TimeSpan()));
|
||||
|
||||
// Options are invalid
|
||||
Assert.Throws<ArgumentOutOfRangeException>("options", () => new Regex("foo", (RegexOptions)(-1)));
|
||||
Assert.Throws<ArgumentOutOfRangeException>("options", () => new Regex("foo", (RegexOptions)(-1), new TimeSpan()));
|
||||
AssertExtensions.Throws<ArgumentOutOfRangeException>("options", () => new Regex("foo", (RegexOptions)(-1)));
|
||||
AssertExtensions.Throws<ArgumentOutOfRangeException>("options", () => new Regex("foo", (RegexOptions)(-1), new TimeSpan()));
|
||||
|
||||
Assert.Throws<ArgumentOutOfRangeException>("options", () => new Regex("foo", (RegexOptions)0x400));
|
||||
Assert.Throws<ArgumentOutOfRangeException>("options", () => new Regex("foo", (RegexOptions)0x400, new TimeSpan()));
|
||||
AssertExtensions.Throws<ArgumentOutOfRangeException>("options", () => new Regex("foo", (RegexOptions)0x400));
|
||||
AssertExtensions.Throws<ArgumentOutOfRangeException>("options", () => new Regex("foo", (RegexOptions)0x400, new TimeSpan()));
|
||||
|
||||
Assert.Throws<ArgumentOutOfRangeException>("options", () => new Regex("foo", RegexOptions.ECMAScript | RegexOptions.IgnoreCase | RegexOptions.Multiline | RegexOptions.CultureInvariant | RegexOptions.RightToLeft));
|
||||
Assert.Throws<ArgumentOutOfRangeException>("options", () => new Regex("foo", RegexOptions.ECMAScript | RegexOptions.IgnoreCase | RegexOptions.Multiline | RegexOptions.CultureInvariant | RegexOptions.ExplicitCapture));
|
||||
Assert.Throws<ArgumentOutOfRangeException>("options", () => new Regex("foo", RegexOptions.ECMAScript | RegexOptions.IgnoreCase | RegexOptions.Multiline | RegexOptions.CultureInvariant | RegexOptions.Singleline));
|
||||
Assert.Throws<ArgumentOutOfRangeException>("options", () => new Regex("foo", RegexOptions.ECMAScript | RegexOptions.IgnoreCase | RegexOptions.Multiline | RegexOptions.CultureInvariant | RegexOptions.IgnorePatternWhitespace));
|
||||
AssertExtensions.Throws<ArgumentOutOfRangeException>("options", () => new Regex("foo", RegexOptions.ECMAScript | RegexOptions.IgnoreCase | RegexOptions.Multiline | RegexOptions.CultureInvariant | RegexOptions.RightToLeft));
|
||||
AssertExtensions.Throws<ArgumentOutOfRangeException>("options", () => new Regex("foo", RegexOptions.ECMAScript | RegexOptions.IgnoreCase | RegexOptions.Multiline | RegexOptions.CultureInvariant | RegexOptions.ExplicitCapture));
|
||||
AssertExtensions.Throws<ArgumentOutOfRangeException>("options", () => new Regex("foo", RegexOptions.ECMAScript | RegexOptions.IgnoreCase | RegexOptions.Multiline | RegexOptions.CultureInvariant | RegexOptions.Singleline));
|
||||
AssertExtensions.Throws<ArgumentOutOfRangeException>("options", () => new Regex("foo", RegexOptions.ECMAScript | RegexOptions.IgnoreCase | RegexOptions.Multiline | RegexOptions.CultureInvariant | RegexOptions.IgnorePatternWhitespace));
|
||||
|
||||
// MatchTimeout is invalid
|
||||
Assert.Throws<ArgumentOutOfRangeException>("matchTimeout", () => new Regex("foo", RegexOptions.None, new TimeSpan(-1)));
|
||||
Assert.Throws<ArgumentOutOfRangeException>("matchTimeout", () => new Regex("foo", RegexOptions.None, TimeSpan.Zero));
|
||||
Assert.Throws<ArgumentOutOfRangeException>("matchTimeout", () => new Regex("foo", RegexOptions.None, TimeSpan.FromMilliseconds(int.MaxValue)));
|
||||
AssertExtensions.Throws<ArgumentOutOfRangeException>("matchTimeout", () => new Regex("foo", RegexOptions.None, new TimeSpan(-1)));
|
||||
AssertExtensions.Throws<ArgumentOutOfRangeException>("matchTimeout", () => new Regex("foo", RegexOptions.None, TimeSpan.Zero));
|
||||
AssertExtensions.Throws<ArgumentOutOfRangeException>("matchTimeout", () => new Regex("foo", RegexOptions.None, TimeSpan.FromMilliseconds(int.MaxValue)));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -97,7 +97,7 @@ namespace System.Text.RegularExpressions.Tests
|
||||
[Fact]
|
||||
public void CacheSize_Set_NegativeValue_ThrowsArgumentOutOfRangeException()
|
||||
{
|
||||
Assert.Throws<ArgumentOutOfRangeException>("value", () => Regex.CacheSize = -1);
|
||||
AssertExtensions.Throws<ArgumentOutOfRangeException>("value", () => Regex.CacheSize = -1);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
|
||||
@@ -22,7 +22,7 @@ namespace System.Text.RegularExpressions.Tests
|
||||
[Fact]
|
||||
public void Escape_NullString_ThrowsArgumentNullException()
|
||||
{
|
||||
Assert.Throws<ArgumentNullException>("str", () => Regex.Escape(null));
|
||||
AssertExtensions.Throws<ArgumentNullException>("str", () => Regex.Escape(null));
|
||||
}
|
||||
|
||||
[Theory]
|
||||
@@ -40,7 +40,7 @@ namespace System.Text.RegularExpressions.Tests
|
||||
[Fact]
|
||||
public void Unscape_NullString_ThrowsArgumentNullException()
|
||||
{
|
||||
Assert.Throws<ArgumentNullException>("str", () => Regex.Unescape(null));
|
||||
AssertExtensions.Throws<ArgumentNullException>("str", () => Regex.Unescape(null));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -168,7 +168,7 @@ namespace System.Text.RegularExpressions.Tests
|
||||
[Fact]
|
||||
public void GroupNumberFromName_NullName_ThrowsArgumentNullException()
|
||||
{
|
||||
Assert.Throws<ArgumentNullException>("name", () => new Regex("foo").GroupNumberFromName(null));
|
||||
AssertExtensions.Throws<ArgumentNullException>("name", () => new Regex("foo").GroupNumberFromName(null));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,12 +3,14 @@
|
||||
// See the LICENSE file in the project root for more information.
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
using Xunit;
|
||||
|
||||
namespace System.Text.RegularExpressions.Tests
|
||||
{
|
||||
public class RegexGroupTests
|
||||
public class RegexGroupTests : RemoteExecutorTestBase
|
||||
{
|
||||
private static readonly CultureInfo s_enUSCulture = new CultureInfo("en-US");
|
||||
private static readonly CultureInfo s_invariantCulture = new CultureInfo("");
|
||||
@@ -622,43 +624,53 @@ namespace System.Text.RegularExpressions.Tests
|
||||
[MemberData(nameof(Groups_CustomCulture_TestData))]
|
||||
public void Groups(string pattern, string input, RegexOptions options, CultureInfo cultureInfo, string[] expectedGroups)
|
||||
{
|
||||
CultureInfo originalCulture = CultureInfo.CurrentCulture;
|
||||
try
|
||||
const string EmptyPlaceholder = "-";
|
||||
const char Seperator = ';';
|
||||
|
||||
string outerPattern = Convert.ToBase64String(Encoding.UTF8.GetBytes(pattern));
|
||||
string outerInput = Convert.ToBase64String(Encoding.UTF8.GetBytes(input));
|
||||
string outerOptions = ((int)options).ToString();
|
||||
string outerCultureInfo = cultureInfo != null ? cultureInfo.ToString() : EmptyPlaceholder;
|
||||
string outerExpectedGroups = expectedGroups != null && expectedGroups.Length > 0 ? "\"" + Convert.ToBase64String(Encoding.UTF8.GetBytes(string.Join(Seperator.ToString(), expectedGroups.Select(s => s == string.Empty ? EmptyPlaceholder : s).ToArray()))) + "\"" : EmptyPlaceholder;
|
||||
|
||||
RemoteInvoke((innerPatternEnc, innerInputEnc, innerOptionsEnc, innerCultureInfoEnc, innerExpectedGroupsEnc) =>
|
||||
{
|
||||
string innerPattern = Encoding.UTF8.GetString(Convert.FromBase64String(innerPatternEnc));
|
||||
string innerInput = Encoding.UTF8.GetString(Convert.FromBase64String(innerInputEnc));
|
||||
RegexOptions innerOptions = (RegexOptions)int.Parse(innerOptionsEnc);
|
||||
CultureInfo innerCultureInfo = innerCultureInfoEnc != EmptyPlaceholder ? new CultureInfo(innerCultureInfoEnc) : null;
|
||||
string[] innerExpectedGroups = innerExpectedGroupsEnc != EmptyPlaceholder ? Encoding.UTF8.GetString(Convert.FromBase64String(innerExpectedGroupsEnc.Trim('"'))).Split(Seperator).Select(s => s == EmptyPlaceholder ? string.Empty : s).ToArray() : new string[] { };
|
||||
|
||||
// In invariant culture, the unicode char matches differ from expected values provided.
|
||||
if (originalCulture.Equals(CultureInfo.InvariantCulture))
|
||||
if (CultureInfo.CurrentCulture.Equals(CultureInfo.InvariantCulture))
|
||||
{
|
||||
CultureInfo.CurrentCulture = s_enUSCulture;
|
||||
CultureInfo.CurrentCulture = new CultureInfo("en-US");
|
||||
}
|
||||
if (cultureInfo != null)
|
||||
if (innerCultureInfo != null)
|
||||
{
|
||||
CultureInfo.CurrentCulture = cultureInfo;
|
||||
CultureInfo.CurrentCulture = innerCultureInfo;
|
||||
}
|
||||
Regex regex = new Regex(pattern, options);
|
||||
Match match = regex.Match(input);
|
||||
|
||||
Regex regex = new Regex(innerPattern, innerOptions);
|
||||
Match match = regex.Match(innerInput);
|
||||
Assert.True(match.Success);
|
||||
|
||||
Assert.Equal(expectedGroups.Length, match.Groups.Count);
|
||||
Assert.True(expectedGroups[0] == match.Value, string.Format("Culture used: {0}", CultureInfo.CurrentCulture));
|
||||
Assert.Equal(innerExpectedGroups.Length, match.Groups.Count);
|
||||
Assert.True(innerExpectedGroups[0] == match.Value, string.Format("Culture used: {0}", CultureInfo.CurrentCulture));
|
||||
|
||||
int[] groupNumbers = regex.GetGroupNumbers();
|
||||
string[] groupNames = regex.GetGroupNames();
|
||||
for (int i = 0; i < expectedGroups.Length; i++)
|
||||
for (int i = 0; i < innerExpectedGroups.Length; i++)
|
||||
{
|
||||
Assert.Equal(expectedGroups[i], match.Groups[groupNumbers[i]].Value);
|
||||
Assert.Equal(innerExpectedGroups[i], match.Groups[groupNumbers[i]].Value);
|
||||
Assert.Equal(match.Groups[groupNumbers[i]], match.Groups[groupNames[i]]);
|
||||
|
||||
Assert.Equal(groupNumbers[i], regex.GroupNumberFromName(groupNames[i]));
|
||||
Assert.Equal(groupNames[i], regex.GroupNameFromNumber(groupNumbers[i]));
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
if (cultureInfo != null || originalCulture.Equals(CultureInfo.InvariantCulture))
|
||||
{
|
||||
CultureInfo.CurrentCulture = originalCulture;
|
||||
}
|
||||
}
|
||||
|
||||
return SuccessExitCode;
|
||||
}, outerPattern, outerInput, outerOptions, outerCultureInfo, outerExpectedGroups).Dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,14 +1,15 @@
|
||||
// Licensed to the .NET Foundation under one or more agreements.
|
||||
// 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.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Globalization;
|
||||
using Xunit;
|
||||
|
||||
namespace System.Text.RegularExpressions.Tests
|
||||
{
|
||||
public class RegexMatchTests
|
||||
public class RegexMatchTests : RemoteExecutorTestBase
|
||||
{
|
||||
public static IEnumerable<object[]> Match_Basic_TestData()
|
||||
{
|
||||
@@ -684,7 +685,7 @@ namespace System.Text.RegularExpressions.Tests
|
||||
public void Result_Invalid()
|
||||
{
|
||||
Match match = Regex.Match("foo", "foo");
|
||||
Assert.Throws<ArgumentNullException>("replacement", () => match.Result(null));
|
||||
AssertExtensions.Throws<ArgumentNullException>("replacement", () => match.Result(null));
|
||||
|
||||
Assert.Throws<NotSupportedException>(() => RegularExpressions.Match.Empty.Result("any"));
|
||||
}
|
||||
@@ -692,11 +693,9 @@ namespace System.Text.RegularExpressions.Tests
|
||||
[Fact]
|
||||
public void Match_SpecialUnicodeCharacters()
|
||||
{
|
||||
CultureInfo currentCulture = CultureInfo.CurrentCulture;
|
||||
CultureInfo enUSCulture = new CultureInfo("en-US");
|
||||
try
|
||||
RemoteInvoke(() =>
|
||||
{
|
||||
CultureInfo.CurrentCulture = enUSCulture;
|
||||
CultureInfo.CurrentCulture = new CultureInfo("en-US");
|
||||
Match("\u0131", "\u0049", RegexOptions.IgnoreCase, 0, 1, false, string.Empty);
|
||||
Match("\u0131", "\u0069", RegexOptions.IgnoreCase, 0, 1, false, string.Empty);
|
||||
|
||||
@@ -705,29 +704,27 @@ namespace System.Text.RegularExpressions.Tests
|
||||
Match("\u0131", "\u0069", RegexOptions.IgnoreCase, 0, 1, false, string.Empty);
|
||||
Match("\u0130", "\u0049", RegexOptions.IgnoreCase, 0, 1, false, string.Empty);
|
||||
Match("\u0130", "\u0069", RegexOptions.IgnoreCase, 0, 1, false, string.Empty);
|
||||
}
|
||||
finally
|
||||
{
|
||||
CultureInfo.CurrentCulture = currentCulture;
|
||||
}
|
||||
|
||||
return SuccessExitCode;
|
||||
}).Dispose();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Match_Invalid()
|
||||
{
|
||||
// Input is null
|
||||
Assert.Throws<ArgumentNullException>("input", () => Regex.Match(null, "pattern"));
|
||||
Assert.Throws<ArgumentNullException>("input", () => Regex.Match(null, "pattern", RegexOptions.None));
|
||||
Assert.Throws<ArgumentNullException>("input", () => Regex.Match(null, "pattern", RegexOptions.None, TimeSpan.FromSeconds(1)));
|
||||
AssertExtensions.Throws<ArgumentNullException>("input", () => Regex.Match(null, "pattern"));
|
||||
AssertExtensions.Throws<ArgumentNullException>("input", () => Regex.Match(null, "pattern", RegexOptions.None));
|
||||
AssertExtensions.Throws<ArgumentNullException>("input", () => Regex.Match(null, "pattern", RegexOptions.None, TimeSpan.FromSeconds(1)));
|
||||
|
||||
Assert.Throws<ArgumentNullException>("input", () => new Regex("pattern").Match(null));
|
||||
Assert.Throws<ArgumentNullException>("input", () => new Regex("pattern").Match(null, 0));
|
||||
Assert.Throws<ArgumentNullException>("input", () => new Regex("pattern").Match(null, 0, 0));
|
||||
AssertExtensions.Throws<ArgumentNullException>("input", () => new Regex("pattern").Match(null));
|
||||
AssertExtensions.Throws<ArgumentNullException>("input", () => new Regex("pattern").Match(null, 0));
|
||||
AssertExtensions.Throws<ArgumentNullException>("input", () => new Regex("pattern").Match(null, 0, 0));
|
||||
|
||||
// Pattern is null
|
||||
Assert.Throws<ArgumentNullException>("pattern", () => Regex.Match("input", null));
|
||||
Assert.Throws<ArgumentNullException>("pattern", () => Regex.Match("input", null, RegexOptions.None));
|
||||
Assert.Throws<ArgumentNullException>("pattern", () => Regex.Match("input", null, RegexOptions.None, TimeSpan.FromSeconds(1)));
|
||||
AssertExtensions.Throws<ArgumentNullException>("pattern", () => Regex.Match("input", null));
|
||||
AssertExtensions.Throws<ArgumentNullException>("pattern", () => Regex.Match("input", null, RegexOptions.None));
|
||||
AssertExtensions.Throws<ArgumentNullException>("pattern", () => Regex.Match("input", null, RegexOptions.None, TimeSpan.FromSeconds(1)));
|
||||
|
||||
// Start is invalid
|
||||
Assert.Throws<ArgumentOutOfRangeException>(() => new Regex("pattern").Match("input", -1));
|
||||
@@ -736,8 +733,8 @@ namespace System.Text.RegularExpressions.Tests
|
||||
Assert.Throws<ArgumentOutOfRangeException>(() => new Regex("pattern").Match("input", 6, 0));
|
||||
|
||||
// Length is invalid
|
||||
Assert.Throws<ArgumentOutOfRangeException>("length", () => new Regex("pattern").Match("input", 0, -1));
|
||||
Assert.Throws<ArgumentOutOfRangeException>("length", () => new Regex("pattern").Match("input", 0, 6));
|
||||
AssertExtensions.Throws<ArgumentOutOfRangeException>("length", () => new Regex("pattern").Match("input", 0, -1));
|
||||
AssertExtensions.Throws<ArgumentOutOfRangeException>("length", () => new Regex("pattern").Match("input", 0, 6));
|
||||
}
|
||||
|
||||
[Theory]
|
||||
@@ -762,17 +759,17 @@ namespace System.Text.RegularExpressions.Tests
|
||||
public void IsMatch_Invalid()
|
||||
{
|
||||
// Input is null
|
||||
Assert.Throws<ArgumentNullException>("input", () => Regex.IsMatch(null, "pattern"));
|
||||
Assert.Throws<ArgumentNullException>("input", () => Regex.IsMatch(null, "pattern", RegexOptions.None));
|
||||
Assert.Throws<ArgumentNullException>("input", () => Regex.IsMatch(null, "pattern", RegexOptions.None, TimeSpan.FromSeconds(1)));
|
||||
AssertExtensions.Throws<ArgumentNullException>("input", () => Regex.IsMatch(null, "pattern"));
|
||||
AssertExtensions.Throws<ArgumentNullException>("input", () => Regex.IsMatch(null, "pattern", RegexOptions.None));
|
||||
AssertExtensions.Throws<ArgumentNullException>("input", () => Regex.IsMatch(null, "pattern", RegexOptions.None, TimeSpan.FromSeconds(1)));
|
||||
|
||||
Assert.Throws<ArgumentNullException>("input", () => new Regex("pattern").IsMatch(null));
|
||||
Assert.Throws<ArgumentNullException>("input", () => new Regex("pattern").IsMatch(null, 0));
|
||||
AssertExtensions.Throws<ArgumentNullException>("input", () => new Regex("pattern").IsMatch(null));
|
||||
AssertExtensions.Throws<ArgumentNullException>("input", () => new Regex("pattern").IsMatch(null, 0));
|
||||
|
||||
// Pattern is null
|
||||
Assert.Throws<ArgumentNullException>("pattern", () => Regex.IsMatch("input", null));
|
||||
Assert.Throws<ArgumentNullException>("pattern", () => Regex.IsMatch("input", null, RegexOptions.None));
|
||||
Assert.Throws<ArgumentNullException>("pattern", () => Regex.IsMatch("input", null, RegexOptions.None, TimeSpan.FromSeconds(1)));
|
||||
AssertExtensions.Throws<ArgumentNullException>("pattern", () => Regex.IsMatch("input", null));
|
||||
AssertExtensions.Throws<ArgumentNullException>("pattern", () => Regex.IsMatch("input", null, RegexOptions.None));
|
||||
AssertExtensions.Throws<ArgumentNullException>("pattern", () => Regex.IsMatch("input", null, RegexOptions.None, TimeSpan.FromSeconds(1)));
|
||||
|
||||
// Start is invalid
|
||||
Assert.Throws<ArgumentOutOfRangeException>(() => new Regex("pattern").IsMatch("input", -1));
|
||||
|
||||
@@ -202,31 +202,31 @@ namespace System.Text.RegularExpressions.Tests
|
||||
public void Matches_Invalid()
|
||||
{
|
||||
// Input is null
|
||||
Assert.Throws<ArgumentNullException>("input", () => Regex.Matches(null, "pattern"));
|
||||
Assert.Throws<ArgumentNullException>("input", () => Regex.Matches(null, "pattern", RegexOptions.None));
|
||||
Assert.Throws<ArgumentNullException>("input", () => Regex.Matches(null, "pattern", RegexOptions.None, TimeSpan.FromSeconds(1)));
|
||||
AssertExtensions.Throws<ArgumentNullException>("input", () => Regex.Matches(null, "pattern"));
|
||||
AssertExtensions.Throws<ArgumentNullException>("input", () => Regex.Matches(null, "pattern", RegexOptions.None));
|
||||
AssertExtensions.Throws<ArgumentNullException>("input", () => Regex.Matches(null, "pattern", RegexOptions.None, TimeSpan.FromSeconds(1)));
|
||||
|
||||
Assert.Throws<ArgumentNullException>("input", () => new Regex("pattern").Matches(null));
|
||||
Assert.Throws<ArgumentNullException>("input", () => new Regex("pattern").Matches(null, 0));
|
||||
AssertExtensions.Throws<ArgumentNullException>("input", () => new Regex("pattern").Matches(null));
|
||||
AssertExtensions.Throws<ArgumentNullException>("input", () => new Regex("pattern").Matches(null, 0));
|
||||
|
||||
// Pattern is null
|
||||
Assert.Throws<ArgumentNullException>("pattern", () => Regex.Matches("input", null));
|
||||
Assert.Throws<ArgumentNullException>("pattern", () => Regex.Matches("input", null, RegexOptions.None));
|
||||
Assert.Throws<ArgumentNullException>("pattern", () => Regex.Matches("input", null, RegexOptions.None, TimeSpan.FromSeconds(1)));
|
||||
AssertExtensions.Throws<ArgumentNullException>("pattern", () => Regex.Matches("input", null));
|
||||
AssertExtensions.Throws<ArgumentNullException>("pattern", () => Regex.Matches("input", null, RegexOptions.None));
|
||||
AssertExtensions.Throws<ArgumentNullException>("pattern", () => Regex.Matches("input", null, RegexOptions.None, TimeSpan.FromSeconds(1)));
|
||||
|
||||
// Options are invalid
|
||||
Assert.Throws<ArgumentOutOfRangeException>("options", () => Regex.Matches("input", "pattern", (RegexOptions)(-1)));
|
||||
Assert.Throws<ArgumentOutOfRangeException>("options", () => Regex.Matches("input", "pattern", (RegexOptions)(-1), TimeSpan.FromSeconds(1)));
|
||||
Assert.Throws<ArgumentOutOfRangeException>("options", () => Regex.Matches("input", "pattern", (RegexOptions)0x400));
|
||||
Assert.Throws<ArgumentOutOfRangeException>("options", () => Regex.Matches("input", "pattern", (RegexOptions)0x400, TimeSpan.FromSeconds(1)));
|
||||
AssertExtensions.Throws<ArgumentOutOfRangeException>("options", () => Regex.Matches("input", "pattern", (RegexOptions)(-1)));
|
||||
AssertExtensions.Throws<ArgumentOutOfRangeException>("options", () => Regex.Matches("input", "pattern", (RegexOptions)(-1), TimeSpan.FromSeconds(1)));
|
||||
AssertExtensions.Throws<ArgumentOutOfRangeException>("options", () => Regex.Matches("input", "pattern", (RegexOptions)0x400));
|
||||
AssertExtensions.Throws<ArgumentOutOfRangeException>("options", () => Regex.Matches("input", "pattern", (RegexOptions)0x400, TimeSpan.FromSeconds(1)));
|
||||
|
||||
// MatchTimeout is invalid
|
||||
Assert.Throws<ArgumentOutOfRangeException>("matchTimeout", () => Regex.Matches("input", "pattern", RegexOptions.None, TimeSpan.Zero));
|
||||
Assert.Throws<ArgumentOutOfRangeException>("matchTimeout", () => Regex.Matches("input", "pattern", RegexOptions.None, TimeSpan.Zero));
|
||||
AssertExtensions.Throws<ArgumentOutOfRangeException>("matchTimeout", () => Regex.Matches("input", "pattern", RegexOptions.None, TimeSpan.Zero));
|
||||
AssertExtensions.Throws<ArgumentOutOfRangeException>("matchTimeout", () => Regex.Matches("input", "pattern", RegexOptions.None, TimeSpan.Zero));
|
||||
|
||||
// Start is invalid
|
||||
Assert.Throws<ArgumentOutOfRangeException>("startat", () => new Regex("pattern").Matches("input", -1));
|
||||
Assert.Throws<ArgumentOutOfRangeException>("startat", () => new Regex("pattern").Matches("input", 6));
|
||||
AssertExtensions.Throws<ArgumentOutOfRangeException>("startat", () => new Regex("pattern").Matches("input", -1));
|
||||
AssertExtensions.Throws<ArgumentOutOfRangeException>("startat", () => new Regex("pattern").Matches("input", 6));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Licensed to the .NET Foundation under one or more agreements.
|
||||
// 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.
|
||||
|
||||
@@ -225,55 +225,55 @@ namespace System.Text.RegularExpressions.Tests
|
||||
public void Replace_Invalid()
|
||||
{
|
||||
// Input is null
|
||||
Assert.Throws<ArgumentNullException>("input", () => Regex.Replace(null, "pattern", "replacement"));
|
||||
Assert.Throws<ArgumentNullException>("input", () => Regex.Replace(null, "pattern", "replacement", RegexOptions.None));
|
||||
Assert.Throws<ArgumentNullException>("input", () => Regex.Replace(null, "pattern", "replacement", RegexOptions.None, TimeSpan.FromMilliseconds(1)));
|
||||
Assert.Throws<ArgumentNullException>("input", () => new Regex("pattern").Replace(null, "replacement"));
|
||||
Assert.Throws<ArgumentNullException>("input", () => new Regex("pattern").Replace(null, "replacement", 0));
|
||||
Assert.Throws<ArgumentNullException>("input", () => new Regex("pattern").Replace(null, "replacement", 0, 0));
|
||||
AssertExtensions.Throws<ArgumentNullException>("input", () => Regex.Replace(null, "pattern", "replacement"));
|
||||
AssertExtensions.Throws<ArgumentNullException>("input", () => Regex.Replace(null, "pattern", "replacement", RegexOptions.None));
|
||||
AssertExtensions.Throws<ArgumentNullException>("input", () => Regex.Replace(null, "pattern", "replacement", RegexOptions.None, TimeSpan.FromMilliseconds(1)));
|
||||
AssertExtensions.Throws<ArgumentNullException>("input", () => new Regex("pattern").Replace(null, "replacement"));
|
||||
AssertExtensions.Throws<ArgumentNullException>("input", () => new Regex("pattern").Replace(null, "replacement", 0));
|
||||
AssertExtensions.Throws<ArgumentNullException>("input", () => new Regex("pattern").Replace(null, "replacement", 0, 0));
|
||||
|
||||
Assert.Throws<ArgumentNullException>("input", () => Regex.Replace(null, "pattern", new MatchEvaluator(MatchEvaluator1)));
|
||||
Assert.Throws<ArgumentNullException>("input", () => Regex.Replace(null, "pattern", new MatchEvaluator(MatchEvaluator1), RegexOptions.None));
|
||||
Assert.Throws<ArgumentNullException>("input", () => Regex.Replace(null, "pattern", new MatchEvaluator(MatchEvaluator1), RegexOptions.None, TimeSpan.FromMilliseconds(1)));
|
||||
Assert.Throws<ArgumentNullException>("input", () => new Regex("pattern").Replace(null, new MatchEvaluator(MatchEvaluator1)));
|
||||
Assert.Throws<ArgumentNullException>("input", () => new Regex("pattern").Replace(null, new MatchEvaluator(MatchEvaluator1), 0));
|
||||
Assert.Throws<ArgumentNullException>("input", () => new Regex("pattern").Replace(null, new MatchEvaluator(MatchEvaluator1), 0, 0));
|
||||
AssertExtensions.Throws<ArgumentNullException>("input", () => Regex.Replace(null, "pattern", new MatchEvaluator(MatchEvaluator1)));
|
||||
AssertExtensions.Throws<ArgumentNullException>("input", () => Regex.Replace(null, "pattern", new MatchEvaluator(MatchEvaluator1), RegexOptions.None));
|
||||
AssertExtensions.Throws<ArgumentNullException>("input", () => Regex.Replace(null, "pattern", new MatchEvaluator(MatchEvaluator1), RegexOptions.None, TimeSpan.FromMilliseconds(1)));
|
||||
AssertExtensions.Throws<ArgumentNullException>("input", () => new Regex("pattern").Replace(null, new MatchEvaluator(MatchEvaluator1)));
|
||||
AssertExtensions.Throws<ArgumentNullException>("input", () => new Regex("pattern").Replace(null, new MatchEvaluator(MatchEvaluator1), 0));
|
||||
AssertExtensions.Throws<ArgumentNullException>("input", () => new Regex("pattern").Replace(null, new MatchEvaluator(MatchEvaluator1), 0, 0));
|
||||
|
||||
// Pattern is null
|
||||
Assert.Throws<ArgumentNullException>("pattern", () => Regex.Replace("input", null, "replacement"));
|
||||
Assert.Throws<ArgumentNullException>("pattern", () => Regex.Replace("input", null, "replacement", RegexOptions.None));
|
||||
Assert.Throws<ArgumentNullException>("pattern", () => Regex.Replace("input", null, "replacement", RegexOptions.None, TimeSpan.FromMilliseconds(1)));
|
||||
Assert.Throws<ArgumentNullException>("pattern", () => Regex.Replace("input", null, new MatchEvaluator(MatchEvaluator1)));
|
||||
Assert.Throws<ArgumentNullException>("pattern", () => Regex.Replace("input", null, new MatchEvaluator(MatchEvaluator1), RegexOptions.None));
|
||||
Assert.Throws<ArgumentNullException>("pattern", () => Regex.Replace("input", null, new MatchEvaluator(MatchEvaluator1), RegexOptions.None, TimeSpan.FromMilliseconds(1)));
|
||||
AssertExtensions.Throws<ArgumentNullException>("pattern", () => Regex.Replace("input", null, "replacement"));
|
||||
AssertExtensions.Throws<ArgumentNullException>("pattern", () => Regex.Replace("input", null, "replacement", RegexOptions.None));
|
||||
AssertExtensions.Throws<ArgumentNullException>("pattern", () => Regex.Replace("input", null, "replacement", RegexOptions.None, TimeSpan.FromMilliseconds(1)));
|
||||
AssertExtensions.Throws<ArgumentNullException>("pattern", () => Regex.Replace("input", null, new MatchEvaluator(MatchEvaluator1)));
|
||||
AssertExtensions.Throws<ArgumentNullException>("pattern", () => Regex.Replace("input", null, new MatchEvaluator(MatchEvaluator1), RegexOptions.None));
|
||||
AssertExtensions.Throws<ArgumentNullException>("pattern", () => Regex.Replace("input", null, new MatchEvaluator(MatchEvaluator1), RegexOptions.None, TimeSpan.FromMilliseconds(1)));
|
||||
|
||||
// Replacement is null
|
||||
Assert.Throws<ArgumentNullException>("replacement", () => Regex.Replace("input", "pattern", (string)null));
|
||||
Assert.Throws<ArgumentNullException>("replacement", () => Regex.Replace("input", "pattern", (string)null, RegexOptions.None));
|
||||
Assert.Throws<ArgumentNullException>("replacement", () => Regex.Replace("input", "pattern", (string)null, RegexOptions.None, TimeSpan.FromMilliseconds(1)));
|
||||
Assert.Throws<ArgumentNullException>("replacement", () => new Regex("pattern").Replace("input", (string)null));
|
||||
Assert.Throws<ArgumentNullException>("replacement", () => new Regex("pattern").Replace("input", (string)null, 0));
|
||||
Assert.Throws<ArgumentNullException>("replacement", () => new Regex("pattern").Replace("input", (string)null, 0, 0));
|
||||
AssertExtensions.Throws<ArgumentNullException>("replacement", () => Regex.Replace("input", "pattern", (string)null));
|
||||
AssertExtensions.Throws<ArgumentNullException>("replacement", () => Regex.Replace("input", "pattern", (string)null, RegexOptions.None));
|
||||
AssertExtensions.Throws<ArgumentNullException>("replacement", () => Regex.Replace("input", "pattern", (string)null, RegexOptions.None, TimeSpan.FromMilliseconds(1)));
|
||||
AssertExtensions.Throws<ArgumentNullException>("replacement", () => new Regex("pattern").Replace("input", (string)null));
|
||||
AssertExtensions.Throws<ArgumentNullException>("replacement", () => new Regex("pattern").Replace("input", (string)null, 0));
|
||||
AssertExtensions.Throws<ArgumentNullException>("replacement", () => new Regex("pattern").Replace("input", (string)null, 0, 0));
|
||||
|
||||
Assert.Throws<ArgumentNullException>("evaluator", () => Regex.Replace("input", "pattern", (MatchEvaluator)null));
|
||||
Assert.Throws<ArgumentNullException>("evaluator", () => Regex.Replace("input", "pattern", (MatchEvaluator)null, RegexOptions.None));
|
||||
Assert.Throws<ArgumentNullException>("evaluator", () => Regex.Replace("input", "pattern", (MatchEvaluator)null, RegexOptions.None, TimeSpan.FromMilliseconds(1)));
|
||||
Assert.Throws<ArgumentNullException>("evaluator", () => new Regex("pattern").Replace("input", (MatchEvaluator)null));
|
||||
Assert.Throws<ArgumentNullException>("evaluator", () => new Regex("pattern").Replace("input", (MatchEvaluator)null, 0));
|
||||
Assert.Throws<ArgumentNullException>("evaluator", () => new Regex("pattern").Replace("input", (MatchEvaluator)null, 0, 0));
|
||||
AssertExtensions.Throws<ArgumentNullException>("evaluator", () => Regex.Replace("input", "pattern", (MatchEvaluator)null));
|
||||
AssertExtensions.Throws<ArgumentNullException>("evaluator", () => Regex.Replace("input", "pattern", (MatchEvaluator)null, RegexOptions.None));
|
||||
AssertExtensions.Throws<ArgumentNullException>("evaluator", () => Regex.Replace("input", "pattern", (MatchEvaluator)null, RegexOptions.None, TimeSpan.FromMilliseconds(1)));
|
||||
AssertExtensions.Throws<ArgumentNullException>("evaluator", () => new Regex("pattern").Replace("input", (MatchEvaluator)null));
|
||||
AssertExtensions.Throws<ArgumentNullException>("evaluator", () => new Regex("pattern").Replace("input", (MatchEvaluator)null, 0));
|
||||
AssertExtensions.Throws<ArgumentNullException>("evaluator", () => new Regex("pattern").Replace("input", (MatchEvaluator)null, 0, 0));
|
||||
|
||||
// Count is invalid
|
||||
Assert.Throws<ArgumentOutOfRangeException>("count", () => new Regex("pattern").Replace("input", "replacement", -2));
|
||||
Assert.Throws<ArgumentOutOfRangeException>("count", () => new Regex("pattern").Replace("input", "replacement", -2, 0));
|
||||
Assert.Throws<ArgumentOutOfRangeException>("count", () => new Regex("pattern").Replace("input", new MatchEvaluator(MatchEvaluator1), -2));
|
||||
Assert.Throws<ArgumentOutOfRangeException>("count", () => new Regex("pattern").Replace("input", new MatchEvaluator(MatchEvaluator1), -2, 0));
|
||||
AssertExtensions.Throws<ArgumentOutOfRangeException>("count", () => new Regex("pattern").Replace("input", "replacement", -2));
|
||||
AssertExtensions.Throws<ArgumentOutOfRangeException>("count", () => new Regex("pattern").Replace("input", "replacement", -2, 0));
|
||||
AssertExtensions.Throws<ArgumentOutOfRangeException>("count", () => new Regex("pattern").Replace("input", new MatchEvaluator(MatchEvaluator1), -2));
|
||||
AssertExtensions.Throws<ArgumentOutOfRangeException>("count", () => new Regex("pattern").Replace("input", new MatchEvaluator(MatchEvaluator1), -2, 0));
|
||||
|
||||
// Start is invalid
|
||||
Assert.Throws<ArgumentOutOfRangeException>("startat", () => new Regex("pattern").Replace("input", "replacement", 0, -1));
|
||||
Assert.Throws<ArgumentOutOfRangeException>("startat", () => new Regex("pattern").Replace("input", new MatchEvaluator(MatchEvaluator1), 0, -1));
|
||||
AssertExtensions.Throws<ArgumentOutOfRangeException>("startat", () => new Regex("pattern").Replace("input", "replacement", 0, -1));
|
||||
AssertExtensions.Throws<ArgumentOutOfRangeException>("startat", () => new Regex("pattern").Replace("input", new MatchEvaluator(MatchEvaluator1), 0, -1));
|
||||
|
||||
Assert.Throws<ArgumentOutOfRangeException>("startat", () => new Regex("pattern").Replace("input", "replacement", 0, 6));
|
||||
Assert.Throws<ArgumentOutOfRangeException>("startat", () => new Regex("pattern").Replace("input", new MatchEvaluator(MatchEvaluator1), 0, 6));
|
||||
AssertExtensions.Throws<ArgumentOutOfRangeException>("startat", () => new Regex("pattern").Replace("input", "replacement", 0, 6));
|
||||
AssertExtensions.Throws<ArgumentOutOfRangeException>("startat", () => new Regex("pattern").Replace("input", new MatchEvaluator(MatchEvaluator1), 0, 6));
|
||||
}
|
||||
|
||||
public static string MatchEvaluator1(Match match) => match.Value.ToLower() == "big" ? "Huge": "Tiny";
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Licensed to the .NET Foundation under one or more agreements.
|
||||
// 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.
|
||||
|
||||
@@ -90,25 +90,25 @@ namespace System.Text.RegularExpressions.Tests
|
||||
public void Split_Invalid()
|
||||
{
|
||||
// Input is null
|
||||
Assert.Throws<ArgumentNullException>("input", () => Regex.Split(null, "pattern"));
|
||||
Assert.Throws<ArgumentNullException>("input", () => Regex.Split(null, "pattern", RegexOptions.None));
|
||||
Assert.Throws<ArgumentNullException>("input", () => Regex.Split(null, "pattern", RegexOptions.None, TimeSpan.FromMilliseconds(1)));
|
||||
Assert.Throws<ArgumentNullException>("input", () => new Regex("pattern").Split(null));
|
||||
Assert.Throws<ArgumentNullException>("input", () => new Regex("pattern").Split(null, 0));
|
||||
Assert.Throws<ArgumentNullException>("input", () => new Regex("pattern").Split(null, 0, 0));
|
||||
AssertExtensions.Throws<ArgumentNullException>("input", () => Regex.Split(null, "pattern"));
|
||||
AssertExtensions.Throws<ArgumentNullException>("input", () => Regex.Split(null, "pattern", RegexOptions.None));
|
||||
AssertExtensions.Throws<ArgumentNullException>("input", () => Regex.Split(null, "pattern", RegexOptions.None, TimeSpan.FromMilliseconds(1)));
|
||||
AssertExtensions.Throws<ArgumentNullException>("input", () => new Regex("pattern").Split(null));
|
||||
AssertExtensions.Throws<ArgumentNullException>("input", () => new Regex("pattern").Split(null, 0));
|
||||
AssertExtensions.Throws<ArgumentNullException>("input", () => new Regex("pattern").Split(null, 0, 0));
|
||||
|
||||
// Pattern is null
|
||||
Assert.Throws<ArgumentNullException>("pattern", () => Regex.Split("input", null));
|
||||
Assert.Throws<ArgumentNullException>("pattern", () => Regex.Split("input", null, RegexOptions.None));
|
||||
Assert.Throws<ArgumentNullException>("pattern", () => Regex.Split("input", null, RegexOptions.None, TimeSpan.FromMilliseconds(1)));
|
||||
AssertExtensions.Throws<ArgumentNullException>("pattern", () => Regex.Split("input", null));
|
||||
AssertExtensions.Throws<ArgumentNullException>("pattern", () => Regex.Split("input", null, RegexOptions.None));
|
||||
AssertExtensions.Throws<ArgumentNullException>("pattern", () => Regex.Split("input", null, RegexOptions.None, TimeSpan.FromMilliseconds(1)));
|
||||
|
||||
// Count is invalid
|
||||
Assert.Throws<ArgumentOutOfRangeException>("count", () => new Regex("pattern").Split("input", -1));
|
||||
Assert.Throws<ArgumentOutOfRangeException>("count", () => new Regex("pattern").Split("input", -1, 0));
|
||||
AssertExtensions.Throws<ArgumentOutOfRangeException>("count", () => new Regex("pattern").Split("input", -1));
|
||||
AssertExtensions.Throws<ArgumentOutOfRangeException>("count", () => new Regex("pattern").Split("input", -1, 0));
|
||||
|
||||
// Start is invalid
|
||||
Assert.Throws<ArgumentOutOfRangeException>("startat", () => new Regex("pattern").Split("input", 0, -1));
|
||||
Assert.Throws<ArgumentOutOfRangeException>("startat", () => new Regex("pattern").Split("input", 0, 6));
|
||||
AssertExtensions.Throws<ArgumentOutOfRangeException>("startat", () => new Regex("pattern").Split("input", 0, -1));
|
||||
AssertExtensions.Throws<ArgumentOutOfRangeException>("startat", () => new Regex("pattern").Split("input", 0, 6));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,6 +15,12 @@
|
||||
<Compile Include="$(CommonTestPath)\System\PlatformDetection.cs">
|
||||
<Link>Common\tests\System\PlatformDetection.cs</Link>
|
||||
</Compile>
|
||||
<Compile Include="$(CommonTestPath)\System\Diagnostics\RemoteExecutorTestBase.cs">
|
||||
<Link>Common\System\Diagnostics\RemoteExecutorTestBase.cs</Link>
|
||||
</Compile>
|
||||
<Compile Include="$(CommonTestPath)\System\IO\FileCleanupTestBase.cs">
|
||||
<Link>Common\System\IO\FileCleanupTestBase.cs</Link>
|
||||
</Compile>
|
||||
<Compile Include="CaptureCollectionTests.cs" />
|
||||
<Compile Include="GroupCollectionTests.cs" />
|
||||
<Compile Include="MatchCollectionTests.cs" />
|
||||
@@ -25,12 +31,19 @@
|
||||
<Compile Include="Regex.UnicodeChar.Tests.cs" />
|
||||
<Compile Include="Regex.Groups.Tests.cs" />
|
||||
<Compile Include="Regex.Replace.Tests.cs" />
|
||||
<Compile Include="Regex.Serialization.cs" />
|
||||
<Compile Include="Regex.Split.Tests.cs" />
|
||||
<Compile Include="Regex.Match.Tests.cs" />
|
||||
<Compile Include="Regex.Tests.Common.cs" />
|
||||
<Compile Include="$(CommonTestPath)\System\AssertExtensions.cs">
|
||||
<Link>Common\System\AssertExtensions.cs</Link>
|
||||
</Compile>
|
||||
<Compile Include="$(CommonTestPath)\System\Runtime\Serialization\Formatters\BinaryFormatterHelpers.cs">
|
||||
<Link>System\Runtime\Serialization\Formatters\BinaryFormatterHelpers.cs</Link>
|
||||
</Compile>
|
||||
<ProjectReference Include="$(CommonTestPath)\System\Diagnostics\RemoteExecutorConsoleApp\RemoteExecutorConsoleApp.csproj">
|
||||
<Name>RemoteExecutorConsoleApp</Name>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<ItemGroup Condition="'$(TargetGroup)' == 'netcoreapp'">
|
||||
<Compile Include="PrecompiledRegexScenarioTest.cs" />
|
||||
@@ -42,12 +55,6 @@
|
||||
<Link>Common\System\Diagnostics\DebuggerAttributes.cs</Link>
|
||||
</Compile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Regex.Serialization.cs" />
|
||||
<Compile Include="$(CommonTestPath)\System\Runtime\Serialization\Formatters\BinaryFormatterHelpers.cs">
|
||||
<Link>System\Runtime\Serialization\Formatters\BinaryFormatterHelpers.cs</Link>
|
||||
</Compile>
|
||||
</ItemGroup>
|
||||
<!-- Automatically added by VS -->
|
||||
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
|
||||
</Project>
|
||||
Reference in New Issue
Block a user