[rubygems/rubygems] standardize pretty-print output for Gem::Source and subclasses

https://github.com/rubygems/rubygems/commit/6d5fbf82f1
This commit is contained in:
Durable Programming Team 2024-09-02 15:16:31 -04:00 committed by git
parent 767d0a1716
commit 675529b9c6
9 changed files with 52 additions and 20 deletions

View File

@ -213,6 +213,7 @@ class Gem::Source
end
def pretty_print(q) # :nodoc:
q.object_group(self) do
q.group 2, "[Remote:", "]" do
q.breakable
q.text @uri.to_s
@ -224,6 +225,7 @@ class Gem::Source
end
end
end
end
def typo_squatting?(host, distance_threshold=4)
return if @uri.host.nil?

View File

@ -157,6 +157,7 @@ class Gem::Source::Git < Gem::Source
end
def pretty_print(q) # :nodoc:
q.object_group(self) do
q.group 2, "[Git: ", "]" do
q.breakable
q.text @repository
@ -165,6 +166,7 @@ class Gem::Source::Git < Gem::Source
q.text @reference
end
end
end
##
# The directory where the git gem's repository will be cached.

View File

@ -32,6 +32,8 @@ class Gem::Source::Installed < Gem::Source
end
def pretty_print(q) # :nodoc:
q.object_group(self) do
q.text "[Installed]"
end
end
end

View File

@ -117,11 +117,15 @@ class Gem::Source::Local < Gem::Source
end
def pretty_print(q) # :nodoc:
q.object_group(self) do
q.group 2, "[Local gems:", "]" do
q.breakable
if @specs
q.seplist @specs.keys do |v|
q.text v.full_name
end
end
end
end
end
end

View File

@ -42,11 +42,13 @@ class Gem::Source::SpecificFile < Gem::Source
end
def pretty_print(q) # :nodoc:
q.object_group(self) do
q.group 2, "[SpecificFile:", "]" do
q.breakable
q.text @path
end
end
end
##
# Orders this source against +other+.

View File

@ -292,6 +292,12 @@ class TestGemSourceGit < Gem::TestCase
assert_equal Gem::URI(@repository), @source.uri
end
def test_pretty_print
assert_equal "#<Gem::Source::Git[Git: \n" \
" #{@repository}\n" \
" HEAD]>\n", @source.pretty_inspect
end
def test_uri_hash
assert_equal @hash, @source.uri_hash

View File

@ -32,4 +32,9 @@ class TestGemSourceInstalled < Gem::TestCase
assert_equal(1, vendor.<=>(installed), "vendor <=> installed")
assert_equal(-1, installed.<=>(vendor), "installed <=> vendor")
end
def test_pretty_print
local = Gem::Source::Installed.new
assert_equal "#<Gem::Source::Installed[Installed]>\n", local.pretty_inspect
end
end

View File

@ -104,4 +104,9 @@ class TestGemSourceLocal < Gem::TestCase
assert_equal(-1, specific.<=>(local), "specific <=> local")
assert_equal(1, local.<=>(specific), "local <=> specific")
end
def test_pretty_print
local = Gem::Source::Local.new
assert_equal "#<Gem::Source::Local[Local gems: ]>\n", local.pretty_inspect
end
end

View File

@ -73,4 +73,8 @@ class TestGemSourceSpecificFile < Gem::TestCase
assert_equal(0, a1_source.<=>(a1_source), "a1_source <=> a1_source") # rubocop:disable Lint/BinaryOperatorWithIdenticalOperands
assert_equal(1, a2_source.<=>(a1_source), "a2_source <=> a1_source")
end
def test_pretty_print
assert_equal "#<Gem::Source::SpecificFile[SpecificFile:\n #{@sf.path}]>\n", @sf.pretty_inspect
end
end