Skip to content

Commit

Permalink
Add Prerelease function onto Constraint
Browse files Browse the repository at this point in the history
  • Loading branch information
liamcervante committed Jun 27, 2022
1 parent b30d5d1 commit 53dbf70
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
6 changes: 6 additions & 0 deletions constraint.go
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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

0 comments on commit 53dbf70

Please sign in to comment.