bstrie | 7b4f52d | 2019-04-30 18:44:21 -0400 | [diff] [blame^] | 1 | extern crate proc_macro2; |
| 2 | extern crate syn; |
| 3 | |
| 4 | use std::str::FromStr; |
| 5 | |
| 6 | use proc_macro2::TokenStream; |
| 7 | use syn::{Expr, parse2}; |
| 8 | |
| 9 | #[test] |
| 10 | fn 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 | } |