File tree Expand file tree Collapse file tree 1 file changed +20
-0
lines changed Expand file tree Collapse file tree 1 file changed +20
-0
lines changed Original file line number Diff line number Diff line change @@ -427,6 +427,10 @@ impl RepoPath {
427427 RepoPathComponentsIter { value : & self . value }
428428 }
429429
430+ pub fn ancestors ( & self ) -> impl Iterator < Item = & RepoPath > {
431+ std:: iter:: successors ( Some ( self ) , |path| path. parent ( ) )
432+ }
433+
430434 pub fn join ( & self , entry : & RepoPathComponent ) -> RepoPathBuf {
431435 let value = if self . value . is_empty ( ) {
432436 entry. as_internal_str ( ) . to_owned ( )
@@ -890,6 +894,22 @@ mod tests {
890894 ) ;
891895 }
892896
897+ #[ test]
898+ fn test_ancestors ( ) {
899+ assert_eq ! (
900+ RepoPath :: root( ) . ancestors( ) . collect_vec( ) ,
901+ vec![ RepoPath :: root( ) ]
902+ ) ;
903+ assert_eq ! (
904+ repo_path( "dir" ) . ancestors( ) . collect_vec( ) ,
905+ vec![ repo_path( "dir" ) , RepoPath :: root( ) ]
906+ ) ;
907+ assert_eq ! (
908+ repo_path( "dir/subdir" ) . ancestors( ) . collect_vec( ) ,
909+ vec![ repo_path( "dir/subdir" ) , repo_path( "dir" ) , RepoPath :: root( ) ]
910+ ) ;
911+ }
912+
893913 #[ test]
894914 fn test_to_fs_path ( ) {
895915 assert_eq ! (
You can’t perform that action at this time.
0 commit comments