blob: b99ef2b23673ded5ef3c6455dbf57d172a6b0010 [file] [log] [blame]
bstrie7b4f52d2019-04-30 18:44:21 -04001extern crate proc_macro2;
2extern crate syn;
3
4use std::str::FromStr;
5
6use proc_macro2::TokenStream;
7use syn::{Expr, parse2};
8
9#[test]
10fn test_expr_parse() {
11 macro_rules! test_equiv {
12 ($code:ident, $old:ident, $new:ident) => (
13 let tt = TokenStream::from_str($code).unwrap();
14 //println!("--- tt ---\n{:?}\n", tt);
15 let ast1: Expr = parse2(tt.clone()).unwrap();
16 //println!("--- ast1 ---\n{:?}\n", ast1);
17 let ast2: syn::$new = parse2(tt).unwrap();
18 //println!("--- ast2 ---\n{:?}\n", ast2);
19 assert_eq!(ast1, Expr::$old(ast2));
20 )
21 }
22
23 let code = "match foo { Bar::Qux => (), _ => panic!() }";
24 test_equiv!(code, Match, ExprMatch);
25
26 let code = "..100u32";
27 test_equiv!(code, Range, ExprRange);
28}