From 972b924cea057e19582488aef229207e13c3b955 Mon Sep 17 00:00:00 2001 From: Seeker Date: Tue, 11 Aug 2020 12:23:07 -0700 Subject: [PATCH] version: allow versions to be compared against tokens --- Library/Homebrew/test/version_spec.rb | 4 ++++ Library/Homebrew/version.rb | 1 + 2 files changed, 5 insertions(+) diff --git a/Library/Homebrew/test/version_spec.rb b/Library/Homebrew/test/version_spec.rb index e255fe9ef0..60b98c2179 100644 --- a/Library/Homebrew/test/version_spec.rb +++ b/Library/Homebrew/test/version_spec.rb @@ -183,6 +183,10 @@ describe Version do expect(described_class.create("1")).to be == 1 end + it "can be compared against tokens" do + expect(described_class.create("1")).to be == Version::Token.create("1") + end + specify "comparison returns nil for non-version" do v = described_class.create("1.0") expect(v <=> Object.new).to be nil diff --git a/Library/Homebrew/version.rb b/Library/Homebrew/version.rb index 909ed38006..1b337377c9 100644 --- a/Library/Homebrew/version.rb +++ b/Library/Homebrew/version.rb @@ -446,6 +446,7 @@ class Version other = Version.new(other.to_s) if other.is_a? Integer return 1 if other.nil? + other = Version.new(other.to_s) if other.is_a? Token return 1 if other.respond_to?(:null?) && other.null? return unless other.is_a?(Version) return 0 if version == other.version