Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions td/t_anchor_118.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
// This source code is licensed under the BSD-style license found in the
// LICENSE file in the root directory of this source tree.

//go:build go1.18
// +build go1.18
//go:build go1.18 && !go1.27
// +build go1.18,!go1.27

package td

Expand Down
4 changes: 2 additions & 2 deletions td/t_anchor_118_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
// This source code is licensed under the BSD-style license found in the
// LICENSE file in the root directory of this source tree.

//go:build go1.18
// +build go1.18
//go:build go1.18 && !go1.27
// +build go1.18,!go1.27

package td_test

Expand Down
24 changes: 22 additions & 2 deletions td/t_anchor_127.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,8 @@ package td
// [T.ResetAnchors], [T.SetAnchorsPersist] and [AddAnchorableStructType].
func (t *T) AnchorT[X any](operator TestDeep) X {
t.Helper()
return Anchor[X](t, operator)
var model X
return t.Anchor(operator, model).(X)
}

// AT returns a typed value allowing to anchor the TestDeep
Expand Down Expand Up @@ -142,5 +143,24 @@ func (t *T) AnchorT[X any](operator TestDeep) X {
// [T.ResetAnchors], [T.SetAnchorsPersist] and [AddAnchorableStructType].
func (t *T) AT[X any](operator TestDeep) X {
t.Helper()
return A[X](t, operator)
var model X
return t.A(operator, model).(X)
}

// Anchor is a generic shortcut to [T.Anchor].
//
// See also [T.AnchorT] method for a generic variant (go1.27 required).
//
//go:fix inline
func Anchor[X any](t *T, operator TestDeep) X {
return t.AnchorT[X](operator)
}

// A is a generic shortcut to [T.A].
//
// See also [T.AT] method for a generic variant (go1.27 required).
//
//go:fix inline
func A[X any](t *T, operator TestDeep) X {
return t.AT[X](operator)
}
17 changes: 17 additions & 0 deletions td/t_anchor_127_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,21 @@ func TestT_AnchorT(tt *testing.T) {
Str: t.AT[string](td.HasPrefix("Pipo")),
Time: t.AT[time.Time](td.TruncTime(timeParse(tt, "2019-01-02T11:22:00Z"), time.Minute)),
}))

// Pre go1.27 versions
td.CmpTrue(tt,
t.Cmp(got, MyStruct{
PNum: td.Anchor[*int](t, td.Ptr(td.Between(40, 45))),
Num: td.Anchor[int64](t, td.Between(int64(135), int64(137))),
Str: td.Anchor[string](t, td.HasPrefix("Pipo")),
Time: td.Anchor[time.Time](t, td.TruncTime(timeParse(tt, "2019-01-02T11:22:00Z"), time.Minute)),
}))

td.CmpTrue(tt,
t.Cmp(got, MyStruct{
PNum: td.A[*int](t, td.Ptr(td.Between(40, 45))),
Num: td.A[int64](t, td.Between(int64(135), int64(137))),
Str: td.A[string](t, td.HasPrefix("Pipo")),
Time: td.A[time.Time](t, td.TruncTime(timeParse(tt, "2019-01-02T11:22:00Z"), time.Minute)),
}))
}
Loading