Skip to content

Commit 8f48d4e

Browse files
authored
Add != operator for version resolve (#520)
1 parent c7a22e4 commit 8f48d4e

File tree

4 files changed

+28
-14
lines changed

4 files changed

+28
-14
lines changed

docs/shard.yml.adoc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ own risk.
8888
The valid values are mostly the same as for _dependencies.version_:
8989
+
9090
--
91-
* A version number prefixed by an operator: _<_, _\<=_, _>_, _>=_ or _~>_.
91+
* A version number prefixed by an operator: _<_, _\<=_, _>_, _>=_, _!=_ or _~>_.
9292
* Just _"*"_ if any version will do (this is the default if unspecified).
9393
* Multiple requirements can be separated by commas.
9494
--
@@ -192,7 +192,7 @@ The version constraint has the following format:
192192
--
193193
- It may be a version number.
194194
- It may be _"*"_ if any version will do.
195-
- The version number may be prefixed by an operator: _<_, _\<=_, _>_, _>=_ or _~>_.
195+
- The version number may be prefixed by an operator: _<_, _\<=_, _>_, _>=_, _!=_ or _~>_.
196196
--
197197
+
198198
[source,yaml]
@@ -328,7 +328,7 @@ A version requirement (string).
328328
- It may be _"*"_ wildcard if any version will do (this is the default).
329329
Shards will then install the latest tagged version (or HEAD if no tagged
330330
version available).
331-
- The version number may be prefixed by an operator: _<_, _\<=_, _>_, _>=_ or _~>_.
331+
- The version number may be prefixed by an operator: _<_, _\<=_, _>_, _>=_, _!=_ or _~>_.
332332
- Multiple requirements can be separated by commas.
333333
--
334334
+

man/shard.yml.5

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
'\" t
22
.\" Title: shard.yml
33
.\" Author: [see the "AUTHOR(S)" section]
4-
.\" Generator: Asciidoctor 2.0.12
5-
.\" Date: 2021-06-29
4+
.\" Generator: Asciidoctor 2.0.16
5+
.\" Date: 2021-08-14
66
.\" Manual: File Formats
77
.\" Source: shards 0.15.0
88
.\" Language: English
99
.\"
10-
.TH "SHARD.YML" "5" "2021-06-29" "shards 0.15.0" "File Formats"
10+
.TH "SHARD.YML" "5" "2021-08-14" "shards 0.15.0" "File Formats"
1111
.ie \n(.g .ds Aq \(aq
1212
.el .ds Aq '
1313
.ss \n[.ss] 0
@@ -165,13 +165,13 @@ It may contain dots and dashes but not consecutive ones.
165165
. sp -1
166166
. IP \(bu 2.3
167167
.\}
168-
It may contain a letter to make it a \(aqprerelease\(aq.
168+
It may contain a letter to make it a \*(Aqprerelease\*(Aq.
169169
.RE
170170
.sp
171171
Examples: \fI1.2.3\fP, \fI2.0.0.1\fP, \fI1.0.0.alpha\fP \fI2.0.0\-rc1\fP or \fI2016.09\fP.
172172
.sp
173173
While Shards doesn\(cqt enforce it, following a rational versioning scheme like
174-
.URL "http://semver.org/" "Semantic Versioning" " "
174+
.URL "http://semver.org/" "Semantic Versioning" ""
175175
or
176176
.URL "http://calver.org/" "Calendar Versioning"
177177
is highly recommended.
@@ -239,7 +239,7 @@ The valid values are mostly the same as for \fIdependencies.version\fP:
239239
. sp -1
240240
. IP \(bu 2.3
241241
.\}
242-
A version number prefixed by an operator: \fI<\fP, \fI<=\fP, \fI>\fP, \fI>=\fP or \fI~>\fP.
242+
A version number prefixed by an operator: \fI<\fP, \fI<=\fP, \fI>\fP, \fI>=\fP, \fI!=\fP or \fI~>\fP.
243243
.RE
244244
.sp
245245
.RS 4
@@ -417,7 +417,7 @@ It may be \fI"*"\fP if any version will do.
417417
. sp -1
418418
. IP \(bu 2.3
419419
.\}
420-
The version number may be prefixed by an operator: \fI<\fP, \fI<=\fP, \fI>\fP, \fI>=\fP or \fI~>\fP.
420+
The version number may be prefixed by an operator: \fI<\fP, \fI<=\fP, \fI>\fP, \fI>=\fP, \fI!=\fP or \fI~>\fP.
421421
.RE
422422
.sp
423423
.if n .RS 4
@@ -435,7 +435,7 @@ libraries:
435435
\fBlicense\fP
436436
.RS 4
437437
An \c
438-
.URL "http://opensource.org/" "OSI license" " "
438+
.URL "http://opensource.org/" "OSI license" ""
439439
name or an URL to a license file
440440
(string, recommended).
441441
.RE
@@ -618,7 +618,7 @@ version available).
618618
. sp -1
619619
. IP \(bu 2.3
620620
.\}
621-
The version number may be prefixed by an operator: \fI<\fP, \fI<=\fP, \fI>\fP, \fI>=\fP or \fI~>\fP.
621+
The version number may be prefixed by an operator: \fI<\fP, \fI<=\fP, \fI>\fP, \fI>=\fP, \fI!=\fP or \fI~>\fP.
622622
.RE
623623
.sp
624624
.RS 4
@@ -684,7 +684,7 @@ with some dependencies:
684684
.fam C
685685
name: shards
686686
version: 1.2.3
687-
crystal: \(aq>= 0.35.0\(aq
687+
crystal: \*(Aq>= 0.35.0\*(Aq
688688

689689
authors:
690690
\- Julien Portalier <[email protected]>

spec/unit/versions_spec.cr

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,13 @@ module Shards
147147
resolve(versions, "0.0.1.alpha").should be_empty
148148
end
149149

150+
it "resolves neq" do
151+
versions = %w(0.0.1 0.1.0 0.1.1 0.1.2 0.2.0 0.10.0)
152+
153+
resolve(versions, "!= 0.1.0").should eq(["0.0.1", "0.1.1", "0.1.2", "0.2.0", "0.10.0"])
154+
resolve(versions, "!= 0.1.0, != 0.2.0, != 0.10.0").should eq(["0.0.1", "0.1.1", "0.1.2"])
155+
end
156+
150157
it "resolve gt" do
151158
versions = %w(0.0.1 0.1.0 0.1.1 0.1.2 0.2.0 0.10.0)
152159

@@ -199,6 +206,11 @@ module Shards
199206
matches?("1.0.0", "1.0").should be_true
200207
matches?("1.0.0", "1.0.1").should be_false
201208

209+
matches?("1.0.0", "> 0.1.0, < 1.0.1, != 1.0.0").should be_false
210+
matches?("0.5.0", "> 0.1, < 1.0, != 0.5").should be_false
211+
matches?("1.0.1", ">= 1.0.0, != 2.0").should be_true
212+
matches?("1.8", ">= 1.0.1, != 2.0").should be_true
213+
202214
matches?("1.0.0", ">= 1.0.0").should be_true
203215
matches?("1.0.0", ">= 1.0").should be_true
204216
matches?("1.0.1", ">= 1.0.0").should be_true

src/versions.cr

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ module Shards
187187
$1
188188
end
189189
matches_approximate?(version.value, $1, ver)
190-
when /\s*(~>|>=|<=|>|<|=)\s*([^~<>=\s]+)\s*/
190+
when /\s*(~>|>=|<=|!=|>|<|=)\s*([^~<>=!\s]+)\s*/
191191
matches_operator?(version.value, $1, $2)
192192
else
193193
matches_operator?(version.value, "=", pattern)
@@ -210,6 +210,8 @@ module Shards
210210
compare(version, requirement) < 0
211211
when "<"
212212
compare(version, requirement) > 0
213+
when "!="
214+
compare(version, requirement) != 0
213215
else
214216
compare(version, requirement) == 0
215217
end

0 commit comments

Comments
 (0)