130
a int8 `reflect:"hi there"`
133
`struct { a int8 "hi there" }`,
133
`struct { a int8 "reflect:\"hi there\"" }`,
137
a int8 "hi \x00there\t\n\"\\"
137
a int8 `reflect:"hi \x00there\t\n\"\\"`
140
`struct { a int8 "hi \x00there\t\n\"\\" }`,
140
`struct { a int8 "reflect:\"hi \\x00there\\t\\n\\\"\\\\\"" }`,
1053
// This will be index 0.
1054
func (p Point) AnotherMethod(scale int) int {
1058
// This will be index 1.
1053
1059
func (p Point) Dist(scale int) int {
1054
1060
// println("Point.Dist", p.x, p.y, scale)
1055
1061
return p.x*p.x*scale + p.y*p.y*scale
1058
1064
func TestMethod(t *testing.T) {
1059
1065
// Non-curried method of type.
1060
1066
p := Point{3, 4}
1061
i := TypeOf(p).Method(0).Func.Call([]Value{ValueOf(p), ValueOf(10)})[0].Int()
1067
i := TypeOf(p).Method(1).Func.Call([]Value{ValueOf(p), ValueOf(10)})[0].Int()
1063
1069
t.Errorf("Type Method returned %d; want 250", i)
1066
i = TypeOf(&p).Method(0).Func.Call([]Value{ValueOf(&p), ValueOf(10)})[0].Int()
1072
m, ok := TypeOf(p).MethodByName("Dist")
1074
t.Fatalf("method by name failed")
1076
m.Func.Call([]Value{ValueOf(p), ValueOf(10)})[0].Int()
1078
t.Errorf("Type MethodByName returned %d; want 250", i)
1081
i = TypeOf(&p).Method(1).Func.Call([]Value{ValueOf(&p), ValueOf(10)})[0].Int()
1068
1083
t.Errorf("Pointer Type Method returned %d; want 250", i)
1086
m, ok = TypeOf(&p).MethodByName("Dist")
1088
t.Fatalf("ptr method by name failed")
1090
i = m.Func.Call([]Value{ValueOf(&p), ValueOf(10)})[0].Int()
1092
t.Errorf("Pointer Type MethodByName returned %d; want 250", i)
1071
1095
// Curried method of value.
1072
i = ValueOf(p).Method(0).Call([]Value{ValueOf(10)})[0].Int()
1096
i = ValueOf(p).Method(1).Call([]Value{ValueOf(10)})[0].Int()
1074
1098
t.Errorf("Value Method returned %d; want 250", i)
1100
i = ValueOf(p).MethodByName("Dist").Call([]Value{ValueOf(10)})[0].Int()
1102
t.Errorf("Value MethodByName returned %d; want 250", i)
1077
1105
// Curried method of pointer.
1078
i = ValueOf(&p).Method(0).Call([]Value{ValueOf(10)})[0].Int()
1080
t.Errorf("Value Method returned %d; want 250", i)
1106
i = ValueOf(&p).Method(1).Call([]Value{ValueOf(10)})[0].Int()
1108
t.Errorf("Pointer Value Method returned %d; want 250", i)
1110
i = ValueOf(&p).MethodByName("Dist").Call([]Value{ValueOf(10)})[0].Int()
1112
t.Errorf("Pointer Value MethodByName returned %d; want 250", i)
1083
1115
// Curried method of interface value.
1095
1127
t.Errorf("Interface Method returned %d; want 250", i)
1129
i = pv.MethodByName("Dist").Call([]Value{ValueOf(10)})[0].Int()
1131
t.Errorf("Interface MethodByName returned %d; want 250", i)
1099
1135
func TestInterfaceSet(t *testing.T) {
1508
1544
t.Errorf("after Fprintf CallSlice: %q != %q", b.String(), "hello 42 world")
1548
var tagGetTests = []struct {
1553
{`protobuf:"PB(1,2)"`, `protobuf`, `PB(1,2)`},
1554
{`protobuf:"PB(1,2)"`, `foo`, ``},
1555
{`protobuf:"PB(1,2)"`, `rotobuf`, ``},
1556
{`protobuf:"PB(1,2)" json:"name"`, `json`, `name`},
1557
{`protobuf:"PB(1,2)" json:"name"`, `protobuf`, `PB(1,2)`},
1560
func TestTagGet(t *testing.T) {
1561
for _, tt := range tagGetTests {
1562
if v := tt.Tag.Get(tt.Key); v != tt.Value {
1563
t.Errorf("StructTag(%#q).Get(%#q) = %#q, want %#q", tt.Tag, tt.Key, v, tt.Value)