-USING: io.backend io.directories io.files.private io.files.temp
-io.files.unique io.pathnames kernel locals math multiline
-namespaces sequences system tools.test ;
+USING: io.backend io.directories io.files.private io.pathnames
+kernel math namespaces sequences system tools.test vocabs.loader ;
{ "passwd" } [ "/etc/passwd" file-name ] unit-test
{ "awk" } [ "/usr/libexec/awk/" file-name ] unit-test
{ "/" } [ "/Users/foo/bar////././." root-path ] unit-test
{ "/" } [ "/Users/foo/bar////.//../../../../../../////./." root-path ] unit-test
{ "/" } [ "/Users/////" root-path ] unit-test
-] if
\ No newline at end of file
+] if
+
+{ t } [ "." has-file-extension? ] unit-test
+{ t } [ ".." has-file-extension? ] unit-test
+{ t } [ "a.b" has-file-extension? ] unit-test
+{ f } [ "a/" has-file-extension? ] unit-test
+{ f } [ "a.b/" has-file-extension? ] unit-test
+{ t } [ "math.factor" has-file-extension? ] unit-test
+{ t } [ "math." has-file-extension? ] unit-test
+{ f } [ "math" has-file-extension? ] unit-test
+
+{ "resource:core/math" } [ "math" vocab-path ] unit-test
+{ "resource:core/math/" } [ "math/" vocab-path ] unit-test
+
+[ "math.omg" vocab-path ] [ not-found-in-roots? ] must-fail-with
+[ "math.omg/" vocab-path ] [ not-found-in-roots? ] must-fail-with
+[ "accessors" vocab-path ] [ not-found-in-roots? ] must-fail-with
+[ "asdfasdfasdfasfd1231231" vocab-path ] [ not-found-in-roots? ] must-fail-with
+[ "resource:extra/benchmark/sum-file/sum-file.txt/" vocab-path ]
+[ not-found-in-roots? ] must-fail-with
+
+{ "resource:extra/benchmark/sum-file/sum-file.txt" }
+[ "benchmark/sum-file/sum-file.txt" vocab-path ] unit-test
+
+{ "resource:extra/benchmark/sum-file" }
+[ "benchmark/sum-file" vocab-path ] unit-test
+
+{ "resource:extra/benchmark/sum-file/" }
+[ "benchmark/sum-file/" vocab-path ] unit-test
\ No newline at end of file
! Copyright (C) 2007, 2010 Eduardo Cavazos, Slava Pestov.
! See http://factorcode.org/license.txt for BSD license.
-USING: accessors arrays assocs continuations definitions init
-io io.files io.pathnames kernel make namespaces parser
-sequences sets splitting strings vocabs words ;
+USING: accessors arrays assocs combinators continuations
+definitions init io io.files io.pathnames kernel make namespaces
+parser sequences sets splitting strings vocabs words ;
IN: vocabs.loader
SYMBOL: vocab-roots
: find-root-for ( path -- path/f )
vocab-roots get [ prepend-path file-exists? ] with find nip ;
-M: string vocab-path
+: find-root-for-vocab-pathname ( path -- path/f )
dup find-root-for [ prepend-path ] [ not-found-in-roots ] if* ;
+: ensure-parent-directory-is-not-dot ( path -- parent-directory )
+ dup parent-directory dup "." =
+ [ drop not-found-in-roots ]
+ [ nip ] if ;
+
+M: string vocab-path
+ {
+ { [ dup ?last path-separator? ] [ find-root-for-vocab-pathname ] }
+ { [ dup has-file-extension? ] [
+ [ ensure-parent-directory-is-not-dot find-root-for-vocab-pathname ]
+ [ file-name ] bi append-path
+ ] }
+ [ find-root-for-vocab-pathname ]
+ } cond ;
+
PRIVATE>
: vocab-dir ( vocab -- dir )