From 6d84dee4e7d70f329df71365f98b2421652b2432 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vincent=20Rouill=C3=A9?= Date: Sat, 28 Dec 2019 22:26:24 +0100 Subject: fix #2520: change expand_repeat loop stop condition --- crates/ra_mbe/src/tests.rs | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) (limited to 'crates/ra_mbe/src/tests.rs') diff --git a/crates/ra_mbe/src/tests.rs b/crates/ra_mbe/src/tests.rs index e640d115b..288366cca 100644 --- a/crates/ra_mbe/src/tests.rs +++ b/crates/ra_mbe/src/tests.rs @@ -1491,3 +1491,49 @@ fn debug_dump_ignore_spaces(node: &ra_syntax::SyntaxNode) -> String { buf } + +#[test] +fn test_issue_2520() { + let macro_fixture = parse_macro( + r#" + macro_rules! my_macro { + { + ( $( + $( [] $sname:ident : $stype:ty )? + $( [$expr:expr] $nname:ident : $ntype:ty )? + ),* ) + } => { + Test { + $( + $( $sname, )? + )* + } + }; + } + "#, + ); + + macro_fixture.assert_expand_items( + r#"my_macro ! { + ([] p1 : u32 , [|_| S0K0] s : S0K0 , [] k0 : i32) + }"#, + "Test {p1 , k0 ,}", + ); +} + +#[test] +fn test_repeat_bad_var() { + parse_macro( + r#" + macro_rules! foo { + ($( $b:ident )+) => { + $( $c )+ + }; + ($( $b:ident )+) => { + $( $b )+ + } + } + "#, + ) + .assert_expand_items("foo!(b0 b1);", "b0 b1"); +} -- cgit v1.2.3