Skip to content

Commit 0269850

Browse files
committed
added test case for tokenization of macro_rules
1 parent 0322832 commit 0269850

File tree

1 file changed

+45
-0
lines changed

1 file changed

+45
-0
lines changed

src/libsyntax/parse/mod.rs

+45
Original file line numberDiff line numberDiff line change
@@ -388,6 +388,51 @@ mod test {
388388
string_to_expr(@"::abc::def::return");
389389
}
390390

391+
// check the token-tree-ization of macros
392+
#[test] fn string_to_tts_macro () {
393+
let tts = string_to_tts(@"macro_rules! zip (($a)=>($a))");
394+
match tts {
395+
[ast::tt_tok(_,_),
396+
ast::tt_tok(_,token::NOT),
397+
ast::tt_tok(_,_),
398+
ast::tt_delim(delim_elts)] =>
399+
match *delim_elts {
400+
[ast::tt_tok(_,token::LPAREN),
401+
ast::tt_delim(first_set),
402+
ast::tt_tok(_,token::FAT_ARROW),
403+
ast::tt_delim(second_set),
404+
ast::tt_tok(_,token::RPAREN)] =>
405+
match *first_set {
406+
[ast::tt_tok(_,token::LPAREN),
407+
ast::tt_tok(_,token::DOLLAR),
408+
ast::tt_tok(_,_),
409+
ast::tt_tok(_,token::RPAREN)] =>
410+
match *second_set {
411+
[ast::tt_tok(_,token::LPAREN),
412+
ast::tt_tok(_,token::DOLLAR),
413+
ast::tt_tok(_,_),
414+
ast::tt_tok(_,token::RPAREN)] =>
415+
assert_eq!("correct","correct"),
416+
_ => assert_eq!("wrong 4","correct")
417+
},
418+
_ => {
419+
error!("failing value 3: %?",first_set);
420+
assert_eq!("wrong 3","correct")
421+
}
422+
},
423+
_ => {
424+
error!("failing value 2: %?",delim_elts);
425+
assert_eq!("wrong","correct");
426+
}
427+
428+
},
429+
_ => {
430+
error!("failing value: %?",tts);
431+
assert_eq!("wrong 1","correct");
432+
}
433+
}
434+
}
435+
391436
#[test] fn string_to_tts_1 () {
392437
let tts = string_to_tts(@"fn a (b : int) { b; }");
393438
assert_eq!(to_json_str(@tts),

0 commit comments

Comments
 (0)