Commit 9b897f6b authored by Geoff Simmons's avatar Geoff Simmons

test the longest_match option

parent 86d6a633
# looks like -*- vcl -*- # looks like -*- vcl -*-
varnishtest "literal, never_nl, dot_nl, case_sensitive and one_line options" varnishtest "options: literal never_nl dot_nl case_sensitive one_line longest_match"
# Tests from re2 testing/parse_test.cc and testing/re2_test.cc # Tests from re2 testing/parse_test.cc and testing/re2_test.cc
...@@ -24,6 +24,8 @@ varnish v1 -vcl { ...@@ -24,6 +24,8 @@ varnish v1 -vcl {
new case = re2.regex("(?i)([wand]{5})", case_sensitive=true); new case = re2.regex("(?i)([wand]{5})", case_sensitive=true);
new not_one = re2.regex("^a$", posix_syntax=true); new not_one = re2.regex("^a$", posix_syntax=true);
new one = re2.regex("^a$", posix_syntax=true, one_line=true); new one = re2.regex("^a$", posix_syntax=true, one_line=true);
new first = re2.regex("a(b|bb)");
new longest = re2.regex("a(b|bb)", longest_match=true);
} }
sub vcl_recv { sub vcl_recv {
...@@ -88,6 +90,12 @@ a ...@@ -88,6 +90,12 @@ a
a"} )) { a"} )) {
set resp.http.one = "match"; set resp.http.one = "match";
} }
if (first.match("abb")) {
set resp.http.first = first.backref(0);
}
if (longest.match("abb")) {
set resp.http.longest = longest.backref(0);
}
} }
} -start } -start
...@@ -110,6 +118,8 @@ client c1 { ...@@ -110,6 +118,8 @@ client c1 {
expect resp.http.case1 == "Wanda" expect resp.http.case1 == "Wanda"
expect resp.http.not_one == "match" expect resp.http.not_one == "match"
expect resp.http.one == <undef> expect resp.http.one == <undef>
expect resp.http.first == "ab"
expect resp.http.longest == "abb"
} -run } -run
# match() function # match() function
...@@ -183,6 +193,12 @@ a ...@@ -183,6 +193,12 @@ a
a"}, one_line=true)) { a"}, one_line=true)) {
set resp.http.one = "match"; set resp.http.one = "match";
} }
if (re2.match("a(b|bb)", "abb")) {
set resp.http.first = re2.backref(0);
}
if (re2.match("a(b|bb)", "abb", longest_match=true)) {
set resp.http.longest = re2.backref(0);
}
} }
} }
...@@ -301,6 +317,9 @@ a ...@@ -301,6 +317,9 @@ a
a"} )) { a"} )) {
set resp.http.one = "match"; set resp.http.one = "match";
} }
# No test for longest_match, because without backrefs
# we can't distinguish which of two alternatives were
# matched.
} }
} }
...@@ -387,6 +406,9 @@ a"}, rewrite="\1z"), {" ...@@ -387,6 +406,9 @@ a"}, rewrite="\1z"), {"
re2.sub(pattern="^a$", posix_syntax=true, text={"a re2.sub(pattern="^a$", posix_syntax=true, text={"a
a a
a"}, rewrite="z", fallback="fail", one_line=true); a"}, rewrite="z", fallback="fail", one_line=true);
set resp.http.first = re2.sub("a(b|bb)", "abb", "z");
set resp.http.longest = re2.sub("a(b|bb)", "abb", "z",
longest_match=true);
} }
} }
...@@ -406,6 +428,8 @@ client c2 { ...@@ -406,6 +428,8 @@ client c2 {
expect resp.http.case == "A fish named *Arty*" expect resp.http.case == "A fish named *Arty*"
expect resp.http.not_one == "znana" expect resp.http.not_one == "znana"
expect resp.http.one == "fail" expect resp.http.one == "fail"
expect resp.http.first == "zb"
expect resp.http.longest == "z"
} -run } -run
# suball() function # suball() function
...@@ -471,6 +495,9 @@ a"}, rewrite="\1z"), {" ...@@ -471,6 +495,9 @@ a"}, rewrite="\1z"), {"
re2.suball(pattern="^a$", posix_syntax=true, text={"a re2.suball(pattern="^a$", posix_syntax=true, text={"a
a a
a"}, rewrite="z", fallback="fail", one_line=true); a"}, rewrite="z", fallback="fail", one_line=true);
set resp.http.first = re2.suball("a(b|bb)", "abb", "z");
set resp.http.longest = re2.suball("a(b|bb)", "abb", "z",
longest_match=true);
} }
} }
...@@ -489,6 +516,8 @@ client c3 { ...@@ -489,6 +516,8 @@ client c3 {
expect resp.http.case == "A fish named *Arty*" expect resp.http.case == "A fish named *Arty*"
expect resp.http.not_one == "znznz" expect resp.http.not_one == "znznz"
expect resp.http.one == "fail" expect resp.http.one == "fail"
expect resp.http.first == "zb"
expect resp.http.longest == "z"
} -run } -run
# extract() function # extract() function
...@@ -550,6 +579,9 @@ a"}, rewrite="\1z"); ...@@ -550,6 +579,9 @@ a"}, rewrite="\1z");
re2.extract(pattern="^a$", posix_syntax=true, text={"a re2.extract(pattern="^a$", posix_syntax=true, text={"a
a a
a"}, rewrite="z", fallback="fail",one_line=true); a"}, rewrite="z", fallback="fail",one_line=true);
set resp.http.first = re2.extract("a(b|bb)", "abb", "\0:\1");
set resp.http.longest = re2.extract("a(b|bb)", "abb", "\0:\1",
longest_match=true);
} }
} }
...@@ -568,4 +600,6 @@ client c3 { ...@@ -568,4 +600,6 @@ client c3 {
expect resp.http.case == "Arty" expect resp.http.case == "Arty"
expect resp.http.not_one == "z" expect resp.http.not_one == "z"
expect resp.http.one == "fail" expect resp.http.one == "fail"
expect resp.http.first == "ab:b"
expect resp.http.longest == "abb:bb"
} -run } -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