httpserver: add not_ends_with (#1688)

* de-duplicates code for 'not' ops and replicates 'not' op for ends_with

* fixes incorrect test expectations
This commit is contained in:
Connor S. Parks
2017-05-25 13:01:24 +01:00
committed by Matt Holt
parent 33e1560d53
commit 474f119702
2 changed files with 18 additions and 8 deletions
+12 -5
View File
@@ -52,6 +52,7 @@ const (
startsWithOp = "starts_with"
notStartsWithOp = "not_starts_with"
endsWithOp = "ends_with"
notEndsWithOp = "not_ends_with"
matchOp = "match"
notMatchOp = "not_match"
)
@@ -71,6 +72,7 @@ var ifConditions = map[string]ifCondition{
startsWithOp: startsWithFunc,
notStartsWithOp: notStartsWithFunc,
endsWithOp: endsWithFunc,
notEndsWithOp: notEndsWithFunc,
matchOp: matchFunc,
notMatchOp: notMatchFunc,
}
@@ -84,7 +86,7 @@ func isFunc(a, b string) bool {
// notFunc is condition for Not operator.
// It checks for inequality.
func notFunc(a, b string) bool {
return a != b
return !isFunc(a, b)
}
// hasFunc is condition for Has operator.
@@ -96,7 +98,7 @@ func hasFunc(a, b string) bool {
// notHasFunc is condition for NotHas operator.
// It checks if b is not a substring of a.
func notHasFunc(a, b string) bool {
return !strings.Contains(a, b)
return !hasFunc(a, b)
}
// startsWithFunc is condition for StartsWith operator.
@@ -108,7 +110,7 @@ func startsWithFunc(a, b string) bool {
// notStartsWithFunc is condition for NotStartsWith operator.
// It checks if b is not a prefix of a.
func notStartsWithFunc(a, b string) bool {
return !strings.HasPrefix(a, b)
return !startsWithFunc(a, b)
}
// endsWithFunc is condition for EndsWith operator.
@@ -117,6 +119,12 @@ func endsWithFunc(a, b string) bool {
return strings.HasSuffix(a, b)
}
// notEndsWithFunc is condition for NotEndsWith operator.
// It checks if b is not a suffix of a.
func notEndsWithFunc(a, b string) bool {
return !endsWithFunc(a, b)
}
// matchFunc is condition for Match operator.
// It does regexp matching of a against pattern in b
// and returns if they match.
@@ -129,8 +137,7 @@ func matchFunc(a, b string) bool {
// It does regexp matching of a against pattern in b
// and returns if they do not match.
func notMatchFunc(a, b string) bool {
matched, _ := regexp.MatchString(b, a)
return !matched
return !matchFunc(a, b)
}
// ifCond is statement for a IfMatcher condition.