From a92690cdc3d71f69b60bc18d1bac104609a40b2d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89mile=20R=C3=A9?= Date: Sat, 2 May 2026 19:48:30 +0400 Subject: [PATCH] Remove unused pkg/equal package MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Émile Ré --- pkg/equal/equal.go | 48 ------------- pkg/equal/equal_test.go | 147 ---------------------------------------- 2 files changed, 195 deletions(-) delete mode 100644 pkg/equal/equal.go delete mode 100644 pkg/equal/equal_test.go diff --git a/pkg/equal/equal.go b/pkg/equal/equal.go deleted file mode 100644 index f12f4fd86..000000000 --- a/pkg/equal/equal.go +++ /dev/null @@ -1,48 +0,0 @@ -// Copyright (c) 2026 Probo Inc . -// -// Permission to use, copy, modify, and/or distribute this software for any -// purpose with or without fee is hereby granted, provided that the above -// copyright notice and this permission notice appear in all copies. -// -// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH -// REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY -// AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, -// INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM -// LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR -// OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR -// PERFORMANCE OF THIS SOFTWARE. - -// Package equal contains small helpers for value equality across the -// codebase, with no business semantics. -package equal - -import ( - "encoding/json" - "fmt" - "reflect" -) - -// Ptr reports whether two nullable values are equal: both nil are equal, -// one nil is not equal to a non-nil, otherwise the pointed-to values are -// compared with ==. -func Ptr[T comparable](a, b *T) bool { - if a == nil || b == nil { - return a == b - } - return *a == *b -} - -// JSON reports whether two JSON blobs are semantically identical after -// normalising whitespace and (top-level and nested) object key ordering. -// Array element order is preserved as significant. Numbers are compared -// after JSON unmarshalling, so 1 and 1.0 compare equal. -func JSON(a, b json.RawMessage) (bool, error) { - var av, bv any - if err := json.Unmarshal(a, &av); err != nil { - return false, fmt.Errorf("cannot unmarshal first json blob: %w", err) - } - if err := json.Unmarshal(b, &bv); err != nil { - return false, fmt.Errorf("cannot unmarshal second json blob: %w", err) - } - return reflect.DeepEqual(av, bv), nil -} diff --git a/pkg/equal/equal_test.go b/pkg/equal/equal_test.go deleted file mode 100644 index ad98ceab3..000000000 --- a/pkg/equal/equal_test.go +++ /dev/null @@ -1,147 +0,0 @@ -// Copyright (c) 2026 Probo Inc . -// -// Permission to use, copy, modify, and/or distribute this software for any -// purpose with or without fee is hereby granted, provided that the above -// copyright notice and this permission notice appear in all copies. -// -// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH -// REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY -// AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, -// INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM -// LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR -// OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR -// PERFORMANCE OF THIS SOFTWARE. - -package equal_test - -import ( - "encoding/json" - "testing" - - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" - "go.probo.inc/probo/pkg/equal" -) - -func TestPtr_String(t *testing.T) { - t.Parallel() - - a := "hello" - b := "hello" - c := "world" - - assert.True(t, equal.Ptr[string](nil, nil)) - assert.False(t, equal.Ptr(&a, nil)) - assert.False(t, equal.Ptr[string](nil, &a)) - assert.True(t, equal.Ptr(&a, &b)) - assert.False(t, equal.Ptr(&a, &c)) -} - -func TestPtr_Int(t *testing.T) { - t.Parallel() - - a := 42 - b := 42 - c := 99 - - assert.True(t, equal.Ptr[int](nil, nil)) - assert.False(t, equal.Ptr(&a, nil)) - assert.False(t, equal.Ptr[int](nil, &a)) - assert.True(t, equal.Ptr(&a, &b)) - assert.False(t, equal.Ptr(&a, &c)) -} - -func TestPtr_Bool(t *testing.T) { - t.Parallel() - - tt := true - tt2 := true - ff := false - - assert.True(t, equal.Ptr(&tt, &tt2)) - assert.False(t, equal.Ptr(&tt, &ff)) -} - -func TestJSON(t *testing.T) { - t.Parallel() - - t.Run("identical bytes", func(t *testing.T) { - t.Parallel() - - a := json.RawMessage(`{"foo":"bar","n":1}`) - b := json.RawMessage(`{"foo":"bar","n":1}`) - - eq, err := equal.JSON(a, b) - require.NoError(t, err) - assert.True(t, eq) - }) - - t.Run("whitespace and key order differences", func(t *testing.T) { - t.Parallel() - - a := json.RawMessage(`{"foo":"bar","n":1}`) - b := json.RawMessage("{\n \"n\": 1,\n \"foo\": \"bar\"\n}") - - eq, err := equal.JSON(a, b) - require.NoError(t, err) - assert.True(t, eq) - }) - - t.Run("nested objects with reordered keys", func(t *testing.T) { - t.Parallel() - - a := json.RawMessage(`{"a":{"x":1,"y":2},"b":[1,2,3]}`) - b := json.RawMessage(`{"b":[1,2,3],"a":{"y":2,"x":1}}`) - - eq, err := equal.JSON(a, b) - require.NoError(t, err) - assert.True(t, eq) - }) - - t.Run("array order matters", func(t *testing.T) { - t.Parallel() - - a := json.RawMessage(`{"items":[1,2,3]}`) - b := json.RawMessage(`{"items":[3,2,1]}`) - - eq, err := equal.JSON(a, b) - require.NoError(t, err) - assert.False(t, eq) - }) - - t.Run("real content change", func(t *testing.T) { - t.Parallel() - - a := json.RawMessage(`{"title":"Cookies"}`) - b := json.RawMessage(`{"title":"Cookies updated"}`) - - eq, err := equal.JSON(a, b) - require.NoError(t, err) - assert.False(t, eq) - }) - - t.Run("integers and floats compare equal", func(t *testing.T) { - t.Parallel() - - a := json.RawMessage(`{"n":1}`) - b := json.RawMessage(`{"n":1.0}`) - - eq, err := equal.JSON(a, b) - require.NoError(t, err) - assert.True(t, eq, "json.Unmarshal yields float64 for both") - }) - - t.Run("invalid first blob returns error", func(t *testing.T) { - t.Parallel() - - _, err := equal.JSON(json.RawMessage(`not json`), json.RawMessage(`{}`)) - assert.Error(t, err) - }) - - t.Run("invalid second blob returns error", func(t *testing.T) { - t.Parallel() - - _, err := equal.JSON(json.RawMessage(`{}`), json.RawMessage(`not json`)) - assert.Error(t, err) - }) -}