@@ -7,6 +7,8 @@ use scarb_proc_macro_server_types::methods::expand::ExpandAttribute;
7
7
use scarb_proc_macro_server_types:: methods:: expand:: ExpandAttributeParams ;
8
8
use scarb_proc_macro_server_types:: methods:: expand:: ExpandDerive ;
9
9
use scarb_proc_macro_server_types:: methods:: expand:: ExpandDeriveParams ;
10
+ use scarb_proc_macro_server_types:: methods:: expand:: ExpandInline ;
11
+ use scarb_proc_macro_server_types:: methods:: expand:: ExpandInlineMacroParams ;
10
12
use scarb_test_support:: cairo_plugin_project_builder:: CairoPluginProjectBuilder ;
11
13
use scarb_test_support:: proc_macro_server:: ProcMacroClient ;
12
14
use scarb_test_support:: proc_macro_server:: SIMPLE_MACROS ;
@@ -126,3 +128,46 @@ fn expand_derive() {
126
128
TokenStream :: new( "impl SomeImpl of SomeTrait {}" . to_string( ) )
127
129
) ;
128
130
}
131
+
132
+ #[ test]
133
+ fn expand_inline ( ) {
134
+ let t = TempDir :: new ( ) . unwrap ( ) ;
135
+ let plugin_package = t. child ( "some" ) ;
136
+
137
+ let replace_all_15_with_25 = r#"
138
+ #[inline_macro]
139
+ pub fn replace_all_15_with_25(token_stream: TokenStream) -> ProcMacroResult {
140
+ ProcMacroResult::new(TokenStream::new(token_stream.to_string().replace("15", "25")))
141
+ }
142
+ "# ;
143
+
144
+ CairoPluginProjectBuilder :: default ( )
145
+ . lib_rs ( format ! ( "{SIMPLE_MACROS}\n {replace_all_15_with_25}" ) )
146
+ . build ( & plugin_package) ;
147
+
148
+ let project = t. child ( "test_package" ) ;
149
+
150
+ ProjectBuilder :: start ( )
151
+ . name ( "test_package" )
152
+ . version ( "1.0.0" )
153
+ . lib_cairo ( "" )
154
+ . dep ( "some" , plugin_package)
155
+ . build ( & project) ;
156
+
157
+ let mut proc_macro_server = ProcMacroClient :: new ( & project) ;
158
+
159
+ let response = proc_macro_server
160
+ . request_and_wait :: < ExpandInline > ( ExpandInlineMacroParams {
161
+ name : "replace_all_15_with_25" . to_string ( ) ,
162
+ args : TokenStream :: new (
163
+ "struct A { field: 15 , other_field: macro_call!(12)}" . to_string ( ) ,
164
+ ) ,
165
+ } )
166
+ . unwrap ( ) ;
167
+
168
+ assert_eq ! ( response. diagnostics, vec![ ] ) ;
169
+ assert_eq ! (
170
+ response. token_stream,
171
+ TokenStream :: new( "struct A { field: 25 , other_field: macro_call!(12)}" . to_string( ) )
172
+ ) ;
173
+ }
0 commit comments