TestInvalidReflectValue ensures the dump and formatter code handles an invalid reflect value properly. This needs access to internal state since it should never happen in real code and therefore can't be tested via the public API.
(t *testing.T)
| 52 | // should never happen in real code and therefore can't be tested via the public |
| 53 | // API. |
| 54 | func TestInvalidReflectValue(t *testing.T) { |
| 55 | i := 1 |
| 56 | |
| 57 | // Dump invalid reflect value. |
| 58 | v := new(reflect.Value) |
| 59 | buf := new(bytes.Buffer) |
| 60 | d := dumpState{w: buf, cs: &Config} |
| 61 | d.dump(*v) |
| 62 | s := buf.String() |
| 63 | want := "<invalid>" |
| 64 | if s != want { |
| 65 | t.Errorf("InvalidReflectValue #%d\n got: %s want: %s", i, s, want) |
| 66 | } |
| 67 | i++ |
| 68 | |
| 69 | // Formatter invalid reflect value. |
| 70 | buf2 := new(dummyFmtState) |
| 71 | f := formatState{value: *v, cs: &Config, fs: buf2} |
| 72 | f.format(*v) |
| 73 | s = buf2.String() |
| 74 | want = "<invalid>" |
| 75 | if s != want { |
| 76 | t.Errorf("InvalidReflectValue #%d got: %s want: %s", i, s, want) |
| 77 | } |
| 78 | } |
| 79 | |
| 80 | // SortValues makes the internal sortValues function available to the test |
| 81 | // package. |