Fixed issue where Dir glob would not work properly when doing /**/*.

This commit is contained in:
marano 2010-11-03 14:09:23 -02:00 committed by Scott Taylor
parent aa0cb96b8e
commit 25c3b4e632
2 changed files with 15 additions and 5 deletions

View File

@ -109,11 +109,14 @@ module FakeFS
matches = case pattern
when '**'
case parts
when ['*'], []
when ['*']
parts = [] # end recursion
directories_under(dir).map do |d|
d.values.select{|f| f.is_a? FakeFile }
d.values.select{|f| f.is_a?(FakeFile) || f.is_a?(FakeDir) }
end.flatten.uniq
when []
parts = [] # end recursion
dir.values.flatten.uniq
else
directories_under(dir)
end

View File

@ -458,6 +458,13 @@ class FakeFSTest < Test::Unit::TestCase
assert_equal ['/path/foo', '/path/foobar'], Dir['/p*h/foo*']
assert_equal ['/path/foo', '/path/foobar'], Dir['/p??h/foo*']
assert_equal ['/path/bar', '/path/bar/baz', '/path/bar2', '/path/bar2/baz', '/path/foo', '/path/foobar'], Dir['/path/**/*']
assert_equal ['/path', '/path/bar', '/path/bar/baz', '/path/bar2', '/path/bar2/baz', '/path/foo', '/path/foobar'], Dir['/**/*']
assert_equal ['/path/bar', '/path/bar/baz', '/path/bar2', '/path/bar2/baz', '/path/foo', '/path/foobar'], Dir['/path/**/*']
assert_equal ['/path/bar/baz'], Dir['/path/bar/**/*']
FileUtils.cp_r '/path', '/otherpath'
assert_equal %w( /otherpath/foo /otherpath/foobar /path/foo /path/foobar ), Dir['/*/foo*']
@ -478,11 +485,11 @@ class FakeFSTest < Test::Unit::TestCase
assert_equal ['/one/two/three'], Dir['/one/**/three']
end
def test_dir_recursive_glob_ending_in_wildcards_only_returns_files
def test_dir_recursive_glob_ending_in_wildcards_returns_both_files_and_dirs
File.open('/one/two/three/four.rb', 'w')
File.open('/one/five.rb', 'w')
assert_equal ['/one/five.rb', '/one/two/three/four.rb'], Dir['/one/**/*']
assert_equal ['/one/five.rb', '/one/two/three/four.rb'], Dir['/one/**']
assert_equal ['/one/five.rb', '/one/two', '/one/two/three', '/one/two/three/four.rb'], Dir['/one/**/*']
assert_equal ['/one/five.rb', '/one/two'], Dir['/one/**']
end
def test_should_report_pos_as_0_when_opening