@@ -194,4 +194,47 @@ fn interpret_child_output(generator_path_str: &str, output: String) -> Result<St
194
194
description : format ! ( "[{}] {}." , generator_path_str, string) ,
195
195
} )
196
196
}
197
+ }
198
+
199
+
200
+ #[ cfg( test) ]
201
+ mod test {
202
+ use std:: collections:: HashMap ;
203
+ use std:: path:: PathBuf ;
204
+ use crate :: { generate_processors, Stream } ;
205
+ use crate :: processors:: Processor ;
206
+
207
+ #[ test]
208
+ fn should_generate_function ( ) {
209
+ let stream = Stream {
210
+ input_topic : "abc" . to_string ( ) ,
211
+ output_topic : "def" . to_string ( ) ,
212
+ processors : vec ! [
213
+ HashMap :: from( [
214
+ ( "generator" . to_string( ) , "test_generator" . to_string( ) ) ,
215
+ ( "field" . to_string( ) , "static_field0" . to_string( ) ) ,
216
+ ( "value" . to_string( ) , "hello world" . to_string( ) ) ,
217
+ ] )
218
+ ]
219
+ } ;
220
+ let mut generators: HashMap < String , PathBuf > = HashMap :: new ( ) ;
221
+ generators. insert ( "test_generator" . to_string ( ) , PathBuf :: from ( "../kjp-generator-generators/static_field.sh" ) ) ;
222
+
223
+ let result = generate_processors ( stream, & generators) ;
224
+ match result {
225
+ Ok ( actual) =>
226
+ assert_eq ! ( vec![
227
+ Processor {
228
+ function_name: "abc_def_0_test_generator" . to_string( ) ,
229
+ function_body: r#"fn abc_def_0_test_generator(_input: &Value, message: &mut OutputMessage) -> Result<(), ProcessingError> {
230
+ message.insert_val(&[Key("static_field0".to_string())], Value::String("hello world".to_string()))?;
231
+ Ok(())
232
+ }
233
+ "# . to_string( )
234
+ } ,
235
+ ] , actual) ,
236
+ Err ( e) =>
237
+ assert_eq ! ( "Ok(_)" , & format!( "Err({e})" ) ) ,
238
+ }
239
+ }
197
240
}
0 commit comments