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 Prerelease function onto Constraint struct #100

Merged
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 6 additions & 0 deletions constraint.go
Expand Up @@ -163,6 +163,12 @@ func (c *Constraint) Check(v *Version) bool {
return c.f(v, c.check)
}

// Prerelease returns true if the version underlying this constraint
// contains a prerelease field.
func (c *Constraint) Prerelease() bool {
return len(c.check.Prerelease()) > 0
}

func (c *Constraint) String() string {
return c.original
}
Expand Down
28 changes: 28 additions & 0 deletions constraint_test.go
Expand Up @@ -100,6 +100,34 @@ func TestConstraintCheck(t *testing.T) {
}
}

func TestConstraintPrerelease(t *testing.T) {
cases := []struct {
constraint string
prerelease bool
}{
{"= 1.0", false},
{"= 1.0-beta", true},
{"~> 2.1.0", false},
{"~> 2.1.0-dev", true},
{"> 2.0", false},
{">= 2.1.0-a", true},
}

for _, tc := range cases {
c, err := parseSingle(tc.constraint)
if err != nil {
t.Fatalf("err: %s", err)
}

actual := c.Prerelease()
expected := tc.prerelease
if actual != expected {
t.Fatalf("Constraint: %s\nExpected: %#v",
tc.constraint, expected)
}
}
}

func TestConstraintEqual(t *testing.T) {
cases := []struct {
leftConstraint string
Expand Down