Fixed issue where Dir glob would not work properly when doing /**/*.
This commit is contained in:
parent
aa0cb96b8e
commit
25c3b4e632
@ -109,11 +109,14 @@ module FakeFS
|
|||||||
matches = case pattern
|
matches = case pattern
|
||||||
when '**'
|
when '**'
|
||||||
case parts
|
case parts
|
||||||
when ['*'], []
|
when ['*']
|
||||||
parts = [] # end recursion
|
parts = [] # end recursion
|
||||||
directories_under(dir).map do |d|
|
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
|
end.flatten.uniq
|
||||||
|
when []
|
||||||
|
parts = [] # end recursion
|
||||||
|
dir.values.flatten.uniq
|
||||||
else
|
else
|
||||||
directories_under(dir)
|
directories_under(dir)
|
||||||
end
|
end
|
||||||
|
@ -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/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'
|
FileUtils.cp_r '/path', '/otherpath'
|
||||||
|
|
||||||
assert_equal %w( /otherpath/foo /otherpath/foobar /path/foo /path/foobar ), Dir['/*/foo*']
|
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']
|
assert_equal ['/one/two/three'], Dir['/one/**/three']
|
||||||
end
|
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/two/three/four.rb', 'w')
|
||||||
File.open('/one/five.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', '/one/two/three', '/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'], Dir['/one/**']
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_should_report_pos_as_0_when_opening
|
def test_should_report_pos_as_0_when_opening
|
||||||
|
Loading…
Reference in New Issue
Block a user