Commit c92d31ec authored by Geoff Simmons's avatar Geoff Simmons

add tests for the suball() function to options.vtc

parent 8fc8bdc6
......@@ -407,3 +407,89 @@ client c2 {
expect resp.http.not_one == "znana"
expect resp.http.one == "fail"
} -run
# suball() function
varnish v1 -vcl {
import re2 from "${vmod_topbuild}/src/.libs/libvmod_re2.so";
backend b { .host = "${bad_ip}"; }
sub vcl_recv {
return(synth(200));
}
sub vcl_synth {
set resp.http.literal =
re2.suball("(|)^$.[*+?]{5,10},\\",
"(|)^$.[*+?]{5,10},\\",
"z", literal=true);
# regsub() the newlines that appear in the header, so as not
# not to disrupt the HTTP protocol (otherwise, two newlines
# are parsed as ending the response header).
set resp.http.never1 =
regsuball(re2.suball(pattern="(.*)", never_nl=true,
text={"abc
def
ghi
"}, rewrite="\1z"), {"
"}, "n");
set resp.http.never2 =
re2.suball("(?s)(abc.*def)", {"abc
def
"}, "z", fallback="fallback", never_nl=true);
set resp.http.never3 =
re2.suball(pattern={"(abc(.|
)def)"}, never_nl=true, text={"abc
def
"}, rewrite="z", fallback="fallback");
set resp.http.never4 =
re2.suball("(abc[^x]*def)", {"abc
def
"}, "z", "fallback", never_nl=true);
set resp.http.never5 =
regsuball(re2.suball("(abc[^x]*def)", {"abczzzdef
def
"}, "\1q", never_nl=true), {"
"}, "n");
set resp.http.dot1 =
re2.suball(pattern=".", dot_nl=true, text={"
"}, rewrite="z");
set resp.http.dot2 =
re2.suball(pattern="(?-s).", dot_nl=true, text={"
"}, rewrite="z", fallback="fallback");
set resp.http.dot3 =
re2.suball(pattern=".", dot_nl=true, never_nl=true, text={"
"}, rewrite="z", fallback="fallback");
set resp.http.case =
re2.suball("(?i)([wand]{5})", "A fish named *Wanda*",
"Arty", case_sensitive=true);
set resp.http.not_one =
regsuball(re2.suball(pattern="^a$", posix_syntax=true,
text={"a
a
a"}, rewrite="\1z"), {"
"}, "n");
set resp.http.one =
re2.suball(pattern="^a$", posix_syntax=true, text={"a
a
a"}, rewrite="z", fallback="fail", one_line=true);
}
}
client c3 {
txreq
rxresp
expect resp.http.literal == "z"
expect resp.http.never1 == "abczndefznghiznz"
expect resp.http.never2 == "fallback"
expect resp.http.never3 == "fallback"
expect resp.http.never4 == "fallback"
expect resp.http.never5 == "abczzzdefqndefn"
expect resp.http.dot1 == "z"
expect resp.http.dot2 == "fallback"
expect resp.http.dot3 == "fallback"
expect resp.http.case == "A fish named *Arty*"
expect resp.http.not_one == "znznz"
expect resp.http.one == "fail"
} -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