Commit e8cf7bd8 authored by Francesco Banconi's avatar Francesco Banconi

Add tests for Format. Also exercise time.Time values

parent 57a7bb22
......@@ -8,6 +8,7 @@ import (
"fmt"
"strings"
"testing"
"time"
"github.com/google/go-cmp/cmp"
"github.com/google/go-cmp/cmp/cmpopts"
......@@ -15,7 +16,10 @@ import (
qt "github.com/frankban/quicktest"
)
var errBadWolf = errors.New("bad wolf")
var (
errBadWolf = errors.New("bad wolf")
goTime = time.Date(2012, 3, 28, 0, 0, 0, 0, time.UTC)
)
var (
sameInts = cmpopts.SortSlices(func(x, y int) bool {
......@@ -377,6 +381,38 @@ got:
want:
[]int{3, 2, 1}
`, prefixf(cmp.Diff([]int{1, 2, 3}, []int{3, 2, 1}))),
}, {
about: "DeepEquals: same times",
checker: qt.DeepEquals,
got: goTime,
args: []interface{}{
goTime,
},
expectedNegateFailure: `
error:
unexpected success
got:
s"2012-03-28 00:00:00 +0000 UTC"
want:
<same as "got">
`,
}, {
about: "DeepEquals: different times",
checker: qt.DeepEquals,
got: goTime.Add(24 * time.Hour),
args: []interface{}{
goTime,
},
expectedCheckFailure: fmt.Sprintf(`
error:
values are not deep equal
diff (-got +want):
%s
got:
s"2012-03-29 00:00:00 +0000 UTC"
want:
s"2012-03-28 00:00:00 +0000 UTC"
`, prefixf(cmp.Diff(goTime.Add(24*time.Hour), goTime))),
}, {
about: "DeepEquals: not enough arguments",
checker: qt.DeepEquals,
......
// Licensed under the MIT license, see LICENCE file for details.
package quicktest_test
import (
"bytes"
"fmt"
"testing"
qt "github.com/frankban/quicktest"
)
var formatTests = []struct {
about string
value interface{}
want string
}{{
about: "error value",
value: errBadWolf,
want: fmt.Sprintf("%+v", errBadWolf),
}, {
about: "stringer",
value: bytes.NewBufferString("I am a stringer"),
want: `s"I am a stringer"`,
}, {
about: "string",
value: "these are the voyages",
want: `"these are the voyages"`,
}, {
about: "slice",
value: []int{1, 2, 3},
want: "[]int{1, 2, 3}",
}, {
about: "time",
value: goTime,
want: `s"2012-03-28 00:00:00 +0000 UTC"`,
}}
func TestFormat(t *testing.T) {
for _, test := range formatTests {
t.Run(test.about, func(t *testing.T) {
got := qt.Format(test.value)
if got != test.want {
t.Fatalf("format:\ngot %q\nwant %q", got, test.want)
}
})
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment