-
Notifications
You must be signed in to change notification settings - Fork 90
/
list_test.go
46 lines (37 loc) · 992 Bytes
/
list_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
package main
import (
"bytes"
"os"
"testing"
)
func TestList(t *testing.T) {
// use buffer instead of Stdout so we can inspect the results
var b bytes.Buffer
c := defaultConfig
c.out = &b
c.customName = "_gen_list_test.go"
// clean up when done
defer os.Remove(c.customName)
// standard
if err := list(c); err != nil {
t.Fatal(err)
}
// 1 line for title + 2 standard typewriters (see imports.go)
if lines := bytes.Count(b.Bytes(), []byte("\n")); lines != 3 {
t.Errorf("standard list should output 2 lines, got %v", lines)
}
// clear out the buffer
b.Reset()
// create a custom typewriter import file
if err := add(c, "github.com/clipperhouse/foowriter"); err != nil {
t.Error(err)
}
// custom file now exists
if err := list(c); err != nil {
t.Error(err)
}
// 1 line for title + 2 custom typewriters
if lines := bytes.Count(b.Bytes(), []byte("\n")); lines != 4 {
t.Errorf("standard list should output 4 lines, got %v:\n%s", lines, b.String())
}
}