-
Notifications
You must be signed in to change notification settings - Fork 10
/
slicewriter_test.go
59 lines (44 loc) · 945 Bytes
/
slicewriter_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
50
51
52
53
54
55
56
57
58
59
package slice
import (
"bytes"
"fmt"
"go/parser"
"go/token"
"testing"
"github.com/clipperhouse/typewriter"
)
var pkg *typewriter.Package
func init() {
pkg = typewriter.NewPackage("dummy", "SomePackage")
t1, err := pkg.Eval("int")
if err != nil {
panic(err)
}
t2, err := pkg.Eval("*rune")
if err != nil {
panic(err)
}
t1.Tags = typewriter.TagSlice{
typewriter.Tag{
Name: "slice",
Values: []typewriter.TagValue{
{Name: "GroupBy", TypeParameters: []typewriter.Type{t2}},
{Name: "Where", TypeParameters: nil},
},
},
}
pkg.Types = append(pkg.Types, t1)
}
func TestWrite(t *testing.T) {
for _, typ := range pkg.Types {
var b bytes.Buffer
sw := NewSliceWriter()
b.WriteString(fmt.Sprintf("package %s\n\n", pkg.Name()))
sw.Write(&b, typ)
src := b.String()
fset := token.NewFileSet()
if _, err := parser.ParseFile(fset, "testwrite.go", src, 0); err != nil {
t.Error(err)
}
}
}