Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Updates for version 0.2.2

  • Loading branch information...
commit 2cf2da2d1846bbc2b20a91d1be1540508ac57511 1 parent f840e5b
@dazuma authored
View
10 History.rdoc
@@ -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
2  README.rdoc
@@ -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
View
10 lib/versionomy/conversion/rubygems.rb
@@ -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.
View
212 lib/versionomy/format/delimiter.rb
@@ -137,30 +137,69 @@ def schema
# uninterpreted characters.
def parse(string_, params_=nil)
- values_ = {}
parse_params_ = default_parse_params
parse_params_.merge!(params_) if params_
- parse_params_[:string] = string_
- parse_params_[:previous_field_missing] = false
- unparse_params_ = {}
- field_ = @schema.root_field
- while field_
+ parse_state_ = {
+ :backtrack => nil,
+ :string => string_,
+ :values => {},
+ :unparse_params => {},
+ :field => @schema.root_field,
+ :recognizer_index => 0,
+ :previous_field_missing => false
+ }
+ while (field_ = parse_state_[:field])
handler_ = @field_handlers[field_.name]
- v_ = handler_.parse(parse_params_, unparse_params_)
- values_[field_.name] = v_
- field_ = field_.child(v_)
+ recognizer_ = handler_.get_recognizer(parse_state_[:recognizer_index])
+ parse_data_ = nil
+ if recognizer_
+ parse_state_[:recognizer_index] += 1
+ parse_data_ = recognizer_.parse(parse_state_, parse_params_)
+ if parse_data_
+ parse_state_[:previous_field_missing] = false
+ if recognizer_.requires_next_field
+ parse_state_[:next_field_required] = true
+ parse_state_ = {
+ :backtrack => parse_state_,
+ :string => parse_state_[:string],
+ :values => parse_state_[:values].dup,
+ :unparse_params => parse_state_[:unparse_params].dup,
+ :field => parse_state_[:field],
+ :recognizer_index => 0,
+ :previous_field_missing => false,
+ }
+ else
+ parse_state_[:next_field_required] = false
+ end
+ end
+ elsif parse_state_[:next_field_required]
+ parse_state_ = parse_state_[:backtrack]
+ else
+ parse_data_ = [handler_.default_value, nil, nil, nil]
+ parse_state_[:previous_field_missing] = true
+ parse_state_[:next_field_required] = false
+ end
+ if parse_data_
+ parse_state_[:values][field_.name] = parse_data_[0]
+ parse_state_[:string] = parse_data_[2] if parse_data_[2]
+ parse_state_[:unparse_params].merge!(parse_data_[3]) if parse_data_[3]
+ parse_state_[:field] = field_.child(parse_data_[0])
+ parse_state_[:recognizer_index] = 0
+ handler_.set_style_unparse_param(parse_data_[1], parse_state_[:unparse_params])
+ end
end
- if parse_params_[:string].length > 0
+ unparse_params_ = parse_state_[:unparse_params]
+ if parse_state_[:string].length > 0
case parse_params_[:extra_characters]
when :ignore
# do nothing
when :suffix
- unparse_params_[:suffix] = parse_params_[:string]
+ unparse_params_[:suffix] = parse_state_[:string]
else
- raise Errors::ParseError, "Extra characters: #{parse_params_[:string].inspect}"
+ raise Errors::ParseError, "Extra characters: #{parse_state_[:string].inspect}"
end
end
- Value.new(values_, self, unparse_params_)
+ Value.new(parse_state_[:values], self, unparse_params_)
end
@@ -210,32 +249,32 @@ def unparse(value_, params_=nil)
unparse_params_.merge!(params_)
_interpret_field_lists(unparse_params_)
end
- unparse_params_.delete(:skipped_handler_list)
- unparse_params_.delete(:required_for_later)
+ skipped_handler_list_ = nil
+ requires_next_field_ = false
string_ = ''
value_.each_field_object do |field_, val_|
handler_ = @field_handlers[field_.name]
- fragment_ = handler_.unparse(val_, unparse_params_)
- if fragment_
- list_ = unparse_params_.delete(:skipped_handler_list)
- if list_ && handler_.requires_previous_field && !unparse_params_[:required_for_later]
- unparse_params_[:required_for_later] = true
- list_.each do |pair_|
- frag_ = pair_[0].unparse(pair_[1], unparse_params_)
+ unparse_data_ = handler_.unparse(val_, unparse_params_, requires_next_field_)
+ if unparse_data_
+ if skipped_handler_list_ && handler_.requires_previous_field
+ skipped_handler_list_.each do |pair_|
+ frag_ = pair_[0].unparse(pair_[1], unparse_params_, true)
unless frag_
raise Errors::UnparseError, "Field #{field_.name} empty although a prerequisite for a later field"
end
- string_ << frag_
+ string_ << frag_[0]
end
- unparse_params_[:required_for_later] = false
end
- string_ << fragment_
+ skipped_handler_list_ = nil
+ string_ << unparse_data_[0]
+ requires_next_field_ = unparse_data_[1]
else
if handler_.requires_previous_field
- (unparse_params_[:skipped_handler_list] ||= []) << [handler_, val_]
+ (skipped_handler_list_ ||= []) << [handler_, val_]
else
- unparse_params_[:skipped_handler_list] = [[handler_, val_]]
+ skipped_handler_list_ = [[handler_, val_]]
end
+ requires_next_field_ = false
end
end
string_ << (unparse_params_[:suffix] || '')
@@ -280,14 +319,14 @@ def modified_copy(&block_)
def _interpret_field_lists(unparse_params_) # :nodoc:
fields_ = unparse_params_.delete(:required_fields)
if fields_
- fields_ = [fields_] unless fields_.kind_of?(Array)
+ fields_ = [fields_] unless fields_.kind_of?(::Array)
fields_.each do |f_|
unparse_params_["#{f_}_required".to_sym] = true
end
end
fields_ = unparse_params_.delete(:optional_fields)
if fields_
- fields_ = [fields_] unless fields_.kind_of?(Array)
+ fields_ = [fields_] unless fields_.kind_of?(::Array)
fields_.each do |f_|
unparse_params_["#{f_}_required".to_sym] = false
end
@@ -353,6 +392,10 @@ def initialize(schema_, field_handlers_, default_parse_params_, default_unparse_
# field is optional, but the first and second are required, so it
# will often be unparsed as "2.0".
# Default is false.
+ # <tt>:default_value</tt>::
+ # The actual value set for this field if it is omitted from the
+ # version string. Defaults to the field's schema default value,
+ # but that can be overridden here.
# <tt>:case_sensitive</tt>::
# If set to true, the regexps are case-sensitive. Default is false.
# <tt>:delimiter_regexp</tt>::
@@ -391,6 +434,15 @@ def initialize(schema_, field_handlers_, default_parse_params_, default_unparse_
# parameter set to true. The default is true, so you must specify
# <tt>:requires_previous_field => false</tt> explicitly if you want
# a field not to require the previous field.
+ # <tt>:requires_next_field</tt>::
+ # If set to true, this field's presence in a formatted version
+ # string requires the presence of the next field. For example, in
+ # the version "1.0a5", the release_type field requires the presence
+ # of the alpha_version field, because if the "5" was missing, the
+ # string "1.0a" looks like a patchlevel indicator. Often it is
+ # easier to set default_value_optional in the next field, but this
+ # option is also available if the behavior is dependent on the
+ # value of this previous field.
# <tt>:default_style</tt>::
# The default style for this field. This is the style used for
# unparsing if the value was not constructed by a parser or is
@@ -607,6 +659,7 @@ def initialize(field_, default_opts_={}, &block_)
@field = field_
@recognizers = []
@requires_previous_field = default_opts_.fetch(:requires_previous_field, true)
+ @default_value = default_opts_[:default_value] || field_.default_value
@default_style = default_opts_.fetch(:default_style, nil)
@style_unparse_param_key = "#{field_.name}_style".to_sym
if block_
@@ -631,37 +684,44 @@ def requires_previous_field
end
- # Parse this field from the string.
- # This must either return a parsed value, or raise an error.
- # It should also set the style in the unparse_params, if the style
- # is determined not to be the default.
+ # Returns the default value set when this field is missing from a
+ # version string.
- def parse(parse_params_, unparse_params_)
- pair_ = nil
- @recognizers.each do |recog_|
- pair_ = recog_.parse(parse_params_, unparse_params_)
- break if pair_
- end
- parse_params_[:previous_field_missing] = pair_.nil?
- pair_ ||= [@field.default_value, @default_style]
- if pair_[1] && pair_[1] != @default_style
- unparse_params_[@style_unparse_param_key] = pair_[1]
+ def default_value
+ @default_value
+ end
+
+
+ # Gets the given indexed recognizer. Returns nil if the index is out
+ # of range.
+
+ def get_recognizer(index_)
+ @recognizers[index_]
+ end
+
+
+ # Finishes up parsing by setting the appropriate style field in the
+ # unparse_params, if needed.
+
+ def set_style_unparse_param(style_, unparse_params_)
+ if style_ && style_ != @default_style
+ unparse_params_[@style_unparse_param_key] = style_
end
- pair_[0]
end
# Unparse a string from this field value.
# This may return nil if this field is not required.
- def unparse(value_, unparse_params_)
+ def unparse(value_, unparse_params_, required_for_later_)
style_ = unparse_params_[@style_unparse_param_key] || @default_style
@recognizers.each do |recog_|
if recog_.should_unparse?(value_, style_)
- return recog_.unparse(value_, style_, unparse_params_)
+ fragment_ = recog_.unparse(value_, style_, unparse_params_, required_for_later_)
+ return fragment_ ? [fragment_, recog_.requires_next_field] : nil
end
end
- unparse_params_[:required_for_later] ? '' : nil
+ required_for_later_ ? ['', false] : nil
end
end
@@ -690,6 +750,7 @@ class RecognizerBase # :nodoc:
def setup(field_, value_regexp_, opts_)
@style = opts_[:style]
@default_value_optional = opts_[:default_value_optional]
+ @default_value = opts_[:default_value] || field_.default_value
@regexp_options = opts_[:case_sensitive] ? nil : ::Regexp::IGNORECASE
@value_regexp = ::Regexp.new("\\A(#{value_regexp_})", @regexp_options)
regexp_ = opts_[:delimiter_regexp] || '\.'
@@ -703,8 +764,8 @@ def setup(field_, value_regexp_, opts_)
@default_delimiter = opts_[:default_delimiter] || '.'
@default_post_delimiter = opts_[:default_post_delimiter] || ''
@requires_previous_field = opts_.fetch(:requires_previous_field, true)
+ @requires_next_field = opts_.fetch(:requires_next_field, false)
name_ = field_.name
- @default_field_value = field_.default_value
@delim_unparse_param_key = "#{name_}_delim".to_sym
@post_delim_unparse_param_key = "#{name_}_postdelim".to_sym
@required_unparse_param_key = "#{name_}_required".to_sym
@@ -716,9 +777,9 @@ def setup(field_, value_regexp_, opts_)
# Returns either nil, indicating that this recognizer doesn't match
# the given syntax, or a two element array of the value and style.
- def parse(parse_params_, unparse_params_)
- return nil if @requires_previous_field && parse_params_[:previous_field_missing]
- string_ = parse_params_[:string]
+ def parse(parse_state_, parse_params_)
+ return nil if @requires_previous_field && parse_state_[:previous_field_missing]
+ string_ = parse_state_[:string]
if @delimiter_regexp
match_ = @delimiter_regexp.match(string_)
return nil unless match_
@@ -743,9 +804,9 @@ def parse(parse_params_, unparse_params_)
match_ = @follower_regexp.match(string_)
return nil unless match_
end
- value_ = parsed_value(value_, parse_params_, unparse_params_)
- return nil unless value_
- parse_params_[:string] = string_
+ parse_result_ = parsed_value(value_, parse_params_)
+ return nil unless parse_result_
+ unparse_params_ = parse_result_[1] || {}
if delim_ != @default_delimiter
unparse_params_[@delim_unparse_param_key] = delim_
end
@@ -753,7 +814,15 @@ def parse(parse_params_, unparse_params_)
unparse_params_[@post_delim_unparse_param_key] = post_delim_
end
unparse_params_[@required_unparse_param_key] = true if @default_value_optional
- [value_, @style]
+ [parse_result_[0], @style, string_, unparse_params_]
+ end
+
+
+ # Returns true if this field can appear in an unparsed string only
+ # if the next field also appears.
+
+ def requires_next_field
+ @requires_next_field
end
@@ -773,11 +842,10 @@ def should_unparse?(value_, style_)
# It is guaranteed that this will be called only if should_unparse?
# returns true.
- def unparse(value_, style_, unparse_params_)
+ def unparse(value_, style_, unparse_params_, required_for_later_)
str_ = nil
- if !@default_value_optional || value_ != @default_field_value ||
- unparse_params_[:required_for_later] ||
- unparse_params_[@required_unparse_param_key]
+ if !@default_value_optional || value_ != @default_value ||
+ required_for_later_ || unparse_params_[@required_unparse_param_key]
then
str_ = unparsed_value(value_, style_, unparse_params_)
if str_
@@ -816,8 +884,8 @@ def initialize(field_, opts_={})
setup(field_, '\d+', opts_)
end
- def parsed_value(value_, parse_params_, unparse_params_)
- value_.to_i
+ def parsed_value(value_, parse_params_)
+ [value_.to_i, nil]
end
def unparsed_value(value_, style_, unparse_params_)
@@ -846,16 +914,14 @@ def initialize(field_, opts_={})
setup(field_, value_regexp_, opts_)
end
- def parsed_value(value_, parse_params_, unparse_params_)
+ def parsed_value(value_, parse_params_)
value_ = value_.unpack('c')[0] # Compatible with both 1.8 and 1.9
if value_ >= 97 && value_ <= 122
- unparse_params_[@case_unparse_param_key] = :lower
- value_ - 96
+ [value_ - 96, {@case_unparse_param_key => :lower}]
elsif value_ >= 65 && value_ <= 90
- unparse_params_[@case_unparse_param_key] = :upper
- value_ - 64
+ [value_ - 64, {@case_unparse_param_key => :upper}]
else
- 0
+ [0, nil]
end
end
@@ -883,8 +949,8 @@ def initialize(field_, regexp_='[a-zA-Z0-9]+', opts_={})
setup(field_, regexp_, opts_)
end
- def parsed_value(value_, parse_params_, unparse_params_)
- value_
+ def parsed_value(value_, parse_params_)
+ [value_, nil]
end
def unparsed_value(value_, style_, unparse_params_)
@@ -905,8 +971,8 @@ def initialize(field_, value_, regexp_, canonical_, opts_={})
@canonical = canonical_
end
- def parsed_value(value_, parse_params, unparse_params_)
- @value
+ def parsed_value(value_, parse_params_)
+ [@value, nil]
end
def unparsed_value(value_, style_, unparse_params_)
@@ -937,9 +1003,9 @@ def initialize(field_, opts_={}, &block_)
end
end
- def parsed_value(value_, parse_params, unparse_params_)
+ def parsed_value(value_, parse_params_)
@mappings_in_order.each do |map_|
- return map_[2] if map_[0].match(value_)
+ return [map_[2], nil] if map_[0].match(value_)
end
nil
end
View
91 lib/versionomy/format/standard.rb
@@ -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
View
15 lib/versionomy/interface.rb
@@ -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
View
2  lib/versionomy/version.rb
@@ -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
70 tests/tc_standard_parse.rb
@@ -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
Please sign in to comment.
Something went wrong with that request. Please try again.