@@ -128,71 +128,69 @@ mod enum_config {
128
128
129
129
let config = config_for_enum ( & item) ?;
130
130
131
- assert_eq ! ( config. exclude, None ) ;
132
-
133
131
Ok ( ( ) )
134
132
}
135
133
136
134
#[ test]
137
- fn accepts_empty_exclude_attrs ( ) -> Result < ( ) , syn:: Error > {
135
+ fn rejects_unrecognized_exclude_attrs ( ) -> Result < ( ) , syn:: Error > {
138
136
let item: syn:: ItemEnum = parse_quote ! {
139
- #[ enumcapsulate( exclude) ]
137
+ #[ enumcapsulate( exclude( IntoVariant , Unrecognized ) ) ]
140
138
enum Dummy { }
141
139
} ;
142
140
143
- let config = config_for_enum ( & item) ?;
144
-
145
- let actual: Vec < syn:: Ident > = config. exclude . unwrap ( ) . idents ;
146
- let expected: Vec < syn:: Ident > = vec ! [ ] ;
141
+ let error = config_for_enum ( & item) . err ( ) . unwrap ( ) ;
147
142
148
- assert_eq ! ( actual , expected ) ;
143
+ assert_eq ! ( error . to_string ( ) , "unrecognized macro derive" ) ;
149
144
150
145
Ok ( ( ) )
151
146
}
152
147
153
- #[ test]
154
- fn accepts_non_empty_exclude_attrs ( ) -> Result < ( ) , syn:: Error > {
155
- let item: syn:: ItemEnum = parse_quote ! {
156
- #[ enumcapsulate( exclude( AsVariant , IntoVariant ) ) ]
157
- enum Dummy { }
158
- } ;
148
+ mod encapsulate {
149
+ use super :: * ;
159
150
160
- let config = config_for_enum ( & item) ?;
151
+ #[ test]
152
+ #[ should_panic]
153
+ fn rejects_empty_exclude_attrs ( ) -> Result < ( ) , syn:: Error > {
154
+ let item: syn:: ItemEnum = parse_quote ! {
155
+ #[ enumcapsulate( exclude) ]
156
+ enum Dummy { }
157
+ } ;
161
158
162
- let actual = config. exclude . unwrap ( ) . idents ;
163
- let expected: Vec < syn:: Ident > =
164
- vec ! [ parse_quote! { AsVariant } , parse_quote! { IntoVariant } ] ;
159
+ let config = encapsulate_config_for_enum ( & item) ?;
165
160
166
- assert_eq ! ( actual, expected) ;
161
+ Ok ( ( ) )
162
+ }
167
163
168
- Ok ( ( ) )
169
- }
164
+ #[ test]
165
+ fn accepts_non_empty_exclude_attrs ( ) -> Result < ( ) , syn:: Error > {
166
+ let item: syn:: ItemEnum = parse_quote ! {
167
+ #[ enumcapsulate( exclude( AsVariant , IntoVariant ) ) ]
168
+ enum Dummy { }
169
+ } ;
170
170
171
- #[ test]
172
- fn rejects_unrecognized_exclude_attrs ( ) -> Result < ( ) , syn:: Error > {
173
- let item: syn:: ItemEnum = parse_quote ! {
174
- #[ enumcapsulate( exclude( IntoVariant , Unrecognized ) ) ]
175
- enum Dummy { }
176
- } ;
171
+ let config = config_for_enum ( & item) ?;
177
172
178
- let error = config_for_enum ( & item) . err ( ) . unwrap ( ) ;
173
+ let actual = config. exclude . unwrap ( ) . idents ;
174
+ let expected: Vec < syn:: Ident > =
175
+ vec ! [ parse_quote! { AsVariant } , parse_quote! { IntoVariant } ] ;
179
176
180
- assert_eq ! ( error . to_string ( ) , "unrecognized macro derive" ) ;
177
+ assert_eq ! ( actual , expected ) ;
181
178
182
- Ok ( ( ) )
183
- }
179
+ Ok ( ( ) )
180
+ }
184
181
185
- #[ test]
186
- fn is_excluded ( ) {
187
- let config = EnumConfig {
188
- exclude : Some ( MacroSelectionConfig {
189
- idents : vec ! [ parse_quote! { FromVariant } , parse_quote! { IntoVariant } ] ,
190
- } ) ,
191
- } ;
182
+ #[ test]
183
+ fn is_excluded ( ) {
184
+ let config = EncapsulateEnumConfig {
185
+ exclude : Some ( MacroSelectionConfig {
186
+ idents : vec ! [ parse_quote! { FromVariant } , parse_quote! { IntoVariant } ] ,
187
+ } ) ,
188
+ } ;
192
189
193
- assert_eq ! ( config. is_excluded( "FromVariant" ) , true ) ;
194
- assert_eq ! ( config. is_excluded( "IntoVariant" ) , true ) ;
195
- assert_eq ! ( config. is_excluded( "AsVariant" ) , false ) ;
190
+ assert_eq ! ( config. is_excluded( "FromVariant" ) , true ) ;
191
+ assert_eq ! ( config. is_excluded( "IntoVariant" ) , true ) ;
192
+ assert_eq ! ( config. is_excluded( "AsVariant" ) , false ) ;
193
+ }
196
194
}
197
195
}
198
196
@@ -416,84 +414,8 @@ mod variant_config {
416
414
mod is_excluded {
417
415
use super :: * ;
418
416
419
- #[ test]
420
- fn no_enum_excludes ( ) {
421
- let enum_config = EnumConfig { exclude : None } ;
422
-
423
- let config = VariantConfig {
424
- exclude : None ,
425
- include : None ,
426
- field : None ,
427
- } ;
428
-
429
- assert_eq ! ( config. is_excluded( "FromVariant" , & enum_config) , false ) ;
430
- assert_eq ! ( config. is_excluded( "IntoVariant" , & enum_config) , false ) ;
431
- assert_eq ! ( config. is_excluded( "AsVariant" , & enum_config) , false ) ;
432
- }
433
-
434
- #[ test]
435
- fn only_enum_excludes ( ) {
436
- let enum_config = EnumConfig {
437
- exclude : Some ( MacroSelectionConfig {
438
- idents : vec ! [ parse_quote! { AsVariant } ] ,
439
- } ) ,
440
- } ;
441
-
442
- let config = VariantConfig {
443
- exclude : None ,
444
- include : None ,
445
- field : None ,
446
- } ;
447
-
448
- assert_eq ! ( config. is_excluded( "FromVariant" , & enum_config) , false ) ;
449
- assert_eq ! ( config. is_excluded( "IntoVariant" , & enum_config) , false ) ;
450
- assert_eq ! ( config. is_excluded( "AsVariant" , & enum_config) , true ) ;
451
- }
452
-
453
- #[ test]
454
- fn blanket_overridden_enum_excludes ( ) {
455
- let enum_config = EnumConfig {
456
- exclude : Some ( MacroSelectionConfig {
457
- idents : vec ! [ parse_quote! { AsVariant } ] ,
458
- } ) ,
459
- } ;
460
-
461
- let config = VariantConfig {
462
- exclude : None ,
463
- include : Some ( MacroSelectionConfig { idents : vec ! [ ] } ) ,
464
- field : None ,
465
- } ;
466
-
467
- assert_eq ! ( config. is_excluded( "FromVariant" , & enum_config) , false ) ;
468
- assert_eq ! ( config. is_excluded( "IntoVariant" , & enum_config) , false ) ;
469
- assert_eq ! ( config. is_excluded( "AsVariant" , & enum_config) , false ) ;
470
- }
471
-
472
- #[ test]
473
- fn selective_overridden_enum_excludes ( ) {
474
- let enum_config = EnumConfig {
475
- exclude : Some ( MacroSelectionConfig {
476
- idents : vec ! [ parse_quote! { AsVariant } , parse_quote! { IntoVariant } ] ,
477
- } ) ,
478
- } ;
479
-
480
- let config = VariantConfig {
481
- exclude : None ,
482
- include : Some ( MacroSelectionConfig {
483
- idents : vec ! [ parse_quote! { AsVariant } ] ,
484
- } ) ,
485
- field : None ,
486
- } ;
487
-
488
- assert_eq ! ( config. is_excluded( "FromVariant" , & enum_config) , false ) ;
489
- assert_eq ! ( config. is_excluded( "IntoVariant" , & enum_config) , true ) ;
490
- assert_eq ! ( config. is_excluded( "AsVariant" , & enum_config) , false ) ;
491
- }
492
-
493
417
#[ test]
494
418
fn selective_overridden_variant_excludes ( ) {
495
- let enum_config = EnumConfig { exclude : None } ;
496
-
497
419
let config = VariantConfig {
498
420
exclude : Some ( MacroSelectionConfig { idents : vec ! [ ] } ) ,
499
421
include : Some ( MacroSelectionConfig {
@@ -502,9 +424,9 @@ mod variant_config {
502
424
field : None ,
503
425
} ;
504
426
505
- assert_eq ! ( config. is_excluded( "FromVariant" , & enum_config ) , true ) ;
506
- assert_eq ! ( config. is_excluded( "IntoVariant" , & enum_config ) , true ) ;
507
- assert_eq ! ( config. is_excluded( "AsVariant" , & enum_config ) , false ) ;
427
+ assert_eq ! ( config. is_excluded( "FromVariant" ) , true ) ;
428
+ assert_eq ! ( config. is_excluded( "IntoVariant" ) , true ) ;
429
+ assert_eq ! ( config. is_excluded( "AsVariant" ) , false ) ;
508
430
}
509
431
}
510
432
}
0 commit comments