public void Write_BigEndian_String_Less_Fixed_Size_Than_RealString() { StackDataWriter writer = new StackDataWriter(32); string str = new string('a', 255); int size = 239; if (BitConverter.IsLittleEndian) { writer.WriteUnicodeLE(str, size); } else { writer.WriteUnicodeBE(str, size); } Span <char> span = stackalloc char[size]; str.AsSpan(0, size).CopyTo(span); Assert.True(MemoryMarshal.AsBytes(span).SequenceEqual(writer.Buffer.Slice(0, writer.BytesWritten))); writer.Dispose(); }