about summary refs log tree commit diff
path: root/src/libsyntax/parse
diff options
context:
space:
mode:
authorJohn Clements <clements@racket-lang.org>2013-09-24 15:57:58 -0700
committerJohn Clements <clements@racket-lang.org>2013-09-24 16:00:58 -0700
commit0269850cc22a9b09f08584d312001afd8887e89b (patch)
treea913c0a677de08a0fe0e5e2ccefb22bafaa77e7c /src/libsyntax/parse
parent032283276396dc7f738cc38ae228f56618cb3edf (diff)
downloadrust-0269850cc22a9b09f08584d312001afd8887e89b.tar.gz
rust-0269850cc22a9b09f08584d312001afd8887e89b.zip
added test case for tokenization of macro_rules
Diffstat (limited to 'src/libsyntax/parse')
-rw-r--r--src/libsyntax/parse/mod.rs45
1 files changed, 45 insertions, 0 deletions
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),