MCPcopy Create free account
hub / github.com/creasty/defaults / TestIsPromotedMethod

Function TestIsPromotedMethod

method_test.go:54–75  ·  view source on GitHub ↗

TestIsPromotedMethod covers where the code behind a method comes from, which reflect reports alike for a method a type declares and one it takes from an embedded field.

(t *testing.T)

Source from the content-addressed store, hash-verified

52// TestIsPromotedMethod covers where the code behind a method comes from, which reflect reports alike
53// for a method a type declares and one it takes from an embedded field.
54func TestIsPromotedMethod(t *testing.T) {
55 tests := []struct {
56 name string
57 typ reflect.Type
58 want bool
59 }{
60 {"declared on a value receiver", reflect.TypeOf(methodValue{}), false},
61 {"declared on a pointer receiver", reflect.TypeOf(methodPointer{}), false},
62 {"declared over an embedded field's", reflect.TypeOf(methodShadows{}), false},
63 {"taken from an embedded value", reflect.TypeOf(methodEmbedsValue{}), true},
64 {"taken from an embedded value, pointer receiver", reflect.TypeOf(methodEmbedsPointerReceiver{}), true},
65 {"taken from an embedded pointer", reflect.TypeOf(methodEmbedsPointerField{}), true},
66 {"taken from a field that took it", reflect.TypeOf(methodEmbedsTwice{}), true},
67 {"taken from an embedded interface", reflect.TypeOf(methodEmbedsInterface{}), true},
68 }
69
70 for _, tt := range tests {
71 t.Run(tt.name, func(t *testing.T) {
72 assert.Equal(t, tt.want, isPromotedMethod(tt.typ, "Ping"))
73 })
74 }
75}

Callers

nothing calls this directly

Calls 1

isPromotedMethodFunction · 0.85

Tested by

no test coverage detected