Skip to content

Commit

Permalink
fixup! GlobGitignore doesn't preprocess patterns
Browse files Browse the repository at this point in the history
  • Loading branch information
robotdana committed Nov 23, 2023
1 parent 2049cad commit a706a72
Showing 1 changed file with 92 additions and 1 deletion.
93 changes: 92 additions & 1 deletion spec/pattern_parser/glob_gitignore_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,20 +39,35 @@ 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
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/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
Expand All @@ -63,13 +78,41 @@ 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(
PathList::Matcher::ExactString.new('/a', :ignore)
)
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(
Expand All @@ -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(
Expand All @@ -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
Expand All @@ -137,16 +211,33 @@ 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(
PathList::Matcher::ExactString.new('/a/path', :ignore)
)
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(
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit a706a72

Please sign in to comment.