diff options
Diffstat (limited to 'src/System.Memory/tests/Memory/Span.cs')
-rw-r--r-- | src/System.Memory/tests/Memory/Span.cs | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/src/System.Memory/tests/Memory/Span.cs b/src/System.Memory/tests/Memory/Span.cs index 55ed001b3d..55956dd6ab 100644 --- a/src/System.Memory/tests/Memory/Span.cs +++ b/src/System.Memory/tests/Memory/Span.cs @@ -3,6 +3,7 @@ // See the LICENSE file in the project root for more information. using System.Buffers; +using System.Runtime.InteropServices; using Xunit; namespace System.MemoryTests @@ -42,6 +43,22 @@ namespace System.MemoryTests } [Fact] + public static void SpanFromCtorArrayChar() + { + char[] a = { '1', '2', '3', '4', '-' }; + Memory<char> memory; + + memory = new Memory<char>(a); + memory.Span.Validate('1', '2', '3', '4', '-'); + + memory = new Memory<char>(a, 0, a.Length); + memory.Span.Validate('1', '2', '3', '4', '-'); + + MemoryManager<char> manager = new CustomMemoryForTest<char>(a); + manager.Memory.Span.Validate('1', '2', '3', '4', '-'); + } + + [Fact] public static void SpanFromCtorArrayObject() { object o1 = new object(); @@ -60,6 +77,19 @@ namespace System.MemoryTests } [Fact] + public static void SpanFromStringAsMemory() + { + string a = "1234-"; + ReadOnlyMemory<char> memory; + + memory = a.AsMemory(); + MemoryMarshal.AsMemory(memory).Span.Validate('1', '2', '3', '4', '-'); + + memory = a.AsMemory(0, a.Length); + MemoryMarshal.AsMemory(memory).Span.Validate('1', '2', '3', '4', '-'); + } + + [Fact] public static void SpanFromCtorArrayZeroLength() { int[] empty = Array.Empty<int>(); |