win32-file 0.6.3 → 0.6.4
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGES +7 -4
- data/Rakefile +49 -50
- data/lib/win32/file.rb +1285 -1266
- data/test/test_win32_file_attributes.rb +1 -1
- data/test/test_win32_file_path.rb +199 -163
- data/win32-file.gemspec +25 -27
- metadata +47 -24
@@ -11,188 +11,224 @@ require 'test/unit'
|
|
11
11
|
require 'win32/file'
|
12
12
|
|
13
13
|
class TC_Win32_File_Path < Test::Unit::TestCase
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
14
|
+
def self.startup
|
15
|
+
Dir.chdir(File.dirname(File.expand_path(File.basename(__FILE__))))
|
16
|
+
@@file = File.join(Dir.pwd, 'path_test.txt')
|
17
|
+
File.open(@@file, 'w'){ |fh| fh.puts "This is a path test." }
|
18
|
+
end
|
19
19
|
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
20
|
+
def setup
|
21
|
+
@long_file = File.join(Dir.pwd, 'path_test.txt')
|
22
|
+
@short_file = File.join(Dir.pwd, 'PATH_T~1.TXT')
|
23
|
+
end
|
24
24
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
25
|
+
test "basename method basic functionality" do
|
26
|
+
assert_respond_to(File, :basename)
|
27
|
+
assert_nothing_raised{ File.basename("C:\\foo") }
|
28
|
+
assert_kind_of(String, File.basename("C:\\foo"))
|
29
|
+
end
|
30
30
|
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
31
|
+
test "basename method handles standard paths" do
|
32
|
+
assert_equal("baz.txt", File.basename("C:\\foo\\bar\\baz.txt"))
|
33
|
+
assert_equal("baz", File.basename("C:\\foo\\bar\\baz.txt", ".txt"))
|
34
|
+
assert_equal("baz.txt", File.basename("C:\\foo\\bar\\baz.txt", ".zip"))
|
35
|
+
assert_equal("bar", File.basename("C:\\foo\\bar"))
|
36
|
+
assert_equal("bar", File.basename("C:\\foo\\bar\\"))
|
37
|
+
assert_equal("foo", File.basename("C:\\foo"))
|
38
|
+
assert_equal("C:\\", File.basename("C:\\"))
|
39
|
+
end
|
40
40
|
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
41
|
+
test "basename method handles unc paths" do
|
42
|
+
assert_equal("baz.txt", File.basename("\\\\foo\\bar\\baz.txt"))
|
43
|
+
assert_equal("baz", File.basename("\\\\foo\\bar\\baz"))
|
44
|
+
assert_equal("\\\\foo", File.basename("\\\\foo"))
|
45
|
+
assert_equal("\\\\foo\\bar", File.basename("\\\\foo\\bar"))
|
46
|
+
end
|
47
|
+
|
48
|
+
test "basename method handles forward slashes in standard unix paths" do
|
49
|
+
assert_equal("bar", File.basename("/foo/bar"))
|
50
|
+
assert_equal("bar.txt", File.basename("/foo/bar.txt"))
|
51
|
+
assert_equal("bar.txt", File.basename("bar.txt"))
|
52
|
+
assert_equal("bar", File.basename("/bar"))
|
53
|
+
assert_equal("bar", File.basename("/bar/"))
|
54
|
+
assert_equal("baz", File.basename("//foo/bar/baz"))
|
55
|
+
end
|
56
|
+
|
57
|
+
test "basename method handles forward slashes in unc unix paths" do
|
58
|
+
assert_equal("\\\\foo", File.basename("//foo"))
|
59
|
+
assert_equal("\\\\foo\\bar", File.basename("//foo/bar"))
|
60
|
+
end
|
58
61
|
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
62
|
+
test "basename method handles forward slashes in windows paths" do
|
63
|
+
assert_equal("bar", File.basename("C:/foo/bar"))
|
64
|
+
assert_equal("bar", File.basename("C:/foo/bar/"))
|
65
|
+
assert_equal("foo", File.basename("C:/foo"))
|
66
|
+
assert_equal("C:\\", File.basename("C:/"))
|
67
|
+
assert_equal("bar", File.basename("C:/foo/bar//"))
|
68
|
+
end
|
66
69
|
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
70
|
+
test "basename handles edge cases as expected" do
|
71
|
+
assert_equal("", File.basename(""))
|
72
|
+
assert_equal(".", File.basename("."))
|
73
|
+
assert_equal("..", File.basename(".."))
|
74
|
+
assert_equal("foo", File.basename("//foo/"))
|
75
|
+
end
|
76
|
+
|
77
|
+
test "basename handles path names with suffixes" do
|
78
|
+
assert_equal("bar", File.basename("bar.txt", ".txt"))
|
79
|
+
assert_equal("bar", File.basename("/foo/bar.txt", ".txt"))
|
80
|
+
assert_equal("bar.txt", File.basename("bar.txt", ".exe"))
|
81
|
+
assert_equal("bar.txt", File.basename("bar.txt.exe", ".exe"))
|
82
|
+
assert_equal("bar.txt.exe", File.basename("bar.txt.exe", ".txt"))
|
83
|
+
assert_equal("bar", File.basename("bar.txt", ".*"))
|
84
|
+
assert_equal("bar.txt", File.basename("bar.txt.exe", ".*"))
|
85
|
+
end
|
73
86
|
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
assert_equal("bar.txt.exe", File.basename("bar.txt.exe", ".txt"))
|
80
|
-
assert_equal("bar", File.basename("bar.txt", ".*"))
|
81
|
-
assert_equal("bar.txt", File.basename("bar.txt.exe", ".*"))
|
82
|
-
end
|
83
|
-
|
84
|
-
def test_basename_does_not_modify_argument
|
85
|
-
path = "C:\\foo\\bar"
|
86
|
-
assert_nothing_raised{ File.basename(path) }
|
87
|
-
assert_equal("C:\\foo\\bar", path)
|
88
|
-
end
|
87
|
+
test "basename method does not modify its argument" do
|
88
|
+
path = "C:\\foo\\bar"
|
89
|
+
assert_nothing_raised{ File.basename(path) }
|
90
|
+
assert_equal("C:\\foo\\bar", path)
|
91
|
+
end
|
89
92
|
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
93
|
+
test "dirname basic functionality" do
|
94
|
+
assert_respond_to(File, :dirname)
|
95
|
+
assert_nothing_raised{ File.dirname("C:\\foo") }
|
96
|
+
assert_kind_of(String, File.dirname("C:\\foo"))
|
97
|
+
end
|
98
|
+
|
99
|
+
test "dirname handles standard windows paths as expected" do
|
100
|
+
assert_equal("C:\\foo", File.dirname("C:\\foo\\bar.txt"))
|
101
|
+
assert_equal("C:\\foo", File.dirname("C:\\foo\\bar"))
|
102
|
+
assert_equal("C:\\", File.dirname("C:\\foo"))
|
103
|
+
assert_equal("C:\\", File.dirname("C:\\"))
|
104
|
+
assert_equal(".", File.dirname("foo"))
|
105
|
+
end
|
103
106
|
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
107
|
+
test "dirname handles unc windows paths as expected" do
|
108
|
+
assert_equal("\\\\foo\\bar", File.dirname("\\\\foo\\bar\\baz"))
|
109
|
+
assert_equal("\\\\foo\\bar", File.dirname("\\\\foo\\bar"))
|
110
|
+
assert_equal("\\\\foo", File.dirname("\\\\foo"))
|
111
|
+
assert_equal("\\\\", File.dirname("\\\\"))
|
112
|
+
end
|
110
113
|
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
114
|
+
test "dirname handles forward slashes in standard windows path names" do
|
115
|
+
assert_equal("C:\\foo", File.dirname("C:/foo/bar.txt"))
|
116
|
+
assert_equal("C:\\foo", File.dirname("C:/foo/bar"))
|
117
|
+
assert_equal("C:\\", File.dirname("C:/foo"))
|
118
|
+
assert_equal("C:\\", File.dirname("C:/"))
|
119
|
+
end
|
120
|
+
|
121
|
+
test "dirname handles forward slashes in unc windows path names" do
|
122
|
+
assert_equal("\\\\foo\\bar", File.dirname("//foo/bar/baz"))
|
123
|
+
assert_equal("\\\\foo\\bar", File.dirname("//foo/bar"))
|
124
|
+
assert_equal("\\\\foo", File.dirname("//foo"))
|
125
|
+
assert_equal("\\\\", File.dirname("//"))
|
126
|
+
end
|
127
|
+
|
128
|
+
test "dirname handles forward slashes in relative path names" do
|
129
|
+
assert_equal(".", File.dirname("./foo"))
|
130
|
+
assert_equal(".\\foo", File.dirname("./foo/bar"))
|
131
|
+
end
|
132
|
+
|
133
|
+
test "dirname handles various edge cases as expected" do
|
134
|
+
assert_equal(".", File.dirname(""))
|
135
|
+
assert_equal(".", File.dirname("."))
|
136
|
+
assert_equal(".", File.dirname("."))
|
137
|
+
assert_equal(".", File.dirname("./"))
|
138
|
+
assert_raises(TypeError){ File.dirname(nil) }
|
139
|
+
end
|
131
140
|
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
141
|
+
test "dirname method does not modify its argument" do
|
142
|
+
path = "C:\\foo\\bar"
|
143
|
+
assert_nothing_raised{ File.dirname(path) }
|
144
|
+
assert_equal("C:\\foo\\bar", path)
|
145
|
+
end
|
137
146
|
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
147
|
+
test "split method basic functionality" do
|
148
|
+
assert_respond_to(File, :split)
|
149
|
+
assert_nothing_raised{ File.split("C:\\foo\\bar") }
|
150
|
+
assert_kind_of(Array, File.split("C:\\foo\\bar"))
|
151
|
+
end
|
143
152
|
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
+
test "split method handles standard windows path names" do
|
154
|
+
assert_equal(["C:\\foo", "bar"], File.split("C:\\foo\\bar"))
|
155
|
+
assert_equal([".", "foo"], File.split("foo"))
|
156
|
+
end
|
157
|
+
|
158
|
+
test "split method handles windows paths with forward slashes" do
|
159
|
+
assert_equal(["C:\\foo", "bar"], File.split("C:/foo/bar"))
|
160
|
+
assert_equal([".", "foo"], File.split("foo"))
|
161
|
+
end
|
153
162
|
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
163
|
+
test "split method handles standard unix paths as expected" do
|
164
|
+
assert_equal(["\\foo","bar"], File.split("/foo/bar"))
|
165
|
+
assert_equal(["\\", "foo"], File.split("/foo"))
|
166
|
+
assert_equal([".", "foo"], File.split("foo"))
|
167
|
+
end
|
159
168
|
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
169
|
+
test "split method handles unc paths as expected" do
|
170
|
+
assert_equal(["\\\\foo\\bar", "baz"], File.split("\\\\foo\\bar\\baz"))
|
171
|
+
assert_equal(["\\\\foo\\bar", ""], File.split("\\\\foo\\bar"))
|
172
|
+
assert_equal(["\\\\foo", ""], File.split("\\\\foo"))
|
173
|
+
assert_equal(["\\\\", ""], File.split("\\\\"))
|
174
|
+
end
|
166
175
|
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
176
|
+
test "split method handles various edge cases as expected" do
|
177
|
+
assert_equal(["C:\\", ""], File.split("C:\\"))
|
178
|
+
assert_equal(["", ""], File.split(""))
|
179
|
+
end
|
171
180
|
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
181
|
+
test "split method does not modify its arguments" do
|
182
|
+
path = "C:\\foo\\bar"
|
183
|
+
assert_nothing_raised{ File.split(path) }
|
184
|
+
assert_equal("C:\\foo\\bar", path)
|
185
|
+
end
|
177
186
|
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
187
|
+
test "long_path method works as expected" do
|
188
|
+
assert_respond_to(File, :long_path)
|
189
|
+
assert_equal(@long_file, File.long_path(@short_file))
|
190
|
+
assert_equal('PATH_T~1.TXT', File.basename(@short_file))
|
191
|
+
end
|
183
192
|
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
193
|
+
test "short_path method works as expected" do
|
194
|
+
assert_respond_to(File, :short_path)
|
195
|
+
assert_equal('path_test.txt', File.basename(@long_file))
|
196
|
+
end
|
197
|
+
|
198
|
+
test "join method works as expected" do
|
199
|
+
assert_respond_to(File, :join)
|
200
|
+
end
|
201
|
+
|
202
|
+
test "join handles multiple arguments as expected" do
|
203
|
+
assert_equal("C:\\foo\\bar", File.join("C:", "foo", "bar"))
|
204
|
+
assert_equal("foo\\bar", File.join("foo", "bar"))
|
205
|
+
end
|
206
|
+
|
207
|
+
test "join handles multiple arguments as expected with unc paths" do
|
208
|
+
assert_equal("\\\\foo", File.join("\\\\foo"))
|
209
|
+
assert_equal("\\\\foo\\bar", File.join("\\\\foo", "bar"))
|
210
|
+
end
|
211
|
+
|
212
|
+
test "join does not normalize paths" do
|
213
|
+
assert_equal("C:\\.\\foo\\..", File.join("C:", ".", "foo", ".."))
|
214
|
+
end
|
215
|
+
|
216
|
+
test "join with no arguments returns an empty string" do
|
217
|
+
assert_equal('', File.join)
|
218
|
+
end
|
219
|
+
|
220
|
+
test "join with one argument returns the argument" do
|
221
|
+
assert_equal('foo', File.join('foo'))
|
222
|
+
assert_equal('c:', File.join('c:'))
|
223
|
+
end
|
188
224
|
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
225
|
+
def teardown
|
226
|
+
@short_file = nil
|
227
|
+
@long_file = nil
|
228
|
+
end
|
193
229
|
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
230
|
+
def self.shutdown
|
231
|
+
File.delete(@@file) if File.exists?(@@file)
|
232
|
+
@@file = nil
|
233
|
+
end
|
198
234
|
end
|
data/win32-file.gemspec
CHANGED
@@ -1,34 +1,32 @@
|
|
1
1
|
require 'rubygems'
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
3
|
+
Gem::Specification.new do |spec|
|
4
|
+
spec.name = 'win32-file'
|
5
|
+
spec.version = '0.6.4'
|
6
|
+
spec.authors = ['Daniel J. Berger', 'Park Heesob']
|
7
|
+
spec.license = 'Artistic 2.0'
|
8
|
+
spec.email = 'djberg96@gmail.com'
|
9
|
+
spec.homepage = 'http://www.rubyforge.org/projects/win32utils'
|
10
|
+
spec.platform = Gem::Platform::RUBY
|
11
|
+
spec.summary = 'Extra or redefined methods for the File class on Windows.'
|
12
|
+
spec.test_files = Dir['test/test*']
|
13
|
+
spec.has_rdoc = true
|
14
|
+
spec.files = Dir['**/*'].reject{ |f| f.include?('git') }
|
15
15
|
|
16
|
-
|
17
|
-
|
16
|
+
spec.rubyforge_project = 'win32utils'
|
17
|
+
spec.extra_rdoc_files = ['README', 'CHANGES', 'MANIFEST']
|
18
18
|
|
19
|
-
|
20
|
-
|
21
|
-
|
19
|
+
spec.add_dependency('win32-api', '>= 1.2.1')
|
20
|
+
spec.add_dependency('win32-file-stat', '>= 1.3.2')
|
21
|
+
spec.add_dependency('windows-pr', '>= 1.0.8')
|
22
22
|
|
23
|
-
|
23
|
+
spec.add_development_dependency('test-unit', '>= 2.0.7')
|
24
24
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
25
|
+
spec.description = <<-EOF
|
26
|
+
The win32-file library adds several methods to the core File class which
|
27
|
+
are specific to MS Windows, such as the ability to set and retrieve file
|
28
|
+
attributes. In addition, several core methods have been redefined in
|
29
|
+
order to work properly on MS Windows, such as File.blksize. See the
|
30
|
+
README file for more details.
|
31
|
+
EOF
|
32
32
|
end
|
33
|
-
|
34
|
-
Gem::Builder.new(spec).build
|