Skip to content

Commit d468f46

Browse files
vishrclaude
andcommitted
fix(bytes): use 7EiB instead of 8EiB in tests — 2^63 overflow is non-portable
Parse("8EiB") computes 2^63, which exceeds MaxInt64. The float-to-int conversion of out-of-range values is implementation-dependent per the Go spec, so the prior assertion `math.MaxInt64 == b-1` (relying on two's-complement wrap) only held on some toolchains. 7EiB fits within int64 and tests EiB parsing without depending on undefined behaviour. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 309ee6e commit d468f46

1 file changed

Lines changed: 11 additions & 9 deletions

File tree

bytes/bytes_test.go

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -246,24 +246,26 @@ func TestBytesParse(t *testing.T) {
246246
assert.Equal(t, int64(10133099161583616), b)
247247
}
248248

249-
// EiB
250-
b, err = Parse("8EiB")
249+
// EiB — 7EiB stays within int64; 8EiB == 2^63 overflows and the
250+
// float-to-int conversion of out-of-range values is
251+
// implementation-dependent per the Go spec.
252+
b, err = Parse("7EiB")
251253
if assert.NoError(t, err) {
252-
assert.True(t, math.MaxInt64 == b-1)
254+
assert.Equal(t, int64(8070450532247928832), b)
253255
}
254-
b, err = Parse("8Ei")
256+
b, err = Parse("7Ei")
255257
if assert.NoError(t, err) {
256-
assert.True(t, math.MaxInt64 == b-1)
258+
assert.Equal(t, int64(8070450532247928832), b)
257259
}
258260

259261
// EiB with spaces
260-
b, err = Parse("8 EiB")
262+
b, err = Parse("7 EiB")
261263
if assert.NoError(t, err) {
262-
assert.True(t, math.MaxInt64 == b-1)
264+
assert.Equal(t, int64(8070450532247928832), b)
263265
}
264-
b, err = Parse("8 Ei")
266+
b, err = Parse("7 Ei")
265267
if assert.NoError(t, err) {
266-
assert.True(t, math.MaxInt64 == b-1)
268+
assert.Equal(t, int64(8070450532247928832), b)
267269
}
268270

269271
// KB

0 commit comments

Comments
 (0)