MCPcopy
hub / github.com/google/go-cmp / project3Tests

Function project3Tests

cmp/compare_test.go:2802–2875  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

2800}
2801
2802func project3Tests() []test {
2803 const label = "Project3"
2804
2805 allowVisibility := cmp.AllowUnexported(ts.Dirt{})
2806
2807 ignoreLocker := cmpopts.IgnoreInterfaces(struct{ sync.Locker }{})
2808
2809 transformProtos := cmp.Transformer("λ", func(x pb.Dirt) *pb.Dirt {
2810 return &x
2811 })
2812
2813 equalTable := cmp.Comparer(func(x, y ts.Table) bool {
2814 tx, ok1 := x.(*ts.MockTable)
2815 ty, ok2 := y.(*ts.MockTable)
2816 if !ok1 || !ok2 {
2817 panic("table type must be MockTable")
2818 }
2819 return cmp.Equal(tx.State(), ty.State())
2820 })
2821
2822 createDirt := func() (d ts.Dirt) {
2823 d.SetTable(ts.CreateMockTable([]string{"a", "b", "c"}))
2824 d.SetTimestamp(12345)
2825 d.Discord = 554
2826 d.Proto = pb.Dirt{Stringer: pb.Stringer{X: "proto"}}
2827 d.SetWizard(map[string]*pb.Wizard{
2828 "harry": {Stringer: pb.Stringer{X: "potter"}},
2829 "albus": {Stringer: pb.Stringer{X: "dumbledore"}},
2830 })
2831 d.SetLastTime(54321)
2832 return d
2833 }
2834
2835 return []test{{
2836 label: label + "/PanicUnexported1",
2837 x: createDirt(),
2838 y: createDirt(),
2839 wantPanic: "cannot handle unexported field",
2840 reason: "struct contains unexported fields",
2841 }, {
2842 label: label + "/PanicUnexported2",
2843 x: createDirt(),
2844 y: createDirt(),
2845 opts: []cmp.Option{allowVisibility, ignoreLocker, cmp.Comparer(pb.Equal), equalTable},
2846 wantPanic: "cannot handle unexported field",
2847 reason: "struct contains references to simulated protobuf types with unexported fields",
2848 }, {
2849 label: label + "/Equal",
2850 x: createDirt(),
2851 y: createDirt(),
2852 opts: []cmp.Option{allowVisibility, transformProtos, ignoreLocker, cmp.Comparer(pb.Equal), equalTable},
2853 wantEqual: true,
2854 reason: "transformer used to create reference to protobuf message so it works with pb.Equal",
2855 }, {
2856 label: label + "/Inequal",
2857 x: func() ts.Dirt {
2858 d := createDirt()
2859 d.SetTable(ts.CreateMockTable([]string{"a", "c"}))

Callers 1

TestDiffFunction · 0.85

Calls 10

AllowUnexportedFunction · 0.92
IgnoreInterfacesFunction · 0.92
TransformerFunction · 0.92
ComparerFunction · 0.92
EqualFunction · 0.92
StateMethod · 0.80
SetTableMethod · 0.80
SetTimestampMethod · 0.80
SetWizardMethod · 0.80
SetLastTimeMethod · 0.80

Tested by

no test coverage detected