not->toBeEmpty(); }); $assemble = function (string $expr) { // eval() here only wraps a line regex-extracted from this repo's own // scripts/ss_nimble_alletra_volumes.php (not external/user input) into a // throwaway named function, matching the existing extract-and-eval // pattern used in Issue7070PercentileContractTest.php. Test-only. // Each call gets a unique function name since PHP cannot redeclare // a named function within the same process. $name = 'nimble_assemble_long_' . str_replace('.', '_', uniqid('', true)); eval("function $name(\$high, \$key, \$value) { $expr return \$long; }"); return $name; }; test('64-bit value assembles the high word followed by the low word', function () use ($matches, $assemble) { $fn = $assemble($matches[0]); $high = ['1' => str_pad(decbin(1), 32, '0', STR_PAD_LEFT)]; $low = str_pad(decbin(500), 32, '0', STR_PAD_LEFT); $long = $fn($high, '1', $low); // Correct: (1 << 32) + 500 expect(bindec($long))->toEqual(4294967796); // The pre-fix expression dropped the low word whenever a high word // existed, collapsing the result down to just the high bits (1). expect(bindec($long))->not->toEqual(1); }); test('falls back to the low word alone when no high word exists for the key', function () use ($matches, $assemble) { $fn = $assemble($matches[0]); $low = str_pad(decbin(500), 32, '0', STR_PAD_LEFT); $long = $fn([], '1', $low); expect(bindec($long))->toEqual(500); });