Remove Version#empty?.

This commit is contained in:
Markus Reiter 2023-05-01 07:59:36 +02:00
parent a1efaf1864
commit fe19ddc3a7
No known key found for this signature in database
GPG Key ID: 245293B51702655B
4 changed files with 21 additions and 21 deletions

View File

@ -195,8 +195,10 @@ class Resource < Downloadable
return super() if val.nil? return super() if val.nil?
@version = case val @version = case val
when String then Version.create(val) when String
when Version then val val.blank? ? Version::NULL : Version.new(val)
when Version
val
else else
# TODO: This can probably go if/when typechecking is enforced in taps. # TODO: This can probably go if/when typechecking is enforced in taps.
raise TypeError, "version '#{val.inspect}' should be a string" raise TypeError, "version '#{val.inspect}' should be a string"

View File

@ -1,9 +1,19 @@
# frozen_string_literal: true # frozen_string_literal: true
describe OS do describe OS do
describe ".kernel_version" do describe "::kernel_version" do
it "is not empty" do it "is not NULL" do
expect(described_class.kernel_version).not_to be_empty expect(described_class.kernel_version).not_to be_null
end
end
describe "::kernel_name" do
it "returns Linux on Linux", :needs_linux do
expect(described_class.kernel_name).to eq "Linux"
end
it "returns Darwin on macOS", :needs_macos do
expect(described_class.kernel_name).to eq "Darwin"
end end
end end
end end

View File

@ -240,16 +240,6 @@ describe Version do
expect(versions.sort_by { |v| described_class.create(v) }).to eq(versions) expect(versions.sort_by { |v| described_class.create(v) }).to eq(versions)
end end
describe "#empty?" do
it "returns true if version is empty" do
expect(described_class.create("").empty?).to be(true)
end
it "returns false if version is not empty" do
expect(described_class.create("1.2.3").empty?).to be(false)
end
end
specify "hash equality" do specify "hash equality" do
v1 = described_class.create("0.1.0") v1 = described_class.create("0.1.0")
v2 = described_class.create("0.1.0") v2 = described_class.create("0.1.0")

View File

@ -494,7 +494,10 @@ class Version
def initialize(val, detected_from_url: false) def initialize(val, detected_from_url: false)
raise TypeError, "Version value must be a string; got a #{val.class} (#{val})" unless val.respond_to?(:to_str) raise TypeError, "Version value must be a string; got a #{val.class} (#{val})" unless val.respond_to?(:to_str)
@version = val.to_str version = val.to_str
raise ArgumentError, "Version must not be empty" if version.blank?
@version = version
@detected_from_url = detected_from_url @detected_from_url = detected_from_url
end end
@ -679,11 +682,6 @@ class Version
major_minor_patch.empty? ? NULL : self.class.new(major_minor_patch.join(".")) major_minor_patch.empty? ? NULL : self.class.new(major_minor_patch.join("."))
end end
sig { returns(T::Boolean) }
def empty?
version&.empty? || false
end
sig { returns(Integer) } sig { returns(Integer) }
def hash def hash
version.hash version.hash