diff options
Diffstat (limited to 'crates/ra_mbe')
-rw-r--r-- | crates/ra_mbe/src/syntax_bridge.rs | 4 | ||||
-rw-r--r-- | crates/ra_mbe/src/tests.rs | 27 |
2 files changed, 15 insertions, 16 deletions
diff --git a/crates/ra_mbe/src/syntax_bridge.rs b/crates/ra_mbe/src/syntax_bridge.rs index 4639baa38..dce82f33d 100644 --- a/crates/ra_mbe/src/syntax_bridge.rs +++ b/crates/ra_mbe/src/syntax_bridge.rs | |||
@@ -384,7 +384,7 @@ mod tests { | |||
384 | } | 384 | } |
385 | "#, | 385 | "#, |
386 | ); | 386 | ); |
387 | let expansion = expand(&rules, "literals!(foo)"); | 387 | let expansion = expand(&rules, "literals!(foo);"); |
388 | let buffer = tt::buffer::TokenBuffer::new(&[expansion.clone().into()]); | 388 | let buffer = tt::buffer::TokenBuffer::new(&[expansion.clone().into()]); |
389 | let mut tt_src = SubtreeTokenSource::new(&buffer); | 389 | let mut tt_src = SubtreeTokenSource::new(&buffer); |
390 | let mut tokens = vec![]; | 390 | let mut tokens = vec![]; |
@@ -423,7 +423,7 @@ mod tests { | |||
423 | } | 423 | } |
424 | "#, | 424 | "#, |
425 | ); | 425 | ); |
426 | let expansion = expand(&rules, "stmts!()"); | 426 | let expansion = expand(&rules, "stmts!();"); |
427 | assert!(token_tree_to_expr(&expansion).is_err()); | 427 | assert!(token_tree_to_expr(&expansion).is_err()); |
428 | } | 428 | } |
429 | } | 429 | } |
diff --git a/crates/ra_mbe/src/tests.rs b/crates/ra_mbe/src/tests.rs index 5e4017f77..1db35cd8d 100644 --- a/crates/ra_mbe/src/tests.rs +++ b/crates/ra_mbe/src/tests.rs | |||
@@ -95,7 +95,7 @@ pub(crate) fn expand_to_expr( | |||
95 | pub(crate) fn text_to_tokentree(text: &str) -> tt::Subtree { | 95 | pub(crate) fn text_to_tokentree(text: &str) -> tt::Subtree { |
96 | // wrap the given text to a macro call | 96 | // wrap the given text to a macro call |
97 | let wrapped = format!("wrap_macro!( {} )", text); | 97 | let wrapped = format!("wrap_macro!( {} )", text); |
98 | let wrapped = ast::SourceFile::parse(&wrapped).ok().unwrap(); | 98 | let wrapped = ast::SourceFile::parse(&wrapped).tree; |
99 | let wrapped = wrapped.syntax().descendants().find_map(ast::TokenTree::cast).unwrap(); | 99 | let wrapped = wrapped.syntax().descendants().find_map(ast::TokenTree::cast).unwrap(); |
100 | let mut wrapped = ast_to_token_tree(wrapped).unwrap().0; | 100 | let mut wrapped = ast_to_token_tree(wrapped).unwrap().0; |
101 | wrapped.delimiter = tt::Delimiter::None; | 101 | wrapped.delimiter = tt::Delimiter::None; |
@@ -378,7 +378,7 @@ fn test_match_group_with_multichar_sep() { | |||
378 | assert_expansion( | 378 | assert_expansion( |
379 | MacroKind::Items, | 379 | MacroKind::Items, |
380 | &rules, | 380 | &rules, |
381 | "foo! (fn baz {true true} )", | 381 | "foo! (fn baz {true true} );", |
382 | "fn baz () -> bool {true &&true}", | 382 | "fn baz () -> bool {true &&true}", |
383 | ); | 383 | ); |
384 | } | 384 | } |
@@ -392,7 +392,7 @@ fn test_match_group_zero_match() { | |||
392 | }"#, | 392 | }"#, |
393 | ); | 393 | ); |
394 | 394 | ||
395 | assert_expansion(MacroKind::Items, &rules, "foo! ()", ""); | 395 | assert_expansion(MacroKind::Items, &rules, "foo! ();", ""); |
396 | } | 396 | } |
397 | 397 | ||
398 | #[test] | 398 | #[test] |
@@ -404,7 +404,7 @@ fn test_match_group_in_group() { | |||
404 | }"#, | 404 | }"#, |
405 | ); | 405 | ); |
406 | 406 | ||
407 | assert_expansion(MacroKind::Items, &rules, "foo! ( (a b) )", "(a b)"); | 407 | assert_expansion(MacroKind::Items, &rules, "foo! ( (a b) );", "(a b)"); |
408 | } | 408 | } |
409 | 409 | ||
410 | #[test] | 410 | #[test] |
@@ -418,7 +418,7 @@ fn test_expand_to_item_list() { | |||
418 | } | 418 | } |
419 | ", | 419 | ", |
420 | ); | 420 | ); |
421 | let expansion = expand(&rules, "structs!(Foo, Bar)"); | 421 | let expansion = expand(&rules, "structs!(Foo, Bar);"); |
422 | let tree = token_tree_to_macro_items(&expansion); | 422 | let tree = token_tree_to_macro_items(&expansion); |
423 | assert_eq!( | 423 | assert_eq!( |
424 | tree.unwrap().syntax().debug_dump().trim(), | 424 | tree.unwrap().syntax().debug_dump().trim(), |
@@ -490,7 +490,7 @@ fn test_expand_literals_to_token_tree() { | |||
490 | } | 490 | } |
491 | "#, | 491 | "#, |
492 | ); | 492 | ); |
493 | let expansion = expand(&rules, "literals!(foo)"); | 493 | let expansion = expand(&rules, "literals!(foo);"); |
494 | let stm_tokens = &to_subtree(&expansion.token_trees[0]).token_trees; | 494 | let stm_tokens = &to_subtree(&expansion.token_trees[0]).token_trees; |
495 | 495 | ||
496 | // [let] [a] [=] ['c'] [;] | 496 | // [let] [a] [=] ['c'] [;] |
@@ -586,7 +586,7 @@ fn test_match_literal() { | |||
586 | } | 586 | } |
587 | "#, | 587 | "#, |
588 | ); | 588 | ); |
589 | assert_expansion(MacroKind::Items, &rules, "foo! ['(']", "fn foo () {}"); | 589 | assert_expansion(MacroKind::Items, &rules, "foo! ['('];", "fn foo () {}"); |
590 | } | 590 | } |
591 | 591 | ||
592 | // The following tests are port from intellij-rust directly | 592 | // The following tests are port from intellij-rust directly |
@@ -725,7 +725,7 @@ fn test_last_expr() { | |||
725 | assert_expansion( | 725 | assert_expansion( |
726 | MacroKind::Items, | 726 | MacroKind::Items, |
727 | &rules, | 727 | &rules, |
728 | "vec!(1,2,3)", | 728 | "vec!(1,2,3);", |
729 | "{let mut v = Vec :: new () ; v . push (1) ; v . push (2) ; v . push (3) ; v}", | 729 | "{let mut v = Vec :: new () ; v . push (1) ; v . push (2) ; v . push (3) ; v}", |
730 | ); | 730 | ); |
731 | } | 731 | } |
@@ -902,7 +902,7 @@ fn test_meta_doc_comments() { | |||
902 | MultiLines Doc | 902 | MultiLines Doc |
903 | */ | 903 | */ |
904 | }"#, | 904 | }"#, |
905 | "# [doc = \" Single Line Doc 1\"] # [doc = \" \\\\n MultiLines Doc\\\\n \"] fn bar () {}", | 905 | "# [doc = \" Single Line Doc 1\"] # [doc = \"\\\\n MultiLines Doc\\\\n \"] fn bar () {}", |
906 | ); | 906 | ); |
907 | } | 907 | } |
908 | 908 | ||
@@ -950,7 +950,7 @@ fn test_literal() { | |||
950 | } | 950 | } |
951 | "#, | 951 | "#, |
952 | ); | 952 | ); |
953 | assert_expansion(MacroKind::Items, &rules, r#"foo!(u8 0)"#, r#"const VALUE : u8 = 0 ;"#); | 953 | assert_expansion(MacroKind::Items, &rules, r#"foo!(u8 0);"#, r#"const VALUE : u8 = 0 ;"#); |
954 | } | 954 | } |
955 | 955 | ||
956 | #[test] | 956 | #[test] |
@@ -1017,12 +1017,12 @@ fn test_vec() { | |||
1017 | assert_expansion( | 1017 | assert_expansion( |
1018 | MacroKind::Items, | 1018 | MacroKind::Items, |
1019 | &rules, | 1019 | &rules, |
1020 | r#"vec![1u32,2]"#, | 1020 | r#"vec![1u32,2];"#, |
1021 | r#"{let mut v = Vec :: new () ; v . push (1u32) ; v . push (2) ; v}"#, | 1021 | r#"{let mut v = Vec :: new () ; v . push (1u32) ; v . push (2) ; v}"#, |
1022 | ); | 1022 | ); |
1023 | 1023 | ||
1024 | assert_eq!( | 1024 | assert_eq!( |
1025 | expand_to_expr(&rules, r#"vec![1u32,2]"#).syntax().debug_dump().trim(), | 1025 | expand_to_expr(&rules, r#"vec![1u32,2];"#).syntax().debug_dump().trim(), |
1026 | r#"BLOCK_EXPR@[0; 45) | 1026 | r#"BLOCK_EXPR@[0; 45) |
1027 | BLOCK@[0; 45) | 1027 | BLOCK@[0; 45) |
1028 | L_CURLY@[0; 1) "{" | 1028 | L_CURLY@[0; 1) "{" |
@@ -1161,7 +1161,7 @@ macro_rules! generate_pattern_iterators { | |||
1161 | "#, | 1161 | "#, |
1162 | ); | 1162 | ); |
1163 | 1163 | ||
1164 | assert_expansion(MacroKind::Items, &rules, r#"generate_pattern_iterators ! ( double ended ; with # [ stable ( feature = "rust1" , since = "1.0.0" ) ] , Split , RSplit , & 'a str )"#, | 1164 | assert_expansion(MacroKind::Items, &rules, r#"generate_pattern_iterators ! ( double ended ; with # [ stable ( feature = "rust1" , since = "1.0.0" ) ] , Split , RSplit , & 'a str );"#, |
1165 | "fn foo () {}"); | 1165 | "fn foo () {}"); |
1166 | } | 1166 | } |
1167 | 1167 | ||
@@ -1208,7 +1208,6 @@ $body: block; )+ | |||
1208 | )+ | 1208 | )+ |
1209 | } | 1209 | } |
1210 | } | 1210 | } |
1211 | } | ||
1212 | "#, | 1211 | "#, |
1213 | ); | 1212 | ); |
1214 | 1213 | ||