From a706a72f9dff106e42e65e539e376b24f96e40c9 Mon Sep 17 00:00:00 2001 From: Dana Sherson Date: Thu, 23 Nov 2023 22:55:10 +1300 Subject: [PATCH] fixup! GlobGitignore doesn't preprocess patterns --- spec/pattern_parser/glob_gitignore_spec.rb | 93 +++++++++++++++++++++- 1 file changed, 92 insertions(+), 1 deletion(-) diff --git a/spec/pattern_parser/glob_gitignore_spec.rb b/spec/pattern_parser/glob_gitignore_spec.rb index f79db17..e23f6e7 100644 --- a/spec/pattern_parser/glob_gitignore_spec.rb +++ b/spec/pattern_parser/glob_gitignore_spec.rb @@ -39,6 +39,7 @@ def build(pattern) it { expect(build('../foo')).to be_like PathList::Matcher::ExactString.new('/a/foo', :ignore) } it { expect(build('../../foo')).to be_like PathList::Matcher::ExactString.new('/foo', :ignore) } it { expect(build('../../../foo')).to be_like PathList::Matcher::ExactString.new('/foo', :ignore) } + it { expect(build('..foo')).to be_like PathList::Matcher::ExactString.new('/a/path/..foo', :ignore) } end describe 'mid /../' do @@ -46,13 +47,27 @@ def build(pattern) it { expect(build('bar/../../foo')).to be_like PathList::Matcher::ExactString.new('/a/foo', :ignore) } it { expect(build('bar/../../../foo')).to be_like PathList::Matcher::ExactString.new('/foo', :ignore) } it { expect(build('bar/../../../../foo')).to be_like PathList::Matcher::ExactString.new('/foo', :ignore) } + + it { expect(build('bar/**/../foo')).to be_like PathList::Matcher::ExactString.new('/a/path/bar/foo', :ignore) } + it { expect(build('bar**/../foo')).to be_like PathList::Matcher::ExactString.new('/a/path/foo', :ignore) } + it { expect(build('bar../foo')).to be_like PathList::Matcher::ExactString.new('/a/path/bar../foo', :ignore) } + it { expect(build('bar/..foo')).to be_like PathList::Matcher::ExactString.new('/a/path/bar/..foo', :ignore) } end describe 'trailing /..' do it { expect(build('bar/..')).to be_like PathList::Matcher::ExactString.new('/a/path', :ignore) } + it { expect(build('b[ai]r/..')).to be_like PathList::Matcher::ExactString.new('/a/path', :ignore) } + it { expect(build('ba[rb]/..')).to be_like PathList::Matcher::ExactString.new('/a/path', :ignore) } + it { expect(build('bar/../..')).to be_like PathList::Matcher::ExactString.new('/a', :ignore) } + it { expect(build('b[ai]r/../..')).to be_like PathList::Matcher::ExactString.new('/a', :ignore) } + it { expect(build('ba[rb]/../..')).to be_like PathList::Matcher::ExactString.new('/a', :ignore) } + it { expect(build('bar/../../..')).to be_like PathList::Matcher::ExactString.new('/', :ignore) } it { expect(build('bar/../../../..')).to be_like PathList::Matcher::ExactString.new('/', :ignore) } + + it { expect(build('bar..')).to be_like PathList::Matcher::ExactString.new('/a/path/bar..', :ignore) } + it { expect(build('bar../..')).to be_like PathList::Matcher::ExactString.new('/a/path', :ignore) } end describe 'trailing /../' do @@ -63,6 +78,20 @@ def build(pattern) ) end + it do + expect(build('b[ai]r/../')) + .to be_like PathList::Matcher::MatchIfDir.new( + PathList::Matcher::ExactString.new('/a/path', :ignore) + ) + end + + it do + expect(build('ba[rb]/../')) + .to be_like PathList::Matcher::MatchIfDir.new( + PathList::Matcher::ExactString.new('/a/path', :ignore) + ) + end + it do expect(build('bar/../../')) .to be_like PathList::Matcher::MatchIfDir.new( @@ -70,6 +99,20 @@ def build(pattern) ) end + it do + expect(build('b[ai]r/../../')) + .to be_like PathList::Matcher::MatchIfDir.new( + PathList::Matcher::ExactString.new('/a', :ignore) + ) + end + + it do + expect(build('ba[rb]/../../')) + .to be_like PathList::Matcher::MatchIfDir.new( + PathList::Matcher::ExactString.new('/a', :ignore) + ) + end + it do expect(build('bar/../../../')) .to be_like PathList::Matcher::MatchIfDir.new( @@ -83,9 +126,28 @@ def build(pattern) PathList::Matcher::ExactString.new('/', :ignore) ) end + + it do + expect(build('bar../')) + .to be_like PathList::Matcher::MatchIfDir.new( + PathList::Matcher::ExactString.new('/a/path/bar..', :ignore) + ) + end + + it do + expect(build('bar../../')) + .to be_like PathList::Matcher::MatchIfDir.new( + PathList::Matcher::ExactString.new('/a/path', :ignore) + ) + end end describe 'only ../' do + it do + expect(build('..')) + .to be_like PathList::Matcher::ExactString.new('/a', :ignore) + end + it do expect(build('../')) .to be_like PathList::Matcher::MatchIfDir.new( @@ -111,16 +173,28 @@ def build(pattern) describe 'initial ./' do it { expect(build('./foo')).to be_like PathList::Matcher::ExactString.new('/a/path/foo', :ignore) } it { expect(build('././foo')).to be_like PathList::Matcher::ExactString.new('/a/path/foo', :ignore) } + + it { expect(build('.foo')).to be_like PathList::Matcher::ExactString.new('/a/path/.foo', :ignore) } + it { expect(build('./.foo')).to be_like PathList::Matcher::ExactString.new('/a/path/.foo', :ignore) } end describe 'mid /./' do it { expect(build('bar/./foo')).to be_like PathList::Matcher::ExactString.new('/a/path/bar/foo', :ignore) } it { expect(build('bar/././foo')).to be_like PathList::Matcher::ExactString.new('/a/path/bar/foo', :ignore) } + + it { expect(build('bar./foo')).to be_like PathList::Matcher::ExactString.new('/a/path/bar./foo', :ignore) } + it { expect(build('bar/.foo')).to be_like PathList::Matcher::ExactString.new('/a/path/bar/.foo', :ignore) } + + it { expect(build('bar././foo')).to be_like PathList::Matcher::ExactString.new('/a/path/bar./foo', :ignore) } + it { expect(build('bar/./.foo')).to be_like PathList::Matcher::ExactString.new('/a/path/bar/.foo', :ignore) } end describe 'trailing /.' do it { expect(build('bar/.')).to be_like PathList::Matcher::ExactString.new('/a/path/bar', :ignore) } it { expect(build('bar/./.')).to be_like PathList::Matcher::ExactString.new('/a/path/bar', :ignore) } + + it { expect(build('bar.')).to be_like PathList::Matcher::ExactString.new('/a/path/bar.', :ignore) } + it { expect(build('bar./.')).to be_like PathList::Matcher::ExactString.new('/a/path/bar.', :ignore) } end describe 'trailing /./' do @@ -137,9 +211,21 @@ def build(pattern) PathList::Matcher::ExactString.new('/a/path/bar', :ignore) ) end + + it do + expect(build('bar./')) + .to be_like PathList::Matcher::MatchIfDir.new( + PathList::Matcher::ExactString.new('/a/path/bar.', :ignore) + ) + end end describe 'only ./' do + it do + expect(build('.')) + .to be_like PathList::Matcher::ExactString.new('/a/path', :ignore) + end + it do expect(build('./')) .to be_like PathList::Matcher::MatchIfDir.new( @@ -147,6 +233,11 @@ def build(pattern) ) end + it do + expect(build('./.')) + .to be_like PathList::Matcher::ExactString.new('/a/path', :ignore) + end + it do expect(build('././')) .to be_like PathList::Matcher::MatchIfDir.new( @@ -264,7 +355,7 @@ def build(pattern) end describe 'leading ./ means current directory based on the root' do - it { expect(build('./foo')).to be_like PathList::Matcher::ExactString.new("#{FSROOT}a/path/foo", :ignore) } + it { expect(build('./foo')).to be_like PathList::Matcher::ExactString.new("/a/path/foo", :ignore) } end describe 'A line starting with # serves as a comment.' do