@@ -757,18 +757,11 @@ fn mark_tts(tts: &[TokenTree], m: Mrk) -> Vec<TokenTree> {
757
757
758
758
#[ cfg( test) ]
759
759
mod tests {
760
- use super :: { pattern_bindings, expand_crate} ;
761
- use super :: { PatIdentFinder , IdentRenamer , PatIdentRenamer , ExpansionConfig } ;
760
+ use super :: { expand_crate, ExpansionConfig } ;
762
761
use ast;
763
- use ast:: Name ;
764
- use syntax_pos;
765
762
use ext:: base:: { ExtCtxt , DummyMacroLoader } ;
766
- use ext:: mtwt;
767
- use fold:: Folder ;
768
763
use parse;
769
- use parse:: token;
770
764
use util:: parser_testing:: { string_to_parser} ;
771
- use util:: parser_testing:: { string_to_pat, string_to_crate, strs_to_idents} ;
772
765
use visit;
773
766
use visit:: Visitor ;
774
767
@@ -789,32 +782,6 @@ mod tests {
789
782
}
790
783
}
791
784
792
- // find the variable references in a crate
793
- fn crate_varrefs ( the_crate : & ast:: Crate ) -> Vec < ast:: Path > {
794
- let mut path_finder = PathExprFinderContext { path_accumulator : Vec :: new ( ) } ;
795
- visit:: walk_crate ( & mut path_finder, the_crate) ;
796
- path_finder. path_accumulator
797
- }
798
-
799
- /// A Visitor that extracts the identifiers from a thingy.
800
- // as a side note, I'm starting to want to abstract over these....
801
- struct IdentFinder {
802
- ident_accumulator : Vec < ast:: Ident >
803
- }
804
-
805
- impl Visitor for IdentFinder {
806
- fn visit_ident ( & mut self , _: syntax_pos:: Span , id : ast:: Ident ) {
807
- self . ident_accumulator . push ( id) ;
808
- }
809
- }
810
-
811
- /// Find the idents in a crate
812
- fn crate_idents ( the_crate : & ast:: Crate ) -> Vec < ast:: Ident > {
813
- let mut ident_finder = IdentFinder { ident_accumulator : Vec :: new ( ) } ;
814
- visit:: walk_crate ( & mut ident_finder, the_crate) ;
815
- ident_finder. ident_accumulator
816
- }
817
-
818
785
// these following tests are quite fragile, in that they don't test what
819
786
// *kind* of failure occurs.
820
787
@@ -876,13 +843,6 @@ mod tests {
876
843
expand_crate ( ecx, vec ! [ ] , crate_ast) . 0
877
844
}
878
845
879
- // find the pat_ident paths in a crate
880
- fn crate_bindings ( the_crate : & ast:: Crate ) -> Vec < ast:: Ident > {
881
- let mut name_finder = PatIdentFinder { ident_accumulator : Vec :: new ( ) } ;
882
- visit:: walk_crate ( & mut name_finder, the_crate) ;
883
- name_finder. ident_accumulator
884
- }
885
-
886
846
#[ test] fn macro_tokens_should_match ( ) {
887
847
expand_crate_str (
888
848
"macro_rules! m((a)=>(13)) ;fn main(){m!(a);}" . to_string ( ) ) ;
@@ -899,93 +859,4 @@ mod tests {
899
859
// create a really evil test case where a $x appears inside a binding of $x
900
860
// but *shouldn't* bind because it was inserted by a different macro....
901
861
// can't write this test case until we have macro-generating macros.
902
-
903
- #[ test]
904
- fn fmt_in_macro_used_inside_module_macro ( ) {
905
- let crate_str = "macro_rules! fmt_wrap(($b:expr)=>($b.to_string()));
906
- macro_rules! foo_module (() => (mod generated { fn a() { let xx = 147; fmt_wrap!(xx);}}));
907
- foo_module!();
908
- " . to_string ( ) ;
909
- let cr = expand_crate_str ( crate_str) ;
910
- // find the xx binding
911
- let bindings = crate_bindings ( & cr) ;
912
- let cxbinds: Vec < & ast:: Ident > =
913
- bindings. iter ( ) . filter ( |b| b. name . as_str ( ) == "xx" ) . collect ( ) ;
914
- let cxbinds: & [ & ast:: Ident ] = & cxbinds[ ..] ;
915
- let cxbind = match ( cxbinds. len ( ) , cxbinds. get ( 0 ) ) {
916
- ( 1 , Some ( b) ) => * b,
917
- _ => panic ! ( "expected just one binding for ext_cx" )
918
- } ;
919
- let resolved_binding = mtwt:: resolve ( * cxbind) ;
920
- let varrefs = crate_varrefs ( & cr) ;
921
-
922
- // the xx binding should bind all of the xx varrefs:
923
- for ( idx, v) in varrefs. iter ( ) . filter ( |p| {
924
- p. segments . len ( ) == 1
925
- && p. segments [ 0 ] . identifier . name . as_str ( ) == "xx"
926
- } ) . enumerate ( ) {
927
- if mtwt:: resolve ( v. segments [ 0 ] . identifier ) != resolved_binding {
928
- println ! ( "uh oh, xx binding didn't match xx varref:" ) ;
929
- println ! ( "this is xx varref \\ # {}" , idx) ;
930
- println ! ( "binding: {}" , cxbind) ;
931
- println ! ( "resolves to: {}" , resolved_binding) ;
932
- println ! ( "varref: {}" , v. segments[ 0 ] . identifier) ;
933
- println ! ( "resolves to: {}" ,
934
- mtwt:: resolve( v. segments[ 0 ] . identifier) ) ;
935
- mtwt:: with_sctable ( |x| mtwt:: display_sctable ( x) ) ;
936
- }
937
- assert_eq ! ( mtwt:: resolve( v. segments[ 0 ] . identifier) ,
938
- resolved_binding) ;
939
- } ;
940
- }
941
-
942
- #[ test]
943
- fn pat_idents ( ) {
944
- let pat = string_to_pat (
945
- "(a,Foo{x:c @ (b,9),y:Bar(4,d)})" . to_string ( ) ) ;
946
- let idents = pattern_bindings ( & pat) ;
947
- assert_eq ! ( idents, strs_to_idents( vec!( "a" , "c" , "b" , "d" ) ) ) ;
948
- }
949
-
950
- // test the list of identifier patterns gathered by the visitor. Note that
951
- // 'None' is listed as an identifier pattern because we don't yet know that
952
- // it's the name of a 0-ary variant, and that 'i' appears twice in succession.
953
- #[ test]
954
- fn crate_bindings_test ( ) {
955
- let the_crate = string_to_crate ( "fn main (a: i32) -> i32 {|b| {
956
- match 34 {None => 3, Some(i) | i => j, Foo{k:z,l:y} => \" banana\" }} }" . to_string ( ) ) ;
957
- let idents = crate_bindings ( & the_crate) ;
958
- assert_eq ! ( idents, strs_to_idents( vec!( "a" , "b" , "None" , "i" , "i" , "z" , "y" ) ) ) ;
959
- }
960
-
961
- // test the IdentRenamer directly
962
- #[ test]
963
- fn ident_renamer_test ( ) {
964
- let the_crate = string_to_crate ( "fn f(x: i32){let x = x; x}" . to_string ( ) ) ;
965
- let f_ident = token:: str_to_ident ( "f" ) ;
966
- let x_ident = token:: str_to_ident ( "x" ) ;
967
- let int_ident = token:: str_to_ident ( "i32" ) ;
968
- let renames = vec ! ( ( x_ident, Name ( 16 ) ) ) ;
969
- let mut renamer = IdentRenamer { renames : & renames} ;
970
- let renamed_crate = renamer. fold_crate ( the_crate) ;
971
- let idents = crate_idents ( & renamed_crate) ;
972
- let resolved : Vec < ast:: Name > = idents. iter ( ) . map ( |id| mtwt:: resolve ( * id) ) . collect ( ) ;
973
- assert_eq ! ( resolved, [ f_ident. name, Name ( 16 ) , int_ident. name, Name ( 16 ) , Name ( 16 ) , Name ( 16 ) ] ) ;
974
- }
975
-
976
- // test the PatIdentRenamer; only PatIdents get renamed
977
- #[ test]
978
- fn pat_ident_renamer_test ( ) {
979
- let the_crate = string_to_crate ( "fn f(x: i32){let x = x; x}" . to_string ( ) ) ;
980
- let f_ident = token:: str_to_ident ( "f" ) ;
981
- let x_ident = token:: str_to_ident ( "x" ) ;
982
- let int_ident = token:: str_to_ident ( "i32" ) ;
983
- let renames = vec ! ( ( x_ident, Name ( 16 ) ) ) ;
984
- let mut renamer = PatIdentRenamer { renames : & renames} ;
985
- let renamed_crate = renamer. fold_crate ( the_crate) ;
986
- let idents = crate_idents ( & renamed_crate) ;
987
- let resolved : Vec < ast:: Name > = idents. iter ( ) . map ( |id| mtwt:: resolve ( * id) ) . collect ( ) ;
988
- let x_name = x_ident. name ;
989
- assert_eq ! ( resolved, [ f_ident. name, Name ( 16 ) , int_ident. name, Name ( 16 ) , x_name, x_name] ) ;
990
- }
991
862
}
0 commit comments