Created
April 16, 2009 07:10
-
-
Save ymendel/96284 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
commit 3bbbf8b7c2d3633af47faf9eda9836e1bc3c681c | |
Author: Yossef Mendelssohn <[email protected]> | |
Date: Thu Apr 16 00:59:30 2009 -0500 | |
Spec changes for trailing zero version tweaks. | |
The desire is for 1.0.0 > 1.0 | |
Note this means quite a few specs need to be changed, | |
since they assume trailing zeroes are insignificant. | |
diff --git a/test/test_gem_version.rb b/test/test_gem_version.rb | |
index 29b8b5b..1d417b4 100644 | |
--- a/test/test_gem_version.rb | |
+++ b/test/test_gem_version.rb | |
@@ -42,7 +42,7 @@ class TestGemVersion < RubyGemTestCase | |
def test_bad | |
assert_inadequate( "", "> 0.1") | |
assert_inadequate( "1.2.3", "!= 1.2.3") | |
- assert_inadequate( "1.2.003.0.0", "!= 1.02.3") | |
+ assert_inadequate( "1.2.003", "!= 1.02.3") | |
assert_inadequate( "4.5.6", "< 1.2.3") | |
assert_inadequate( "1.0", "> 1.1") | |
assert_inadequate( "0", ">") | |
@@ -56,6 +56,10 @@ class TestGemVersion < RubyGemTestCase | |
assert_inadequate( "9.3.1", ">= 9.3.2") | |
assert_inadequate( "9.3.03", "<= 9.3.2") | |
assert_inadequate( "1.0.0.1", "= 1.0") | |
+ assert_inadequate( "1.0", "= 1.0.0") | |
+ assert_inadequate( "1.0", "> 1.0.0") | |
+ assert_inadequate( "1.0.0", "= 1.0") | |
+ assert_inadequate( "1.0.0", "< 1.0") | |
end | |
def test_bump_trailing_zeros | |
@@ -144,7 +148,7 @@ class TestGemVersion < RubyGemTestCase | |
assert_equal [0], Gem::Version.new("").normalize.map { |part| part.value } | |
assert_equal [0], Gem::Version.new("0").normalize.map { |part| part.value } | |
assert_equal [1], Gem::Version.new("1").normalize.map { |part| part.value } | |
- assert_equal [1], Gem::Version.new("1.0").normalize.map { |part| part.value } | |
+ assert_equal [1, 0], Gem::Version.new("1.0").normalize.map { |part| part.value } | |
assert_equal [1, 1], Gem::Version.new("1.1").normalize.map { |part| part.value } | |
assert_equal [1, 1, "a"], Gem::Version.new("1.1.a").normalize.map { |part| part.value } | |
end | |
@@ -160,7 +164,6 @@ class TestGemVersion < RubyGemTestCase | |
assert_adequate( "0.0.0.0.0.2", "> 0.0.0") | |
assert_adequate( "0.0.1.0", "> 0.0.0.1") | |
assert_adequate( "10.3.2", "> 9.3.2") | |
- assert_adequate( "1.0.0.0", "= 1.0") | |
assert_adequate( "10.3.2", "!= 9.3.4") | |
assert_adequate( "10.3.2", "> 9.3.2") | |
assert_adequate( "10.3.2", "> 9.3.2") | |
@@ -181,6 +184,8 @@ class TestGemVersion < RubyGemTestCase | |
assert_adequate( "3.0.rc2", "< 3.0") | |
assert_adequate( "3.0.rc2", "< 3.0.0") | |
assert_adequate( "3.0.rc2", "< 3.0.1") | |
+ assert_adequate( "1.0.0", "> 1.0") | |
+ assert_adequate( "1.0", "< 1.0.0") | |
end | |
def test_parse_parts_from_version_string | |
@@ -225,7 +230,7 @@ class TestGemVersion < RubyGemTestCase | |
end | |
def test_spaceship | |
- assert_equal 0, Gem::Version.new('1.0') <=> Gem::Version.new('1.0.0') | |
+ assert_equal 0, Gem::Version.new('1.0') <=> Gem::Version.new('1.0') | |
assert_equal 1, Gem::Version.new('1.0') <=> Gem::Version.new('1.0.a') | |
assert_equal 1, Gem::Version.new('1.8.2') <=> Gem::Version.new('0.0.0') | |
assert_equal 1, Gem::Version.new('1.8.2') <=> Gem::Version.new('1.8.2.a') |
This file contains hidden or 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
commit fae921649228e3679d1ca173e019bb51da0eced6 | |
Author: Yossef Mendelssohn <[email protected]> | |
Date: Thu Apr 16 02:01:25 2009 -0500 | |
Tweaking version to make trailing zeroes significant. | |
1.0.0 > 1.0 ftw | |
diff --git a/lib/rubygems/version.rb b/lib/rubygems/version.rb | |
index d996538..cc748a3 100644 | |
--- a/lib/rubygems/version.rb | |
+++ b/lib/rubygems/version.rb | |
@@ -129,10 +129,7 @@ class Gem::Version | |
def normalize | |
parts_arr = parse_parts_from_version_string | |
- if parts_arr.length != 1 | |
- parts_arr.pop while parts_arr.last && parts_arr.last.value == 0 | |
- parts_arr = [Part.new(0)] if parts_arr.empty? | |
- end | |
+ parts_arr = [Part.new(0)] if parts_arr.empty? | |
parts_arr | |
end | |
@@ -172,14 +169,16 @@ class Gem::Version | |
def <=>(other) | |
return nil unless self.class === other | |
return 1 unless other | |
- mine, theirs = balance(self.parts.dup, other.parts.dup) | |
+ mine, theirs = balance(self, other) | |
mine <=> theirs | |
end | |
def balance(a, b) | |
- a << Part.new(0) while a.size < b.size | |
- b << Part.new(0) while b.size < a.size | |
- [a, b] | |
+ a_parts = a.parts.dup | |
+ b_parts = b.parts.dup | |
+ a_parts << Part.new(0) while a_parts.size < b_parts.size and b.prerelease? | |
+ b_parts << Part.new(0) while b_parts.size < a_parts.size and a.prerelease? | |
+ [a_parts, b_parts] | |
end | |
## |
This file contains hidden or 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
Cassady:~/dev/projects/others/rubygems(version_tweak) yossef$ flog lib/rubygems/version.rb | |
146.4: flog total | |
5.6: flog/method average | |
25.1: Gem::Version#balance | |
18.2: Gem::Version#bump | |
13.1: Part#<=> | |
7.4: Gem::Version#<=> | |
6.8: Gem::Version#correct? | |
6.4: Part#succ | |
6.2: Gem::Version#parse_parts_from_version_string | |
6.1: Gem::Version#eql? | |
Cassady:~/dev/projects/others/rubygems(version_tweak) yossef$ reek lib/rubygems/version.rb | |
"lib/rubygems/version.rb" -- 13 warnings: | |
Gem::Version#<=> is controlled by argument other (Control Couple) | |
Gem::Version#Part#<=> refers to other more than self (Feature Envy) | |
Gem::Version#balance calls a_parts.size multiple times (Duplication) | |
Gem::Version#balance calls b_parts.size multiple times (Duplication) | |
Gem::Version#balance doesn't depend on instance state (Utility Function) | |
Gem::Version#balance has the variable name 'a' (Uncommunicative Name) | |
Gem::Version#balance has the variable name 'b' (Uncommunicative Name) | |
Gem::Version#balance refers to a_parts more than self (Feature Envy) | |
Gem::Version#balance refers to b_parts more than self (Feature Envy) | |
Gem::Version#bump calls parts.pop multiple times (Duplication) | |
Gem::Version#bump refers to parts more than self (Feature Envy) | |
Gem::Version#parse_parts_from_version_string/block has the variable name 's' (Uncommunicative Name) | |
Gem::Version#pretty_print has the variable name 'q' (Uncommunicative Name) | |
--------------------------------------------------- | |
Cassady:~/dev/projects/others/rubygems(master) yossef$ flog lib/rubygems/version.rb | |
155.1: flog total | |
6.0: flog/method average | |
18.2: Gem::Version#bump | |
17.8: Gem::Version#normalize | |
15.4: Gem::Version#balance | |
13.1: Part#<=> | |
13.0: Gem::Version#<=> | |
6.8: Gem::Version#correct? | |
6.4: Part#succ | |
6.2: Gem::Version#parse_parts_from_version_string | |
Cassady:~/dev/projects/others/rubygems(master) yossef$ reek lib/rubygems/version.rb | |
"lib/rubygems/version.rb" -- 15 warnings: | |
Gem::Version#<=> is controlled by argument other (Control Couple) | |
Gem::Version#Part#<=> refers to other more than self (Feature Envy) | |
Gem::Version#balance calls a.size multiple times (Duplication) | |
Gem::Version#balance calls b.size multiple times (Duplication) | |
Gem::Version#balance doesn't depend on instance state (Utility Function) | |
Gem::Version#balance has the variable name 'a' (Uncommunicative Name) | |
Gem::Version#balance has the variable name 'b' (Uncommunicative Name) | |
Gem::Version#balance refers to a more than self (Feature Envy) | |
Gem::Version#balance refers to b more than self (Feature Envy) | |
Gem::Version#bump calls parts.pop multiple times (Duplication) | |
Gem::Version#bump refers to parts more than self (Feature Envy) | |
Gem::Version#normalize calls parts_arr.last multiple times (Duplication) | |
Gem::Version#normalize refers to parts_arr more than self (Feature Envy) | |
Gem::Version#parse_parts_from_version_string/block has the variable name 's' (Uncommunicative Name) | |
Gem::Version#pretty_print has the variable name 'q' (Uncommunicative Name) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment