Skip to content

Commit

Permalink
fix: tilde constraint
Browse files Browse the repository at this point in the history
  • Loading branch information
shyim committed May 1, 2024
1 parent 84a6afa commit 070a3f8
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 8 deletions.
8 changes: 0 additions & 8 deletions version/constraint.go
Original file line number Diff line number Diff line change
Expand Up @@ -274,14 +274,6 @@ func constraintTilde(v, c *Version) bool {
return false
}

if v.segments[1] != c.segments[1] && c.si > 1 {
return false
}

if reflect.DeepEqual(v.segments, c.segments) && !prereleaseCheck(v, c) {
return false
}

return true
}

Expand Down
21 changes: 21 additions & 0 deletions version/constraint_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,24 @@ func TestConstraintVersionNumber(t *testing.T) {
assert.True(t, c.Check(Must(NewVersion("1.0.0"))))
assert.False(t, c.Check(Must(NewVersion("1.0.1"))))
}

func TestTildeConstraintPositive(t *testing.T) {
assert.True(t, MustConstraints(NewConstraint("~2.4")).Check(Must(NewVersion("2.9.0"))))
assert.True(t, MustConstraints(NewConstraint("~2.4")).Check(Must(NewVersion("2.4.5"))))

assert.True(t, MustConstraints(NewConstraint("~1")).Check(Must(NewVersion("1.2.3"))))
assert.True(t, MustConstraints(NewConstraint("~1.0")).Check(Must(NewVersion("1.4.7"))))

assert.True(t, MustConstraints(NewConstraint("~1.2.1 >=1.2.3")).Check(Must(NewVersion("1.2.3"))))
assert.True(t, MustConstraints(NewConstraint("~1.2.1 =1.2.3")).Check(Must(NewVersion("1.2.3"))))
assert.True(t, MustConstraints(NewConstraint("~1.2.1 1.2.3")).Check(Must(NewVersion("1.2.3"))))
assert.True(t, MustConstraints(NewConstraint("~1.2.1 >=1.2.3 1.2.3")).Check(Must(NewVersion("1.2.3"))))
assert.True(t, MustConstraints(NewConstraint("~1.2.1 1.2.3 >=1.2.3")).Check(Must(NewVersion("1.2.3"))))
assert.True(t, MustConstraints(NewConstraint("~1.2.1 1.2.3")).Check(Must(NewVersion("1.2.3"))))
}

func TestTildeConstraintNegative(t *testing.T) {
assert.False(t, MustConstraints(NewConstraint("~2.4")).Check(Must(NewVersion("3.0.0"))))
assert.False(t, MustConstraints(NewConstraint("~2.4")).Check(Must(NewVersion("2.3.9"))))
assert.False(t, MustConstraints(NewConstraint("~1")).Check(Must(NewVersion("0.2.3"))))
}

0 comments on commit 070a3f8

Please sign in to comment.