Skip to content

Commit

Permalink
Gradle: Handle multiple updates to a superstring
Browse files Browse the repository at this point in the history
  • Loading branch information
greysteil committed Mar 18, 2019
1 parent e471fe4 commit acb75bf
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,10 @@ def update_files_for_property_change(property_name:,
file_to_update = dependency_files.find { |f| f.name == filename }
updated_content = file_to_update.content.sub(
declaration_string,
declaration_string.sub(previous_value, updated_value)
declaration_string.sub(
previous_value_regex(previous_value),
updated_value
)
)

updated_files = dependency_files.dup
Expand All @@ -50,6 +53,10 @@ def update_file(file:, content:)
updated_file.content = content
updated_file
end

def previous_value_regex(previous_value)
/(?<=['"])#{Regexp.quote(previous_value)}(?=['"])/
end
end
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,5 +46,16 @@
expect(updated_files.first.content).
to include("ext.kotlin_version = '3.2.1'")
end

context "when updating from a substring to the same value" do
let(:previous_value) { "1.1.4" }
let(:updated_value) { "1.1.4-3" }

it "leaves the files alone" do
expect(updated_files.last).to eq(dependency_files.last)
expect(updated_files.first.content).
to include("ext.kotlin_version = '1.1.4-3'")
end
end
end
end

0 comments on commit acb75bf

Please sign in to comment.