File tree 2 files changed +26
-0
lines changed 2 files changed +26
-0
lines changed Original file line number Diff line number Diff line change @@ -246,3 +246,21 @@ func (and *And) String() string {
246
246
res += ")"
247
247
return res
248
248
}
249
+
250
+ // Not match if Operand does not match and viceversa
251
+ type Not struct {
252
+ Operand Constraint
253
+ }
254
+
255
+ // Match returns ture if v does NOT satisfies the condition
256
+ func (not * Not ) Match (v * Version ) bool {
257
+ return ! not .Operand .Match (v )
258
+ }
259
+
260
+ func (not * Not ) String () string {
261
+ op := not .Operand .String ()
262
+ if op [0 ] != '(' {
263
+ return "!(" + op + ")"
264
+ }
265
+ return "!" + op
266
+ }
Original file line number Diff line number Diff line change @@ -69,6 +69,14 @@ func TestConstraints(t *testing.T) {
69
69
require .False (t , or .Match (v ("2.0.0" )))
70
70
require .True (t , or .Match (v ("2.1.0" )))
71
71
require .Equal (t , "(>2.0.0 || <=1.0.0)" , or .String ())
72
+
73
+ notOr := & Not {or }
74
+ require .False (t , notOr .Match (v ("0.9.0" )))
75
+ require .False (t , notOr .Match (v ("1.0.0" )))
76
+ require .True (t , notOr .Match (v ("1.3.0" )))
77
+ require .True (t , notOr .Match (v ("2.0.0" )))
78
+ require .False (t , notOr .Match (v ("2.1.0" )))
79
+ require .Equal (t , "!(>2.0.0 || <=1.0.0)" , notOr .String ())
72
80
}
73
81
74
82
func TestConstraintsParser (t * testing.T ) {
You can’t perform that action at this time.
0 commit comments