From 8eaa01b505f7449406a88af0d164e798c2ed7c4b Mon Sep 17 00:00:00 2001 From: Oliver Booth Date: Wed, 12 Jun 2024 11:59:47 +0100 Subject: [PATCH] test: TryWriteBytes should return false for smol span --- X10D.Tests/src/IO/DecimalTests.cs | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/X10D.Tests/src/IO/DecimalTests.cs b/X10D.Tests/src/IO/DecimalTests.cs index 93dea74..46e7077 100644 --- a/X10D.Tests/src/IO/DecimalTests.cs +++ b/X10D.Tests/src/IO/DecimalTests.cs @@ -35,7 +35,7 @@ internal class DecimalTests byte[] expected = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 210]; Span bytes = stackalloc byte[16]; - value.TryWriteBigEndianBytes(bytes); + Assert.That(value.TryWriteBigEndianBytes(bytes)); CollectionAssert.AreEqual(expected, bytes.ToArray()); } @@ -47,8 +47,26 @@ internal class DecimalTests byte[] expected = [210, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]; Span bytes = stackalloc byte[16]; - value.TryWriteLittleEndianBytes(bytes); + Assert.That(value.TryWriteLittleEndianBytes(bytes)); CollectionAssert.AreEqual(expected, bytes.ToArray()); } + + [Test] + public void TryWriteBigEndianBytes_ShouldReturnFalse_GivenSmallSpan() + { + const decimal value = 1234m; + + Span bytes = Span.Empty; + Assert.That(value.TryWriteBigEndianBytes(bytes), Is.False); + } + + [Test] + public void TryWriteLittleEndianBytes_ShouldReturnFalse_GivenSmallSpan() + { + const decimal value = 1234m; + + Span bytes = Span.Empty; + Assert.That(value.TryWriteLittleEndianBytes(bytes), Is.False); + } }