versionomy 0.4.1 → 0.4.2
Sign up to get free protection for your applications and to get access to all the features.
- data/History.rdoc +4 -0
- data/Version +1 -1
- data/lib/versionomy.rb +19 -25
- data/lib/versionomy/conversion.rb +41 -41
- data/lib/versionomy/conversion/base.rb +31 -31
- data/lib/versionomy/conversion/parsing.rb +49 -49
- data/lib/versionomy/errors.rb +63 -63
- data/lib/versionomy/format.rb +51 -51
- data/lib/versionomy/format/base.rb +44 -44
- data/lib/versionomy/format/delimiter.rb +205 -205
- data/lib/versionomy/format_definitions/rubygems.rb +85 -85
- data/lib/versionomy/format_definitions/semver.rb +78 -78
- data/lib/versionomy/format_definitions/standard.rb +68 -68
- data/lib/versionomy/interface.rb +46 -46
- data/lib/versionomy/schema.rb +21 -21
- data/lib/versionomy/schema/field.rb +112 -112
- data/lib/versionomy/schema/wrapper.rb +91 -91
- data/lib/versionomy/value.rb +224 -180
- data/lib/versionomy/version.rb +9 -9
- data/test/tc_custom_format.rb +14 -14
- data/test/tc_readme_examples.rb +24 -24
- data/test/tc_rubygems_basic.rb +68 -68
- data/test/tc_rubygems_conversions.rb +46 -46
- data/test/tc_semver_basic.rb +62 -62
- data/test/tc_semver_conversions.rb +52 -52
- data/test/tc_standard_basic.rb +35 -35
- data/test/tc_standard_bump.rb +35 -35
- data/test/tc_standard_change.rb +20 -20
- data/test/tc_standard_comparison.rb +38 -38
- data/test/tc_standard_misc.rb +23 -23
- data/test/tc_standard_parse.rb +77 -77
- data/test/tc_standard_reset.rb +29 -29
- data/test/tc_version_of.rb +15 -15
- metadata +30 -34
@@ -1,17 +1,17 @@
|
|
1
1
|
# -----------------------------------------------------------------------------
|
2
|
-
#
|
2
|
+
#
|
3
3
|
# Versionomy tests on rubygems schema conversions
|
4
|
-
#
|
4
|
+
#
|
5
5
|
# This file contains tests converting to and from the rubygems schema
|
6
|
-
#
|
6
|
+
#
|
7
7
|
# -----------------------------------------------------------------------------
|
8
8
|
# Copyright 2008-2009 Daniel Azuma
|
9
|
-
#
|
9
|
+
#
|
10
10
|
# All rights reserved.
|
11
|
-
#
|
11
|
+
#
|
12
12
|
# Redistribution and use in source and binary forms, with or without
|
13
13
|
# modification, are permitted provided that the following conditions are met:
|
14
|
-
#
|
14
|
+
#
|
15
15
|
# * Redistributions of source code must retain the above copyright notice,
|
16
16
|
# this list of conditions and the following disclaimer.
|
17
17
|
# * Redistributions in binary form must reproduce the above copyright notice,
|
@@ -20,7 +20,7 @@
|
|
20
20
|
# * Neither the name of the copyright holder, nor the names of any other
|
21
21
|
# contributors to this software, may be used to endorse or promote products
|
22
22
|
# derived from this software without specific prior written permission.
|
23
|
-
#
|
23
|
+
#
|
24
24
|
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
25
25
|
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
26
26
|
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
@@ -41,18 +41,18 @@ require 'versionomy'
|
|
41
41
|
|
42
42
|
module Versionomy
|
43
43
|
module Tests # :nodoc:
|
44
|
-
|
44
|
+
|
45
45
|
class TestRubygemsConversions < ::Test::Unit::TestCase # :nodoc:
|
46
|
-
|
47
|
-
|
46
|
+
|
47
|
+
|
48
48
|
def setup
|
49
49
|
@standard_format = Format.get(:standard)
|
50
50
|
@rubygems_format = Format.get(:rubygems)
|
51
51
|
end
|
52
|
-
|
53
|
-
|
52
|
+
|
53
|
+
|
54
54
|
# Test simple conversion from standard to rubygems.
|
55
|
-
|
55
|
+
|
56
56
|
def test_standard_to_rubygems_simple
|
57
57
|
value_ = ::Versionomy.parse('1.2')
|
58
58
|
value2_ = value_.convert(:rubygems)
|
@@ -63,10 +63,10 @@ module Versionomy
|
|
63
63
|
assert_equal(@rubygems_format, value2_.format)
|
64
64
|
assert_equal([1, 2, 4, 1, 0, 0, 0, 0], value2_.values_array)
|
65
65
|
end
|
66
|
-
|
67
|
-
|
66
|
+
|
67
|
+
|
68
68
|
# Test conversion from standard to rubygems including a patchlevel
|
69
|
-
|
69
|
+
|
70
70
|
def test_standard_to_rubygems_with_patchlevel
|
71
71
|
value_ = ::Versionomy.parse('1.2-3')
|
72
72
|
value2_ = value_.convert(:rubygems)
|
@@ -78,10 +78,10 @@ module Versionomy
|
|
78
78
|
value2_ = value_.convert(:rubygems)
|
79
79
|
assert_equal([1, 2, 3, 0, 0, 0, 0, 0], value2_.values_array)
|
80
80
|
end
|
81
|
-
|
82
|
-
|
81
|
+
|
82
|
+
|
83
83
|
# Test conversion from standard to rubygems with a beta version
|
84
|
-
|
84
|
+
|
85
85
|
def test_standard_to_rubygems_beta
|
86
86
|
value_ = ::Versionomy.parse('1.2b3')
|
87
87
|
value2_ = value_.convert(:rubygems)
|
@@ -90,10 +90,10 @@ module Versionomy
|
|
90
90
|
value2_ = value_.convert(:rubygems)
|
91
91
|
assert_equal([1, 2, 'beta', 3, 4, 0, 0, 0], value2_.values_array)
|
92
92
|
end
|
93
|
-
|
94
|
-
|
93
|
+
|
94
|
+
|
95
95
|
# Test conversion from standard to rubygems with a "v" prefix
|
96
|
-
|
96
|
+
|
97
97
|
def test_standard_to_rubygems_with_v
|
98
98
|
value_ = ::Versionomy.parse('v1.2b3')
|
99
99
|
value2_ = value_.convert(:rubygems)
|
@@ -102,10 +102,10 @@ module Versionomy
|
|
102
102
|
value2_ = value_.convert(:rubygems)
|
103
103
|
assert_equal([1, 2, 'b', 3, 0, 0, 0, 0], value2_.values_array)
|
104
104
|
end
|
105
|
-
|
106
|
-
|
105
|
+
|
106
|
+
|
107
107
|
# Test simple conversion from rubygems to standard.
|
108
|
-
|
108
|
+
|
109
109
|
def test_rubygems_to_standard_simple
|
110
110
|
value_ = ::Versionomy.parse('1.2', :rubygems)
|
111
111
|
value2_ = value_.convert(:standard)
|
@@ -116,10 +116,10 @@ module Versionomy
|
|
116
116
|
assert_equal(@standard_format, value2_.format)
|
117
117
|
assert_equal([1, 2, 4, 1, :final, 0, 0], value2_.values_array)
|
118
118
|
end
|
119
|
-
|
120
|
-
|
119
|
+
|
120
|
+
|
121
121
|
# Test conversion from rubygems to standard with a beta version
|
122
|
-
|
122
|
+
|
123
123
|
def test_rubygems_to_standard_beta
|
124
124
|
value_ = ::Versionomy.parse('1.2.b.3', :rubygems)
|
125
125
|
value2_ = value_.convert(:standard)
|
@@ -134,10 +134,10 @@ module Versionomy
|
|
134
134
|
value2_ = value_.convert(:standard)
|
135
135
|
assert_equal([1, 2, 0, 0, :beta, 0, 0], value2_.values_array)
|
136
136
|
end
|
137
|
-
|
138
|
-
|
137
|
+
|
138
|
+
|
139
139
|
# Test conversion from rubygems to standard with an expectation of failure
|
140
|
-
|
140
|
+
|
141
141
|
def test_rubygems_to_standard_fail
|
142
142
|
value_ = ::Versionomy.parse('1.2.b.3.4.5', :rubygems)
|
143
143
|
assert_raise(::Versionomy::Errors::ConversionError) do
|
@@ -148,43 +148,43 @@ module Versionomy
|
|
148
148
|
value2_ = value_.convert(:standard)
|
149
149
|
end
|
150
150
|
end
|
151
|
-
|
152
|
-
|
151
|
+
|
152
|
+
|
153
153
|
# Test equality comparisons between rubygems and standard
|
154
|
-
|
154
|
+
|
155
155
|
def test_rubygems_to_standard_equality_comparison
|
156
156
|
assert_operator(::Versionomy.parse('1.2.0', :rubygems), :==, ::Versionomy.parse('1.2'))
|
157
157
|
assert_operator(::Versionomy.parse('1.2.b.3', :rubygems), :==, ::Versionomy.parse('1.2b3'))
|
158
158
|
end
|
159
|
-
|
160
|
-
|
159
|
+
|
160
|
+
|
161
161
|
# Test inequality comparisons between rubygems and standard
|
162
|
-
|
162
|
+
|
163
163
|
def test_rubygems_to_standard_inequality_comparison
|
164
164
|
assert_operator(::Versionomy.parse('1.2.3', :rubygems), :<, ::Versionomy.parse('1.2.4'))
|
165
165
|
assert_operator(::Versionomy.parse('1.2.b.3', :rubygems), :>, ::Versionomy.parse('1.2b2'))
|
166
166
|
assert_operator(::Versionomy.parse('1.2', :rubygems), :>, ::Versionomy.parse('1.2b1'))
|
167
167
|
end
|
168
|
-
|
169
|
-
|
168
|
+
|
169
|
+
|
170
170
|
# Test equality comparisons between standard and rubygems
|
171
|
-
|
171
|
+
|
172
172
|
def test_standard_to_rubygems_equality_comparison
|
173
173
|
assert_operator(::Versionomy.parse('1.2.0'), :==, ::Versionomy.parse('1.2', :rubygems))
|
174
174
|
assert_operator(::Versionomy.parse('1.2b3'), :==, ::Versionomy.parse('1.2.beta.3', :rubygems))
|
175
175
|
end
|
176
|
-
|
177
|
-
|
176
|
+
|
177
|
+
|
178
178
|
# Test inequality comparisons between standard and rubygems
|
179
|
-
|
179
|
+
|
180
180
|
def test_standard_to_rubygems_inequality_comparison
|
181
181
|
assert_operator(::Versionomy.parse('1.2.4'), :>, ::Versionomy.parse('1.2.3', :rubygems))
|
182
182
|
assert_operator(::Versionomy.parse('1.2b2'), :<, ::Versionomy.parse('1.2.beta.3', :rubygems))
|
183
183
|
assert_operator(::Versionomy.parse('1.2b2'), :<, ::Versionomy.parse('1.2', :rubygems))
|
184
184
|
end
|
185
|
-
|
186
|
-
|
185
|
+
|
186
|
+
|
187
187
|
end
|
188
|
-
|
188
|
+
|
189
189
|
end
|
190
190
|
end
|
data/test/tc_semver_basic.rb
CHANGED
@@ -1,17 +1,17 @@
|
|
1
1
|
# -----------------------------------------------------------------------------
|
2
|
-
#
|
2
|
+
#
|
3
3
|
# Versionomy basic tests on rubygems schema
|
4
|
-
#
|
4
|
+
#
|
5
5
|
# This file contains tests for the basic use cases on the rubygems schema
|
6
|
-
#
|
6
|
+
#
|
7
7
|
# -----------------------------------------------------------------------------
|
8
8
|
# Copyright 2008-2009 Daniel Azuma
|
9
|
-
#
|
9
|
+
#
|
10
10
|
# All rights reserved.
|
11
|
-
#
|
11
|
+
#
|
12
12
|
# Redistribution and use in source and binary forms, with or without
|
13
13
|
# modification, are permitted provided that the following conditions are met:
|
14
|
-
#
|
14
|
+
#
|
15
15
|
# * Redistributions of source code must retain the above copyright notice,
|
16
16
|
# this list of conditions and the following disclaimer.
|
17
17
|
# * Redistributions in binary form must reproduce the above copyright notice,
|
@@ -20,7 +20,7 @@
|
|
20
20
|
# * Neither the name of the copyright holder, nor the names of any other
|
21
21
|
# contributors to this software, may be used to endorse or promote products
|
22
22
|
# derived from this software without specific prior written permission.
|
23
|
-
#
|
23
|
+
#
|
24
24
|
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
25
25
|
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
26
26
|
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
@@ -41,12 +41,12 @@ require 'versionomy'
|
|
41
41
|
|
42
42
|
module Versionomy
|
43
43
|
module Tests # :nodoc:
|
44
|
-
|
44
|
+
|
45
45
|
class TestSemverBasic < ::Test::Unit::TestCase # :nodoc:
|
46
|
-
|
47
|
-
|
46
|
+
|
47
|
+
|
48
48
|
# Test the default version value.
|
49
|
-
|
49
|
+
|
50
50
|
def test_default_value
|
51
51
|
value_ = ::Versionomy.create(nil, :semver)
|
52
52
|
assert_equal(1, value_.major)
|
@@ -54,10 +54,10 @@ module Versionomy
|
|
54
54
|
assert_equal(0, value_.patch)
|
55
55
|
assert_equal('', value_.prerelease_suffix)
|
56
56
|
end
|
57
|
-
|
58
|
-
|
57
|
+
|
58
|
+
|
59
59
|
# Test an arbitrary value.
|
60
|
-
|
60
|
+
|
61
61
|
def test_arbitrary_value
|
62
62
|
value_ = ::Versionomy.create([1, 9, 2, 'pre2'], :semver)
|
63
63
|
assert_equal(1, value_.major)
|
@@ -65,26 +65,26 @@ module Versionomy
|
|
65
65
|
assert_equal(2, value_.patch)
|
66
66
|
assert_equal('pre2', value_.prerelease_suffix)
|
67
67
|
end
|
68
|
-
|
69
|
-
|
68
|
+
|
69
|
+
|
70
70
|
# Test aliases
|
71
|
-
|
71
|
+
|
72
72
|
def test_alias_fields
|
73
73
|
value_ = ::Versionomy.create([1, 9, 2, 'pre2'], :semver)
|
74
74
|
assert_equal('pre2', value_.special_suffix)
|
75
75
|
end
|
76
|
-
|
77
|
-
|
76
|
+
|
77
|
+
|
78
78
|
# Test construction using aliases
|
79
|
-
|
79
|
+
|
80
80
|
def test_alias_field_construction
|
81
81
|
value_ = ::Versionomy.create({:major => 1, :minor => 9, :special_suffix => 'pre2'}, :semver)
|
82
82
|
assert_equal([1, 9, 0, 'pre2'], value_.values_array)
|
83
83
|
end
|
84
|
-
|
85
|
-
|
84
|
+
|
85
|
+
|
86
86
|
# Test comparison of numeric values.
|
87
|
-
|
87
|
+
|
88
88
|
def test_numeric_comparison
|
89
89
|
value1_ = ::Versionomy.create([1, 9, 2], :semver)
|
90
90
|
value2_ = ::Versionomy.create([1, 9], :semver)
|
@@ -93,46 +93,46 @@ module Versionomy
|
|
93
93
|
value2_ = ::Versionomy.create([1, 9], :semver)
|
94
94
|
assert(value2_ == value1_)
|
95
95
|
end
|
96
|
-
|
97
|
-
|
96
|
+
|
97
|
+
|
98
98
|
# Test comparison of string values.
|
99
|
-
|
99
|
+
|
100
100
|
def test_string_comparison
|
101
101
|
value1_ = ::Versionomy.create([1, 9, 2, 'a2'], :semver)
|
102
102
|
value2_ = ::Versionomy.create([1, 9, 2, 'b1'], :semver)
|
103
103
|
assert(value2_ > value1_)
|
104
104
|
end
|
105
|
-
|
106
|
-
|
105
|
+
|
106
|
+
|
107
107
|
# Test comparison of numeric and string values.
|
108
|
-
|
108
|
+
|
109
109
|
def test_numeric_and_string_comparison
|
110
110
|
value1_ = ::Versionomy.create([1, 9, 2, 'a2'], :semver)
|
111
111
|
value2_ = ::Versionomy.create([1, 9, 2], :semver)
|
112
112
|
assert(value2_ > value1_)
|
113
113
|
end
|
114
|
-
|
115
|
-
|
114
|
+
|
115
|
+
|
116
116
|
# Test parsing numeric.
|
117
|
-
|
117
|
+
|
118
118
|
def test_parsing_numeric
|
119
119
|
value_ = ::Versionomy.parse('2.0.1', :semver)
|
120
120
|
assert_equal([2, 0, 1, ''], value_.values_array)
|
121
121
|
assert_equal('2.0.1', value_.unparse)
|
122
122
|
end
|
123
|
-
|
124
|
-
|
123
|
+
|
124
|
+
|
125
125
|
# Test parsing with a string.
|
126
|
-
|
126
|
+
|
127
127
|
def test_parsing_with_string
|
128
128
|
value_ = ::Versionomy.parse('1.9.2pre2', :semver)
|
129
129
|
assert_equal([1, 9, 2, 'pre2'], value_.values_array)
|
130
130
|
assert_equal('1.9.2pre2', value_.unparse)
|
131
131
|
end
|
132
|
-
|
133
|
-
|
132
|
+
|
133
|
+
|
134
134
|
# Test making sure unparsing requires all three fields.
|
135
|
-
|
135
|
+
|
136
136
|
def test_parsing_require_all_fields
|
137
137
|
value_ = ::Versionomy.parse('2.0', :semver)
|
138
138
|
assert_equal([2, 0, 0, ''], value_.values_array)
|
@@ -141,73 +141,73 @@ module Versionomy
|
|
141
141
|
value_ = ::Versionomy.parse('2.0b1', :semver)
|
142
142
|
end
|
143
143
|
end
|
144
|
-
|
145
|
-
|
144
|
+
|
145
|
+
|
146
146
|
# Test convenience parsing
|
147
|
-
|
147
|
+
|
148
148
|
def test_convenience_parse
|
149
149
|
value_ = ::Versionomy.semver('2.0.1')
|
150
150
|
assert_equal([2, 0, 1, ''], value_.values_array)
|
151
151
|
end
|
152
|
-
|
153
|
-
|
152
|
+
|
153
|
+
|
154
154
|
# Test convenience creation from hash
|
155
|
-
|
155
|
+
|
156
156
|
def test_convenience_create
|
157
157
|
value_ = ::Versionomy.semver(:major => 2, :patch => 1, :prerelease_suffix => 'b2')
|
158
158
|
assert_equal([2, 0, 1, 'b2'], value_.values_array)
|
159
159
|
end
|
160
|
-
|
161
|
-
|
160
|
+
|
161
|
+
|
162
162
|
# Test bumping a numeric field.
|
163
|
-
|
163
|
+
|
164
164
|
def test_bump_numeric
|
165
165
|
value_ = ::Versionomy.create([1, 9, 2, 'a2'], :semver)
|
166
166
|
value_ = value_.bump(:patch)
|
167
167
|
assert_equal([1, 9, 3, ''], value_.values_array)
|
168
168
|
end
|
169
|
-
|
170
|
-
|
169
|
+
|
170
|
+
|
171
171
|
# Test bumping a string field.
|
172
|
-
|
172
|
+
|
173
173
|
def test_bump_string
|
174
174
|
value_ = ::Versionomy.create([1, 9, 2, 'a2'], :semver)
|
175
175
|
value_ = value_.bump(:prerelease_suffix)
|
176
176
|
assert_equal([1, 9, 2, 'a3'], value_.values_array)
|
177
177
|
end
|
178
|
-
|
179
|
-
|
178
|
+
|
179
|
+
|
180
180
|
# Test "prerelase?" custom method
|
181
|
-
|
181
|
+
|
182
182
|
def test_method_prereleasep
|
183
183
|
value_ = ::Versionomy.create([1, 9, 2, 'a2'], :semver)
|
184
184
|
assert_equal(true, value_.prerelease?)
|
185
185
|
value_ = ::Versionomy.create([1, 9, 2], :semver)
|
186
186
|
assert_equal(false, value_.prerelease?)
|
187
187
|
end
|
188
|
-
|
189
|
-
|
188
|
+
|
189
|
+
|
190
190
|
# Test marshalling
|
191
|
-
|
191
|
+
|
192
192
|
def test_marshal
|
193
193
|
value_ = ::Versionomy.create([1, 9, 2, 'pre2'], :semver)
|
194
194
|
str_ = ::Marshal.dump(value_)
|
195
195
|
value2_ = ::Marshal.load(str_)
|
196
196
|
assert_equal(value_, value2_)
|
197
197
|
end
|
198
|
-
|
199
|
-
|
198
|
+
|
199
|
+
|
200
200
|
# Test YAML
|
201
|
-
|
201
|
+
|
202
202
|
def test_yaml
|
203
203
|
value_ = ::Versionomy.create([1, 9, 2, 'pre2'], :semver)
|
204
204
|
str_ = ::YAML.dump(value_)
|
205
205
|
value2_ = ::YAML.load(str_)
|
206
206
|
assert_equal(value_, value2_)
|
207
207
|
end
|
208
|
-
|
209
|
-
|
208
|
+
|
209
|
+
|
210
210
|
end
|
211
|
-
|
211
|
+
|
212
212
|
end
|
213
213
|
end
|