aboutsummaryrefslogtreecommitdiff
path: root/lib/libc/tests/regex
diff options
context:
space:
mode:
Diffstat (limited to 'lib/libc/tests/regex')
-rw-r--r--lib/libc/tests/regex/Makefile8
-rw-r--r--lib/libc/tests/regex/Makefile.depend19
-rw-r--r--lib/libc/tests/regex/Makefile.inc56
-rwxr-xr-xlib/libc/tests/regex/multibyte.sh93
4 files changed, 176 insertions, 0 deletions
diff --git a/lib/libc/tests/regex/Makefile b/lib/libc/tests/regex/Makefile
new file mode 100644
index 000000000000..65675d94c59c
--- /dev/null
+++ b/lib/libc/tests/regex/Makefile
@@ -0,0 +1,8 @@
+PACKAGE= tests
+
+# local test cases
+ATF_TESTS_SH+= multibyte
+
+.include "Makefile.inc"
+.include "${.CURDIR:H}/Makefile.netbsd-tests"
+.include <bsd.test.mk>
diff --git a/lib/libc/tests/regex/Makefile.depend b/lib/libc/tests/regex/Makefile.depend
new file mode 100644
index 000000000000..9df74fa6efd2
--- /dev/null
+++ b/lib/libc/tests/regex/Makefile.depend
@@ -0,0 +1,19 @@
+# Autogenerated - do NOT edit!
+
+DIRDEPS = \
+ gnu/lib/csu \
+ include \
+ include/xlocale \
+ lib/${CSU_DIR} \
+ lib/atf/libatf-c \
+ lib/libc \
+ lib/libcompiler_rt \
+ lib/libnetbsd \
+ lib/libutil \
+
+
+.include <dirdeps.mk>
+
+.if ${DEP_RELDIR} == ${_DEP_RELDIR}
+# local dependencies - needed for -jN in clean tree
+.endif
diff --git a/lib/libc/tests/regex/Makefile.inc b/lib/libc/tests/regex/Makefile.inc
new file mode 100644
index 000000000000..aca7ae47be18
--- /dev/null
+++ b/lib/libc/tests/regex/Makefile.inc
@@ -0,0 +1,56 @@
+.include <bsd.own.mk>
+
+BINDIR?= ${TESTSDIR}
+WARNS?= 3
+
+# SKIP_LEFTASSOC -> these testcases fail on FreeBSD.
+IMPLEMENTATION?= -DREGEX_SPENCER -DSKIP_LEFTASSOC
+
+CFLAGS.h_regex+=-I${TESTSRC} -I${SRCTOP}/lib/libc/regex
+PROGS+= h_regex
+SRCS.h_regex= main.c split.c debug.c
+
+NETBSD_ATF_TESTS_SH= regex_test
+
+${PACKAGE}FILES+= README
+
+FILESGROUPS+= ${PACKAGE}DATA_FILES
+${PACKAGE}DATA_FILESPACKAGE=${PACKAGE}
+
+${PACKAGE}DATA_FILESDIR= ${TESTSDIR}/data
+${PACKAGE}DATA_FILES+= data/anchor.in
+${PACKAGE}DATA_FILES+= data/backref.in
+${PACKAGE}DATA_FILES+= data/basic.in
+${PACKAGE}DATA_FILES+= data/bracket.in
+${PACKAGE}DATA_FILES+= data/c_comments.in
+${PACKAGE}DATA_FILES+= data/complex.in
+${PACKAGE}DATA_FILES+= data/error.in
+${PACKAGE}DATA_FILES+= data/meta.in
+${PACKAGE}DATA_FILES+= data/nospec.in
+${PACKAGE}DATA_FILES+= data/paren.in
+${PACKAGE}DATA_FILES+= data/regress.in
+${PACKAGE}DATA_FILES+= data/repet_bounded.in
+${PACKAGE}DATA_FILES+= data/repet_multi.in
+${PACKAGE}DATA_FILES+= data/repet_ordinary.in
+${PACKAGE}DATA_FILES+= data/startend.in
+${PACKAGE}DATA_FILES+= data/subexp.in
+${PACKAGE}DATA_FILES+= data/subtle.in
+${PACKAGE}DATA_FILES+= data/word_bound.in
+${PACKAGE}DATA_FILES+= data/zero.in
+#${PACKAGE}DATA_FILES+= data/att/README
+${PACKAGE}DATA_FILES+= data/att/basic.dat
+${PACKAGE}DATA_FILES+= data/att/categorization.dat
+${PACKAGE}DATA_FILES+= data/att/forcedassoc.dat
+${PACKAGE}DATA_FILES+= data/att/leftassoc.dat
+${PACKAGE}DATA_FILES+= data/att/nullsubexpr.dat
+${PACKAGE}DATA_FILES+= data/att/repetition.dat
+${PACKAGE}DATA_FILES+= data/att/rightassoc.dat
+
+NETBSD_ATF_TESTS_C= exhaust_test
+NETBSD_ATF_TESTS_C+= regex_att_test
+
+.for t in ${NETBSD_ATF_TESTS_C}
+CFLAGS.$t+= -I${TESTSRC} ${IMPLEMENTATION}
+.endfor
+
+LIBADD.regex_att_test+= util
diff --git a/lib/libc/tests/regex/multibyte.sh b/lib/libc/tests/regex/multibyte.sh
new file mode 100755
index 000000000000..18323f500a2b
--- /dev/null
+++ b/lib/libc/tests/regex/multibyte.sh
@@ -0,0 +1,93 @@
+atf_test_case bmpat
+bmpat_head()
+{
+ atf_set "descr" "Check matching multibyte characters (PR153502)"
+}
+bmpat_body()
+{
+ export LC_CTYPE="C.UTF-8"
+
+ printf 'é' | atf_check -o "inline:é" \
+ sed -ne '/^.$/p'
+ printf 'éé' | atf_check -o "inline:éé" \
+ sed -ne '/^..$/p'
+ printf 'aéa' | atf_check -o "inline:aéa" \
+ sed -ne '/a.a/p'
+ printf 'aéa'| atf_check -o "inline:aéa" \
+ sed -ne '/a.*a/p'
+ printf 'aaéaa' | atf_check -o "inline:aaéaa" \
+ sed -ne '/aa.aa/p'
+ printf 'aéaéa' | atf_check -o "inline:aéaéa" \
+ sed -ne '/a.a.a/p'
+ printf 'éa' | atf_check -o "inline:éa" \
+ sed -ne '/.a/p'
+ printf 'aéaa' | atf_check -o "inline:aéaa" \
+ sed -ne '/a.aa/p'
+ printf 'éaé' | atf_check -o "inline:éaé" \
+ sed -ne '/.a./p'
+}
+
+atf_test_case icase
+icase_head()
+{
+ atf_set "descr" "Check case-insensitive matching for characters 128-255"
+}
+icase_body()
+{
+ export LC_CTYPE="C.UTF-8"
+
+ a=$(printf '\302\265\n') # U+00B5
+ b=$(printf '\316\234\n') # U+039C
+ c=$(printf '\316\274\n') # U+03BC
+
+ echo $b | atf_check -o "inline:$b\n" sed -ne "/$a/Ip"
+ echo $c | atf_check -o "inline:$c\n" sed -ne "/$a/Ip"
+}
+
+atf_test_case mbset cleanup
+mbset_head()
+{
+ atf_set "descr" "Check multibyte sets matching"
+}
+mbset_body()
+{
+ export LC_CTYPE="C.UTF-8"
+
+ # This involved an erroneously implemented optimization which reduces
+ # single-element sets to an exact match with a single codepoint.
+ # Match sets record small-codepoint characters in a bitmap and
+ # large-codepoint characters in an array; the optimization would falsely
+ # trigger if either the bitmap or the array was a singleton, ignoring
+ # the members of the other side of the set.
+ #
+ # To exercise this, we construct sets which have one member of one side
+ # and one or more of the other, and verify that all members can be
+ # found.
+ printf "a" > mbset; atf_check -o not-empty sed -ne '/[aà]/p' mbset
+ printf "à" > mbset; atf_check -o not-empty sed -ne '/[aà]/p' mbset
+ printf "a" > mbset; atf_check -o not-empty sed -ne '/[aàá]/p' mbset
+ printf "à" > mbset; atf_check -o not-empty sed -ne '/[aàá]/p' mbset
+ printf "á" > mbset; atf_check -o not-empty sed -ne '/[aàá]/p' mbset
+ printf "à" > mbset; atf_check -o not-empty sed -ne '/[abà]/p' mbset
+ printf "a" > mbset; atf_check -o not-empty sed -ne '/[abà]/p' mbset
+ printf "b" > mbset; atf_check -o not-empty sed -ne '/[abà]/p' mbset
+ printf "a" > mbset; atf_check -o not-empty sed -Ene '/[aà]/p' mbset
+ printf "à" > mbset; atf_check -o not-empty sed -Ene '/[aà]/p' mbset
+ printf "a" > mbset; atf_check -o not-empty sed -Ene '/[aàá]/p' mbset
+ printf "à" > mbset; atf_check -o not-empty sed -Ene '/[aàá]/p' mbset
+ printf "á" > mbset; atf_check -o not-empty sed -Ene '/[aàá]/p' mbset
+ printf "à" > mbset; atf_check -o not-empty sed -Ene '/[abà]/p' mbset
+ printf "a" > mbset; atf_check -o not-empty sed -Ene '/[abà]/p' mbset
+ printf "b" > mbset; atf_check -o not-empty sed -Ene '/[abà]/p' mbset
+}
+mbset_cleanup()
+{
+ rm -f mbset
+}
+
+atf_init_test_cases()
+{
+ atf_add_test_case bmpat
+ atf_add_test_case icase
+ atf_add_test_case mbset
+}