add windows-absolute-path? and move unit tests

db4
erg 2008-03-27 09:00:59 -05:00
parent 3dde03bb4d
commit e39894155c
2 changed files with 20 additions and 1 deletions

View File

@ -3,7 +3,7 @@
USING: io.backend io.files.private io hashtables kernel math
memory namespaces sequences strings assocs arrays definitions
system combinators splitting sbufs continuations io.encodings
io.encodings.binary init ;
io.encodings.binary init unicode.categories ;
IN: io.files
HOOK: (file-reader) io-backend ( path -- stream )
@ -98,11 +98,19 @@ ERROR: no-parent-directory path ;
PRIVATE>
: windows-absolute-path? ( path -- path ? )
{
{ [ dup length 2 < ] [ f ] }
{ [ dup first2 >r Letter? r> CHAR: : = and ] [ t ] }
{ [ t ] [ f ] }
} cond ;
: absolute-path? ( path -- ? )
{
{ [ dup empty? ] [ f ] }
{ [ dup "resource:" head? ] [ t ] }
{ [ dup first path-separator? ] [ t ] }
{ [ windows? ] [ windows-absolute-path? ] }
{ [ t ] [ f ] }
} cond nip ;

View File

@ -0,0 +1,11 @@
USING: kernel tools.test ;
IN: io.windows.nt.files.tests
[ f ] [ "" root-directory? ] unit-test
[ t ] [ "\\" root-directory? ] unit-test
[ t ] [ "\\\\" root-directory? ] unit-test
[ t ] [ "\\\\\\\\\\\\" root-directory? ] unit-test
[ t ] [ "/" root-directory? ] unit-test
[ t ] [ "//" root-directory? ] unit-test
[ t ] [ "//////////////" root-directory? ] unit-test
[ t ] [ "\\foo" absolute-path? ] unit-test