Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Version.rb to support Semantic Versioning pre-release versions #584

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions lib/cocoapods/version.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
module Pod
class Version < Gem::Version

# Conforms to Semantic Versioning by including a hyphen
VERSION_PATTERN = '[0-9]+(\.[0-9a-zA-Z\-]+)*' # :nodoc:
ANCHORED_VERSION_PATTERN = /\A\s*(#{VERSION_PATTERN})*\s*\z/ # :nodoc:

def self.correct? version
version.to_s =~ ANCHORED_VERSION_PATTERN
end

# @returns A Version described by its #to_s method.
#
# @TODO The `from' part of the regexp should be remove before 1.0.0.
Expand All @@ -21,6 +29,12 @@ def self.from_string(string)
def to_s
head? ? "HEAD based on #{super}" : super
end

# Conform to Semantic Versioning instead of RubyGems
# pre-release gems can contain a hyphen and/or a letter
def prerelease?
@prerelease ||= @version =~ /[a-zA-Z\-]/
end
end
end

18 changes: 18 additions & 0 deletions spec/unit/version_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,23 @@ module Pod
version.should.be.head
version.to_s.should == 'HEAD based on 1.2.3'
end

it "identifies release versions" do
version = Version.from_string('1.0.0')
version.should.not.be.prerelease
end

it "matches Semantic Version pre-release versions" do
version = Version.from_string('1.0.0a1')
version.should.be.prerelease
version = Version.from_string('1.0.0-alpha')
version.should.be.prerelease
version = Version.from_string('1.0.0-alpha.1')
version.should.be.prerelease
version = Version.from_string('1.0.0-0.3.7')
version.should.be.prerelease
version = Version.from_string('1.0.0-x.7.z.92')
version.should.be.prerelease
end
end
end