Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

YAML support and various fixes

  • Loading branch information...
commit 175d88df513b1748a52079d1c4ebc96690e2a126 1 parent 5118922
@dazuma authored
View
10 History.rdoc
@@ -1,14 +1,16 @@
=== 0.2.0 / 2009-11-05
+* API CHANGE: Slight change to value comparison semantics. Value#eql? returns true only if the schemas are the same, whereas Value#== and the greater than and less than comparisons attempt to compare the semantic value, and thus may perform automatic schema conversion on the RHS.
+* API CHANGE: Merged Formats namespace into Format. Versionomy::Formats is now a (deprecated) alias for Versionomy::Format.
+* API CHANGE: The delimiter parsing algorithm now defaults :extra_characters to :error instead of :ignore.
* Added a mechanism for converting from one format/schema to another.
* Added Rubygems format, along with conversions to and from the standard format.
-* Slight change to value comparison semantics. Value#eql? returns true only if the schemas are the same, whereas Value#== and the greater than and less than comparisons attempt to compare the semantic value, and thus may perform automatic schema conversion on the RHS.
* Values now include Comparable.
-* Values can now be marshalled and unmarshalled.
-* Schemas can now add custom methods to value objects.
+* Values can now be serialized using Marshal and YAML.
+* Schemas can now add custom methods to value objects. Added "prerelease?" and "release" methods to rubygems and standard format values.
* Added default field settings to schema DSL.
* Implemented #=== for schemas and formats.
-* Merged Formats namespace into Format. Versionomy::Formats is now a (deprecated) alias for Versionomy::Format.
+* Many minor bug fixes.
=== 0.1.3 / 2009-10-29
View
30 README.rdoc
@@ -4,6 +4,31 @@ Versionomy is a generalized version number library.
It provides tools to represent, manipulate, parse, and compare version
numbers in the wide variety of versioning schemes in use.
+=== Version numbers done right?
+
+Let's be honest. Version numbers are not easy to deal with, and very
+seldom seem to be done right.
+Imagine the common case of testing the ruby version. Most of us, if we
+need to worry about Ruby VM compatibility, will do something like:
+
+ do_something if RUBY_VERSION >= "1.8.7"
+
+Treating the version number as a string is all well and good, until it
+isn't. The above code works for Ruby 1.8.6, 1.8.7, 1.8.8, and 1.9.1. But
+it will fail if the version is "1.8.10".
+
+There are a few version number classes out there that do better than
+treating version numbers as plain strings. Perhaps the most well known and
+often used is Gem::Version, part of rubygems. This class separates the
+version into fields and lets you manipulate and compare version numbers
+more robustly. It provides limited support for "prerelease" versions
+through using string-valued fields. However, it's still a little clumsy.
+A prerelease version has to be represented like this: "1.9.2.b.1" or
+"1.9.2.preview.2". Wouldn't it be nice to be able to parse more typical
+version number formats such as "1.9.2b1" and "1.9.2 preview-2"?
+
+Yes you can!
+
=== Some examples
require 'versionomy'
@@ -86,8 +111,9 @@ semantics for comparing, parsing, and modifying version numbers.
=== Requirements
-* Ruby 1.8.6 or later (1.8.7 recommended), Ruby 1.9.1 or later, or JRuby 1.4 or later.
-* blockenspiel gem.
+* Ruby 1.8.6 or later (1.8.7 recommended), Ruby 1.9.1 or later, or JRuby
+ 1.4 or later.
+* blockenspiel 0.3 or later.
=== Installation
View
6 lib/versionomy/conversion.rb
@@ -51,6 +51,12 @@ module Versionomy
# it will use your conversion. You can register the same conversion object
# for multiple pairs of schemas, but you can register only one conversion
# object for any pair.
+ #
+ # A common technique for doing conversions is to unparse the version to a
+ # string, and then parse it in the new format. Versionomy provides a tool,
+ # Versionomy::Conversion::Parsing, for performing such conversions. The
+ # conversions between the standard and rubygems formats uses this tool.
+ # See Versionomy::Conversion::Rubygems for annotated examples.
module Conversion
View
14 lib/versionomy/conversion/rubygems.rb
@@ -106,17 +106,9 @@ def self.create_standard_to_rubygems
def self.create_rubygems_to_standard
# We'll use a parsing conversion to do this conversion.
- Conversion::Parsing.new do
-
- # The standard format generally will understand the rubygems
- # format, except that the standard format supports only four
- # fields (plus prerelease versions or patchlevel). So cause the
- # parser to error out if rubygems unparses too many fields.
- to_generate_parse_params do |convert_params_|
- {:extra_characters => :error}
- end
-
- end
+ # The standard format generally understands the rubygems format
+ # already, so we don't need to do any special configuration.
+ Conversion::Parsing.new
end
View
21 lib/versionomy/format.rb
@@ -53,7 +53,7 @@ module Versionomy
# (e.g. alpha, beta, release candidate, etc.) forms and patchlevels.
#
# You may also create your own formats, either by implementing the
- # format contract (see Versionomy::Format::Base) or by using the
+ # format contract (see Versionomy::Format::Base), or by using the
# Versionomy::Format::Delimiter tool, which can be used to construct
# parsers for many version number formats.
#
@@ -88,11 +88,17 @@ def get(name_, strict_=false)
# Register the given format under the given name.
#
+ # Valid names may contain only letters, digits, underscores, dashes,
+ # and periods.
+ #
# Raises Versionomy::Errors::FormatRedefinedError if the name has
# already been defined.
def register(name_, format_)
name_ = name_.to_s
+ unless name_ =~ /^[\w.-]+$/
+ raise ::ArgumentError, "Illegal name: #{name_.inspect}"
+ end
if @names_to_formats.include?(name_)
raise Errors::FormatRedefinedError, name_
end
@@ -103,10 +109,17 @@ def register(name_, format_)
# Get the canonical name for the given format, as a string.
# This is the first name the format was registered under.
- # Returns nil if this format was never registered.
+ #
+ # If the given format was never registered, and strict is set to true,
+ # raises Versionomy::Errors::UnknownFormatError. If strict is set to
+ # false, returns nil if the given format was never registered.
- def canonical_name_for(format_)
- @formats_to_names[format_.object_id]
+ def canonical_name_for(format_, strict_=false)
+ name_ = @formats_to_names[format_.object_id]
+ if name_.nil? && strict_
+ raise Errors::UnknownFormatError
+ end
+ name_
end
View
34 lib/versionomy/format/base.rb
@@ -44,12 +44,14 @@ module Format
#
# This format doesn't actually do anything useful. It causes all strings
# to parse to the schema's default value, and unparses all values to the
- # empty string.
+ # empty string. Instead, the purpose here is to define the API for a
+ # format.
#
- # Instead, the purpose here is to define the API for a format. All
- # formats must define the methods +schema+, +parse+, and +unparse+.
+ # All formats must define the methods +schema+, +parse+, and +unparse+.
# It is also recommended that formats define the <tt>===</tt> method,
- # though this is not strictly required.
+ # though this is not strictly required. Finally, formats may optionally
+ # implement <tt>uparse_for_serialize</tt>.
+ #
# Formats need not extend this base class, as long as they duck-type
# these methods.
@@ -101,6 +103,30 @@ def unparse(value_, params_=nil)
end
+ # An optional method that does unparsing especially for serialization.
+ # Implement this if normal unparsing is "lossy" and doesn't guarantee
+ # reconstruction of the version number. This method should attempt to
+ # unparse in such a way that the entire version value can be
+ # reconstructed from the unparsed string. Serialization routines will
+ # first attempt to call this method to unparse for serialization. If
+ # this method is not present, the normal unparse method will be used.
+ #
+ # Return either the unparsed string, or an array consisting of the
+ # unparsed string and a hash of parse params to pass to the parser
+ # when the string is to be reconstructed. You may also either return
+ # nil or raise Versionomy::Errors::UnparseError if the unparsing
+ # cannot be done satisfactorily for serialization. In this case,
+ # serialization will be done using the raw value data rather than an
+ # unparsed string.
+ #
+ # This default implementation just turns around and calls unparse.
+ # Thus it is equivalent to the method not being present at all.
+
+ def unparse_for_serialization(value_)
+ unparse(value_)
+ end
+
+
# Determine whether the given value uses this format.
def ===(obj_)
View
30 lib/versionomy/format/delimiter.rb
@@ -128,11 +128,11 @@ def schema
#
# <tt>:extra_characters</tt>::
# Determines what to do if the entire string cannot be consumed by
- # the parsing process. If set to <tt>:ignore</tt> (the default),
- # any extra characters are ignored. If set to <tt>:suffix</tt>,
- # the extra characters are set as the <tt>:suffix</tt> unparse
- # parameter and are thus appended to the end of the string when
- # unparsing takes place. If set to <tt>:error</tt>, causes a
+ # the parsing process. If set to <tt>:ignore</tt>, any extra
+ # characters are ignored. If set to <tt>:suffix</tt>, the extra
+ # characters are set as the <tt>:suffix</tt> unparse parameter and
+ # are thus appended to the end of the string when unparsing takes
+ # place. If set to <tt>:error</tt> (the default), causes a
# Versionomy::Errors::ParseError to be raised if there are
# uninterpreted characters.
@@ -152,10 +152,12 @@ def parse(string_, params_=nil)
end
if parse_params_[:string].length > 0
case parse_params_[:extra_characters]
- when :error
- raise Errors::ParseError, "Extra characters: #{parse_params_[:string].inspect}"
+ when :ignore
+ # do nothing
when :suffix
unparse_params_[:suffix] = parse_params_[:string]
+ else
+ raise Errors::ParseError, "Extra characters: #{parse_params_[:string].inspect}"
end
end
Value.new(values_, self, unparse_params_)
@@ -689,15 +691,15 @@ def setup(field_, value_regexp_, opts_)
@style = opts_[:style]
@default_value_optional = opts_[:default_value_optional]
@regexp_options = opts_[:case_sensitive] ? nil : ::Regexp::IGNORECASE
- @value_regexp = ::Regexp.new("^(#{value_regexp_})", @regexp_options)
+ @value_regexp = ::Regexp.new("\\A(#{value_regexp_})", @regexp_options)
regexp_ = opts_[:delimiter_regexp] || '\.'
- @delimiter_regexp = regexp_.length > 0 ? ::Regexp.new("^(#{regexp_})", @regexp_options) : nil
- @full_delimiter_regexp = regexp_.length > 0 ? ::Regexp.new("^(#{regexp_})$", @regexp_options) : nil
+ @delimiter_regexp = regexp_.length > 0 ? ::Regexp.new("\\A(#{regexp_})", @regexp_options) : nil
+ @full_delimiter_regexp = regexp_.length > 0 ? ::Regexp.new("\\A(#{regexp_})\\z", @regexp_options) : nil
regexp_ = opts_[:post_delimiter_regexp] || ''
- @post_delimiter_regexp = regexp_.length > 0 ? ::Regexp.new("^(#{regexp_})", @regexp_options) : nil
- @full_post_delimiter_regexp = regexp_.length > 0 ? ::Regexp.new("^(#{regexp_})$", @regexp_options) : nil
+ @post_delimiter_regexp = regexp_.length > 0 ? ::Regexp.new("\\A(#{regexp_})", @regexp_options) : nil
+ @full_post_delimiter_regexp = regexp_.length > 0 ? ::Regexp.new("\\A(#{regexp_})\\z", @regexp_options) : nil
regexp_ = opts_[:expected_follower_regexp] || ''
- @follower_regexp = regexp_.length > 0 ? ::Regexp.new("^(#{regexp_})", @regexp_options) : nil
+ @follower_regexp = regexp_.length > 0 ? ::Regexp.new("\\A(#{regexp_})", @regexp_options) : nil
@default_delimiter = opts_[:default_delimiter] || '.'
@default_post_delimiter = opts_[:default_post_delimiter] || ''
@requires_previous_field = opts_.fetch(:requires_previous_field, true)
@@ -931,7 +933,7 @@ def initialize(field_, opts_={}, &block_)
regexps_ = @mappings_in_order.map{ |map_| "(#{map_[0]})" }
setup(field_, regexps_.join('|'), opts_)
@mappings_in_order.each do |map_|
- map_[0] = ::Regexp.new("^(#{map_[0]})", @regexp_options)
+ map_[0] = ::Regexp.new("\\A(#{map_[0]})", @regexp_options)
end
end
View
2  lib/versionomy/format/rubygems.rb
@@ -123,7 +123,7 @@ def self.create
val_
else
val_ = val_.to_s
- if val_ =~ /^\d*$/
+ if val_ =~ /\A\d*\z/
val_.to_i
else
val_
View
2  lib/versionomy/format/standard.rb
@@ -358,7 +358,7 @@ def self.create
:delimiter_regexp => '(-|\.|\s?)p|-')
recognize_letter(:style => :letter, :default_delimiter => '',
:delimiter_regexp => '-|\.|\s?',
- :expected_follower_regexp => '$')
+ :expected_follower_regexp => '\z')
end
field(:patchlevel_minor) do
recognize_number(:default_value_optional => true)
View
8 lib/versionomy/interface.rb
@@ -91,6 +91,10 @@ def default_format=(format_)
# is not registered.
def create(values_=nil, format_=nil, unparse_params_=nil)
+ if format_.kind_of?(::Hash) && unparse_params_.nil?
+ unparse_params_ = format_
+ format_ = nil
+ end
if format_.kind_of?(::String) || format_.kind_of?(::Symbol)
format_ = Format.get(format_, true)
end
@@ -115,6 +119,10 @@ def create(values_=nil, format_=nil, unparse_params_=nil)
# May raise Versionomy::Errors::ParseError if parsing failed.
def parse(str_, format_=nil, parse_params_=nil)
+ if format_.kind_of?(::Hash) && parse_params_.nil?
+ parse_params_ = format_
+ format_ = nil
+ end
if format_.kind_of?(::String) || format_.kind_of?(::Symbol)
format_ = Format.get(format_, true)
end
View
72 lib/versionomy/value.rb
@@ -34,6 +34,9 @@
;
+require 'yaml'
+
+
module Versionomy
@@ -112,23 +115,72 @@ def to_s
# Marshal this version number.
- def marshal_dump
- format_name_ = Format.canonical_name_for(@format)
- unless format_name_
- raise Errors::SerializationError, "Cannot marshal because the format is not registered"
+ def marshal_dump # :nodoc:
+ format_name_ = Format.canonical_name_for(@format, true)
+ unparsed_data_ = nil
+ if @format.respond_to?(:unparse_for_serialization)
+ unparsed_data_ = @format.unparse_for_serialization(self) rescue nil
end
- [format_name_, @unparse_params, values_array]
+ unparsed_data_ ||= @format.unparse(self) rescue nil
+ data_ = [format_name_]
+ case unparsed_data_
+ when ::Array
+ data_ << unparsed_data_[0]
+ data_ << unparsed_data_[1] if unparsed_data_[1]
+ when ::String
+ data_ << unparsed_data_
+ else
+ data_ << values_array
+ data_ << @unparse_params if @unparse_params
+ end
+ data_
end
# Unmarshal this version number.
- def marshal_load(data_)
- format_ = Format.get(data_[0])
- unless format_
- raise Errors::SerializationError, "Cannot unmarshal because the format is not registered"
+ def marshal_load(data_) # :nodoc:
+ format_ = Format.get(data_[0], true)
+ if data_[1].kind_of?(::String)
+ val_ = format_.parse(data_[1], data_[2])
+ initialize(val_.values_array, format_, val_.unparse_params)
+ else
+ initialize(data_[1], format_, data_[2])
+ end
+ end
+
+
+ yaml_as "tag:danielazuma.com,2009:version"
+
+
+ def self.yaml_new(klass_, tag_, data_) # :nodoc:
+ unless data_.kind_of?(::Hash)
+ raise ::YAML::TypeError, "Invalid version format: #{val_.inspect}"
+ end
+ format_ = Format.get(data_['format'], true)
+ value_ = data_['value']
+ if value_
+ format_.parse(value_, data_['parse_params'])
+ else
+ Value.new(format_, data_['fields'], data_['unparse_params'])
+ end
+ end
+
+
+ def to_yaml(opts_={}) # :nodoc:
+ data_ = marshal_dump
+ ::YAML::quick_emit(nil, opts_) do |out_|
+ out_.map(taguri, to_yaml_style) do |map_|
+ map_.add('format', data_[0])
+ if data_[1].kind_of?(::String)
+ map_.add('value', data_[1])
+ map_.add('parse_params', data_[2]) if data_[2]
+ else
+ map_.add('fields', data_[1])
+ map_.add('unparse_params', data_[2]) if data_[2]
+ end
+ end
end
- initialize(data_[2], format_, data_[1])
end
View
8 tests/tc_custom_format.rb
@@ -36,24 +36,24 @@
require 'test/unit'
-require File.expand_path("#{File.dirname(__FILE__)}/../lib/versionomy.rb")
+require ::File.expand_path("#{::File.dirname(__FILE__)}/../lib/versionomy.rb")
module Versionomy
module Tests # :nodoc:
- class TestCustomFormat < Test::Unit::TestCase # :nodoc:
+ class TestCustomFormat < ::Test::Unit::TestCase # :nodoc:
# Test parsing with custom format for patchlevel
def test_parsing_custom_patchlevel_format
- format_ = Versionomy.default_format.modified_copy do
+ format_ = ::Versionomy.default_format.modified_copy do
field(:patchlevel, :requires_previous_field => false) do
recognize_number(:delimiter_regexp => '\s?sp', :default_delimiter => ' SP')
end
end
- value1_ = Versionomy.parse('2008 SP2', format_)
+ value1_ = ::Versionomy.parse('2008 SP2', format_)
assert_equal(2, value1_.patchlevel)
value2_ = value1_.format.parse('2008 sp3')
assert_equal(3, value2_.patchlevel)
View
16 tests/tc_readme_examples.rb
@@ -36,13 +36,13 @@
require 'test/unit'
-require File.expand_path("#{File.dirname(__FILE__)}/../lib/versionomy.rb")
+require ::File.expand_path("#{::File.dirname(__FILE__)}/../lib/versionomy.rb")
module Versionomy
module Tests # :nodoc:
- class TestReadmeExamples < Test::Unit::TestCase # :nodoc:
+ class TestReadmeExamples < ::Test::Unit::TestCase # :nodoc:
# Test the README file.
@@ -51,7 +51,7 @@ class TestReadmeExamples < Test::Unit::TestCase # :nodoc:
def test_readme_file
binding_ = _get_binding
- File.open("#{File.dirname(__FILE__)}/../README.rdoc") do |io_|
+ ::File.open("#{::File.dirname(__FILE__)}/../README.rdoc") do |io_|
running_ = false
buffer_ = ''
buffer_start_line_ = nil
@@ -77,7 +77,7 @@ def test_readme_file
# At this point, we have an expects clause. First run any buffer
# accumulated up to now.
if buffer_.length > 0
- Kernel.eval(buffer_, binding_, 'README.rdoc', buffer_start_line_)
+ ::Kernel.eval(buffer_, binding_, 'README.rdoc', buffer_start_line_)
buffer_ = ''
buffer_start_line_ = nil
end
@@ -88,17 +88,17 @@ def test_readme_file
if expect_ =~ /^=> (.*)$/
# Expect a value
- expect_value_ = Kernel.eval($1, binding_, 'README.rdoc', io_.lineno)
- actual_value_ = Kernel.eval(expr_, binding_, 'README.rdoc', io_.lineno)
+ expect_value_ = ::Kernel.eval($1, binding_, 'README.rdoc', io_.lineno)
+ actual_value_ = ::Kernel.eval(expr_, binding_, 'README.rdoc', io_.lineno)
assert_equal(expect_value_, actual_value_,
"Values did not match on line #{io_.lineno} of README.rdoc")
elsif expect_ =~ /^raises (.*)$/
# Expect an exception to be raised
- expect_error_ = Kernel.eval($1, binding_, 'README.rdoc', io_.lineno)
+ expect_error_ = ::Kernel.eval($1, binding_, 'README.rdoc', io_.lineno)
got_error_ = false
assert_raise(expect_error_) do
- Kernel.eval(expr_, binding_, 'README.rdoc', io_.lineno)
+ ::Kernel.eval(expr_, binding_, 'README.rdoc', io_.lineno)
end
else
View
54 tests/tc_rubygems_basic.rb
@@ -36,19 +36,19 @@
require 'test/unit'
-require File.expand_path("#{File.dirname(__FILE__)}/../lib/versionomy.rb")
+require ::File.expand_path("#{::File.dirname(__FILE__)}/../lib/versionomy.rb")
module Versionomy
module Tests # :nodoc:
- class TestRubygemsBasic < Test::Unit::TestCase # :nodoc:
+ class TestRubygemsBasic < ::Test::Unit::TestCase # :nodoc:
# Test the default version value.
def test_default_value
- value_ = Versionomy.create(nil, :rubygems)
+ value_ = ::Versionomy.create(nil, :rubygems)
assert_equal(1, value_.field0)
assert_equal(0, value_.field1)
assert_equal(0, value_.field2)
@@ -63,7 +63,7 @@ def test_default_value
# Test an arbitrary value.
def test_arbitrary_value
- value_ = Versionomy.create([1, 9, 2, 'pre', 2], :rubygems)
+ value_ = ::Versionomy.create([1, 9, 2, 'pre', 2], :rubygems)
assert_equal(1, value_.field0)
assert_equal(9, value_.field1)
assert_equal(2, value_.field2)
@@ -78,11 +78,11 @@ def test_arbitrary_value
# Test comparison of numeric values.
def test_numeric_comparison
- value1_ = Versionomy.create([1, 9, 2], :rubygems)
- value2_ = Versionomy.create([1, 9], :rubygems)
+ value1_ = ::Versionomy.create([1, 9, 2], :rubygems)
+ value2_ = ::Versionomy.create([1, 9], :rubygems)
assert(value2_ < value1_)
- value1_ = Versionomy.create([1, 9, 0], :rubygems)
- value2_ = Versionomy.create([1, 9], :rubygems)
+ value1_ = ::Versionomy.create([1, 9, 0], :rubygems)
+ value2_ = ::Versionomy.create([1, 9], :rubygems)
assert(value2_ == value1_)
end
@@ -90,8 +90,8 @@ def test_numeric_comparison
# Test comparison of string values.
def test_string_comparison
- value1_ = Versionomy.create([1, 9, 2, 'a', 2], :rubygems)
- value2_ = Versionomy.create([1, 9, 2, 'b', 1], :rubygems)
+ value1_ = ::Versionomy.create([1, 9, 2, 'a', 2], :rubygems)
+ value2_ = ::Versionomy.create([1, 9, 2, 'b', 1], :rubygems)
assert(value2_ > value1_)
end
@@ -99,8 +99,8 @@ def test_string_comparison
# Test comparison of numeric and string values.
def test_numeric_and_string_comparison
- value1_ = Versionomy.create([1, 9, 2, 'a', 2], :rubygems)
- value2_ = Versionomy.create([1, 9, 2, 1], :rubygems)
+ value1_ = ::Versionomy.create([1, 9, 2, 'a', 2], :rubygems)
+ value2_ = ::Versionomy.create([1, 9, 2, 1], :rubygems)
assert(value2_ > value1_)
end
@@ -108,7 +108,7 @@ def test_numeric_and_string_comparison
# Test parsing numeric.
def test_parsing_numeric
- value_ = Versionomy.parse('2.0.1.1.4.6', :rubygems)
+ value_ = ::Versionomy.parse('2.0.1.1.4.6', :rubygems)
assert_equal([2, 0, 1, 1, 4, 6, 0, 0], value_.values_array)
assert_equal('2.0.1.1.4.6', value_.unparse)
end
@@ -117,7 +117,7 @@ def test_parsing_numeric
# Test parsing with a string.
def test_parsing_with_string
- value_ = Versionomy.parse('1.9.2.pre.2', :rubygems)
+ value_ = ::Versionomy.parse('1.9.2.pre.2', :rubygems)
assert_equal([1, 9, 2, 'pre', 2, 0, 0, 0], value_.values_array)
assert_equal('1.9.2.pre.2', value_.unparse)
end
@@ -126,7 +126,7 @@ def test_parsing_with_string
# Test parsing with trailing zeros.
def test_parsing_trailing_zeros
- value_ = Versionomy.parse('2.0.0', :rubygems)
+ value_ = ::Versionomy.parse('2.0.0', :rubygems)
assert_equal([2, 0, 0, 0, 0, 0, 0, 0], value_.values_array)
assert_equal('2.0.0', value_.unparse)
assert_equal('2.0.0.0.0', value_.unparse(:required_fields => [:field4]))
@@ -137,7 +137,7 @@ def test_parsing_trailing_zeros
# Test bumping a numeric field.
def test_bump_numeric
- value_ = Versionomy.create([1, 9, 2, 'a', 2], :rubygems)
+ value_ = ::Versionomy.create([1, 9, 2, 'a', 2], :rubygems)
value_ = value_.bump(:field2)
assert_equal([1, 9, 3, 0, 0, 0, 0, 0], value_.values_array)
end
@@ -146,7 +146,7 @@ def test_bump_numeric
# Test bumping a string field.
def test_bump_string
- value_ = Versionomy.create([1, 9, 2, 'a', 2], :rubygems)
+ value_ = ::Versionomy.create([1, 9, 2, 'a', 2], :rubygems)
value_ = value_.bump(:field3)
assert_equal([1, 9, 2, 'b', 0, 0, 0, 0], value_.values_array)
end
@@ -155,9 +155,9 @@ def test_bump_string
# Test "prerelase?" custom method
def test_method_prereleasep
- value_ = Versionomy.create([1, 9, 2, 'a', 2], :rubygems)
+ value_ = ::Versionomy.create([1, 9, 2, 'a', 2], :rubygems)
assert_equal(true, value_.prerelease?)
- value_ = Versionomy.create([1, 9, 2, 2], :rubygems)
+ value_ = ::Versionomy.create([1, 9, 2, 2], :rubygems)
assert_equal(false, value_.prerelease?)
end
@@ -165,10 +165,10 @@ def test_method_prereleasep
# Test "relase" custom method
def test_method_release
- value_ = Versionomy.create([1, 9, 2, 'a', 2], :rubygems)
+ value_ = ::Versionomy.create([1, 9, 2, 'a', 2], :rubygems)
value2_ = value_.release
assert_equal([1, 9, 2, 0, 0, 0, 0, 0], value2_.values_array)
- value_ = Versionomy.create([1, 9, 2, 5, 2], :rubygems)
+ value_ = ::Versionomy.create([1, 9, 2, 5, 2], :rubygems)
value2_ = value_.release
assert_equal(value_, value2_)
end
@@ -177,13 +177,23 @@ def test_method_release
# Test marshalling
def test_marshal
- value_ = Versionomy.create([1, 9, 2, 'a', 2], :rubygems)
+ value_ = ::Versionomy.create([1, 9, 2, 'a', 2], :rubygems)
str_ = ::Marshal.dump(value_)
value2_ = ::Marshal.load(str_)
assert_equal(value_, value2_)
end
+ # Test YAML
+
+ def test_yaml
+ value_ = ::Versionomy.create([1, 9, 2, 'a', 2], :rubygems)
+ str_ = ::YAML.dump(value_)
+ value2_ = ::YAML.load(str_)
+ assert_equal(value_, value2_)
+ end
+
+
end
end
View
56 tests/tc_rubygems_conversions.rb
@@ -36,13 +36,13 @@
require 'test/unit'
-require File.expand_path("#{File.dirname(__FILE__)}/../lib/versionomy.rb")
+require ::File.expand_path("#{::File.dirname(__FILE__)}/../lib/versionomy.rb")
module Versionomy
module Tests # :nodoc:
- class TestRubygemsConversions < Test::Unit::TestCase # :nodoc:
+ class TestRubygemsConversions < ::Test::Unit::TestCase # :nodoc:
def setup
@@ -54,11 +54,11 @@ def setup
# Test simple conversion from standard to rubygems.
def test_standard_to_rubygems_simple
- value_ = Versionomy.parse('1.2')
+ value_ = ::Versionomy.parse('1.2')
value2_ = value_.convert(:rubygems)
assert_equal(@rubygems_format, value2_.format)
assert_equal([1, 2, 0, 0, 0, 0, 0, 0], value2_.values_array)
- value_ = Versionomy.parse('1.2.4.1')
+ value_ = ::Versionomy.parse('1.2.4.1')
value2_ = value_.convert(:rubygems)
assert_equal(@rubygems_format, value2_.format)
assert_equal([1, 2, 4, 1, 0, 0, 0, 0], value2_.values_array)
@@ -68,15 +68,15 @@ def test_standard_to_rubygems_simple
# Test conversion from standard to rubygems including a patchlevel
def test_standard_to_rubygems_with_patchlevel
- value_ = Versionomy.parse('1.2-3')
+ value_ = ::Versionomy.parse('1.2-3')
value2_ = value_.convert(:rubygems)
assert_equal(@rubygems_format, value2_.format)
assert_equal([1, 2, 3, 0, 0, 0, 0, 0], value2_.values_array)
- value_ = Versionomy.parse('1.2p3')
+ value_ = ::Versionomy.parse('1.2p3')
value2_ = value_.convert(:rubygems)
assert_equal(@rubygems_format, value2_.format)
assert_equal([1, 2, 3, 0, 0, 0, 0, 0], value2_.values_array)
- value_ = Versionomy.parse('1.2c')
+ value_ = ::Versionomy.parse('1.2c')
value2_ = value_.convert(:rubygems)
assert_equal(@rubygems_format, value2_.format)
assert_equal([1, 2, 3, 0, 0, 0, 0, 0], value2_.values_array)
@@ -86,11 +86,11 @@ def test_standard_to_rubygems_with_patchlevel
# Test conversion from standard to rubygems with a beta version
def test_standard_to_rubygems_beta
- value_ = Versionomy.parse('1.2b3')
+ value_ = ::Versionomy.parse('1.2b3')
value2_ = value_.convert(:rubygems)
assert_equal(@rubygems_format, value2_.format)
assert_equal([1, 2, 'b', 3, 0, 0, 0, 0], value2_.values_array)
- value_ = Versionomy.parse('1.2 beta 3.4')
+ value_ = ::Versionomy.parse('1.2 beta 3.4')
value2_ = value_.convert(:rubygems)
assert_equal(@rubygems_format, value2_.format)
assert_equal([1, 2, 'beta', 3, 4, 0, 0, 0], value2_.values_array)
@@ -100,11 +100,11 @@ def test_standard_to_rubygems_beta
# Test simple conversion from rubygems to standard.
def test_rubygems_to_standard_simple
- value_ = Versionomy.parse('1.2', :rubygems)
+ value_ = ::Versionomy.parse('1.2', :rubygems)
value2_ = value_.convert(:standard)
assert_equal(@standard_format, value2_.format)
assert_equal([1, 2, 0, 0, :final, 0, 0], value2_.values_array)
- value_ = Versionomy.parse('1.2.4.1', :rubygems)
+ value_ = ::Versionomy.parse('1.2.4.1', :rubygems)
value2_ = value_.convert(:standard)
assert_equal(@standard_format, value2_.format)
assert_equal([1, 2, 4, 1, :final, 0, 0], value2_.values_array)
@@ -114,15 +114,15 @@ def test_rubygems_to_standard_simple
# Test conversion from rubygems to standard with a beta version
def test_rubygems_to_standard_beta
- value_ = Versionomy.parse('1.2.b.3', :rubygems)
+ value_ = ::Versionomy.parse('1.2.b.3', :rubygems)
value2_ = value_.convert(:standard)
assert_equal(@standard_format, value2_.format)
assert_equal([1, 2, 0, 0, :beta, 3, 0], value2_.values_array)
- value_ = Versionomy.parse('1.2.b3', :rubygems)
+ value_ = ::Versionomy.parse('1.2.b3', :rubygems)
value2_ = value_.convert(:standard)
assert_equal(@standard_format, value2_.format)
assert_equal([1, 2, 0, 0, :beta, 3, 0], value2_.values_array)
- value_ = Versionomy.parse('1.2.beta3', :rubygems)
+ value_ = ::Versionomy.parse('1.2.beta3', :rubygems)
value2_ = value_.convert(:standard)
assert_equal(@standard_format, value2_.format)
assert_equal([1, 2, 0, 0, :beta, 3, 0], value2_.values_array)
@@ -132,12 +132,12 @@ def test_rubygems_to_standard_beta
# Test conversion from rubygems to standard with an expectation of failure
def test_rubygems_to_standard_fail
- value_ = Versionomy.parse('1.2.b.3.4.5', :rubygems)
- assert_raise(Versionomy::Errors::ConversionError) do
+ value_ = ::Versionomy.parse('1.2.b.3.4.5', :rubygems)
+ assert_raise(::Versionomy::Errors::ConversionError) do
value2_ = value_.convert(:standard)
end
- value_ = Versionomy.parse('1.2.c.3', :rubygems)
- assert_raise(Versionomy::Errors::ConversionError) do
+ value_ = ::Versionomy.parse('1.2.c.3', :rubygems)
+ assert_raise(::Versionomy::Errors::ConversionError) do
value2_ = value_.convert(:standard)
end
end
@@ -146,34 +146,34 @@ def test_rubygems_to_standard_fail
# Test equality comparisons between rubygems and standard
def test_rubygems_to_standard_equality_comparison
- assert_operator(Versionomy.parse('1.2.0', :rubygems), :==, Versionomy.parse('1.2'))
- assert_operator(Versionomy.parse('1.2.b.3', :rubygems), :==, Versionomy.parse('1.2b3'))
+ assert_operator(::Versionomy.parse('1.2.0', :rubygems), :==, ::Versionomy.parse('1.2'))
+ assert_operator(::Versionomy.parse('1.2.b.3', :rubygems), :==, ::Versionomy.parse('1.2b3'))
end
# Test inequality comparisons between rubygems and standard
def test_rubygems_to_standard_equality_comparison
- assert_operator(Versionomy.parse('1.2.3', :rubygems), :<, Versionomy.parse('1.2.4'))
- assert_operator(Versionomy.parse('1.2.b.3', :rubygems), :>, Versionomy.parse('1.2b2'))
- assert_operator(Versionomy.parse('1.2', :rubygems), :>, Versionomy.parse('1.2b1'))
+ assert_operator(::Versionomy.parse('1.2.3', :rubygems), :<, ::Versionomy.parse('1.2.4'))
+ assert_operator(::Versionomy.parse('1.2.b.3', :rubygems), :>, ::Versionomy.parse('1.2b2'))
+ assert_operator(::Versionomy.parse('1.2', :rubygems), :>, ::Versionomy.parse('1.2b1'))
end
# Test equality comparisons between standard and rubygems
def test_standard_to_rubygems_equality_comparison
- assert_operator(Versionomy.parse('1.2.0'), :==, Versionomy.parse('1.2', :rubygems))
- assert_operator(Versionomy.parse('1.2b3'), :==, Versionomy.parse('1.2.beta.3', :rubygems))
+ assert_operator(::Versionomy.parse('1.2.0'), :==, ::Versionomy.parse('1.2', :rubygems))
+ assert_operator(::Versionomy.parse('1.2b3'), :==, ::Versionomy.parse('1.2.beta.3', :rubygems))
end
# Test inequality comparisons between standard and rubygems
def test_standard_to_rubygems_inequality_comparison
- assert_operator(Versionomy.parse('1.2.4'), :>, Versionomy.parse('1.2.3', :rubygems))
- assert_operator(Versionomy.parse('1.2b2'), :<, Versionomy.parse('1.2.beta.3', :rubygems))
- assert_operator(Versionomy.parse('1.2b2'), :<, Versionomy.parse('1.2', :rubygems))
+ assert_operator(::Versionomy.parse('1.2.4'), :>, ::Versionomy.parse('1.2.3', :rubygems))
+ assert_operator(::Versionomy.parse('1.2b2'), :<, ::Versionomy.parse('1.2.beta.3', :rubygems))
+ assert_operator(::Versionomy.parse('1.2b2'), :<, ::Versionomy.parse('1.2', :rubygems))
end
View
54 tests/tc_standard_basic.rb
@@ -36,19 +36,19 @@
require 'test/unit'
-require File.expand_path("#{File.dirname(__FILE__)}/../lib/versionomy.rb")
+require ::File.expand_path("#{::File.dirname(__FILE__)}/../lib/versionomy.rb")
module Versionomy
module Tests # :nodoc:
- class TestStandardBasic < Test::Unit::TestCase # :nodoc:
+ class TestStandardBasic < ::Test::Unit::TestCase # :nodoc:
# Test the default version value.
def test_default_value
- value_ = Versionomy.create
+ value_ = ::Versionomy.create
assert_equal(1, value_.major)
assert_equal(0, value_.minor)
assert_equal(0, value_.tiny)
@@ -62,7 +62,7 @@ def test_default_value
# Test an arbitrary release value.
def test_release_value_1
- value_ = Versionomy.create(:major => 1, :tiny => 4, :tiny2 => 2, :patchlevel => 5)
+ value_ = ::Versionomy.create(:major => 1, :tiny => 4, :tiny2 => 2, :patchlevel => 5)
assert_equal(1, value_.major)
assert_equal(0, value_.minor)
assert_equal(4, value_.tiny)
@@ -78,7 +78,7 @@ def test_release_value_1
# Test an arbitrary release value.
def test_release_value_2
- value_ = Versionomy.create(:major => 0, :minor => 3)
+ value_ = ::Versionomy.create(:major => 0, :minor => 3)
assert_equal(0, value_.major)
assert_equal(3, value_.minor)
assert_equal(0, value_.tiny)
@@ -94,7 +94,7 @@ def test_release_value_2
# Test an arbitrary preview value.
def test_preview_value_1
- value_ = Versionomy.create(:major => 2, :minor => 3, :release_type => :preview, :preview_version => 3)
+ value_ = ::Versionomy.create(:major => 2, :minor => 3, :release_type => :preview, :preview_version => 3)
assert_equal(2, value_.major)
assert_equal(3, value_.minor)
assert_equal(0, value_.tiny)
@@ -110,7 +110,7 @@ def test_preview_value_1
# Test an arbitrary preview value.
def test_preview_value_2
- value_ = Versionomy.create(:major => 2, :minor => 3, :release_type => :preview)
+ value_ = ::Versionomy.create(:major => 2, :minor => 3, :release_type => :preview)
assert_equal(2, value_.major)
assert_equal(3, value_.minor)
assert_equal(0, value_.tiny)
@@ -126,7 +126,7 @@ def test_preview_value_2
# Test an arbitrary beta value.
def test_beta_value
- value_ = Versionomy.create(:major => 2, :tiny => 1, :release_type => :beta, :beta_version => 3)
+ value_ = ::Versionomy.create(:major => 2, :tiny => 1, :release_type => :beta, :beta_version => 3)
assert_equal(2, value_.major)
assert_equal(0, value_.minor)
assert_equal(1, value_.tiny)
@@ -144,7 +144,7 @@ def test_beta_value
# Test specifying fields by index.
def test_field_get_index
- value_ = Versionomy.create(:major => 2, :tiny => 1, :release_type => :beta, :beta_version => 3)
+ value_ = ::Versionomy.create(:major => 2, :tiny => 1, :release_type => :beta, :beta_version => 3)
assert_equal(2, value_[0])
assert_equal(0, value_[1])
assert_equal(1, value_[2])
@@ -158,7 +158,7 @@ def test_field_get_index
# Test specifying fields by name.
def test_field_get_name
- value_ = Versionomy.create(:major => 2, :tiny => 1, :release_type => :beta, :beta_version => 3)
+ value_ = ::Versionomy.create(:major => 2, :tiny => 1, :release_type => :beta, :beta_version => 3)
assert_equal(2, value_[:major])
assert_equal(0, value_[:minor])
assert_equal(1, value_[:tiny])
@@ -169,40 +169,6 @@ def test_field_get_name
end
- # Test "prerelase?" custom method
-
- def test_method_prereleasep
- value_ = Versionomy.create(:major => 2, :tiny => 1, :release_type => :beta, :beta_version => 3)
- assert_equal(true, value_.prerelease?)
- value_ = Versionomy.create(:major => 2, :tiny => 1, :release_type => :final, :patchlevel => 1)
- assert_equal(false, value_.prerelease?)
- value_ = Versionomy.create(:major => 2, :tiny => 1)
- assert_equal(false, value_.prerelease?)
- end
-
-
- # Test "relase" custom method
-
- def test_method_release
- value_ = Versionomy.create(:major => 1, :minor => 9, :tiny => 2, :release_type => :alpha, :alpha_version => 4)
- value2_ = value_.release
- assert_equal([1, 9, 2, 0, :final, 0, 0], value2_.values_array)
- value_ = Versionomy.create(:major => 1, :minor => 9, :tiny => 2)
- value2_ = value_.release
- assert_equal(value_, value2_)
- end
-
-
- # Test marshalling
-
- def test_marshal
- value_ = Versionomy.create(:major => 1, :minor => 9, :tiny => 2, :release_type => :alpha, :alpha_version => 4)
- str_ = ::Marshal.dump(value_)
- value2_ = ::Marshal.load(str_)
- assert_equal(value_, value2_)
- end
-
-
end
end
View
20 tests/tc_standard_bump.rb
@@ -36,19 +36,19 @@
require 'test/unit'
-require File.expand_path("#{File.dirname(__FILE__)}/../lib/versionomy.rb")
+require ::File.expand_path("#{::File.dirname(__FILE__)}/../lib/versionomy.rb")
module Versionomy
module Tests # :nodoc:
- class TestStandardBump < Test::Unit::TestCase # :nodoc:
+ class TestStandardBump < ::Test::Unit::TestCase # :nodoc:
# Test bumping a minor patchlevel.
def test_bump_patchlevel_minor
- value_ = Versionomy.create(:major => 2, :tiny => 1, :patchlevel => 3, :patchlevel_minor => 0)
+ value_ = ::Versionomy.create(:major => 2, :tiny => 1, :patchlevel => 3, :patchlevel_minor => 0)
value_ = value_.bump(:patchlevel_minor)
assert_equal(2, value_.major)
assert_equal(0, value_.minor)
@@ -63,7 +63,7 @@ def test_bump_patchlevel_minor
# Test bumping a major patchlevel.
def test_bump_patchlevel
- value_ = Versionomy.create(:major => 2, :tiny => 1, :patchlevel => 3, :patchlevel_minor => 1)
+ value_ = ::Versionomy.create(:major => 2, :tiny => 1, :patchlevel => 3, :patchlevel_minor => 1)
value_ = value_.bump(:patchlevel)
assert_equal(2, value_.major)
assert_equal(0, value_.minor)
@@ -78,7 +78,7 @@ def test_bump_patchlevel
# Test bumping release type preview.
def test_bump_preview_to_release
- value_ = Versionomy.create(:major => 2, :tiny => 1, :release_type => :preview)
+ value_ = ::Versionomy.create(:major => 2, :tiny => 1, :release_type => :preview)
value_ = value_.bump(:release_type)
assert_equal(2, value_.major)
assert_equal(0, value_.minor)
@@ -93,7 +93,7 @@ def test_bump_preview_to_release
# Test bumping release type development.
def test_bump_development_to_alpha
- value_ = Versionomy.create(:major => 2, :tiny => 1, :release_type => :development, :development_version => 7)
+ value_ = ::Versionomy.create(:major => 2, :tiny => 1, :release_type => :development, :development_version => 7)
value_ = value_.bump(:release_type)
assert_equal(2, value_.major)
assert_equal(0, value_.minor)
@@ -108,7 +108,7 @@ def test_bump_development_to_alpha
# Test bumping release type alpha.
def test_bump_alpha_to_beta
- value_ = Versionomy.create(:major => 2, :tiny => 1, :release_type => :alpha)
+ value_ = ::Versionomy.create(:major => 2, :tiny => 1, :release_type => :alpha)
value_ = value_.bump(:release_type)
assert_equal(2, value_.major)
assert_equal(0, value_.minor)
@@ -123,7 +123,7 @@ def test_bump_alpha_to_beta
# Test bumping release type release_candidate.
def test_bump_release_candidate_to_release
- value_ = Versionomy.create(:major => 2, :tiny => 1, :release_type => :release_candidate, :release_candidate_version => 2)
+ value_ = ::Versionomy.create(:major => 2, :tiny => 1, :release_type => :release_candidate, :release_candidate_version => 2)
value_ = value_.bump(:release_type)
assert_equal(2, value_.major)
assert_equal(0, value_.minor)
@@ -138,7 +138,7 @@ def test_bump_release_candidate_to_release
# Test bumping tiny.
def test_bump_tiny
- value_ = Versionomy.create(:major => 2, :tiny => 1, :tiny2 => 3, :release_type => :release_candidate, :release_candidate_version => 2)
+ value_ = ::Versionomy.create(:major => 2, :tiny => 1, :tiny2 => 3, :release_type => :release_candidate, :release_candidate_version => 2)
value_ = value_.bump(:tiny)
assert_equal(2, value_.major)
assert_equal(0, value_.minor)
@@ -153,7 +153,7 @@ def test_bump_tiny
# Test bumping major.
def test_bump_major
- value_ = Versionomy.create(:major => 2, :tiny => 1, :tiny2 => 3, :release_type => :release_candidate, :release_candidate_version => 2)
+ value_ = ::Versionomy.create(:major => 2, :tiny => 1, :tiny2 => 3, :release_type => :release_candidate, :release_candidate_version => 2)
value_ = value_.bump(:major)
assert_equal(3, value_.major)
assert_equal(0, value_.minor)
View
10 tests/tc_standard_change.rb
@@ -36,19 +36,19 @@
require 'test/unit'
-require File.expand_path("#{File.dirname(__FILE__)}/../lib/versionomy.rb")
+require ::File.expand_path("#{::File.dirname(__FILE__)}/../lib/versionomy.rb")
module Versionomy
module Tests # :nodoc:
- class TestStandardChange < Test::Unit::TestCase # :nodoc:
+ class TestStandardChange < ::Test::Unit::TestCase # :nodoc:
# Test with a changed tiny
def test_change_tiny
- value_ = Versionomy.create(:major => 2, :tiny => 1, :tiny2 => 3, :release_type => :release_candidate, :release_candidate_version => 2)
+ value_ = ::Versionomy.create(:major => 2, :tiny => 1, :tiny2 => 3, :release_type => :release_candidate, :release_candidate_version => 2)
value_ = value_.change(:tiny => 4)
assert_equal(2, value_.major)
assert_equal(0, value_.minor)
@@ -63,7 +63,7 @@ def test_change_tiny
# Test with several changed fields
def test_change_several
- value_ = Versionomy.create(:major => 2, :tiny => 1, :tiny2 => 3, :release_type => :release_candidate, :release_candidate_version => 2)
+ value_ = ::Versionomy.create(:major => 2, :tiny => 1, :tiny2 => 3, :release_type => :release_candidate, :release_candidate_version => 2)
value_ = value_.change(:tiny => 4, :release_candidate_version => 5)
assert_equal(2, value_.major)
assert_equal(0, value_.minor)
@@ -78,7 +78,7 @@ def test_change_several
# Test with a changed release type
def test_change_release_type
- value_ = Versionomy.create(:major => 2, :tiny => 1, :tiny2 => 3, :release_type => :release_candidate, :release_candidate_version => 2)
+ value_ = ::Versionomy.create(:major => 2, :tiny => 1, :tiny2 => 3, :release_type => :release_candidate, :release_candidate_version => 2)
value_ = value_.change(:release_type => :beta)
assert_equal(2, value_.major)
assert_equal(0, value_.minor)
View
45 tests/tc_standard_comparison.rb
@@ -36,20 +36,20 @@
require 'test/unit'
-require File.expand_path("#{File.dirname(__FILE__)}/../lib/versionomy.rb")
+require ::File.expand_path("#{::File.dirname(__FILE__)}/../lib/versionomy.rb")
module Versionomy
module Tests # :nodoc:
- class TestStandardComparison < Test::Unit::TestCase # :nodoc:
+ class TestStandardComparison < ::Test::Unit::TestCase # :nodoc:
# Test comparisons with difference in major.
def test_comparison_major
- value1_ = Versionomy.create(:major => 2, :tiny => 1, :tiny2 => 3, :release_type => :release_candidate, :release_candidate_version => 2)
- value2_ = Versionomy.create(:major => 3, :release_type => :alpha)
+ value1_ = ::Versionomy.create(:major => 2, :tiny => 1, :tiny2 => 3, :release_type => :release_candidate, :release_candidate_version => 2)
+ value2_ = ::Versionomy.create(:major => 3, :release_type => :alpha)
assert(value2_ > value1_)
end
@@ -57,8 +57,8 @@ def test_comparison_major
# Test comparisons with difference in minor.
def test_comparison_minor
- value1_ = Versionomy.create(:major => 2, :tiny => 1, :tiny2 => 3, :release_type => :release_candidate, :release_candidate_version => 2)
- value2_ = Versionomy.create(:major => 2, :minor => 1, :release_type => :alpha)
+ value1_ = ::Versionomy.create(:major => 2, :tiny => 1, :tiny2 => 3, :release_type => :release_candidate, :release_candidate_version => 2)
+ value2_ = ::Versionomy.create(:major => 2, :minor => 1, :release_type => :alpha)
assert(value2_ > value1_)
end
@@ -66,8 +66,8 @@ def test_comparison_minor
# Test comparisons with difference in release type.
def test_comparison_release_type
- value1_ = Versionomy.create(:major => 2, :release_type => :alpha, :alpha_version => 5)
- value2_ = Versionomy.create(:major => 2, :release_type => :release_candidate, :release_candidate_version => 2)
+ value1_ = ::Versionomy.create(:major => 2, :release_type => :alpha, :alpha_version => 5)
+ value2_ = ::Versionomy.create(:major => 2, :release_type => :release_candidate, :release_candidate_version => 2)
assert(value2_ > value1_)
end
@@ -75,8 +75,8 @@ def test_comparison_release_type
# Test equality for a simple case.
def test_equality_simple
- value1_ = Versionomy.create(:major => 2, :minor => 0, :release_type => :alpha, :alpha_version => 5)
- value2_ = Versionomy.create(:major => 2, :release_type => :alpha, :alpha_version => 5)
+ value1_ = ::Versionomy.create(:major => 2, :minor => 0, :release_type => :alpha, :alpha_version => 5)
+ value2_ = ::Versionomy.create(:major => 2, :release_type => :alpha, :alpha_version => 5)
assert_equal(value2_, value1_)
assert_equal(value2_.hash, value1_.hash)
end
@@ -85,8 +85,8 @@ def test_equality_simple
# Test equality from parsed values.
def test_equality_parsed
- value1_ = Versionomy.parse("1.8.7p72")
- value2_ = Versionomy.parse("1.8.7.0-72.0")
+ value1_ = ::Versionomy.parse("1.8.7p72")
+ value2_ = ::Versionomy.parse("1.8.7.0-72.0")
assert_equal(value2_, value1_)
assert_equal(value2_.hash, value1_.hash)
end
@@ -95,8 +95,8 @@ def test_equality_parsed
# Test non-equality from parsed values.
def test_nonequality_parsed
- value1_ = Versionomy.parse("1.8.7b7")
- value2_ = Versionomy.parse("1.8.7a7")
+ value1_ = ::Versionomy.parse("1.8.7b7")
+ value2_ = ::Versionomy.parse("1.8.7a7")
assert_not_equal(value2_, value1_)
assert_not_equal(value2_.hash, value1_.hash)
end
@@ -105,7 +105,7 @@ def test_nonequality_parsed
# Test equality with string.
def test_equality_string
- value1_ = Versionomy.parse("1.8.7p72")
+ value1_ = ::Versionomy.parse("1.8.7p72")
assert_operator(value1_, :==, "1.8.7p72")
assert_operator(value1_, :==, "1.8.7.0-72.0")
end
@@ -114,7 +114,7 @@ def test_equality_string
# Test comparison with string.
def test_comparison_string
- value1_ = Versionomy.parse("1.8.7p72")
+ value1_ = ::Versionomy.parse("1.8.7p72")
assert_operator(value1_, :<, "1.8.7p73")
assert_operator(value1_, :<, "1.8.8pre1")
assert_operator(value1_, :>, "1.8.7p71")
@@ -123,6 +123,19 @@ def test_comparison_string
end
+ # Test sorting.
+
+ def test_sort
+ value1_ = ::Versionomy.parse("1.8.7p73")
+ value2_ = ::Versionomy.parse("1.8.7p72")
+ value3_ = ::Versionomy.parse("1.8.8pre1")
+ value4_ = ::Versionomy.parse("1.8.7.0")
+ value5_ = ::Versionomy.parse("1.8.7rc2")
+ assert_equal([value5_, value4_, value2_, value1_, value3_],
+ [value1_, value2_, value3_, value4_, value5_].sort)
+ end
+
+
end
end
View
95 tests/tc_standard_misc.rb
@@ -0,0 +1,95 @@
+# -----------------------------------------------------------------------------
+#
+# Versionomy basic tests on standard schema
+#
+# This file contains tests for the basic use cases on the standard schema
+#
+# -----------------------------------------------------------------------------
+# Copyright 2008-2009 Daniel Azuma
+#
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions are met:
+#
+# * Redistributions of source code must retain the above copyright notice,
+# this list of conditions and the following disclaimer.
+# * Redistributions in binary form must reproduce the above copyright notice,
+# this list of conditions and the following disclaimer in the documentation
+# and/or other materials provided with the distribution.
+# * Neither the name of the copyright holder, nor the names of any other
+# contributors to this software, may be used to endorse or promote products
+# derived from this software without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+# POSSIBILITY OF SUCH DAMAGE.
+# -----------------------------------------------------------------------------
+
+
+require 'test/unit'
+require ::File.expand_path("#{::File.dirname(__FILE__)}/../lib/versionomy.rb")
+
+
+module Versionomy
+ module Tests # :nodoc:
+
+ class TestStandardMisc < ::Test::Unit::TestCase # :nodoc:
+
+
+ # Test "prerelase?" custom method
+
+ def test_method_prereleasep
+ value_ = ::Versionomy.create(:major => 2, :tiny => 1, :release_type => :beta, :beta_version => 3)
+ assert_equal(true, value_.prerelease?)
+ value_ = ::Versionomy.create(:major => 2, :tiny => 1, :release_type => :final, :patchlevel => 1)
+ assert_equal(false, value_.prerelease?)
+ value_ = ::Versionomy.create(:major => 2, :tiny => 1)
+ assert_equal(false, value_.prerelease?)
+ end
+
+
+ # Test "relase" custom method
+
+ def test_method_release
+ value_ = ::Versionomy.create(:major => 1, :minor => 9, :tiny => 2, :release_type => :alpha, :alpha_version => 4)
+ value2_ = value_.release
+ assert_equal([1, 9, 2, 0, :final, 0, 0], value2_.values_array)
+ value_ = ::Versionomy.create(:major => 1, :minor => 9, :tiny => 2)
+ value2_ = value_.release
+ assert_equal(value_, value2_)
+ end
+
+
+ # Test marshalling
+
+ def test_marshal
+ value_ = ::Versionomy.create(:major => 1, :minor => 9, :tiny => 2, :release_type => :alpha, :alpha_version => 4)
+ str_ = ::Marshal.dump(value_)
+ value2_ = ::Marshal.load(str_)
+ assert_equal(value_, value2_)
+ end
+
+
+ # Test YAML
+
+ def test_yaml
+ value_ = ::Versionomy.create(:major => 1, :minor => 9, :tiny => 2, :release_type => :alpha, :alpha_version => 4)
+ str_ = ::YAML.dump(value_)
+ value2_ = ::YAML.load(str_)
+ assert_equal(value_, value2_)
+ end
+
+
+ end
+
+ end
+end
View
59 tests/tc_standard_parse.rb
@@ -36,19 +36,19 @@
require 'test/unit'
-require File.expand_path("#{File.dirname(__FILE__)}/../lib/versionomy.rb")
+require ::File.expand_path("#{::File.dirname(__FILE__)}/../lib/versionomy.rb")
module Versionomy
module Tests # :nodoc:
- class TestStandardParse < Test::Unit::TestCase # :nodoc:
+ class TestStandardParse < ::Test::Unit::TestCase # :nodoc:
# Test parsing full.
def test_parsing_full_release
- value_ = Versionomy.parse('2.0.1.1-4.6')
+ value_ = ::Versionomy.parse('2.0.1.1-4.6')
assert_equal(2, value_.major)
assert_equal(0, value_.minor)
assert_equal(1, value_.tiny)
@@ -63,7 +63,7 @@ def test_parsing_full_release
# Test parsing abbreviated.
def test_parsing_abbrev_release
- value_ = Versionomy.parse('2.0.1')
+ value_ = ::Versionomy.parse('2.0.1')
assert_equal(2, value_.major)
assert_equal(0, value_.minor)
assert_equal(1, value_.tiny)
@@ -80,7 +80,7 @@ def test_parsing_abbrev_release
# Test parsing with trailing zeros.
def test_parsing_trailing_zeros
- value_ = Versionomy.parse('2.0.0')
+ value_ = ::Versionomy.parse('2.0.0')
assert_equal(2, value_.major)
assert_equal(0, value_.minor)
assert_equal(0, value_.tiny)
@@ -95,7 +95,7 @@ def test_parsing_trailing_zeros
# Test parsing preview.
def test_parsing_preview
- value_ = Versionomy.parse('2.0.1pre4')
+ value_ = ::Versionomy.parse('2.0.1pre4')
assert_equal(2, value_.major)
assert_equal(0, value_.minor)
assert_equal(1, value_.tiny)
@@ -111,7 +111,7 @@ def test_parsing_preview
# Test parsing alpha.
def test_parsing_alpha
- value_ = Versionomy.parse('2.0.1a4.1')
+ value_ = ::Versionomy.parse('2.0.1a4.1')
assert_equal(2, value_.major)
assert_equal(0, value_.minor)
assert_equal(1, value_.tiny)
@@ -127,7 +127,7 @@ def test_parsing_alpha
# Test parsing beta.
def test_parsing_beta
- value_ = Versionomy.parse('2.52.1b4.0')
+ value_ = ::Versionomy.parse('2.52.1b4.0')
assert_equal(2, value_.major)
assert_equal(52, value_.minor)
assert_equal(1, value_.tiny)
@@ -143,20 +143,20 @@ def test_parsing_beta
# Test parsing beta alternates
def test_parsing_beta_alternates
- assert_equal(Versionomy.parse('2.52.1 beta4'), '2.52.1b4')
- assert_equal(Versionomy.parse('2.52.1-b4'), '2.52.1b4')
- assert_equal(Versionomy.parse('2.52.1.b4'), '2.52.1b4')
- assert_equal(Versionomy.parse('2.52.1B4'), '2.52.1b4')
- 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'), '2.52.1')
+ assert_equal(::Versionomy.parse('2.52.1 beta4'), '2.52.1b4')
+ assert_equal(::Versionomy.parse('2.52.1-b4'), '2.52.1b4')
+ assert_equal(::Versionomy.parse('2.52.1.b4'), '2.52.1b4')
+ assert_equal(::Versionomy.parse('2.52.1B4'), '2.52.1b4')
+ 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')
end
# Test parsing release candidate.
def test_parsing_release_candidate
- value_ = Versionomy.parse('0.2rc0')
+ value_ = ::Versionomy.parse('0.2rc0')
assert_equal(0, value_.major)
assert_equal(2, value_.minor)
assert_equal(0, value_.tiny)
@@ -173,7 +173,7 @@ def test_parsing_release_candidate
# Test unparsing a value that requires lookback.
def test_unparsing_with_lookback
- value_ = Versionomy.parse('2.0')
+ value_ = ::Versionomy.parse('2.0')
value2_ = value_.change(:tiny2 => 1)
assert_equal(1, value2_.tiny2)
assert_equal('2.0.0.1', value2_.unparse)
@@ -186,7 +186,7 @@ def test_unparsing_with_lookback
# Test delimiter changes in a multi-form field.
def test_multi_form_delimiter_changes
- value_ = Versionomy.parse('2.0 preview 1')
+ value_ = ::Versionomy.parse('2.0 preview 1')
assert_equal('2.0 preview 1', value_.to_s)
value2_ = value_.change(:release_type => :final)
assert_equal('2.0', value2_.to_s)
@@ -199,25 +199,34 @@ def test_multi_form_delimiter_changes
def test_patchlevel_separators
expected_ = [1,9,1,0,:final,243,0]
- assert_equal(expected_, Versionomy.parse('1.9.1-p243').values_array)
- assert_equal(expected_, Versionomy.parse('1.9.1p243').values_array)
- assert_equal(expected_, Versionomy.parse('1.9.1.p243').values_array)
- assert_equal(expected_, Versionomy.parse('1.9.1 p243').values_array)
- assert_equal(expected_, Versionomy.parse('1.9.1-243').values_array)
+ assert_equal(expected_, ::Versionomy.parse('1.9.1-p243').values_array)
+ assert_equal(expected_, ::Versionomy.parse('1.9.1p243').values_array)
+ assert_equal(expected_, ::Versionomy.parse('1.9.1.p243').values_array)
+ assert_equal(expected_, ::Versionomy.parse('1.9.1 p243').values_array)
+ assert_equal(expected_, ::Versionomy.parse('1.9.1-243').values_array)
end
# Test setting delimiters on unparse, including testing for illegal delimiters
def test_unparse_with_custom_delimiters
- value_ = Versionomy.parse('1.2b3')
+ 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 => '*'))
- value_ = Versionomy.parse('1.2-4')
+ value_ = ::Versionomy.parse('1.2-4')
assert_equal('1.2-4', value_.unparse(:release_type_delim => '.', :release_type_postdelim => '.'))
end
+ # Test parse errors
+
+ def test_parsing_errors
+ assert_raise(::Versionomy::Errors::ParseError) do
+ ::Versionomy.parse('2.52.1 eta4')
+ end
+ end
+
+
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.