public static unsafe void GetUtf16SpanFromSBytePointerTest() { Assert.That(() => MarshalUtilities.GetUtf16Span(null, -1).ToArray(), Is.EqualTo(Array.Empty <ushort>()) ); fixed(ushort *source = Array.Empty <ushort>()) { var pSource = source; Assert.That(() => MarshalUtilities.GetUtf16Span(pSource, -1).ToArray(), Is.EqualTo(Array.Empty <ushort>()) ); } fixed(ushort *source = new ushort[] { 'A', 'B', 'C' }) { var pSource = source; Assert.That(() => MarshalUtilities.GetUtf16Span(pSource, -1).ToArray(), Is.EqualTo(new ushort[] { 'A', 'B', 'C' }) ); Assert.That(() => MarshalUtilities.GetUtf16Span(pSource, 2).ToArray(), Is.EqualTo(new ushort[] { 'A', 'B' }) ); } }
public static void GetUtf16SpanFromStringTest() { Assert.That(() => MarshalUtilities.GetUtf16Span(null).ToArray(), Is.EqualTo(Array.Empty <ushort>()) ); Assert.That(() => MarshalUtilities.GetUtf16Span(string.Empty).ToArray(), Is.EqualTo(Array.Empty <ushort>()) ); Assert.That(() => MarshalUtilities.GetUtf16Span("ABC").ToArray(), Is.EqualTo(new ushort[] { 'A', 'B', 'C' }) ); }
public static unsafe void GetUtf16SpanFromSByteReferenceTest() { Assert.That(() => MarshalUtilities.GetUtf16Span(UnsafeUtilities.NullRef <ushort>(), -1).ToArray(), Is.EqualTo(Array.Empty <ushort>()) ); var source = new ushort[] { 'A', 'B', 'C' }; Assert.That(() => MarshalUtilities.GetUtf16Span(in source[0], -1).ToArray(), Is.EqualTo(new ushort[] { 'A', 'B', 'C' }) ); Assert.That(() => MarshalUtilities.GetUtf16Span(in source[0], 2).ToArray(), Is.EqualTo(new ushort[] { 'A', 'B' }) ); }