Debian Codegraph @

td/t_anchor_127_test.go

raw
1 // Copyright (c) 2026, Maxime Soulé
2 // All rights reserved.
3 //
4 // This source code is licensed under the BSD-style license found in the
5 // LICENSE file in the root directory of this source tree.
6
7 //go:build go1.27
8 // +build go1.27
9
10 package td_test
11
12 import (
13 "testing"
14 "time"
15
16 "github.com/maxatome/go-testdeep/internal/test"
17 "github.com/maxatome/go-testdeep/td"
18 )
19
20 func TestT_AnchorT(tt *testing.T) {
21 ttt := test.NewTestingTB(tt.Name())
22 t := td.NewT(ttt)
23 type MyStruct struct {
24 PNum *int
25 Num int64
26 Str string
27 Slice []int
28 Map map[string]bool
29 Time time.Time
30 }
31 n := 42
32 got := MyStruct{
33 PNum: &n,
34 Num: 136,
35 Str: "Pipo bingo",
36 Time: timeParse(tt, "2019-01-02T11:22:33.123456Z"),
37 }
38
39 td.CmpTrue(tt,
40 t.Cmp(got, MyStruct{
41 PNum: t.AnchorT[*int](td.Ptr(td.Between(40, 45))),
42 Num: t.AnchorT[int64](td.Between(int64(135), int64(137))),
43 Str: t.AnchorT[string](td.HasPrefix("Pipo")),
44 Time: t.AnchorT[time.Time](td.TruncTime(timeParse(tt, "2019-01-02T11:22:00Z"), time.Minute)),
45 }))
46
47 td.CmpTrue(tt,
48 t.Cmp(got, MyStruct{
49 PNum: t.AT[*int](td.Ptr(td.Between(40, 45))),
50 Num: t.AT[int64](td.Between(int64(135), int64(137))),
51 Str: t.AT[string](td.HasPrefix("Pipo")),
52 Time: t.AT[time.Time](td.TruncTime(timeParse(tt, "2019-01-02T11:22:00Z"), time.Minute)),
53 }))
54 }