From f06a8b0866fe25c557058b99b8ea754cfbe23e8d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20Budai?= Date: Wed, 26 Aug 2020 15:13:20 +0200 Subject: [PATCH] do not rely on undefined behaviour in bytes_test.go 8 exbi equals 2^64, therefore it cannot be stored in int64. The tests use the fact that on x86_64 the following expressions holds true: int64(0) - 1 == math.MaxInt64. However, this is not true for other platforms, specifically aarch64, s390x and ppc64le. This commit fixes it by testing the library with 7 exbi. Fixes #37 --- bytes/bytes_test.go | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/bytes/bytes_test.go b/bytes/bytes_test.go index 279275c..ee5e4c8 100644 --- a/bytes/bytes_test.go +++ b/bytes/bytes_test.go @@ -120,7 +120,6 @@ func TestBytesParse(t *testing.T) { assert.Equal(t, int64(12288), b) } - // KB with space b, err = Parse("12.25 KB") if assert.NoError(t, err) { @@ -206,22 +205,22 @@ func TestBytesParse(t *testing.T) { } // EB - b, err = Parse("8EB") + b, err = Parse("7EB") if assert.NoError(t, err) { - assert.True(t, math.MaxInt64 == b-1) + assert.Equal(t, 7*int64(1152921504606846976), b) } - b, err = Parse("8E") + b, err = Parse("7E") if assert.NoError(t, err) { - assert.True(t, math.MaxInt64 == b-1) + assert.Equal(t, 7*int64(1152921504606846976), b) } // EB with spaces - b, err = Parse("8 EB") + b, err = Parse("7 EB") if assert.NoError(t, err) { - assert.True(t, math.MaxInt64 == b-1) + assert.Equal(t, 7*int64(1152921504606846976), b) } - b, err = Parse("8 E") + b, err = Parse("7 E") if assert.NoError(t, err) { - assert.True(t, math.MaxInt64 == b-1) + assert.Equal(t, 7*int64(1152921504606846976), b) } }