@@ -22,6 +22,9 @@ use rustc_data_structures::sync::Lrc;
2222use std:: ops:: DerefMut ;
2323use std:: { panic, process, ptr} ;
2424
25+ #[ cfg( test) ]
26+ mod tests;
27+
2528pub trait ExpectOne < A : Array > {
2629 fn expect_one ( self , err : & ' static str ) -> A :: Item ;
2730}
@@ -1255,77 +1258,3 @@ pub fn noop_visit_vis<T: MutVisitor>(Spanned { node, span }: &mut Visibility, vi
12551258 }
12561259 vis. visit_span ( span) ;
12571260}
1258-
1259- #[ cfg( test) ]
1260- mod tests {
1261- use crate :: ast:: { self , Ident } ;
1262- use crate :: util:: parser_testing:: { string_to_crate, matches_codepattern} ;
1263- use crate :: print:: pprust;
1264- use crate :: mut_visit;
1265- use crate :: with_default_globals;
1266- use super :: * ;
1267-
1268- // this version doesn't care about getting comments or docstrings in.
1269- fn fake_print_crate ( s : & mut pprust:: State < ' _ > ,
1270- krate : & ast:: Crate ) {
1271- s. print_mod ( & krate. module , & krate. attrs )
1272- }
1273-
1274- // change every identifier to "zz"
1275- struct ToZzIdentMutVisitor ;
1276-
1277- impl MutVisitor for ToZzIdentMutVisitor {
1278- fn visit_ident ( & mut self , ident : & mut ast:: Ident ) {
1279- * ident = Ident :: from_str ( "zz" ) ;
1280- }
1281- fn visit_mac ( & mut self , mac : & mut ast:: Mac ) {
1282- mut_visit:: noop_visit_mac ( mac, self )
1283- }
1284- }
1285-
1286- // maybe add to expand.rs...
1287- macro_rules! assert_pred {
1288- ( $pred: expr, $predname: expr, $a: expr , $b: expr) => (
1289- {
1290- let pred_val = $pred;
1291- let a_val = $a;
1292- let b_val = $b;
1293- if !( pred_val( & a_val, & b_val) ) {
1294- panic!( "expected args satisfying {}, got {} and {}" ,
1295- $predname, a_val, b_val) ;
1296- }
1297- }
1298- )
1299- }
1300-
1301- // make sure idents get transformed everywhere
1302- #[ test] fn ident_transformation ( ) {
1303- with_default_globals ( || {
1304- let mut zz_visitor = ToZzIdentMutVisitor ;
1305- let mut krate = string_to_crate (
1306- "#[a] mod b {fn c (d : e, f : g) {h!(i,j,k);l;m}}" . to_string ( ) ) ;
1307- zz_visitor. visit_crate ( & mut krate) ;
1308- assert_pred ! (
1309- matches_codepattern,
1310- "matches_codepattern" ,
1311- pprust:: to_string( |s| fake_print_crate( s, & krate) ) ,
1312- "#[zz]mod zz{fn zz(zz:zz,zz:zz){zz!(zz,zz,zz);zz;zz}}" . to_string( ) ) ;
1313- } )
1314- }
1315-
1316- // even inside macro defs....
1317- #[ test] fn ident_transformation_in_defs ( ) {
1318- with_default_globals ( || {
1319- let mut zz_visitor = ToZzIdentMutVisitor ;
1320- let mut krate = string_to_crate (
1321- "macro_rules! a {(b $c:expr $(d $e:token)f+ => \
1322- (g $(d $d $e)+))} ". to_string ( ) ) ;
1323- zz_visitor. visit_crate ( & mut krate) ;
1324- assert_pred ! (
1325- matches_codepattern,
1326- "matches_codepattern" ,
1327- pprust:: to_string( |s| fake_print_crate( s, & krate) ) ,
1328- "macro_rules! zz{(zz$zz:zz$(zz $zz:zz)zz+=>(zz$(zz$zz$zz)+))}" . to_string( ) ) ;
1329- } )
1330- }
1331- }
0 commit comments