/
out_test.go
49 lines (39 loc) · 980 Bytes
/
out_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
47
48
49
package dragon
import (
"bytes"
"strings"
"testing"
)
func TestOut(t *testing.T) {
libChan := make(chan lib)
go func() {
libChan <- lib{
object: "Imports",
path: "github.com/monochromegane/dragon-imports",
}
libChan <- lib{
object: "Imports",
path: "github.com/someone/dragon-imports",
}
close(libChan)
}()
expect := `// AUTO-GENERATED BY dragon-imports
package imports
var stdlib = map[string]map[string]bool{`
buf := &bytes.Buffer{}
out(libChan, buf)
actual := buf.String()
if !strings.HasPrefix(actual, expect) {
t.Errorf("out should have prefix\n%s\n but\n%s", expect, actual)
}
contains := []string{
`"github.com/monochromegane/dragon-imports":map[string]bool{"Imports":true}`,
`"github.com/someone/dragon-imports":map[string]bool{"Imports":true}`,
`"unsafe":map[string]bool{`,
}
for _, s := range contains {
if !strings.Contains(actual, s) {
t.Errorf("out should contain \n%s\n but\n%s", s, actual)
}
}
}