1
1
Fork 0
mirror of https://github.com/NixOS/nix.git synced 2025-12-20 16:01:07 +01:00

libutil: Add alignUp helper function

This commit is contained in:
Sergei Zimmerman 2025-10-20 21:08:49 +03:00
parent ddf7de0a76
commit a91b787524
No known key found for this signature in database
4 changed files with 43 additions and 0 deletions

View file

@ -0,0 +1,18 @@
#include "nix/util/alignment.hh"
#include <gtest/gtest.h>
namespace nix {
TEST(alignUp, value)
{
for (uint64_t i = 1; i <= 8; ++i)
EXPECT_EQ(alignUp(i, 8), 8);
}
TEST(alignUp, notAPowerOf2)
{
ASSERT_DEATH({ alignUp(1u, 42); }, "alignment must be a power of 2");
}
} // namespace nix