@@ -193,7 +193,6 @@ const INTERPOLATE_STRING: &str = "Interpolate string";
193193const FILL_UNUSED_FIELDS : & str = "Fill unused fields" ;
194194const REMOVE_ALL_ECHOS_FROM_THIS_MODULE : & str = "Remove all `echo`s from this module" ;
195195const WRAP_IN_BLOCK : & str = "Wrap in block" ;
196- const GENERATE_VARIANT : & str = "Generate variant" ;
197196const REMOVE_BLOCK : & str = "Remove block" ;
198197const REMOVE_OPAQUE_FROM_PRIVATE_TYPE : & str = "Remove opaque from private type" ;
199198const COLLAPSE_NESTED_CASE : & str = "Collapse nested case" ;
@@ -211,6 +210,10 @@ const ADD_EXTRA_PARENTHESES: &str = "Add extra parentheses";
211210const CONVERT_TO_DOCUMENTATION_COMMENT : & str = "Convert to documentation comment" ;
212211const CONVERT_TO_REGULAR_COMMENT : & str = "Convert to regular comment" ;
213212
213+ fn generate_variant_message ( type_name : & str ) -> String {
214+ format ! ( "Generate `{type_name}` variant" )
215+ }
216+
214217macro_rules! assert_code_action {
215218 ( $title: expr, $code: literal, $range_selector: expr $( , ) ?) => {
216219 let project = TestProject :: for_source( $code) ;
@@ -291,6 +294,23 @@ macro_rules! assert_no_code_actions {
291294 ) ;
292295 assert_eq!( expected, result) ;
293296 } ;
297+
298+ ( $title: expr, $code: literal, $range_selector: expr $( , ) ?) => {
299+ let project = TestProject :: for_source( $code) ;
300+ assert_no_code_actions!( $title, project, $range_selector) ;
301+ } ;
302+
303+ ( $title: expr, $project: expr, $range_selector: expr $( , ) ?) => {
304+ let expected: Vec <lsp_types:: CodeAction > = vec![ ] ;
305+ let result = actions_with_title(
306+ vec![ $title] ,
307+ & $project,
308+ Origin :: Src ,
309+ LSP_TEST_ROOT_PACKAGE_NAME ,
310+ $range_selector
311+ ) ;
312+ assert_eq!( expected, result) ;
313+ } ;
294314}
295315
296316#[ test]
@@ -322,7 +342,7 @@ pub fn main() {
322342#[ test]
323343fn generate_variant_with_fields_in_same_module ( ) {
324344 assert_code_action ! (
325- GENERATE_VARIANT ,
345+ & generate_variant_message ( "Wibble" ) ,
326346 r#"
327347pub type Wibble {
328348 Wibble
@@ -338,7 +358,7 @@ pub fn main() -> Wibble {
338358#[ test]
339359fn generate_variant_with_no_fields_in_same_module ( ) {
340360 assert_code_action ! (
341- GENERATE_VARIANT ,
361+ & generate_variant_message ( "Wibble" ) ,
342362 r#"
343363pub type Wibble {
344364 Wibble
@@ -354,7 +374,7 @@ pub fn main() -> Wibble {
354374#[ test]
355375fn generate_variant_with_labels_in_same_module ( ) {
356376 assert_code_action ! (
357- GENERATE_VARIANT ,
377+ & generate_variant_message ( "Wibble" ) ,
358378 r#"
359379pub type Wibble {
360380 Wibble
@@ -370,7 +390,7 @@ pub fn main() -> Wibble {
370390#[ test]
371391fn generate_variant_from_pattern_with_fields ( ) {
372392 assert_code_action ! (
373- GENERATE_VARIANT ,
393+ & generate_variant_message ( "Wibble" ) ,
374394 r#"
375395pub type Wibble {
376396 Wibble
@@ -390,7 +410,7 @@ pub fn main() -> Wibble {
390410#[ test]
391411fn generate_variant_from_pattern_with_labelled_fields ( ) {
392412 assert_code_action ! (
393- GENERATE_VARIANT ,
413+ & generate_variant_message ( "Wibble" ) ,
394414 r#"
395415pub type Wibble {
396416 Wibble
@@ -410,7 +430,7 @@ pub fn main() -> Wibble {
410430#[ test]
411431fn generate_variant_from_pattern_with_no_fields ( ) {
412432 assert_code_action ! (
413- GENERATE_VARIANT ,
433+ & generate_variant_message ( "Wibble" ) ,
414434 r#"
415435pub type Wibble {
416436 Wibble
@@ -440,7 +460,7 @@ pub fn new() -> other.Wibble { todo }
440460"# ;
441461
442462 assert_code_action ! (
443- GENERATE_VARIANT ,
463+ & generate_variant_message ( "other.Wibble" ) ,
444464 TestProject :: for_source( src) . add_module( "other" , "pub type Wibble" ) ,
445465 find_position_of( "Wobble" ) . to_selection( )
446466 ) ;
@@ -460,7 +480,7 @@ pub fn new() -> other.Wibble { todo }
460480"# ;
461481
462482 assert_code_action ! (
463- GENERATE_VARIANT ,
483+ & generate_variant_message ( "other.Wibble" ) ,
464484 TestProject :: for_source( src) . add_module(
465485 "other" ,
466486 "pub type Wibble {
@@ -485,7 +505,7 @@ pub fn new() -> other.Wibble { todo }
485505"# ;
486506
487507 assert_code_action ! (
488- GENERATE_VARIANT ,
508+ & generate_variant_message ( "other.Wibble" ) ,
489509 TestProject :: for_source( src) . add_module(
490510 "other" ,
491511 "pub type Wibble {
@@ -508,7 +528,7 @@ pub fn main() -> other.Wibble {
508528pub fn new() -> other.Wibble { todo }
509529"# ;
510530 assert_code_action ! (
511- GENERATE_VARIANT ,
531+ & generate_variant_message ( "other.Wibble" ) ,
512532 TestProject :: for_source( src) . add_module( "other" , "pub type Wibble" ) ,
513533 find_position_of( "Wobble" ) . to_selection( )
514534 ) ;
@@ -517,7 +537,7 @@ pub fn new() -> other.Wibble { todo }
517537#[ test]
518538fn do_not_generate_variant_if_one_with_the_same_name_exists ( ) {
519539 assert_no_code_actions ! (
520- GENERATE_VARIANT ,
540+ & generate_variant_message ( "Wibble" ) ,
521541 r#"
522542pub fn main() -> Wibble {
523543 let assert Wobble = new()
@@ -545,7 +565,7 @@ pub fn main() -> Wibble {
545565pub fn new() -> Wibble { todo }
546566"# ;
547567 assert_no_code_actions ! (
548- GENERATE_VARIANT ,
568+ & generate_variant_message ( "Wibble" ) ,
549569 TestProject :: for_source( src) . add_module( "other" , "pub type Wibble { Wobble(String) }" ) ,
550570 find_position_of( "Wobble" ) . to_selection( )
551571 ) ;
@@ -563,7 +583,7 @@ pub fn main() -> Wibble {
563583pub fn new() -> Wibble { todo }
564584"# ;
565585 assert_no_code_actions ! (
566- GENERATE_VARIANT ,
586+ & generate_variant_message ( "Wibble" ) ,
567587 TestProject :: for_source( src) . add_module( "other" , "pub type Wibble { Wobble(String) }" ) ,
568588 find_position_of( "Wobble" ) . to_selection( )
569589 ) ;
0 commit comments