test/test_file_find.rb in file-find-0.3.6 vs test/test_file_find.rb in file-find-0.3.7
- old
+ new
@@ -61,11 +61,11 @@
@rule1 = File::Find.new(:name => '*.txt')
@rule2 = File::Find.new
end
def test_version
- assert_equal('0.3.6', File::Find::VERSION)
+ assert_equal('0.3.7', File::Find::VERSION)
end
def test_path
assert_respond_to(@rule1, :path)
assert_respond_to(@rule1, :path=)
@@ -227,10 +227,45 @@
assert_respond_to(@rule1, :maxdepth)
assert_respond_to(@rule1, :maxdepth=)
assert_nil(@rule1.maxdepth)
end
+ # This test is a little uglier because we actually check to make sure
+ # we're looking at the right subdir, not just a filename shows up.
+ # I did this because I'm a little paranoid about the directory
+ # not getting mangled. - jlawler.
+ #
+ def test_dirs_with_brackets
+ omit_if(@@windows, 'dirs with brackets test skipped on MS Windows')
+
+ bracket_files = [ 'bracket/a[1]/a.foo', 'bracket/a [2] /b.foo', 'bracket/[a] b [c]/d.foo' ].sort
+ bracket_paths = [ 'bracket/a[1]', 'bracket/a [2] ', 'bracket/[a] b [c]', 'bracket/[z] x' ].sort
+
+ bracket_paths.each{ |e| mkpath(e) }
+ bracket_files.each{ |e| touch(e) }
+
+ @file_rule = File::Find.new(
+ :ftype => 'file',
+ :path => ['bracket']
+ )
+
+ @dir_rule = File::Find.new(
+ :path => ['bracket'],
+ :ftype => 'directory'
+ )
+
+ file_results = @file_rule.find.sort
+
+ assert_equal(bracket_files.size,file_results.size)
+ path = file_results.first.chomp(bracket_files.first)
+
+ # Confirm the first thing in results is the first thing in bracket_paths
+ assert_not_equal(path, file_results.first)
+ assert_equal(bracket_files, file_results.map{ |e| e.sub(path,'') }.sort )
+ assert_equal(bracket_paths, @dir_rule.find.sort )
+ end
+
def test_maxdepth_file
mkpath('a1/a2/a3')
touch('a1/a.foo')
touch('a1/a2/b.foo')
touch('a1/a2/c.foo')
@@ -244,11 +279,11 @@
@rule2.maxdepth = 2
assert_equal(['a.foo'], @rule2.find.map{ |e| File.basename(e) })
@rule2.maxdepth = 3
- assert_equal(['a.foo', 'b.foo', 'c.foo'], @rule2.find.map{ |e| File.basename(e) })
+ assert_equal(['a.foo', 'b.foo', 'c.foo'], @rule2.find.map{ |e| File.basename(e) }.sort)
@rule2.maxdepth = nil
assert_equal(
['a.foo', 'b.foo', 'c.foo', 'd.foo', 'e.foo', 'f.foo'],
@rule2.find.map{ |e| File.basename(e) }.sort
@@ -442,9 +477,10 @@
rm_rf(@directory1)
rm_rf(@directory2)
rm_rf(@link1) unless @@windows
rm_rf('a')
rm_rf('a1')
+ rm_rf('bracket')
rm_rf('z.min') if File.exists?('z.min')
@rule1 = nil
@rule2 = nil
@file_rb = nil