diff options
Diffstat (limited to 'src/libsyntax')
| -rw-r--r-- | src/libsyntax/ext/expand.rs | 131 | ||||
| -rw-r--r-- | src/libsyntax/ext/mtwt.rs | 23 | ||||
| -rw-r--r-- | src/libsyntax/parse/token.rs | 18 |
3 files changed, 3 insertions, 169 deletions
diff --git a/src/libsyntax/ext/expand.rs b/src/libsyntax/ext/expand.rs index 10b66d08955..b94079984eb 100644 --- a/src/libsyntax/ext/expand.rs +++ b/src/libsyntax/ext/expand.rs @@ -757,18 +757,11 @@ fn mark_tts(tts: &[TokenTree], m: Mrk) -> Vec<TokenTree> { #[cfg(test)] mod tests { - use super::{pattern_bindings, expand_crate}; - use super::{PatIdentFinder, IdentRenamer, PatIdentRenamer, ExpansionConfig}; + use super::{expand_crate, ExpansionConfig}; use ast; - use ast::Name; - use syntax_pos; use ext::base::{ExtCtxt, DummyMacroLoader}; - use ext::mtwt; - use fold::Folder; use parse; - use parse::token; use util::parser_testing::{string_to_parser}; - use util::parser_testing::{string_to_pat, string_to_crate, strs_to_idents}; use visit; use visit::Visitor; @@ -789,32 +782,6 @@ mod tests { } } - // find the variable references in a crate - fn crate_varrefs(the_crate : &ast::Crate) -> Vec<ast::Path> { - let mut path_finder = PathExprFinderContext{path_accumulator:Vec::new()}; - visit::walk_crate(&mut path_finder, the_crate); - path_finder.path_accumulator - } - - /// A Visitor that extracts the identifiers from a thingy. - // as a side note, I'm starting to want to abstract over these.... - struct IdentFinder { - ident_accumulator: Vec<ast::Ident> - } - - impl Visitor for IdentFinder { - fn visit_ident(&mut self, _: syntax_pos::Span, id: ast::Ident){ - self.ident_accumulator.push(id); - } - } - - /// Find the idents in a crate - fn crate_idents(the_crate: &ast::Crate) -> Vec<ast::Ident> { - let mut ident_finder = IdentFinder{ident_accumulator: Vec::new()}; - visit::walk_crate(&mut ident_finder, the_crate); - ident_finder.ident_accumulator - } - // these following tests are quite fragile, in that they don't test what // *kind* of failure occurs. @@ -876,13 +843,6 @@ mod tests { expand_crate(ecx, vec![], crate_ast).0 } - // find the pat_ident paths in a crate - fn crate_bindings(the_crate : &ast::Crate) -> Vec<ast::Ident> { - let mut name_finder = PatIdentFinder{ident_accumulator:Vec::new()}; - visit::walk_crate(&mut name_finder, the_crate); - name_finder.ident_accumulator - } - #[test] fn macro_tokens_should_match(){ expand_crate_str( "macro_rules! m((a)=>(13)) ;fn main(){m!(a);}".to_string()); @@ -899,93 +859,4 @@ mod tests { // create a really evil test case where a $x appears inside a binding of $x // but *shouldn't* bind because it was inserted by a different macro.... // can't write this test case until we have macro-generating macros. - - #[test] - fn fmt_in_macro_used_inside_module_macro() { - let crate_str = "macro_rules! fmt_wrap(($b:expr)=>($b.to_string())); -macro_rules! foo_module (() => (mod generated { fn a() { let xx = 147; fmt_wrap!(xx);}})); -foo_module!(); -".to_string(); - let cr = expand_crate_str(crate_str); - // find the xx binding - let bindings = crate_bindings(&cr); - let cxbinds: Vec<&ast::Ident> = - bindings.iter().filter(|b| b.name.as_str() == "xx").collect(); - let cxbinds: &[&ast::Ident] = &cxbinds[..]; - let cxbind = match (cxbinds.len(), cxbinds.get(0)) { - (1, Some(b)) => *b, - _ => panic!("expected just one binding for ext_cx") - }; - let resolved_binding = mtwt::resolve(*cxbind); - let varrefs = crate_varrefs(&cr); - - // the xx binding should bind all of the xx varrefs: - for (idx,v) in varrefs.iter().filter(|p| { - p.segments.len() == 1 - && p.segments[0].identifier.name.as_str() == "xx" - }).enumerate() { - if mtwt::resolve(v.segments[0].identifier) != resolved_binding { - println!("uh oh, xx binding didn't match xx varref:"); - println!("this is xx varref \\# {}", idx); - println!("binding: {}", cxbind); - println!("resolves to: {}", resolved_binding); - println!("varref: {}", v.segments[0].identifier); - println!("resolves to: {}", - mtwt::resolve(v.segments[0].identifier)); - mtwt::with_sctable(|x| mtwt::display_sctable(x)); - } - assert_eq!(mtwt::resolve(v.segments[0].identifier), - resolved_binding); - }; - } - - #[test] - fn pat_idents(){ - let pat = string_to_pat( - "(a,Foo{x:c @ (b,9),y:Bar(4,d)})".to_string()); - let idents = pattern_bindings(&pat); - assert_eq!(idents, strs_to_idents(vec!("a","c","b","d"))); - } - - // test the list of identifier patterns gathered by the visitor. Note that - // 'None' is listed as an identifier pattern because we don't yet know that - // it's the name of a 0-ary variant, and that 'i' appears twice in succession. - #[test] - fn crate_bindings_test(){ - let the_crate = string_to_crate("fn main (a: i32) -> i32 {|b| { - match 34 {None => 3, Some(i) | i => j, Foo{k:z,l:y} => \"banana\"}} }".to_string()); - let idents = crate_bindings(&the_crate); - assert_eq!(idents, strs_to_idents(vec!("a","b","None","i","i","z","y"))); - } - - // test the IdentRenamer directly - #[test] - fn ident_renamer_test () { - let the_crate = string_to_crate("fn f(x: i32){let x = x; x}".to_string()); - let f_ident = token::str_to_ident("f"); - let x_ident = token::str_to_ident("x"); - let int_ident = token::str_to_ident("i32"); - let renames = vec!((x_ident,Name(16))); - let mut renamer = IdentRenamer{renames: &renames}; - let renamed_crate = renamer.fold_crate(the_crate); - let idents = crate_idents(&renamed_crate); - let resolved : Vec<ast::Name> = idents.iter().map(|id| mtwt::resolve(*id)).collect(); - assert_eq!(resolved, [f_ident.name,Name(16),int_ident.name,Name(16),Name(16),Name(16)]); - } - - // test the PatIdentRenamer; only PatIdents get renamed - #[test] - fn pat_ident_renamer_test () { - let the_crate = string_to_crate("fn f(x: i32){let x = x; x}".to_string()); - let f_ident = token::str_to_ident("f"); - let x_ident = token::str_to_ident("x"); - let int_ident = token::str_to_ident("i32"); - let renames = vec!((x_ident,Name(16))); - let mut renamer = PatIdentRenamer{renames: &renames}; - let renamed_crate = renamer.fold_crate(the_crate); - let idents = crate_idents(&renamed_crate); - let resolved : Vec<ast::Name> = idents.iter().map(|id| mtwt::resolve(*id)).collect(); - let x_name = x_ident.name; - assert_eq!(resolved, [f_ident.name,Name(16),int_ident.name,Name(16),x_name,x_name]); - } } diff --git a/src/libsyntax/ext/mtwt.rs b/src/libsyntax/ext/mtwt.rs index ac5bac58d2a..d2f6df9d5db 100644 --- a/src/libsyntax/ext/mtwt.rs +++ b/src/libsyntax/ext/mtwt.rs @@ -71,14 +71,6 @@ fn new_sctable_internal() -> SCTable { } } -/// Print out an SCTable for debugging -pub fn display_sctable(table: &SCTable) { - error!("SC table:"); - for (idx,val) in table.table.borrow().iter().enumerate() { - error!("{:4} : {:?}",idx,val); - } -} - /// Clear the tables from TLD to reclaim memory. pub fn clear_tables() { with_sctable(|table| { @@ -128,13 +120,8 @@ pub fn source(ident: Ident) -> Option<(Ident /* source ident */, Mrk /* source m #[cfg(test)] mod tests { - use ast::{EMPTY_CTXT, Ident, Mrk, Name, SyntaxContext}; - use super::{resolve, apply_mark_internal, new_sctable_internal}; - use super::{SCTable, Mark}; - - fn id(n: u32, s: SyntaxContext) -> Ident { - Ident::new(Name(n), s) - } + use ast::{EMPTY_CTXT, Mrk, SyntaxContext}; + use super::{apply_mark_internal, new_sctable_internal, Mark, SCTable}; // extend a syntax context with a sequence of marks given // in a vector. v[0] will be the outermost mark. @@ -156,12 +143,6 @@ mod tests { } #[test] - fn mtwt_resolve_test(){ - let a = 40; - assert_eq!(resolve(id(a,EMPTY_CTXT)),Name(a)); - } - - #[test] fn hashing_tests () { let mut t = new_sctable_internal(); assert_eq!(apply_mark_internal(12,EMPTY_CTXT,&mut t),SyntaxContext(1)); diff --git a/src/libsyntax/parse/token.rs b/src/libsyntax/parse/token.rs index 3b25d381419..64547414d07 100644 --- a/src/libsyntax/parse/token.rs +++ b/src/libsyntax/parse/token.rs @@ -637,21 +637,3 @@ pub fn fresh_name(src: ast::Ident) -> ast::Name { pub fn fresh_mark() -> ast::Mrk { gensym("mark").0 } - -#[cfg(test)] -mod tests { - use super::*; - use ast; - use ext::mtwt; - - fn mark_ident(id : ast::Ident, m : ast::Mrk) -> ast::Ident { - ast::Ident::new(id.name, mtwt::apply_mark(m, id.ctxt)) - } - - #[test] fn mtwt_token_eq_test() { - assert!(Gt.mtwt_eq(&Gt)); - let a = str_to_ident("bac"); - let a1 = mark_ident(a,92); - assert!(Ident(a).mtwt_eq(&Ident(a1))); - } -} |
