Skip to content

Commit

Permalink
Updated readme
Browse files Browse the repository at this point in the history
  • Loading branch information
cmaglie committed May 27, 2022
1 parent 0cb3fc0 commit 5245208
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 15 deletions.
33 changes: 19 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ The following operators are supported:
| `>=` | greater than or equal to |
| `<` | less than |
| `<=` | less than or equal to |
| `^` | compatible-with |
| `!` | NOT |
| `&&` | AND |
| `\|\|` | OR |
Expand All @@ -57,21 +58,25 @@ Given the following releases of a dependency:
- `0.1.0`
- `1.0.0`
- `2.0.0`
- `2.0.5`
- `2.0.6`
- `2.1.0`

constraints would resolve as follows:

| Constraint | Resolution |
| -------------------------------- | ---------- |
| `=1.0.0` | `1.0.0` |
| `>1.0.0` | `2.1.0` |
| `>=1.0.0` | `2.1.0` |
| `<2.0.0` | `1.0.0` |
| `<=2.0.0` | `2.0.0` |
| `!=1.0.0` | `2.1.0` |
| `>1.0.0 && <2.1.0` | `2.0.0` |
| `<1.0.0 \|\| >2.0.0` | `2.1.0` |
| `(>0.1.0 && <2.0.0) \|\| >2.1.0` | `1.0.0` |
- `3.0.0`

constraints conditions would match as follows:

| The following condition... | will match with versions... |
| -------------------------------- | ---------------------------------------------------- |
| `=1.0.0` | `1.0.0` |
| `>1.0.0` | `2.0.0`, `2.0.5`, `2.0.6`, `2.1.0`, `3.0.0` |
| `>=1.0.0` | `1.0.0`, `2.0.0`, `2.0.5`, `2.0.6`, `2.1.0`, `3.0.0` |
| `<2.0.0` | `0.1.0`, `1.0.0` |
| `<=2.0.0` | `0.1.0`, `1.0.0`, `2.0.0` |
| `!=1.0.0` | `0.1.0`, `2.0.0`, `2.0.5`, `2.0.6`, `2.1.0`, `3.0.0` |
| `>1.0.0 && <2.1.0` | `2.0.0`, `2.0.5`, `2.0.6` |
| `<1.0.0 \|\| >2.0.0` | `0.1.0`, `2.0.5`, `2.0.6`, `2.1.0`, `3.0.0` |
| `(>0.1.0 && <2.0.0) \|\| >2.0.5` | `1.0.0`, `2.0.6`, `2.1.0`,`3.0.0` |
| `^2.0.5` | `2.0.5`, `2.0.6`, `2.1.0` |

## Json parsable

Expand Down
2 changes: 1 addition & 1 deletion constraints.go
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ type CompatibleWith struct {

// Match returns true if v satisfies the condition
func (cw *CompatibleWith) Match(v *Version) bool {
return v.CompatibleWith(cw.Version)
return cw.Version.CompatibleWith(v)
}

func (cw *CompatibleWith) String() string {
Expand Down
19 changes: 19 additions & 0 deletions constraints_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,19 @@ func TestConstraints(t *testing.T) {
require.True(t, notOr.Match(v("2.0.0")))
require.False(t, notOr.Match(v("2.1.0")))
require.Equal(t, "!(>2.0.0 || <=1.0.0)", notOr.String())

comp := &CompatibleWith{v("1.3.4-rc.3")}
require.False(t, comp.Match(v("1.2.3")))
require.False(t, comp.Match(v("1.3.2")))
require.False(t, comp.Match(v("1.2.3")))
require.False(t, comp.Match(v("1.3.4-rc.1")))
require.True(t, comp.Match(v("1.3.4-rc.5")))
require.True(t, comp.Match(v("1.3.4")))
require.True(t, comp.Match(v("1.3.6")))
require.True(t, comp.Match(v("1.4.0")))
require.True(t, comp.Match(v("1.4.5")))
require.True(t, comp.Match(v("1.4.5-rc.2")))
require.False(t, comp.Match(v("2.0.0")))
}

func TestConstraintsParser(t *testing.T) {
Expand All @@ -92,10 +105,15 @@ func TestConstraintsParser(t *testing.T) {
{">1.3.0", ">1.3.0"},
{"<=1.3.0", "<=1.3.0"},
{"<1.3.0", "<1.3.0"},
{"^1.3.0", "^1.3.0"},
{" ^1.3.0", "^1.3.0"},
{"^1.3.0 ", "^1.3.0"},
{" ^1.3.0 ", "^1.3.0"},
{"(=1.4.0)", "=1.4.0"},
{"!(=1.4.0)", "!(=1.4.0)"},
{"!(((=1.4.0)))", "!(=1.4.0)"},
{"=1.2.4 && =1.3.0", "(=1.2.4 && =1.3.0)"},
{"=1.2.4 && ^1.3.0", "(=1.2.4 && ^1.3.0)"},
{"=1.2.4 && =1.3.0 && =1.2.0", "(=1.2.4 && =1.3.0 && =1.2.0)"},
{"=1.2.4 && =1.3.0 || =1.2.0", "((=1.2.4 && =1.3.0) || =1.2.0)"},
{"=1.2.4 || =1.3.0 && =1.2.0", "(=1.2.4 || (=1.3.0 && =1.2.0))"},
Expand Down Expand Up @@ -124,6 +142,7 @@ func TestConstraintsParser(t *testing.T) {
">>1.0.0",
">1.0.0 =2.0.0",
">1.0.0 &",
"^1.1.1.1",
"!1.0.0",
">1.0.0 && 2.0.0",
">1.0.0 | =2.0.0",
Expand Down

0 comments on commit 5245208

Please sign in to comment.