public static void EmptyProperty() { // Act Utf8Span span = Utf8Span.Empty; // Assert // GetPinnableReference should be 'null' to match behavior of empty ROS<byte>.GetPinnableReference(); Assert.True(span.IsEmpty); Assert.Equal(IntPtr.Zero, (IntPtr)(void *)Unsafe.AsPointer(ref Unsafe.AsRef(in span.GetPinnableReference()))); Assert.Equal(IntPtr.Zero, (IntPtr)(void *)Unsafe.AsPointer(ref MemoryMarshal.GetReference(span.Bytes))); Assert.Equal(0, span.Length); }
public static void Ctor_UnsafeFromByteSpan_NonNullEmptyArray() { // Arrange ReadOnlySpan <byte> original = new byte[0]; // Act Utf8Span span = Utf8Span.UnsafeCreateWithoutValidation(original); // Assert // GetPinnableReference should be 'null' to match behavior of empty ROS<byte>.GetPinnableReference(); Assert.True(span.IsEmpty); Assert.Equal(IntPtr.Zero, (IntPtr)(void *)Unsafe.AsPointer(ref Unsafe.AsRef(in span.GetPinnableReference()))); Assert.True(Unsafe.AreSame(ref MemoryMarshal.GetReference(original), ref MemoryMarshal.GetReference(span.Bytes))); Assert.Equal(0, span.Length); }
public static void Ctor_NullUtf8String() { // Arrange ustring str = null; // Act Utf8Span span = new Utf8Span(str); // Assert // GetPinnableReference should be 'null' to match behavior of empty ROS<byte>.GetPinnableReference(); Assert.True(span.IsEmpty); Assert.Equal(IntPtr.Zero, (IntPtr)(void *)Unsafe.AsPointer(ref Unsafe.AsRef(in span.GetPinnableReference()))); Assert.Equal(IntPtr.Zero, (IntPtr)(void *)Unsafe.AsPointer(ref MemoryMarshal.GetReference(span.Bytes))); Assert.Equal(0, span.Length); }
public static void Ctor_UnsafeFromByteSpan_NonEmpty() { // Arrange ReadOnlySpan <byte> original = new byte[] { 1, 2, 3, 4, 5 }; // Act Utf8Span span = Utf8Span.UnsafeCreateWithoutValidation(original); // Assert Assert.False(span.IsEmpty); Assert.True(Unsafe.AreSame(ref Unsafe.AsRef(in original.GetPinnableReference()), ref Unsafe.AsRef(in span.GetPinnableReference()))); Assert.True(Unsafe.AreSame(ref Unsafe.AsRef(in original.GetPinnableReference()), ref MemoryMarshal.GetReference(span.Bytes))); Assert.Equal(5, span.Length); }
public static void Ctor_NonEmptyUtf8String() { // Arrange ustring str = u8("Hello!"); // Act Utf8Span span = new Utf8Span(str); // Assert Assert.False(span.IsEmpty); Assert.True(Unsafe.AreSame(ref Unsafe.AsRef(in str.GetPinnableReference()), ref Unsafe.AsRef(in span.GetPinnableReference()))); Assert.True(Unsafe.AreSame(ref Unsafe.AsRef(in str.GetPinnableReference()), ref MemoryMarshal.GetReference(span.Bytes))); Assert.Equal(6, span.Length); }