aboutsummaryrefslogtreecommitdiffstats
path: root/Library/Homebrew/test
diff options
context:
space:
mode:
authorJack Nagel2012-08-18 13:34:31 -0500
committerJack Nagel2012-08-18 15:53:04 -0500
commitc924de7086e793661cd3ef1a62f6d0175a42b8d4 (patch)
tree97aa397628c68211f1cf4a1ac56176f8c4dfacc3 /Library/Homebrew/test
parenta119ee718d00c7dab4e06f5e0ce156212f7f5b45 (diff)
downloadbrew-c924de7086e793661cd3ef1a62f6d0175a42b8d4.tar.bz2
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 <jacknagel@gmail.com>
Diffstat (limited to 'Library/Homebrew/test')
-rw-r--r--Library/Homebrew/test/test_versions.rb6
1 files changed, 6 insertions, 0 deletions
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