Refactor away String#indent
This commit is contained in:
parent
e74dc47d67
commit
0852e1d7b6
@ -511,11 +511,11 @@ describe "brew bottle" do
|
|||||||
bottle.sha256(catalina: "109c0cb581a7b5d84da36d84b221fb9dd0f8a927b3044d82611791c9907e202e")
|
bottle.sha256(catalina: "109c0cb581a7b5d84da36d84b221fb9dd0f8a927b3044d82611791c9907e202e")
|
||||||
|
|
||||||
expect(homebrew.bottle_output(bottle, nil)).to eq(
|
expect(homebrew.bottle_output(bottle, nil)).to eq(
|
||||||
<<~RUBY.indent(2),
|
<<-RUBY,
|
||||||
bottle do
|
bottle do
|
||||||
root_url "https://example.com"
|
root_url "https://example.com"
|
||||||
sha256 catalina: "109c0cb581a7b5d84da36d84b221fb9dd0f8a927b3044d82611791c9907e202e"
|
sha256 catalina: "109c0cb581a7b5d84da36d84b221fb9dd0f8a927b3044d82611791c9907e202e"
|
||||||
end
|
end
|
||||||
RUBY
|
RUBY
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
@ -526,12 +526,12 @@ describe "brew bottle" do
|
|||||||
bottle.sha256(catalina: "109c0cb581a7b5d84da36d84b221fb9dd0f8a927b3044d82611791c9907e202e")
|
bottle.sha256(catalina: "109c0cb581a7b5d84da36d84b221fb9dd0f8a927b3044d82611791c9907e202e")
|
||||||
|
|
||||||
expect(homebrew.bottle_output(bottle, "ExampleStrategy")).to eq(
|
expect(homebrew.bottle_output(bottle, "ExampleStrategy")).to eq(
|
||||||
<<~RUBY.indent(2),
|
<<-RUBY,
|
||||||
bottle do
|
bottle do
|
||||||
root_url "https://example.com",
|
root_url "https://example.com",
|
||||||
using: ExampleStrategy
|
using: ExampleStrategy
|
||||||
sha256 catalina: "109c0cb581a7b5d84da36d84b221fb9dd0f8a927b3044d82611791c9907e202e"
|
sha256 catalina: "109c0cb581a7b5d84da36d84b221fb9dd0f8a927b3044d82611791c9907e202e"
|
||||||
end
|
end
|
||||||
RUBY
|
RUBY
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|||||||
@ -177,7 +177,7 @@ RSpec.shared_context "integration test" do # rubocop:disable RSpec/ContextWordin
|
|||||||
Formulary.core_path(name).tap do |formula_path|
|
Formulary.core_path(name).tap do |formula_path|
|
||||||
formula_path.write <<~RUBY
|
formula_path.write <<~RUBY
|
||||||
class #{Formulary.class_s(name)} < Formula
|
class #{Formulary.class_s(name)} < Formula
|
||||||
#{content.indent(2)}
|
#{content.gsub(/^(?!$)/, " ")}
|
||||||
end
|
end
|
||||||
RUBY
|
RUBY
|
||||||
end
|
end
|
||||||
|
|||||||
@ -5,12 +5,12 @@ require "utils/ast"
|
|||||||
describe Utils::AST do
|
describe Utils::AST do
|
||||||
describe ".stanza_text" do
|
describe ".stanza_text" do
|
||||||
let(:compound_license) do
|
let(:compound_license) do
|
||||||
<<~RUBY.chomp
|
<<-RUBY
|
||||||
license all_of: [
|
license all_of: [
|
||||||
:public_domain,
|
:public_domain,
|
||||||
"MIT",
|
"MIT",
|
||||||
"GPL-3.0-or-later" => { with: "Autoconf-exception-3.0" },
|
"GPL-3.0-or-later" => { with: "Autoconf-exception-3.0" },
|
||||||
]
|
]
|
||||||
RUBY
|
RUBY
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -36,14 +36,14 @@ describe Utils::AST do
|
|||||||
it "adds indent to stanza text if specified" do
|
it "adds indent to stanza text if specified" do
|
||||||
expect(described_class.stanza_text(:revision, "revision 1", indent: 2)).to eq(" revision 1")
|
expect(described_class.stanza_text(:revision, "revision 1", indent: 2)).to eq(" revision 1")
|
||||||
expect(described_class.stanza_text(:license, 'license "MIT"', indent: 2)).to eq(' license "MIT"')
|
expect(described_class.stanza_text(:license, 'license "MIT"', indent: 2)).to eq(' license "MIT"')
|
||||||
expect(described_class.stanza_text(:license, compound_license, indent: 2)).to eq(compound_license.indent(2))
|
expect(described_class.stanza_text(:license, compound_license, indent: 2)).to eq(compound_license)
|
||||||
end
|
end
|
||||||
|
|
||||||
it "does not add indent if already indented" do
|
it "does not add indent if already indented" do
|
||||||
expect(described_class.stanza_text(:revision, " revision 1", indent: 2)).to eq(" revision 1")
|
expect(described_class.stanza_text(:revision, " revision 1", indent: 2)).to eq(" revision 1")
|
||||||
expect(
|
expect(
|
||||||
described_class.stanza_text(:license, compound_license.indent(2), indent: 2),
|
described_class.stanza_text(:license, compound_license, indent: 2),
|
||||||
).to eq(compound_license.indent(2))
|
).to eq(compound_license)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@ -248,10 +248,10 @@ describe Utils::AST::FormulaAST do
|
|||||||
|
|
||||||
describe "#add_bottle_block" do
|
describe "#add_bottle_block" do
|
||||||
let(:bottle_output) do
|
let(:bottle_output) do
|
||||||
<<~RUBY.chomp.indent(2)
|
<<-RUBY
|
||||||
bottle do
|
bottle do
|
||||||
sha256 "f7b1fc772c79c20fddf621ccc791090bc1085fcef4da6cca03399424c66e06ca" => :sierra
|
sha256 "f7b1fc772c79c20fddf621ccc791090bc1085fcef4da6cca03399424c66e06ca" => :sierra
|
||||||
end
|
end
|
||||||
RUBY
|
RUBY
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@ -35,7 +35,7 @@ module Utils
|
|||||||
value if (node.is_a?(SendNode) || node.is_a?(BlockNode)) && node.method_name == name
|
value if (node.is_a?(SendNode) || node.is_a?(BlockNode)) && node.method_name == name
|
||||||
end
|
end
|
||||||
text ||= "#{name} #{value.inspect}"
|
text ||= "#{name} #{value.inspect}"
|
||||||
text = text.indent(indent) if indent && !text.match?(/\A\n* +/)
|
text = text.gsub(/^(?!$)/, " " * indent) if indent && !text.match?(/\A\n* +/)
|
||||||
text
|
text
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user