win32-file 0.6.7 → 0.6.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/CHANGES +5 -0
- data/README +80 -70
- data/Rakefile +0 -2
- data/lib/win32/file.rb +1296 -1298
- data/test/test_win32_file_attributes.rb +43 -43
- data/test/test_win32_file_path.rb +256 -256
- data/test/test_win32_file_stat.rb +17 -14
- data/win32-file.gemspec +2 -3
- metadata +12 -12
@@ -26,21 +26,21 @@ class TC_Win32_File_Attributes < Test::Unit::TestCase
|
|
26
26
|
end
|
27
27
|
|
28
28
|
def test_version
|
29
|
-
assert_equal('0.6.
|
29
|
+
assert_equal('0.6.8', File::WIN32_FILE_VERSION)
|
30
30
|
end
|
31
|
-
|
31
|
+
|
32
32
|
def test_is_directory
|
33
33
|
assert_true(File.directory?(Dir.pwd))
|
34
34
|
assert_false(File.directory?(@@file))
|
35
|
-
assert_false(File.directory?('C:/aaabbbccc'))
|
35
|
+
assert_false(File.directory?('C:/aaabbbccc'))
|
36
36
|
end
|
37
|
-
|
37
|
+
|
38
38
|
def test_temporary
|
39
39
|
assert_respond_to(File, :temporary?)
|
40
|
-
assert_nothing_raised{ File.temporary?(@@file) }
|
40
|
+
assert_nothing_raised{ File.temporary?(@@file) }
|
41
41
|
assert_equal(false, File.temporary?(@@file))
|
42
42
|
end
|
43
|
-
|
43
|
+
|
44
44
|
def test_temporary_instance
|
45
45
|
assert_respond_to(@fh, :temporary=)
|
46
46
|
assert_nothing_raised{ @fh.temporary = true }
|
@@ -51,13 +51,13 @@ class TC_Win32_File_Attributes < Test::Unit::TestCase
|
|
51
51
|
assert_raises(ArgumentError){ File.temporary? }
|
52
52
|
assert_raises(ArgumentError){ File.temporary?(@@file, 'foo') }
|
53
53
|
end
|
54
|
-
|
54
|
+
|
55
55
|
def test_system
|
56
56
|
assert_respond_to(File, :system?)
|
57
|
-
assert_nothing_raised{ File.system?(@@file) }
|
57
|
+
assert_nothing_raised{ File.system?(@@file) }
|
58
58
|
assert_equal(false, File.system?(@@file))
|
59
59
|
end
|
60
|
-
|
60
|
+
|
61
61
|
def test_system_instance
|
62
62
|
assert_respond_to(@fh, :system=)
|
63
63
|
assert_nothing_raised{ @fh.system = true }
|
@@ -68,13 +68,13 @@ class TC_Win32_File_Attributes < Test::Unit::TestCase
|
|
68
68
|
assert_raises(ArgumentError){ File.system? }
|
69
69
|
assert_raises(ArgumentError){ File.system?(@@file, 'foo') }
|
70
70
|
end
|
71
|
-
|
71
|
+
|
72
72
|
def test_sparse
|
73
73
|
assert_respond_to(File, :sparse?)
|
74
|
-
assert_nothing_raised{ File.sparse?(@@file) }
|
74
|
+
assert_nothing_raised{ File.sparse?(@@file) }
|
75
75
|
assert_equal(false, File.sparse?(@@file))
|
76
76
|
end
|
77
|
-
|
77
|
+
|
78
78
|
# I don't actually test assignment here since making a file a sparse
|
79
79
|
# file can't be undone.
|
80
80
|
def test_sparse_instance
|
@@ -85,10 +85,10 @@ class TC_Win32_File_Attributes < Test::Unit::TestCase
|
|
85
85
|
assert_raises(ArgumentError){ File.sparse? }
|
86
86
|
assert_raises(ArgumentError){ File.sparse?(@@file, 'foo') }
|
87
87
|
end
|
88
|
-
|
88
|
+
|
89
89
|
def test_reparse_point
|
90
90
|
assert_respond_to(File, :reparse_point?)
|
91
|
-
assert_nothing_raised{ File.reparse_point?(@@file) }
|
91
|
+
assert_nothing_raised{ File.reparse_point?(@@file) }
|
92
92
|
assert_equal(false, File.reparse_point?(@@file))
|
93
93
|
end
|
94
94
|
|
@@ -96,10 +96,10 @@ class TC_Win32_File_Attributes < Test::Unit::TestCase
|
|
96
96
|
assert_raises(ArgumentError){ File.reparse_point? }
|
97
97
|
assert_raises(ArgumentError){ File.reparse_point?(@@file, 'foo') }
|
98
98
|
end
|
99
|
-
|
99
|
+
|
100
100
|
def test_readonly
|
101
101
|
assert_respond_to(File, :readonly?)
|
102
|
-
assert_nothing_raised{ File.readonly?(@@file) }
|
102
|
+
assert_nothing_raised{ File.readonly?(@@file) }
|
103
103
|
assert_equal(false, File.readonly?(@@file))
|
104
104
|
end
|
105
105
|
|
@@ -107,7 +107,7 @@ class TC_Win32_File_Attributes < Test::Unit::TestCase
|
|
107
107
|
assert_respond_to(File, :read_only?)
|
108
108
|
assert_equal(true, File.method(:readonly?) == File.method(:read_only?))
|
109
109
|
end
|
110
|
-
|
110
|
+
|
111
111
|
def test_readonly_instance
|
112
112
|
assert_respond_to(@fh, :readonly=)
|
113
113
|
assert_nothing_raised{ @fh.readonly = true }
|
@@ -118,13 +118,13 @@ class TC_Win32_File_Attributes < Test::Unit::TestCase
|
|
118
118
|
assert_raises(ArgumentError){ File.read_only? }
|
119
119
|
assert_raises(ArgumentError){ File.read_only?(@@file, 'foo') }
|
120
120
|
end
|
121
|
-
|
121
|
+
|
122
122
|
def test_offline
|
123
123
|
assert_respond_to(File, :offline?)
|
124
|
-
assert_nothing_raised{ File.offline?(@@file) }
|
124
|
+
assert_nothing_raised{ File.offline?(@@file) }
|
125
125
|
assert_equal(false, File.offline?(@@file))
|
126
126
|
end
|
127
|
-
|
127
|
+
|
128
128
|
def test_offline_instance
|
129
129
|
assert_respond_to(@fh, :offline=)
|
130
130
|
assert_nothing_raised{ @fh.offline = true }
|
@@ -135,13 +135,13 @@ class TC_Win32_File_Attributes < Test::Unit::TestCase
|
|
135
135
|
assert_raises(ArgumentError){ File.offline? }
|
136
136
|
assert_raises(ArgumentError){ File.offline?(@@file, 'foo') }
|
137
137
|
end
|
138
|
-
|
138
|
+
|
139
139
|
def test_normal
|
140
140
|
assert_respond_to(File, :normal?)
|
141
|
-
assert_nothing_raised{ File.normal?(@@file) }
|
141
|
+
assert_nothing_raised{ File.normal?(@@file) }
|
142
142
|
assert_equal(false, File.normal?(@@file))
|
143
143
|
end
|
144
|
-
|
144
|
+
|
145
145
|
def test_normal_instance
|
146
146
|
assert_respond_to(@fh, :normal=)
|
147
147
|
assert_nothing_raised{ @fh.normal = true }
|
@@ -153,13 +153,13 @@ class TC_Win32_File_Attributes < Test::Unit::TestCase
|
|
153
153
|
assert_raises(ArgumentError){ File.normal?(@@file, 'foo') }
|
154
154
|
assert_raises(ArgumentError){ @fh.normal = false }
|
155
155
|
end
|
156
|
-
|
156
|
+
|
157
157
|
def test_hidden
|
158
158
|
assert_respond_to(File, :hidden?)
|
159
|
-
assert_nothing_raised{ File.hidden?(@@file) }
|
159
|
+
assert_nothing_raised{ File.hidden?(@@file) }
|
160
160
|
assert_equal(false, File.hidden?(@@file))
|
161
161
|
end
|
162
|
-
|
162
|
+
|
163
163
|
def test_hidden_instance
|
164
164
|
assert_respond_to(@fh, :hidden=)
|
165
165
|
assert_nothing_raised{ @fh.hidden = true }
|
@@ -169,22 +169,22 @@ class TC_Win32_File_Attributes < Test::Unit::TestCase
|
|
169
169
|
def test_hidden_expected_errors
|
170
170
|
assert_raises(ArgumentError){ File.hidden? }
|
171
171
|
assert_raises(ArgumentError){ File.hidden?(@@file, 'foo') }
|
172
|
-
end
|
172
|
+
end
|
173
173
|
|
174
174
|
def test_encrypted
|
175
175
|
assert_respond_to(File, :encrypted?)
|
176
|
-
assert_nothing_raised{ File.encrypted?(@@file) }
|
176
|
+
assert_nothing_raised{ File.encrypted?(@@file) }
|
177
177
|
assert_equal(false, File.encrypted?(@@file))
|
178
178
|
end
|
179
179
|
|
180
180
|
def test_encrypted_expected_errors
|
181
181
|
assert_raises(ArgumentError){ File.encrypted? }
|
182
182
|
assert_raises(ArgumentError){ File.encrypted?(@@file, 'foo') }
|
183
|
-
end
|
183
|
+
end
|
184
184
|
|
185
185
|
def test_indexed
|
186
186
|
assert_respond_to(File, :indexed?)
|
187
|
-
assert_nothing_raised{ File.indexed?(@@file) }
|
187
|
+
assert_nothing_raised{ File.indexed?(@@file) }
|
188
188
|
assert_equal(true, File.indexed?(@@file))
|
189
189
|
end
|
190
190
|
|
@@ -192,7 +192,7 @@ class TC_Win32_File_Attributes < Test::Unit::TestCase
|
|
192
192
|
assert_respond_to(File, :content_indexed?)
|
193
193
|
assert(File.method(:content_indexed?) == File.method(:indexed?))
|
194
194
|
end
|
195
|
-
|
195
|
+
|
196
196
|
def test_indexed_instance
|
197
197
|
assert_respond_to(@fh, :indexed=)
|
198
198
|
assert_nothing_raised{ @fh.indexed = true }
|
@@ -202,14 +202,14 @@ class TC_Win32_File_Attributes < Test::Unit::TestCase
|
|
202
202
|
def test_indexed_expected_errors
|
203
203
|
assert_raises(ArgumentError){ File.indexed? }
|
204
204
|
assert_raises(ArgumentError){ File.indexed?(@@file, 'foo') }
|
205
|
-
end
|
205
|
+
end
|
206
206
|
|
207
207
|
def test_compressed
|
208
208
|
assert_respond_to(File, :compressed?)
|
209
|
-
assert_nothing_raised{ File.compressed?(@@file) }
|
209
|
+
assert_nothing_raised{ File.compressed?(@@file) }
|
210
210
|
assert_equal(false, File.compressed?(@@file))
|
211
211
|
end
|
212
|
-
|
212
|
+
|
213
213
|
# We have to explicitly reset the compressed attribute to false as
|
214
214
|
# the last of these assertions.
|
215
215
|
def test_compressed_instance
|
@@ -226,31 +226,31 @@ class TC_Win32_File_Attributes < Test::Unit::TestCase
|
|
226
226
|
def test_compressed_expected_errors
|
227
227
|
assert_raises(ArgumentError){ File.compressed? }
|
228
228
|
assert_raises(ArgumentError){ File.compressed?(@@file, 'foo') }
|
229
|
-
end
|
230
|
-
|
229
|
+
end
|
230
|
+
|
231
231
|
def test_archive
|
232
232
|
assert_respond_to(File, :archive?)
|
233
|
-
assert_nothing_raised{ File.archive?(@@file) }
|
233
|
+
assert_nothing_raised{ File.archive?(@@file) }
|
234
234
|
assert_equal(true, File.archive?(@@file))
|
235
235
|
end
|
236
|
-
|
236
|
+
|
237
237
|
def test_archive_instance
|
238
238
|
assert_respond_to(@fh, :archive=)
|
239
239
|
assert_nothing_raised{ @fh.archive = false }
|
240
240
|
assert_equal(false, File.archive?(@@file))
|
241
241
|
end
|
242
|
-
|
242
|
+
|
243
243
|
def test_archive_expected_errors
|
244
244
|
assert_raises(ArgumentError){ File.archive? }
|
245
245
|
assert_raises(ArgumentError){ File.archive?(@@file, 'foo') }
|
246
246
|
end
|
247
|
-
|
247
|
+
|
248
248
|
def test_attributes
|
249
249
|
assert_respond_to(File, :attributes)
|
250
250
|
assert_kind_of(Array, File.attributes(@@file))
|
251
251
|
assert_equal(['archive', 'indexed'], File.attributes(@@file))
|
252
252
|
end
|
253
|
-
|
253
|
+
|
254
254
|
def test_set_attributes
|
255
255
|
assert_respond_to(File, :set_attributes)
|
256
256
|
assert_nothing_raised{ File.set_attributes(@@file, File::HIDDEN) }
|
@@ -261,12 +261,12 @@ class TC_Win32_File_Attributes < Test::Unit::TestCase
|
|
261
261
|
assert_respond_to(File, :set_attr)
|
262
262
|
assert(File.method(:set_attr) == File.method(:set_attributes))
|
263
263
|
end
|
264
|
-
|
264
|
+
|
265
265
|
def test_remove_attributes
|
266
266
|
assert_respond_to(File, :remove_attributes)
|
267
267
|
assert_nothing_raised{ File.remove_attributes(@@file, File::ARCHIVE) }
|
268
268
|
assert_equal(false, File.archive?(@@file))
|
269
|
-
end
|
269
|
+
end
|
270
270
|
|
271
271
|
def test_unset_attr_alias
|
272
272
|
assert_respond_to(File, :unset_attr)
|
@@ -1,256 +1,256 @@
|
|
1
|
-
#############################################################################
|
2
|
-
# test_win32_file_path.rb
|
3
|
-
#
|
4
|
-
# Test case for the path related methods of win32-file. You should run this
|
5
|
-
# test via the 'rake test' or 'rake test_path' task.
|
6
|
-
#############################################################################
|
7
|
-
require 'rubygems'
|
8
|
-
gem 'test-unit'
|
9
|
-
|
10
|
-
require 'test/unit'
|
11
|
-
require 'win32/file'
|
12
|
-
|
13
|
-
class TC_Win32_File_Path < Test::Unit::TestCase
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
61
|
-
|
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
|
69
|
-
|
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
|
86
|
-
|
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
|
92
|
-
|
93
|
-
test "basename removes all trailing slashes" do
|
94
|
-
assert_equal("foo.txt", File.basename("C:/foo.txt/"))
|
95
|
-
assert_equal("foo.txt", File.basename("C:/foo.txt//"))
|
96
|
-
assert_equal("foo.txt", File.basename("C:/foo.txt///"))
|
97
|
-
assert_equal("foo.txt", File.basename("C:\\foo.txt\\"))
|
98
|
-
assert_equal("foo.txt", File.basename("C:\\foo.txt\\\\"))
|
99
|
-
assert_equal("foo.txt", File.basename("C:\\foo.txt\\\\\\"))
|
100
|
-
assert_equal("foo.txt", File.basename("foo.txt\\\\\\"))
|
101
|
-
end
|
102
|
-
|
103
|
-
test "dirname basic functionality" do
|
104
|
-
assert_respond_to(File, :dirname)
|
105
|
-
assert_nothing_raised{ File.dirname("C:\\foo") }
|
106
|
-
assert_kind_of(String, File.dirname("C:\\foo"))
|
107
|
-
end
|
108
|
-
|
109
|
-
test "dirname handles standard windows paths as expected" do
|
110
|
-
assert_equal("C:\\foo", File.dirname("C:\\foo\\bar.txt"))
|
111
|
-
assert_equal("C:\\foo", File.dirname("C:\\foo\\bar"))
|
112
|
-
assert_equal("C:\\", File.dirname("C:\\foo"))
|
113
|
-
assert_equal("C:\\", File.dirname("C:\\"))
|
114
|
-
assert_equal(".", File.dirname("foo"))
|
115
|
-
end
|
116
|
-
|
117
|
-
test "dirname handles unc windows paths as expected" do
|
118
|
-
assert_equal("\\\\foo\\bar", File.dirname("\\\\foo\\bar\\baz"))
|
119
|
-
assert_equal("\\\\foo\\bar", File.dirname("\\\\foo\\bar"))
|
120
|
-
assert_equal("\\\\foo", File.dirname("\\\\foo"))
|
121
|
-
assert_equal("\\\\", File.dirname("\\\\"))
|
122
|
-
end
|
123
|
-
|
124
|
-
test "dirname handles forward slashes in standard windows path names" do
|
125
|
-
assert_equal("C:\\foo", File.dirname("C:/foo/bar.txt"))
|
126
|
-
assert_equal("C:\\foo", File.dirname("C:/foo/bar"))
|
127
|
-
assert_equal("C:\\", File.dirname("C:/foo"))
|
128
|
-
assert_equal("C:\\", File.dirname("C:/"))
|
129
|
-
end
|
130
|
-
|
131
|
-
test "dirname handles forward slashes in unc windows path names" do
|
132
|
-
assert_equal("\\\\foo\\bar", File.dirname("//foo/bar/baz"))
|
133
|
-
assert_equal("\\\\foo\\bar", File.dirname("//foo/bar"))
|
134
|
-
assert_equal("\\\\foo", File.dirname("//foo"))
|
135
|
-
assert_equal("\\\\", File.dirname("//"))
|
136
|
-
end
|
137
|
-
|
138
|
-
test "dirname handles forward slashes in relative path names" do
|
139
|
-
assert_equal(".", File.dirname("./foo"))
|
140
|
-
assert_equal(".\\foo", File.dirname("./foo/bar"))
|
141
|
-
end
|
142
|
-
|
143
|
-
test "dirname handles various edge cases as expected" do
|
144
|
-
assert_equal(".", File.dirname(""))
|
145
|
-
assert_equal(".", File.dirname("."))
|
146
|
-
assert_equal(".", File.dirname(".."))
|
147
|
-
assert_equal(".", File.dirname("./"))
|
148
|
-
end
|
149
|
-
|
150
|
-
test "dirname method does not modify its argument" do
|
151
|
-
path = "C:\\foo\\bar"
|
152
|
-
assert_nothing_raised{ File.dirname(path) }
|
153
|
-
assert_equal("C:\\foo\\bar", path)
|
154
|
-
end
|
155
|
-
|
156
|
-
test "dirname method ignores trailing slashes" do
|
157
|
-
assert_equal("C:\\foo\\bar", File.dirname("C:/foo/bar/baz/"))
|
158
|
-
assert_equal("C:\\foo\\bar", File.dirname("C:/foo/bar/baz//"))
|
159
|
-
assert_equal("C:\\foo\\bar", File.dirname("C:/foo/bar/baz///"))
|
160
|
-
assert_equal("C:\\foo\\bar", File.dirname("C:\\foo\\bar\\baz\\"))
|
161
|
-
assert_equal("\\\\foo\\bar", File.dirname("\\\\foo\\bar\\baz\\"))
|
162
|
-
end
|
163
|
-
|
164
|
-
test "argument to dirname must be a string" do
|
165
|
-
assert_raises(TypeError){ File.dirname(nil) }
|
166
|
-
assert_raises(TypeError){ File.dirname(['foo', 'bar']) }
|
167
|
-
end
|
168
|
-
|
169
|
-
test "split method basic functionality" do
|
170
|
-
assert_respond_to(File, :split)
|
171
|
-
assert_nothing_raised{ File.split("C:\\foo\\bar") }
|
172
|
-
assert_kind_of(Array, File.split("C:\\foo\\bar"))
|
173
|
-
end
|
174
|
-
|
175
|
-
test "split method handles standard windows path names" do
|
176
|
-
assert_equal(["C:\\foo", "bar"], File.split("C:\\foo\\bar"))
|
177
|
-
assert_equal([".", "foo"], File.split("foo"))
|
178
|
-
end
|
179
|
-
|
180
|
-
test "split method handles windows paths with forward slashes" do
|
181
|
-
assert_equal(["C:\\foo", "bar"], File.split("C:/foo/bar"))
|
182
|
-
assert_equal([".", "foo"], File.split("foo"))
|
183
|
-
end
|
184
|
-
|
185
|
-
test "split method handles standard unix paths as expected" do
|
186
|
-
assert_equal(["\\foo","bar"], File.split("/foo/bar"))
|
187
|
-
assert_equal(["\\", "foo"], File.split("/foo"))
|
188
|
-
assert_equal([".", "foo"], File.split("foo"))
|
189
|
-
end
|
190
|
-
|
191
|
-
test "split method handles unc paths as expected" do
|
192
|
-
assert_equal(["\\\\foo\\bar", "baz"], File.split("\\\\foo\\bar\\baz"))
|
193
|
-
assert_equal(["\\\\foo\\bar", ""], File.split("\\\\foo\\bar"))
|
194
|
-
assert_equal(["\\\\foo", ""], File.split("\\\\foo"))
|
195
|
-
assert_equal(["\\\\", ""], File.split("\\\\"))
|
196
|
-
end
|
197
|
-
|
198
|
-
test "split method handles various edge cases as expected" do
|
199
|
-
assert_equal(["C:\\", ""], File.split("C:\\"))
|
200
|
-
assert_equal(["", ""], File.split(""))
|
201
|
-
end
|
202
|
-
|
203
|
-
test "split method does not modify its arguments" do
|
204
|
-
path = "C:\\foo\\bar"
|
205
|
-
assert_nothing_raised{ File.split(path) }
|
206
|
-
assert_equal("C:\\foo\\bar", path)
|
207
|
-
end
|
208
|
-
|
209
|
-
test "long_path method works as expected" do
|
210
|
-
assert_respond_to(File, :long_path)
|
211
|
-
assert_equal(@long_file, File.long_path(@short_file))
|
212
|
-
assert_equal('PATH_T~1.TXT', File.basename(@short_file))
|
213
|
-
end
|
214
|
-
|
215
|
-
test "short_path method works as expected" do
|
216
|
-
assert_respond_to(File, :short_path)
|
217
|
-
assert_equal('path_test.txt', File.basename(@long_file))
|
218
|
-
end
|
219
|
-
|
220
|
-
test "join method works as expected" do
|
221
|
-
assert_respond_to(File, :join)
|
222
|
-
end
|
223
|
-
|
224
|
-
test "join handles multiple arguments as expected" do
|
225
|
-
assert_equal("C:\\foo\\bar", File.join("C:", "foo", "bar"))
|
226
|
-
assert_equal("foo\\bar", File.join("foo", "bar"))
|
227
|
-
end
|
228
|
-
|
229
|
-
test "join handles multiple arguments as expected with unc paths" do
|
230
|
-
assert_equal("\\\\foo", File.join("\\\\foo"))
|
231
|
-
assert_equal("\\\\foo\\bar", File.join("\\\\foo", "bar"))
|
232
|
-
end
|
233
|
-
|
234
|
-
test "join does not normalize paths" do
|
235
|
-
assert_equal("C:\\.\\foo\\..", File.join("C:", ".", "foo", ".."))
|
236
|
-
end
|
237
|
-
|
238
|
-
test "join with no arguments returns an empty string" do
|
239
|
-
assert_equal('', File.join)
|
240
|
-
end
|
241
|
-
|
242
|
-
test "join with one argument returns the argument" do
|
243
|
-
assert_equal('foo', File.join('foo'))
|
244
|
-
assert_equal('c:', File.join('c:'))
|
245
|
-
end
|
246
|
-
|
247
|
-
def teardown
|
248
|
-
@short_file = nil
|
249
|
-
@long_file = nil
|
250
|
-
end
|
251
|
-
|
252
|
-
def self.shutdown
|
253
|
-
File.delete(@@file) if File.exists?(@@file)
|
254
|
-
@@file = nil
|
255
|
-
end
|
256
|
-
end
|
1
|
+
#############################################################################
|
2
|
+
# test_win32_file_path.rb
|
3
|
+
#
|
4
|
+
# Test case for the path related methods of win32-file. You should run this
|
5
|
+
# test via the 'rake test' or 'rake test_path' task.
|
6
|
+
#############################################################################
|
7
|
+
require 'rubygems'
|
8
|
+
gem 'test-unit'
|
9
|
+
|
10
|
+
require 'test/unit'
|
11
|
+
require 'win32/file'
|
12
|
+
|
13
|
+
class TC_Win32_File_Path < Test::Unit::TestCase
|
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
|
+
|
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
|
+
|
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
|
+
|
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
|
+
|
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
|
61
|
+
|
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
|
69
|
+
|
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
|
86
|
+
|
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
|
92
|
+
|
93
|
+
test "basename removes all trailing slashes" do
|
94
|
+
assert_equal("foo.txt", File.basename("C:/foo.txt/"))
|
95
|
+
assert_equal("foo.txt", File.basename("C:/foo.txt//"))
|
96
|
+
assert_equal("foo.txt", File.basename("C:/foo.txt///"))
|
97
|
+
assert_equal("foo.txt", File.basename("C:\\foo.txt\\"))
|
98
|
+
assert_equal("foo.txt", File.basename("C:\\foo.txt\\\\"))
|
99
|
+
assert_equal("foo.txt", File.basename("C:\\foo.txt\\\\\\"))
|
100
|
+
assert_equal("foo.txt", File.basename("foo.txt\\\\\\"))
|
101
|
+
end
|
102
|
+
|
103
|
+
test "dirname basic functionality" do
|
104
|
+
assert_respond_to(File, :dirname)
|
105
|
+
assert_nothing_raised{ File.dirname("C:\\foo") }
|
106
|
+
assert_kind_of(String, File.dirname("C:\\foo"))
|
107
|
+
end
|
108
|
+
|
109
|
+
test "dirname handles standard windows paths as expected" do
|
110
|
+
assert_equal("C:\\foo", File.dirname("C:\\foo\\bar.txt"))
|
111
|
+
assert_equal("C:\\foo", File.dirname("C:\\foo\\bar"))
|
112
|
+
assert_equal("C:\\", File.dirname("C:\\foo"))
|
113
|
+
assert_equal("C:\\", File.dirname("C:\\"))
|
114
|
+
assert_equal(".", File.dirname("foo"))
|
115
|
+
end
|
116
|
+
|
117
|
+
test "dirname handles unc windows paths as expected" do
|
118
|
+
assert_equal("\\\\foo\\bar", File.dirname("\\\\foo\\bar\\baz"))
|
119
|
+
assert_equal("\\\\foo\\bar", File.dirname("\\\\foo\\bar"))
|
120
|
+
assert_equal("\\\\foo", File.dirname("\\\\foo"))
|
121
|
+
assert_equal("\\\\", File.dirname("\\\\"))
|
122
|
+
end
|
123
|
+
|
124
|
+
test "dirname handles forward slashes in standard windows path names" do
|
125
|
+
assert_equal("C:\\foo", File.dirname("C:/foo/bar.txt"))
|
126
|
+
assert_equal("C:\\foo", File.dirname("C:/foo/bar"))
|
127
|
+
assert_equal("C:\\", File.dirname("C:/foo"))
|
128
|
+
assert_equal("C:\\", File.dirname("C:/"))
|
129
|
+
end
|
130
|
+
|
131
|
+
test "dirname handles forward slashes in unc windows path names" do
|
132
|
+
assert_equal("\\\\foo\\bar", File.dirname("//foo/bar/baz"))
|
133
|
+
assert_equal("\\\\foo\\bar", File.dirname("//foo/bar"))
|
134
|
+
assert_equal("\\\\foo", File.dirname("//foo"))
|
135
|
+
assert_equal("\\\\", File.dirname("//"))
|
136
|
+
end
|
137
|
+
|
138
|
+
test "dirname handles forward slashes in relative path names" do
|
139
|
+
assert_equal(".", File.dirname("./foo"))
|
140
|
+
assert_equal(".\\foo", File.dirname("./foo/bar"))
|
141
|
+
end
|
142
|
+
|
143
|
+
test "dirname handles various edge cases as expected" do
|
144
|
+
assert_equal(".", File.dirname(""))
|
145
|
+
assert_equal(".", File.dirname("."))
|
146
|
+
assert_equal(".", File.dirname(".."))
|
147
|
+
assert_equal(".", File.dirname("./"))
|
148
|
+
end
|
149
|
+
|
150
|
+
test "dirname method does not modify its argument" do
|
151
|
+
path = "C:\\foo\\bar"
|
152
|
+
assert_nothing_raised{ File.dirname(path) }
|
153
|
+
assert_equal("C:\\foo\\bar", path)
|
154
|
+
end
|
155
|
+
|
156
|
+
test "dirname method ignores trailing slashes" do
|
157
|
+
assert_equal("C:\\foo\\bar", File.dirname("C:/foo/bar/baz/"))
|
158
|
+
assert_equal("C:\\foo\\bar", File.dirname("C:/foo/bar/baz//"))
|
159
|
+
assert_equal("C:\\foo\\bar", File.dirname("C:/foo/bar/baz///"))
|
160
|
+
assert_equal("C:\\foo\\bar", File.dirname("C:\\foo\\bar\\baz\\"))
|
161
|
+
assert_equal("\\\\foo\\bar", File.dirname("\\\\foo\\bar\\baz\\"))
|
162
|
+
end
|
163
|
+
|
164
|
+
test "argument to dirname must be a string" do
|
165
|
+
assert_raises(TypeError){ File.dirname(nil) }
|
166
|
+
assert_raises(TypeError){ File.dirname(['foo', 'bar']) }
|
167
|
+
end
|
168
|
+
|
169
|
+
test "split method basic functionality" do
|
170
|
+
assert_respond_to(File, :split)
|
171
|
+
assert_nothing_raised{ File.split("C:\\foo\\bar") }
|
172
|
+
assert_kind_of(Array, File.split("C:\\foo\\bar"))
|
173
|
+
end
|
174
|
+
|
175
|
+
test "split method handles standard windows path names" do
|
176
|
+
assert_equal(["C:\\foo", "bar"], File.split("C:\\foo\\bar"))
|
177
|
+
assert_equal([".", "foo"], File.split("foo"))
|
178
|
+
end
|
179
|
+
|
180
|
+
test "split method handles windows paths with forward slashes" do
|
181
|
+
assert_equal(["C:\\foo", "bar"], File.split("C:/foo/bar"))
|
182
|
+
assert_equal([".", "foo"], File.split("foo"))
|
183
|
+
end
|
184
|
+
|
185
|
+
test "split method handles standard unix paths as expected" do
|
186
|
+
assert_equal(["\\foo","bar"], File.split("/foo/bar"))
|
187
|
+
assert_equal(["\\", "foo"], File.split("/foo"))
|
188
|
+
assert_equal([".", "foo"], File.split("foo"))
|
189
|
+
end
|
190
|
+
|
191
|
+
test "split method handles unc paths as expected" do
|
192
|
+
assert_equal(["\\\\foo\\bar", "baz"], File.split("\\\\foo\\bar\\baz"))
|
193
|
+
assert_equal(["\\\\foo\\bar", ""], File.split("\\\\foo\\bar"))
|
194
|
+
assert_equal(["\\\\foo", ""], File.split("\\\\foo"))
|
195
|
+
assert_equal(["\\\\", ""], File.split("\\\\"))
|
196
|
+
end
|
197
|
+
|
198
|
+
test "split method handles various edge cases as expected" do
|
199
|
+
assert_equal(["C:\\", ""], File.split("C:\\"))
|
200
|
+
assert_equal(["", ""], File.split(""))
|
201
|
+
end
|
202
|
+
|
203
|
+
test "split method does not modify its arguments" do
|
204
|
+
path = "C:\\foo\\bar"
|
205
|
+
assert_nothing_raised{ File.split(path) }
|
206
|
+
assert_equal("C:\\foo\\bar", path)
|
207
|
+
end
|
208
|
+
|
209
|
+
test "long_path method works as expected" do
|
210
|
+
assert_respond_to(File, :long_path)
|
211
|
+
assert_equal(@long_file, File.long_path(@short_file))
|
212
|
+
assert_equal('PATH_T~1.TXT', File.basename(@short_file))
|
213
|
+
end
|
214
|
+
|
215
|
+
test "short_path method works as expected" do
|
216
|
+
assert_respond_to(File, :short_path)
|
217
|
+
assert_equal('path_test.txt', File.basename(@long_file))
|
218
|
+
end
|
219
|
+
|
220
|
+
test "join method works as expected" do
|
221
|
+
assert_respond_to(File, :join)
|
222
|
+
end
|
223
|
+
|
224
|
+
test "join handles multiple arguments as expected" do
|
225
|
+
assert_equal("C:\\foo\\bar", File.join("C:", "foo", "bar"))
|
226
|
+
assert_equal("foo\\bar", File.join("foo", "bar"))
|
227
|
+
end
|
228
|
+
|
229
|
+
test "join handles multiple arguments as expected with unc paths" do
|
230
|
+
assert_equal("\\\\foo", File.join("\\\\foo"))
|
231
|
+
assert_equal("\\\\foo\\bar", File.join("\\\\foo", "bar"))
|
232
|
+
end
|
233
|
+
|
234
|
+
test "join does not normalize paths" do
|
235
|
+
assert_equal("C:\\.\\foo\\..", File.join("C:", ".", "foo", ".."))
|
236
|
+
end
|
237
|
+
|
238
|
+
test "join with no arguments returns an empty string" do
|
239
|
+
assert_equal('', File.join)
|
240
|
+
end
|
241
|
+
|
242
|
+
test "join with one argument returns the argument" do
|
243
|
+
assert_equal('foo', File.join('foo'))
|
244
|
+
assert_equal('c:', File.join('c:'))
|
245
|
+
end
|
246
|
+
|
247
|
+
def teardown
|
248
|
+
@short_file = nil
|
249
|
+
@long_file = nil
|
250
|
+
end
|
251
|
+
|
252
|
+
def self.shutdown
|
253
|
+
File.delete(@@file) if File.exists?(@@file)
|
254
|
+
@@file = nil
|
255
|
+
end
|
256
|
+
end
|