diff --git a/constraint.go b/constraint.go index 1d88090..8d7b24a 100644 --- a/constraint.go +++ b/constraint.go @@ -46,6 +46,8 @@ func init() { ">=": {op: greaterThanEqual, f: constraintGreaterThanEqual}, "<=": {op: lessThanEqual, f: constraintLessThanEqual}, "~>": {op: pessimistic, f: constraintPessimistic}, + "^": {op: caret, f: constraintCaret}, + "~": {op: tilde, f: constraintTilde}, } ops := make([]string, 0, len(constraintOperators)) @@ -221,7 +223,9 @@ const ( lessThan operator = '<' greaterThanEqual operator = '≥' lessThanEqual operator = '≤' - pessimistic operator = '~' + pessimistic operator = '≳' + caret operator = '^' + tilde operator = '~' ) func constraintEqual(v, c *Version) bool { @@ -288,3 +292,31 @@ func constraintPessimistic(v, c *Version) bool { // If nothing has rejected the version by now, it's valid return true } + +func constraintCaret(v, c *Version) bool { + if !prereleaseCheck(v, c) || v.LessThan(c) { + return false + } + + if v.segments[0] != c.segments[0] { + return false + } + + return true +} + +func constraintTilde(v, c *Version) bool { + if !prereleaseCheck(v, c) || v.LessThan(c) { + return false + } + + if v.segments[0] != c.segments[0] { + return false + } + + if v.segments[1] != c.segments[1] && c.si > 1 { + return false + } + + return true +} diff --git a/constraint_test.go b/constraint_test.go index a6f90d7..17ee339 100644 --- a/constraint_test.go +++ b/constraint_test.go @@ -78,6 +78,19 @@ func TestConstraintCheck(t *testing.T) { {">= 2.1.0-a", "2.1.1-beta", false}, {">= 2.1.0-a", "2.1.0", true}, {"<= 2.1.0-a", "2.0.0", true}, + {"^1.1", "1.1.1", true}, + {"^1.1", "1.2.3", true}, + {"^1.1", "2.1.0", false}, + {"^1.1.2", "1.1.1", false}, + {"^1.1.2", "1.1.2", true}, + {"^1.1.2", "1.1.2.3", true}, + {"~1", "1.3.5", true}, + {"~1", "2.1.0", false}, + {"~1.1", "1.1.1", true}, + {"~1.1", "1.2.3", false}, + {"~1.1.2", "1.1.1", false}, + {"~1.1.2", "1.1.2", true}, + {"~1.1.2", "1.1.2.3", true}, } for _, tc := range cases {