Skip to content

Commit

Permalink
Merge pull request #100 from liamcervante/liamcervante/constraint-pre…
Browse files Browse the repository at this point in the history
…release

Add Prerelease function onto Constraint struct
  • Loading branch information
liamcervante authored Jun 28, 2022
2 parents b30d5d1 + 53dbf70 commit afc32b7
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 afc32b7

Please sign in to comment.