summaryrefslogtreecommitdiff
path: root/tests/pcre-context
blob: d66bebb6ce2bd29a78d27b24300393934de57f08 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#!/bin/sh
# Test Perl regex with context
. "${srcdir=.}/init.sh"; path_prepend_ ../src
require_pcre_

cat >in <<'EOF'
b0
ab1
aab2
aaab3
aaaab4
EOF
test $? -eq 0 || framework_failure_

cat >exp <<'EOF'
b3
ab4
EOF
test $? -eq 0 || framework_failure_

fail=0

grep -Po '(?<=aaa).*' in >out || fail_ 'grep -Po failed'
compare exp out || fail=1

printf 'NUL preceded by 0 empty lines.\0' >in &&
printf '\nNUL preceded by 1 empty line.\0' >>in &&
printf '\n\nNUL preceded by 2 empty lines.\0' >>in &&
printf '\n\n\nNUL preceded by 3 empty lines.\0' >>in &&
printf '\n\n\n\nNUL preceded by 4 empty lines.\0' >>in &&
printf '\n' >>in || framework_failure_

# This output is not correct as it is missing the expected LF characters,
# but a full fix will have to wait until PCRE2.
printf '%s\0' \
       'NUL preceded by 3 empty lines.' \
       'NUL preceded by 4 empty lines.' >exp || framework_failure_

grep -Pzo '(?<=\n\n\n).*' in >out || fail_ 'grep -Pzo failed'
compare exp out || fail=1

Exit $fail