factor/core/io/files/files-tests.factor

208 lines
5.8 KiB
Factor
Raw Normal View History

2008-03-01 17:00:45 -05:00
IN: io.files.tests
USING: tools.test io.files io threads kernel continuations
io.encodings.ascii io.files.unique sequences strings accessors
io.encodings.utf8 ;
2007-09-20 18:09:08 -04:00
2008-03-15 07:23:10 -04:00
[ ] [ "blahblah" temp-file dup exists? [ delete-directory ] [ drop ] if ] unit-test
[ ] [ "blahblah" temp-file make-directory ] unit-test
[ t ] [ "blahblah" temp-file directory? ] unit-test
2007-09-20 18:09:08 -04:00
[ "passwd" ] [ "/etc/passwd" file-name ] unit-test
2008-02-06 20:23:39 -05:00
[ "awk" ] [ "/usr/libexec/awk/" file-name ] unit-test
[ "awk" ] [ "/usr/libexec/awk///" file-name ] unit-test
2008-03-25 20:50:39 -04:00
[ "" ] [ "" file-name ] unit-test
2007-09-20 18:09:08 -04:00
[ ] [
2008-03-07 22:26:35 -05:00
{ "Hello world." }
"test-foo.txt" temp-file ascii set-file-lines
2007-09-20 18:09:08 -04:00
] unit-test
[ ] [
"test-foo.txt" temp-file ascii [
2007-09-20 18:09:08 -04:00
"Hello appender." print
] with-file-appender
2007-09-20 18:09:08 -04:00
] unit-test
[ ] [
"test-bar.txt" temp-file ascii [
2007-09-20 18:09:08 -04:00
"Hello appender." print
] with-file-appender
2007-09-20 18:09:08 -04:00
] unit-test
[ "Hello world.\nHello appender.\n" ] [
"test-foo.txt" temp-file ascii file-contents
2007-09-20 18:09:08 -04:00
] unit-test
[ "Hello appender.\n" ] [
"test-bar.txt" temp-file ascii file-contents
2007-09-20 18:09:08 -04:00
] unit-test
2008-02-27 15:59:15 -05:00
[ ] [ "test-foo.txt" temp-file delete-file ] unit-test
2007-09-20 18:09:08 -04:00
2008-02-27 15:59:15 -05:00
[ ] [ "test-bar.txt" temp-file delete-file ] unit-test
2007-09-20 18:09:08 -04:00
2008-02-27 15:59:15 -05:00
[ f ] [ "test-foo.txt" temp-file exists? ] unit-test
2007-09-20 18:09:08 -04:00
2008-02-27 15:59:15 -05:00
[ f ] [ "test-bar.txt" temp-file exists? ] unit-test
2007-09-20 18:09:08 -04:00
2008-02-27 15:59:15 -05:00
[ ] [ "test-blah" temp-file make-directory ] unit-test
2007-09-20 18:09:08 -04:00
[ ] [
"test-blah/fooz" temp-file ascii <file-writer> dispose
2007-09-20 18:09:08 -04:00
] unit-test
[ t ] [
2008-02-27 15:59:15 -05:00
"test-blah/fooz" temp-file exists?
2007-09-20 18:09:08 -04:00
] unit-test
2008-02-27 15:59:15 -05:00
[ ] [ "test-blah/fooz" temp-file delete-file ] unit-test
2007-09-20 18:09:08 -04:00
2008-02-27 15:59:15 -05:00
[ ] [ "test-blah" temp-file delete-directory ] unit-test
2007-09-20 18:09:08 -04:00
2008-02-27 15:59:15 -05:00
[ f ] [ "test-blah" temp-file exists? ] unit-test
2007-09-20 18:09:08 -04:00
[ ] [ "test-quux.txt" temp-file ascii [ [ yield "Hi" write ] "Test" spawn drop ] with-file-writer ] unit-test
2007-09-20 18:09:08 -04:00
2008-02-27 15:59:15 -05:00
[ ] [ "test-quux.txt" temp-file delete-file ] unit-test
2007-09-20 18:09:08 -04:00
[ ] [ "test-quux.txt" temp-file ascii [ [ yield "Hi" write ] "Test" spawn drop ] with-file-writer ] unit-test
2007-09-20 18:09:08 -04:00
2008-02-27 15:59:15 -05:00
[ ] [ "test-quux.txt" "quux-test.txt" [ temp-file ] 2apply move-file ] unit-test
[ t ] [ "quux-test.txt" temp-file exists? ] unit-test
2007-09-20 18:09:08 -04:00
2008-02-27 15:59:15 -05:00
[ ] [ "quux-test.txt" temp-file delete-file ] unit-test
2007-09-20 18:09:08 -04:00
2008-02-27 15:59:15 -05:00
[ ] [ "delete-tree-test/a/b/c" temp-file make-directories ] unit-test
[ ] [
2008-03-07 22:26:35 -05:00
{ "Hi" }
"delete-tree-test/a/b/c/d" temp-file ascii set-file-lines
2008-02-27 15:59:15 -05:00
] unit-test
[ ] [
"delete-tree-test" temp-file delete-tree
] unit-test
[ { { "kernel" t } } ] [
"core" resource-path [
"." directory [ first "kernel" = ] subset
] with-directory
] unit-test
2008-02-27 15:59:15 -05:00
[ ] [
"copy-tree-test/a/b/c" temp-file make-directories
] unit-test
[ ] [
2008-03-07 22:26:35 -05:00
"Foobar"
2008-02-27 15:59:15 -05:00
"copy-tree-test/a/b/c/d" temp-file
2008-03-07 22:26:35 -05:00
ascii set-file-contents
2008-02-27 15:59:15 -05:00
] unit-test
[ ] [
"copy-tree-test" temp-file
"copy-destination" temp-file copy-tree
] unit-test
[ "Foobar" ] [
2008-03-04 19:12:01 -05:00
"copy-destination/a/b/c/d" temp-file ascii file-contents
2008-02-27 15:59:15 -05:00
] unit-test
[ ] [
"copy-destination" temp-file delete-tree
] unit-test
[ ] [
"copy-tree-test" temp-file
2008-03-01 16:52:34 -05:00
"copy-destination" temp-file copy-tree-into
2008-02-27 15:59:15 -05:00
] unit-test
[ "Foobar" ] [
2008-03-04 19:12:01 -05:00
"copy-destination/copy-tree-test/a/b/c/d" temp-file ascii file-contents
2008-02-27 15:59:15 -05:00
] unit-test
[ ] [
2008-03-01 16:52:34 -05:00
"copy-destination/copy-tree-test/a/b/c/d" temp-file "" temp-file copy-file-into
2008-02-27 15:59:15 -05:00
] unit-test
[ "Foobar" ] [
2008-03-04 19:12:01 -05:00
"d" temp-file ascii file-contents
2008-02-27 15:59:15 -05:00
] unit-test
[ ] [ "d" temp-file delete-file ] unit-test
[ ] [ "copy-destination" temp-file delete-tree ] unit-test
[ ] [ "copy-tree-test" temp-file delete-tree ] unit-test
[ t ] [ cwd "misc" resource-path [ ] with-directory cwd = ] unit-test
2008-03-15 07:23:10 -04:00
[ t ] [
2008-03-26 23:39:16 -04:00
temp-directory [ "hi41" "test41" utf8 set-file-contents ] with-directory
temp-directory "test41" append-path utf8 file-contents "hi41" =
] unit-test
[ t ] [
2008-03-26 23:39:16 -04:00
temp-directory [ "test41" file-info size>> ] with-directory 4 =
] unit-test
2008-03-15 07:23:10 -04:00
[ ] [ "append-test" temp-file dup exists? [ delete-file ] [ drop ] if ] unit-test
2008-03-21 01:37:58 -04:00
[ ] [ "append-test" temp-file ascii <file-appender> dispose ] unit-test
2008-03-20 17:57:13 -04:00
[ 123 ] [
"core" ".test" [
[
ascii [
123 CHAR: a <repetition> >string write
] with-file-writer
] keep file-info size>>
] with-unique-file
] unit-test
2008-03-25 20:50:39 -04:00
[ "/usr/lib" ] [ "/usr" "lib" append-path ] unit-test
[ "/usr/lib" ] [ "/usr/" "lib" append-path ] unit-test
[ "/lib" ] [ "/usr/" "/lib" append-path ] unit-test
[ "/lib/" ] [ "/usr/" "/lib/" append-path ] unit-test
[ "/usr/lib" ] [ "/usr" "./lib" append-path ] unit-test
[ "/usr/lib/" ] [ "/usr" "./lib/" append-path ] unit-test
[ "/lib" ] [ "/usr" "../lib" append-path ] unit-test
[ "/lib/" ] [ "/usr" "../lib/" append-path ] unit-test
[ "" ] [ "" "." append-path ] unit-test
[ "" ".." append-path ] must-fail
[ "/" ] [ "/" "./." append-path ] unit-test
[ "/" ] [ "/" "././" append-path ] unit-test
[ "/a/b/lib" ] [ "/a/b/c/d/e/f/" "../../../../lib" append-path ] unit-test
[ "/a/b/lib/" ] [ "/a/b/c/d/e/f/" "../../../../lib/" append-path ] unit-test
[ "" "../lib/" append-path ] must-fail
[ "lib" ] [ "" "lib" append-path ] unit-test
[ "lib" ] [ "" "./lib" append-path ] unit-test
[ "/lib/bux" ] [ "/usr" "/lib/bux" append-path ] unit-test
[ "/lib/bux/" ] [ "/usr" "/lib/bux/" append-path ] unit-test
2008-03-26 16:24:54 -04:00
[ "foo/bar/." parent-directory ] must-fail
[ "foo/bar/./" parent-directory ] must-fail
[ "foo/bar/baz/.." parent-directory ] must-fail
[ "foo/bar/baz/../" parent-directory ] must-fail
2008-03-25 20:50:39 -04:00
[ "." parent-directory ] must-fail
[ "./" parent-directory ] must-fail
[ ".." parent-directory ] must-fail
[ "../" parent-directory ] must-fail
[ "../../" parent-directory ] must-fail
[ "foo/.." parent-directory ] must-fail
[ "foo/../" parent-directory ] must-fail
2008-03-26 16:24:54 -04:00
[ "" parent-directory ] must-fail
[ "." ] [ "boot.x86.64.image" parent-directory ] unit-test
2008-03-25 20:50:39 -04:00
[ "bar/foo" ] [ "bar/baz" "..///foo" append-path ] unit-test
[ "bar/baz/foo" ] [ "bar/baz" ".///foo" append-path ] unit-test
[ "bar/foo" ] [ "bar/baz" "./..//foo" append-path ] unit-test
[ "bar/foo" ] [ "bar/baz" "./../././././././///foo" append-path ] unit-test