aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_mbe/src/lib.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_mbe/src/lib.rs')
-rw-r--r--crates/ra_mbe/src/lib.rs55
1 files changed, 54 insertions, 1 deletions
diff --git a/crates/ra_mbe/src/lib.rs b/crates/ra_mbe/src/lib.rs
index 4203929d4..a21ea4dbc 100644
--- a/crates/ra_mbe/src/lib.rs
+++ b/crates/ra_mbe/src/lib.rs
@@ -15,10 +15,13 @@ macro_rules! impl_froms {
15 } 15 }
16} 16}
17 17
18mod tt_cursor; 18// mod tt_cursor;
19mod mbe_parser; 19mod mbe_parser;
20mod mbe_expander; 20mod mbe_expander;
21mod syntax_bridge; 21mod syntax_bridge;
22mod tt_cursor;
23mod subtree_source;
24mod subtree_parser;
22 25
23use ra_syntax::SmolStr; 26use ra_syntax::SmolStr;
24 27
@@ -379,4 +382,54 @@ SOURCE_FILE@[0; 40)
379 // [let] [s] [=] ["rust1"] [;] 382 // [let] [s] [=] ["rust1"] [;]
380 assert_eq!(to_literal(&stm_tokens[15 + 3]).text, "\"rust1\""); 383 assert_eq!(to_literal(&stm_tokens[15 + 3]).text, "\"rust1\"");
381 } 384 }
385
386 #[test]
387 fn test_two_idents() {
388 let rules = create_rules(
389 r#"
390 macro_rules! foo {
391 ($ i:ident, $ j:ident) => {
392 fn foo() { let a = $ i; let b = $j; }
393 }
394 }
395"#,
396 );
397 assert_expansion(&rules, "foo! { foo, bar }", "fn foo () {let a = foo ; let b = bar ;}");
398 }
399
400 // The following tests are port from intellij-rust directly
401 // https://github.com/intellij-rust/intellij-rust/blob/c4e9feee4ad46e7953b1948c112533360b6087bb/src/test/kotlin/org/rust/lang/core/macros/RsMacroExpansionTest.kt
402
403 #[test]
404 fn test_path() {
405 let rules = create_rules(
406 r#"
407 macro_rules! foo {
408 ($ i:path) => {
409 fn foo() { let a = $ i; }
410 }
411 }
412"#,
413 );
414 assert_expansion(&rules, "foo! { foo }", "fn foo () {let a = foo ;}");
415 assert_expansion(
416 &rules,
417 "foo! { bar::<u8>::baz::<u8> }",
418 "fn foo () {let a = bar ::< u8 > ::baz ::< u8 > ;}",
419 );
420 }
421
422 #[test]
423 fn test_two_paths() {
424 let rules = create_rules(
425 r#"
426 macro_rules! foo {
427 ($ i:path, $ j:path) => {
428 fn foo() { let a = $ i; let b = $j; }
429 }
430 }
431"#,
432 );
433 assert_expansion(&rules, "foo! { foo, bar }", "fn foo () {let a = foo ; let b = bar ;}");
434 }
382} 435}