Repository: dotnet/runtime
File: src/libraries/System.Memory/tests/Base64/Base64DecoderUnitTests.cs (C#)

Code before:
            Assert.Equal(new byte[] { 0, 0 }, output[..2]);
        }

        [Fact]
        public void DecodingWithWhiteSpaceSplitFinalQuantumStreamingScenario()
        {
            // Simulate a streaming scenario where we call DecodeFromUtf8 multiple times
            ReadOnlySpan<byte> base64Data = "AA\r\nA="u8;
            var output = new byte[10];

            // First call with isFinalBlock=false
            OperationStatus status = Base64.DecodeFromUtf8(base64Data, output, out int bytesConsumed, out int bytesWritten, isFinalBlock: false);
            Assert.Equal(OperationStatus.InvalidData, status);
            Assert.Equal(0, bytesConsumed);
            Assert.Equal(0, bytesWritten);

            // Slice the buffer based on what was consumed (nothing in this case)
            base64Data = base64Data.Slice(bytesConsumed);
            var outputSpan = output.AsSpan().Slice(bytesWritten);

            // Second call with isFinalBlock=true should successfully decode
            status = Base64.DecodeFromUtf8(base64Data, outputSpan, out bytesConsumed, out bytesWritten, isFinalBlock: true);
            Assert.Equal(OperationStatus.Done, status);
            Assert.Equal(6, bytesConsumed); // All 6 bytes: "AA\r\nA="
            Assert.Equal(2, bytesWritten); // "AAA=" decodes to 2 bytes
        }

        [Fact]
        public void DecodingCompleteQuantumWithIsFinalBlockFalse()
        {
            // Complete quantum without padding should be decoded even when isFinalBlock=false
            ReadOnlySpan<byte> base64Data = "AAAA"u8;
            var output = new byte[10];

            OperationStatus status = Base64.DecodeFromUtf8(base64Data, output, out int bytesConsumed, out int bytesWritten, isFinalBlock: false);
            Assert.Equal(OperationStatus.Done, status);
            Assert.Equal(4, bytesConsumed);
            Assert.Equal(3, bytesWritten);
        }

        [Fact]
        public void DecodingPaddedQuantumWithIsFinalBlockFalse()
        {
            // Quantum with padding should not be decoded when isFinalBlock=false
            ReadOnlySpan<byte> base64Data = "AAA="u8;
            var output = new byte[10];

            OperationStatus status = Base64.DecodeFromUtf8(base64Data, output, out int bytesConsumed, out int bytesWritten, isFinalBlock: false);
            Assert.Equal(OperationStatus.InvalidData, status);
            Assert.Equal(0, bytesConsumed);
            Assert.Equal(0, bytesWritten);

Review comment (suggestion):
```suggestion
```

This test does the same as the one right above

Code after:
        [Fact]
        public void DecodingWithWhiteSpaceIntoSmallDestination()
        {
            // Input "  zAww  " (8 bytes) contains "zAww" which decodes to 3 bytes.
            // 'z' = 51, 'A' = 0, 'w' = 48, 'w' = 48 -> bits: 110011 000000 110000 110000 -> 0xCC 0x0C 0x30
            // With destination of 3 bytes, this should succeed, not report "Destination too short".
            byte[] input = Encoding.UTF8.GetBytes("  zAww  ");

            byte[] destination5 = new byte[5];
            OperationStatus status5 = Base64.DecodeFromUtf8(input, destination5, out int consumed5, out int written5);
            Assert.Equal(OperationStatus.Done, status5);
            Assert.Equal(input.Length, consumed5);
            Assert.Equal(3, written5);

            byte[] destination3 = new byte[3];
            OperationStatus status3 = Base64.DecodeFromUtf8(input, destination3, out int consumed3, out int written3);
            Assert.Equal(OperationStatus.Done, status3);
            Assert.Equal(input.Length, consumed3);
            Assert.Equal(3, written3);
        }

        [Fact]
        public void DecodingWithOnlyWhiteSpaceIntoSmallDestination()
        {
            // Input "        " (8 spaces) decodes to 0 bytes.
            // With destination of 1 byte, this should succeed, not report "Destination too short".
            byte[] allSpaces = Encoding.UTF8.GetBytes(new string(' ', 8));

            byte[] destination = new byte[1];
            OperationStatus status = Base64.DecodeFromUtf8(allSpaces, destination, out int consumed, out int written);
            Assert.Equal(OperationStatus.Done, status);
            Assert.Equal(allSpaces.Length, consumed);
            Assert.Equal(0, written);

            // Also test with empty destination buffer
            byte[] emptyDestination = Array.Empty<byte>();
            OperationStatus statusEmpty = Base64.DecodeFromUtf8(allSpaces, emptyDestination, out int consumedEmpty, out int writtenEmpty);
            Assert.Equal(OperationStatus.Done, statusEmpty);
            Assert.Equal(allSpaces.Length, consumedEmpty);
            Assert.Equal(0, writtenEmpty);
        }

        [Fact]
        public void DecodingWithWhiteSpaceIntoSmallDestination_ActualDestinationTooSmall()
        {
            // Input "  AQID" (leading whitespace only) decodes to 3 bytes.
            // With destination of 1 byte, this should correctly report "Destination too short".
            // Note: Base64 requires input length to be multiple of 4, so we use "AQIDBA==" which decodes to 4 bytes.
            byte[] input = Encoding.UTF8.GetBytes("  AQIDBA==");

            byte[] destination1 = new byte[1];