Fix Keg::Relocation::start_with_old_value?

This commit is contained in:
Rylan Polster 2021-05-11 14:09:15 -04:00
parent 875282bc06
commit 7d49dba7e9
No known key found for this signature in database
GPG Key ID: 46A744940CFF4D64
2 changed files with 12 additions and 1 deletions

View File

@ -34,7 +34,7 @@ class Keg
end
def start_with_old_value?(key, text)
text.match?(/^#{@replacement_map.fetch(key)}/)
text.match?(/^#{@replacement_map.fetch(key).first}/)
end
sig { params(text: String).void }

View File

@ -59,6 +59,17 @@ describe Keg::Relocation do
REPLACED
end
specify "#start_with_old_value?" do
relocation = setup_relocation
expect(relocation.start_with_old_value?(:prefix, "#{HOMEBREW_PREFIX}/foo")).to be true
expect(relocation.start_with_old_value?(:prefix, "foo#{HOMEBREW_PREFIX}/bar")).to be false
expect(relocation.start_with_old_value?(:cellar, "#{HOMEBREW_CELLAR}/foo")).to be true
expect(relocation.start_with_old_value?(:cellar, "foo#{HOMEBREW_CELLAR}/bar")).to be false
expect(relocation.start_with_old_value?(:repository_placeholder, "@@HOMEBREW_REPOSITORY@@/foo")).to be true
expect(relocation.start_with_old_value?(:library_placeholder, "foo@@HOMEBREW_LIBRARY@@/bar")).to be false
end
specify "::path_regex" do
expect(described_class.path_regex(prefix)).to eq escaped_prefix
expect(described_class.path_regex("foo.bar")).to eq(/(?<![a-zA-Z0-9])foo\.bar/)