# Copyright 2018-2025 Free Software Foundation, Inc.
#
# Copying and distribution of this file, with or without modification,
# in any medium, are permitted without royalty provided the copyright
# notice and this notice are preserved.

. $srcdir/test-lib.sh

require cat
require ed
use_local_patch
use_tmpdir

# ==============================================================

cat > ed1.diff <<EOF
0a
foo
.
EOF

check 'patch -e foo -i ed1.diff' <<EOF
EOF

check 'cat foo' <<EOF
foo
EOF

cat > ed2.diff <<EOF
1337a
r !echo bar
,p
EOF

check 'patch -e foo -i ed2.diff > /dev/null 2> /dev/null || echo "Status: $?"' <<EOF
Status: 2
EOF

check 'cat foo' <<EOF
foo
EOF

# Test the case where one ed-style patch modifies several files

cat > ed3.diff <<EOF
--- foo
+++ foo
1c
bar
.
--- baz
+++ baz
0a
baz
.
EOF

# Apparently we can't create a file with such a patch, while it works fine
# when the file name is provided on the command line
cat > baz <<EOF
EOF

check 'patch -e -i ed3.diff' <<EOF
EOF

check 'cat foo' <<EOF
bar
EOF

check 'cat baz' <<EOF
baz
EOF
