base32 refactoring
.NET Test / .NET tests (push) Failing after 1m54s

This commit is contained in:
2026-07-10 21:53:37 +04:00
parent d11c74e5d6
commit 566c813e8d
18 changed files with 375 additions and 88 deletions
+41
View File
@@ -4,6 +4,7 @@ public class Encode
{
[Theory]
[InlineData("TQ======")]
[InlineData("CE======")]
[InlineData("3X3A====")]
[InlineData("426G6===")]
[InlineData("C3V3Y===")]
@@ -30,8 +31,10 @@ public class Encode
{
var resultBytes = Base32.Decode(testString);
var resultString = Base32.Encode(resultBytes);
var resultStringLowerCase = Base32.Encode(resultBytes, Base32EncodeOptions.LowerCase);
resultString.ShouldBe(testString);
resultStringLowerCase.ShouldBe(testString.ToLowerInvariant());
}
[Theory]
@@ -47,7 +50,29 @@ public class Encode
public void WhenCalledWithNotEmptyByteArray_ShouldReturnValidString(string expected, byte[] testArray)
{
var str = Base32.Encode(testArray);
var strLowerCase = Base32.Encode(testArray, Base32EncodeOptions.LowerCase);
str.ShouldBe(expected);
strLowerCase.ShouldBe(expected.ToLowerInvariant());
}
[Theory]
[InlineData("FG4M3ZQM3TVWDMBUP5L7N7V3JS7KBM2E", new byte[] { 0x29, 0xb8, 0xcd, 0xe6, 0x0c, 0xdc, 0xeb, 0x61, 0xb0, 0x34, 0x7f, 0x57, 0xf6, 0xfe, 0xbb, 0x4c, 0xbe, 0xa0, 0xb3, 0x44, })]
[InlineData("WXYEOQUZULMCY6ZQTDOLTRUZZMKQ", new byte[] { 0xb5, 0xf0, 0x47, 0x42, 0x99, 0xa2, 0xd8, 0x2c, 0x7b, 0x30, 0x98, 0xdc, 0xb9, 0xc6, 0x99, 0xcb, 0x15, })]
[InlineData("2IO2HTALCXZWCBD2AAAAAAAAAAAA", new byte[] { 0xd2, 0x1d, 0xa3, 0xcc, 0x0b, 0x15, 0xf3, 0x61, 0x04, 0x7a, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, })]
[InlineData("2IO2HTALCXZWCBD2AAAAAAAA", new byte[] { 0xd2, 0x1d, 0xa3, 0xcc, 0x0b, 0x15, 0xf3, 0x61, 0x04, 0x7a, 0x00, 0x00, 0x00, 0x00, 0x00, })]
[InlineData("2IO2HTALCXZWCBD2", new byte[] { 0xd2, 0x1d, 0xa3, 0xcc, 0x0b, 0x15, 0xf3, 0x61, 0x04, 0x7a, })]
[InlineData("ZFXJMF5N", new byte[] { 0b11001001, 0b01101110, 0b10010110, 0b00010111, 0b10101101, })]
[InlineData("CPIKTMY", new byte[] { 0b00010011, 0b11010000, 0b10101001, 0b10110011, })]
[InlineData("JVNJA", new byte[] { 0b01001101, 0b01011010, 0b10010000, })]
[InlineData("74OQ", new byte[] { 0b11111111, 0b00011101, })]
public void WhenCalledWithNotEmptyByteArray_ShouldReturnValidStringWithNoPadding(string expected, byte[] testArray)
{
var str = Base32.Encode(testArray, Base32EncodeOptions.NoPadding);
var strLowerCase = Base32.Encode(testArray, Base32EncodeOptions.NoPadding | Base32EncodeOptions.LowerCase);
str.ShouldBe(expected);
strLowerCase.ShouldBe(expected.ToLowerInvariant());
}
[Theory]
@@ -71,4 +96,20 @@ public class Encode
charsWritten.ShouldBe(0);
output.ShouldBe(['1', '2', '3', '4']);
}
[Theory]
[InlineData(new byte[] { 1, 2, 3 }, 3)]
[InlineData(new byte[] { 1, 2, 3 }, 4)]
[InlineData(new byte[] { 1, 2, 3 }, 5)]
[InlineData(new byte[] { 1, 2, 3 }, 6)]
[InlineData(new byte[] { 1, 2, 3 }, 7)]
[InlineData(new byte[] { 1, 2, 3, 4, 5, 6 }, 15)]
[InlineData(new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 }, 23)]
public void SpanTooSmall_ThrowsArgumentException(byte[] input, int outputLength)
{
var output = new char[outputLength];
Action action = () => _ = Base32.Encode(input, output);
action.ShouldThrow<ArgumentException>()
.WithMessage("Encoded input can not fit in output span. (Parameter 'output')");
}
}