1
0
Fork 0

Adding upstream version 2.6.3.

Signed-off-by: Daniel Baumann <daniel@debian.org>
This commit is contained in:
Daniel Baumann 2025-05-18 22:58:26 +02:00
parent 4d8cd0ce4c
commit 2b08a89310
Signed by: daniel
GPG key ID: FBB4F0E80A80222F
39 changed files with 2140 additions and 0 deletions

22
internal/assert/assert.go Normal file
View file

@ -0,0 +1,22 @@
package assert
import (
"testing"
"github.com/google/go-cmp/cmp"
)
func Equal(t *testing.T, x, y interface{}) {
t.Helper()
r := DiffReporter{}
if !cmp.Equal(x, y, cmp.Reporter(&r)) {
t.Error(r.String())
}
}
func Nil(t *testing.T, x interface{}) {
t.Helper()
Equal(t, x, nil)
}

View file

@ -0,0 +1,36 @@
// this code is from the examples
// https://pkg.go.dev/github.com/google/go-cmp/cmp?tab=doc#Reporter
package assert
import (
"fmt"
"strings"
"github.com/google/go-cmp/cmp"
)
// DiffReporter is a simple custom reporter that only records differences
// detected during comparison.
type DiffReporter struct {
path cmp.Path
diffs []string
}
func (r *DiffReporter) PushStep(ps cmp.PathStep) {
r.path = append(r.path, ps)
}
func (r *DiffReporter) Report(rs cmp.Result) {
if !rs.Equal() {
vx, vy := r.path.Last().Values()
r.diffs = append(r.diffs, fmt.Sprintf("%#v:\n\t-: %+v\n\t+: %+v\n", r.path, vx, vy))
}
}
func (r *DiffReporter) PopStep() {
r.path = r.path[:len(r.path)-1]
}
func (r *DiffReporter) String() string {
return strings.Join(r.diffs, "\n")
}