-
-
Notifications
You must be signed in to change notification settings - Fork 9.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c64c834
commit 8307890
Showing
5 changed files
with
127 additions
and
122 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
# typed: strict | ||
# frozen_string_literal: true | ||
|
||
module Homebrew | ||
# Class handling architecture-specific version information. | ||
# | ||
# @api private | ||
class BumpVersionParser | ||
sig { returns(T.nilable(T.any(Version, Cask::DSL::Version))) } | ||
attr_reader :arm, :general, :intel | ||
|
||
sig { | ||
params(general: T.nilable(T.any(Version, String)), | ||
arm: T.nilable(T.any(Version, String)), | ||
intel: T.nilable(T.any(Version, String))).void | ||
} | ||
def initialize(general: nil, arm: nil, intel: nil) | ||
@general = T.let(parse_version(general), T.nilable(T.any(Version, Cask::DSL::Version))) if general.present? | ||
@arm = T.let(parse_version(arm), T.nilable(T.any(Version, Cask::DSL::Version))) if arm.present? | ||
@intel = T.let(parse_version(intel), T.nilable(T.any(Version, Cask::DSL::Version))) if intel.present? | ||
|
||
return if @general.present? | ||
raise UsageError, "`--version` must not be empty." if arm.blank? && intel.blank? | ||
raise UsageError, "`--version-arm` must not be empty." if arm.blank? | ||
raise UsageError, "`--version-intel` must not be empty." if intel.blank? | ||
end | ||
|
||
sig { | ||
params(version: T.any(Version, String)) | ||
.returns(T.nilable(T.any(Version, Cask::DSL::Version))) | ||
} | ||
def parse_version(version) | ||
if version.is_a?(Version) | ||
version | ||
elsif version.is_a?(String) | ||
parse_cask_version(version) | ||
end | ||
end | ||
|
||
sig { params(version: String).returns(T.nilable(Cask::DSL::Version)) } | ||
def parse_cask_version(version) | ||
if version == "latest" | ||
Cask::DSL::Version.new(:latest) | ||
else | ||
Cask::DSL::Version.new(version) | ||
end | ||
end | ||
|
||
sig { returns(T::Boolean) } | ||
def blank? | ||
@general.blank? && @arm.blank? && @intel.blank? | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
# frozen_string_literal: true | ||
|
||
require "bump_version_parser" | ||
|
||
describe Homebrew::BumpVersionParser do | ||
let(:general_version) { "1.2.3" } | ||
let(:intel_version) { "2.3.4" } | ||
let(:arm_version) { "3.4.5" } | ||
|
||
context "when initializing with no versions" do | ||
it "raises a usage error" do | ||
expect do | ||
described_class.new | ||
end.to raise_error(UsageError, "Invalid usage: `--version` must not be empty.") | ||
end | ||
end | ||
|
||
context "when initializing with valid versions" do | ||
let(:new_version) { described_class.new(general: general_version, arm: arm_version, intel: intel_version) } | ||
|
||
it "correctly parses general version" do | ||
expect(new_version.general).to eq(Cask::DSL::Version.new(general_version.to_s)) | ||
end | ||
|
||
it "correctly parses arm version" do | ||
expect(new_version.arm).to eq(Cask::DSL::Version.new(arm_version.to_s)) | ||
end | ||
|
||
it "correctly parses intel version" do | ||
expect(new_version.intel).to eq(Cask::DSL::Version.new(intel_version.to_s)) | ||
end | ||
|
||
context "when only the intel version is provided" do | ||
it "raises a UsageError" do | ||
expect do | ||
described_class.new(intel: intel_version) | ||
end.to raise_error(UsageError, | ||
"Invalid usage: `--version-arm` must not be empty.") | ||
end | ||
end | ||
|
||
context "when only the arm version is provided" do | ||
it "raises a UsageError" do | ||
expect do | ||
described_class.new(arm: arm_version) | ||
end.to raise_error(UsageError, | ||
"Invalid usage: `--version-intel` must not be empty.") | ||
end | ||
end | ||
|
||
context "when the version is latest" do | ||
it "returns a version object for latest" do | ||
new_version = described_class.new(general: "latest") | ||
expect(new_version.general.to_s).to eq("latest") | ||
end | ||
|
||
context "when the version is not latest" do | ||
it "returns a version object for the given version" do | ||
new_version = described_class.new(general: general_version) | ||
expect(new_version.general.to_s).to eq(general_version) | ||
end | ||
end | ||
end | ||
|
||
context "when checking if VersionParser is blank" do | ||
it "returns false if any version is present" do | ||
new_version = described_class.new(general: general_version.to_s, arm: "", intel: "") | ||
expect(new_version.blank?).to be(false) | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters