From 0269850cc22a9b09f08584d312001afd8887e89b Mon Sep 17 00:00:00 2001 From: John Clements Date: Tue, 24 Sep 2013 15:57:58 -0700 Subject: [PATCH] added test case for tokenization of macro_rules --- src/libsyntax/parse/mod.rs | 45 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/src/libsyntax/parse/mod.rs b/src/libsyntax/parse/mod.rs index f5fe53ddb4f..37f2f8345cd 100644 --- a/src/libsyntax/parse/mod.rs +++ b/src/libsyntax/parse/mod.rs @@ -388,6 +388,51 @@ mod test { string_to_expr(@"::abc::def::return"); } + // check the token-tree-ization of macros + #[test] fn string_to_tts_macro () { + let tts = string_to_tts(@"macro_rules! zip (($a)=>($a))"); + match tts { + [ast::tt_tok(_,_), + ast::tt_tok(_,token::NOT), + ast::tt_tok(_,_), + ast::tt_delim(delim_elts)] => + match *delim_elts { + [ast::tt_tok(_,token::LPAREN), + ast::tt_delim(first_set), + ast::tt_tok(_,token::FAT_ARROW), + ast::tt_delim(second_set), + ast::tt_tok(_,token::RPAREN)] => + match *first_set { + [ast::tt_tok(_,token::LPAREN), + ast::tt_tok(_,token::DOLLAR), + ast::tt_tok(_,_), + ast::tt_tok(_,token::RPAREN)] => + match *second_set { + [ast::tt_tok(_,token::LPAREN), + ast::tt_tok(_,token::DOLLAR), + ast::tt_tok(_,_), + ast::tt_tok(_,token::RPAREN)] => + assert_eq!("correct","correct"), + _ => assert_eq!("wrong 4","correct") + }, + _ => { + error!("failing value 3: %?",first_set); + assert_eq!("wrong 3","correct") + } + }, + _ => { + error!("failing value 2: %?",delim_elts); + assert_eq!("wrong","correct"); + } + + }, + _ => { + error!("failing value: %?",tts); + assert_eq!("wrong 1","correct"); + } + } + } + #[test] fn string_to_tts_1 () { let tts = string_to_tts(@"fn a (b : int) { b; }"); assert_eq!(to_json_str(@tts),