From 6ccf2aa253bfad33d527e80f36832fab96601ff2 Mon Sep 17 00:00:00 2001 From: Jack Nagel Date: Sat, 18 Aug 2012 13:34:31 -0500 Subject: Version: build-in devel version comparisons The heuristic used by the default version comparison is simple. A version string is scanned for strings of digits, split into an array of these strings, and then an element-wise comparison is done. This fails when presented with something like Version.new("1.0.0beta7") <=> Version.new("1.0.0") because the first three digits match, and the fourth digit of the receiver (7) is greater than the assumed fourth digit of the parameter (0). Fix this by defining an element-wise comparator on a new VersionElement class. This allows us to correctly compare "alpha", "beta", and "rc" style version strings, and keeps the logic out of the main version comparison. Signed-off-by: Jack Nagel --- Library/Homebrew/test/test_versions.rb | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'Library/Homebrew/test') diff --git a/Library/Homebrew/test/test_versions.rb b/Library/Homebrew/test/test_versions.rb index 972ce130b..9811db57e 100644 --- a/Library/Homebrew/test/test_versions.rb +++ b/Library/Homebrew/test/test_versions.rb @@ -23,6 +23,12 @@ class VersionComparisonTests < Test::Unit::TestCase assert_version_comparison 'HEAD', '==', 'HEAD' assert_version_comparison 'HEAD', '>', '1.2.3' assert_version_comparison '1.2.3', '<', 'HEAD' + assert_version_comparison '3.2.0b4', '<', '3.2.0' + assert_version_comparison '1.0beta6', '<', '1.0b7' + assert_version_comparison '1.0b6', '<', '1.0beta7' + assert_version_comparison '1.1alpha4', '<', '1.1beta2' + assert_version_comparison '1.1beta2', '<', '1.1rc1' + assert_nil Version.new('1.0') <=> 'foo' end def test_macos_version_comparison -- cgit v1.2.3