diff options
author | Duncan Overbruck <github@duncano.de> | 2023-08-24 20:39:33 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-08-24 20:39:33 +0200 |
commit | 6aea1e0d440708a970c8294978b57ee27097bfc5 (patch) | |
tree | 56c42e7c231a28d3c46253d240fa9b8b8c1e07c8 | |
parent | Update ErrNoMultipartForm (diff) | |
download | fasthttp-6aea1e0d440708a970c8294978b57ee27097bfc5.tar.gz fasthttp-6aea1e0d440708a970c8294978b57ee27097bfc5.tar.bz2 fasthttp-6aea1e0d440708a970c8294978b57ee27097bfc5.zip |
fix round2_32, split round2 tests because they depend on sizeof int at compile time (#1607)
-rw-r--r-- | http_test.go | 30 | ||||
-rw-r--r-- | round2_32.go | 2 | ||||
-rw-r--r-- | round2_32_test.go | 32 | ||||
-rw-r--r-- | round2_64_test.go | 33 |
4 files changed, 67 insertions, 30 deletions
diff --git a/http_test.go b/http_test.go index 370e9aa..37b8ce1 100644 --- a/http_test.go +++ b/http_test.go @@ -7,7 +7,6 @@ import ( "errors" "fmt" "io" - "math" "mime/multipart" "net/http" "net/http/httptest" @@ -16,7 +15,6 @@ import ( "strings" "testing" "time" - "unsafe" "github.com/valyala/bytebufferpool" ) @@ -1968,34 +1966,6 @@ func testSetResponseBodyStreamChunked(t *testing.T, body string, trailer map[str } } -func TestRound2ForSliceCap(t *testing.T) { - t.Parallel() - - testRound2ForSliceCap(t, 0, 0) - testRound2ForSliceCap(t, 1, 1) - testRound2ForSliceCap(t, 2, 2) - testRound2ForSliceCap(t, 3, 4) - testRound2ForSliceCap(t, 4, 4) - testRound2ForSliceCap(t, 5, 8) - testRound2ForSliceCap(t, 7, 8) - testRound2ForSliceCap(t, 8, 8) - testRound2ForSliceCap(t, 9, 16) - testRound2ForSliceCap(t, 0x10001, 0x20000) - - if unsafe.Sizeof(int(0)) == 4 { - testRound2ForSliceCap(t, math.MaxInt32-1, math.MaxInt32) - } else { - testRound2ForSliceCap(t, math.MaxInt32, math.MaxInt32) - testRound2ForSliceCap(t, math.MaxInt64-1, math.MaxInt64-1) - } -} - -func testRound2ForSliceCap(t *testing.T, n, expectedRound2 int) { - if roundUpForSliceCap(n) != expectedRound2 { - t.Fatalf("Unexpected round2(%d)=%d. Expected %d", n, roundUpForSliceCap(n), expectedRound2) - } -} - func TestRequestReadChunked(t *testing.T) { t.Parallel() diff --git a/round2_32.go b/round2_32.go index 541b85e..2990e42 100644 --- a/round2_32.go +++ b/round2_32.go @@ -3,6 +3,8 @@ package fasthttp +import "math" + func roundUpForSliceCap(n int) int { if n <= 0 { return 0 diff --git a/round2_32_test.go b/round2_32_test.go new file mode 100644 index 0000000..1bb2c0d --- /dev/null +++ b/round2_32_test.go @@ -0,0 +1,32 @@ +//go:build !amd64 && !arm64 && !ppc64 && !ppc64le && !s390x +// +build !amd64,!arm64,!ppc64,!ppc64le,!s390x + +package fasthttp + +import ( + "math" + "testing" +) + +func TestRound2ForSliceCap(t *testing.T) { + t.Parallel() + + testRound2ForSliceCap(t, 0, 0) + testRound2ForSliceCap(t, 1, 1) + testRound2ForSliceCap(t, 2, 2) + testRound2ForSliceCap(t, 3, 4) + testRound2ForSliceCap(t, 4, 4) + testRound2ForSliceCap(t, 5, 8) + testRound2ForSliceCap(t, 7, 8) + testRound2ForSliceCap(t, 8, 8) + testRound2ForSliceCap(t, 9, 16) + testRound2ForSliceCap(t, 0x10001, 0x20000) + + testRound2ForSliceCap(t, math.MaxInt32-1, math.MaxInt32-1) +} + +func testRound2ForSliceCap(t *testing.T, n, expectedRound2 int) { + if roundUpForSliceCap(n) != expectedRound2 { + t.Fatalf("Unexpected round2(%d)=%d. Expected %d", n, roundUpForSliceCap(n), expectedRound2) + } +} diff --git a/round2_64_test.go b/round2_64_test.go new file mode 100644 index 0000000..d805802 --- /dev/null +++ b/round2_64_test.go @@ -0,0 +1,33 @@ +//go:build amd64 || arm64 || ppc64 || ppc64le || s390x +// +build amd64 arm64 ppc64 ppc64le s390x + +package fasthttp + +import ( + "math" + "testing" +) + +func TestRound2ForSliceCap(t *testing.T) { + t.Parallel() + + testRound2ForSliceCap(t, 0, 0) + testRound2ForSliceCap(t, 1, 1) + testRound2ForSliceCap(t, 2, 2) + testRound2ForSliceCap(t, 3, 4) + testRound2ForSliceCap(t, 4, 4) + testRound2ForSliceCap(t, 5, 8) + testRound2ForSliceCap(t, 7, 8) + testRound2ForSliceCap(t, 8, 8) + testRound2ForSliceCap(t, 9, 16) + testRound2ForSliceCap(t, 0x10001, 0x20000) + + testRound2ForSliceCap(t, math.MaxInt32, math.MaxInt32) + testRound2ForSliceCap(t, math.MaxInt64-1, math.MaxInt64-1) +} + +func testRound2ForSliceCap(t *testing.T, n, expectedRound2 int) { + if roundUpForSliceCap(n) != expectedRound2 { + t.Fatalf("Unexpected round2(%d)=%d. Expected %d", n, roundUpForSliceCap(n), expectedRound2) + } +} |