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
/
enum_value_test.go
126 lines (103 loc) · 2.59 KB
/
enum_value_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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
package pgs
import (
"errors"
"testing"
"github.com/golang/protobuf/proto"
"github.com/golang/protobuf/protoc-gen-go/descriptor"
"github.com/stretchr/testify/assert"
)
func TestEnumVal_Name(t *testing.T) {
t.Parallel()
ev := &enumVal{desc: &descriptor.EnumValueDescriptorProto{Name: proto.String("eval")}}
assert.Equal(t, "eval", ev.Name().String())
}
func TestEnumVal_FullyQualifiedName(t *testing.T) {
t.Parallel()
ev := &enumVal{fqn: "ev"}
assert.Equal(t, ev.fqn, ev.FullyQualifiedName())
}
func TestEnumVal_Syntax(t *testing.T) {
t.Parallel()
ev := &enumVal{}
e := dummyEnum()
e.addValue(ev)
assert.Equal(t, e.Syntax(), ev.Syntax())
}
func TestEnumVal_Package(t *testing.T) {
t.Parallel()
ev := &enumVal{}
e := dummyEnum()
e.addValue(ev)
assert.NotNil(t, ev.Package())
assert.Equal(t, e.Package(), ev.Package())
}
func TestEnumVal_File(t *testing.T) {
t.Parallel()
ev := &enumVal{}
e := dummyEnum()
e.addValue(ev)
assert.NotNil(t, ev.File())
assert.Equal(t, e.File(), ev.File())
}
func TestEnumVal_BuildTarget(t *testing.T) {
t.Parallel()
ev := &enumVal{}
e := dummyEnum()
e.addValue(ev)
assert.False(t, ev.BuildTarget())
e.parent = &file{buildTarget: true}
assert.True(t, ev.BuildTarget())
}
func TestEnumVal_Descriptor(t *testing.T) {
t.Parallel()
ev := &enumVal{desc: &descriptor.EnumValueDescriptorProto{}}
assert.Equal(t, ev.desc, ev.Descriptor())
}
func TestEnumVal_Enum(t *testing.T) {
t.Parallel()
ev := &enumVal{}
e := dummyEnum()
e.addValue(ev)
assert.Equal(t, e, ev.Enum())
}
func TestEnumVal_Value(t *testing.T) {
t.Parallel()
ev := &enumVal{desc: &descriptor.EnumValueDescriptorProto{Number: proto.Int32(123)}}
assert.Equal(t, int32(123), ev.Value())
}
func TestEnumVal_Imports(t *testing.T) {
t.Parallel()
assert.Nil(t, (&enumVal{}).Imports())
}
func TestEnumVal_Extension(t *testing.T) {
// cannot be parallel
ev := &enumVal{desc: &descriptor.EnumValueDescriptorProto{}}
assert.NotPanics(t, func() { ev.Extension(nil, nil) })
}
func TestEnumVal_Accept(t *testing.T) {
t.Parallel()
ev := &enumVal{}
assert.NoError(t, ev.accept(nil))
v := &mockVisitor{err: errors.New("")}
assert.Error(t, ev.accept(v))
assert.Equal(t, 1, v.enumvalue)
}
func TestEnumVal_ChildAtPath(t *testing.T) {
t.Parallel()
ev := &enumVal{}
assert.Equal(t, ev, ev.childAtPath(nil))
assert.Nil(t, ev.childAtPath([]int32{1}))
}
type mockEnumValue struct {
EnumValue
e Enum
err error
}
func (ev *mockEnumValue) setEnum(e Enum) { ev.e = e }
func (ev *mockEnumValue) accept(v Visitor) error {
_, err := v.VisitEnumValue(ev)
if ev.err != nil {
return ev.err
}
return err
}