Skip to content

Commit

Permalink
Add specs for git wildmatch edgecases
Browse files Browse the repository at this point in the history
  • Loading branch information
jdpace committed May 24, 2017
1 parent 1ce4365 commit 468b0f3
Showing 1 changed file with 50 additions and 2 deletions.
52 changes: 50 additions & 2 deletions spec/unit/pathspec/gitignorespec_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@
subject { GitIgnoreSpec.new 'foo/' }
it { is_expected.to match('foo/') }
it { is_expected.to match('foo/bar') }
it { is_expected.to match('baz/foo/bar') }
it { is_expected.to_not match('foo') }
it { is_expected.to be_inclusive }
end
Expand All @@ -88,10 +89,31 @@
describe 'handles basic globbing' do
subject { GitIgnoreSpec.new '*.tmp' }
it { is_expected.to match('foo.tmp') }
it { is_expected.to match('foo/bar.tmp') }
it { is_expected.to match('foo/bar.tmp/baz') }
it { is_expected.to_not match('foo.rb') }
it { is_expected.to be_inclusive }
end

describe 'handles inner globs' do
subject { GitIgnoreSpec.new 'foo-*-bar' }
it { is_expected.to match('foo--bar') }
it { is_expected.to match('foo-hello-bar') }
it { is_expected.to match('a/foo-hello-bar') }
it { is_expected.to match('foo-hello-bar/b') }
it { is_expected.to match('a/foo-hello-bar/b') }
it { is_expected.to_not match('foo.tmp') }
end

describe 'handles postfix globs' do
subject { GitIgnoreSpec.new '~temp-*' }
it { is_expected.to match('~temp-') }
it { is_expected.to match('~temp-foo') }
it { is_expected.to match('foo/~temp-bar') }
it { is_expected.to match('foo/~temp-bar/baz') }
it { is_expected.to_not match('~temp') }
end

describe 'handles multiple globs' do
subject { GitIgnoreSpec.new '*.middle.*' }
it { is_expected.to match('hello.middle.rb') }
Expand Down Expand Up @@ -182,6 +204,16 @@
it { is_expected.to be_inclusive }
end

describe 'handles simple single paths' do
subject { GitIgnoreSpec.new 'spam' }
it { is_expected.to match('spam') }
it { is_expected.to match('spam/') }
it { is_expected.to match('foo/spam') }
it { is_expected.to match('spam/foo') }
it { is_expected.to match('foo/spam/bar') }
it { is_expected.to_not match('foo') }
end

# Two consecutive asterisks ("**") in patterns matched against full pathname
# may have special meaning:

Expand All @@ -203,6 +235,7 @@
it { is_expected.to_not match('foo') }
it { is_expected.to match('foo/bar') }
it { is_expected.to match('baz/foo/bar') }
it { is_expected.to match('baz/foo/bar/sub') }
it { is_expected.to_not match('baz/foo/bar.rb') }
it { is_expected.to_not match('baz/bananafoo/bar') }
it { is_expected.to be_inclusive }
Expand All @@ -215,8 +248,8 @@
subject { GitIgnoreSpec.new 'abc/**' }
it { is_expected.to match('abc/') }
it { is_expected.to match('abc/def') }
it { is_expected.to_not match('123/abc/def') } # TODO: Maybe?
it { is_expected.to_not match('123/456/abc/') } # TODO: Maybe?
it { is_expected.to_not match('123/abc/def') }
it { is_expected.to_not match('123/456/abc/') }
it { is_expected.to be_inclusive }
end

Expand Down Expand Up @@ -254,4 +287,19 @@
it { is_expected.to_not be_inclusive }
end

describe 'does not match single absolute paths' do
subject { GitIgnoreSpec.new "/" }
it { is_expected.to_not match('foo.tmp') }
it { is_expected.to_not match(' ') }
it { is_expected.to_not match('a/b') }
end

describe 'nested paths are relative to the file' do
subject { GitIgnoreSpec.new 'foo/spam' }
it { is_expected.to match('foo/spam') }
it { is_expected.to match('foo/spam/bar') }
it { is_expected.to_not match('bar/foo/spam') }
end


end

0 comments on commit 468b0f3

Please sign in to comment.