summaryrefslogtreecommitdiff
path: root/regress/usr.bin/sed
diff options
context:
space:
mode:
authorIngo Schwarze <schwarze@cvs.openbsd.org>2011-06-23 11:53:58 +0000
committerIngo Schwarze <schwarze@cvs.openbsd.org>2011-06-23 11:53:58 +0000
commita1ffd84f864f889290dd4c98effc0ac608148ebb (patch)
tree02035c49d4264e663c105c698a9f64a52517d00d /regress/usr.bin/sed
parentfb7575877289f437012013ff386acf9d4277192d (diff)
regression tests for the sed substitute command
most of these still fail, a patch to fix them is on tech@ for review ok to commit the tests deraadt@ otto@
Diffstat (limited to 'regress/usr.bin/sed')
-rw-r--r--regress/usr.bin/sed/Makefile7
-rwxr-xr-xregress/usr.bin/sed/substitute.sh74
2 files changed, 79 insertions, 2 deletions
diff --git a/regress/usr.bin/sed/Makefile b/regress/usr.bin/sed/Makefile
index 2b73e5e06ad..826ef2c1a51 100644
--- a/regress/usr.bin/sed/Makefile
+++ b/regress/usr.bin/sed/Makefile
@@ -1,14 +1,17 @@
-# $OpenBSD: Makefile,v 1.2 2008/10/13 13:27:33 millert Exp $
+# $OpenBSD: Makefile,v 1.3 2011/06/23 11:53:57 schwarze Exp $
# $NetBSD: Makefile,v 1.1 2005/04/04 16:48:45 peter Exp $
SED= /usr/bin/sed
-REGRESS_TARGETS= sedtest hanoi math sierpinski
+REGRESS_TARGETS= sedtest substitute hanoi math sierpinski
sedtest:
sh ${.CURDIR}/$@.sh ${SED} $@.out
diff ${.CURDIR}/$@.expected $@.out
+substitute:
+ sh ${.CURDIR}/$@.sh
+
hanoi:
${SED} -f ${.CURDIR}/$@.sed ${.CURDIR}/$@.in > $@.out
diff ${.CURDIR}/$@.expected $@.out
diff --git a/regress/usr.bin/sed/substitute.sh b/regress/usr.bin/sed/substitute.sh
new file mode 100755
index 00000000000..ea0714cc37c
--- /dev/null
+++ b/regress/usr.bin/sed/substitute.sh
@@ -0,0 +1,74 @@
+#!/bin/sh
+
+# error counter
+err=0
+
+# test function; arguments are:
+# input string
+# regular expression to replace
+# wanted output for /g (global substitution)
+# wanted output for /1 (substitution of first match) and so on
+t() {
+ # global substitution
+ in=$1
+ expr=$2
+ want=$3
+ shift 3
+ out=`echo "$in" | sed -E "s/$expr/x/g"`
+ [ "X$out" = "X$want" ] || echo "$in/$expr/g/$want/$out ($((++err)))"
+
+ # substitution with specific index
+ num=1
+ while [ $# -gt 0 ]; do
+ want=$1
+ shift
+ out=`echo "$in" | sed -E "s/$expr/x/$num"`
+ [ "X$out" = "X$want" ] || \
+ echo "$in/$expr/$num/$want/$out ($((++err)))"
+ num=$((num+1))
+ done
+
+ # substitution with excessive index
+ out=`echo "$in" | sed -E "s/$expr/x/$num"`
+ [ "X$out" = "X$in" ] || echo "$in/$expr/$num/=/$out ($((++err)))"
+}
+
+t '' ^ x x
+t '' '()' x x
+t '' '$' x x
+t '' '^|$' x x
+t a ^ xa xa
+t a '()' xax xa ax
+t a '$' ax ax
+t a '^|a' x x
+t a '^|$' xax xa ax
+t a '^|a|$' x x
+t a 'a|$' x x
+t ab ^ xab xab
+t ab '()' xaxbx xab axb abx
+t ab '$' abx abx
+t ab '^|a' xb xb
+t ab '^|b' xax xab ax
+t ab '^|$' xabx xab abx
+t ab '^|a|$' xbx xb abx
+t ab '^|b|$' xax xab ax
+t ab '^|a|b|$' xx xb ax
+t ab '^|ab|$' x x
+t ab 'a|()' xbx xb abx
+t ab 'a|$' xbx xb abx
+t ab 'ab|$' x x
+t ab 'b|()' xax xab ax
+t ab 'b|$' ax ax
+t abc '^|b' xaxc xabc axc
+t abc '^|b|$' xaxcx xabc axc abcx
+t abc '^|bc|$' xax xabc ax
+t abc 'ab|()' xcx xc abcx
+t abc 'ab|$' xcx xc abcx
+t abc 'b|()' xaxcx xabc axc abcx
+t abc 'bc|()' xax xabc ax
+t abc 'b|$' axcx axc abcx
+t aa a xx xa ax
+t aa 'a|()' xx xa ax
+t aa 'a*' x x
+
+exit $err