Last active
June 24, 2017 03:56
-
-
Save samcv/7dade9fb0a93c53497afc91d864d21c7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
sub get-dirs (IO::Path:D $path, Bool :$d = False) { | |
my @all = $path.dir; | |
my @dirs = @all.grep(*.d); | |
my @thing = @dirs.map({ get-dirs($_; :$d) } ).flat; | |
if @thing.elems != 0 && @thing.all !~~ IO::Path:D { | |
@thing.say; | |
die; | |
} | |
if $d { | |
@dirs ?? @dirs.append(@thing) !! @dirs; | |
} | |
else { | |
@dirs ?? @all.append( @thing ).grep(*.Bool) !! @all; | |
} | |
} | |
sub test-it { | |
use Test; | |
plan 6; | |
my @dirs = get-dirs("/home/samantha/git/rakudo".IO, :d); | |
nok @dirs.first(*.f), "there's no files when doing :d"; | |
ok(@dirs.elems < 9541, "less than 9541 elems with :d"); | |
my @files-and-dirs = get-dirs("/home/samantha/git/rakudo".IO); | |
ok((@files-and-dirs.any.d and @files-and-dirs.any.f), "There are dirs and files without :d"); | |
ok @files-and-dirs.all.d, "Everything is a dir with :d"; | |
is @files-and-dirs.elems, 9541; | |
is @files-and-dirs.grep(!*.d).elems, 0; | |
ok @files-and-dirs.all ~~ IO::Path; | |
is @files-and-dirs.sort(&[eqv]).unique.elems, @files-and-dirs.elems; | |
} | |
test-it(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment