From ada4462eb989d8f3b90e107aae38324399ed49be Mon Sep 17 00:00:00 2001 From: syeopite Date: Fri, 13 Aug 2021 18:46:12 -0700 Subject: [PATCH 1/4] Implement != operator for version resolve --- spec/unit/versions_spec.cr | 12 ++++++++++++ src/versions.cr | 4 +++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/spec/unit/versions_spec.cr b/spec/unit/versions_spec.cr index 5dc06ad0..a7f07d77 100644 --- a/spec/unit/versions_spec.cr +++ b/spec/unit/versions_spec.cr @@ -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"]) + 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) @@ -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 + 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 diff --git a/src/versions.cr b/src/versions.cr index 169313ff..1ee1562f 100644 --- a/src/versions.cr +++ b/src/versions.cr @@ -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) @@ -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 From 0efe578f929c2b78a70cd36baa437dcea2a898f1 Mon Sep 17 00:00:00 2001 From: syeopite Date: Fri, 13 Aug 2021 19:01:08 -0700 Subject: [PATCH 2/4] Update docs and manuals --- docs/shard.yml.adoc | 6 +++--- man/shard.yml.5 | 20 ++++++++++---------- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/docs/shard.yml.adoc b/docs/shard.yml.adoc index 62f261dd..707a9273 100644 --- a/docs/shard.yml.adoc +++ b/docs/shard.yml.adoc @@ -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. -- @@ -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] @@ -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. -- + diff --git a/man/shard.yml.5 b/man/shard.yml.5 index 086a5ebf..d5ceffd8 100644 --- a/man/shard.yml.5 +++ b/man/shard.yml.5 @@ -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 @@ -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. @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 From 7062b4cd63638bd012ae76343a1ee3e746dd0df8 Mon Sep 17 00:00:00 2001 From: syeopite Date: Wed, 18 Aug 2021 13:31:12 -0700 Subject: [PATCH 3/4] Fix lint --- spec/unit/versions_spec.cr | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/unit/versions_spec.cr b/spec/unit/versions_spec.cr index a7f07d77..29e2783b 100644 --- a/spec/unit/versions_spec.cr +++ b/spec/unit/versions_spec.cr @@ -151,7 +151,7 @@ module Shards 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"]) + resolve(versions, "!= 0.1.0, != 0.2.0, != 0.10.0").should eq(["0.0.1", "0.1.1", "0.1.2"]) end it "resolve gt" do From 30df126f90c73534f04ed6ca69a8f91c2ac95ebe Mon Sep 17 00:00:00 2001 From: syeopite Date: Wed, 18 Aug 2021 14:58:19 -0700 Subject: [PATCH 4/4] Improve specs for not equal operator - Better check for resolve - Errors caused by linting --- spec/unit/versions_spec.cr | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/spec/unit/versions_spec.cr b/spec/unit/versions_spec.cr index 29e2783b..c800e685 100644 --- a/spec/unit/versions_spec.cr +++ b/spec/unit/versions_spec.cr @@ -150,8 +150,8 @@ module Shards 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"]) + 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"]) end it "resolve gt" do @@ -207,9 +207,9 @@ module Shards 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 + matches?("0.5.0", "> 0.1, < 1.0, != 0.5").should be_false 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.8", ">= 1.0.1, != 2.0").should be_true matches?("1.0.0", ">= 1.0.0").should be_true matches?("1.0.0", ">= 1.0").should be_true