Commit 4bcac550 authored by Geoff Simmons's avatar Geoff Simmons

Add tests for sub() when Unicode is enabled.

parent f81d9f81
......@@ -21,22 +21,29 @@ vcc_if.c: vcc_if.h
vcc_if.h vmod_pcre2.man.rst: @VMODTOOL@ $(top_srcdir)/src/vmod_pcre2.vcc
@VMODTOOL@ $(top_srcdir)/src/vmod_pcre2.vcc
VMOD_TESTS = $(builddir)/tests/*.vtc $(builddir)/tests/locale_fr.vtc $(builddir)/tests/compile_utf8.vtc
VMOD_TESTS = $(builddir)/tests/*.vtc \
$(builddir)/tests/locale_fr.vtc \
$(builddir)/tests/compile_utf8.vtc \
$(builddir)/tests/sub_utf8.vtc
.PHONY: $(VMOD_TESTS)
locale_fr:
cp $(top_srcdir)/src/tests/@LOCALE_FR_VTC@ $(top_srcdir)/src/tests/locale_fr.vtc
cp $(builddir)/tests/@LOCALE_FR_VTC@ $(builddir)/tests/locale_fr.vtc
utf8:
cp $(builddir)/tests/compile_utf8.vtc.@PCRE2_UTF8@ $(builddir)/tests/compile_utf8.vtc
cp $(builddir)/tests/compile_utf8.vtc.@PCRE2_UTF8@ \
$(builddir)/tests/compile_utf8.vtc
cp $(builddir)/tests/sub_utf8.vtc.@PCRE2_UTF8@ \
$(builddir)/tests/sub_utf8.vtc
$(builddir)/tests/*.vtc $(builddir)/tests/locale_fr.vtc $(builddir)/tests/compile_utf8.vtc: locale_fr utf8 libvmod_pcre2.la
$(VMOD_TESTS): locale_fr utf8 libvmod_pcre2.la
PATH=@LIBVARNISHAPI_SBINDIR@:$$PATH \
@VARNISHTEST@ -Dvmod_topbuild=$(abs_top_builddir) $@
check: $(VMOD_TESTS)
rm $(top_srcdir)/src/tests/locale_fr.vtc
rm $(builddir)/tests/locale_fr.vtc
rm $(builddir)/tests/compile_utf8.vtc
rm $(builddir)/tests/sub_utf8.vtc
EXTRA_DIST = \
vmod_pcre2.vcc \
......
varnishtest "not testing substitutions with UTF-8"
# If Unicode is disabled for libpcre2, then this test is run as
# sub_utf8.vtc, and does nothing.
# -*-mode: vcl; coding: raw-text;-*-
varnishtest "substitutions with UTF-8"
# This test is only run if Unicode is enabled for libpcre2.
# Tests from PCRE2 testoutput5 and testoutput10
# Test r5 uses the extended sub syntax, including strings of the form
# ${...}. varnishtest interprets them as macros in a vtc script and
# rejects the test, so we include the line from another file.
varnish v1 -vcl {
import pcre2 from "${vmod_topbuild}/src/.libs/libvmod_pcre2.so";
backend b { .host = "${bad_ip}"; }
sub vcl_init {
new r1 = pcre2.regex("ábc", utf=true);
new r2 = pcre2.regex("(?<=abc)(|def)", utf=true);
new r3 = pcre2.regex("abcd", utf=true);
new r4
= pcre2.regex("a(\x{e0}\x{101})(\x{c0}\x{102})", utf=true);
new r5
= pcre2.regex("((?<digit>\d)|(?<letter>\p{L}))", utf=true);
new r6 = pcre2.regex("abc", utf=true);
}
sub vcl_recv {
return(synth(200));
}
sub vcl_synth {
set resp.http.r1 = r1.sub("123ábc123", "XሴZ");
set resp.http.r2
= r2.sub("123abcáyzabcdef789abcሴqr",
"<$0>", suball=true);
set resp.http.r3
= r3.sub("abcd", "x\x{824}y\o{3333}z(\Q12\$34$$\x34\E5$$)",
sub_extended=true);
set resp.http.r4 = r4.sub("aàāÀĂ",
"a\u$1\U$1\E$1\l$2\L$2\Eab\U\x{e0}\x{101}\L\x{d0}\x{160}\EDone",
sub_extended=true);
include "${vmod_topbuild}/src/tests/sub_utf8_macro.vcl";
set resp.http.r6 = r6.sub("abc", "");
return(deliver);
}
} -start
client c1 {
txreq
rxresp
expect resp.status == "200"
expect resp.http.r1 == "123XሴZ123"
expect resp.http.r2 == "123abc<>áyzabc<><def>789abc<>ሴqr"
expect resp.http.r3 == {xࠤyۛz(12\$34$$\x345$)}
expect resp.http.r4 == {aÀāÀĀàāàĂàăabÀĀðšDone}
expect resp.http.r5 == "<not digit; letter><not digit; letter><digit; not a letter><digit; not a letter><not digit; letter><not digit; letter><not digit; letter>"
expect resp.http.r6 == ""
} -run
# This line is included from sub_utf8.vtc.yes, run as sub_utf8.vtc
# when Unicode is enabled for libpcre2. The extended syntax for pcre2
# substitutions includes the form ${...}, which varnishtest always
# interprets as a macro in a vtc script. So this snippet is included
# as a workaround.
set resp.http.r5 = r5.sub("ab12cde", suball=true, replacement=
"<${digit:+digit; :not digit; }${letter:+letter:not a letter}>",
sub_extended=true);
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