File tree 4 files changed +42
-2
lines changed
4 files changed +42
-2
lines changed Original file line number Diff line number Diff line change @@ -41,3 +41,9 @@ func MutateParams(pm ...ParamMutator) InitOption {
41
41
// disk. By default, the OS's file system is used. This option currently only
42
42
// impacts CustomFile and CustomTemplateFile artifacts generated by modules.
43
43
func FileSystem (fs afero.Fs ) InitOption { return func (g * Generator ) { g .persister .SetFS (fs ) } }
44
+
45
+ // BiDirectional instructs the Generator to build the AST graph in both
46
+ // directions (ie, accessing dependents of an entity, not just dependencies).
47
+ func BiDirectional () InitOption {
48
+ return func (g * Generator ) { g .workflow = & onceWorkflow {workflow : & standardWorkflow {BiDi : true }} }
49
+ }
Original file line number Diff line number Diff line change 9
9
10
10
"github.com/spf13/afero"
11
11
"github.com/stretchr/testify/assert"
12
+ "github.com/stretchr/testify/require"
12
13
)
13
14
14
15
func TestDebugMode (t * testing.T ) {
@@ -70,3 +71,21 @@ func TestProtocOutput(t *testing.T) {
70
71
ProtocOutput (b )(g )
71
72
assert .Equal (t , b , g .out )
72
73
}
74
+
75
+ func TestBiDirectional (t * testing.T ) {
76
+ t .Parallel ()
77
+
78
+ g := & Generator {}
79
+ assert .Nil (t , g .workflow )
80
+
81
+ BiDirectional ()(g )
82
+ wf := g .workflow
83
+
84
+ require .IsType (t , & onceWorkflow {}, wf )
85
+ once := wf .(* onceWorkflow )
86
+
87
+ require .IsType (t , & standardWorkflow {}, once .workflow )
88
+ std := once .workflow .(* standardWorkflow )
89
+
90
+ assert .True (t , std .BiDi )
91
+ }
Original file line number Diff line number Diff line change @@ -15,9 +15,12 @@ type workflow interface {
15
15
}
16
16
17
17
// standardWorkflow describes a typical protoc-plugin flow, with the only
18
- // exception being the behavior of the persistor directly writing custom file
18
+ // exception being the behavior of the persister directly writing custom file
19
19
// artifacts to disk (instead of via the plugin's output to protoc).
20
- type standardWorkflow struct { * Generator }
20
+ type standardWorkflow struct {
21
+ * Generator
22
+ BiDi bool
23
+ }
21
24
22
25
func (wf * standardWorkflow ) Init (g * Generator ) AST {
23
26
wf .Generator = g
@@ -38,6 +41,10 @@ func (wf *standardWorkflow) Init(g *Generator) AST {
38
41
pm (wf .params )
39
42
}
40
43
44
+ if wf .BiDi {
45
+ return ProcessCodeGeneratorRequestBidirectional (g , req )
46
+ }
47
+
41
48
return ProcessCodeGeneratorRequest (g , req )
42
49
}
43
50
Original file line number Diff line number Diff line change @@ -23,6 +23,14 @@ func TestStandardWorkflow_Init(t *testing.T) {
23
23
g .workflow .Init (g )
24
24
25
25
assert .True (t , mutated )
26
+
27
+ t .Run ("bidi" , func (t * testing.T ) {
28
+ mutated = false
29
+ g = Init (ProtocInput (bytes .NewReader (b )), BiDirectional (), MutateParams (func (p Parameters ) { mutated = true }))
30
+ g .workflow .Init (g )
31
+
32
+ assert .True (t , mutated )
33
+ })
26
34
}
27
35
28
36
func TestStandardWorkflow_Run (t * testing.T ) {
You can’t perform that action at this time.
0 commit comments