From 65b331b4a19ecf3dc073e2363cb8294e986ded44 Mon Sep 17 00:00:00 2001 From: yar Date: Sat, 21 Apr 2007 01:21:36 +0000 Subject: Change the semantics of -i (in-place editing) so that it treats each file independently from other files. The new semantics are desired in the most of practical cases, e.g.: delete lines 5-9 from each file. Keep the previous semantics of -i under a new option, -I, which uses a single continuous address space covering all files to edit in-place -- they are too cool to just drop them. Add regression tests for -i and -I. Approved by: dds Compared with: GNU sed Discussed on: -hackers MFC after: 2 weeks --- tools/regression/usr.bin/sed/regress.sh | 36 ++++++++++++++++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) (limited to 'tools/regression/usr.bin/sed') diff --git a/tools/regression/usr.bin/sed/regress.sh b/tools/regression/usr.bin/sed/regress.sh index a99e7ba..2820a25 100644 --- a/tools/regression/usr.bin/sed/regress.sh +++ b/tools/regression/usr.bin/sed/regress.sh @@ -2,7 +2,7 @@ REGRESSION_START($1) -echo '1..16' +echo '1..20' REGRESSION_TEST(`G', `sed G < regress.in') REGRESSION_TEST(`P', `sed P < regress.in') @@ -28,6 +28,40 @@ foo REGRESSION_TEST(`b2a', `sed ''`2,3b 1,2d''` < regress.in') +` +inplace_test() +{ + expr="$1" + rc=0 + ns=$(jot 5) + ins= outs= _ins= + for n in $ns; do + jot -w "l${n}_%d" 9 | tee lines.in.$n lines._in.$n | \ + sed "$expr" > lines.out.$n + ins="$ins lines.in.$n" + outs="$outs lines.out.$n" + _ins="$_ins lines._in.$n" + done + sed "$expr" $_ins > lines.out + + sed -i "" "$expr" $ins + sed -I "" "$expr" $_ins + + for n in $ns; do + diff -u lines.out.$n lines.in.$n || rc=1 + done + cat $_ins | diff -u lines.out - || rc=1 + rm -f $ins $outs $_ins lines.out + + return $rc +} +' + +REGRESSION_TEST_FREEFORM(`inplace1', `inplace_test 3,6d') +REGRESSION_TEST_FREEFORM(`inplace2', `inplace_test 8,30d') +REGRESSION_TEST_FREEFORM(`inplace3', `inplace_test 20,99d') +REGRESSION_TEST_FREEFORM(`inplace4', `inplace_test "{;{;8,30d;};}"') + REGRESSION_TEST(`hanoi', `echo ":abcd: : :" | sed -f hanoi.sed') REGRESSION_TEST(`math', `echo "4+7*3+2^7/3" | sed -f math.sed') -- cgit v1.1