Improves readability of Go example test.
This commit is contained in:
parent
1cc541b3be
commit
7df1d773b7
1 changed files with 5 additions and 25 deletions
|
@ -21,34 +21,14 @@ func TestWritePersonWritesPerson(t *testing.T) {
|
||||||
}
|
}
|
||||||
// [END populate_proto]
|
// [END populate_proto]
|
||||||
writePerson(buf, &p)
|
writePerson(buf, &p)
|
||||||
want := strings.Split(`Person ID: 1234
|
got := buf.String()
|
||||||
|
want := `Person ID: 1234
|
||||||
Name: John Doe
|
Name: John Doe
|
||||||
E-mail address: jdoe@example.com
|
E-mail address: jdoe@example.com
|
||||||
Home phone #: 555-4321
|
Home phone #: 555-4321
|
||||||
`, "\n")
|
`
|
||||||
|
if got != want {
|
||||||
got := strings.Split(buf.String(), "\n")
|
t.Errorf("writePerson(%s) =>\n\t%q, want %q", p.String(), got, want)
|
||||||
if len(got) != len(want) {
|
|
||||||
t.Errorf(
|
|
||||||
"writePerson(%s) =>\n\t%q has %d lines, want %d",
|
|
||||||
p.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(
|
|
||||||
"writePerson(%s) =>\n\tline %d %q, want %q",
|
|
||||||
p.String(),
|
|
||||||
i,
|
|
||||||
got[i],
|
|
||||||
want[i])
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue