File tree 2 files changed +34
-0
lines changed 2 files changed +34
-0
lines changed Original file line number Diff line number Diff line change @@ -163,6 +163,12 @@ func (c *Constraint) Check(v *Version) bool {
163
163
return c .f (v , c .check )
164
164
}
165
165
166
+ // Prerelease returns true if the version underlying this constraint
167
+ // contains a prerelease field.
168
+ func (c * Constraint ) Prerelease () bool {
169
+ return len (c .check .Prerelease ()) > 0
170
+ }
171
+
166
172
func (c * Constraint ) String () string {
167
173
return c .original
168
174
}
Original file line number Diff line number Diff line change @@ -100,6 +100,34 @@ func TestConstraintCheck(t *testing.T) {
100
100
}
101
101
}
102
102
103
+ func TestConstraintPrerelease (t * testing.T ) {
104
+ cases := []struct {
105
+ constraint string
106
+ prerelease bool
107
+ }{
108
+ {"= 1.0" , false },
109
+ {"= 1.0-beta" , true },
110
+ {"~> 2.1.0" , false },
111
+ {"~> 2.1.0-dev" , true },
112
+ {"> 2.0" , false },
113
+ {">= 2.1.0-a" , true },
114
+ }
115
+
116
+ for _ , tc := range cases {
117
+ c , err := parseSingle (tc .constraint )
118
+ if err != nil {
119
+ t .Fatalf ("err: %s" , err )
120
+ }
121
+
122
+ actual := c .Prerelease ()
123
+ expected := tc .prerelease
124
+ if actual != expected {
125
+ t .Fatalf ("Constraint: %s\n Expected: %#v" ,
126
+ tc .constraint , expected )
127
+ }
128
+ }
129
+ }
130
+
103
131
func TestConstraintEqual (t * testing.T ) {
104
132
cases := []struct {
105
133
leftConstraint string
You can’t perform that action at this time.
0 commit comments