Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add != operator for version resolve #520

Merged
merged 4 commits into from
Sep 20, 2021
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions docs/shard.yml.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ own risk.
The valid values are mostly the same as for _dependencies.version_:
+
--
* A version number prefixed by an operator: _<_, _\<=_, _>_, _>=_ or _~>_.
* A version number prefixed by an operator: _<_, _\<=_, _>_, _>=_, _!=_ or _~>_.
* Just _"*"_ if any version will do (this is the default if unspecified).
* Multiple requirements can be separated by commas.
--
Expand Down Expand Up @@ -192,7 +192,7 @@ The version constraint has the following format:
--
- It may be a version number.
- It may be _"*"_ if any version will do.
- The version number may be prefixed by an operator: _<_, _\<=_, _>_, _>=_ or _~>_.
- The version number may be prefixed by an operator: _<_, _\<=_, _>_, _>=_, _!=_ or _~>_.
--
+
[source,yaml]
Expand Down Expand Up @@ -328,7 +328,7 @@ A version requirement (string).
- It may be _"*"_ wildcard if any version will do (this is the default).
Shards will then install the latest tagged version (or HEAD if no tagged
version available).
- The version number may be prefixed by an operator: _<_, _\<=_, _>_, _>=_ or _~>_.
- The version number may be prefixed by an operator: _<_, _\<=_, _>_, _>=_, _!=_ or _~>_.
- Multiple requirements can be separated by commas.
--
+
Expand Down
20 changes: 10 additions & 10 deletions man/shard.yml.5
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
'\" t
.\" Title: shard.yml
.\" Author: [see the "AUTHOR(S)" section]
.\" Generator: Asciidoctor 2.0.12
.\" Date: 2021-06-29
.\" Generator: Asciidoctor 2.0.16
.\" Date: 2021-08-14
.\" Manual: File Formats
.\" Source: shards 0.15.0
.\" Language: English
.\"
.TH "SHARD.YML" "5" "2021-06-29" "shards 0.15.0" "File Formats"
.TH "SHARD.YML" "5" "2021-08-14" "shards 0.15.0" "File Formats"
.ie \n(.g .ds Aq \(aq
.el .ds Aq '
.ss \n[.ss] 0
Expand Down Expand Up @@ -165,13 +165,13 @@ It may contain dots and dashes but not consecutive ones.
. sp -1
. IP \(bu 2.3
.\}
It may contain a letter to make it a \(aqprerelease\(aq.
It may contain a letter to make it a \*(Aqprerelease\*(Aq.
.RE
.sp
Examples: \fI1.2.3\fP, \fI2.0.0.1\fP, \fI1.0.0.alpha\fP \fI2.0.0\-rc1\fP or \fI2016.09\fP.
.sp
While Shards doesn\(cqt enforce it, following a rational versioning scheme like
.URL "http://semver.org/" "Semantic Versioning" " "
.URL "http://semver.org/" "Semantic Versioning" ""
or
.URL "http://calver.org/" "Calendar Versioning"
is highly recommended.
Expand Down Expand Up @@ -239,7 +239,7 @@ The valid values are mostly the same as for \fIdependencies.version\fP:
. sp -1
. IP \(bu 2.3
.\}
A version number prefixed by an operator: \fI<\fP, \fI<=\fP, \fI>\fP, \fI>=\fP or \fI~>\fP.
A version number prefixed by an operator: \fI<\fP, \fI<=\fP, \fI>\fP, \fI>=\fP, \fI!=\fP or \fI~>\fP.
.RE
.sp
.RS 4
Expand Down Expand Up @@ -417,7 +417,7 @@ It may be \fI"*"\fP if any version will do.
. sp -1
. IP \(bu 2.3
.\}
The version number may be prefixed by an operator: \fI<\fP, \fI<=\fP, \fI>\fP, \fI>=\fP or \fI~>\fP.
The version number may be prefixed by an operator: \fI<\fP, \fI<=\fP, \fI>\fP, \fI>=\fP, \fI!=\fP or \fI~>\fP.
.RE
.sp
.if n .RS 4
Expand All @@ -435,7 +435,7 @@ libraries:
\fBlicense\fP
.RS 4
An \c
.URL "http://opensource.org/" "OSI license" " "
.URL "http://opensource.org/" "OSI license" ""
name or an URL to a license file
(string, recommended).
.RE
Expand Down Expand Up @@ -618,7 +618,7 @@ version available).
. sp -1
. IP \(bu 2.3
.\}
The version number may be prefixed by an operator: \fI<\fP, \fI<=\fP, \fI>\fP, \fI>=\fP or \fI~>\fP.
The version number may be prefixed by an operator: \fI<\fP, \fI<=\fP, \fI>\fP, \fI>=\fP, \fI!=\fP or \fI~>\fP.
.RE
.sp
.RS 4
Expand Down Expand Up @@ -684,7 +684,7 @@ with some dependencies:
.fam C
name: shards
version: 1.2.3
crystal: \(aq>= 0.35.0\(aq
crystal: \*(Aq>= 0.35.0\*(Aq

authors:
\- Julien Portalier <julien@example.com>
Expand Down
12 changes: 12 additions & 0 deletions spec/unit/versions_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,13 @@ module Shards
resolve(versions, "0.0.1.alpha").should be_empty
end

it "resolves neq" do
versions = %w(0.0.1 0.1.0 0.1.1 0.1.2 0.2.0 0.10.0)

resolve(versions, "!= 0.1.0").should eq(["0.0.1", "0.1.1", "0.1.2", "0.2.0", "0.10.0"]),
resolve(versions, "!= 0.1.0, != 0.2.0, != 0.10.0").should eq(["0.0.1", "0.1.1", "0.1.2"])
syeopite marked this conversation as resolved.
Show resolved Hide resolved
end

it "resolve gt" do
versions = %w(0.0.1 0.1.0 0.1.1 0.1.2 0.2.0 0.10.0)

Expand Down Expand Up @@ -199,6 +206,11 @@ module Shards
matches?("1.0.0", "1.0").should be_true
matches?("1.0.0", "1.0.1").should be_false

matches?("1.0.0", "> 0.1.0, < 1.0.1, != 1.0.0").should be_false
matches?("1.0.0", "> 0.1, < 1.0, != 1.0").should be_false
syeopite marked this conversation as resolved.
Show resolved Hide resolved
matches?("1.0.1", ">= 1.0.0, != 2.0").should be_true
matches?("1.0.0", ">= 1.0.1, != 1.0.0").should be_false

matches?("1.0.0", ">= 1.0.0").should be_true
matches?("1.0.0", ">= 1.0").should be_true
matches?("1.0.1", ">= 1.0.0").should be_true
Expand Down
4 changes: 3 additions & 1 deletion src/versions.cr
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ module Shards
$1
end
matches_approximate?(version.value, $1, ver)
when /\s*(~>|>=|<=|>|<|=)\s*([^~<>=\s]+)\s*/
when /\s*(~>|>=|<=|!=|>|<|=)\s*([^~<>=!\s]+)\s*/
matches_operator?(version.value, $1, $2)
else
matches_operator?(version.value, "=", pattern)
Expand All @@ -210,6 +210,8 @@ module Shards
compare(version, requirement) < 0
when "<"
compare(version, requirement) > 0
when "!="
compare(version, requirement) != 0
else
compare(version, requirement) == 0
end
Expand Down