This repository has been archived by the owner on Apr 3, 2023. It is now read-only.
forked from lyft/protoc-gen-star
-
Notifications
You must be signed in to change notification settings - Fork 0
/
package_test.go
88 lines (67 loc) · 1.53 KB
/
package_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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
package pgs
import (
"testing"
"github.com/golang/protobuf/proto"
"github.com/golang/protobuf/protoc-gen-go/descriptor"
"errors"
"github.com/stretchr/testify/assert"
)
func TestPkg_ProtoName(t *testing.T) {
t.Parallel()
p := dummyPkg()
assert.Equal(t, p.fd.GetPackage(), p.ProtoName().String())
}
func TestPkg_Files(t *testing.T) {
t.Parallel()
p := &pkg{}
assert.Empty(t, p.Files())
p.addFile(&file{})
p.addFile(&file{})
p.addFile(&file{})
assert.Len(t, p.Files(), 3)
}
func TestPkg_AddFile(t *testing.T) {
t.Parallel()
p := &pkg{}
f := &file{}
p.addFile(f)
assert.Len(t, p.files, 1)
assert.EqualValues(t, f, p.files[0])
}
func TestPkg_Accept(t *testing.T) {
t.Parallel()
p := &pkg{
files: []File{&mockFile{}},
}
assert.Nil(t, p.accept(nil))
v := &mockVisitor{}
assert.NoError(t, p.accept(v))
assert.Equal(t, 1, v.pkg)
assert.Zero(t, v.file)
v.Reset()
v.err = errors.New("foobar")
assert.EqualError(t, p.accept(v), "foobar")
assert.Equal(t, 1, v.pkg)
assert.Zero(t, v.file)
v.Reset()
v.v = v
assert.NoError(t, p.accept(v))
assert.Equal(t, 1, v.pkg)
assert.Equal(t, 1, v.file)
v.Reset()
p.addFile(&mockFile{err: errors.New("fizzbuzz")})
assert.EqualError(t, p.accept(v), "fizzbuzz")
assert.Equal(t, 1, v.pkg)
assert.Equal(t, 2, v.file)
}
func TestPackage_Comments(t *testing.T) {
t.Parallel()
pkg := dummyPkg()
pkg.setComments("foobar")
assert.Equal(t, "foobar", pkg.Comments())
}
func dummyPkg() *pkg {
return &pkg{
fd: &descriptor.FileDescriptorProto{Package: proto.String("pkg_name")},
}
}