allow for {p,q} literals in globs

This commit is contained in:
John Bintz 2011-02-18 16:14:13 -05:00
parent f366142c64
commit 005ddaaeb2
2 changed files with 6 additions and 1 deletions

View File

@ -121,7 +121,10 @@ module FakeFS
directories_under(dir)
end
else
dir.reject {|k,v| /\A#{pattern.gsub('?','.').gsub('*', '.*')}\Z/ !~ k }.values
pattern = pattern.gsub('?','.').gsub('*', '.*')
pattern = pattern.gsub(%r{\{([^\}]+)\}}) { |all| "(#{$1.gsub(',', '|')})" }
dir.reject {|k,v| /\A#{pattern}\Z/ !~ k }.values
end
if parts.empty? # we're done recursing

View File

@ -569,6 +569,8 @@ class FakeFSTest < Test::Unit::TestCase
assert_equal ['/path/bar/baz'], Dir['/path/bar/**/*']
assert_equal ['/path/bar', '/path/foo'], Dir['/path/{foo,bar}'].sort
FileUtils.cp_r '/path', '/otherpath'
assert_equal %w( /otherpath/foo /otherpath/foobar /path/foo /path/foobar ), Dir['/*/foo*']