Add bytes to string function

This commit is contained in:
Dan Paulat 2024-03-21 22:21:03 -05:00
parent 8d706c463c
commit 94726631cb
3 changed files with 103 additions and 0 deletions

View file

@ -7,6 +7,35 @@ namespace scwx
namespace util
{
class BytesToStringTest :
public testing::TestWithParam<std::pair<std::ptrdiff_t, std::string>>
{
};
TEST_P(BytesToStringTest, BytesToString)
{
auto& [bytes, expected] = GetParam();
std::string s = BytesToString(bytes);
EXPECT_EQ(s, expected);
}
INSTANTIATE_TEST_SUITE_P(StringsTest,
BytesToStringTest,
testing::Values(std::make_pair(123, "123 bytes"),
std::make_pair(1000, "0.98 KB"),
std::make_pair(1018, "0.99 KB"),
std::make_pair(1024, "1.0 KB"),
std::make_pair(1127, "1.1 KB"),
std::make_pair(1260, "1.23 KB"),
std::make_pair(24012, "23.4 KB"),
std::make_pair(353974, "346 KB"),
std::make_pair(1024000, "0.98 MB"),
std::make_pair(1048576000, "0.98 GB"),
std::make_pair(1073741824000,
"0.98 TB")));
TEST(StringsTest, ParseTokensColor)
{
static const std::string line {"Color: red green blue alpha discarded"};