Skip to content

Commit

Permalink
Adress PR feedback: Add test to demonstrate extra whitespace is counted
Browse files Browse the repository at this point in the history
  • Loading branch information
heathbm committed Mar 10, 2023
1 parent b35ce12 commit 5848058
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions src/libraries/System.Memory/tests/Base64/Base64DecoderUnitTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -730,5 +730,38 @@ public void DecodingInPlaceWithOnlyCharsToBeIgnored(string utf8WithCharsToBeIgno
Assert.Equal(OperationStatus.Done, result);
Assert.Equal(0, bytesWritten);
}

[Theory]
[InlineData("AQ==", 4, 1)]
[InlineData("AQ== ", 5, 1)]
[InlineData("AQ== ", 6, 1)]
[InlineData("AQ== ", 7, 1)]
[InlineData("AQ== ", 8, 1)]
[InlineData("AQ== ", 9, 1)]
[InlineData("AQ==\n", 5, 1)]
[InlineData("AQ==\n\n", 6, 1)]
[InlineData("AQ==\n\n\n", 7, 1)]
[InlineData("AQ==\n\n\n\n", 8, 1)]
[InlineData("AQ==\n\n\n\n\n", 9, 1)]
[InlineData("AQ==\t", 5, 1)]
[InlineData("AQ==\t\t", 6, 1)]
[InlineData("AQ==\t\t\t", 7, 1)]
[InlineData("AQ==\t\t\t\t", 8, 1)]
[InlineData("AQ==\t\t\t\t\t", 9, 1)]
[InlineData("AQ==\r", 5, 1)]
[InlineData("AQ==\r\r", 6, 1)]
[InlineData("AQ==\r\r\r", 7, 1)]
[InlineData("AQ==\r\r\r\r", 8, 1)]
[InlineData("AQ==\r\r\r\r\r", 9, 1)]
public void BasicDecodingWithExtraWhitespaceShouldBeCountedInConsumedBytes(string inputString, int expectedConsumed, int expectedWritten)
{
Span<byte> source = Encoding.ASCII.GetBytes(inputString);
Span<byte> decodedBytes = new byte[Base64.GetMaxDecodedFromUtf8Length(source.Length)];

Assert.Equal(OperationStatus.Done, Base64.DecodeFromUtf8(source, decodedBytes, out int consumed, out int decodedByteCount));
Assert.Equal(expectedConsumed, consumed);
Assert.Equal(expectedWritten, decodedByteCount);
Assert.True(Base64TestHelper.VerifyDecodingCorrectness(expectedConsumed, expectedWritten, source, decodedBytes));
}
}
}

0 comments on commit 5848058

Please sign in to comment.