Skip to content

Commit 6549f8b

Browse files
committed
Fix bigint tests for the no-int128 build
The fallback uint128 aggregate has no constructor from integers, so constructing it directly from int/uint64_t literals broke the zmij-no-int128-test build. Route construction through a make_bigint helper that handles both the native __int128 and the fallback type.
1 parent bdf3a3b commit 6549f8b

1 file changed

Lines changed: 16 additions & 7 deletions

File tree

test/zmij-impl-test.cc

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -695,6 +695,16 @@ TEST(zmij_impl_test, utilities) {
695695
EXPECT_EQ(count_trailing_nonzeros(0x09000000'00000000ull), 8);
696696
}
697697

698+
// Builds a bigint from a 64-bit value; handles both the native __int128 and
699+
// the fallback uint128 aggregate (which has no integer constructor).
700+
static auto make_bigint(uint64_t value) -> bigint {
701+
#if ZMIJ_USE_INT128
702+
return bigint(uint128_t(value));
703+
#else
704+
return bigint(uint128_t{0, value});
705+
#endif
706+
}
707+
698708
static auto to_string(bigint n) -> std::string {
699709
std::string s;
700710
while (n.size != 0) {
@@ -708,23 +718,22 @@ static auto to_string(bigint n) -> std::string {
708718

709719
TEST(zmij_impl_test, bigint) {
710720
// Construction from a 128-bit value and base-10**9 output.
711-
EXPECT_EQ(to_string(bigint(uint128_t(0))), "0");
712-
EXPECT_EQ(to_string(bigint(uint128_t(123456789))), "123456789");
713-
EXPECT_EQ(to_string(bigint(uint128_t(1000000000000000000ull))),
721+
EXPECT_EQ(to_string(make_bigint(0)), "0");
722+
EXPECT_EQ(to_string(make_bigint(123456789)), "123456789");
723+
EXPECT_EQ(to_string(make_bigint(1000000000000000000ull)),
714724
"1000000000000000000");
715725

716726
// shift_left multiplies by 2**bits (word-aligned and unaligned).
717-
bigint a(uint128_t(1));
727+
bigint a = make_bigint(1);
718728
a.shift_left(64);
719729
EXPECT_EQ(to_string(a), "18446744073709551616");
720-
bigint b(uint128_t(1));
730+
bigint b = make_bigint(1);
721731
b.shift_left(80);
722732
EXPECT_EQ(to_string(b), "1208925819614629174706176");
723733

724734
// shift_right_round divides by 2**bits, rounding ties to even.
725735
auto rshift = [](uint64_t value, int bits) {
726-
uint128_t scaled = value;
727-
bigint n(scaled);
736+
bigint n = make_bigint(value);
728737
n.shift_right_round(bits);
729738
return to_string(n);
730739
};

0 commit comments

Comments
 (0)