TestAddedReflectValue tests functionality of the dump and formatter code which falls back to the standard fmt library for new types that might get added to the language.
(t *testing.T)
| 51 | // falls back to the standard fmt library for new types that might get added to |
| 52 | // the language. |
| 53 | func TestAddedReflectValue(t *testing.T) { |
| 54 | i := 1 |
| 55 | |
| 56 | // Dump using a reflect.Value that is exported. |
| 57 | v := reflect.ValueOf(int8(5)) |
| 58 | changeKind(&v, false) |
| 59 | buf := new(bytes.Buffer) |
| 60 | d := dumpState{w: buf, cs: &Config} |
| 61 | d.dump(v) |
| 62 | s := buf.String() |
| 63 | want := "(int8) 5" |
| 64 | if s != want { |
| 65 | t.Errorf("TestAddedReflectValue #%d\n got: %s want: %s", i, s, want) |
| 66 | } |
| 67 | i++ |
| 68 | |
| 69 | // Dump using a reflect.Value that is not exported. |
| 70 | changeKind(&v, true) |
| 71 | buf.Reset() |
| 72 | d.dump(v) |
| 73 | s = buf.String() |
| 74 | want = "(int8) <int8 Value>" |
| 75 | if s != want { |
| 76 | t.Errorf("TestAddedReflectValue #%d\n got: %s want: %s", i, s, want) |
| 77 | } |
| 78 | i++ |
| 79 | |
| 80 | // Formatter using a reflect.Value that is exported. |
| 81 | changeKind(&v, false) |
| 82 | buf2 := new(dummyFmtState) |
| 83 | f := formatState{value: v, cs: &Config, fs: buf2} |
| 84 | f.format(v) |
| 85 | s = buf2.String() |
| 86 | want = "5" |
| 87 | if s != want { |
| 88 | t.Errorf("TestAddedReflectValue #%d got: %s want: %s", i, s, want) |
| 89 | } |
| 90 | i++ |
| 91 | |
| 92 | // Formatter using a reflect.Value that is not exported. |
| 93 | changeKind(&v, true) |
| 94 | buf2.Reset() |
| 95 | f = formatState{value: v, cs: &Config, fs: buf2} |
| 96 | f.format(v) |
| 97 | s = buf2.String() |
| 98 | want = "<int8 Value>" |
| 99 | if s != want { |
| 100 | t.Errorf("TestAddedReflectValue #%d got: %s want: %s", i, s, want) |
| 101 | } |
| 102 | } |