parent
92ac63fd94
commit
0f5a80a97b
@ -2,6 +2,8 @@ require 'testing_env'
|
|||||||
require 'version'
|
require 'version'
|
||||||
|
|
||||||
class VersionTests < Test::Unit::TestCase
|
class VersionTests < Test::Unit::TestCase
|
||||||
|
include VersionAssertions
|
||||||
|
|
||||||
def test_accepts_objects_responding_to_to_str
|
def test_accepts_objects_responding_to_to_str
|
||||||
value = stub(:to_str => '0.1')
|
value = stub(:to_str => '0.1')
|
||||||
assert_equal '0.1', Version.new(value).to_s
|
assert_equal '0.1', Version.new(value).to_s
|
||||||
@ -12,6 +14,18 @@ class VersionTests < Test::Unit::TestCase
|
|||||||
assert_raises(TypeError) { Version.new(1) }
|
assert_raises(TypeError) { Version.new(1) }
|
||||||
assert_raises(TypeError) { Version.new(:symbol) }
|
assert_raises(TypeError) { Version.new(:symbol) }
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_tokens
|
||||||
|
assert_version_tokens %w{1 0 z23}, version('1.0z23')
|
||||||
|
assert_version_tokens %w{1 0 z23}, version('1.0.z23')
|
||||||
|
assert_version_tokens %w{1 0 z 23}, version('1.0.z.23')
|
||||||
|
assert_version_tokens %w{1 0 23 z}, version('1.0.23z')
|
||||||
|
assert_version_tokens %w{1 0 23 z}, version('1.0.23.z')
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_openssl_style_tokenization
|
||||||
|
assert_version_tokens %w{1 0 1 f}, version('1.0.1f')
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
class VersionComparisonTests < Test::Unit::TestCase
|
class VersionComparisonTests < Test::Unit::TestCase
|
||||||
|
@ -97,6 +97,10 @@ module VersionAssertions
|
|||||||
def assert_version_nil url
|
def assert_version_nil url
|
||||||
assert_nil Version.parse(url)
|
assert_nil Version.parse(url)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def assert_version_tokens tokens, version
|
||||||
|
assert_equal tokens, version.send(:tokens).map(&:to_s)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
module Test::Unit::Assertions
|
module Test::Unit::Assertions
|
||||||
|
@ -43,7 +43,7 @@ class Version
|
|||||||
NULL_TOKEN = NullToken.new
|
NULL_TOKEN = NullToken.new
|
||||||
|
|
||||||
class StringToken < Token
|
class StringToken < Token
|
||||||
PATTERN = /[a-z]+[0-9]+/i
|
PATTERN = /[a-z]+[0-9]*/i
|
||||||
|
|
||||||
def initialize(value)
|
def initialize(value)
|
||||||
@value = value.to_s
|
@value = value.to_s
|
||||||
|
Loading…
x
Reference in New Issue
Block a user