globs: add "glob-parent-directory" word that returns the deepest level of a path without glob symbols

db4
Joe Groff 2010-02-14 11:49:33 -08:00
parent 9c77d7bde8
commit 5f0855c5c2
2 changed files with 24 additions and 1 deletions

View File

@ -1,4 +1,4 @@
USING: tools.test globs io.pathnames ;
USING: arrays tools.test globs io.pathnames sequences ;
IN: globs.tests
[ f ] [ "abd" "fdf" glob-matches? ] unit-test
@ -22,3 +22,19 @@ IN: globs.tests
[ t ] [ "foo" "bar" append-path "*" "*" append-path glob-matches? ] unit-test
[ f ] [ "foo" "bar" append-path "foo?bar" glob-matches? ] unit-test
[ t ] [ "foo" "bar" append-path "fo?" "bar" append-path glob-matches? ] unit-test
[ f ] [ "foo" glob-pattern? ] unit-test
[ t ] [ "fo?" glob-pattern? ] unit-test
[ t ] [ "fo*" glob-pattern? ] unit-test
[ t ] [ "fo[mno]" glob-pattern? ] unit-test
[ t ] [ "fo\\*" glob-pattern? ] unit-test
[ t ] [ "fo{o,bro}" glob-pattern? ] unit-test
"foo" "bar" append-path 1array
[ { "foo" "bar" "ba?" } path-separator join glob-parent-directory ] unit-test
[ "foo" ]
[ { "foo" "b?r" "bas" } path-separator join glob-parent-directory ] unit-test
[ "" ]
[ { "f*" "bar" "bas" } path-separator join glob-parent-directory ] unit-test

View File

@ -43,3 +43,10 @@ Main = Concatenation End
: glob-matches? ( input glob -- ? )
[ >case-fold ] bi@ <glob> matches? ;
: glob-pattern? ( string -- ? )
[ "\\*?[{" member? ] any? ;
: glob-parent-directory ( glob -- parent-directory )
path-components dup [ glob-pattern? ] find drop head
path-separator join ;