@@ -21,11 +21,11 @@ pub(crate) fn world_init(
21
21
) -> syn:: Result < TokenStream > {
22
22
let input = syn:: parse2 :: < syn:: DeriveInput > ( input) ?;
23
23
24
- let step_types = step_types ( steps) ;
25
- let step_structs = generate_step_structs ( steps, & input) ;
26
-
27
24
let world = & input. ident ;
28
25
26
+ let step_types = step_types ( steps, world) ;
27
+ let step_structs = generate_step_structs ( steps, & input) ;
28
+
29
29
Ok ( quote ! {
30
30
impl :: cucumber:: codegen:: WorldInventory <
31
31
#( #step_types, ) *
@@ -38,12 +38,12 @@ pub(crate) fn world_init(
38
38
/// Generates [`syn::Ident`]s of generic types for private trait impl.
39
39
///
40
40
/// [`syn::Ident`]: struct@syn::Ident
41
- fn step_types ( steps : & [ & str ] ) -> Vec < syn:: Ident > {
41
+ fn step_types ( steps : & [ & str ] , world : & syn :: Ident ) -> Vec < syn:: Ident > {
42
42
steps
43
43
. iter ( )
44
44
. map ( |step| {
45
45
let step = to_pascal_case ( step) ;
46
- format_ident ! ( "Cucumber{}" , step)
46
+ format_ident ! ( "Cucumber{}{} " , step, world )
47
47
} )
48
48
. collect ( )
49
49
}
@@ -55,7 +55,7 @@ fn generate_step_structs(
55
55
) -> Vec < TokenStream > {
56
56
let ( world, world_vis) = ( & world. ident , & world. vis ) ;
57
57
58
- step_types ( steps)
58
+ step_types ( steps, world )
59
59
. iter ( )
60
60
. map ( |ty| {
61
61
quote ! {
@@ -101,3 +101,152 @@ fn generate_step_structs(
101
101
} )
102
102
. collect ( )
103
103
}
104
+
105
+ #[ cfg( test) ]
106
+ mod spec {
107
+ use quote:: quote;
108
+ use syn:: parse_quote;
109
+
110
+ #[ test]
111
+ fn expand ( ) {
112
+ let input = parse_quote ! {
113
+ pub struct World ;
114
+ } ;
115
+
116
+ let output = quote ! {
117
+ impl :: cucumber:: codegen:: WorldInventory <
118
+ CucumberGivenWorld , CucumberWhenWorld , CucumberThenWorld ,
119
+ > for World { }
120
+
121
+ #[ automatically_derived]
122
+ #[ doc( hidden) ]
123
+ pub struct CucumberGivenWorld {
124
+ #[ doc( hidden) ]
125
+ pub loc: :: cucumber:: step:: Location ,
126
+
127
+ #[ doc( hidden) ]
128
+ pub regex: :: cucumber:: codegen:: Regex ,
129
+
130
+ #[ doc( hidden) ]
131
+ pub func: :: cucumber:: Step <World >,
132
+ }
133
+
134
+ #[ automatically_derived]
135
+ impl :: cucumber:: codegen:: StepConstructor <World > for
136
+ CucumberGivenWorld
137
+ {
138
+ fn new (
139
+ loc: :: cucumber:: step:: Location ,
140
+ regex: :: cucumber:: codegen:: Regex ,
141
+ func: :: cucumber:: Step <World >,
142
+ ) -> Self {
143
+ Self { loc, regex, func }
144
+ }
145
+
146
+ fn inner( & self ) -> (
147
+ :: cucumber:: step:: Location ,
148
+ :: cucumber:: codegen:: Regex ,
149
+ :: cucumber:: Step <World >,
150
+ ) {
151
+ (
152
+ self . loc. clone( ) ,
153
+ self . regex. clone( ) ,
154
+ self . func. clone( ) ,
155
+ )
156
+ }
157
+ }
158
+
159
+ #[ automatically_derived]
160
+ :: cucumber:: codegen:: collect!( CucumberGivenWorld ) ;
161
+
162
+ #[ automatically_derived]
163
+ #[ doc( hidden) ]
164
+ pub struct CucumberWhenWorld {
165
+ #[ doc( hidden) ]
166
+ pub loc: :: cucumber:: step:: Location ,
167
+
168
+ #[ doc( hidden) ]
169
+ pub regex: :: cucumber:: codegen:: Regex ,
170
+
171
+ #[ doc( hidden) ]
172
+ pub func: :: cucumber:: Step <World >,
173
+ }
174
+
175
+ #[ automatically_derived]
176
+ impl :: cucumber:: codegen:: StepConstructor <World > for
177
+ CucumberWhenWorld
178
+ {
179
+ fn new (
180
+ loc: :: cucumber:: step:: Location ,
181
+ regex: :: cucumber:: codegen:: Regex ,
182
+ func: :: cucumber:: Step <World >,
183
+ ) -> Self {
184
+ Self { loc, regex, func }
185
+ }
186
+
187
+ fn inner( & self ) -> (
188
+ :: cucumber:: step:: Location ,
189
+ :: cucumber:: codegen:: Regex ,
190
+ :: cucumber:: Step <World >,
191
+ ) {
192
+ (
193
+ self . loc. clone( ) ,
194
+ self . regex. clone( ) ,
195
+ self . func. clone( ) ,
196
+ )
197
+ }
198
+ }
199
+
200
+ #[ automatically_derived]
201
+ :: cucumber:: codegen:: collect!( CucumberWhenWorld ) ;
202
+
203
+ #[ automatically_derived]
204
+ #[ doc( hidden) ]
205
+ pub struct CucumberThenWorld {
206
+ #[ doc( hidden) ]
207
+ pub loc: :: cucumber:: step:: Location ,
208
+
209
+ #[ doc( hidden) ]
210
+ pub regex: :: cucumber:: codegen:: Regex ,
211
+
212
+ #[ doc( hidden) ]
213
+ pub func: :: cucumber:: Step <World >,
214
+ }
215
+
216
+ #[ automatically_derived]
217
+ impl :: cucumber:: codegen:: StepConstructor <World > for
218
+ CucumberThenWorld
219
+ {
220
+ fn new (
221
+ loc: :: cucumber:: step:: Location ,
222
+ regex: :: cucumber:: codegen:: Regex ,
223
+ func: :: cucumber:: Step <World >,
224
+ ) -> Self {
225
+ Self { loc, regex, func }
226
+ }
227
+
228
+ fn inner( & self ) -> (
229
+ :: cucumber:: step:: Location ,
230
+ :: cucumber:: codegen:: Regex ,
231
+ :: cucumber:: Step <World >,
232
+ ) {
233
+ (
234
+ self . loc. clone( ) ,
235
+ self . regex. clone( ) ,
236
+ self . func. clone( ) ,
237
+ )
238
+ }
239
+ }
240
+
241
+ #[ automatically_derived]
242
+ :: cucumber:: codegen:: collect!( CucumberThenWorld ) ;
243
+ } ;
244
+
245
+ assert_eq ! (
246
+ super :: world_init( input, & [ "given" , "when" , "then" ] )
247
+ . unwrap( )
248
+ . to_string( ) ,
249
+ output. to_string( ) ,
250
+ ) ;
251
+ }
252
+ }
0 commit comments