1 // Copyright 2011 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
13 var tests = []struct {
14 x interface{} // x is printed as s
22 {1 + 2.718i, "0 (1+2.718i)"},
23 {"foobar", "0 \"foobar\""},
26 {map[string]int{"a": 1},
27 `0 map[string] int (len = 1) {
43 {struct{ X, Y int }{42, 991},
44 `0 struct { X int; Y int } {
50 // Split s into lines, trim whitespace from all lines, and return
51 // the concatenated non-empty lines.
52 func trim(s string) string {
53 lines := strings.Split(s, "\n")
55 for _, line := range lines {
56 line = strings.TrimSpace(line)
62 return strings.Join(lines[0:i], "\n")
65 func TestPrint(t *testing.T) {
67 for _, test := range tests {
69 if _, err := Fprint(&buf, nil, test.x, nil); err != nil {
70 t.Errorf("Fprint failed: %s", err)
72 if s, ts := trim(buf.String()), trim(test.s); s != ts {
73 t.Errorf("got:\n%s\nexpected:\n%s\n", s, ts)