func TestUnmarshalling(t *testing.T) { for _, tt := range unmarshallingTests { // Make a new instance of the type of our expected object. p := proto.Clone(tt.pb) p.Reset() err := UnmarshalString(tt.json, p) if err != nil { t.Error(err) continue } // For easier diffs, compare text strings of the protos. exp := proto.MarshalTextString(tt.pb) act := proto.MarshalTextString(p) if string(exp) != string(act) { t.Errorf("%s: got [%s] want [%s]", tt.desc, act, exp) } } }
func TestFooProtoText(t *testing.T) { popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) p := NewPopulatedFoo(popr, true) data := github_com_gogo_protobuf_proto.MarshalTextString(p) msg := &Foo{} if err := github_com_gogo_protobuf_proto.UnmarshalText(data, msg); err != nil { panic(err) } if !p.Equal(msg) { t.Fatalf("%#v !Proto %#v", msg, p) } }
func TestCastawayProtoText(t *testing.T) { popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) p := NewPopulatedCastaway(popr, true) data := github_com_gogo_protobuf_proto.MarshalTextString(p) msg := &Castaway{} if err := github_com_gogo_protobuf_proto.UnmarshalText(data, msg); err != nil { panic(err) } if err := p.VerboseEqual(msg); err != nil { t.Fatalf("%#v !VerboseProto %#v, since %v", msg, p, err) } if !p.Equal(msg) { t.Fatalf("%#v !Proto %#v", msg, p) } }
func TestRepeatedNilText(t *testing.T) { m := &pb.MessageList{ Message: []*pb.MessageList_Message{ nil, { Name: proto.String("Horse"), }, nil, }, } want := `Message <nil> Message { name: "Horse" } Message <nil> ` if s := proto.MarshalTextString(m); s != want { t.Errorf(" got: %s\nwant: %s", s, want) } }