grep: add a test for backreferences in PCRE patterns
authorÆvar Arnfjörð Bjarmason <avarab@gmail.com>
Sat, 20 May 2017 21:42:10 +0000 (21:42 +0000)
committerJunio C Hamano <gitster@pobox.com>
Sat, 20 May 2017 23:25:37 +0000 (08:25 +0900)
Add a test for backreferences such as (.)\1 in PCRE patterns. This
test ensures that the PCRE_NO_AUTO_CAPTURE option isn't turned
on. Before this change turning it on would break these sort of
patterns, but wouldn't break any tests.

Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
t/t7810-grep.sh
index 8d69113695ef600057c92144633cf00cb6bb94ef..daa906b9b0eebd3824141dedcc39c38b7498632f 100755 (executable)
@@ -1114,6 +1114,13 @@ test_expect_success PCRE 'grep -P -w pattern' '
        test_cmp expected actual
 '
 
        test_cmp expected actual
 '
 
+test_expect_success PCRE 'grep -P backreferences work (the PCRE NO_AUTO_CAPTURE flag is not set)' '
+       git grep -P -h "(?P<one>.)(?P=one)" hello_world >actual &&
+       test_cmp hello_world actual &&
+       git grep -P -h "(.)\1" hello_world >actual &&
+       test_cmp hello_world actual
+'
+
 test_expect_success 'grep -G invalidpattern properly dies ' '
        test_must_fail git grep -G "a["
 '
 test_expect_success 'grep -G invalidpattern properly dies ' '
        test_must_fail git grep -G "a["
 '