From 04af290d4e08e282dda0c0273f20a46f381224f4 Mon Sep 17 00:00:00 2001 From: Edwin Cheng Date: Mon, 4 Nov 2019 23:22:18 +0800 Subject: Add TokenId Shif in macro_rules --- crates/ra_mbe/src/tests.rs | 27 +++++++++++++++++++++++++++ 1 file changed, 27 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 f34ab52e1..a23e3afe3 100644 --- a/crates/ra_mbe/src/tests.rs +++ b/crates/ra_mbe/src/tests.rs @@ -58,6 +58,33 @@ mod rule_parsing { // * Port the test to rust and add it to this module // * Make it pass :-) +#[test] +fn test_token_id_shift() { + let macro_definition = r#" +macro_rules! foobar { + ($e:ident) => { foo bar $e } +} +"#; + let rules = create_rules(macro_definition); + let expansion = expand(&rules, "foobar!(baz);"); + + fn get_id(t: &tt::TokenTree) -> Option { + if let tt::TokenTree::Leaf(tt::Leaf::Ident(ident)) = t { + return Some(ident.id.0); + } + None + } + + assert_eq!(expansion.token_trees.len(), 3); + // ($e:ident) => { foo bar $e } + // 0 1 2 3 4 + assert_eq!(get_id(&expansion.token_trees[0]), Some(2)); + assert_eq!(get_id(&expansion.token_trees[1]), Some(3)); + + // So baz should be 5 + assert_eq!(get_id(&expansion.token_trees[2]), Some(5)); +} + #[test] fn test_convert_tt() { let macro_definition = r#" -- cgit v1.2.3