Add tests for new Sprint* family functions.

This commit adds tests for the new Sprint, Sprintf, and Sprintln functions
at the package level and as part of a ConfigState.
This commit is contained in:
Dave Collins 2013-02-23 21:53:16 -06:00
parent ce74710920
commit 803b1997c4
1 changed files with 42 additions and 0 deletions

View File

@ -36,6 +36,9 @@ const (
fCSFprintln fCSFprintln
fCSPrint fCSPrint
fCSPrintln fCSPrintln
fCSSprint
fCSSprintf
fCSSprintln
fCSErrorf fCSErrorf
fCSNewFormatter fCSNewFormatter
fErrorf fErrorf
@ -43,6 +46,9 @@ const (
fFprintln fFprintln
fPrint fPrint
fPrintln fPrintln
fSprint
fSprintf
fSprintln
) )
// Map of spewFunc values to names for pretty printing. // Map of spewFunc values to names for pretty printing.
@ -53,6 +59,9 @@ var spewFuncStrings = map[spewFunc]string{
fCSFprintln: "ConfigState.Fprintln", fCSFprintln: "ConfigState.Fprintln",
fCSPrint: "ConfigState.Print", fCSPrint: "ConfigState.Print",
fCSPrintln: "ConfigState.Println", fCSPrintln: "ConfigState.Println",
fCSSprint: "ConfigState.Sprint",
fCSSprintf: "ConfigState.Sprintf",
fCSSprintln: "ConfigState.Sprintln",
fCSErrorf: "ConfigState.Errorf", fCSErrorf: "ConfigState.Errorf",
fCSNewFormatter: "ConfigState.NewFormatter", fCSNewFormatter: "ConfigState.NewFormatter",
fErrorf: "spew.Errorf", fErrorf: "spew.Errorf",
@ -60,6 +69,9 @@ var spewFuncStrings = map[spewFunc]string{
fFprintln: "spew.Fprintln", fFprintln: "spew.Fprintln",
fPrint: "spew.Print", fPrint: "spew.Print",
fPrintln: "spew.Println", fPrintln: "spew.Println",
fSprint: "spew.Sprint",
fSprintf: "spew.Sprintf",
fSprintln: "spew.Sprintln",
} }
func (f spewFunc) String() string { func (f spewFunc) String() string {
@ -136,6 +148,9 @@ func initSpewTests() {
{scsDefault, fCSFprintln, "", int(2147483647), "2147483647\n"}, {scsDefault, fCSFprintln, "", int(2147483647), "2147483647\n"},
{scsDefault, fCSPrint, "", int64(9223372036854775807), "9223372036854775807"}, {scsDefault, fCSPrint, "", int64(9223372036854775807), "9223372036854775807"},
{scsDefault, fCSPrintln, "", uint8(255), "255\n"}, {scsDefault, fCSPrintln, "", uint8(255), "255\n"},
{scsDefault, fCSSprint, "", complex(1, 2), "(1+2i)"},
{scsDefault, fCSSprintf, "%v", complex(float32(3), 4), "(3+4i)"},
{scsDefault, fCSSprintln, "", complex(float64(5), 6), "(5+6i)\n"},
{scsDefault, fCSErrorf, "%#v", uint16(65535), "(uint16)65535"}, {scsDefault, fCSErrorf, "%#v", uint16(65535), "(uint16)65535"},
{scsDefault, fCSNewFormatter, "%v", uint32(4294967295), "4294967295"}, {scsDefault, fCSNewFormatter, "%v", uint32(4294967295), "4294967295"},
{scsDefault, fErrorf, "%v", uint64(18446744073709551615), "18446744073709551615"}, {scsDefault, fErrorf, "%v", uint64(18446744073709551615), "18446744073709551615"},
@ -143,6 +158,9 @@ func initSpewTests() {
{scsDefault, fFprintln, "", float64(6.28), "6.28\n"}, {scsDefault, fFprintln, "", float64(6.28), "6.28\n"},
{scsDefault, fPrint, "", true, "true"}, {scsDefault, fPrint, "", true, "true"},
{scsDefault, fPrintln, "", false, "false\n"}, {scsDefault, fPrintln, "", false, "false\n"},
{scsDefault, fSprint, "", complex(-1, -2), "(-1-2i)"},
{scsDefault, fSprintf, "%v", complex(float32(-3), -4), "(-3-4i)"},
{scsDefault, fSprintln, "", complex(float64(-5), -6), "(-5-6i)\n"},
{scsNoMethods, fCSFprint, "", ts, "test"}, {scsNoMethods, fCSFprint, "", ts, "test"},
{scsNoMethods, fCSFprint, "", &ts, "<*>test"}, {scsNoMethods, fCSFprint, "", &ts, "<*>test"},
{scsNoMethods, fCSFprint, "", tps, "test"}, {scsNoMethods, fCSFprint, "", tps, "test"},
@ -196,6 +214,18 @@ func TestSpew(t *testing.T) {
} }
buf.Write(b) buf.Write(b)
case fCSSprint:
str := test.cs.Sprint(test.in)
buf.WriteString(str)
case fCSSprintf:
str := test.cs.Sprintf(test.format, test.in)
buf.WriteString(str)
case fCSSprintln:
str := test.cs.Sprintln(test.in)
buf.WriteString(str)
case fCSErrorf: case fCSErrorf:
err := test.cs.Errorf(test.format, test.in) err := test.cs.Errorf(test.format, test.in)
buf.WriteString(err.Error()) buf.WriteString(err.Error())
@ -229,6 +259,18 @@ func TestSpew(t *testing.T) {
} }
buf.Write(b) buf.Write(b)
case fSprint:
str := spew.Sprint(test.in)
buf.WriteString(str)
case fSprintf:
str := spew.Sprintf(test.format, test.in)
buf.WriteString(str)
case fSprintln:
str := spew.Sprintln(test.in)
buf.WriteString(str)
default: default:
t.Errorf("%v #%d unrecognized function", test.f, i) t.Errorf("%v #%d unrecognized function", test.f, i)
continue continue