diff options
Diffstat (limited to 'crates/ra_mbe/src/tests.rs')
-rw-r--r-- | crates/ra_mbe/src/tests.rs | 27 |
1 files changed, 27 insertions, 0 deletions
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 | |||
@@ -59,6 +59,33 @@ mod rule_parsing { | |||
59 | // * Make it pass :-) | 59 | // * Make it pass :-) |
60 | 60 | ||
61 | #[test] | 61 | #[test] |
62 | fn test_token_id_shift() { | ||
63 | let macro_definition = r#" | ||
64 | macro_rules! foobar { | ||
65 | ($e:ident) => { foo bar $e } | ||
66 | } | ||
67 | "#; | ||
68 | let rules = create_rules(macro_definition); | ||
69 | let expansion = expand(&rules, "foobar!(baz);"); | ||
70 | |||
71 | fn get_id(t: &tt::TokenTree) -> Option<u32> { | ||
72 | if let tt::TokenTree::Leaf(tt::Leaf::Ident(ident)) = t { | ||
73 | return Some(ident.id.0); | ||
74 | } | ||
75 | None | ||
76 | } | ||
77 | |||
78 | assert_eq!(expansion.token_trees.len(), 3); | ||
79 | // ($e:ident) => { foo bar $e } | ||
80 | // 0 1 2 3 4 | ||
81 | assert_eq!(get_id(&expansion.token_trees[0]), Some(2)); | ||
82 | assert_eq!(get_id(&expansion.token_trees[1]), Some(3)); | ||
83 | |||
84 | // So baz should be 5 | ||
85 | assert_eq!(get_id(&expansion.token_trees[2]), Some(5)); | ||
86 | } | ||
87 | |||
88 | #[test] | ||
62 | fn test_convert_tt() { | 89 | fn test_convert_tt() { |
63 | let macro_definition = r#" | 90 | let macro_definition = r#" |
64 | macro_rules! impl_froms { | 91 | macro_rules! impl_froms { |