Adding upstream version 2.6.3.
Signed-off-by: Daniel Baumann <daniel@debian.org>
This commit is contained in:
parent
4d8cd0ce4c
commit
2b08a89310
39 changed files with 2140 additions and 0 deletions
22
internal/assert/assert.go
Normal file
22
internal/assert/assert.go
Normal 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)
|
||||
}
|
36
internal/assert/diff_reporter.go
Normal file
36
internal/assert/diff_reporter.go
Normal 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")
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue