MCPcopy
hub / github.com/adonovan/gopl.io / TestEcho

Function TestEcho

ch11/echo/echo_test.go:15–43  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

13)
14
15func TestEcho(t *testing.T) {
16 var tests = []struct {
17 newline bool
18 sep string
19 args []string
20 want string
21 }{
22 {true, "", []string{}, "\n"},
23 {false, "", []string{}, ""},
24 {true, "\t", []string{"one", "two", "three"}, "one\ttwo\tthree\n"},
25 {true, ",", []string{"a", "b", "c"}, "a,b,c\n"},
26 {false, ":", []string{"1", "2", "3"}, "1:2:3"},
27 }
28
29 for _, test := range tests {
30 descr := fmt.Sprintf("echo(%v, %q, %q)",
31 test.newline, test.sep, test.args)
32
33 out = new(bytes.Buffer) // captured output
34 if err := echo(test.newline, test.sep, test.args); err != nil {
35 t.Errorf("%s failed: %v", descr, err)
36 continue
37 }
38 got := out.(*bytes.Buffer).String()
39 if got != test.want {
40 t.Errorf("%s = %q, want %q", descr, got, test.want)
41 }
42 }
43}
44
45//!-

Callers

nothing calls this directly

Calls 2

echoFunction · 0.70
StringMethod · 0.45

Tested by

no test coverage detected