lib/base: Support colons in from_hex()

This commit is contained in:
Povilas Kanapickas
2021-11-01 02:52:42 +02:00
parent aa3afa9062
commit 8f88dc2585
2 changed files with 26 additions and 5 deletions

View File

@@ -69,6 +69,13 @@ TEST(StringTests, fromhex_plaintext_string)
EXPECT_EQ(result, std::vector<std::uint8_t>(expected.begin(), expected.end()));
}
TEST(StringTests, fromhex_plaintext_string_colons)
{
auto result = string::from_hex("66:6f:6f:62:61:72");
std::string expected = "foobar";
EXPECT_EQ(result, std::vector<std::uint8_t>(expected.begin(), expected.end()));
}
TEST(StringTests, fromhex_binary_string)
{
auto result = string::from_hex("01020304050600fff9");
@@ -76,6 +83,13 @@ TEST(StringTests, fromhex_binary_string)
EXPECT_EQ(result, expected);
}
TEST(StringTests, fromhex_invalid_string)
{
EXPECT_TRUE(string::from_hex("66:6").empty());
EXPECT_TRUE(string::from_hex("66:612").empty());
EXPECT_TRUE(string::from_hex("66:WW").empty());
}
TEST(StringTests, uppercase_lowercaseInput_uppercaseOutput)
{
String subject = "12foo3BaR";