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

Fix the handling of pre-releases and the 0.0.0 release edge case #70

Merged
merged 1 commit into from
Apr 10, 2018
Merged
Show file tree
Hide file tree
Changes from all 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
20 changes: 0 additions & 20 deletions constraints.go
Original file line number Diff line number Diff line change
Expand Up @@ -233,12 +233,6 @@ func constraintNotEqual(v *Version, c *constraint) bool {

func constraintGreaterThan(v *Version, c *constraint) bool {

// An edge case the constraint is 0.0.0 and the version is 0.0.0-someprerelease
// exists. This that case.
if !isNonZero(c.con) && isNonZero(v) {
return true
}

// If there is a pre-release on the version but the constraint isn't looking
// for them assume that pre-releases are not compatible. See issue 21 for
// more details.
Expand Down Expand Up @@ -271,11 +265,6 @@ func constraintLessThan(v *Version, c *constraint) bool {
}

func constraintGreaterThanEqual(v *Version, c *constraint) bool {
// An edge case the constraint is 0.0.0 and the version is 0.0.0-someprerelease
// exists. This that case.
if !isNonZero(c.con) && isNonZero(v) {
return true
}

// If there is a pre-release on the version but the constraint isn't looking
// for them assume that pre-releases are not compatible. See issue 21 for
Expand Down Expand Up @@ -415,12 +404,3 @@ func rewriteRange(i string) string {

return o
}

// Detect if a version is not zero (0.0.0)
func isNonZero(v *Version) bool {
if v.Major() != 0 || v.Minor() != 0 || v.Patch() != 0 || v.Prerelease() != "" {
return true
}

return false
}
16 changes: 14 additions & 2 deletions constraints_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,21 @@ func TestConstraintCheck(t *testing.T) {
{"<=1.1", "0.1.0", true},
{"<=1.1", "1.1.0", true},
{"<=1.1", "1.1.1", false},
{">0", "0.0.1-alpha", true},
{">=0", "0.0.1-alpha", true},
{">0", "0", false},
{">0", "0.0.1-alpha", false},
{">0.0", "0.0.1-alpha", false},
{">0-0", "0.0.1-alpha", true},
{">0.0-0", "0.0.1-alpha", true},

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm curious to know if the following test cases also succeed. They should right?

{">0.0.0", "0.0.1-alpha", false},
{">0.0.0-0", "0.0.1-alpha", true},

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes.

{">0", "0.0.0-alpha", false},
{">0-0", "0.0.0-alpha", true},
{">=0", "0.0.1-alpha", false},
{">=0.0", "0.0.1-alpha", false},
{">=0-0", "0.0.1-alpha", true},
{">=0.0-0", "0.0.1-alpha", true},
{">=0", "0.0.0-alpha", false},
{">=0-0", "0.0.0-alpha", true},
{"<0", "0.0.0-alpha", false},

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Confused about this test ({"<0", "0.0.0-alpha", false}), especially because {">=0", "0.0.0-alpha", false}

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Without a pre-release in the comparator (e.g., <0, >=0) you'll find all pre-release values are ignored. That's why they are false.

{"<0-z", "0.0.0-alpha", true},
{">=0", "0", true},
{"=0", "1", false},
}
Expand Down