77// Needed for Clippy to accept #[cfg(all())] 
88#![ allow( clippy:: non_minimal_cfg) ]  
99
10+ use  crate :: framework:: itest; 
11+ use  godot:: engine:: ClassDb ; 
1012use  godot:: prelude:: * ; 
1113
1214#[ derive( GodotClass ) ]  
@@ -29,6 +31,26 @@ impl FuncRename {
2931    fn  renamed_static ( )  -> GodotString  { 
3032        GodotString :: from ( "static" ) 
3133    } 
34+ 
35+     #[ cfg( all( ) ) ]  
36+     fn  returns_hello_world ( & self )  -> GodotString  { 
37+         GodotString :: from ( "Hello world!" ) 
38+     } 
39+ 
40+     #[ cfg( any( ) ) ]  
41+     fn  returns_hello_world ( & self )  -> GodotString  { 
42+         compile_error ! ( "Removed by #[cfg]" ) 
43+     } 
44+ 
45+     #[ cfg( any( ) ) ]  
46+     fn  returns_bye_world ( & self )  -> GodotString  { 
47+         compile_error ! ( "Removed by #[cfg]" ) 
48+     } 
49+ 
50+     #[ cfg( all( ) ) ]  
51+     fn  returns_bye_world ( & self )  -> GodotString  { 
52+         GodotString :: from ( "Bye world!" ) 
53+     } 
3254} 
3355
3456impl  FuncRename  { 
@@ -89,6 +111,35 @@ impl GdSelfReference {
89111        f1 && f2
90112    } 
91113
114+     #[ func]  
115+     fn  cfg_removes_function ( )  -> bool  { 
116+         true 
117+     } 
118+ 
119+     #[ cfg( any( ) ) ]  
120+     #[ func]  
121+     fn  cfg_removes_function ( )  -> bool  { 
122+         false 
123+     } 
124+ 
125+     #[ func]  
126+     #[ cfg( any( ) ) ]  
127+     fn  cfg_removes_function ( )  -> bool  { 
128+         false 
129+     } 
130+ 
131+     #[ cfg( any( ) ) ]  
132+     #[ func]  
133+     fn  cfg_removes_function_ffi_glue ( )  -> bool  { 
134+         true 
135+     } 
136+ 
137+     #[ func]  
138+     #[ cfg( any( ) ) ]  
139+     fn  cfg_removes_function_ffi_glue ( )  -> bool  { 
140+         true 
141+     } 
142+ 
92143    #[ signal]  
93144    #[ rustfmt:: skip]  
94145    fn  signal_shouldnt_panic_with_segmented_path_attribute ( ) ; 
@@ -148,3 +199,36 @@ impl RefCountedVirtual for GdSelfReference {
148199        } 
149200    } 
150201} 
202+ 
203+ #[ itest]  
204+ fn  cfg_doesnt_interfere_with_valid_method_impls ( )  { 
205+     // if we re-implement this method but the re-implementation is removed, that should keep the non-removed 
206+     // implementation. 
207+     let  object = Gd :: new ( FuncRename ) ; 
208+     assert_eq ! ( 
209+         object. bind( ) . returns_hello_world( ) , 
210+         GodotString :: from( "Hello world!" ) 
211+     ) ; 
212+     assert_eq ! ( 
213+         object. bind( ) . returns_bye_world( ) , 
214+         GodotString :: from( "Bye world!" ) 
215+     ) ; 
216+ } 
217+ 
218+ #[ itest]  
219+ fn  cfg_removes_or_keeps_methods ( )  { 
220+     let  has_method = |name :  & str | { 
221+         ClassDb :: singleton ( ) 
222+             . class_has_method_ex ( GdSelfReference :: class_name ( ) . to_string_name ( ) ,  name. into ( ) ) 
223+             . no_inheritance ( true ) 
224+             . done ( ) 
225+     } ; 
226+     assert ! ( has_method( 
227+         "func_recognized_with_simple_path_attribute_above_func_attr" 
228+     ) ) ; 
229+     assert ! ( has_method( 
230+         "func_recognized_with_simple_path_attribute_below_func_attr" 
231+     ) ) ; 
232+     assert ! ( has_method( "cfg_removes_function" ) ) ; 
233+     assert ! ( !has_method( "cfg_removes_function_ffi_glue" ) ) ; 
234+ } 
0 commit comments