| 103 | } |
| 104 | |
| 105 | func TestIndent(t *testing.T) { |
| 106 | var buf bytes.Buffer |
| 107 | for _, tt := range examples { |
| 108 | buf.Reset() |
| 109 | if err := Indent(&buf, []byte(tt.indent), "", "\t"); err != nil { |
| 110 | t.Errorf("Indent(%#q): %v", tt.indent, err) |
| 111 | } else if s := buf.String(); s != tt.indent { |
| 112 | t.Errorf("Indent(%#q) = %#q, want original", tt.indent, s) |
| 113 | } |
| 114 | |
| 115 | buf.Reset() |
| 116 | if err := Indent(&buf, []byte(tt.compact), "", "\t"); err != nil { |
| 117 | t.Errorf("Indent(%#q): %v", tt.compact, err) |
| 118 | continue |
| 119 | } else if s := buf.String(); s != tt.indent { |
| 120 | t.Errorf("Indent(%#q) = %#q, want %#q", tt.compact, s, tt.indent) |
| 121 | } |
| 122 | } |
| 123 | } |
| 124 | |
| 125 | // Tests of a large random structure. |
| 126 | |