diff --git a/src/System.Text.RegularExpressions/pkg/System.Text.RegularExpressions.pkgproj b/src/System.Text.RegularExpressions/pkg/System.Text.RegularExpressions.pkgproj
index 4343aba64d21..c134914c49a3 100644
--- a/src/System.Text.RegularExpressions/pkg/System.Text.RegularExpressions.pkgproj
+++ b/src/System.Text.RegularExpressions/pkg/System.Text.RegularExpressions.pkgproj
@@ -2,7 +2,7 @@
-
+
net463;netcoreapp1.1;$(AllXamarinFrameworks)
diff --git a/src/System.Text.RegularExpressions/ref/System.Text.RegularExpressions.builds b/src/System.Text.RegularExpressions/ref/System.Text.RegularExpressions.builds
new file mode 100644
index 000000000000..3b09b658f036
--- /dev/null
+++ b/src/System.Text.RegularExpressions/ref/System.Text.RegularExpressions.builds
@@ -0,0 +1,11 @@
+
+
+
+
+
+
+ netcoreapp1.1
+
+
+
+
diff --git a/src/System.Text.RegularExpressions/ref/System.Text.RegularExpressions.csproj b/src/System.Text.RegularExpressions/ref/System.Text.RegularExpressions.csproj
index a38d128e686c..a342cee09859 100644
--- a/src/System.Text.RegularExpressions/ref/System.Text.RegularExpressions.csproj
+++ b/src/System.Text.RegularExpressions/ref/System.Text.RegularExpressions.csproj
@@ -8,6 +8,9 @@
+
+
+
diff --git a/src/System.Text.RegularExpressions/ref/System.Text.RegularExpressions.netcoreapp1.1.cs b/src/System.Text.RegularExpressions/ref/System.Text.RegularExpressions.netcoreapp1.1.cs
new file mode 100644
index 000000000000..6dddfad15ca0
--- /dev/null
+++ b/src/System.Text.RegularExpressions/ref/System.Text.RegularExpressions.netcoreapp1.1.cs
@@ -0,0 +1,77 @@
+// 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.
+// ------------------------------------------------------------------------------
+// Changes to this file must follow the http://aka.ms/api-review process.
+// ------------------------------------------------------------------------------
+
+
+namespace System.Text.RegularExpressions
+{
+ public partial class CaptureCollection : System.Collections.Generic.ICollection, System.Collections.Generic.IEnumerable, System.Collections.Generic.IList, System.Collections.Generic.IReadOnlyCollection, System.Collections.Generic.IReadOnlyList, System.Collections.ICollection, System.Collections.IEnumerable, System.Collections.IList
+ {
+ public void CopyTo(System.Text.RegularExpressions.Capture[] array, int arrayIndex) { }
+ System.Collections.Generic.IEnumerator System.Collections.Generic.IEnumerable.GetEnumerator() { throw null; }
+ int System.Collections.Generic.IList.IndexOf(System.Text.RegularExpressions.Capture item) { throw null; }
+ void System.Collections.Generic.IList.Insert(int index, System.Text.RegularExpressions.Capture item) { }
+ void System.Collections.Generic.IList.RemoveAt(int index) { }
+ System.Text.RegularExpressions.Capture System.Collections.Generic.IList.this[int index] { get { throw null; } set { } }
+ void System.Collections.Generic.ICollection.Add(System.Text.RegularExpressions.Capture item) { }
+ void System.Collections.Generic.ICollection.Clear() { }
+ bool System.Collections.Generic.ICollection.Contains(System.Text.RegularExpressions.Capture item) { throw null; }
+ bool System.Collections.Generic.ICollection.Remove(System.Text.RegularExpressions.Capture item) { throw null; }
+ int System.Collections.IList.Add(object value) { throw null; }
+ void System.Collections.IList.Clear() { }
+ bool System.Collections.IList.Contains(object value) { throw null; }
+ int System.Collections.IList.IndexOf(object value) { throw null; }
+ void System.Collections.IList.Insert(int index, object value) { }
+ bool System.Collections.IList.IsFixedSize { get { throw null; } }
+ void System.Collections.IList.Remove(object value) { }
+ void System.Collections.IList.RemoveAt(int index) { }
+ object System.Collections.IList.this[int index] { get { throw null; } set { } }
+ }
+ public partial class GroupCollection : System.Collections.Generic.ICollection, System.Collections.Generic.IEnumerable, System.Collections.Generic.IList, System.Collections.Generic.IReadOnlyCollection, System.Collections.Generic.IReadOnlyList, System.Collections.ICollection, System.Collections.IEnumerable, System.Collections.IList
+ {
+ public void CopyTo(System.Text.RegularExpressions.Group[] array, int arrayIndex) { }
+ System.Collections.Generic.IEnumerator System.Collections.Generic.IEnumerable.GetEnumerator() { throw null; }
+ int System.Collections.Generic.IList.IndexOf(System.Text.RegularExpressions.Group item) { throw null; }
+ void System.Collections.Generic.IList.Insert(int index, System.Text.RegularExpressions.Group item) { }
+ void System.Collections.Generic.IList.RemoveAt(int index) { }
+ System.Text.RegularExpressions.Group System.Collections.Generic.IList.this[int index] { get { throw null; } set { } }
+ void System.Collections.Generic.ICollection.Add(System.Text.RegularExpressions.Group item) { }
+ void System.Collections.Generic.ICollection.Clear() { }
+ bool System.Collections.Generic.ICollection.Contains(System.Text.RegularExpressions.Group item) { throw null; }
+ bool System.Collections.Generic.ICollection.Remove(System.Text.RegularExpressions.Group item) { throw null; }
+ int System.Collections.IList.Add(object value) { throw null; }
+ void System.Collections.IList.Clear() { }
+ bool System.Collections.IList.Contains(object value) { throw null; }
+ int System.Collections.IList.IndexOf(object value) { throw null; }
+ void System.Collections.IList.Insert(int index, object value) { }
+ bool System.Collections.IList.IsFixedSize { get { throw null; } }
+ void System.Collections.IList.Remove(object value) { }
+ void System.Collections.IList.RemoveAt(int index) { }
+ object System.Collections.IList.this[int index] { get { throw null; } set { } }
+ }
+ public partial class MatchCollection : System.Collections.Generic.ICollection, System.Collections.Generic.IEnumerable, System.Collections.Generic.IList, System.Collections.Generic.IReadOnlyCollection, System.Collections.Generic.IReadOnlyList, System.Collections.ICollection, System.Collections.IEnumerable, System.Collections.IList
+ {
+ public void CopyTo(System.Text.RegularExpressions.Match[] array, int arrayIndex) { }
+ System.Collections.Generic.IEnumerator System.Collections.Generic.IEnumerable.GetEnumerator() { throw null; }
+ int System.Collections.Generic.IList.IndexOf(System.Text.RegularExpressions.Match item) { throw null; }
+ void System.Collections.Generic.IList.Insert(int index, System.Text.RegularExpressions.Match item) { }
+ void System.Collections.Generic.IList.RemoveAt(int index) { }
+ System.Text.RegularExpressions.Match System.Collections.Generic.IList.this[int index] { get { throw null; } set { } }
+ void System.Collections.Generic.ICollection.Add(System.Text.RegularExpressions.Match item) { }
+ void System.Collections.Generic.ICollection.Clear() { }
+ bool System.Collections.Generic.ICollection.Contains(System.Text.RegularExpressions.Match item) { throw null; }
+ bool System.Collections.Generic.ICollection.Remove(System.Text.RegularExpressions.Match item) { throw null; }
+ int System.Collections.IList.Add(object value) { throw null; }
+ void System.Collections.IList.Clear() { }
+ bool System.Collections.IList.Contains(object value) { throw null; }
+ int System.Collections.IList.IndexOf(object value) { throw null; }
+ void System.Collections.IList.Insert(int index, object value) { }
+ bool System.Collections.IList.IsFixedSize { get { throw null; } }
+ void System.Collections.IList.Remove(object value) { }
+ void System.Collections.IList.RemoveAt(int index) { }
+ object System.Collections.IList.this[int index] { get { throw null; } set { } }
+ }
+}
diff --git a/src/System.Text.RegularExpressions/ref/project.json b/src/System.Text.RegularExpressions/ref/project.json
index bf3be05e3c9a..ff6d3212f136 100644
--- a/src/System.Text.RegularExpressions/ref/project.json
+++ b/src/System.Text.RegularExpressions/ref/project.json
@@ -4,6 +4,7 @@
"System.Collections.NonGeneric": "4.4.0-beta-24612-03"
},
"frameworks": {
- "netstandard1.7": {}
+ "netstandard1.7": {},
+ "netcoreapp1.1": {},
}
}
diff --git a/src/System.Text.RegularExpressions/src/Resources/Strings.resx b/src/System.Text.RegularExpressions/src/Resources/Strings.resx
index a19bf53c1928..61d67f4602a5 100644
--- a/src/System.Text.RegularExpressions/src/Resources/Strings.resx
+++ b/src/System.Text.RegularExpressions/src/Resources/Strings.resx
@@ -123,6 +123,9 @@
Alternation conditions cannot be comments.
+
+ Destination array is not long enough to copy all the items in the collection. Check array index and length.
+
Cannot include class \\{0} in character range.
@@ -186,6 +189,9 @@
Not enough )'s.
+
+ Collection is read-only.
+
This operation is only allowed once per object.
diff --git a/src/System.Text.RegularExpressions/src/System.Text.RegularExpressions.csproj b/src/System.Text.RegularExpressions/src/System.Text.RegularExpressions.csproj
index a7a45e9e4fb8..40ae6023f9d7 100644
--- a/src/System.Text.RegularExpressions/src/System.Text.RegularExpressions.csproj
+++ b/src/System.Text.RegularExpressions/src/System.Text.RegularExpressions.csproj
@@ -21,6 +21,7 @@
+
diff --git a/src/System.Text.RegularExpressions/src/System/Text/RegularExpressions/RegexCaptureCollection.cs b/src/System.Text.RegularExpressions/src/System/Text/RegularExpressions/RegexCaptureCollection.cs
index 5290a20cbd36..e306088d50e9 100644
--- a/src/System.Text.RegularExpressions/src/System/Text/RegularExpressions/RegexCaptureCollection.cs
+++ b/src/System.Text.RegularExpressions/src/System/Text/RegularExpressions/RegexCaptureCollection.cs
@@ -6,6 +6,7 @@
// contained in a compiled Regex.
using System.Collections;
+using System.Collections.Generic;
using System.Diagnostics;
namespace System.Text.RegularExpressions
@@ -19,7 +20,9 @@ namespace System.Text.RegularExpressions
/// Represents a sequence of capture substrings. The object is used
/// to return the set of captures done by a single capturing group.
///
- public class CaptureCollection : ICollection
+ [DebuggerDisplay("Count = {Count}")]
+ [DebuggerTypeProxy(typeof(RegexCollectionDebuggerProxy))]
+ public class CaptureCollection : IList, IReadOnlyList, IList
{
private readonly Group _group;
private readonly int _capcount;
@@ -36,26 +39,19 @@ internal CaptureCollection(Group group)
///
/// Returns the number of captures.
///
- public int Count
- {
- get { return _capcount; }
- }
+ public int Count => _capcount;
///
/// Returns a specific capture, by index, in this collection.
///
- public Capture this[int i]
- {
- get { return GetCapture(i); }
- }
+ public Capture this[int i] => GetCapture(i);
///
/// Provides an enumerator in the same order as Item[].
///
- public IEnumerator GetEnumerator()
- {
- return new Enumerator(this);
- }
+ public IEnumerator GetEnumerator() => new Enumerator(this);
+
+ IEnumerator IEnumerable.GetEnumerator() => new Enumerator(this);
///
/// Returns the set of captures for the group
@@ -81,15 +77,9 @@ private Capture GetCapture(int i)
return _captures[i];
}
- public bool IsSynchronized
- {
- get { return false; }
- }
+ public bool IsSynchronized => false;
- public object SyncRoot
- {
- get { return _group; }
- }
+ public object SyncRoot => _group;
public void CopyTo(Array array, int arrayIndex)
{
@@ -102,7 +92,106 @@ public void CopyTo(Array array, int arrayIndex)
}
}
- private class Enumerator : IEnumerator
+ public void CopyTo(Capture[] array, int arrayIndex)
+ {
+ if (array == null)
+ throw new ArgumentNullException(nameof(array));
+ if (arrayIndex < 0 || arrayIndex > array.Length)
+ throw new ArgumentOutOfRangeException(nameof(arrayIndex));
+ if (array.Length - arrayIndex < Count)
+ throw new ArgumentException(SR.Arg_ArrayPlusOffTooSmall);
+
+ for (int i = arrayIndex, j = 0; j < Count; i++, j++)
+ {
+ array[i] = this[j];
+ }
+ }
+
+ int IList.IndexOf(Capture item)
+ {
+ var comparer = EqualityComparer.Default;
+ for (int i = 0; i < Count; i++)
+ {
+ if (comparer.Equals(this[i], item))
+ return i;
+ }
+ return -1;
+ }
+
+ void IList.Insert(int index, Capture item)
+ {
+ throw new NotSupportedException(SR.NotSupported_ReadOnlyCollection);
+ }
+
+ void IList.RemoveAt(int index)
+ {
+ throw new NotSupportedException(SR.NotSupported_ReadOnlyCollection);
+ }
+
+ Capture IList.this[int index]
+ {
+ get { return this[index]; }
+ set { throw new NotSupportedException(SR.NotSupported_ReadOnlyCollection); }
+ }
+
+ void ICollection.Add(Capture item)
+ {
+ throw new NotSupportedException(SR.NotSupported_ReadOnlyCollection);
+ }
+
+ void ICollection.Clear()
+ {
+ throw new NotSupportedException(SR.NotSupported_ReadOnlyCollection);
+ }
+
+ bool ICollection.Contains(Capture item) =>
+ ((IList)this).IndexOf(item) >= 0;
+
+ bool ICollection.Remove(Capture item)
+ {
+ throw new NotSupportedException(SR.NotSupported_ReadOnlyCollection);
+ }
+
+ int IList.Add(object value)
+ {
+ throw new NotSupportedException(SR.NotSupported_ReadOnlyCollection);
+ }
+
+ void IList.Clear()
+ {
+ throw new NotSupportedException(SR.NotSupported_ReadOnlyCollection);
+ }
+
+ bool IList.Contains(object value) =>
+ value is Capture && ((ICollection)this).Contains((Capture)value);
+
+ int IList.IndexOf(object value) =>
+ value is Capture ? ((IList)this).IndexOf((Capture)value) : -1;
+
+ void IList.Insert(int index, object value)
+ {
+ throw new NotSupportedException(SR.NotSupported_ReadOnlyCollection);
+ }
+
+ bool IList.IsFixedSize => true;
+
+ void IList.Remove(object value)
+ {
+ throw new NotSupportedException(SR.NotSupported_ReadOnlyCollection);
+ }
+
+ void IList.RemoveAt(int index)
+ {
+ throw new NotSupportedException(SR.NotSupported_ReadOnlyCollection);
+ }
+
+ object IList.this[int index]
+ {
+ get { return this[index]; }
+ set { throw new NotSupportedException(SR.NotSupported_ReadOnlyCollection); }
+ }
+
+ private sealed class Enumerator : IEnumerator
{
private readonly CaptureCollection _collection;
private int _index;
@@ -138,15 +227,14 @@ public Capture Current
}
}
- object IEnumerator.Current
- {
- get { return Current; }
- }
+ object IEnumerator.Current => Current;
void IEnumerator.Reset()
{
_index = -1;
}
+
+ void IDisposable.Dispose() { }
}
}
}
diff --git a/src/System.Text.RegularExpressions/src/System/Text/RegularExpressions/RegexCollectionDebuggerProxy.cs b/src/System.Text.RegularExpressions/src/System/Text/RegularExpressions/RegexCollectionDebuggerProxy.cs
new file mode 100644
index 000000000000..5caea8d58fba
--- /dev/null
+++ b/src/System.Text.RegularExpressions/src/System/Text/RegularExpressions/RegexCollectionDebuggerProxy.cs
@@ -0,0 +1,33 @@
+// 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;
+
+namespace System.Text.RegularExpressions
+{
+ internal sealed class RegexCollectionDebuggerProxy
+ {
+ private readonly ICollection _collection;
+
+ public RegexCollectionDebuggerProxy(ICollection collection)
+ {
+ if (collection == null)
+ throw new ArgumentNullException(nameof(collection));
+
+ _collection = collection;
+ }
+
+ [DebuggerBrowsable(DebuggerBrowsableState.RootHidden)]
+ public T[] Items
+ {
+ get
+ {
+ T[] items = new T[_collection.Count];
+ _collection.CopyTo(items, 0);
+ return items;
+ }
+ }
+ }
+}
diff --git a/src/System.Text.RegularExpressions/src/System/Text/RegularExpressions/RegexGroup.cs b/src/System.Text.RegularExpressions/src/System/Text/RegularExpressions/RegexGroup.cs
index 3d35c07d0f14..6dca9d6ca256 100644
--- a/src/System.Text.RegularExpressions/src/System/Text/RegularExpressions/RegexGroup.cs
+++ b/src/System.Text.RegularExpressions/src/System/Text/RegularExpressions/RegexGroup.cs
@@ -16,7 +16,7 @@ namespace System.Text.RegularExpressions
public class Group : Capture
{
// the empty group object
- internal static Group _emptygroup = new Group(String.Empty, Array.Empty(), 0, string.Empty);
+ internal static Group s_emptyGroup = new Group(string.Empty, Array.Empty(), 0, string.Empty);
internal readonly int[] _caps;
internal int _capcount;
diff --git a/src/System.Text.RegularExpressions/src/System/Text/RegularExpressions/RegexGroupCollection.cs b/src/System.Text.RegularExpressions/src/System/Text/RegularExpressions/RegexGroupCollection.cs
index dffe736c0a94..f13ea13e739c 100644
--- a/src/System.Text.RegularExpressions/src/System/Text/RegularExpressions/RegexGroupCollection.cs
+++ b/src/System.Text.RegularExpressions/src/System/Text/RegularExpressions/RegexGroupCollection.cs
@@ -15,7 +15,9 @@ namespace System.Text.RegularExpressions
/// Represents a sequence of capture substrings. The object is used
/// to return the set of captures done by a single capturing group.
///
- public class GroupCollection : ICollection
+ [DebuggerDisplay("Count = {Count}")]
+ [DebuggerTypeProxy(typeof(RegexCollectionDebuggerProxy))]
+ public class GroupCollection : IList, IReadOnlyList, IList
{
private readonly Match _match;
private readonly Hashtable _captureMap;
@@ -34,34 +36,20 @@ internal GroupCollection(Match match, Hashtable caps)
///
/// Returns the number of groups.
///
- public int Count
- {
- get { return _match._matchcount.Length; }
- }
-
- public Group this[int groupnum]
- {
- get { return GetGroup(groupnum); }
- }
+ public int Count => _match._matchcount.Length;
- public Group this[string groupname]
- {
- get
- {
- if (_match._regex == null)
- return Group._emptygroup;
+ public Group this[int groupnum] => GetGroup(groupnum);
- return GetGroup(_match._regex.GroupNumberFromName(groupname));
- }
- }
+ public Group this[string groupname] => _match._regex == null ?
+ Group.s_emptyGroup :
+ GetGroup(_match._regex.GroupNumberFromName(groupname));
///
/// Provides an enumerator in the same order as Item[].
///
- public IEnumerator GetEnumerator()
- {
- return new Enumerator(this);
- }
+ public IEnumerator GetEnumerator() => new Enumerator(this);
+
+ IEnumerator IEnumerable.GetEnumerator() => new Enumerator(this);
private Group GetGroup(int groupnum)
{
@@ -78,7 +66,7 @@ private Group GetGroup(int groupnum)
return GetGroupImpl(groupnum);
}
- return Group._emptygroup;
+ return Group.s_emptyGroup;
}
///
@@ -104,15 +92,9 @@ private Group GetGroupImpl(int groupnum)
return _groups[groupnum - 1];
}
- public bool IsSynchronized
- {
- get { return false; }
- }
+ public bool IsSynchronized => false;
- public object SyncRoot
- {
- get { return _match; }
- }
+ public object SyncRoot => _match;
public void CopyTo(Array array, int arrayIndex)
{
@@ -125,7 +107,106 @@ public void CopyTo(Array array, int arrayIndex)
}
}
- private class Enumerator : IEnumerator
+ public void CopyTo(Group[] array, int arrayIndex)
+ {
+ if (array == null)
+ throw new ArgumentNullException(nameof(array));
+ if (arrayIndex < 0 || arrayIndex > array.Length)
+ throw new ArgumentOutOfRangeException(nameof(arrayIndex));
+ if (array.Length - arrayIndex < Count)
+ throw new ArgumentException(SR.Arg_ArrayPlusOffTooSmall);
+
+ for (int i = arrayIndex, j = 0; j < Count; i++, j++)
+ {
+ array[i] = this[j];
+ }
+ }
+
+ int IList.IndexOf(Group item)
+ {
+ var comparer = EqualityComparer.Default;
+ for (int i = 0; i < Count; i++)
+ {
+ if (comparer.Equals(this[i], item))
+ return i;
+ }
+ return -1;
+ }
+
+ void IList.Insert(int index, Group item)
+ {
+ throw new NotSupportedException(SR.NotSupported_ReadOnlyCollection);
+ }
+
+ void IList.RemoveAt(int index)
+ {
+ throw new NotSupportedException(SR.NotSupported_ReadOnlyCollection);
+ }
+
+ Group IList.this[int index]
+ {
+ get { return this[index]; }
+ set { throw new NotSupportedException(SR.NotSupported_ReadOnlyCollection); }
+ }
+
+ void ICollection.Add(Group item)
+ {
+ throw new NotSupportedException(SR.NotSupported_ReadOnlyCollection);
+ }
+
+ void ICollection.Clear()
+ {
+ throw new NotSupportedException(SR.NotSupported_ReadOnlyCollection);
+ }
+
+ bool ICollection.Contains(Group item) =>
+ ((IList)this).IndexOf(item) >= 0;
+
+ bool ICollection.Remove(Group item)
+ {
+ throw new NotSupportedException(SR.NotSupported_ReadOnlyCollection);
+ }
+
+ int IList.Add(object value)
+ {
+ throw new NotSupportedException(SR.NotSupported_ReadOnlyCollection);
+ }
+
+ void IList.Clear()
+ {
+ throw new NotSupportedException(SR.NotSupported_ReadOnlyCollection);
+ }
+
+ bool IList.Contains(object value) =>
+ value is Group && ((ICollection)this).Contains((Group)value);
+
+ int IList.IndexOf(object value) =>
+ value is Group ? ((IList)this).IndexOf((Group)value) : -1;
+
+ void IList.Insert(int index, object value)
+ {
+ throw new NotSupportedException(SR.NotSupported_ReadOnlyCollection);
+ }
+
+ bool IList.IsFixedSize => true;
+
+ void IList.Remove(object value)
+ {
+ throw new NotSupportedException(SR.NotSupported_ReadOnlyCollection);
+ }
+
+ void IList.RemoveAt(int index)
+ {
+ throw new NotSupportedException(SR.NotSupported_ReadOnlyCollection);
+ }
+
+ object IList.this[int index]
+ {
+ get { return this[index]; }
+ set { throw new NotSupportedException(SR.NotSupported_ReadOnlyCollection); }
+ }
+
+ private sealed class Enumerator : IEnumerator
{
private readonly GroupCollection _collection;
private int _index;
@@ -161,15 +242,14 @@ public Group Current
}
}
- object IEnumerator.Current
- {
- get { return Current; }
- }
+ object IEnumerator.Current => Current;
void IEnumerator.Reset()
{
_index = -1;
}
+
+ void IDisposable.Dispose() { }
}
}
}
diff --git a/src/System.Text.RegularExpressions/src/System/Text/RegularExpressions/RegexMatchCollection.cs b/src/System.Text.RegularExpressions/src/System/Text/RegularExpressions/RegexMatchCollection.cs
index c2833df72230..7e28d26a3f8c 100644
--- a/src/System.Text.RegularExpressions/src/System/Text/RegularExpressions/RegexMatchCollection.cs
+++ b/src/System.Text.RegularExpressions/src/System/Text/RegularExpressions/RegexMatchCollection.cs
@@ -20,7 +20,9 @@ namespace System.Text.RegularExpressions
/// Represents the set of names appearing as capturing group
/// names in a regular expression.
///
- public class MatchCollection : ICollection
+ [DebuggerDisplay("Count = {Count}")]
+ [DebuggerTypeProxy(typeof(RegexCollectionDebuggerProxy))]
+ public class MatchCollection : IList, IReadOnlyList, IList
{
private readonly Regex _regex;
private readonly List _matches;
@@ -82,10 +84,9 @@ public virtual Match this[int i]
///
/// Provides an enumerator in the same order as Item[i].
///
- public IEnumerator GetEnumerator()
- {
- return new Enumerator(this);
- }
+ public IEnumerator GetEnumerator() => new Enumerator(this);
+
+ IEnumerator IEnumerable.GetEnumerator() => new Enumerator(this);
private Match GetMatch(int i)
{
@@ -126,23 +127,105 @@ private void EnsureInitialized()
}
}
- public bool IsSynchronized
+ public bool IsSynchronized => false;
+
+ public object SyncRoot => this;
+
+ public void CopyTo(Array array, int arrayIndex)
{
- get { return false; }
+ EnsureInitialized();
+ ((ICollection)_matches).CopyTo(array, arrayIndex);
}
- public object SyncRoot
+ public void CopyTo(Match[] array, int arrayIndex)
{
- get { return this; }
+ EnsureInitialized();
+ _matches.CopyTo(array, arrayIndex);
}
- public void CopyTo(Array array, int arrayIndex)
+ int IList.IndexOf(Match item)
{
EnsureInitialized();
- ((ICollection)_matches).CopyTo(array, arrayIndex);
+ return _matches.IndexOf(item);
}
- private class Enumerator : IEnumerator
+ void IList.Insert(int index, Match item)
+ {
+ throw new NotSupportedException(SR.NotSupported_ReadOnlyCollection);
+ }
+
+ void IList.RemoveAt(int index)
+ {
+ throw new NotSupportedException(SR.NotSupported_ReadOnlyCollection);
+ }
+
+ Match IList.this[int index]
+ {
+ get { return this[index]; }
+ set { throw new NotSupportedException(SR.NotSupported_ReadOnlyCollection); }
+ }
+
+ void ICollection.Add(Match item)
+ {
+ throw new NotSupportedException(SR.NotSupported_ReadOnlyCollection);
+ }
+
+ void ICollection.Clear()
+ {
+ throw new NotSupportedException(SR.NotSupported_ReadOnlyCollection);
+ }
+
+ bool ICollection.Contains(Match item)
+ {
+ EnsureInitialized();
+ return _matches.Contains(item);
+ }
+
+ bool ICollection.Remove(Match item)
+ {
+ throw new NotSupportedException(SR.NotSupported_ReadOnlyCollection);
+ }
+
+ int IList.Add(object value)
+ {
+ throw new NotSupportedException(SR.NotSupported_ReadOnlyCollection);
+ }
+
+ void IList.Clear()
+ {
+ throw new NotSupportedException(SR.NotSupported_ReadOnlyCollection);
+ }
+
+ bool IList.Contains(object value) =>
+ value is Match && ((ICollection)this).Contains((Match)value);
+
+ int IList.IndexOf(object value) =>
+ value is Match ? ((IList)this).IndexOf((Match)value) : -1;
+
+ void IList.Insert(int index, object value)
+ {
+ throw new NotSupportedException(SR.NotSupported_ReadOnlyCollection);
+ }
+
+ bool IList.IsFixedSize => true;
+
+ void IList.Remove(object value)
+ {
+ throw new NotSupportedException(SR.NotSupported_ReadOnlyCollection);
+ }
+
+ void IList.RemoveAt(int index)
+ {
+ throw new NotSupportedException(SR.NotSupported_ReadOnlyCollection);
+ }
+
+ object IList.this[int index]
+ {
+ get { return this[index]; }
+ set { throw new NotSupportedException(SR.NotSupported_ReadOnlyCollection); }
+ }
+
+ private sealed class Enumerator : IEnumerator
{
private readonly MatchCollection _collection;
private int _index;
@@ -183,15 +266,14 @@ public Match Current
}
}
- object IEnumerator.Current
- {
- get { return Current; }
- }
+ object IEnumerator.Current => Current;
void IEnumerator.Reset()
{
_index = -1;
}
+
+ void IDisposable.Dispose() { }
}
}
}
diff --git a/src/System.Text.RegularExpressions/tests/CaptureCollectionTests.cs b/src/System.Text.RegularExpressions/tests/CaptureCollectionTests.cs
index bb92f5acb412..20e073409397 100644
--- a/src/System.Text.RegularExpressions/tests/CaptureCollectionTests.cs
+++ b/src/System.Text.RegularExpressions/tests/CaptureCollectionTests.cs
@@ -7,7 +7,7 @@
namespace System.Text.RegularExpressions.Tests
{
- public class CaptureCollectionTests
+ public static partial class CaptureCollectionTests
{
[Fact]
public static void GetEnumerator()
@@ -47,6 +47,16 @@ public static void GetEnumerator_Invalid()
Assert.Throws(() => enumerator.Current);
}
+ [Fact]
+ public static void Item_Get()
+ {
+ CaptureCollection collection = CreateCollection();
+ Assert.Equal("This ", collection[0].ToString());
+ Assert.Equal("is ", collection[1].ToString());
+ Assert.Equal("a ", collection[2].ToString());
+ Assert.Equal("sentence", collection[3].ToString());
+ }
+
[Fact]
public static void Item_Get_InvalidIndex_ThrowsArgumentOutOfRangeException()
{
@@ -58,26 +68,27 @@ public static void Item_Get_InvalidIndex_ThrowsArgumentOutOfRangeException()
}
[Fact]
- public void ICollection_Properties()
+ public static void ICollection_Properties()
{
Regex regex = new Regex(@"(?a*)(?b*)(?c*)");
CaptureCollection captures = regex.Match("aaabbccccccccccaaaabc").Captures;
ICollection collection = captures;
Assert.False(collection.IsSynchronized);
+ Assert.NotNull(collection.SyncRoot);
Assert.Same(collection.SyncRoot, collection.SyncRoot);
}
-
+
[Theory]
[InlineData(0)]
[InlineData(5)]
- public void ICollection_CopyTo(int index)
+ public static void ICollection_CopyTo(int index)
{
Regex regex = new Regex(@"(?a*)(?b*)(?c*)");
CaptureCollection captures = regex.Match("aaabbccccccccccaaaabc").Captures;
ICollection collection = captures;
- RegularExpressions.Capture[] copy = new RegularExpressions.Capture[collection.Count + index];
+ Capture[] copy = new Capture[collection.Count + index];
collection.CopyTo(copy, index);
for (int i = 0; i < index; i++)
@@ -91,7 +102,7 @@ public void ICollection_CopyTo(int index)
}
[Fact]
- public void ICollection_CopyTo_Invalid()
+ public static void ICollection_CopyTo_Invalid()
{
Regex regex = new Regex(@"(?a*)(?b*)(?c*)");
ICollection collection = regex.Match("aaabbccccccccccaaaabc").Captures;
@@ -113,5 +124,12 @@ public void ICollection_CopyTo_Invalid()
Assert.Throws(() => collection.CopyTo(new object[collection.Count], 1));
Assert.Throws(() => collection.CopyTo(new object[collection.Count + 1], 2));
}
+
+ private static CaptureCollection CreateCollection()
+ {
+ Regex regex = new Regex(@"\b(\w+\s*)+\.");
+ Match match = regex.Match("This is a sentence.");
+ return match.Groups[1].Captures;
+ }
}
}
diff --git a/src/System.Text.RegularExpressions/tests/CaptureCollectionTests.netcoreapp1.1.cs b/src/System.Text.RegularExpressions/tests/CaptureCollectionTests.netcoreapp1.1.cs
new file mode 100644
index 000000000000..87d3a49cafc0
--- /dev/null
+++ b/src/System.Text.RegularExpressions/tests/CaptureCollectionTests.netcoreapp1.1.cs
@@ -0,0 +1,172 @@
+// 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;
+using System.Collections.Generic;
+using System.Diagnostics;
+using System.Linq;
+using Xunit;
+
+namespace System.Text.RegularExpressions.Tests
+{
+ public static partial class CaptureCollectionTests
+ {
+ [Fact]
+ public static void IListOfT_Item_Get()
+ {
+ IList collection = CreateCollection();
+ Assert.Equal("This ", collection[0].ToString());
+ Assert.Equal("is ", collection[1].ToString());
+ Assert.Equal("a ", collection[2].ToString());
+ Assert.Equal("sentence", collection[3].ToString());
+ }
+
+ [Fact]
+ public static void IReadOnlyListOfT_Item_Get()
+ {
+ IReadOnlyList collection = CreateCollection();
+ Assert.Equal("This ", collection[0].ToString());
+ Assert.Equal("is ", collection[1].ToString());
+ Assert.Equal("a ", collection[2].ToString());
+ Assert.Equal("sentence", collection[3].ToString());
+ }
+
+ [Fact]
+ public static void IList_Item_Get()
+ {
+ IList collection = CreateCollection();
+ Assert.Equal("This ", collection[0].ToString());
+ Assert.Equal("is ", collection[1].ToString());
+ Assert.Equal("a ", collection[2].ToString());
+ Assert.Equal("sentence", collection[3].ToString());
+ }
+
+ [Fact]
+ public static void ICollectionOfT_Contains()
+ {
+ ICollection collection = CreateCollection();
+ foreach (Capture item in collection)
+ {
+ Assert.True(collection.Contains(item));
+ }
+
+ foreach (Capture item in CreateCollection())
+ {
+ Assert.False(collection.Contains(item));
+ }
+ }
+
+ [Fact]
+ public static void IList_Contains()
+ {
+ IList collection = CreateCollection();
+ foreach (object item in collection)
+ {
+ Assert.True(collection.Contains(item));
+ }
+
+ foreach (object item in CreateCollection())
+ {
+ Assert.False(collection.Contains(item));
+ }
+
+ Assert.False(collection.Contains(new object()));
+ }
+
+ [Fact]
+ public static void IListOfT_IndexOf()
+ {
+ IList collection = CreateCollection();
+
+ int i = 0;
+ foreach (Capture item in collection)
+ {
+ Assert.Equal(i, collection.IndexOf(item));
+ i++;
+ }
+
+ foreach (Capture item in CreateCollection())
+ {
+ Assert.Equal(-1, collection.IndexOf(item));
+ }
+ }
+
+ [Fact]
+ public static void IList_IndexOf()
+ {
+ IList collection = CreateCollection();
+
+ int i = 0;
+ foreach (object item in collection)
+ {
+ Assert.Equal(i, collection.IndexOf(item));
+ i++;
+ }
+
+ foreach (object item in CreateCollection())
+ {
+ Assert.Equal(-1, collection.IndexOf(item));
+ }
+
+ Assert.Equal(-1, collection.IndexOf(new object()));
+ }
+
+ [Fact]
+ public static void ICollectionOfT_CopyTo()
+ {
+ string[] expected = new[] { "This ", "is ", "a ", "sentence" };
+ ICollection collection = CreateCollection();
+
+ Capture[] array = new Capture[collection.Count];
+ collection.CopyTo(array, 0);
+
+ Assert.Equal(expected, array.Select(c => c.ToString()));
+ }
+
+ [Fact]
+ public static void ICollectionOfT_CopyTo_Invalid()
+ {
+ ICollection collection = CreateCollection();
+ Assert.Throws("array", () => collection.CopyTo((Capture[])null, 0));
+ Assert.Throws("arrayIndex", () => collection.CopyTo(new Capture[1], -1));
+ Assert.Throws(() => collection.CopyTo(new Capture[1], 0));
+ Assert.Throws(() => collection.CopyTo(new Capture[1], 1));
+ Assert.Throws("arrayIndex", () => collection.CopyTo(new Capture[1], 2));
+ }
+
+ [Fact]
+ public static void IListOfT_IsReadOnly()
+ {
+ IList list = CreateCollection();
+ Assert.True(list.IsReadOnly);
+ Assert.Throws(() => list.Add(default(Capture)));
+ Assert.Throws(() => list.Clear());
+ Assert.Throws(() => list.Insert(0, default(Capture)));
+ Assert.Throws(() => list.Remove(default(Capture)));
+ Assert.Throws(() => list.RemoveAt(0));
+ Assert.Throws(() => list[0] = default(Capture));
+ }
+
+ [Fact]
+ public static void IList_IsReadOnly()
+ {
+ IList list = CreateCollection();
+ Assert.True(list.IsReadOnly);
+ Assert.True(list.IsFixedSize);
+ Assert.Throws(() => list.Add(default(Capture)));
+ Assert.Throws(() => list.Clear());
+ Assert.Throws(() => list.Insert(0, default(Capture)));
+ Assert.Throws(() => list.Remove(default(Capture)));
+ Assert.Throws(() => list.RemoveAt(0));
+ Assert.Throws(() => list[0] = default(Capture));
+ }
+
+ [Fact]
+ public static void DebuggerAttributeTests()
+ {
+ DebuggerAttributes.ValidateDebuggerDisplayReferences(CreateCollection());
+ DebuggerAttributes.ValidateDebuggerTypeProxyProperties(CreateCollection());
+ }
+ }
+}
diff --git a/src/System.Text.RegularExpressions/tests/GroupCollectionTests.cs b/src/System.Text.RegularExpressions/tests/GroupCollectionTests.cs
index e2e49addf5ed..60a36991aa65 100644
--- a/src/System.Text.RegularExpressions/tests/GroupCollectionTests.cs
+++ b/src/System.Text.RegularExpressions/tests/GroupCollectionTests.cs
@@ -3,12 +3,11 @@
// See the LICENSE file in the project root for more information.
using System.Collections;
-using System.Diagnostics;
using Xunit;
namespace System.Text.RegularExpressions.Tests
{
- public class GroupCollectionTests
+ public static partial class GroupCollectionTests
{
[Fact]
public static void GetEnumerator()
@@ -48,6 +47,15 @@ public static void GetEnumerator_Invalid()
Assert.Throws(() => enumerator.Current);
}
+ [Fact]
+ public static void Item_Get()
+ {
+ GroupCollection collection = CreateCollection();
+ Assert.Equal("212-555-6666", collection[0].ToString());
+ Assert.Equal("212", collection[1].ToString());
+ Assert.Equal("555-6666", collection[2].ToString());
+ }
+
[Theory]
[InlineData(-1)]
[InlineData(4)]
@@ -64,20 +72,21 @@ public static void Item_Invalid(int groupNumber)
}
[Fact]
- public void ICollection_Properties()
+ public static void ICollection_Properties()
{
Regex regex = new Regex(@"(?a*)(?b*)(?c*)");
GroupCollection groups = regex.Match("aaabbccccccccccaaaabc").Groups;
ICollection collection = groups;
Assert.False(collection.IsSynchronized);
+ Assert.NotNull(collection.SyncRoot);
Assert.Same(collection.SyncRoot, collection.SyncRoot);
}
-
+
[Theory]
[InlineData(0)]
[InlineData(5)]
- public void ICollection_CopyTo(int index)
+ public static void ICollection_CopyTo(int index)
{
Regex regex = new Regex(@"(?a*)(?b*)(?c*)");
GroupCollection groups = regex.Match("aaabbccccccccccaaaabc").Groups;
@@ -96,7 +105,7 @@ public void ICollection_CopyTo(int index)
}
[Fact]
- public void ICollection_CopyTo_Invalid()
+ public static void ICollection_CopyTo_Invalid()
{
Regex regex = new Regex("e");
ICollection collection = regex.Match("aaabbccccccccccaaaabc").Groups;
@@ -118,5 +127,12 @@ public void ICollection_CopyTo_Invalid()
Assert.Throws(() => collection.CopyTo(new object[collection.Count], 1));
Assert.Throws(() => collection.CopyTo(new object[collection.Count + 1], 2));
}
+
+ private static GroupCollection CreateCollection()
+ {
+ Regex regex = new Regex(@"(\d{3})-(\d{3}-\d{4})");
+ Match match = regex.Match("212-555-6666");
+ return match.Groups;
+ }
}
}
diff --git a/src/System.Text.RegularExpressions/tests/GroupCollectionTests.netcoreapp1.1.cs b/src/System.Text.RegularExpressions/tests/GroupCollectionTests.netcoreapp1.1.cs
new file mode 100644
index 000000000000..6868348e5876
--- /dev/null
+++ b/src/System.Text.RegularExpressions/tests/GroupCollectionTests.netcoreapp1.1.cs
@@ -0,0 +1,169 @@
+// 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;
+using System.Collections.Generic;
+using System.Diagnostics;
+using System.Linq;
+using Xunit;
+
+namespace System.Text.RegularExpressions.Tests
+{
+ public static partial class GroupCollectionTests
+ {
+ [Fact]
+ public static void IListOfT_Item_Get()
+ {
+ IList collection = CreateCollection();
+ Assert.Equal("212-555-6666", collection[0].ToString());
+ Assert.Equal("212", collection[1].ToString());
+ Assert.Equal("555-6666", collection[2].ToString());
+ }
+
+ [Fact]
+ public static void IReadOnlyListOfT_Item_Get()
+ {
+ IReadOnlyList collection = CreateCollection();
+ Assert.Equal("212-555-6666", collection[0].ToString());
+ Assert.Equal("212", collection[1].ToString());
+ Assert.Equal("555-6666", collection[2].ToString());
+ }
+
+ [Fact]
+ public static void IList_Item_Get()
+ {
+ IList collection = CreateCollection();
+ Assert.Equal("212-555-6666", collection[0].ToString());
+ Assert.Equal("212", collection[1].ToString());
+ Assert.Equal("555-6666", collection[2].ToString());
+ }
+
+ [Fact]
+ public static void ICollectionOfT_Contains()
+ {
+ ICollection collection = CreateCollection();
+ foreach (Group item in collection)
+ {
+ Assert.True(collection.Contains(item));
+ }
+
+ foreach (Group item in CreateCollection())
+ {
+ Assert.False(collection.Contains(item));
+ }
+ }
+
+ [Fact]
+ public static void IList_Contains()
+ {
+ IList collection = CreateCollection();
+ foreach (object item in collection)
+ {
+ Assert.True(collection.Contains(item));
+ }
+
+ foreach (object item in CreateCollection())
+ {
+ Assert.False(collection.Contains(item));
+ }
+
+ Assert.False(collection.Contains(new object()));
+ }
+
+ [Fact]
+ public static void IListOfT_IndexOf()
+ {
+ IList collection = CreateCollection();
+
+ int i = 0;
+ foreach (Group item in collection)
+ {
+ Assert.Equal(i, collection.IndexOf(item));
+ i++;
+ }
+
+ foreach (Group item in CreateCollection())
+ {
+ Assert.Equal(-1, collection.IndexOf(item));
+ }
+ }
+
+ [Fact]
+ public static void IList_IndexOf()
+ {
+ IList collection = CreateCollection();
+
+ int i = 0;
+ foreach (object item in collection)
+ {
+ Assert.Equal(i, collection.IndexOf(item));
+ i++;
+ }
+
+ foreach (object item in CreateCollection())
+ {
+ Assert.Equal(-1, collection.IndexOf(item));
+ }
+
+ Assert.Equal(-1, collection.IndexOf(new object()));
+ }
+
+ [Fact]
+ public static void ICollectionOfT_CopyTo()
+ {
+ string[] expected = new[] { "212-555-6666", "212", "555-6666" };
+ ICollection collection = CreateCollection();
+
+ Group[] array = new Group[collection.Count];
+ collection.CopyTo(array, 0);
+
+ Assert.Equal(expected, array.Select(c => c.ToString()));
+ }
+
+ [Fact]
+ public static void ICollectionOfT_CopyTo_Invalid()
+ {
+ ICollection collection = CreateCollection();
+ Assert.Throws("array", () => collection.CopyTo(null, 0));
+ Assert.Throws("arrayIndex", () => collection.CopyTo(new Group[1], -1));
+ Assert.Throws(() => collection.CopyTo(new Group[1], 0));
+ Assert.Throws(() => collection.CopyTo(new Group[1], 1));
+ Assert.Throws("arrayIndex", () => collection.CopyTo(new Group[1], 2));
+ }
+
+ [Fact]
+ public static void IListOfT_IsReadOnly()
+ {
+ IList list = CreateCollection();
+ Assert.True(list.IsReadOnly);
+ Assert.Throws(() => list.Add(default(Group)));
+ Assert.Throws(() => list.Clear());
+ Assert.Throws(() => list.Insert(0, default(Group)));
+ Assert.Throws(() => list.Remove(default(Group)));
+ Assert.Throws(() => list.RemoveAt(0));
+ Assert.Throws(() => list[0] = default(Group));
+ }
+
+ [Fact]
+ public static void IList_IsReadOnly()
+ {
+ IList list = CreateCollection();
+ Assert.True(list.IsReadOnly);
+ Assert.True(list.IsFixedSize);
+ Assert.Throws(() => list.Add(default(Group)));
+ Assert.Throws(() => list.Clear());
+ Assert.Throws(() => list.Insert(0, default(Group)));
+ Assert.Throws(() => list.Remove(default(Group)));
+ Assert.Throws(() => list.RemoveAt(0));
+ Assert.Throws(() => list[0] = default(Group));
+ }
+
+ [Fact]
+ public static void DebuggerAttributeTests()
+ {
+ DebuggerAttributes.ValidateDebuggerDisplayReferences(CreateCollection());
+ DebuggerAttributes.ValidateDebuggerTypeProxyProperties(CreateCollection());
+ }
+ }
+}
diff --git a/src/System.Text.RegularExpressions/tests/MatchCollectionTests.cs b/src/System.Text.RegularExpressions/tests/MatchCollectionTests.cs
index c273d7505eca..1dcef0d9d33b 100644
--- a/src/System.Text.RegularExpressions/tests/MatchCollectionTests.cs
+++ b/src/System.Text.RegularExpressions/tests/MatchCollectionTests.cs
@@ -7,10 +7,10 @@
namespace System.Text.RegularExpressions.Tests
{
- public class MatchCollectionTests
+ public static partial class MatchCollectionTests
{
[Fact]
- public void GetEnumerator()
+ public static void GetEnumerator()
{
Regex regex = new Regex("e");
MatchCollection matches = regex.Matches("dotnet");
@@ -30,7 +30,7 @@ public void GetEnumerator()
}
[Fact]
- public void GetEnumerator_Invalid()
+ public static void GetEnumerator_Invalid()
{
Regex regex = new Regex("e");
MatchCollection matches = regex.Matches("dotnet");
@@ -48,7 +48,15 @@ public void GetEnumerator_Invalid()
}
[Fact]
- public void Item_Get_InvalidIndex_ThrowsArgumentOutOfRangeException()
+ public static void Item_Get()
+ {
+ MatchCollection collection = CreateCollection();
+ Assert.Equal("t", collection[0].ToString());
+ Assert.Equal("t", collection[1].ToString());
+ }
+
+ [Fact]
+ public static void Item_Get_InvalidIndex_ThrowsArgumentOutOfRangeException()
{
Regex regex = new Regex("e");
MatchCollection matches = regex.Matches("dotnet");
@@ -57,20 +65,21 @@ public void Item_Get_InvalidIndex_ThrowsArgumentOutOfRangeException()
}
[Fact]
- public void ICollection_Properties()
+ public static void ICollection_Properties()
{
Regex regex = new Regex("e");
MatchCollection matches = regex.Matches("dotnet");
ICollection collection = matches;
Assert.False(collection.IsSynchronized);
+ Assert.NotNull(collection.SyncRoot);
Assert.Same(matches, collection.SyncRoot);
}
[Theory]
[InlineData(0)]
[InlineData(5)]
- public void ICollection_CopyTo(int index)
+ public static void ICollection_CopyTo(int index)
{
Regex regex = new Regex("e");
MatchCollection matches = regex.Matches("dotnet");
@@ -90,7 +99,7 @@ public void ICollection_CopyTo(int index)
}
[Fact]
- public void ICollection_CopyTo_Invalid()
+ public static void ICollection_CopyTo_Invalid()
{
Regex regex = new Regex("e");
ICollection collection = regex.Matches("dotnet");
@@ -112,5 +121,7 @@ public void ICollection_CopyTo_Invalid()
Assert.Throws("", () => collection.CopyTo(new object[collection.Count], 1));
Assert.Throws("", () => collection.CopyTo(new object[collection.Count + 1], 2));
}
+
+ private static MatchCollection CreateCollection() => new Regex("t").Matches("dotnet");
}
}
diff --git a/src/System.Text.RegularExpressions/tests/MatchCollectionTests.netcoreapp1.1.cs b/src/System.Text.RegularExpressions/tests/MatchCollectionTests.netcoreapp1.1.cs
new file mode 100644
index 000000000000..c4120da59dbd
--- /dev/null
+++ b/src/System.Text.RegularExpressions/tests/MatchCollectionTests.netcoreapp1.1.cs
@@ -0,0 +1,166 @@
+// 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;
+using System.Collections.Generic;
+using System.Diagnostics;
+using System.Linq;
+using Xunit;
+
+namespace System.Text.RegularExpressions.Tests
+{
+ public static partial class MatchCollectionTests
+ {
+ [Fact]
+ public static void IListOfT_Item_Get()
+ {
+ IList collection = CreateCollection();
+ Assert.Equal("t", collection[0].ToString());
+ Assert.Equal("t", collection[1].ToString());
+ }
+
+ [Fact]
+ public static void IReadOnlyListOfT_Item_Get()
+ {
+ IReadOnlyList collection = CreateCollection();
+ Assert.Equal("t", collection[0].ToString());
+ Assert.Equal("t", collection[1].ToString());
+ }
+
+ [Fact]
+ public static void IList_Item_Get()
+ {
+ IList collection = CreateCollection();
+ Assert.Equal("t", collection[0].ToString());
+ Assert.Equal("t", collection[1].ToString());
+ }
+
+ [Fact]
+ public static void ICollectionOfT_Contains()
+ {
+ ICollection collection = CreateCollection();
+ foreach (Match item in collection)
+ {
+ Assert.True(collection.Contains(item));
+ }
+
+ foreach (Match item in CreateCollection())
+ {
+ Assert.False(collection.Contains(item));
+ }
+ }
+
+ [Fact]
+ public static void IList_Contains()
+ {
+ IList collection = CreateCollection();
+ foreach (object item in collection)
+ {
+ Assert.True(collection.Contains(item));
+ }
+
+ foreach (object item in CreateCollection())
+ {
+ Assert.False(collection.Contains(item));
+ }
+
+ Assert.False(collection.Contains(new object()));
+ }
+
+ [Fact]
+ public static void IListOfT_IndexOf()
+ {
+ IList collection = CreateCollection();
+
+ int i = 0;
+ foreach (Match item in collection)
+ {
+ Assert.Equal(i, collection.IndexOf(item));
+ i++;
+ }
+
+ foreach (Match item in CreateCollection())
+ {
+ Assert.Equal(-1, collection.IndexOf(item));
+ }
+ }
+
+ [Fact]
+ public static void IList_IndexOf()
+ {
+ IList collection = CreateCollection();
+
+ int i = 0;
+ foreach (object item in collection)
+ {
+ Assert.Equal(i, collection.IndexOf(item));
+ i++;
+ }
+
+ foreach (object item in CreateCollection())
+ {
+ Assert.Equal(-1, collection.IndexOf(item));
+ }
+
+ Assert.Equal(-1, collection.IndexOf(new object()));
+ }
+
+ [Fact]
+ public static void ICollectionOfT_CopyTo()
+ {
+ string[] expected = new[] { "t", "t" };
+ ICollection collection = CreateCollection();
+
+ Match[] array = new Match[collection.Count];
+ collection.CopyTo(array, 0);
+
+ Assert.Equal(expected, array.Select(c => c.ToString()));
+ }
+
+ [Fact]
+ public static void ICollectionOfT_CopyTo_Invalid()
+ {
+ ICollection collection = CreateCollection();
+ Assert.Throws(() => collection.CopyTo(null, 0));
+ Assert.Throws(() => collection.CopyTo(new Match[1], -1));
+ Assert.Throws(() => collection.CopyTo(new Match[1], 0));
+ Assert.Throws(() => collection.CopyTo(new Match[1], 1));
+ Assert.Throws(() => collection.CopyTo(new Match[1], 2));
+ }
+
+ [Fact]
+ public static void IListOfT_IsReadOnly()
+ {
+ IList list = CreateCollection();
+ Assert.True(list.IsReadOnly);
+ Assert.Throws(() => list.Add(default(Match)));
+ Assert.Throws(() => list.Clear());
+ Assert.Throws(() => list.Insert(0, default(Match)));
+ Assert.Throws(() => list.Remove(default(Match)));
+ Assert.Throws(() => list.RemoveAt(0));
+ Assert.Throws(() => list[0] = default(Match));
+ }
+
+ [Fact]
+ public static void IList_IsReadOnly()
+ {
+ IList list = CreateCollection();
+ Assert.True(list.IsReadOnly);
+ Assert.True(list.IsFixedSize);
+ Assert.Throws(() => list.Add(default(Match)));
+ Assert.Throws(() => list.Clear());
+ Assert.Throws(() => list.Insert(0, default(Match)));
+ Assert.Throws(() => list.Remove(default(Match)));
+ Assert.Throws(() => list.RemoveAt(0));
+ Assert.Throws(() => list[0] = default(Match));
+ }
+
+ [Fact]
+ public static void DebuggerAttributeTests()
+ {
+ DebuggerAttributes.ValidateDebuggerDisplayReferences(CreateCollection());
+ DebuggerAttributes.ValidateDebuggerTypeProxyProperties(CreateCollection());
+ }
+ }
+}
diff --git a/src/System.Text.RegularExpressions/tests/Regex.Match.Tests.cs b/src/System.Text.RegularExpressions/tests/Regex.Match.Tests.cs
index 79a44db07fa9..22f87292cb0d 100644
--- a/src/System.Text.RegularExpressions/tests/Regex.Match.Tests.cs
+++ b/src/System.Text.RegularExpressions/tests/Regex.Match.Tests.cs
@@ -325,10 +325,10 @@ public static IEnumerable
+
+ netcoreapp1.1
+ netcoreapp1.1
+
netstandard1.6
Windows_NT
diff --git a/src/System.Text.RegularExpressions/tests/System.Text.RegularExpressions.Tests.csproj b/src/System.Text.RegularExpressions/tests/System.Text.RegularExpressions.Tests.csproj
index 280c4e3d8ace..7ec80dc8848a 100644
--- a/src/System.Text.RegularExpressions/tests/System.Text.RegularExpressions.Tests.csproj
+++ b/src/System.Text.RegularExpressions/tests/System.Text.RegularExpressions.Tests.csproj
@@ -32,6 +32,14 @@
+
+
+
+
+
+ Common\System\Diagnostics\DebuggerAttributes.cs
+
+
diff --git a/src/System.Text.RegularExpressions/tests/project.json b/src/System.Text.RegularExpressions/tests/project.json
index 617a72b3e035..2de32e52162b 100644
--- a/src/System.Text.RegularExpressions/tests/project.json
+++ b/src/System.Text.RegularExpressions/tests/project.json
@@ -4,9 +4,12 @@
"System.Collections": "4.4.0-beta-24612-03",
"System.Collections.NonGeneric": "4.4.0-beta-24612-03",
"System.Console": "4.4.0-beta-24612-03",
+ "System.Diagnostics.Debug": "4.4.0-beta-24612-03",
"System.Globalization": "4.4.0-beta-24612-03",
+ "System.Linq": "4.4.0-beta-24612-03",
"System.Linq.Expressions": "4.4.0-beta-24612-03",
"System.ObjectModel": "4.4.0-beta-24612-03",
+ "System.Reflection": "4.4.0-beta-24612-03",
"System.Runtime": "4.4.0-beta-24612-03",
"System.Runtime.Extensions": "4.4.0-beta-24612-03",
"System.Text.RegularExpressions": "4.4.0-beta-24612-03",
@@ -25,7 +28,8 @@
"System.IO": "4.4.0-beta-24612-03",
"System.Runtime.Serialization.Formatters": "4.4.0-beta-24612-03"
}
- }
+ },
+ "netcoreapp1.1": {}
},
"supports": {
"coreFx.Test.netcoreapp1.0": {},