|
@@ -36,6 +36,9 @@ type dummyFmtState struct {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
func (dfs *dummyFmtState) Flag(f int) bool {
|
|
func (dfs *dummyFmtState) Flag(f int) bool {
|
|
|
|
|
+ if f == int('+') {
|
|
|
|
|
+ return true
|
|
|
|
|
+ }
|
|
|
return false
|
|
return false
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -47,10 +50,14 @@ func (dfs *dummyFmtState) Width() (int, bool) {
|
|
|
return 0, false
|
|
return 0, false
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-// TestDumpInvalidReflectValue ensures the dump 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.
|
|
|
|
|
-func TestDumpInvalidReflectValue(t *testing.T) {
|
|
|
|
|
|
|
+// 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.
|
|
|
|
|
+func TestInvalidReflectValue(t *testing.T) {
|
|
|
|
|
+ i := 1
|
|
|
|
|
+
|
|
|
|
|
+ // Dump invalid reflect value.
|
|
|
v := new(reflect.Value)
|
|
v := new(reflect.Value)
|
|
|
buf := new(bytes.Buffer)
|
|
buf := new(bytes.Buffer)
|
|
|
d := dumpState{w: buf, cs: &Config}
|
|
d := dumpState{w: buf, cs: &Config}
|
|
@@ -58,22 +65,17 @@ func TestDumpInvalidReflectValue(t *testing.T) {
|
|
|
s := buf.String()
|
|
s := buf.String()
|
|
|
want := "<invalid>"
|
|
want := "<invalid>"
|
|
|
if s != want {
|
|
if s != want {
|
|
|
- t.Errorf("DumpInvalidReflectValue\n got: %s want: %s", s, want)
|
|
|
|
|
|
|
+ t.Errorf("InvalidReflectValue #%d\n got: %s want: %s", i, s, want)
|
|
|
}
|
|
}
|
|
|
-}
|
|
|
|
|
|
|
+ i++
|
|
|
|
|
|
|
|
-// TestFormatterInvalidReflectValue ensures the 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.
|
|
|
|
|
-func TestFormatterInvalidReflectValue(t *testing.T) {
|
|
|
|
|
- v := new(reflect.Value)
|
|
|
|
|
- buf := new(dummyFmtState)
|
|
|
|
|
- f := formatState{value: *v, cs: &Config, fs: buf}
|
|
|
|
|
|
|
+ // Formatter invalid reflect value.
|
|
|
|
|
+ buf2 := new(dummyFmtState)
|
|
|
|
|
+ f := formatState{value: *v, cs: &Config, fs: buf2}
|
|
|
f.format(*v)
|
|
f.format(*v)
|
|
|
- s := buf.String()
|
|
|
|
|
- want := "<invalid>"
|
|
|
|
|
|
|
+ s = buf2.String()
|
|
|
|
|
+ want = "<invalid>"
|
|
|
if s != want {
|
|
if s != want {
|
|
|
- t.Errorf("FormatterInvalidReflectValue\n got: %s want: %s", s, want)
|
|
|
|
|
|
|
+ t.Errorf("InvalidReflectValue #%d got: %s want: %s", i, s, want)
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|