tst.go 847 Б
Newer Older
keewek's avatar
keewek включено в состав коммита
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
// SPDX-FileCopyrightText: 2023 Alexander Bugrov <abugrov+dev@gmail.com>
//
// SPDX-License-Identifier: MIT

package tst

import (
	"fmt"
	"testing"

	"github.com/google/go-cmp/cmp"
)

// ReprValue returns a Go-syntax representation of the value
//
// Equivalent to fmt.Sprintf("%#v", value)
func ReprValue(value any) string {
	return fmt.Sprintf("%#v", value)
}

// ReprType returns a Go-syntax representation of the type of the value
//
// Equivalent to fmt.Sprintf("%T, value)
func ReprType(value any) string {
	return fmt.Sprintf("%T", value)
}

func DiffError(t *testing.T, want, got any) {
	if diff := cmp.Diff(want, got); diff != "" {
		t.Errorf("(-want +got): \n%s", diff)
	}
}

func DiffErrorBefore(t *testing.T, want, got any, fn func()) {
	if diff := cmp.Diff(want, got); diff != "" {
		fn()
		t.Errorf("(-want +got): \n%s", diff)
	}
}