@@ -236,16 +236,16 @@ pub trait GenericPath : Clone + Eq + ToStr {
236236
237237 /// Returns `true` iff `child` is a suffix of `parent`. See the test
238238 /// case for examples.
239- pub fn is_parent_of ( parent : & Path , child : & Path ) -> bool {
240- if !parent . is_absolute ( ) || child. is_absolute ( )
241- || parent . components . len ( ) < child. components . len ( )
242- || parent . components . is_empty ( ) {
239+ fn is_parent_of ( & self , child : & Self ) -> bool {
240+ if !self . is_absolute ( ) || child. is_absolute ( )
241+ || self . components ( ) . len ( ) < child. components ( ) . len ( )
242+ || self . components ( ) . is_empty ( ) {
243243 return false ;
244244 }
245245 let child_components = child. components ( ) . len ( ) ;
246- let parent_components = parent . components ( ) . len ( ) ;
247- let to_drop = parent . components . len ( ) - child_components;
248- parent . components . slice ( to_drop, parent_components) == child. components
246+ let parent_components = self . components ( ) . len ( ) ;
247+ let to_drop = self . components ( ) . len ( ) - child_components;
248+ self . components ( ) . slice ( to_drop, parent_components) == child. components ( )
249249 }
250250
251251 fn components < ' a > ( & ' a self ) -> & ' a [ ~str ] ;
@@ -1468,14 +1468,22 @@ mod tests {
14681468
14691469 #[ test]
14701470 fn test_is_parent_of( ) {
1471- assert!( is_parent_of( & PosixPath ( "/a/b/c/d/e" ) , & PosixPath ( "c/d/e" ) ) ) ;
1472- assert!( !is_parent_of( & PosixPath ( "a/b/c/d/e" ) , & PosixPath ( "c/d/e" ) ) ) ;
1473- assert!( !is_parent_of( & PosixPath ( "/a/b/c/d/e" ) , & PosixPath ( "/c/d/e" ) ) ) ;
1474- assert!( !is_parent_of( & PosixPath ( "" ) , & PosixPath ( "" ) ) ) ;
1475- assert!( !is_parent_of( & PosixPath ( "" ) , & PosixPath ( "a/b/c" ) ) ) ;
1476- assert!( is_parent_of( & PosixPath ( "/a/b/c" ) , & PosixPath ( "" ) ) ) ;
1477- assert!( is_parent_of( & PosixPath ( "/a/b/c" ) , & PosixPath ( "a/b/c" ) ) ) ;
1478- assert!( !is_parent_of( & PosixPath ( "/a/b/c" ) , & PosixPath ( "d/e/f" ) ) ) ;
1471+ fn is_parent_of_pp( p: & PosixPath , q: & PosixPath ) -> bool {
1472+ p. is_parent_of( q)
1473+ }
1474+
1475+ assert!( is_parent_of_pp( & PosixPath ( "/a/b/c/d/e" ) , & PosixPath ( "c/d/e" ) ) ) ;
1476+ assert!( !is_parent_of_pp( & PosixPath ( "a/b/c/d/e" ) , & PosixPath ( "c/d/e" ) ) ) ;
1477+ assert!( !is_parent_of_pp( & PosixPath ( "/a/b/c/d/e" ) , & PosixPath ( "/c/d/e" ) ) ) ;
1478+ assert!( !is_parent_of_pp( & PosixPath ( "" ) , & PosixPath ( "" ) ) ) ;
1479+ assert!( !is_parent_of_pp( & PosixPath ( "" ) , & PosixPath ( "a/b/c" ) ) ) ;
1480+ assert!( is_parent_of_pp( & PosixPath ( "/a/b/c" ) , & PosixPath ( "" ) ) ) ;
1481+ assert!( is_parent_of_pp( & PosixPath ( "/a/b/c" ) , & PosixPath ( "a/b/c" ) ) ) ;
1482+ assert!( !is_parent_of_pp( & PosixPath ( "/a/b/c" ) , & PosixPath ( "d/e/f" ) ) ) ;
1483+
1484+ fn is_parent_of_wp( p: & WindowsPath , q: & WindowsPath ) -> bool {
1485+ p. is_parent_of( q)
1486+ }
14791487
14801488 let abcde = WindowsPath ( "C:\\ a\\ b\\ c\\ d\\ e" ) ;
14811489 let rel_abcde = WindowsPath ( "a\\ b\\ c\\ d\\ e" ) ;
@@ -1486,13 +1494,14 @@ mod tests {
14861494 let rel_abc = WindowsPath ( "a\\ b\\ c" ) ;
14871495 let def = WindowsPath ( "d\\ e\\ f" ) ;
14881496
1489- assert!( is_parent_of( & abcde, & cde) ) ;
1490- assert!( !is_parent_of( & rel_abcde, & cde) ) ;
1491- assert!( !is_parent_of( & abcde, & slashcde) ) ;
1492- assert!( !is_parent_of( & empty, & empty) ) ;
1493- assert!( is_parent_of( & abc, & empty) ;
1494- assert!( is_parent_of( & abc, & rel_abc) ) ;
1495- assert!( !is_parent_of( & abc, & def) ) ;
1497+ assert!( is_parent_of_wp( & abcde, & cde) ) ;
1498+ assert!( !is_parent_of_wp( & rel_abcde, & cde) ) ;
1499+ assert!( !is_parent_of_wp( & abcde, & slashcde) ) ;
1500+ assert!( !is_parent_of_wp( & empty, & empty) ) ;
1501+ assert!( !is_parent_of_wp( & empty, & rel_abc) ) ;
1502+ assert!( is_parent_of_wp( & abc, & empty) ) ;
1503+ assert!( is_parent_of_wp( & abc, & rel_abc) ) ;
1504+ assert!( !is_parent_of_wp( & abc, & def) ) ;
14961505 }
14971506
14981507}
0 commit comments