Skip to content

Commit

Permalink
Handle SNAPSHOTs
Browse files Browse the repository at this point in the history
  • Loading branch information
reiz committed Mar 15, 2015
1 parent d83b431 commit 2fe1865
Show file tree
Hide file tree
Showing 6 changed files with 125 additions and 106 deletions.
2 changes: 1 addition & 1 deletion lib/naturalsorter/version.rb
@@ -1,3 +1,3 @@
module Naturalsorter
VERSION = "3.0.1"
VERSION = "3.0.2"
end
7 changes: 7 additions & 0 deletions lib/versioncmp.rb
Expand Up @@ -163,6 +163,7 @@ def self.timestamp? part
def self.pre_process val
cleaned_version = replace_x_dev val
cleaned_version = replace_wildcards cleaned_version
replace_snapshot cleaned_version
replace_leading_v cleaned_version
replace_99_does_not_exist cleaned_version
replace_timestamps cleaned_version
Expand All @@ -184,6 +185,12 @@ def self.replace_groovy val
end
end

def self.replace_snapshot val
if val.match(/\-SNAPSHOT/)
val.gsub!("-SNAPSHOT", "")
end
end


# Some glory Java Devs used the timestamp as version string
# http://www.versioneye.com/package/commons-beanutils--commons-beanutils
Expand Down
2 changes: 1 addition & 1 deletion naturalsorter.gemspec
Expand Up @@ -22,5 +22,5 @@ Gem::Specification.new do |s|
# specify any dependencies here; for example:
# s.add_development_dependency "rspec"
# s.add_runtime_dependency "rest-client"
s.add_development_dependency "rspec", "2.14.1"
s.add_development_dependency "rspec", "3.2.0"
end
78 changes: 39 additions & 39 deletions spec/naturalsorter_spec.rb
Expand Up @@ -116,28 +116,28 @@

describe "is_version_current?" do
it "returns true" do
Naturalsorter::Sorter.is_version_current?("1.1.1", "1.1.9").should be_true
Naturalsorter::Sorter.is_version_current?("1.1.1", "1.1.9").should be_truthy
end
it "returns true" do
Naturalsorter::Sorter.is_version_current?("1.1.1", "1.1.2").should be_true
Naturalsorter::Sorter.is_version_current?("1.1.1", "1.1.2").should be_truthy
end
it "returns true" do
Naturalsorter::Sorter.is_version_current?("1.1.1", "1.1.12").should be_true
Naturalsorter::Sorter.is_version_current?("1.1.1", "1.1.12").should be_truthy
end
it "returns false" do
Naturalsorter::Sorter.is_version_current?("1.1.1", "1.2.0").should be_false
Naturalsorter::Sorter.is_version_current?("1.1.1", "1.2.0").should be_falsey
end
it "returns false" do
Naturalsorter::Sorter.is_version_current?("1.1.1", "1.2").should be_false
Naturalsorter::Sorter.is_version_current?("1.1.1", "1.2").should be_falsey
end
it "returns false" do
Naturalsorter::Sorter.is_version_current?("1.1.1", "2.0").should be_false
Naturalsorter::Sorter.is_version_current?("1.1.1", "2.0").should be_falsey
end
it "returns false" do
Naturalsorter::Sorter.is_version_current?("1.1.1", "2").should be_false
Naturalsorter::Sorter.is_version_current?("1.1.1", "2").should be_falsey
end
it "returns false" do
Naturalsorter::Sorter.is_version_current?("1.1", "2.0").should be_false
Naturalsorter::Sorter.is_version_current?("1.1", "2.0").should be_falsey
end
end

Expand Down Expand Up @@ -182,112 +182,112 @@
describe "bigger?" do

it "returns true" do
Naturalsorter::Sorter.bigger?("1.1", "1.0").should be_true
Naturalsorter::Sorter.bigger?("1.1", "1.0").should be_truthy
end
it "returns true" do
Naturalsorter::Sorter.bigger?("1.1", "20030211.134440").should be_true
Naturalsorter::Sorter.bigger?("1.1", "20030211.134440").should be_truthy
end
it "returns true" do
Naturalsorter::Sorter.bigger?("1.1", "20030211").should be_true
Naturalsorter::Sorter.bigger?("1.1", "20030211").should be_truthy
end
it "returns true" do
Naturalsorter::Sorter.bigger?("2.0", "1.0").should be_true
Naturalsorter::Sorter.bigger?("2.0", "1.0").should be_truthy
end
it "returns true" do
Naturalsorter::Sorter.bigger?("2.20", "2.9").should be_true
Naturalsorter::Sorter.bigger?("2.20", "2.9").should be_truthy
end
it "returns false" do
Naturalsorter::Sorter.bigger?("2.20", "2.20").should be_false
Naturalsorter::Sorter.bigger?("2.20", "2.20").should be_falsey
end
it "returns false" do
Naturalsorter::Sorter.bigger?("2.20", "3.0").should be_false
Naturalsorter::Sorter.bigger?("2.20", "3.0").should be_falsey
end

end

describe "bigger_or_equal?" do

it "returns true" do
Naturalsorter::Sorter.bigger_or_equal?("1.1", "1.0").should be_true
Naturalsorter::Sorter.bigger_or_equal?("1.1", "1.0").should be_truthy
end
it "returns true" do
Naturalsorter::Sorter.bigger_or_equal?("2.0", "1.0").should be_true
Naturalsorter::Sorter.bigger_or_equal?("2.0", "1.0").should be_truthy
end
it "returns true" do
Naturalsorter::Sorter.bigger_or_equal?("2.20", "2.9").should be_true
Naturalsorter::Sorter.bigger_or_equal?("2.20", "2.9").should be_truthy
end
it "returns true" do
Naturalsorter::Sorter.bigger_or_equal?("2.20", "2.20").should be_true
Naturalsorter::Sorter.bigger_or_equal?("2.20", "2.20").should be_truthy
end
it "returns true" do
Naturalsorter::Sorter.bigger_or_equal?("2.20", "2.20.0").should be_true
Naturalsorter::Sorter.bigger_or_equal?("2.20", "2.20.0").should be_truthy
end
it "returns true" do
Naturalsorter::Sorter.bigger_or_equal?("2.20", "2.20").should be_true
Naturalsorter::Sorter.bigger_or_equal?("2.20", "2.20").should be_truthy
end
it "returns true" do
Naturalsorter::Sorter.bigger_or_equal?("v3.2.0", "3.2.0").should be_true
Naturalsorter::Sorter.bigger_or_equal?("v3.2.0", "3.2.0").should be_truthy
end
it "returns true" do
Naturalsorter::Sorter.bigger_or_equal?("v3.2.0", "3.1.0").should be_true
Naturalsorter::Sorter.bigger_or_equal?("v3.2.0", "3.1.0").should be_truthy
end
it "returns false" do
Naturalsorter::Sorter.bigger_or_equal?("2.20", "3.0").should be_false
Naturalsorter::Sorter.bigger_or_equal?("2.20", "3.0").should be_falsey
end

end

describe "smaller?" do

it "returns false" do
Naturalsorter::Sorter.smaller?("1.1", "1.0").should be_false
Naturalsorter::Sorter.smaller?("1.1", "1.0").should be_falsey
end
it "returns false" do
Naturalsorter::Sorter.smaller?("2.0", "1.0").should be_false
Naturalsorter::Sorter.smaller?("2.0", "1.0").should be_falsey
end
it "returns false" do
Naturalsorter::Sorter.smaller?("2.20", "2.9").should be_false
Naturalsorter::Sorter.smaller?("2.20", "2.9").should be_falsey
end
it "returns false" do
Naturalsorter::Sorter.smaller?("2.20", "2.20").should be_false
Naturalsorter::Sorter.smaller?("2.20", "2.20").should be_falsey
end
it "returns true" do
Naturalsorter::Sorter.smaller?("2.20", "3.0").should be_true
Naturalsorter::Sorter.smaller?("2.20", "3.0").should be_truthy
end
it "returns false" do
Naturalsorter::Sorter.smaller?("2.0", "2.0").should be_false
Naturalsorter::Sorter.smaller?("2.0", "2.0").should be_falsey
end
it "returns false" do
Naturalsorter::Sorter.smaller?("2.0", "2.0.0").should be_false
Naturalsorter::Sorter.smaller?("2.0", "2.0.0").should be_falsey
end

end

describe "smaller_or_equal?" do

it "returns false" do
Naturalsorter::Sorter.smaller_or_equal?("1.1", "1.0").should be_false
Naturalsorter::Sorter.smaller_or_equal?("1.1", "1.0").should be_falsey
end
it "returns false" do
Naturalsorter::Sorter.smaller_or_equal?("2.0", "1.0").should be_false
Naturalsorter::Sorter.smaller_or_equal?("2.0", "1.0").should be_falsey
end
it "returns false" do
Naturalsorter::Sorter.smaller_or_equal?("2.20", "2.9").should be_false
Naturalsorter::Sorter.smaller_or_equal?("2.20", "2.9").should be_falsey
end
it "returns false" do
Naturalsorter::Sorter.smaller_or_equal?("2.20", "2.20").should be_true
Naturalsorter::Sorter.smaller_or_equal?("2.20", "2.20").should be_truthy
end
it "returns false" do
Naturalsorter::Sorter.smaller_or_equal?("2.20.0", "2.20").should be_true
Naturalsorter::Sorter.smaller_or_equal?("2.20.0", "2.20").should be_truthy
end
it "returns true" do
Naturalsorter::Sorter.smaller_or_equal?("2.20", "2.20").should be_true
Naturalsorter::Sorter.smaller_or_equal?("2.20", "2.20").should be_truthy
end
it "returns true" do
Naturalsorter::Sorter.smaller_or_equal?("2.20", "3.0").should be_true
Naturalsorter::Sorter.smaller_or_equal?("2.20", "3.0").should be_truthy
end
it "returns true" do
Naturalsorter::Sorter.smaller_or_equal?("2.20", "v3.0").should be_true
Naturalsorter::Sorter.smaller_or_equal?("2.20", "v3.0").should be_truthy
end

end
Expand Down

0 comments on commit 2fe1865

Please sign in to comment.