refactor: use slices.Equal to simplify code (#7141)

Signed-off-by: minxinyi <minxinyi6@outlook.com>
This commit is contained in:
minxinyi 2025-07-23 22:07:46 +08:00 committed by GitHub
parent 6de2c9e135
commit ab3b2d64ba
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -2,6 +2,7 @@ package encode
import ( import (
"net/http" "net/http"
"slices"
"sync" "sync"
"testing" "testing"
) )
@ -112,7 +113,7 @@ func TestPreferOrder(t *testing.T) {
} }
enc.Prefer = test.prefer enc.Prefer = test.prefer
result := AcceptedEncodings(r, enc.Prefer) result := AcceptedEncodings(r, enc.Prefer)
if !sliceEqual(result, test.expected) { if !slices.Equal(result, test.expected) {
t.Errorf("AcceptedEncodings() actual: %s expected: %s", t.Errorf("AcceptedEncodings() actual: %s expected: %s",
result, result,
test.expected) test.expected)
@ -121,17 +122,6 @@ func TestPreferOrder(t *testing.T) {
} }
} }
func sliceEqual(a, b []string) bool {
if len(a) != len(b) {
return false
}
for i := range a {
if a[i] != b[i] {
return false
}
}
return true
}
func TestValidate(t *testing.T) { func TestValidate(t *testing.T) {
type testCase struct { type testCase struct {