diff options
author | ahsonkhan <ahson_ahmedk@yahoo.com> | 2018-02-03 04:10:37 +0300 |
---|---|---|
committer | Jan Kotas <jkotas@microsoft.com> | 2018-02-04 10:39:03 +0300 |
commit | cd48d8680762ab47e39236227c346efa042d789c (patch) | |
tree | f3515f3d735ac6ac403f02d54c831a5ad6bcd7a7 /src/System.Memory | |
parent | c98a1539d423bb579af01610bec73b79559156bb (diff) |
Changing Span to return default on null instead of throwing.
Diffstat (limited to 'src/System.Memory')
-rw-r--r-- | src/System.Memory/System.Memory.sln | 14 | ||||
-rw-r--r-- | src/System.Memory/src/System/MemoryExtensions.Fast.cs | 10 | ||||
-rw-r--r-- | src/System.Memory/src/System/MemoryExtensions.Portable.cs | 40 | ||||
-rw-r--r-- | src/System.Memory/src/System/ReadOnlySpan.Portable.cs | 18 | ||||
-rw-r--r-- | src/System.Memory/src/System/Span.Portable.cs | 18 | ||||
-rw-r--r-- | src/System.Memory/src/System/ThrowHelper.cs | 7 | ||||
-rw-r--r-- | src/System.Memory/tests/Memory/CtorArray.cs | 9 | ||||
-rw-r--r-- | src/System.Memory/tests/ReadOnlyMemory/CtorArray.cs | 9 | ||||
-rw-r--r-- | src/System.Memory/tests/ReadOnlyMemory/Strings.cs | 20 | ||||
-rw-r--r-- | src/System.Memory/tests/ReadOnlySpan/AsReadOnlySpan.cs | 22 | ||||
-rw-r--r-- | src/System.Memory/tests/ReadOnlySpan/CtorArray.cs | 9 | ||||
-rw-r--r-- | src/System.Memory/tests/Span/CtorArray.cs | 9 |
12 files changed, 130 insertions, 55 deletions
diff --git a/src/System.Memory/System.Memory.sln b/src/System.Memory/System.Memory.sln index 402cbd12a0..7c68229780 100644 --- a/src/System.Memory/System.Memory.sln +++ b/src/System.Memory/System.Memory.sln @@ -1,6 +1,6 @@ Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio 14 -VisualStudioVersion = 14.0.25420.1 +# Visual Studio 15 +VisualStudioVersion = 15.0.27331.1 MinimumVisualStudioVersion = 10.0.40219.1 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "System.Memory.Tests", "tests\System.Memory.Tests.csproj", "{15DB0DCC-68B4-4CFB-8BD2-F26BCCAF5A3F}" ProjectSection(ProjectDependencies) = postProject @@ -25,6 +25,13 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{E107E9C1-E89 EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "ref", "ref", "{2E666815-2EDB-464B-9DF6-380BF4789AD4}" EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{3F794AE4-319F-4498-A9DA-C49A4EB11D9E}" + ProjectSection(SolutionItems) = preProject + ..\Common\src\CoreLib\System\ReadOnlySpan.Fast.cs = ..\Common\src\CoreLib\System\ReadOnlySpan.Fast.cs + ..\Common\src\CoreLib\System\Span.Fast.cs = ..\Common\src\CoreLib\System\Span.Fast.cs + ..\Common\src\CoreLib\System\Span.NonGeneric.cs = ..\Common\src\CoreLib\System\Span.NonGeneric.cs + EndProjectSection +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -57,4 +64,7 @@ Global {4BBC8F69-D03E-4432-AA8A-D458FA5B235A} = {E107E9C1-E893-4E87-987E-04EF0DCEAEFD} {E883935B-D8FD-4FC9-A189-9D9E7F7EF550} = {2E666815-2EDB-464B-9DF6-380BF4789AD4} EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {D1974D36-E7EF-4503-B474-D92F2D79ABE5} + EndGlobalSection EndGlobal diff --git a/src/System.Memory/src/System/MemoryExtensions.Fast.cs b/src/System.Memory/src/System/MemoryExtensions.Fast.cs index 3ef952951b..2a540f43e8 100644 --- a/src/System.Memory/src/System/MemoryExtensions.Fast.cs +++ b/src/System.Memory/src/System/MemoryExtensions.Fast.cs @@ -43,7 +43,7 @@ namespace System /// Creates a new readonly span over the portion of the target string. /// </summary> /// <param name="text">The target string.</param> - /// <exception cref="System.ArgumentNullException">Thrown when <paramref name="text"/> is null.</exception> + /// <remarks>Returns default when <paramref name="text"/> is null.</remarks> public static ReadOnlySpan<char> AsReadOnlySpan(this string text) => Span.AsReadOnlySpan(text); /// <summary> @@ -63,7 +63,7 @@ namespace System /// <param name="text">The target string.</param> /// <param name="start">The index at which to begin this slice.</param> /// <param name="length">The desired length for the slice (exclusive).</param> - /// <exception cref="System.ArgumentNullException">Thrown when <paramref name="text"/> is null.</exception> + /// <remarks>Returns default when <paramref name="text"/> is null.</remarks> /// <exception cref="System.ArgumentOutOfRangeException"> /// Thrown when the specified <paramref name="start"/> index or <paramref name="length"/> is not in range. /// </exception> @@ -71,13 +71,13 @@ namespace System /// <summary>Creates a new <see cref="ReadOnlyMemory{T}"/> over the portion of the target string.</summary> /// <param name="text">The target string.</param> - /// <exception cref="System.ArgumentNullException">Thrown when <paramref name="text"/> is a null reference (Nothing in Visual Basic).</exception> + /// <remarks>Returns default when <paramref name="text"/> is null.</remarks> public static ReadOnlyMemory<char> AsReadOnlyMemory(this string text) => Span.AsReadOnlyMemory(text); /// <summary>Creates a new <see cref="ReadOnlyMemory{T}"/> over the portion of the target string.</summary> /// <param name="text">The target string.</param> /// <param name="start">The index at which to begin this slice.</param> - /// <exception cref="System.ArgumentNullException">Thrown when <paramref name="text"/> is a null reference (Nothing in Visual Basic).</exception> + /// <remarks>Returns default when <paramref name="text"/> is null.</remarks> /// <exception cref="System.ArgumentOutOfRangeException"> /// Thrown when the specified <paramref name="start"/> index is not in range (<0 or >text.Length). /// </exception> @@ -87,7 +87,7 @@ namespace System /// <param name="text">The target string.</param> /// <param name="start">The index at which to begin this slice.</param> /// <param name="length">The desired length for the slice (exclusive).</param> - /// <exception cref="System.ArgumentNullException">Thrown when <paramref name="text"/> is a null reference (Nothing in Visual Basic).</exception> + /// <remarks>Returns default when <paramref name="text"/> is null.</remarks> /// <exception cref="System.ArgumentOutOfRangeException"> /// Thrown when the specified <paramref name="start"/> index or <paramref name="length"/> is not in range. /// </exception> diff --git a/src/System.Memory/src/System/MemoryExtensions.Portable.cs b/src/System.Memory/src/System/MemoryExtensions.Portable.cs index 6b64749797..8e306acf6e 100644 --- a/src/System.Memory/src/System/MemoryExtensions.Portable.cs +++ b/src/System.Memory/src/System/MemoryExtensions.Portable.cs @@ -60,12 +60,12 @@ namespace System /// Creates a new readonly span over the portion of the target string. /// </summary> /// <param name="text">The target string.</param> - /// <exception cref="System.ArgumentNullException">Thrown when <paramref name="text"/> is null.</exception> + /// <remarks>Returns default when <paramref name="text"/> is null.</remarks> [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ReadOnlySpan<char> AsReadOnlySpan(this string text) { if (text == null) - ThrowHelper.ThrowArgumentNullException(ExceptionArgument.text); + return default; return new ReadOnlySpan<char>(Unsafe.As<Pinnable<char>>(text), StringAdjustment, text.Length); } @@ -75,7 +75,7 @@ namespace System /// </summary> /// <param name="text">The target string.</param> /// <param name="start">The index at which to begin this slice.</param> - /// <exception cref="System.ArgumentNullException">Thrown when <paramref name="text"/> is null.</exception> + /// <remarks>Returns default when <paramref name="text"/> is null.</remarks> /// <exception cref="System.ArgumentOutOfRangeException"> /// Thrown when the specified <paramref name="start"/> index is not in range (<0 or >text.Length). /// </exception> @@ -83,7 +83,11 @@ namespace System public static ReadOnlySpan<char> AsReadOnlySpan(this string text, int start) { if (text == null) - ThrowHelper.ThrowArgumentNullException(ExceptionArgument.text); + { + if (start != 0) + ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.start); + return default; + } if ((uint)start > (uint)text.Length) ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.start); @@ -96,7 +100,7 @@ namespace System /// <param name="text">The target string.</param> /// <param name="start">The index at which to begin this slice.</param> /// <param name="length">The desired length for the slice (exclusive).</param> - /// <exception cref="System.ArgumentNullException">Thrown when <paramref name="text"/> is null.</exception> + /// <remarks>Returns default when <paramref name="text"/> is null.</remarks> /// <exception cref="System.ArgumentOutOfRangeException"> /// Thrown when the specified <paramref name="start"/> index or <paramref name="length"/> is not in range. /// </exception> @@ -104,7 +108,11 @@ namespace System public static ReadOnlySpan<char> AsReadOnlySpan(this string text, int start, int length) { if (text == null) - ThrowHelper.ThrowArgumentNullException(ExceptionArgument.text); + { + if (start != 0 || length != 0) + ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.start); + return default; + } if ((uint)start > (uint)text.Length || (uint)length > (uint)(text.Length - start)) ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.start); @@ -113,11 +121,11 @@ namespace System /// <summary>Creates a new <see cref="ReadOnlyMemory{T}"/> over the portion of the target string.</summary> /// <param name="text">The target string.</param> - /// <exception cref="System.ArgumentNullException">Thrown when <paramref name="text"/> is a null reference (Nothing in Visual Basic).</exception> + /// <remarks>Returns default when <paramref name="text"/> is null.</remarks> public static ReadOnlyMemory<char> AsReadOnlyMemory(this string text) { if (text == null) - ThrowHelper.ThrowArgumentNullException(ExceptionArgument.text); + return default; return new ReadOnlyMemory<char>(text, 0, text.Length); } @@ -125,14 +133,18 @@ namespace System /// <summary>Creates a new <see cref="ReadOnlyMemory{T}"/> over the portion of the target string.</summary> /// <param name="text">The target string.</param> /// <param name="start">The index at which to begin this slice.</param> - /// <exception cref="System.ArgumentNullException">Thrown when <paramref name="text"/> is a null reference (Nothing in Visual Basic).</exception> + /// <remarks>Returns default when <paramref name="text"/> is null.</remarks> /// <exception cref="System.ArgumentOutOfRangeException"> /// Thrown when the specified <paramref name="start"/> index is not in range (<0 or >text.Length). /// </exception> public static ReadOnlyMemory<char> AsReadOnlyMemory(this string text, int start) { if (text == null) - ThrowHelper.ThrowArgumentNullException(ExceptionArgument.text); + { + if (start != 0) + ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.start); + return default; + } if ((uint)start > (uint)text.Length) ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.start); @@ -143,14 +155,18 @@ namespace System /// <param name="text">The target string.</param> /// <param name="start">The index at which to begin this slice.</param> /// <param name="length">The desired length for the slice (exclusive).</param> - /// <exception cref="System.ArgumentNullException">Thrown when <paramref name="text"/> is a null reference (Nothing in Visual Basic).</exception> + /// <remarks>Returns default when <paramref name="text"/> is null.</remarks> /// <exception cref="System.ArgumentOutOfRangeException"> /// Thrown when the specified <paramref name="start"/> index or <paramref name="length"/> is not in range. /// </exception> public static ReadOnlyMemory<char> AsReadOnlyMemory(this string text, int start, int length) { if (text == null) - ThrowHelper.ThrowArgumentNullException(ExceptionArgument.text); + { + if (start != 0 || length != 0) + ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.start); + return default; + } if ((uint)start > (uint)text.Length || (uint)length > (uint)(text.Length - start)) ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.start); diff --git a/src/System.Memory/src/System/ReadOnlySpan.Portable.cs b/src/System.Memory/src/System/ReadOnlySpan.Portable.cs index a1025f3582..2d733fc35c 100644 --- a/src/System.Memory/src/System/ReadOnlySpan.Portable.cs +++ b/src/System.Memory/src/System/ReadOnlySpan.Portable.cs @@ -23,14 +23,16 @@ namespace System /// Creates a new read-only span over the entirety of the target array. /// </summary> /// <param name="array">The target array.</param> - /// <exception cref="System.ArgumentNullException">Thrown when <paramref name="array"/> is a null - /// reference (Nothing in Visual Basic).</exception> + /// <remarks>Returns default when <paramref name="array"/> is null.</remarks> /// <exception cref="System.ArrayTypeMismatchException">Thrown when <paramref name="array"/> is covariant and array's type is not exactly T[].</exception> [MethodImpl(MethodImplOptions.AggressiveInlining)] public ReadOnlySpan(T[] array) { if (array == null) - ThrowHelper.ThrowArgumentNullException(ExceptionArgument.array); + { + this = default; + return; // returns default + } _length = array.Length; _pinnable = Unsafe.As<Pinnable<T>>(array); @@ -44,8 +46,7 @@ namespace System /// <param name="array">The target array.</param> /// <param name="start">The index at which to begin the read-only span.</param> /// <param name="length">The number of items in the read-only span.</param> - /// <exception cref="System.ArgumentNullException">Thrown when <paramref name="array"/> is a null - /// reference (Nothing in Visual Basic).</exception> + /// <remarks>Returns default when <paramref name="array"/> is null.</remarks> /// <exception cref="System.ArrayTypeMismatchException">Thrown when <paramref name="array"/> is covariant and array's type is not exactly T[].</exception> /// <exception cref="System.ArgumentOutOfRangeException"> /// Thrown when the specified <paramref name="start"/> or end index is not in the range (<0 or >=Length). @@ -54,7 +55,12 @@ namespace System public ReadOnlySpan(T[] array, int start, int length) { if (array == null) - ThrowHelper.ThrowArgumentNullException(ExceptionArgument.array); + { + if (start != 0 || length != 0) + ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.start); + this = default; + return; // returns default + } if ((uint)start > (uint)array.Length || (uint)length > (uint)(array.Length - start)) ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.start); diff --git a/src/System.Memory/src/System/Span.Portable.cs b/src/System.Memory/src/System/Span.Portable.cs index 39162b07a1..ba42e7e77a 100644 --- a/src/System.Memory/src/System/Span.Portable.cs +++ b/src/System.Memory/src/System/Span.Portable.cs @@ -23,14 +23,16 @@ namespace System /// Creates a new span over the entirety of the target array. /// </summary> /// <param name="array">The target array.</param> - /// <exception cref="System.ArgumentNullException">Thrown when <paramref name="array"/> is a null - /// reference (Nothing in Visual Basic).</exception> + /// <remarks>Returns default when <paramref name="array"/> is null.</remarks> /// <exception cref="System.ArrayTypeMismatchException">Thrown when <paramref name="array"/> is covariant and array's type is not exactly T[].</exception> [MethodImpl(MethodImplOptions.AggressiveInlining)] public Span(T[] array) { if (array == null) - ThrowHelper.ThrowArgumentNullException(ExceptionArgument.array); + { + this = default; + return; // returns default + } if (default(T) == null && array.GetType() != typeof(T[])) ThrowHelper.ThrowArrayTypeMismatchException(); @@ -46,8 +48,7 @@ namespace System /// <param name="array">The target array.</param> /// <param name="start">The index at which to begin the span.</param> /// <param name="length">The number of items in the span.</param> - /// <exception cref="System.ArgumentNullException">Thrown when <paramref name="array"/> is a null - /// reference (Nothing in Visual Basic).</exception> + /// <remarks>Returns default when <paramref name="array"/> is null.</remarks> /// <exception cref="System.ArrayTypeMismatchException">Thrown when <paramref name="array"/> is covariant and array's type is not exactly T[].</exception> /// <exception cref="System.ArgumentOutOfRangeException"> /// Thrown when the specified <paramref name="start"/> or end index is not in the range (<0 or >=Length). @@ -56,7 +57,12 @@ namespace System public Span(T[] array, int start, int length) { if (array == null) - ThrowHelper.ThrowArgumentNullException(ExceptionArgument.array); + { + if (start != 0 || length != 0) + ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.start); + this = default; + return; // returns default + } if (default(T) == null && array.GetType() != typeof(T[])) ThrowHelper.ThrowArrayTypeMismatchException(); if ((uint)start > (uint)array.Length || (uint)length > (uint)(array.Length - start)) diff --git a/src/System.Memory/src/System/ThrowHelper.cs b/src/System.Memory/src/System/ThrowHelper.cs index 459b436f5b..4ba7eec5fd 100644 --- a/src/System.Memory/src/System/ThrowHelper.cs +++ b/src/System.Memory/src/System/ThrowHelper.cs @@ -106,17 +106,16 @@ namespace System } } + // + // The convention for this enum is using the argument name as the enum name + // internal enum ExceptionArgument { array, length, start, - text, - obj, - ownedMemory, minimumBufferSize, byteOffset, - pointer, comparable, comparer } diff --git a/src/System.Memory/tests/Memory/CtorArray.cs b/src/System.Memory/tests/Memory/CtorArray.cs index d5b153768f..e2f67d1162 100644 --- a/src/System.Memory/tests/Memory/CtorArray.cs +++ b/src/System.Memory/tests/Memory/CtorArray.cs @@ -71,8 +71,13 @@ namespace System.MemoryTests [Fact] public static void CtorArrayNullArray() { - Assert.Throws<ArgumentNullException>(() => new Memory<int>(null)); - Assert.Throws<ArgumentNullException>(() => new Memory<int>(null, 0, 0)); + var memory = new Memory<int>(null); + memory.Validate(); + Assert.Equal(default, memory); + + memory = new Memory<int>(null, 0, 0); + memory.Validate(); + Assert.Equal(default, memory); } [Fact] diff --git a/src/System.Memory/tests/ReadOnlyMemory/CtorArray.cs b/src/System.Memory/tests/ReadOnlyMemory/CtorArray.cs index 046398c076..f4ddfe7daa 100644 --- a/src/System.Memory/tests/ReadOnlyMemory/CtorArray.cs +++ b/src/System.Memory/tests/ReadOnlyMemory/CtorArray.cs @@ -72,8 +72,13 @@ namespace System.MemoryTests [Fact] public static void CtorArrayNullArray() { - Assert.Throws<ArgumentNullException>(() => new ReadOnlyMemory<int>(null)); - Assert.Throws<ArgumentNullException>(() => new ReadOnlyMemory<int>(null, 0, 0)); + var memory = new ReadOnlyMemory<int>(null); + memory.Validate(); + Assert.Equal(default, memory); + + memory = new ReadOnlyMemory<int>(null, 0, 0); + memory.Validate(); + Assert.Equal(default, memory); } [Fact] diff --git a/src/System.Memory/tests/ReadOnlyMemory/Strings.cs b/src/System.Memory/tests/ReadOnlyMemory/Strings.cs index 592f398987..248cf818c3 100644 --- a/src/System.Memory/tests/ReadOnlyMemory/Strings.cs +++ b/src/System.Memory/tests/ReadOnlyMemory/Strings.cs @@ -54,11 +54,19 @@ namespace System.MemoryTests } [Fact] - public static void AsReadOnlyMemory_NullString_Throws() + public static void AsReadOnlyMemory_NullString_Default() { - AssertExtensions.Throws<ArgumentNullException>("text", () => ((string)null).AsReadOnlyMemory()); - AssertExtensions.Throws<ArgumentNullException>("text", () => ((string)null).AsReadOnlyMemory(0)); - AssertExtensions.Throws<ArgumentNullException>("text", () => ((string)null).AsReadOnlyMemory(0, 0)); + ReadOnlyMemory<char> m = ((string)null).AsReadOnlyMemory(); + m.Validate(); + Assert.Equal(default, m); + + m = ((string)null).AsReadOnlyMemory(0); + m.Validate(); + Assert.Equal(default, m); + + m = ((string)null).AsReadOnlyMemory(0, 0); + m.Validate(); + Assert.Equal(default, m); } [Fact] @@ -191,14 +199,14 @@ namespace System.MemoryTests [MemberData(nameof(TestHelpers.StringSlice2ArgTestOutOfRangeData), MemberType = typeof(TestHelpers))] public static unsafe void AsReadOnlyMemory_2Arg_OutOfRange(string text, int start) { - AssertExtensions.Throws<ArgumentOutOfRangeException>("start", () => text.AsReadOnlyMemory(start)); + AssertExtensions.Throws<ArgumentOutOfRangeException>("Start", () => text.AsReadOnlyMemory(start)); } [Theory] [MemberData(nameof(TestHelpers.StringSlice3ArgTestOutOfRangeData), MemberType = typeof(TestHelpers))] public static unsafe void AsReadOnlyMemory_3Arg_OutOfRange(string text, int start, int length) { - AssertExtensions.Throws<ArgumentOutOfRangeException>("start", () => text.AsReadOnlyMemory(start, length)); + AssertExtensions.Throws<ArgumentOutOfRangeException>("Start", () => text.AsReadOnlyMemory(start, length)); } [Fact] diff --git a/src/System.Memory/tests/ReadOnlySpan/AsReadOnlySpan.cs b/src/System.Memory/tests/ReadOnlySpan/AsReadOnlySpan.cs index 71dfa9b417..dc69d4a086 100644 --- a/src/System.Memory/tests/ReadOnlySpan/AsReadOnlySpan.cs +++ b/src/System.Memory/tests/ReadOnlySpan/AsReadOnlySpan.cs @@ -40,7 +40,9 @@ namespace System.SpanTests public static void NullArrayAsReadOnlySpan() { int[] a = null; - Assert.Throws<ArgumentNullException>(() => a.AsReadOnlySpan().DontBox()); + ReadOnlySpan<int> span = a.AsReadOnlySpan(); + span.Validate(); + Assert.True(span == default); } [Fact] @@ -117,9 +119,17 @@ namespace System.SpanTests public static void StringAsReadOnlySpanNullChecked() { string s = null; - Assert.Throws<ArgumentNullException>(() => s.AsReadOnlySpan().DontBox()); - Assert.Throws<ArgumentNullException>(() => s.AsReadOnlySpan(0).DontBox()); - Assert.Throws<ArgumentNullException>(() => s.AsReadOnlySpan(0, 0).DontBox()); + ReadOnlySpan<char> span = s.AsReadOnlySpan(); + span.Validate(); + Assert.True(span == default); + + span = s.AsReadOnlySpan(0); + span.Validate(); + Assert.True(span == default); + + span = s.AsReadOnlySpan(0, 0); + span.Validate(); + Assert.True(span == default); } [Fact] @@ -174,14 +184,14 @@ namespace System.SpanTests [MemberData(nameof(TestHelpers.StringSlice2ArgTestOutOfRangeData), MemberType = typeof(TestHelpers))] public static unsafe void AsReadOnlySpan_2Arg_OutOfRange(string text, int start) { - AssertExtensions.Throws<ArgumentOutOfRangeException>("start", () => text.AsReadOnlySpan(start).DontBox()); + AssertExtensions.Throws<ArgumentOutOfRangeException>("Start", () => text.AsReadOnlySpan(start).DontBox()); } [Theory] [MemberData(nameof(TestHelpers.StringSlice3ArgTestOutOfRangeData), MemberType = typeof(TestHelpers))] public static unsafe void AsReadOnlySpan_3Arg_OutOfRange(string text, int start, int length) { - AssertExtensions.Throws<ArgumentOutOfRangeException>("start", () => text.AsReadOnlySpan(start, length).DontBox()); + AssertExtensions.Throws<ArgumentOutOfRangeException>("Start", () => text.AsReadOnlySpan(start, length).DontBox()); } } } diff --git a/src/System.Memory/tests/ReadOnlySpan/CtorArray.cs b/src/System.Memory/tests/ReadOnlySpan/CtorArray.cs index ea8f3ba831..f72a3c6dbb 100644 --- a/src/System.Memory/tests/ReadOnlySpan/CtorArray.cs +++ b/src/System.Memory/tests/ReadOnlySpan/CtorArray.cs @@ -72,8 +72,13 @@ namespace System.SpanTests [Fact] public static void CtorArrayNullArray() { - Assert.Throws<ArgumentNullException>(() => new ReadOnlySpan<int>(null).DontBox()); - Assert.Throws<ArgumentNullException>(() => new ReadOnlySpan<int>(null, 0, 0).DontBox()); + var span = new ReadOnlySpan<int>(null); + span.Validate(); + Assert.True(span == default); + + span = new ReadOnlySpan<int>(null, 0, 0); + span.Validate(); + Assert.True(span == default); } [Fact] diff --git a/src/System.Memory/tests/Span/CtorArray.cs b/src/System.Memory/tests/Span/CtorArray.cs index 6105a99748..a26334a009 100644 --- a/src/System.Memory/tests/Span/CtorArray.cs +++ b/src/System.Memory/tests/Span/CtorArray.cs @@ -71,8 +71,13 @@ namespace System.SpanTests [Fact] public static void CtorArrayNullArray() { - Assert.Throws<ArgumentNullException>(() => new Span<int>(null).DontBox()); - Assert.Throws<ArgumentNullException>(() => new Span<int>(null, 0, 0).DontBox()); + var span = new Span<int>(null); + span.Validate(); + Assert.True(span == default); + + span = new Span<int>(null, 0, 0); + span.Validate(); + Assert.True(span == default); } [Fact] |