| 1 |
package runtime |
| 2 |
|
| 3 |
import ( |
| 4 |
"reflect" |
| 5 |
"testing" |
| 6 |
"time" |
| 7 |
) |
| 8 |
|
| 9 |
// Each lookup finds the method of its name, and nothing in a type without it. |
| 10 |
func TestMethodLookups(t *testing.T) { |
| 11 |
timePtr := reflect.TypeOf(&time.Time{}) |
| 12 |
for name, lookup := range map[string]MethodLookup{ |
| 13 |
"MarshalJSON": MarshalJSONMethod, "MarshalText": MarshalTextMethod, "AppendText": AppendTextMethod, |
| 14 |
"UnmarshalJSON": UnmarshalJSONMethod, |
| 15 |
} { |
| 16 |
want, wantOK := timePtr.MethodByName(name) |
| 17 |
got, ok := lookup(timePtr) |
| 18 |
if ok != wantOK || got.Name != want.Name || got.Func.Pointer() != want.Func.Pointer() { |
| 19 |
t.Errorf("%s of *time.Time: got %v %v, want %v %v", name, got.Name, ok, want.Name, wantOK) |
| 20 |
} |
| 21 |
if _, ok := lookup(reflect.TypeOf(0)); ok { |
| 22 |
t.Errorf("%s of int: found", name) |
| 23 |
} |
| 24 |
} |
| 25 |
} |