// main.go
package main
type TreeNode struct {
Name string
ID int
Children []*TreeNode
A int
B int
C int
// 注释掉 go test 可以正常运行
A1 int
B2 int
C1 int
}
func first[T any](a, b T) T { return a }
func second[T any](a, b T) T { return b }
// main_test.go
package main
import (
"fmt"
"reflect"
"testing"
"github.com/go-kiss/monkey"
)
func Test_main(t *testing.T) {
t1 := TreeNode{ ID: 1 }
t2 := TreeNode{ ID: 2 }
monkey.Patch(first[TreeNode], second[TreeNode], monkey.OptGeneric)
if reflect.DeepEqual(t2, first(t1, t2)) {
fmt.Println("equal")
} else {
fmt.Println("not equal")
t.Fatalf("not equal")
}
}