Permalink
Browse files

Updates for version 0.2.2

  • Loading branch information...
1 parent f840e5b commit 2cf2da2d1846bbc2b20a91d1be1540508ac57511 @dazuma committed Nov 18, 2009
View
@@ -1,8 +1,14 @@
+=== 0.2.2 / 2009-11-18
+
+* Standard format now supports certain kinds of prereleases without a prerelease number. e.g. "1.9.2dev" is interpreted as the same number as "1.9.2dev0".
+* Added Versionomy#ruby_version.
+* A field can specify a default_value for parsing, distinct from the one specified by the schema.
+* A field can specify requires_next_field to control whether the following field is required or optional.
+
=== 0.2.1 / 2009-11-08
* Added Versionomy#version_of.
-* Now lets Blockenspiel set its own VERSION instead of reaching into
- Blockenspiel's namespace.
+* Now lets Blockenspiel set its own VERSION instead of reaching into Blockenspiel's namespace.
=== 0.2.0 / 2009-11-05
View
@@ -149,8 +149,6 @@ provides a schema and formatter/parser matching Gem::Version.
* Test coverage is still a little skimpy. It is focused on the "standard"
version number format and schema, but doesn't fully exercise all the
capabilities of custom formats.
-* The standard format parser requires that "prerelease" versions have a
- prerelease number. e.g. it accepts "1.9.2dev1" but not "1.9.2dev".
=== Development and support
@@ -50,7 +50,7 @@ module Rubygems
# and you should not need to call it again. It is documented, however,
# so that you can inspect its source code from RDoc, since the source
# contains useful examples of how to use the conversion DSLs.
-
+
def self.create_standard_to_rubygems
# We'll use a parsing conversion.
@@ -65,10 +65,14 @@ def self.create_standard_to_rubygems
# If the standard format version has a prerelease notation,
# make sure it is set off using a delimiter that the rubygems
- # format can recognized. So instead of "1.0b2", we force the
+ # format can recognize. So instead of "1.0b2", we force the
# unparsing to generate "1.0.b.2".
params_[:release_type_delim] = '.'
- params_[:release_type_postdelim] = '.'
+ params_[:development_version_delim] = '.'
+ params_[:alpha_version_delim] = '.'
+ params_[:beta_version_delim] = '.'
+ params_[:release_candidate_version_delim] = '.'
+ params_[:preview_version_delim] = '.'
# If the standard format version has a patchlevel notation,
# force it to use the default number rather than letter style.

Large diffs are not rendered by default.

Oops, something went wrong.
@@ -277,73 +277,87 @@ def self.create
# syntax looks like "1.0a5". Long syntax looks more like
# "1.0 Alpha 5". The parsed value retains knowledge of which style
# it came from so it can be reconstructed when the value is unparsed.
- # Finally, we turn requires_previous_field off because the release
+ # Note that we turn requires_previous_field off because the release
# type syntax markers don't require any particular set of the core
# version number fields to be present. "1.0a5" and "1.0.0.0a5" are
# both valid version numbers.
field(:release_type, :requires_previous_field => false,
:default_style => :short) do
- # First check for "short form" syntax. Not that we support post-
- # delimiters; that is, we recognize "1.0 pre-2" where the hyphen
- # is a post-delimiter. Also notice that we expect prerelease types
- # to be followed by a numeric prerelease version number.
+ # Some markers require a prerelease version (e.g. the 5 in
+ # "1.0a5") while others don't (e.g. "1.9.2dev"). This is because
+ # the syntax "1.0a" looks like a patchlevel syntax. So some of
+ # the following recognizers set requires_next_field while others
+ # do not.
+ # Also note that we omit the value <tt>:final</tt>. This is
+ # because that value is signaled by the absence of any syntax in
+ # the version string, including the absence of any delimiters.
+ # So we just allow it to fall through to the default.
+
+ recognize_regexp_map(:style => :long, :default_delimiter => '',
+ :delimiter_regexp => '-|\.|\s?') do
+ map(:development, 'dev')
+ map(:alpha, 'alpha')
+ map(:beta, 'beta')
+ map(:preview, 'preview')
+ end
recognize_regexp_map(:style => :short, :default_delimiter => '',
- :delimiter_regexp => '-|\.|\s?',
- :post_delimiter_regexp => '-|\.|\s?',
- :expected_follower_regexp => '\d') do
- map(:development, 'd')
- map(:alpha, 'a')
- map(:beta, 'b')
+ :delimiter_regexp => '-|\.|\s?') do
map(:release_candidate, 'rc')
map(:preview, 'pre')
- # Note that we omit the value <tt>:final</tt>. This is because
- # that value is signaled by the absence of any syntax in the
- # version string, including the absence of any delimiters. So we
- # just allow it to fall through to the default.
end
- # Check for "long form" syntax. Note again that we omit :final.
recognize_regexp_map(:style => :long, :default_delimiter => '',
- :delimiter_regexp => '-|\.|\s?',
- :post_delimiter_regexp => '-|\.|\s?',
- :expected_follower_regexp => '\d') do
- map(:development, 'dev')
- map(:alpha, 'alpha')
- map(:beta, 'beta')
+ :delimiter_regexp => '-|\.|\s?') do
map(:release_candidate, 'rc')
- map(:preview, 'preview')
+ end
+ recognize_regexp_map(:style => :short, :default_delimiter => '',
+ :delimiter_regexp => '-|\.|\s?',
+ :requires_next_field => true) do
+ map(:development, 'd')
+ map(:alpha, 'a')
+ map(:beta, 'b')
end
end
- # The development version must appear in the string if it is present
- # in the value, even if the value is 0. Similar for all the other
- # prerelease version numbers: alpha, beta, release candidate, and
- # preview. However, the minor fields are optional.
- field(:development_version) do
- recognize_number(:delimiter_regexp => '', :default_delimiter => '')
+ # The main prerelease version may sometimes be optional, so we
+ # mark it as optional here. If it is required, that will be
+ # signalled by requires_next_field on the release_type field.
+ # Minor prerelease versions are always optional.
+ # Note that we override the default_value (normally 1) and set
+ # it to 0 if a main prerelease version is not present. This is
+ # so schema-oriented operations like bumping will set the value
+ # to 1, while parsing a string will yield 0 when the field is
+ # missing (e.g. we want "1.9.2dev" to mean "1.9.2dev0".)
+ field(:development_version, :default_value => 0) do
+ recognize_number(:delimiter_regexp => '-|\.|\s?', :default_delimiter => '',
+ :default_value_optional => true)
end
field(:development_minor) do
recognize_number(:default_value_optional => true)
end
- field(:alpha_version) do
- recognize_number(:delimiter_regexp => '', :default_delimiter => '')
+ field(:alpha_version, :default_value => 0) do
+ recognize_number(:delimiter_regexp => '-|\.|\s?', :default_delimiter => '',
+ :default_value_optional => true)
end
field(:alpha_minor) do
recognize_number(:default_value_optional => true)
end
- field(:beta_version) do
- recognize_number(:delimiter_regexp => '', :default_delimiter => '')
+ field(:beta_version, :default_value => 0) do
+ recognize_number(:delimiter_regexp => '-|\.|\s?', :default_delimiter => '',
+ :default_value_optional => true)
end
field(:beta_minor) do
recognize_number(:default_value_optional => true)
end
- field(:release_candidate_version) do
- recognize_number(:delimiter_regexp => '', :default_delimiter => '')
+ field(:release_candidate_version, :default_value => 0) do
+ recognize_number(:delimiter_regexp => '-|\.|\s?', :default_delimiter => '',
+ :default_value_optional => true)
end
field(:release_candidate_minor) do
recognize_number(:default_value_optional => true)
end
- field(:preview_version) do
- recognize_number(:delimiter_regexp => '', :default_delimiter => '')
+ field(:preview_version, :default_value => 0) do
+ recognize_number(:delimiter_regexp => '-|\.|\s?', :default_delimiter => '',
+ :default_value_optional => true)
end
field(:preview_minor) do
recognize_number(:default_value_optional => true)
@@ -366,7 +380,8 @@ def self.create
# By default, we require that at least the major and minor fields
# appear in an unparsed version string.
- default_unparse_params(:required_fields => [:minor])
+ default_unparse_params(:required_fields => [:minor, :development_version, :alpha_version,
+ :beta_version, :release_candidate_version, :preview_version])
end
end
@@ -154,6 +154,21 @@ def version_of(mod_)
end
+ # Get the ruby version as a Versionomy::Value, using the builtin
+ # constants RUBY_VERSION and RUBY_PATCHLEVEL.
+
+ def ruby_version
+ unless @ruby_version
+ @ruby_version = parse(::RUBY_VERSION, :standard)
+ if @ruby_version.release_type == :final
+ @ruby_version = @ruby_version.change({:patchlevel => ::RUBY_PATCHLEVEL},
+ :patchlevel_required => true, :patchlevel_delim => '-p')
+ end
+ end
+ @ruby_version
+ end
+
+
end
end
@@ -37,7 +37,7 @@
module Versionomy
# Current gem version, as a frozen string.
- VERSION_STRING = '0.2.1'.freeze
+ VERSION_STRING = '0.2.2'.freeze
# Current gem version, as a Versionomy::Value.
VERSION = ::Versionomy.parse(VERSION_STRING, :standard)
View
@@ -93,6 +93,21 @@ def test_parsing_trailing_zeros
end
+ # Test parsing major version only.
+
+ def test_parsing_major_only
+ value_ = ::Versionomy.parse('2')
+ assert_equal(2, value_.major)
+ assert_equal(0, value_.minor)
+ assert_equal(0, value_.tiny)
+ assert_equal(0, value_.tiny2)
+ assert_equal(:final, value_.release_type)
+ assert_equal(0, value_.patchlevel)
+ assert_equal(0, value_.patchlevel_minor)
+ assert_equal('2', value_.unparse)
+ end
+
+
# Test parsing preview.
def test_parsing_preview
@@ -151,6 +166,7 @@ def test_parsing_beta_alternates
assert_equal(::Versionomy.parse('2.52.1BETA4'), '2.52.1b4')
assert_equal(::Versionomy.parse('2.52.1 Beta4'), '2.52.1b4')
assert_equal(::Versionomy.parse('2.52.1 eta4', :extra_characters => :ignore), '2.52.1')
+ assert_equal(::Versionomy.parse('2.52.1 Beta'), '2.52.1b0')
end
@@ -167,7 +183,53 @@ def test_parsing_release_candidate
assert_equal(0, value_.release_candidate_minor)
assert_equal('0.2rc0', value_.unparse)
assert_equal('0.2rc0.0', value_.unparse(:required_fields => [:release_candidate_minor]))
- assert_equal('0.2rc0', value_.unparse(:optional_fields => [:release_candidate_version]))
+ assert_equal('0.2rc', value_.unparse(:optional_fields => [:release_candidate_version]))
+ end
+
+
+ # Test parsing release candidate changing to other prerelease.
+ # Ensures that :short style takes precedence over :long for parsing "rc".
+
+ def test_parsing_release_candidate_type_change
+ value_ = ::Versionomy.parse('0.2rc1')
+ assert_equal(:release_candidate, value_.release_type)
+ assert_equal(1, value_.release_candidate_version)
+ assert_equal('0.2rc1', value_.unparse)
+ value_ = value_.change(:release_type => :beta)
+ assert_equal(:beta, value_.release_type)
+ assert_equal(1, value_.beta_version)
+ assert_equal('0.2b1', value_.unparse)
+ value_ = value_.change({:release_type => :beta}, :release_type_style => :long)
+ assert_equal(:beta, value_.release_type)
+ assert_equal(1, value_.beta_version)
+ assert_equal('0.2beta1', value_.unparse)
+ end
+
+
+ # Test parsing forms without a prerelease version
+
+ def test_parsing_without_prerelease_version
+ value_ = ::Versionomy.parse('1.9.2dev')
+ assert_equal(value_.release_type, :development)
+ assert_equal(value_.development_version, 0)
+ assert_equal('1.9.2dev', value_.to_s)
+ value_ = value_.bump(:development_version)
+ assert_equal('1.9.2dev1', value_.to_s)
+ end
+
+
+ # Test parsing forms without a prerelease version.
+ # Ensures that :development_version prefers to be required.
+
+ def test_unparsing_prerelease_version_0
+ value_ = ::Versionomy.parse('1.9.2dev1')
+ assert_equal(value_.release_type, :development)
+ assert_equal(value_.development_version, 1)
+ assert_equal('1.9.2dev1', value_.to_s)
+ value2_ = value_.change(:development_version => 0)
+ assert_equal('1.9.2dev0', value2_.to_s)
+ value2_ = value_.change({:development_version => 0}, :optional_fields => [:development_version])
+ assert_equal('1.9.2dev', value2_.to_s)
end
@@ -212,10 +274,10 @@ def test_patchlevel_separators
def test_unparse_with_custom_delimiters
value_ = ::Versionomy.parse('1.2b3')
- assert_equal('1.2.b.3', value_.unparse(:release_type_delim => '.', :release_type_postdelim => '.'))
- assert_equal('1.2b3', value_.unparse(:release_type_delim => '=', :release_type_postdelim => '*'))
+ assert_equal('1.2.b.3', value_.unparse(:release_type_delim => '.', :beta_version_delim => '.'))
+ assert_equal('1.2b3', value_.unparse(:release_type_delim => '=', :beta_version_delim => '*'))
value_ = ::Versionomy.parse('1.2-4')
- assert_equal('1.2-4', value_.unparse(:release_type_delim => '.', :release_type_postdelim => '.'))
+ assert_equal('1.2-4', value_.unparse(:release_type_delim => '.'))
end

0 comments on commit 2cf2da2

Please sign in to comment.