}
}
}
+
+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);
+ }
+}
return nil, false;
}
+func getArray(v reflect.Value) (val reflect.ArrayValue, ok bool) {
+ switch v.Kind() {
+ case reflect.ArrayKind:
+ return v.(reflect.ArrayValue), true;
+ }
+ return nil, false;
+}
+
// Convert ASCII to integer. n is 0 (and got is false) if no number present.
func parsenum(s string, start, end int) (n int, got bool, newi int) {
if v, ok := getPtr(field); v == 0 {
s = "<nil>"
} else {
- // pointer to array?
+ // pointer to array? (TODO(r): holdover; delete?)
if a, ok := getArrayPtr(field); ok {
p.addstr("&[");
for i := 0; i < a.Len(); i++ {
s = p.fmt.uX64(uint64(v)).str();
}
}
+ case reflect.ArrayKind:
+ if a, ok := getArray(field); ok {
+ p.addstr("[");
+ for i := 0; i < a.Len(); i++ {
+ if i > 0 {
+ p.addstr(" ");
+ }
+ p.printField(a.Elem(i));
+ }
+ p.addstr("]");
+ }
case reflect.StructKind:
p.add('{');
v := field.(reflect.StructValue);