Skip to content

Commit

Permalink
rename class and reorganize files
Browse files Browse the repository at this point in the history
  • Loading branch information
razvanazamfirei committed Jul 25, 2023
1 parent c64c834 commit 8307890
Show file tree
Hide file tree
Showing 5 changed files with 127 additions and 122 deletions.
54 changes: 54 additions & 0 deletions Library/Homebrew/bump_version_parser.rb
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
2 changes: 1 addition & 1 deletion Library/Homebrew/dev-cmd/bump-cask-pr.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# typed: strict
# frozen_string_literal: true

require "bump_version_parser"
require "cask"
require "cask/download"
require "cli/parser"
require "extend/version-parser"
require "utils/tar"

module Homebrew
Expand Down
52 changes: 0 additions & 52 deletions Library/Homebrew/extend/version-parser.rb

This file was deleted.

72 changes: 72 additions & 0 deletions Library/Homebrew/test/bump_version_parser_spec.rb
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
69 changes: 0 additions & 69 deletions Library/Homebrew/test/dev-cmd/bump-cask-pr_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,73 +5,4 @@

describe "brew bump-cask-pr" do
it_behaves_like "parseable arguments"

describe Homebrew::VersionParser 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
end

0 comments on commit 8307890

Please sign in to comment.