more tests for io.directories.search, fix docs, refactoring

db4
Doug Coleman 2009-04-24 15:22:12 -05:00
parent 33743c1a3d
commit c3c51e2c60
3 changed files with 35 additions and 13 deletions

View File

@ -15,13 +15,20 @@ HELP: each-file
}
} ;
HELP: recursive-directory
HELP: recursive-directory-files
{ $values
{ "path" "a pathname string" } { "bfs?" "a boolean, breadth-first or depth-first" }
{ "paths" "a sequence of pathname strings" }
}
{ $description "Traverses a directory path recursively and returns a sequence of files in a breadth-first or depth-first manner." } ;
HELP: recursive-directory-entries
{ $values
{ "path" "a pathname string" } { "bfs?" "a boolean, breadth-first or depth-first" }
{ "directory-entries" "a sequence of directory-entries" }
}
{ $description "Traverses a directory path recursively and returns a sequence of directory-entries in a breadth-first or depth-first manner." } ;
HELP: find-file
{ $values
{ "path" "a pathname string" } { "bfs?" "a boolean, breadth-first or depth-first" } { "quot" quotation }
@ -55,7 +62,8 @@ HELP: find-all-in-directories
ARTICLE: "io.directories.search" "Searching directories"
"The " { $vocab-link "io.directories.search" } " vocabulary contains words used for recursively iterating over a directory and for finding files in a directory tree." $nl
"Traversing directories:"
{ $subsection recursive-directory }
{ $subsection recursive-directory-files }
{ $subsection recursive-directory-entries }
{ $subsection each-file }
"Finding files:"
{ $subsection find-file }

View File

@ -1,12 +1,14 @@
USING: io.directories.search io.files io.files.unique
io.pathnames kernel namespaces sequences sorting tools.test ;
USING: combinators.smart io.directories
io.directories.hierarchy io.directories.search io.files
io.files.unique io.pathnames kernel namespaces sequences
sorting strings tools.test ;
IN: io.directories.search.tests
[ t ] [
[
10 [ "io.paths.test" "gogogo" make-unique-file ] replicate
current-temporary-directory get [ ] find-all-files
] with-unique-directory drop [ natural-sort ] bi@ =
] cleanup-unique-directory [ natural-sort ] bi@ =
] unit-test
[ f ] [
@ -18,3 +20,18 @@ IN: io.directories.search.tests
[ f ] [
{ } t [ "asdfasdfasdfasdfasdf" tail? ] find-in-directories
] unit-test
[ t ] [
[
current-temporary-directory get
"the-head" unique-file drop t
[ file-name "the-head" head? ] find-file string?
] cleanup-unique-directory
] unit-test
[ t ] [
[ unique-directory unique-directory ] output>array
[ [ "abcd" append-path touch-file ] each ]
[ [ file-name "abcd" = ] find-all-in-directories length 2 = ]
[ [ delete-tree ] each ] tri
] unit-test

View File

@ -43,7 +43,8 @@ TUPLE: directory-iterator path bfs queue ;
:: iterate-directory-entries ( iter quot -- directory-entry/f )
iter next-directory-entry [
quot call( obj -- obj ) [ iter quot iterate-directory-entries ] unless*
quot call( obj -- obj )
[ iter quot iterate-directory-entries ] unless*
] [
f
] if* ; inline recursive
@ -57,8 +58,7 @@ TUPLE: directory-iterator path bfs queue ;
PRIVATE>
: each-file ( path bfs? quot -- )
setup-traversal [ name>> ] prepose
iterate-directory-entries drop ; inline
setup-traversal iterate-directory drop ;
: each-directory-entry ( path bfs? quot -- )
setup-traversal iterate-directory-entries drop ;
@ -87,11 +87,8 @@ ERROR: file-not-found path bfs? quot ;
3dup find-file dup [ 2nip nip ] [ drop file-not-found ] if ;
: find-in-directories ( directories bfs? quot -- path'/f )
'[
_ [ _ _ find-file-throws ] attempt-all
] [
drop f
] recover ;
'[ _ [ _ _ find-file-throws ] attempt-all ]
[ drop f ] recover ;
: find-all-in-directories ( directories quot -- paths/f )
'[ _ find-all-files ] map concat ;