print array (not just *array) using %v

TBR=rsc
DELTA=34  (33 added, 0 deleted, 1 changed)
OCL=21718
CL=21718
This commit is contained in:
Rob Pike 2008-12-22 11:04:17 -08:00
parent eb32228627
commit b0d62676d2
2 changed files with 34 additions and 1 deletions

View file

@ -232,3 +232,17 @@ export func TestStructPrinter(t *testing.T) {
}
}
}
export func TestArrayPrinter(t *testing.T) {
a := []int{1, 2, 3, 4, 5};
want := "[1 2 3 4 5]";
out := fmt.sprintf("%v", a);
if out != want {
t.Errorf("sprintf(%%v, array) = %q, want %q", out, want);
}
want = "&" + want;
out = fmt.sprintf("%v", &a);
if out != want {
t.Errorf("sprintf(%%v, &array) = %q, want %q", out, want);
}
}