Commit 7c3ab258 authored by Federico G. Schwindt's avatar Federico G. Schwindt

Allow duration types in boolean contexts

Polish test while here.
parent e8420fd1
......@@ -78,11 +78,6 @@ varnish v1 -errvcl {Unknown time unit 'k'. Legal are 'ms', 's', 'm', 'h', 'd',
sub vcl_backend_response { set beresp.ttl = 1. k; }
}
varnish v1 -errvcl {Expression has type DURATION, expected BOOL} {
backend b { .host = "127.0.0.1"; }
sub vcl_backend_response { if (beresp.ttl *= 2) { } }
}
varnish v1 -errvcl {Operator > not possible on BACKEND} {
backend a { .host = "127.0.0.1"; }
backend b { .host = "127.0.0.1"; }
......
......@@ -58,14 +58,6 @@ varnish v1 -errvcl {Unknown token '-' when looking for DURATION} {
}
}
varnish v1 -errvcl {'&&' must be followed by BOOL, found DURATION.} {
sub vcl_recv {
if (req.ttl < 3s && req.ttl) {
set req.http.foo = vcl_recv;
}
}
}
varnish v1 -errvcl {Operator * not possible on type STRING.} {
sub vcl_recv {
set req.http.foo = "bla" * "foo";
......@@ -78,13 +70,6 @@ varnish v1 -errvcl {DURATION + INT not possible.} {
}
}
varnish v1 -errvcl {'!' must be followed by BOOL, found DURATION.} {
sub vcl_backend_response {
if (! req.ttl) {
}
}
}
varnish v1 -errvcl {BOOL + BOOL not possible.} {
sub vcl_backend_response {
if (beresp.do_gzip + beresp.do_gunzip) {
......@@ -124,16 +109,11 @@ varnish v1 -vcl {
set req.http.foo = req.http.foo + "bar" !~ "bar";
set req.ttl = 1s;
}
}
if (req.ttl) { }
if (!req.ttl) { }
varnish v1 -vcl {
import std;
backend b { .host = "127.0.0.1"; }
sub vcl_recv {
if (std.integer("1", 1)) {
}
if (1) { }
}
}
......@@ -251,22 +231,6 @@ varnish v1 -errvcl {DURATION + STRING not possible.} {
}
}
varnish v1 -errvcl {'||' must be followed by BOOL, found DURATION.} {
backend b { .host = "127.0.0.1"; }
sub vcl_backend_response {
if (req.url || beresp.ttl) {
}
}
}
varnish v1 -errvcl {'&&' must be followed by BOOL, found DURATION.} {
backend b { .host = "127.0.0.1"; }
sub vcl_backend_response {
if (req.url && beresp.ttl) {
}
}
}
varnish v1 -vcl {
backend b { .host = "127.0.0.1"; }
sub vcl_miss {
......
......@@ -93,7 +93,8 @@ their value.
String types will evaluate to *false* if they are empty; backend types
will evalute to *false* if they don't have a backend assigned; integer
types will evaluate to *false* if their value is zero.
types will evaluate to *false* if their value is zero; duration types
will evaluate to *false* if their value is equal or less than zero.
Time
~~~~
......
......@@ -1200,12 +1200,12 @@ vcc_expr_cmp(struct vcc *tl, struct expr **e, vcc_type_t fmt)
default:
break;
}
if (fmt == BOOL &&
((*e)->fmt == STRING || (*e)->fmt == BACKEND ||
(*e)->fmt == INT)) {
*e = vcc_expr_edit(BOOL, "(\v1 != 0)", *e, NULL);
if (fmt != BOOL)
return;
}
if ((*e)->fmt == STRING || (*e)->fmt == BACKEND || (*e)->fmt == INT)
*e = vcc_expr_edit(BOOL, "(\v1 != 0)", *e, NULL);
else if ((*e)->fmt == DURATION)
*e = vcc_expr_edit(BOOL, "(\v1 > 0)", *e, NULL);
}
/*--------------------------------------------------------------------
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment