]> gitweb.factorcode.org Git - factor.git/blob - basis/io/files/windows/windows-tests.factor
c5c7a1ff03f54a641578aca538fa58b4ad1538a3
[factor.git] / basis / io / files / windows / windows-tests.factor
1 ! Copyright (C) 2010 Doug Coleman.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: combinators continuations io.backend io.directories io.files
4 io.files.temp io.files.windows io.pathnames kernel kernel.private libc
5 literals memory sequences splitting tools.test windows.kernel32
6 io.files.unique destructors ;
7 IN: io.files.windows.tests
8
9 [ f ] [ "\\foo" absolute-path? ] unit-test
10 [ t ] [ "\\\\?\\c:\\foo" absolute-path? ] unit-test
11 [ t ] [ "\\\\?\\c:\\" absolute-path? ] unit-test
12 [ t ] [ "\\\\?\\c:" absolute-path? ] unit-test
13 [ t ] [ "c:\\foo" absolute-path? ] unit-test
14 [ t ] [ "c:" absolute-path? ] unit-test
15 [ t ] [ "c:\\" absolute-path? ] unit-test
16 [ f ] [ "/cygdrive/c/builds" absolute-path? ] unit-test
17
18 [ "c:\\foo\\" ] [ "c:\\foo\\bar" parent-directory ] unit-test
19 [ "c:\\" ] [ "c:\\foo\\" parent-directory ] unit-test
20 [ "c:\\" ] [ "c:\\foo" parent-directory ] unit-test
21 ! { "c:" "c:\\" "c:/" } [ directory ] each -- all do the same thing
22 [ "c:\\" ] [ "c:\\" parent-directory ] unit-test
23 [ "Z:\\" ] [ "Z:\\" parent-directory ] unit-test
24 [ "c:" ] [ "c:" parent-directory ] unit-test
25 [ "Z:" ] [ "Z:" parent-directory ] unit-test
26
27 [ f ] [ "" root-directory? ] unit-test
28 [ t ] [ "\\" root-directory? ] unit-test
29 [ t ] [ "\\\\" root-directory? ] unit-test
30 [ t ] [ "/" root-directory? ] unit-test
31 [ t ] [ "//" root-directory? ] unit-test
32 [ t ] [ "c:\\" trim-tail-separators root-directory? ] unit-test
33 [ t ] [ "Z:\\" trim-tail-separators root-directory? ] unit-test
34 [ f ] [ "c:\\foo" root-directory? ] unit-test
35 [ f ] [ "." root-directory? ] unit-test
36 [ f ] [ ".." root-directory? ] unit-test
37 [ t ] [ "\\\\?\\c:\\" root-directory? ] unit-test
38 [ t ] [ "\\\\?\\c:" root-directory? ] unit-test
39 [ f ] [ "\\\\?\\c:\\bar" root-directory? ] unit-test
40
41 [ "\\\\a\\b\\c\\foo.xls" ] [ "//a/b/c/foo.xls" normalize-path ] unit-test
42 [ "\\\\a\\b\\c\\foo.xls" ] [ "\\\\a\\b\\c\\foo.xls" normalize-path ] unit-test
43
44 [ "\\foo\\bar" ] [ "/foo/bar" normalize-path ":" split1 nip ] unit-test
45
46 [ "\\\\?\\C:\\builds\\factor\\log.txt" ] [
47     "C:\\builds\\factor\\12345\\"
48     "..\\log.txt" append-path normalize-path
49 ] unit-test
50
51 [ "\\\\?\\C:\\builds\\" ] [
52     "C:\\builds\\factor\\12345\\"
53     "..\\.." append-path normalize-path
54 ] unit-test
55
56 [ "\\\\?\\C:\\builds\\" ] [
57     "C:\\builds\\factor\\12345\\"
58     "..\\.." append-path normalize-path
59 ] unit-test
60
61 [ "c:\\blah" ] [ "c:\\foo\\bar" "\\blah" append-path ] unit-test
62 [ t ] [ "" resource-path 2 tail exists? ] unit-test
63
64 ! win32-file-attributes
65 {
66     { +read-only+ +hidden+ }
67 } [
68     3 win32-file-attributes
69 ] unit-test
70
71 ! set-file-attributes & save-image
72 { ${ KERNEL-ERROR ERROR-IO EIO f } } [
73     [
74         "read-only.image" temp-file {
75             [ ?delete-file ]
76             [ touch-file ]
77             [ FILE_ATTRIBUTE_READONLY set-file-attributes ]
78             [ save-image ]
79         } cleave
80     ] [ ] recover
81 ] unit-test
82
83 ! test that we can open a shared file
84 ! https://github.com/factor/factor/pull/1636
85 { } [
86     "open-file-" "-test.txt" [
87         [ open-write ] [ open-read ] bi [ dispose ] bi@
88     ] cleanup-unique-file
89 ] unit-test