Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(217)

Side by Side Diff: third_party/protobuf/examples/add_person_test.go

Issue 1842653006: Update //third_party/protobuf to version 3. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: merge Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 package main
2
3 import (
4 "strings"
5 "testing"
6
7 "github.com/golang/protobuf/proto"
8 pb "github.com/google/protobuf/examples/tutorial"
9 )
10
11 func TestPromptForAddressReturnsAddress(t *testing.T) {
12 in := `12345
13 Example Name
14 name@example.com
15 123-456-7890
16 home
17 222-222-2222
18 mobile
19 111-111-1111
20 work
21 777-777-7777
22 unknown
23
24 `
25 got, err := promptForAddress(strings.NewReader(in))
26 if err != nil {
27 t.Fatalf("promptForAddress(%q) had unexpected error: %s", in, er r.Error())
28 }
29 if got.Id != 12345 {
30 t.Errorf("promptForAddress(%q) got %d, want ID %d", in, got.Id, 12345)
31 }
32 if got.Name != "Example Name" {
33 t.Errorf("promptForAddress(%q) => want name %q, got %q", "Exampl e Name", got.Name)
34 }
35 if got.Email != "name@example.com" {
36 t.Errorf("promptForAddress(%q) => want email %q, got %q", "name@ example.com", got.Email)
37 }
38
39 want := []*pb.Person_PhoneNumber{
40 {Number: "123-456-7890", Type: pb.Person_HOME},
41 {Number: "222-222-2222", Type: pb.Person_MOBILE},
42 {Number: "111-111-1111", Type: pb.Person_WORK},
43 {Number: "777-777-7777", Type: pb.Person_MOBILE},
44 }
45 if len(got.Phones) != len(want) {
46 t.Errorf("want %d phone numbers, got %d", len(want), len(got.Pho nes))
47 }
48 phones := len(got.Phones)
49 if phones > len(want) {
50 phones = len(want)
51 }
52 for i := 0; i < phones; i++ {
53 if !proto.Equal(got.Phones[i], want[i]) {
54 t.Errorf("want phone %q, got %q", *want[i], *got.Phones[ i])
55 }
56
57 }
58 }
OLDNEW
« no previous file with comments | « third_party/protobuf/examples/add_person.py ('k') | third_party/protobuf/examples/addressbook.proto » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698