@@ -803,110 +803,3 @@ impl Folder for Marker {
803
803
fn mark_tts ( tts : & [ TokenTree ] , m : Mark ) -> Vec < TokenTree > {
804
804
noop_fold_tts ( tts, & mut Marker { mark : m, expn_id : None } )
805
805
}
806
-
807
-
808
- #[ cfg( test) ]
809
- mod tests {
810
- use super :: { expand_crate, ExpansionConfig } ;
811
- use ast;
812
- use ext:: base:: { ExtCtxt , DummyResolver } ;
813
- use parse;
814
- use util:: parser_testing:: { string_to_parser} ;
815
- use visit;
816
- use visit:: Visitor ;
817
-
818
- // a visitor that extracts the paths
819
- // from a given thingy and puts them in a mutable
820
- // array (passed in to the traversal)
821
- #[ derive( Clone ) ]
822
- struct PathExprFinderContext {
823
- path_accumulator : Vec < ast:: Path > ,
824
- }
825
-
826
- impl Visitor for PathExprFinderContext {
827
- fn visit_expr ( & mut self , expr : & ast:: Expr ) {
828
- if let ast:: ExprKind :: Path ( None , ref p) = expr. node {
829
- self . path_accumulator . push ( p. clone ( ) ) ;
830
- }
831
- visit:: walk_expr ( self , expr) ;
832
- }
833
- }
834
-
835
- // these following tests are quite fragile, in that they don't test what
836
- // *kind* of failure occurs.
837
-
838
- fn test_ecfg ( ) -> ExpansionConfig < ' static > {
839
- ExpansionConfig :: default ( "test" . to_string ( ) )
840
- }
841
-
842
- // make sure that macros can't escape fns
843
- #[ should_panic]
844
- #[ test] fn macros_cant_escape_fns_test ( ) {
845
- let src = "fn bogus() {macro_rules! z (() => (3+4));}\
846
- fn inty() -> i32 { z!() }". to_string ( ) ;
847
- let sess = parse:: ParseSess :: new ( ) ;
848
- let crate_ast = parse:: parse_crate_from_source_str (
849
- "<test>" . to_string ( ) ,
850
- src,
851
- Vec :: new ( ) , & sess) . unwrap ( ) ;
852
- // should fail:
853
- let mut loader = DummyResolver ;
854
- let mut ecx = ExtCtxt :: new ( & sess, vec ! [ ] , test_ecfg ( ) , & mut loader) ;
855
- expand_crate ( & mut ecx, vec ! [ ] , crate_ast) ;
856
- }
857
-
858
- // make sure that macros can't escape modules
859
- #[ should_panic]
860
- #[ test] fn macros_cant_escape_mods_test ( ) {
861
- let src = "mod foo {macro_rules! z (() => (3+4));}\
862
- fn inty() -> i32 { z!() }". to_string ( ) ;
863
- let sess = parse:: ParseSess :: new ( ) ;
864
- let crate_ast = parse:: parse_crate_from_source_str (
865
- "<test>" . to_string ( ) ,
866
- src,
867
- Vec :: new ( ) , & sess) . unwrap ( ) ;
868
- let mut loader = DummyResolver ;
869
- let mut ecx = ExtCtxt :: new ( & sess, vec ! [ ] , test_ecfg ( ) , & mut loader) ;
870
- expand_crate ( & mut ecx, vec ! [ ] , crate_ast) ;
871
- }
872
-
873
- // macro_use modules should allow macros to escape
874
- #[ test] fn macros_can_escape_flattened_mods_test ( ) {
875
- let src = "#[macro_use] mod foo {macro_rules! z (() => (3+4));}\
876
- fn inty() -> i32 { z!() }". to_string ( ) ;
877
- let sess = parse:: ParseSess :: new ( ) ;
878
- let crate_ast = parse:: parse_crate_from_source_str (
879
- "<test>" . to_string ( ) ,
880
- src,
881
- Vec :: new ( ) , & sess) . unwrap ( ) ;
882
- let mut loader = DummyResolver ;
883
- let mut ecx = ExtCtxt :: new ( & sess, vec ! [ ] , test_ecfg ( ) , & mut loader) ;
884
- expand_crate ( & mut ecx, vec ! [ ] , crate_ast) ;
885
- }
886
-
887
- fn expand_crate_str ( crate_str : String ) -> ast:: Crate {
888
- let ps = parse:: ParseSess :: new ( ) ;
889
- let crate_ast = panictry ! ( string_to_parser( & ps, crate_str) . parse_crate_mod( ) ) ;
890
- // the cfg argument actually does matter, here...
891
- let mut loader = DummyResolver ;
892
- let mut ecx = ExtCtxt :: new ( & ps, vec ! [ ] , test_ecfg ( ) , & mut loader) ;
893
- expand_crate ( & mut ecx, vec ! [ ] , crate_ast)
894
- }
895
-
896
- #[ test] fn macro_tokens_should_match ( ) {
897
- expand_crate_str (
898
- "macro_rules! m((a)=>(13)) ;fn main(){m!(a);}" . to_string ( ) ) ;
899
- }
900
-
901
- // should be able to use a bound identifier as a literal in a macro definition:
902
- #[ test] fn self_macro_parsing ( ) {
903
- expand_crate_str (
904
- "macro_rules! foo ((zz) => (287;));
905
- fn f(zz: i32) {foo!(zz);}" . to_string ( )
906
- ) ;
907
- }
908
-
909
- // create a really evil test case where a $x appears inside a binding of $x
910
- // but *shouldn't* bind because it was inserted by a different macro....
911
- // can't write this test case until we have macro-generating macros.
912
- }
0 commit comments