renderSize(): Add some unit tests

This commit is contained in:
Eelco Dolstra 2024-05-13 12:08:45 +02:00
parent cf3b044b7e
commit f0b5628eb2

View File

@ -421,6 +421,23 @@ namespace nix {
ASSERT_EQ(string2Int<int>("-100"), -100);
}
/* ----------------------------------------------------------------------------
* renderSize
* --------------------------------------------------------------------------*/
TEST(renderSize, misc) {
ASSERT_EQ(renderSize(0, true), " 0.0 KiB");
ASSERT_EQ(renderSize(100, true), " 0.1 KiB");
ASSERT_EQ(renderSize(100), "0.1 KiB");
ASSERT_EQ(renderSize(972, true), " 0.9 KiB");
ASSERT_EQ(renderSize(973, true), " 1.0 KiB"); // FIXME: should round down
ASSERT_EQ(renderSize(1024, true), " 1.0 KiB");
ASSERT_EQ(renderSize(1024 * 1024, true), "1024.0 KiB");
ASSERT_EQ(renderSize(1100 * 1024, true), " 1.1 MiB");
ASSERT_EQ(renderSize(2ULL * 1024 * 1024 * 1024, true), " 2.0 GiB");
ASSERT_EQ(renderSize(2100ULL * 1024 * 1024 * 1024, true), " 2.1 TiB");
}
#ifndef _WIN32 // TODO re-enable on Windows, once we can start processes
/* ----------------------------------------------------------------------------
* statusOk