Skip to content

Commit eff455a

Browse files
committed
test: Add golden fmt file for safe_integer_conversion
Adds the `safe_integer_conversion.jsonnet.fmt.golden` file containing the expected output from `jsonnetfmt`. This resolves the formatting test failure for this file in `run_fmt_tests.sh` by providing an explicit golden output for comparison, accounting for minor spacing differences introduced by the formatter. Signed-off-by: Ville Vesilehto <[email protected]>
1 parent 499b0db commit eff455a

File tree

1 file changed

+44
-0
lines changed

1 file changed

+44
-0
lines changed
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
// Test values at boundary of safe integer range
2+
local max_safe = 9007199254740992; // 2^53
3+
local min_safe = -9007199254740992; // -2^53
4+
5+
std.assertEqual(max_safe & 1, 0) && // Check 2^53
6+
std.assertEqual(min_safe & 1, 0) && // Check -2^53
7+
std.assertEqual((max_safe - 1) & 1, 1) && // Check 2^53 - 1
8+
std.assertEqual((min_safe + 1) & 1, 1) && // Check -2^53 + 1
9+
10+
std.assertEqual(~(max_safe - 1), min_safe) && // ~(2^53 - 1) == -2^53
11+
std.assertEqual(~(min_safe + 1), max_safe - 2) && // ~(-2^53 + 1) == 2^53 - 2
12+
13+
// Test basic values
14+
std.assertEqual(~0, -1) &&
15+
std.assertEqual(~1, -2) &&
16+
std.assertEqual(~(-1), 0) &&
17+
18+
// Test shift operations with large values at safe boundary
19+
// (2^53 - 1) right shift by 4 bits
20+
std.assertEqual((max_safe - 1) >> 4, 562949953421311) &&
21+
// MAX_SAFE_INTEGER (2^53) right shift by 1 bit
22+
std.assertEqual(max_safe >> 1, 4503599627370496) && // 2^52
23+
// MIN_SAFE_INTEGER (-2^53) right shift by 1 bit
24+
std.assertEqual(min_safe >> 1, -4503599627370496) && // -2^52
25+
26+
// Cannot left shift 2^53 without potential overflow/loss of precision issues
27+
// depending on the shift amount, but can shift smaller numbers up to it.
28+
// (2^52) left shift by 1 bit (result is 2^53)
29+
std.assertEqual((max_safe >> 1) << 1, max_safe) &&
30+
// (-2^52) left shift by 1 bit (result is -2^53)
31+
std.assertEqual((min_safe >> 1) << 1, min_safe) &&
32+
33+
// Test larger values within safe range
34+
std.assertEqual(~123456789, -123456790) &&
35+
std.assertEqual(~(-987654321), 987654320) &&
36+
37+
// Test other bitwise operations
38+
std.assertEqual(123 & 456, 72) &&
39+
std.assertEqual(123 | 456, 507) &&
40+
std.assertEqual(123 ^ 456, 435) &&
41+
std.assertEqual(123 << 2, 492) &&
42+
std.assertEqual(123 >> 2, 30) &&
43+
44+
true

0 commit comments

Comments
 (0)