diff options
author | Jakob Buchgraber <buchgr@google.com> | 2017-04-12 14:30:38 +0200 |
---|---|---|
committer | Jakob Buchgraber <buchgr@google.com> | 2017-04-13 14:32:42 +0200 |
commit | ea82aa115794b019472b44d4f94ed902c1217f30 (patch) | |
tree | 06ace57ced74604ddcfb545632cfc7eb768ff164 /third_party/protobuf/examples/list_people_test.go | |
parent | e1c31944c3bcc89722a8e77013b11110edf3b5f6 (diff) |
protobuf: Update protobuf to @laszlocsomor's master at commit 421d909.
Update protobuf to @laszlocsomor's fork of protobuf. This is essentially
the development version of protobuf 3.2.0 and windows specific fixes
from laszlo. Those fixes will be merged into protobuf soon:
https://github.com/google/protobuf/pull/2969).
For instructions on how to update protobuf for bazel see
README.bazel.md.
Change-Id: I4f663955b0baeea3232b69ce32d9292427f5274a
Diffstat (limited to 'third_party/protobuf/examples/list_people_test.go')
-rw-r--r-- | third_party/protobuf/examples/list_people_test.go | 120 |
1 files changed, 120 insertions, 0 deletions
diff --git a/third_party/protobuf/examples/list_people_test.go b/third_party/protobuf/examples/list_people_test.go new file mode 100644 index 0000000000..87d6ad6ec6 --- /dev/null +++ b/third_party/protobuf/examples/list_people_test.go @@ -0,0 +1,120 @@ +package main + +import ( + "bytes" + "strings" + "testing" + + pb "github.com/google/protobuf/examples/tutorial" +) + +func TestWritePersonWritesPerson(t *testing.T) { + buf := new(bytes.Buffer) + // [START populate_proto] + p := pb.Person{ + Id: 1234, + Name: "John Doe", + Email: "jdoe@example.com", + Phones: []*pb.Person_PhoneNumber{ + {Number: "555-4321", Type: pb.Person_HOME}, + }, + } + // [END populate_proto] + writePerson(buf, &p) + got := buf.String() + want := `Person ID: 1234 + Name: John Doe + E-mail address: jdoe@example.com + Home phone #: 555-4321 +` + if got != want { + t.Errorf("writePerson(%s) =>\n\t%q, want %q", p.String(), got, want) + } +} + +func TestListPeopleWritesList(t *testing.T) { + buf := new(bytes.Buffer) + in := pb.AddressBook{[]*pb.Person{ + { + Name: "John Doe", + Id: 101, + Email: "john@example.com", + }, + { + Name: "Jane Doe", + Id: 102, + }, + { + Name: "Jack Doe", + Id: 201, + Email: "jack@example.com", + Phones: []*pb.Person_PhoneNumber{ + {Number: "555-555-5555", Type: pb.Person_WORK}, + }, + }, + { + Name: "Jack Buck", + Id: 301, + Email: "buck@example.com", + Phones: []*pb.Person_PhoneNumber{ + {Number: "555-555-0000", Type: pb.Person_HOME}, + {Number: "555-555-0001", Type: pb.Person_MOBILE}, + {Number: "555-555-0002", Type: pb.Person_WORK}, + }, + }, + { + Name: "Janet Doe", + Id: 1001, + Email: "janet@example.com", + Phones: []*pb.Person_PhoneNumber{ + {Number: "555-777-0000"}, + {Number: "555-777-0001", Type: pb.Person_HOME}, + }, + }, + }} + listPeople(buf, &in) + want := strings.Split(`Person ID: 101 + Name: John Doe + E-mail address: john@example.com +Person ID: 102 + Name: Jane Doe +Person ID: 201 + Name: Jack Doe + E-mail address: jack@example.com + Work phone #: 555-555-5555 +Person ID: 301 + Name: Jack Buck + E-mail address: buck@example.com + Home phone #: 555-555-0000 + Mobile phone #: 555-555-0001 + Work phone #: 555-555-0002 +Person ID: 1001 + Name: Janet Doe + E-mail address: janet@example.com + Mobile phone #: 555-777-0000 + Home phone #: 555-777-0001 +`, "\n") + got := strings.Split(buf.String(), "\n") + if len(got) != len(want) { + t.Errorf( + "listPeople(%s) =>\n\t%q has %d lines, want %d", + in.String(), + buf.String(), + len(got), + len(want)) + } + lines := len(got) + if lines > len(want) { + lines = len(want) + } + for i := 0; i < lines; i++ { + if got[i] != want[i] { + t.Errorf( + "listPeople(%s) =>\n\tline %d %q, want %q", + in.String(), + i, + got[i], + want[i]) + } + } +} |