@@ -501,4 +501,42 @@ mod tests {
501
501
assert_eq ! ( params, vec![ [ 0 , 21 ] , [ 23 , 38 ] ] ) ;
502
502
assert_eq ! ( signature_help. active_parameter. unwrap( ) , 0 ) ;
503
503
}
504
+
505
+ #[ test]
506
+ fn handle_execute_command_new_project_works ( ) {
507
+ // Initializes memory.
508
+ let mut memory = Memory :: new ( ) ;
509
+
510
+ // Creates test project.
511
+ let project_name = "hello_ink" ;
512
+ let project_uri = lsp_types:: Url :: parse ( "file:///tmp/hello_ink/" ) . unwrap ( ) ;
513
+
514
+ // Calls handler and verifies that the expected response is returned.
515
+ let result = handle_execute_command (
516
+ lsp_types:: ExecuteCommandParams {
517
+ command : "createProject" . to_string ( ) ,
518
+ arguments : vec ! [ serde_json:: json!( {
519
+ "name" : project_name,
520
+ "root" : project_uri
521
+ } ) ] ,
522
+ work_done_progress_params : Default :: default ( ) ,
523
+ } ,
524
+ & mut memory,
525
+ & simple_client_config ( ) ,
526
+ ) ;
527
+ assert ! ( result. is_ok( ) ) ;
528
+ let resp: CreateProjectResponse = serde_json:: from_value ( result. unwrap ( ) . unwrap ( ) ) . unwrap ( ) ;
529
+ // Verifies project metadata.
530
+ assert_eq ! ( resp. name, project_name) ;
531
+ assert_eq ! ( resp. uri, project_uri) ;
532
+ // Verifies project files and their contents.
533
+ let lib_uri = project_uri. clone ( ) . join ( "lib.rs" ) . unwrap ( ) ;
534
+ let cargo_uri = project_uri. clone ( ) . join ( "Cargo.toml" ) . unwrap ( ) ;
535
+ let lib_content = resp. files . get ( & lib_uri) . unwrap ( ) ;
536
+ let cargo_content = resp. files . get ( & cargo_uri) . unwrap ( ) ;
537
+ assert ! ( resp. files. contains_key( & lib_uri) ) ;
538
+ assert ! ( resp. files. contains_key( & cargo_uri) ) ;
539
+ assert ! ( lib_content. contains( "#[ink::contract]\n pub mod hello_ink {" ) ) ;
540
+ assert ! ( cargo_content. contains( r#"name = "hello_ink""# ) ) ;
541
+ }
504
542
}
0 commit comments