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 Match_Advanced_TestData() yield return new object[] { @".*\B(SUCCESS)\B.*", "adfadsfSUCCESSadsfadsf", RegexOptions.None, 0, 22, - new Capture[] + new CaptureData[] { - new Capture("adfadsfSUCCESSadsfadsf", 0, 22), - new Capture("SUCCESS", 7, 7) + new CaptureData("adfadsfSUCCESSadsfadsf", 0, 22), + new CaptureData("SUCCESS", 7, 7) } }; @@ -336,11 +336,11 @@ public static IEnumerable Match_Advanced_TestData() yield return new object[] { "^aaa(bb.+)(d|c)$", "aaabb.cc", RegexOptions.None, 0, 8, - new Capture[] + new CaptureData[] { - new Capture("aaabb.cc", 0, 8), - new Capture("bb.c", 3, 4), - new Capture("c", 7, 1) + new CaptureData("aaabb.cc", 0, 8), + new CaptureData("bb.c", 3, 4), + new CaptureData("c", 7, 1) } }; @@ -348,12 +348,12 @@ public static IEnumerable Match_Advanced_TestData() yield return new object[] { "(a+)(b*)(c?)", "aaabbbccc", RegexOptions.None, 0, 9, - new Capture[] + new CaptureData[] { - new Capture("aaabbbc", 0, 7), - new Capture("aaa", 0, 3), - new Capture("bbb", 3, 3), - new Capture("c", 6, 1) + new CaptureData("aaabbbc", 0, 7), + new CaptureData("aaa", 0, 3), + new CaptureData("bbb", 3, 3), + new CaptureData("c", 6, 1) } }; @@ -362,12 +362,12 @@ public static IEnumerable Match_Advanced_TestData() yield return new object[] { "(d+?)(e*?)(f??)", "dddeeefff", RegexOptions.None, 0, 9, - new Capture[] + new CaptureData[] { - new Capture("d", 0, 1), - new Capture("d", 0, 1), - new Capture(string.Empty, 1, 0), - new Capture(string.Empty, 1, 0) + new CaptureData("d", 0, 1), + new CaptureData("d", 0, 1), + new CaptureData(string.Empty, 1, 0), + new CaptureData(string.Empty, 1, 0) } }; @@ -375,11 +375,11 @@ public static IEnumerable Match_Advanced_TestData() yield return new object[] { "(a+)(?:b*)(ccc)", "aaabbbccc", RegexOptions.None, 0, 9, - new Capture[] + new CaptureData[] { - new Capture("aaabbbccc", 0, 9), - new Capture("aaa", 0, 3), - new Capture("ccc", 6, 3), + new CaptureData("aaabbbccc", 0, 9), + new CaptureData("aaa", 0, 3), + new CaptureData("ccc", 6, 3), } }; @@ -387,9 +387,9 @@ public static IEnumerable Match_Advanced_TestData() yield return new object[] { @"abc(?=XXX)\w+", "abcXXXdef", RegexOptions.None, 0, 9, - new Capture[] + new CaptureData[] { - new Capture("abcXXXdef", 0, 9) + new CaptureData("abcXXXdef", 0, 9) } }; @@ -397,10 +397,10 @@ public static IEnumerable Match_Advanced_TestData() yield return new object[] { @"(\w)\1", "aa", RegexOptions.None, 0, 2, - new Capture[] + new CaptureData[] { - new Capture("aa", 0, 2), - new Capture("a", 0, 1), + new CaptureData("aa", 0, 2), + new CaptureData("a", 0, 1), } }; @@ -408,10 +408,10 @@ public static IEnumerable Match_Advanced_TestData() yield return new object[] { "(111|aaa)", "aaa", RegexOptions.None, 0, 3, - new Capture[] + new CaptureData[] { - new Capture("aaa", 0, 3), - new Capture("aaa", 0, 3) + new CaptureData("aaa", 0, 3), + new CaptureData("aaa", 0, 3) } }; @@ -419,10 +419,10 @@ public static IEnumerable Match_Advanced_TestData() yield return new object[] { @"(?\d+)abc(?(MyDigits)222|111)", "111abc222", RegexOptions.None, 0, 9, - new Capture[] + new CaptureData[] { - new Capture("111abc222", 0, 9), - new Capture("111", 0, 3) + new CaptureData("111abc222", 0, 9), + new CaptureData("111", 0, 3) } }; @@ -430,10 +430,10 @@ public static IEnumerable Match_Advanced_TestData() yield return new object[] { @"([0-9]*)\s(?[a-z_A-Z]+)", "200 dollars", RegexOptions.ExplicitCapture, 0, 11, - new Capture[] + new CaptureData[] { - new Capture("200 dollars", 0, 11), - new Capture("dollars", 4, 7) + new CaptureData("200 dollars", 0, 11), + new CaptureData("dollars", 4, 7) } }; @@ -441,10 +441,10 @@ public static IEnumerable Match_Advanced_TestData() yield return new object[] { "(.*)", "abc\nsfc", RegexOptions.Singleline, 0, 7, - new Capture[] + new CaptureData[] { - new Capture("abc\nsfc", 0, 7), - new Capture("abc\nsfc", 0, 7), + new CaptureData("abc\nsfc", 0, 7), + new CaptureData("abc\nsfc", 0, 7), } }; @@ -452,15 +452,15 @@ public static IEnumerable Match_Advanced_TestData() yield return new object[] { @"([0-9]+(\.[0-9]+){3})", "209.25.0.111", RegexOptions.None, 0, 12, - new Capture[] + new CaptureData[] { - new Capture("209.25.0.111", 0, 12), - new Capture("209.25.0.111", 0, 12), - new Capture(".111", 8, 4, new Capture[] + new CaptureData("209.25.0.111", 0, 12), + new CaptureData("209.25.0.111", 0, 12), + new CaptureData(".111", 8, 4, new CaptureData[] { - new Capture(".25", 3, 3), - new Capture(".0", 6, 2), - new Capture(".111", 8, 4), + new CaptureData(".25", 3, 3), + new CaptureData(".0", 6, 2), + new CaptureData(".111", 8, 4), }), } }; @@ -469,24 +469,24 @@ public static IEnumerable Match_Advanced_TestData() yield return new object[] { @"(?a*)(?b*)(?c*)", "aaabbccccccccccaaaabc", RegexOptions.None, 0, 21, - new Capture[] + new CaptureData[] { - new Capture("aaabbcccccccccc", 0, 15), - new Capture("aaa", 0, 3), - new Capture("bb", 3, 2), - new Capture("cccccccccc", 5, 10) + new CaptureData("aaabbcccccccccc", 0, 15), + new CaptureData("aaa", 0, 3), + new CaptureData("bb", 3, 2), + new CaptureData("cccccccccc", 5, 10) } }; yield return new object[] { @"(?A*)(?B*)(?C*)", "aaabbccccccccccaaaabc", RegexOptions.IgnoreCase, 0, 21, - new Capture[] + new CaptureData[] { - new Capture("aaabbcccccccccc", 0, 15), - new Capture("aaa", 0, 3), - new Capture("bb", 3, 2), - new Capture("cccccccccc", 5, 10) + new CaptureData("aaabbcccccccccc", 0, 15), + new CaptureData("aaa", 0, 3), + new CaptureData("bb", 3, 2), + new CaptureData("cccccccccc", 5, 10) } }; @@ -494,11 +494,11 @@ public static IEnumerable Match_Advanced_TestData() yield return new object[] { "^aaa(bb.+)(d|c)$", "aaabb.cc", RegexOptions.None, 0, 8, - new Capture[] + new CaptureData[] { - new Capture("aaabb.cc", 0, 8), - new Capture("bb.c", 3, 4), - new Capture("c", 7, 1) + new CaptureData("aaabb.cc", 0, 8), + new CaptureData("bb.c", 3, 4), + new CaptureData("c", 7, 1) } }; @@ -506,10 +506,10 @@ public static IEnumerable Match_Advanced_TestData() yield return new object[] { @".*\b(\w+)\b", "XSP_TEST_FAILURE SUCCESS", RegexOptions.None, 0, 24, - new Capture[] + new CaptureData[] { - new Capture("XSP_TEST_FAILURE SUCCESS", 0, 24), - new Capture("SUCCESS", 17, 7) + new CaptureData("XSP_TEST_FAILURE SUCCESS", 0, 24), + new CaptureData("SUCCESS", 17, 7) } }; @@ -517,10 +517,10 @@ public static IEnumerable Match_Advanced_TestData() yield return new object[] { "(line2$\n)line3", "line1\nline2\nline3\n\nline4", RegexOptions.Multiline, 0, 24, - new Capture[] + new CaptureData[] { - new Capture("line2\nline3", 6, 11), - new Capture("line2\n", 6, 6) + new CaptureData("line2\nline3", 6, 11), + new CaptureData("line2\n", 6, 6) } }; @@ -528,10 +528,10 @@ public static IEnumerable Match_Advanced_TestData() yield return new object[] { "(line2\n^)line3", "line1\nline2\nline3\n\nline4", RegexOptions.Multiline, 0, 24, - new Capture[] + new CaptureData[] { - new Capture("line2\nline3", 6, 11), - new Capture("line2\n", 6, 6) + new CaptureData("line2\nline3", 6, 11), + new CaptureData("line2\n", 6, 6) } }; @@ -539,10 +539,10 @@ public static IEnumerable Match_Advanced_TestData() yield return new object[] { "(line3\n$\n)line4", "line1\nline2\nline3\n\nline4", RegexOptions.Multiline, 0, 24, - new Capture[] + new CaptureData[] { - new Capture("line3\n\nline4", 12, 12), - new Capture("line3\n\n", 12, 7) + new CaptureData("line3\n\nline4", 12, 12), + new CaptureData("line3\n\n", 12, 7) } }; @@ -550,10 +550,10 @@ public static IEnumerable Match_Advanced_TestData() yield return new object[] { "(line3\n^\n)line4", "line1\nline2\nline3\n\nline4", RegexOptions.Multiline, 0, 24, - new Capture[] + new CaptureData[] { - new Capture("line3\n\nline4", 12, 12), - new Capture("line3\n\n", 12, 7) + new CaptureData("line3\n\nline4", 12, 12), + new CaptureData("line3\n\n", 12, 7) } }; @@ -561,10 +561,10 @@ public static IEnumerable Match_Advanced_TestData() yield return new object[] { "(line2$\n^)line3", "line1\nline2\nline3\n\nline4", RegexOptions.Multiline, 0, 24, - new Capture[] + new CaptureData[] { - new Capture("line2\nline3", 6, 11), - new Capture("line2\n", 6, 6) + new CaptureData("line2\nline3", 6, 11), + new CaptureData("line2\n", 6, 6) } }; @@ -572,16 +572,16 @@ public static IEnumerable Match_Advanced_TestData() yield return new object[] { "aaa", "aaabbb", RegexOptions.RightToLeft, 3, 3, - new Capture[] + new CaptureData[] { - new Capture("aaa", 0, 3) + new CaptureData("aaa", 0, 3) } }; } [Theory] [MemberData(nameof(Match_Advanced_TestData))] - public void Match(string pattern, string input, RegexOptions options, int beginning, int length, Capture[] expected) + public void Match(string pattern, string input, RegexOptions options, int beginning, int length, CaptureData[] expected) { bool isDefaultStart = RegexHelpers.IsDefaultStart(input, options, beginning); bool isDefaultCount = RegexHelpers.IsDefaultStart(input, options, length); @@ -629,7 +629,7 @@ public void Match(string pattern, string input, RegexOptions options, int beginn } } - public static void VerifyMatch(Match match, bool expectedSuccess, Capture[] expected) + public static void VerifyMatch(Match match, bool expectedSuccess, CaptureData[] expected) { Assert.Equal(expectedSuccess, match.Success); diff --git a/src/System.Text.RegularExpressions/tests/Regex.MultipleMatches.Tests.cs b/src/System.Text.RegularExpressions/tests/Regex.MultipleMatches.Tests.cs index 17dc528aa528..fddb2a763902 100644 --- a/src/System.Text.RegularExpressions/tests/Regex.MultipleMatches.Tests.cs +++ b/src/System.Text.RegularExpressions/tests/Regex.MultipleMatches.Tests.cs @@ -54,76 +54,76 @@ public static IEnumerable Matches_TestData() yield return new object[] { "[0-9]", "12345asdfasdfasdfljkhsda67890", RegexOptions.None, - new Capture[] + new CaptureData[] { - new Capture("1", 0, 1), - new Capture("2", 1, 1), - new Capture("3", 2, 1), - new Capture("4", 3, 1), - new Capture("5", 4, 1), - new Capture("6", 24, 1), - new Capture("7", 25, 1), - new Capture("8", 26, 1), - new Capture("9", 27, 1), - new Capture("0", 28, 1), + new CaptureData("1", 0, 1), + new CaptureData("2", 1, 1), + new CaptureData("3", 2, 1), + new CaptureData("4", 3, 1), + new CaptureData("5", 4, 1), + new CaptureData("6", 24, 1), + new CaptureData("7", 25, 1), + new CaptureData("8", 26, 1), + new CaptureData("9", 27, 1), + new CaptureData("0", 28, 1), } }; yield return new object[] { "[a-z0-9]+", "[token1]? GARBAGEtoken2GARBAGE ;token3!", RegexOptions.None, - new Capture[] + new CaptureData[] { - new Capture("token1", 1, 6), - new Capture("token2", 17, 6), - new Capture("token3", 32, 6) + new CaptureData("token1", 1, 6), + new CaptureData("token2", 17, 6), + new CaptureData("token3", 32, 6) } }; yield return new object[] { "(abc){2}", " !abcabcasl dkfjasiduf 12343214-//asdfjzpiouxoifzuoxpicvql23r\\` #$3245,2345278 :asdfas & 100% @daeeffga (ryyy27343) poiweurwabcabcasdfalksdhfaiuyoiruqwer{234}/[(132387 + x)]'aaa''?", RegexOptions.None, - new Capture[] + new CaptureData[] { - new Capture("abcabc", 2, 6), - new Capture("abcabc", 125, 6) + new CaptureData("abcabc", 2, 6), + new CaptureData("abcabc", 125, 6) } }; yield return new object[] { @"foo\d+", "0123456789foo4567890foo1foo 0987", RegexOptions.RightToLeft, - new Capture[] + new CaptureData[] { - new Capture("foo1", 20, 4), - new Capture("foo4567890", 10, 10), + new CaptureData("foo1", 20, 4), + new CaptureData("foo4567890", 10, 10), } }; yield return new object[] { "[a-z]", "a", RegexOptions.None, - new Capture[] + new CaptureData[] { - new Capture("a", 0, 1) + new CaptureData("a", 0, 1) } }; yield return new object[] { "[a-z]", "a1bc", RegexOptions.None, - new Capture[] + new CaptureData[] { - new Capture("a", 0, 1), - new Capture("b", 2, 1), - new Capture("c", 3, 1) + new CaptureData("a", 0, 1), + new CaptureData("b", 2, 1), + new CaptureData("c", 3, 1) } }; } [Theory] [MemberData(nameof(Matches_TestData))] - public void Matches(string pattern, string input, RegexOptions options, Capture[] expected) + public void Matches(string pattern, string input, RegexOptions options, CaptureData[] expected) { if (options == RegexOptions.None) { @@ -143,7 +143,7 @@ public void Matches(string pattern, string input, RegexOptions options, Capture[ VerifyMatches(Regex.Match(input, pattern, options), expected); } - public static void VerifyMatches(Match match, Capture[] expected) + public static void VerifyMatches(Match match, CaptureData[] expected) { for (int i = 0; match.Success; i++, match = match.NextMatch()) { @@ -151,7 +151,7 @@ public static void VerifyMatches(Match match, Capture[] expected) } } - public static void VerifyMatches(MatchCollection matches, Capture[] expected) + public static void VerifyMatches(MatchCollection matches, CaptureData[] expected) { Assert.Equal(expected.Length, matches.Count); for (int i = 0; i < matches.Count; i++) @@ -160,7 +160,7 @@ public static void VerifyMatches(MatchCollection matches, Capture[] expected) } } - public static void VerifyMatch(Match match, Capture expected) + public static void VerifyMatch(Match match, CaptureData expected) { Assert.True(match.Success); Assert.Equal(expected.Value, match.Value); diff --git a/src/System.Text.RegularExpressions/tests/Regex.Tests.Common.cs b/src/System.Text.RegularExpressions/tests/Regex.Tests.Common.cs index 88b2876b9b44..0ec9c4462f62 100644 --- a/src/System.Text.RegularExpressions/tests/Regex.Tests.Common.cs +++ b/src/System.Text.RegularExpressions/tests/Regex.Tests.Common.cs @@ -25,9 +25,9 @@ public static bool IsDefaultStart(string input, RegexOptions options, int start) } } - public class Capture + public class CaptureData { - private Capture(string value, int index, int length, bool createCaptures) + private CaptureData(string value, int index, int length, bool createCaptures) { Value = value; Index = index; @@ -36,15 +36,15 @@ private Capture(string value, int index, int length, bool createCaptures) // Prevent a StackOverflow recursion in the constructor if (createCaptures) { - Captures = new Capture[] { new Capture(value, index, length, false) }; + Captures = new CaptureData[] { new CaptureData(value, index, length, false) }; } } - public Capture(string value, int index, int length) : this(value, index, length, true) + public CaptureData(string value, int index, int length) : this(value, index, length, true) { } - public Capture(string value, int index, int length, Capture[] captures) : this(value, index, length, false) + public CaptureData(string value, int index, int length, CaptureData[] captures) : this(value, index, length, false) { Captures = captures; } @@ -52,6 +52,6 @@ public Capture(string value, int index, int length, Capture[] captures) : this(v public string Value { get; } public int Index { get; } public int Length { get; } - public Capture[] Captures { get; } + public CaptureData[] Captures { get; } } } diff --git a/src/System.Text.RegularExpressions/tests/System.Text.RegularExpressions.Tests.builds b/src/System.Text.RegularExpressions/tests/System.Text.RegularExpressions.Tests.builds index 6a45044d91bb..c698dcddcee8 100644 --- a/src/System.Text.RegularExpressions/tests/System.Text.RegularExpressions.Tests.builds +++ b/src/System.Text.RegularExpressions/tests/System.Text.RegularExpressions.Tests.builds @@ -7,6 +7,10 @@ netstandard1.6 netcoreapp1.0 + + 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": {},