Commit 7cc8686d authored by Geoff Simmons's avatar Geoff Simmons

add tests for suball() to vcl_regex.vtc

parent a0bda08d
......@@ -2,7 +2,7 @@
varnishtest "backrefs not affected by standard VCL regex code"
varnish v1 -vcl+backend {
varnish v1 -vcl {
import re2 from "${vmod_topbuild}/src/.libs/libvmod_re2.so";
backend b { .host = "${bad_ip}"; }
......@@ -23,8 +23,6 @@ varnish v1 -vcl+backend {
if (resp.http.foo ~ "bar(baz)") {
set resp.http.tilde0 = barbaz.backref(0, "tilde0");
set resp.http.tilde1 = barbaz.backref(1, "tilde1");
set resp.http.tildesub =
barbaz.sub(resp.http.foo, "\0\1", "tildesub");
} else {
set resp.status = 999;
}
......@@ -32,8 +30,6 @@ varnish v1 -vcl+backend {
if (resp.http.foo !~ "bar(quux)") {
set resp.http.neg0 = barbaz.backref(0, "neg0");
set resp.http.neg1 = barbaz.backref(1, "neg1");
set resp.http.negsub =
barbaz.sub(resp.http.foo, "\0\1", "negsub");
} else {
set resp.status = 999;
}
......@@ -42,17 +38,12 @@ varnish v1 -vcl+backend {
= regsub(resp.http.foo, "bar(baz)", "\1");
set resp.http.regsub0 = barbaz.backref(0, "regsub0");
set resp.http.regsub1 = barbaz.backref(1, "regsub1");
set resp.http.regsubsub = barbaz.sub(resp.http.foo, "\0\1",
"regsubsub");
set resp.http.regsuball
= regsuball(resp.http.foo, "(.)", "x");
set resp.http.regsuball0 = barbaz.backref(0, "regsuball0");
set resp.http.regsuball1 = barbaz.backref(1, "regsuball1");
set resp.http.regsuballsub = barbaz.sub(resp.http.foo, "\0\1",
"regsuballsub");
}
} -start
client c1 {
......@@ -61,23 +52,19 @@ client c1 {
expect resp.status == 200
expect resp.http.tilde0 == "barbaz"
expect resp.http.tilde1 == "bar"
expect resp.http.tildesub == "barbazbar"
expect resp.http.neg0 == "barbaz"
expect resp.http.neg1 == "bar"
expect resp.http.negsub == "barbazbar"
expect resp.http.regsub == "baz"
expect resp.http.regsub0 == "barbaz"
expect resp.http.regsub1 == "bar"
expect resp.http.regsubsub == "barbazbar"
expect resp.http.regsuball == "xxxxxx"
expect resp.http.regsuball0 == "barbaz"
expect resp.http.regsuball1 == "bar"
expect resp.http.regsuballsub == "barbazbar"
} -run
# Function interface
# match() function
varnish v1 -vcl+backend {
varnish v1 -vcl {
import re2 from "${vmod_topbuild}/src/.libs/libvmod_re2.so";
backend b { .host = "${bad_ip}"; }
......@@ -115,21 +102,114 @@ varnish v1 -vcl+backend {
set resp.http.regsuball0 = re2.backref(0, "regsuball0");
set resp.http.regsuball1 = re2.backref(1, "regsuball1");
}
}
client c1 -run
# sub() function
varnish v1 -vcl {
import re2 from "${vmod_topbuild}/src/.libs/libvmod_re2.so";
backend b { .host = "${bad_ip}"; }
sub vcl_init {
new barbaz = re2.regex("(bar)baz");
}
sub vcl_recv {
return(synth(200));
}
sub vcl_synth {
set resp.http.foo = "barbaz";
if (!barbaz.match(resp.http.foo)) {
set resp.status = 999;
}
if (resp.http.foo ~ "bar(baz)") {
set resp.http.tilde =
barbaz.sub(resp.http.foo, "\0\1", "tildesub");
} else {
set resp.status = 999;
}
if (resp.http.foo !~ "bar(quux)") {
set resp.http.neg =
barbaz.sub(resp.http.foo, "\0\1", "negsub");
} else {
set resp.status = 999;
}
set resp.http.regsub
= regsub(resp.http.foo, "bar(baz)", "\1");
set resp.http.regsubsub = barbaz.sub(resp.http.foo, "\0\1",
"regsubsub");
set resp.http.regsuball
= regsuball(resp.http.foo, "(.)", "x");
set resp.http.regsuballsub = barbaz.sub(resp.http.foo, "\0\1",
"regsuballsub");
}
}
client c1 {
client c2 {
txreq
rxresp
expect resp.status == 200
expect resp.http.tilde0 == "barbaz"
expect resp.http.tilde1 == "bar"
expect resp.http.neg0 == "barbaz"
expect resp.http.neg1 == "bar"
expect resp.http.tilde == "barbazbar"
expect resp.http.neg == "barbazbar"
expect resp.http.regsub == "baz"
expect resp.http.regsub0 == "barbaz"
expect resp.http.regsub1 == "bar"
expect resp.http.regsubsub == "barbazbar"
expect resp.http.regsuball == "xxxxxx"
expect resp.http.regsuball0 == "barbaz"
expect resp.http.regsuball1 == "bar"
expect resp.http.regsuballsub == "barbazbar"
} -run
# suball() function
varnish v1 -vcl {
import re2 from "${vmod_topbuild}/src/.libs/libvmod_re2.so";
backend b { .host = "${bad_ip}"; }
sub vcl_init {
new barbaz = re2.regex("(bar)baz");
}
sub vcl_recv {
return(synth(200));
}
sub vcl_synth {
set resp.http.foo = "barbaz";
if (!barbaz.match(resp.http.foo)) {
set resp.status = 999;
}
if (resp.http.foo ~ "bar(baz)") {
set resp.http.tilde =
barbaz.suball(resp.http.foo, "\0\1",
"tildesub");
} else {
set resp.status = 999;
}
if (resp.http.foo !~ "bar(quux)") {
set resp.http.neg =
barbaz.suball(resp.http.foo, "\0\1", "negsub");
} else {
set resp.status = 999;
}
set resp.http.regsub
= regsub(resp.http.foo, "bar(baz)", "\1");
set resp.http.regsubsub = barbaz.suball(resp.http.foo, "\0\1",
"regsubsub");
set resp.http.regsuball
= regsuball(resp.http.foo, "(.)", "x");
set resp.http.regsuballsub = barbaz.suball(resp.http.foo,
"\0\1",
"regsuballsub");
}
}
client c2 -run
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