summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorStephane Chazelas <stephane.chazelas@gmail.com>2014-02-25 15:55:04 +0000
committerJim Meyering <meyering@fb.com>2014-02-25 09:53:34 -0800
commit0b5003dd7c485bceba81cf8ffa901f3646c2417d (patch)
treefd696902f342042dcfd412c5d1c43c99b493d536 /tests
parentbc4e0307da6fc43b897e7a16c56b36e7f5990832 (diff)
downloadgrep-0b5003dd7c485bceba81cf8ffa901f3646c2417d.tar.gz
align grep -Pw with grep -w
For the -w option, with -P, we used to look for the pattern surrounded by word boundaries. That's different from what grep -w does and what the documentation describes. Now align with grep -w and the documentation by using PCRE look-behind and look-ahead operators to match the pattern if it is not surrounded by word constituents. * src/pcresearch.c (Pcompile): Use (?<!\w)(?:...)(?!\w) rather than \b(?:...)\b. * NEWS (Bug fixes): Mention it. * tests/pcre-w: New file. * tests/Makefile.am (TESTS): Add it. This complements the fix for http://debbugs.gnu.org/16865
Diffstat (limited to 'tests')
-rw-r--r--tests/Makefile.am1
-rwxr-xr-xtests/pcre-w31
2 files changed, 32 insertions, 0 deletions
diff --git a/tests/Makefile.am b/tests/Makefile.am
index ecbe0e68..742a5804 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -83,6 +83,7 @@ TESTS = \
pcre-abort \
pcre-invalid-utf8-input \
pcre-utf8 \
+ pcre-w \
pcre-wx-backref \
pcre-z \
prefix-of-multibyte \
diff --git a/tests/pcre-w b/tests/pcre-w
new file mode 100755
index 00000000..5040c5a3
--- /dev/null
+++ b/tests/pcre-w
@@ -0,0 +1,31 @@
+#! /bin/sh
+# Before grep-2.19, grep -Pw %% would match %% enclosed in word boundaries
+#
+# Copyright (C) 2014 Free Software Foundation, Inc.
+#
+# Copying and distribution of this file, with or without modification,
+# are permitted in any medium without royalty provided the copyright
+# notice and this notice are preserved.
+
+. "${srcdir=.}/init.sh"; path_prepend_ ../src
+require_pcre_
+
+fail=0
+
+echo %aa% > in || framework_failure_
+grep -Pw aa in > out || fail=1
+compare out in || fail=1
+
+echo a%%a > in || framework_failure_
+grep -Pw %% in > out && fail=1
+compare /dev/null out || fail=1
+
+echo %%%% > in || framework_failure_
+grep -Pw %% in > out || fail=1
+compare out in || fail=1
+
+echo %% > in || framework_failure_
+grep -Pw %% in > out || fail=1
+compare out in || fail=1
+
+Exit $fail