From 12d7976055fc36b8f3aed1a881b79f784e5fd040 Mon Sep 17 00:00:00 2001 From: Bas van der Linden Date: Sun, 12 Jul 2020 15:12:18 +0200 Subject: [PATCH] Added test for ByteString.CopyFrom(ReadOnlySpan bytes) --- csharp/src/Google.Protobuf.Test/ByteStringTest.cs | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/csharp/src/Google.Protobuf.Test/ByteStringTest.cs b/csharp/src/Google.Protobuf.Test/ByteStringTest.cs index 0ef8d8f4e7..e31ecd1839 100644 --- a/csharp/src/Google.Protobuf.Test/ByteStringTest.cs +++ b/csharp/src/Google.Protobuf.Test/ByteStringTest.cs @@ -110,6 +110,18 @@ namespace Google.Protobuf Assert.AreEqual(10, bs[0]); } + [Test] + public void CopyFromReadOnlySpanCopiesContents() + { + byte[] data = new byte[1]; + data[0] = 10; + ReadOnlySpan byteSpan = data; + var bs = ByteString.CopyFrom(byteSpan); + Assert.AreEqual(10, bs[0]); + data[0] = 5; + Assert.AreEqual(10, bs[0]); + } + [Test] public void ToByteArrayCopiesContents() { @@ -249,5 +261,6 @@ namespace Google.Protobuf var copied = byteString.Memory.ToArray(); CollectionAssert.AreEqual(byteString, copied); } + } } \ No newline at end of file