Skip to content

Commit e2b282d

Browse files
authored
Implement Stringer in constraint (#6)
Signed-off-by: Kimmo Lehto <[email protected]>
1 parent beeed05 commit e2b282d

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

constraint.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,15 @@ func MustConstraint(cs string) Constraints {
4747
return c
4848
}
4949

50+
// String returns the constraint as a string.
51+
func (cs Constraints) String() string {
52+
s := make([]string, len(cs))
53+
for i, c := range cs {
54+
s[i] = c.String()
55+
}
56+
return strings.Join(s, ", ")
57+
}
58+
5059
// Check returns true if the given version satisfies all of the constraints.
5160
func (cs Constraints) Check(v *Version) bool {
5261
for _, c := range cs {

constraint_test.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,3 +151,11 @@ func TestCheckString(t *testing.T) {
151151
assert.False(t, c.CheckString("0.9.9"))
152152
assert.False(t, c.CheckString("x"))
153153
}
154+
155+
func TestString(t *testing.T) {
156+
c, err := NewConstraint(">= 1.0.0, < 2.0.0")
157+
assert.NoError(t, err)
158+
159+
assert.Equal(t, ">= 1.0.0, < 2.0.0", c.String())
160+
}
161+

0 commit comments

Comments
 (0)