ruby-libversion 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +10 -0
- data/LICENSE +21 -0
- data/README.md +3 -0
- data/Rakefile +8 -0
- data/ext/libversion/extconf.rb +5 -0
- data/ext/libversion/libversion.c +20 -0
- data/lib/libversion.rb +1 -0
- data/ruby-libversion.gemspec +11 -0
- data/test/test_ruby_libversion.rb +343 -0
- metadata +52 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: c2aaf113a6cb56ae52674d46944ae80b6f563ff7c4652a510c1c0f32bccd6ada
|
4
|
+
data.tar.gz: d7601cfdbf8412d5a8e59177881b1b985a077ddd537eda12e980ec8a93dc8fbc
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 4cbc1439eff77ecda561b19e5eba5d3dc5729f813fba77794f3d24e3a351ac0c98f26d56b6b26bd3e2c9453dd0b3b133e05897e7ac15628833c9e8f2bfa36b0c
|
7
|
+
data.tar.gz: 3a83fdde12a0e61efddd341b181c8d33465cb869594df76d382aa0040f5b5a790b947f180bc387d15ed74f25092f31b4a902b076cbe3e79aef6e34928bb33244
|
data/.gitignore
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2024 Maximilian Downey Twiss
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
data/README.md
ADDED
data/Rakefile
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
#include "ruby.h"
|
2
|
+
#include "libversion/version.h"
|
3
|
+
|
4
|
+
static VALUE rb_version_compare2(VALUE self, VALUE v1, VALUE v2) {
|
5
|
+
return INT2NUM(version_compare2(StringValueCStr(v1), StringValueCStr(v2)));
|
6
|
+
}
|
7
|
+
|
8
|
+
static VALUE rb_version_compare4(VALUE self, VALUE v1, VALUE v2, VALUE v1_flags, VALUE v2_flags) {
|
9
|
+
return INT2NUM(version_compare4(StringValueCStr(v1), StringValueCStr(v2), NUM2INT(v1_flags), NUM2INT(v2_flags)));
|
10
|
+
}
|
11
|
+
|
12
|
+
void Init_ruby_libversion(void) {
|
13
|
+
VALUE Libversion = rb_define_module("Libversion");
|
14
|
+
rb_define_singleton_method(Libversion, "version_compare2", rb_version_compare2, 2);
|
15
|
+
rb_define_singleton_method(Libversion, "version_compare4", rb_version_compare4, 4);
|
16
|
+
rb_define_const(Libversion, "VERSIONFLAG_P_IS_PATCH", INT2NUM(VERSIONFLAG_P_IS_PATCH));
|
17
|
+
rb_define_const(Libversion, "VERSIONFLAG_ANY_IS_PATCH", INT2NUM(VERSIONFLAG_ANY_IS_PATCH));
|
18
|
+
rb_define_const(Libversion, "VERSIONFLAG_LOWER_BOUND", INT2NUM(VERSIONFLAG_LOWER_BOUND));
|
19
|
+
rb_define_const(Libversion, "VERSIONFLAG_UPPER_BOUND", INT2NUM(VERSIONFLAG_UPPER_BOUND));
|
20
|
+
}
|
data/lib/libversion.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'libversion'
|
@@ -0,0 +1,11 @@
|
|
1
|
+
Gem::Specification.new do |spec|
|
2
|
+
spec.name = 'ruby-libversion'
|
3
|
+
spec.summary = 'Ruby bindings for libversion'
|
4
|
+
spec.version = '1.0.0'
|
5
|
+
spec.license = 'MIT'
|
6
|
+
spec.author = 'Maximilian Downey Twiss'
|
7
|
+
spec.email = 'creatorsmithmdt@.com'
|
8
|
+
spec.homepage = 'https://github.com/Zopolis4/ruby-libversion'
|
9
|
+
spec.files = `git ls-files`.split("\n")
|
10
|
+
spec.extensions = 'ext/libversion/extconf.rb'
|
11
|
+
end
|
@@ -0,0 +1,343 @@
|
|
1
|
+
require 'minitest/autorun'
|
2
|
+
require 'ruby_libversion'
|
3
|
+
|
4
|
+
# These test cases are taken from here:
|
5
|
+
# https://github.com/repology/libversion/blob/master/tests/compare_test.c
|
6
|
+
# The copyright notice from that file is reproduced here:
|
7
|
+
# Copyright (c)) 2017-2018 Dmitry Marakasov <amdmi3@amdmi3.ru>
|
8
|
+
class RubyLibversionTest < Minitest::Test
|
9
|
+
def test_equality
|
10
|
+
assert_equal(0, Libversion.version_compare2('0', '0'))
|
11
|
+
assert_equal(0, Libversion.version_compare2('0', '0'))
|
12
|
+
assert_equal(0, Libversion.version_compare2('0a', '0a'))
|
13
|
+
assert_equal(0, Libversion.version_compare2('a', 'a'))
|
14
|
+
assert_equal(0, Libversion.version_compare2('a0', 'a0'))
|
15
|
+
assert_equal(0, Libversion.version_compare2('0a1', '0a1'))
|
16
|
+
assert_equal(0, Libversion.version_compare2('0a1b2', '0a1b2'))
|
17
|
+
assert_equal(0, Libversion.version_compare2('1alpha1', '1alpha1'))
|
18
|
+
assert_equal(0, Libversion.version_compare2('foo', 'foo'))
|
19
|
+
assert_equal(0, Libversion.version_compare2('1.2.3', '1.2.3'))
|
20
|
+
assert_equal(0, Libversion.version_compare2('hello.world', 'hello.world'))
|
21
|
+
end
|
22
|
+
|
23
|
+
def test_different_number_of_components
|
24
|
+
assert_equal(0, Libversion.version_compare2('1', '1.0'))
|
25
|
+
assert_equal(0, Libversion.version_compare2('1', '1.0.0'))
|
26
|
+
assert_equal(0, Libversion.version_compare2('1.0', '1.0.0'))
|
27
|
+
assert_equal(0, Libversion.version_compare2('1.0', '1.0.0.0.0.0.0.0'))
|
28
|
+
end
|
29
|
+
|
30
|
+
def test_leading_zeroes
|
31
|
+
assert_equal(0, Libversion.version_compare2('00100.00100', '100.100'))
|
32
|
+
assert_equal(0, Libversion.version_compare2('0', '00000000000000000'))
|
33
|
+
end
|
34
|
+
|
35
|
+
def test_simple_comparisons
|
36
|
+
assert_equal(-1, Libversion.version_compare2('0.0.0', '0.0.1'))
|
37
|
+
assert_equal(-1, Libversion.version_compare2('0.0.1', '0.0.2'))
|
38
|
+
assert_equal(-1, Libversion.version_compare2('0.0.2', '0.0.10'))
|
39
|
+
assert_equal(-1, Libversion.version_compare2('0.0.2', '0.1.0'))
|
40
|
+
assert_equal(-1, Libversion.version_compare2('0.0.10', '0.1.0'))
|
41
|
+
assert_equal(-1, Libversion.version_compare2('0.1.0', '0.1.1'))
|
42
|
+
assert_equal(-1, Libversion.version_compare2('0.1.1', '1.0.0'))
|
43
|
+
assert_equal(-1, Libversion.version_compare2('1.0.0', '10.0.0'))
|
44
|
+
assert_equal(-1, Libversion.version_compare2('10.0.0', '100.0.0'))
|
45
|
+
assert_equal(-1, Libversion.version_compare2('10.10000.10000', '11.0.0'))
|
46
|
+
end
|
47
|
+
|
48
|
+
def test_long_numbers
|
49
|
+
assert_equal(-1, Libversion.version_compare2('20160101', '20160102'))
|
50
|
+
assert_equal(-1, Libversion.version_compare2('999999999999999999', '1000000000000000000'))
|
51
|
+
end
|
52
|
+
|
53
|
+
def test_very_long_numbers
|
54
|
+
assert_equal(-1, Libversion.version_compare2('99999999999999999999999999999999999998', '99999999999999999999999999999999999999'))
|
55
|
+
end
|
56
|
+
|
57
|
+
def test_letter_addendum
|
58
|
+
assert_equal(-1, Libversion.version_compare2('1.0', '1.0a'))
|
59
|
+
assert_equal(-1, Libversion.version_compare2('1.0a', '1.0b'))
|
60
|
+
assert_equal(-1, Libversion.version_compare2('1.0b', '1.1'))
|
61
|
+
end
|
62
|
+
|
63
|
+
def test_letter_vs_number
|
64
|
+
assert_equal(-1, Libversion.version_compare2('a', '0'))
|
65
|
+
assert_equal(-1, Libversion.version_compare2('1.a', '1.0'))
|
66
|
+
end
|
67
|
+
|
68
|
+
def test_letter_only_component
|
69
|
+
assert_equal(-1, Libversion.version_compare2('1.0.a', '1.0.b'))
|
70
|
+
assert_equal(-1, Libversion.version_compare2('1.0.b', '1.0.c'))
|
71
|
+
assert_equal(-1, Libversion.version_compare2('1.0.c', '1.0'))
|
72
|
+
assert_equal(-1, Libversion.version_compare2('1.0.c', '1.0.0'))
|
73
|
+
end
|
74
|
+
|
75
|
+
def test_letter_component_split
|
76
|
+
assert_equal(0, Libversion.version_compare2('1.0a0', '1.0.a0'))
|
77
|
+
assert_equal(0, Libversion.version_compare2('1.0beta3', '1.0.b3'))
|
78
|
+
end
|
79
|
+
|
80
|
+
def test_ignore_case
|
81
|
+
assert_equal(0, Libversion.version_compare2('a', 'A'))
|
82
|
+
assert_equal(0, Libversion.version_compare2('1alpha', '1ALPHA'))
|
83
|
+
assert_equal(0, Libversion.version_compare2('alpha1', 'ALPHA1'))
|
84
|
+
end
|
85
|
+
|
86
|
+
def test_one_letter_string_shortening
|
87
|
+
assert_equal(0, Libversion.version_compare2('a', 'alpha'))
|
88
|
+
assert_equal(0, Libversion.version_compare2('b', 'beta'))
|
89
|
+
assert_equal(0, Libversion.version_compare2('p', 'prerelease'))
|
90
|
+
end
|
91
|
+
|
92
|
+
def test_unusual_component_separators
|
93
|
+
assert_equal(0, Libversion.version_compare2('1.0.alpha.2', '1_0_alpha_2'))
|
94
|
+
assert_equal(0, Libversion.version_compare2('1.0.alpha.2', '1-0-alpha-2'))
|
95
|
+
assert_equal(0, Libversion.version_compare2('1.0.alpha.2', '1,0:alpha~2'))
|
96
|
+
end
|
97
|
+
|
98
|
+
def test_multiple_consecutive_separators
|
99
|
+
assert_equal(0, Libversion.version_compare2('..1....2....3..', '1.2.3'))
|
100
|
+
assert_equal(0, Libversion.version_compare2('.-~1~-.-~2~-.', '1.2'))
|
101
|
+
assert_equal(0, Libversion.version_compare2('.,:;~+-_', '0'))
|
102
|
+
end
|
103
|
+
|
104
|
+
def test_empty_string
|
105
|
+
assert_equal(0, Libversion.version_compare2('', ''))
|
106
|
+
assert_equal(0, Libversion.version_compare2('', '0'))
|
107
|
+
assert_equal(-1, Libversion.version_compare2('', '1'))
|
108
|
+
end
|
109
|
+
|
110
|
+
def test_prerelease_sequence
|
111
|
+
assert_equal(-1, Libversion.version_compare2('1.0alpha1', '1.0alpha2'))
|
112
|
+
assert_equal(-1, Libversion.version_compare2('1.0alpha2', '1.0beta1'))
|
113
|
+
assert_equal(-1, Libversion.version_compare2('1.0beta1', '1.0beta2'))
|
114
|
+
assert_equal(-1, Libversion.version_compare2('1.0beta2', '1.0rc1'))
|
115
|
+
assert_equal(-1, Libversion.version_compare2('1.0beta2', '1.0pre1'))
|
116
|
+
assert_equal(-1, Libversion.version_compare2('1.0rc1', '1.0'))
|
117
|
+
assert_equal(-1, Libversion.version_compare2('1.0pre1', '1.0'))
|
118
|
+
|
119
|
+
assert_equal(-1, Libversion.version_compare2('1.0.alpha1', '1.0.alpha2'))
|
120
|
+
assert_equal(-1, Libversion.version_compare2('1.0.alpha2', '1.0.beta1'))
|
121
|
+
assert_equal(-1, Libversion.version_compare2('1.0.beta1', '1.0.beta2'))
|
122
|
+
assert_equal(-1, Libversion.version_compare2('1.0.beta2', '1.0.rc1'))
|
123
|
+
assert_equal(-1, Libversion.version_compare2('1.0.beta2', '1.0.pre1'))
|
124
|
+
assert_equal(-1, Libversion.version_compare2('1.0.rc1', '1.0'))
|
125
|
+
assert_equal(-1, Libversion.version_compare2('1.0.pre1', '1.0'))
|
126
|
+
|
127
|
+
assert_equal(-1, Libversion.version_compare2('1.0alpha.1', '1.0alpha.2'))
|
128
|
+
assert_equal(-1, Libversion.version_compare2('1.0alpha.2', '1.0beta.1'))
|
129
|
+
assert_equal(-1, Libversion.version_compare2('1.0beta.1', '1.0beta.2'))
|
130
|
+
assert_equal(-1, Libversion.version_compare2('1.0beta.2', '1.0rc.1'))
|
131
|
+
assert_equal(-1, Libversion.version_compare2('1.0beta.2', '1.0pre.1'))
|
132
|
+
assert_equal(-1, Libversion.version_compare2('1.0rc.1', '1.0'))
|
133
|
+
assert_equal(-1, Libversion.version_compare2('1.0pre.1', '1.0'))
|
134
|
+
|
135
|
+
assert_equal(-1, Libversion.version_compare2('1.0.alpha.1', '1.0.alpha.2'))
|
136
|
+
assert_equal(-1, Libversion.version_compare2('1.0.alpha.2', '1.0.beta.1'))
|
137
|
+
assert_equal(-1, Libversion.version_compare2('1.0.beta.1', '1.0.beta.2'))
|
138
|
+
assert_equal(-1, Libversion.version_compare2('1.0.beta.2', '1.0.rc.1'))
|
139
|
+
assert_equal(-1, Libversion.version_compare2('1.0.beta.2', '1.0.pre.1'))
|
140
|
+
assert_equal(-1, Libversion.version_compare2('1.0.rc.1', '1.0'))
|
141
|
+
assert_equal(-1, Libversion.version_compare2('1.0.pre.1', '1.0'))
|
142
|
+
end
|
143
|
+
|
144
|
+
def test_long_word_awareness
|
145
|
+
assert_equal(1, Libversion.version_compare2('1.0alpha-1', '0.9'))
|
146
|
+
assert_equal(-1, Libversion.version_compare2('1.0alpha-1', '1.0'))
|
147
|
+
assert_equal(-1, Libversion.version_compare2('1.0alpha-1', '1.0.1'))
|
148
|
+
assert_equal(-1, Libversion.version_compare2('1.0alpha-1', '1.1'))
|
149
|
+
|
150
|
+
assert_equal(1, Libversion.version_compare2('1.0beta-1', '0.9'))
|
151
|
+
assert_equal(-1, Libversion.version_compare2('1.0beta-1', '1.0'))
|
152
|
+
assert_equal(-1, Libversion.version_compare2('1.0beta-1', '1.0.1'))
|
153
|
+
assert_equal(-1, Libversion.version_compare2('1.0beta-1', '1.1'))
|
154
|
+
|
155
|
+
assert_equal(1, Libversion.version_compare2('1.0pre-1', '0.9'))
|
156
|
+
assert_equal(-1, Libversion.version_compare2('1.0pre-1', '1.0'))
|
157
|
+
assert_equal(-1, Libversion.version_compare2('1.0pre-1', '1.0.1'))
|
158
|
+
assert_equal(-1, Libversion.version_compare2('1.0pre-1', '1.1'))
|
159
|
+
|
160
|
+
assert_equal(1, Libversion.version_compare2('1.0prerelease-1', '0.9'))
|
161
|
+
assert_equal(-1, Libversion.version_compare2('1.0prerelease-1', '1.0'))
|
162
|
+
assert_equal(-1, Libversion.version_compare2('1.0prerelease-1', '1.0.1'))
|
163
|
+
assert_equal(-1, Libversion.version_compare2('1.0prerelease-1', '1.1'))
|
164
|
+
|
165
|
+
assert_equal(1, Libversion.version_compare2('1.0rc-1', '0.9'))
|
166
|
+
assert_equal(-1, Libversion.version_compare2('1.0rc-1', '1.0'))
|
167
|
+
assert_equal(-1, Libversion.version_compare2('1.0rc-1', '1.0.1'))
|
168
|
+
assert_equal(-1, Libversion.version_compare2('1.0rc-1', '1.1'))
|
169
|
+
end
|
170
|
+
|
171
|
+
def test_post_release_keyword_awareness
|
172
|
+
assert_equal(1, Libversion.version_compare2('1.0patch1', '0.9'))
|
173
|
+
assert_equal(1, Libversion.version_compare2('1.0patch1', '1.0'))
|
174
|
+
assert_equal(-1, Libversion.version_compare2('1.0patch1', '1.0.1'))
|
175
|
+
assert_equal(-1, Libversion.version_compare2('1.0patch1', '1.1'))
|
176
|
+
|
177
|
+
assert_equal(1, Libversion.version_compare2('1.0.patch1', '0.9'))
|
178
|
+
assert_equal(1, Libversion.version_compare2('1.0.patch1', '1.0'))
|
179
|
+
assert_equal(-1, Libversion.version_compare2('1.0.patch1', '1.0.1'))
|
180
|
+
assert_equal(-1, Libversion.version_compare2('1.0.patch1', '1.1'))
|
181
|
+
|
182
|
+
assert_equal(1, Libversion.version_compare2('1.0patch.1', '0.9'))
|
183
|
+
assert_equal(1, Libversion.version_compare2('1.0patch.1', '1.0'))
|
184
|
+
assert_equal(-1, Libversion.version_compare2('1.0patch.1', '1.0.1'))
|
185
|
+
assert_equal(-1, Libversion.version_compare2('1.0patch.1', '1.1'))
|
186
|
+
|
187
|
+
assert_equal(1, Libversion.version_compare2('1.0.patch.1', '0.9'))
|
188
|
+
assert_equal(1, Libversion.version_compare2('1.0.patch.1', '1.0'))
|
189
|
+
assert_equal(-1, Libversion.version_compare2('1.0.patch.1', '1.0.1'))
|
190
|
+
assert_equal(-1, Libversion.version_compare2('1.0.patch.1', '1.1'))
|
191
|
+
|
192
|
+
assert_equal(1, Libversion.version_compare2('1.0post1', '0.9'))
|
193
|
+
assert_equal(1, Libversion.version_compare2('1.0post1', '1.0'))
|
194
|
+
assert_equal(-1, Libversion.version_compare2('1.0post1', '1.0.1'))
|
195
|
+
assert_equal(-1, Libversion.version_compare2('1.0post1', '1.1'))
|
196
|
+
|
197
|
+
assert_equal(1, Libversion.version_compare2('1.0postanythinggoeshere1', '0.9'))
|
198
|
+
assert_equal(1, Libversion.version_compare2('1.0postanythinggoeshere1', '1.0'))
|
199
|
+
assert_equal(-1, Libversion.version_compare2('1.0postanythinggoeshere1', '1.0.1'))
|
200
|
+
assert_equal(-1, Libversion.version_compare2('1.0postanythinggoeshere1', '1.1'))
|
201
|
+
|
202
|
+
assert_equal(1, Libversion.version_compare2('1.0pl1', '0.9'))
|
203
|
+
assert_equal(1, Libversion.version_compare2('1.0pl1', '1.0'))
|
204
|
+
assert_equal(-1, Libversion.version_compare2('1.0pl1', '1.0.1'))
|
205
|
+
assert_equal(-1, Libversion.version_compare2('1.0pl1', '1.1'))
|
206
|
+
|
207
|
+
assert_equal(1, Libversion.version_compare2('1.0errata1', '0.9'))
|
208
|
+
assert_equal(1, Libversion.version_compare2('1.0errata1', '1.0'))
|
209
|
+
assert_equal(-1, Libversion.version_compare2('1.0errata1', '1.0.1'))
|
210
|
+
assert_equal(-1, Libversion.version_compare2('1.0errata1', '1.1'))
|
211
|
+
end
|
212
|
+
|
213
|
+
def test_p_is_patch_flag
|
214
|
+
assert_equal(0, Libversion.version_compare4('1.0p1', '1.0p1', 0, 0))
|
215
|
+
assert_equal(0, Libversion.version_compare4('1.0p1', '1.0p1', Libversion::VERSIONFLAG_P_IS_PATCH, Libversion::VERSIONFLAG_P_IS_PATCH))
|
216
|
+
assert_equal(1, Libversion.version_compare4('1.0p1', '1.0p1', Libversion::VERSIONFLAG_P_IS_PATCH, 0))
|
217
|
+
assert_equal(-1, Libversion.version_compare4('1.0p1', '1.0p1', 0, Libversion::VERSIONFLAG_P_IS_PATCH))
|
218
|
+
|
219
|
+
assert_equal(0, Libversion.version_compare4('1.0p1', '1.0P1', 0, 0))
|
220
|
+
assert_equal(0, Libversion.version_compare4('1.0p1', '1.0P1', Libversion::VERSIONFLAG_P_IS_PATCH, Libversion::VERSIONFLAG_P_IS_PATCH))
|
221
|
+
|
222
|
+
assert_equal(1, Libversion.version_compare4('1.0', '1.0p1', 0, 0))
|
223
|
+
assert_equal(1, Libversion.version_compare4('1.0', '1.0p1', Libversion::VERSIONFLAG_P_IS_PATCH, 0))
|
224
|
+
assert_equal(-1, Libversion.version_compare4('1.0', '1.0p1', 0, Libversion::VERSIONFLAG_P_IS_PATCH))
|
225
|
+
|
226
|
+
assert_equal(1, Libversion.version_compare4('1.0', '1.0.p1', 0, 0))
|
227
|
+
assert_equal(1, Libversion.version_compare4('1.0', '1.0.p1', Libversion::VERSIONFLAG_P_IS_PATCH, 0))
|
228
|
+
assert_equal(-1, Libversion.version_compare4('1.0', '1.0.p1', 0, Libversion::VERSIONFLAG_P_IS_PATCH))
|
229
|
+
|
230
|
+
assert_equal(1, Libversion.version_compare4('1.0', '1.0.p.1', 0, 0))
|
231
|
+
assert_equal(1, Libversion.version_compare4('1.0', '1.0.p.1', Libversion::VERSIONFLAG_P_IS_PATCH, 0))
|
232
|
+
assert_equal(-1, Libversion.version_compare4('1.0', '1.0.p.1', 0, Libversion::VERSIONFLAG_P_IS_PATCH))
|
233
|
+
|
234
|
+
assert_equal(-1, Libversion.version_compare4('1.0', '1.0p.1', 0, 0))
|
235
|
+
assert_equal(-1, Libversion.version_compare4('1.0', '1.0p.1', Libversion::VERSIONFLAG_P_IS_PATCH, 0))
|
236
|
+
assert_equal(-1, Libversion.version_compare4('1.0', '1.0p.1', 0, Libversion::VERSIONFLAG_P_IS_PATCH))
|
237
|
+
end
|
238
|
+
|
239
|
+
def test_any_is_patch_flag
|
240
|
+
assert_equal(0, Libversion.version_compare4('1.0a1', '1.0a1', 0, 0))
|
241
|
+
assert_equal(0, Libversion.version_compare4('1.0a1', '1.0a1', Libversion::VERSIONFLAG_ANY_IS_PATCH, Libversion::VERSIONFLAG_ANY_IS_PATCH))
|
242
|
+
assert_equal(1, Libversion.version_compare4('1.0a1', '1.0a1', Libversion::VERSIONFLAG_ANY_IS_PATCH, 0))
|
243
|
+
assert_equal(-1, Libversion.version_compare4('1.0a1', '1.0a1', 0, Libversion::VERSIONFLAG_ANY_IS_PATCH))
|
244
|
+
|
245
|
+
assert_equal(1, Libversion.version_compare4('1.0', '1.0a1', 0, 0))
|
246
|
+
assert_equal(1, Libversion.version_compare4('1.0', '1.0a1', Libversion::VERSIONFLAG_ANY_IS_PATCH, 0))
|
247
|
+
assert_equal(-1, Libversion.version_compare4('1.0', '1.0a1', 0, Libversion::VERSIONFLAG_ANY_IS_PATCH))
|
248
|
+
|
249
|
+
assert_equal(1, Libversion.version_compare4('1.0', '1.0.a1', 0, 0))
|
250
|
+
assert_equal(1, Libversion.version_compare4('1.0', '1.0.a1', Libversion::VERSIONFLAG_ANY_IS_PATCH, 0))
|
251
|
+
assert_equal(-1, Libversion.version_compare4('1.0', '1.0.a1', 0, Libversion::VERSIONFLAG_ANY_IS_PATCH))
|
252
|
+
|
253
|
+
assert_equal(1, Libversion.version_compare4('1.0', '1.0.a.1', 0, 0))
|
254
|
+
assert_equal(1, Libversion.version_compare4('1.0', '1.0.a.1', Libversion::VERSIONFLAG_ANY_IS_PATCH, 0))
|
255
|
+
assert_equal(-1, Libversion.version_compare4('1.0', '1.0.a.1', 0, Libversion::VERSIONFLAG_ANY_IS_PATCH))
|
256
|
+
|
257
|
+
assert_equal(-1, Libversion.version_compare4('1.0', '1.0a.1', 0, 0))
|
258
|
+
assert_equal(-1, Libversion.version_compare4('1.0', '1.0a.1', Libversion::VERSIONFLAG_ANY_IS_PATCH, 0))
|
259
|
+
assert_equal(-1, Libversion.version_compare4('1.0', '1.0a.1', 0, Libversion::VERSIONFLAG_ANY_IS_PATCH))
|
260
|
+
end
|
261
|
+
|
262
|
+
def test_p_patch_compatibility
|
263
|
+
assert_equal(0, Libversion.version_compare4('1.0p1', '1.0pre1', 0, 0))
|
264
|
+
assert_equal(-1, Libversion.version_compare4('1.0p1', '1.0patch1', 0, 0))
|
265
|
+
assert_equal(-1, Libversion.version_compare4('1.0p1', '1.0post1', 0, 0))
|
266
|
+
|
267
|
+
assert_equal(1, Libversion.version_compare4('1.0p1', '1.0pre1', Libversion::VERSIONFLAG_P_IS_PATCH, Libversion::VERSIONFLAG_P_IS_PATCH))
|
268
|
+
assert_equal(0, Libversion.version_compare4('1.0p1', '1.0patch1', Libversion::VERSIONFLAG_P_IS_PATCH, Libversion::VERSIONFLAG_P_IS_PATCH))
|
269
|
+
assert_equal(0, Libversion.version_compare4('1.0p1', '1.0post1', Libversion::VERSIONFLAG_P_IS_PATCH, Libversion::VERSIONFLAG_P_IS_PATCH))
|
270
|
+
end
|
271
|
+
|
272
|
+
def test_prelease_words_without_numbers
|
273
|
+
assert_equal(-1, Libversion.version_compare2('1.0alpha', '1.0'))
|
274
|
+
assert_equal(-1, Libversion.version_compare2('1.0.alpha', '1.0'))
|
275
|
+
|
276
|
+
assert_equal(-1, Libversion.version_compare2('1.0beta', '1.0'))
|
277
|
+
assert_equal(-1, Libversion.version_compare2('1.0.beta', '1.0'))
|
278
|
+
|
279
|
+
assert_equal(-1, Libversion.version_compare2('1.0rc', '1.0'))
|
280
|
+
assert_equal(-1, Libversion.version_compare2('1.0.rc', '1.0'))
|
281
|
+
|
282
|
+
assert_equal(-1, Libversion.version_compare2('1.0pre', '1.0'))
|
283
|
+
assert_equal(-1, Libversion.version_compare2('1.0.pre', '1.0'))
|
284
|
+
|
285
|
+
assert_equal(-1, Libversion.version_compare2('1.0prerelese', '1.0'))
|
286
|
+
assert_equal(-1, Libversion.version_compare2('1.0.prerelese', '1.0'))
|
287
|
+
|
288
|
+
assert_equal(1, Libversion.version_compare2('1.0patch', '1.0'))
|
289
|
+
assert_equal(1, Libversion.version_compare2('1.0.patch', '1.0'))
|
290
|
+
end
|
291
|
+
|
292
|
+
def test_release_bounds
|
293
|
+
assert_equal(-1, Libversion.version_compare4('0.99999', '1.0', 0, 0))
|
294
|
+
assert_equal(-1, Libversion.version_compare4('1.0alpha', '1.0', 0, 0))
|
295
|
+
assert_equal(-1, Libversion.version_compare4('1.0alpha0', '1.0', 0, 0))
|
296
|
+
assert_equal(0, Libversion.version_compare4('1.0', '1.0', 0, 0))
|
297
|
+
assert_equal(1, Libversion.version_compare4('1.0patch', '1.0', 0, 0))
|
298
|
+
assert_equal(1, Libversion.version_compare4('1.0patch0', '1.0', 0, 0))
|
299
|
+
assert_equal(1, Libversion.version_compare4('1.0.1', '1.0', 0, 0))
|
300
|
+
assert_equal(1, Libversion.version_compare4('1.1', '1.0', 0, 0))
|
301
|
+
|
302
|
+
assert_equal(-1, Libversion.version_compare4('0.99999', '1.0', 0, Libversion::VERSIONFLAG_LOWER_BOUND))
|
303
|
+
assert_equal(1, Libversion.version_compare4('1.0alpha', '1.0', 0, Libversion::VERSIONFLAG_LOWER_BOUND))
|
304
|
+
assert_equal(1, Libversion.version_compare4('1.0alpha0', '1.0', 0, Libversion::VERSIONFLAG_LOWER_BOUND))
|
305
|
+
assert_equal(1, Libversion.version_compare4('1.0', '1.0', 0, Libversion::VERSIONFLAG_LOWER_BOUND))
|
306
|
+
assert_equal(1, Libversion.version_compare4('1.0patch', '1.0', 0, Libversion::VERSIONFLAG_LOWER_BOUND))
|
307
|
+
assert_equal(1, Libversion.version_compare4('1.0patch0', '1.0', 0, Libversion::VERSIONFLAG_LOWER_BOUND))
|
308
|
+
assert_equal(1, Libversion.version_compare4('1.0a', '1.0', 0, Libversion::VERSIONFLAG_LOWER_BOUND))
|
309
|
+
assert_equal(1, Libversion.version_compare4('1.0.1', '1.0', 0, Libversion::VERSIONFLAG_LOWER_BOUND))
|
310
|
+
assert_equal(1, Libversion.version_compare4('1.1', '1.0', 0, Libversion::VERSIONFLAG_LOWER_BOUND))
|
311
|
+
|
312
|
+
assert_equal(-1, Libversion.version_compare4('0.99999', '1.0', 0, Libversion::VERSIONFLAG_UPPER_BOUND))
|
313
|
+
assert_equal(-1, Libversion.version_compare4('1.0alpha', '1.0', 0, Libversion::VERSIONFLAG_UPPER_BOUND))
|
314
|
+
assert_equal(-1, Libversion.version_compare4('1.0alpha0', '1.0', 0, Libversion::VERSIONFLAG_UPPER_BOUND))
|
315
|
+
assert_equal(-1, Libversion.version_compare4('1.0', '1.0', 0, Libversion::VERSIONFLAG_UPPER_BOUND))
|
316
|
+
assert_equal(-1, Libversion.version_compare4('1.0patch', '1.0', 0, Libversion::VERSIONFLAG_UPPER_BOUND))
|
317
|
+
assert_equal(-1, Libversion.version_compare4('1.0patch0', '1.0', 0, Libversion::VERSIONFLAG_UPPER_BOUND))
|
318
|
+
assert_equal(-1, Libversion.version_compare4('1.0a', '1.0', 0, Libversion::VERSIONFLAG_UPPER_BOUND))
|
319
|
+
assert_equal(-1, Libversion.version_compare4('1.0.1', '1.0', 0, Libversion::VERSIONFLAG_UPPER_BOUND))
|
320
|
+
assert_equal(1, Libversion.version_compare4('1.1', '1.0', 0, Libversion::VERSIONFLAG_UPPER_BOUND))
|
321
|
+
|
322
|
+
assert_equal(0, Libversion.version_compare4('1.0', '1.0', Libversion::VERSIONFLAG_LOWER_BOUND, Libversion::VERSIONFLAG_LOWER_BOUND))
|
323
|
+
assert_equal(0, Libversion.version_compare4('1.0', '1.0', Libversion::VERSIONFLAG_UPPER_BOUND, Libversion::VERSIONFLAG_UPPER_BOUND))
|
324
|
+
assert_equal(-1, Libversion.version_compare4('1.0', '1.0', Libversion::VERSIONFLAG_LOWER_BOUND, Libversion::VERSIONFLAG_UPPER_BOUND))
|
325
|
+
|
326
|
+
assert_equal(-1, Libversion.version_compare4('1.0', '1.1', Libversion::VERSIONFLAG_UPPER_BOUND, Libversion::VERSIONFLAG_LOWER_BOUND))
|
327
|
+
|
328
|
+
assert_equal(1, Libversion.version_compare4('0', '0.0', Libversion::VERSIONFLAG_UPPER_BOUND, Libversion::VERSIONFLAG_UPPER_BOUND))
|
329
|
+
assert_equal(-1, Libversion.version_compare4('0', '0.0', Libversion::VERSIONFLAG_LOWER_BOUND, Libversion::VERSIONFLAG_LOWER_BOUND))
|
330
|
+
end
|
331
|
+
|
332
|
+
def test_uniform_component_splitting
|
333
|
+
assert_equal(0, Libversion.version_compare2('1.0alpha1', '1.0alpha1'))
|
334
|
+
assert_equal(0, Libversion.version_compare2('1.0alpha1', '1.0.alpha1'))
|
335
|
+
assert_equal(0, Libversion.version_compare2('1.0alpha1', '1.0alpha.1'))
|
336
|
+
assert_equal(0, Libversion.version_compare2('1.0alpha1', '1.0.alpha.1'))
|
337
|
+
|
338
|
+
assert_equal(0, Libversion.version_compare2('1.0patch1', '1.0patch1'))
|
339
|
+
assert_equal(0, Libversion.version_compare2('1.0patch1', '1.0.patch1'))
|
340
|
+
assert_equal(0, Libversion.version_compare2('1.0patch1', '1.0patch.1'))
|
341
|
+
assert_equal(0, Libversion.version_compare2('1.0patch1', '1.0.patch.1'))
|
342
|
+
end
|
343
|
+
end
|
metadata
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: ruby-libversion
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Maximilian Downey Twiss
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2024-02-08 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description:
|
14
|
+
email: creatorsmithmdt@.com
|
15
|
+
executables: []
|
16
|
+
extensions:
|
17
|
+
- ext/libversion/extconf.rb
|
18
|
+
extra_rdoc_files: []
|
19
|
+
files:
|
20
|
+
- ".gitignore"
|
21
|
+
- LICENSE
|
22
|
+
- README.md
|
23
|
+
- Rakefile
|
24
|
+
- ext/libversion/extconf.rb
|
25
|
+
- ext/libversion/libversion.c
|
26
|
+
- lib/libversion.rb
|
27
|
+
- ruby-libversion.gemspec
|
28
|
+
- test/test_ruby_libversion.rb
|
29
|
+
homepage: https://github.com/Zopolis4/ruby-libversion
|
30
|
+
licenses:
|
31
|
+
- MIT
|
32
|
+
metadata: {}
|
33
|
+
post_install_message:
|
34
|
+
rdoc_options: []
|
35
|
+
require_paths:
|
36
|
+
- lib
|
37
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - ">="
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: '0'
|
42
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
43
|
+
requirements:
|
44
|
+
- - ">="
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: '0'
|
47
|
+
requirements: []
|
48
|
+
rubygems_version: 3.4.20
|
49
|
+
signing_key:
|
50
|
+
specification_version: 4
|
51
|
+
summary: Ruby bindings for libversion
|
52
|
+
test_files: []
|