xref: /freebsd/usr.bin/sed/tests/multi_test.sh (revision bdcbfde31e8e9b343f113a1956384bdf30d1ed62)
13a92d97fSJulio Merino#!/bin/sh -
23a92d97fSJulio Merino#
33a92d97fSJulio Merino# Copyright (c) 1992 Diomidis Spinellis.
43a92d97fSJulio Merino# Copyright (c) 1992, 1993
53a92d97fSJulio Merino#	The Regents of the University of California.  All rights reserved.
63a92d97fSJulio Merino#
73a92d97fSJulio Merino# Redistribution and use in source and binary forms, with or without
83a92d97fSJulio Merino# modification, are permitted provided that the following conditions
93a92d97fSJulio Merino# are met:
103a92d97fSJulio Merino# 1. Redistributions of source code must retain the above copyright
113a92d97fSJulio Merino#    notice, this list of conditions and the following disclaimer.
123a92d97fSJulio Merino# 2. Redistributions in binary form must reproduce the above copyright
133a92d97fSJulio Merino#    notice, this list of conditions and the following disclaimer in the
143a92d97fSJulio Merino#    documentation and/or other materials provided with the distribution.
15fbbd9655SWarner Losh# 3. Neither the name of the University nor the names of its contributors
163a92d97fSJulio Merino#    may be used to endorse or promote products derived from this software
173a92d97fSJulio Merino#    without specific prior written permission.
183a92d97fSJulio Merino#
193a92d97fSJulio Merino# THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
203a92d97fSJulio Merino# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
213a92d97fSJulio Merino# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
223a92d97fSJulio Merino# ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
233a92d97fSJulio Merino# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
243a92d97fSJulio Merino# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
253a92d97fSJulio Merino# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
263a92d97fSJulio Merino# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
273a92d97fSJulio Merino# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
283a92d97fSJulio Merino# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
293a92d97fSJulio Merino# SUCH DAMAGE.
303a92d97fSJulio Merino
313a92d97fSJulio Merino# sed Regression Tests
323a92d97fSJulio Merino#
333a92d97fSJulio Merino# The directory regress.test.out contains the expected test results
343a92d97fSJulio Merino#
353a92d97fSJulio Merino# These are the regression tests mostly created during the development
363a92d97fSJulio Merino# of the BSD sed.  Each test should have a unique mark name, which is
373a92d97fSJulio Merino# used for naming the corresponding file in regress.multitest.out.
383a92d97fSJulio Merino
393a92d97fSJulio MerinoSRCDIR=$(dirname $0)
403a92d97fSJulio Merino
413a92d97fSJulio Merinomain()
423a92d97fSJulio Merino{
433a92d97fSJulio Merino	REGRESS=${SRCDIR}/regress.multitest.out
443a92d97fSJulio Merino	DICT=/usr/share/dict/words
453a92d97fSJulio Merino
463a92d97fSJulio Merino	awk 'END { for (i = 1; i < 15; i++) print "l1_" i}' </dev/null >lines1
473a92d97fSJulio Merino	awk 'END { for (i = 1; i < 10; i++) print "l2_" i}' </dev/null >lines2
483a92d97fSJulio Merino
4998648ee8SJeremie Le Hen	echo "1..130"
503a92d97fSJulio Merino
513a92d97fSJulio Merino	exec 4>&1 5>&2
523a92d97fSJulio Merino	tests
533a92d97fSJulio Merino	exec 1>&4 2>&5
543a92d97fSJulio Merino
553a92d97fSJulio Merino	# Remove temporary files
563a92d97fSJulio Merino	rm -f current.out lines[1-4] script[1-2]
573a92d97fSJulio Merino}
583a92d97fSJulio Merino
593a92d97fSJulio Merinotests()
603a92d97fSJulio Merino{
613a92d97fSJulio Merino	SED=sed
623a92d97fSJulio Merino	MARK=0
633a92d97fSJulio Merino
643a92d97fSJulio Merino	test_args
653a92d97fSJulio Merino	test_addr
663a92d97fSJulio Merino	test_group
673a92d97fSJulio Merino	test_acid
683a92d97fSJulio Merino	test_branch
693a92d97fSJulio Merino	test_pattern
703a92d97fSJulio Merino	test_print
713a92d97fSJulio Merino	test_subst
723a92d97fSJulio Merino	test_error
733a92d97fSJulio Merino	# Handle the result of the last test
743a92d97fSJulio Merino	result
753a92d97fSJulio Merino}
763a92d97fSJulio Merino
773a92d97fSJulio Merino# Display a test's result
783a92d97fSJulio Merinoresult()
793a92d97fSJulio Merino{
803a92d97fSJulio Merino	if [ "$TODO" = '1' ] ; then
813a92d97fSJulio Merino		TODO='TODO '
823a92d97fSJulio Merino	else
833a92d97fSJulio Merino		TODO=''
843a92d97fSJulio Merino	fi
853a92d97fSJulio Merino	if ! [ -r $REGRESS/${TESTNAME} ] ; then
863a92d97fSJulio Merino		echo "Seeding $REGRESS/${TESTNAME} with current result" 1>&2
873a92d97fSJulio Merino		cp current.out $REGRESS/${TESTNAME}
883a92d97fSJulio Merino	fi
893a92d97fSJulio Merino	if diff -c $REGRESS/${TESTNAME} current.out ; then
90*e4bfd2a6SYuri Pankov		echo "ok $MARK $TESTNAME # $TODO$OCOMMENT"
913a92d97fSJulio Merino	else
92*e4bfd2a6SYuri Pankov		echo "not ok $MARK $TESTNAME # $TODO$OCOMMENT"
933a92d97fSJulio Merino	fi 1>&4 2>&5
943a92d97fSJulio Merino}
953a92d97fSJulio Merino
963a92d97fSJulio Merino# Mark the beginning of each test
973a92d97fSJulio Merinomark()
983a92d97fSJulio Merino{
993a92d97fSJulio Merino	[ $MARK -gt 0 ] && result
100*e4bfd2a6SYuri Pankov	OCOMMENT=$COMMENT
1013a92d97fSJulio Merino	MARK=`expr $MARK + 1`
1023a92d97fSJulio Merino	TESTNAME=$1
1033a92d97fSJulio Merino	exec 1>&4 2>&5
1043a92d97fSJulio Merino	exec >"current.out"
1053a92d97fSJulio Merino}
1063a92d97fSJulio Merino
1073a92d97fSJulio Merinotest_args()
1083a92d97fSJulio Merino{
1093a92d97fSJulio Merino	COMMENT='Argument parsing - first type'
1103a92d97fSJulio Merino	mark '1.1'
1113a92d97fSJulio Merino	$SED 's/^/e1_/p' lines1
1123a92d97fSJulio Merino	mark '1.2' ; $SED -n 's/^/e1_/p' lines1
1133a92d97fSJulio Merino	mark '1.3'
1143a92d97fSJulio Merino	$SED 's/^/e1_/p' <lines1
1153a92d97fSJulio Merino	mark '1.4' ; $SED -n 's/^/e1_/p' <lines1
1163a92d97fSJulio Merino	COMMENT='Argument parsing - second type'
1173a92d97fSJulio Merino	mark '1.4.1'
1183a92d97fSJulio Merino	$SED -e '' <lines1
1193a92d97fSJulio Merino	echo 's/^/s1_/p' >script1
1203a92d97fSJulio Merino	echo 's/^/s2_/p' >script2
1213a92d97fSJulio Merino	mark '1.5'
1223a92d97fSJulio Merino	$SED -f script1 lines1
1233a92d97fSJulio Merino	mark '1.6'
1243a92d97fSJulio Merino	$SED -f script1 <lines1
1253a92d97fSJulio Merino	mark '1.7'
1263a92d97fSJulio Merino	$SED -e 's/^/e1_/p' lines1
1273a92d97fSJulio Merino	mark '1.8'
1283a92d97fSJulio Merino	$SED -e 's/^/e1_/p' <lines1
1293a92d97fSJulio Merino	mark '1.9' ; $SED -n -f script1 lines1
1303a92d97fSJulio Merino	mark '1.10' ; $SED -n -f script1 <lines1
1313a92d97fSJulio Merino	mark '1.11' ; $SED -n -e 's/^/e1_/p' lines1
1323a92d97fSJulio Merino	mark '1.12'
1333a92d97fSJulio Merino	$SED -n -e 's/^/e1_/p' <lines1
1343a92d97fSJulio Merino	mark '1.13'
1353a92d97fSJulio Merino	$SED -e 's/^/e1_/p' -e 's/^/e2_/p' lines1
1363a92d97fSJulio Merino	mark '1.14'
1373a92d97fSJulio Merino	$SED -f script1 -f script2 lines1
1383a92d97fSJulio Merino	mark '1.15'
1393a92d97fSJulio Merino	$SED -e 's/^/e1_/p' -f script1 lines1
1403a92d97fSJulio Merino	mark '1.16'
1413a92d97fSJulio Merino	$SED -e 's/^/e1_/p' lines1 lines1
1423a92d97fSJulio Merino	# POSIX D11.2:11251
1433a92d97fSJulio Merino	mark '1.17' ; $SED p <lines1 lines1
1443a92d97fSJulio Merinocat >script1 <<EOF
1453a92d97fSJulio Merino#n
1463a92d97fSJulio Merino# A comment
1473a92d97fSJulio Merino
1483a92d97fSJulio Merinop
1493a92d97fSJulio MerinoEOF
1503a92d97fSJulio Merino	mark '1.18' ; $SED -f script1 <lines1 lines1
1513a92d97fSJulio Merino}
1523a92d97fSJulio Merino
1533a92d97fSJulio Merinotest_addr()
1543a92d97fSJulio Merino{
1553a92d97fSJulio Merino	COMMENT='Address ranges'
1563a92d97fSJulio Merino	mark '2.1' ; $SED -n -e '4p' lines1
1573a92d97fSJulio Merino	mark '2.2' ; $SED -n -e '20p' lines1 lines2
1583a92d97fSJulio Merino	mark '2.3' ; $SED -n -e '$p' lines1
1593a92d97fSJulio Merino	mark '2.4' ; $SED -n -e '$p' lines1 lines2
1603a92d97fSJulio Merino	mark '2.5' ; $SED -n -e '$a\
1613a92d97fSJulio Merinohello' /dev/null
1623a92d97fSJulio Merino	mark '2.6' ; $SED -n -e '$p' lines1 /dev/null lines2
1633a92d97fSJulio Merino	# Should not print anything
1643a92d97fSJulio Merino	mark '2.7' ; $SED -n -e '20p' lines1
1653a92d97fSJulio Merino	mark '2.8' ; $SED -n -e '/NOTFOUND/p' lines1
1663a92d97fSJulio Merino	mark '2.9' ; $SED -n '/l1_7/p' lines1
1673a92d97fSJulio Merino	mark '2.10' ; $SED -n ' /l1_7/ p' lines1
1683a92d97fSJulio Merino	mark '2.11' ; $SED -n '\_l1\_7_p' lines1
1693a92d97fSJulio Merino	mark '2.12' ; $SED -n '1,4p' lines1
1703a92d97fSJulio Merino	mark '2.13' ; $SED -n '1,$p' lines1 lines2
1713a92d97fSJulio Merino	mark '2.14' ; $SED -n '1,/l2_9/p' lines1 lines2
1723a92d97fSJulio Merino	mark '2.15' ; $SED -n '/4/,$p' lines1 lines2
1733a92d97fSJulio Merino	mark '2.16' ; $SED -n '/4/,20p' lines1 lines2
1743a92d97fSJulio Merino	mark '2.17' ; $SED -n '/4/,/10/p' lines1 lines2
1753a92d97fSJulio Merino	mark '2.18' ; $SED -n '/l2_3/,/l1_8/p' lines1 lines2
1763a92d97fSJulio Merino	mark '2.19' ; $SED -n '12,3p' lines1 lines2
1773a92d97fSJulio Merino	mark '2.20' ; $SED -n '/l1_7/,3p' lines1 lines2
1783a92d97fSJulio Merino	mark '2.21' ; $SED -n '13,+4p' lines1 lines2
1793a92d97fSJulio Merino	mark '2.22' ; $SED -n '/l1_6/,+2p' lines1 lines2
18098648ee8SJeremie Le Hen	# For PR bin/192108
18198648ee8SJeremie Le Hen	mark '2.23'; $SED -n '12,+1p' lines1
1823a92d97fSJulio Merino}
1833a92d97fSJulio Merino
1843a92d97fSJulio Merinotest_group()
1853a92d97fSJulio Merino{
1863a92d97fSJulio Merino	COMMENT='Brace and other grouping'
1873a92d97fSJulio Merino	mark '3.1' ; $SED -e '
1883a92d97fSJulio Merino4,12 {
1893a92d97fSJulio Merino	s/^/^/
1903a92d97fSJulio Merino	s/$/$/
1913a92d97fSJulio Merino	s/_/T/
1923a92d97fSJulio Merino}' lines1
1933a92d97fSJulio Merino	mark '3.2' ; $SED -e '
1943a92d97fSJulio Merino4,12 {
1953a92d97fSJulio Merino	s/^/^/
1963a92d97fSJulio Merino	/6/,/10/ {
1973a92d97fSJulio Merino		s/$/$/
1983a92d97fSJulio Merino		/8/ s/_/T/
1993a92d97fSJulio Merino	}
2003a92d97fSJulio Merino}' lines1
2013a92d97fSJulio Merino	mark '3.3' ; $SED -e '
2023a92d97fSJulio Merino4,12 !{
2033a92d97fSJulio Merino	s/^/^/
2043a92d97fSJulio Merino	/6/,/10/ !{
2053a92d97fSJulio Merino		s/$/$/
2063a92d97fSJulio Merino		/8/ !s/_/T/
2073a92d97fSJulio Merino	}
2083a92d97fSJulio Merino}' lines1
2093a92d97fSJulio Merino	mark '3.4' ; $SED -e '4,12!s/^/^/' lines1
2103a92d97fSJulio Merino}
2113a92d97fSJulio Merino
2123a92d97fSJulio Merinotest_acid()
2133a92d97fSJulio Merino{
2143a92d97fSJulio Merino	COMMENT='Commands a c d and i'
2153a92d97fSJulio Merino	mark '4.1' ; $SED -n -e '
2163a92d97fSJulio Merinos/^/before_i/p
2173a92d97fSJulio Merino20i\
2183a92d97fSJulio Merinoinserted
2193a92d97fSJulio Merinos/^/after_i/p
2203a92d97fSJulio Merino' lines1 lines2
2213a92d97fSJulio Merino	mark '4.2' ; $SED -n -e '
2223a92d97fSJulio Merino5,12s/^/5-12/
2233a92d97fSJulio Merinos/^/before_a/p
2243a92d97fSJulio Merino/5-12/a\
2253a92d97fSJulio Merinoappended
2263a92d97fSJulio Merinos/^/after_a/p
2273a92d97fSJulio Merino' lines1 lines2
2283a92d97fSJulio Merino	mark '4.3'
2293a92d97fSJulio Merino	$SED -n -e '
2303a92d97fSJulio Merinos/^/^/p
2313a92d97fSJulio Merino/l1_/a\
2323a92d97fSJulio Merinoappended
2333a92d97fSJulio Merino8,10N
2343a92d97fSJulio Merinos/$/$/p
2353a92d97fSJulio Merino' lines1 lines2
2363a92d97fSJulio Merino	mark '4.4' ; $SED -n -e '
2373a92d97fSJulio Merinoc\
2383a92d97fSJulio Merinohello
2393a92d97fSJulio Merino' lines1
2403a92d97fSJulio Merino	mark '4.5' ; $SED -n -e '
2413a92d97fSJulio Merino8c\
2423a92d97fSJulio Merinohello
2433a92d97fSJulio Merino' lines1
2443a92d97fSJulio Merino	mark '4.6' ; $SED -n -e '
2453a92d97fSJulio Merino3,14c\
2463a92d97fSJulio Merinohello
2473a92d97fSJulio Merino' lines1
2483a92d97fSJulio Merino# SunOS and GNU sed behave differently.   We follow POSIX
2493a92d97fSJulio Merino	mark '4.7' ; $SED -n -e '
2503a92d97fSJulio Merino8,3c\
2513a92d97fSJulio Merinohello
2523a92d97fSJulio Merino' lines1
2533a92d97fSJulio Merino	mark '4.8' ; $SED d <lines1
2543a92d97fSJulio Merino}
2553a92d97fSJulio Merino
2563a92d97fSJulio Merinotest_branch()
2573a92d97fSJulio Merino{
2583a92d97fSJulio Merino	COMMENT='Labels and branching'
2593a92d97fSJulio Merino	mark '5.1' ; $SED -n -e '
2603a92d97fSJulio Merinob label4
2613a92d97fSJulio Merino:label3
2623a92d97fSJulio Merinos/^/label3_/p
2633a92d97fSJulio Merinob end
2643a92d97fSJulio Merino:label4
2653a92d97fSJulio Merino2,12b label1
2663a92d97fSJulio Merinob label2
2673a92d97fSJulio Merino:label1
2683a92d97fSJulio Merinos/^/label1_/p
2693a92d97fSJulio Merinob
2703a92d97fSJulio Merino:label2
2713a92d97fSJulio Merinos/^/label2_/p
2723a92d97fSJulio Merinob label3
2733a92d97fSJulio Merino:end
2743a92d97fSJulio Merino' lines1
2753a92d97fSJulio Merino	mark '5.2'
2763a92d97fSJulio Merino	$SED -n -e '
2773a92d97fSJulio Merinos/l1_/l2_/
2783a92d97fSJulio Merinot ok
2793a92d97fSJulio Merinob
2803a92d97fSJulio Merino:ok
2813a92d97fSJulio Merinos/^/tested /p
2823a92d97fSJulio Merino' lines1 lines2
2833a92d97fSJulio Merino# SunOS and GNU sed behave as follows: lines 9-$ aren't printed at all
2843a92d97fSJulio Merino	mark '5.3' ; $SED -n -e '
2853a92d97fSJulio Merino5,8b inside
2863a92d97fSJulio Merino1,5 {
2873a92d97fSJulio Merino	s/^/^/p
2883a92d97fSJulio Merino	:inside
2893a92d97fSJulio Merino	s/$/$/p
2903a92d97fSJulio Merino}
2913a92d97fSJulio Merino' lines1
2923a92d97fSJulio Merino# Check that t clears the substitution done flag
2933a92d97fSJulio Merino	mark '5.4' ; $SED -n -e '
2943a92d97fSJulio Merino1,8s/^/^/
2953a92d97fSJulio Merinot l1
2963a92d97fSJulio Merino:l1
2973a92d97fSJulio Merinot l2
2983a92d97fSJulio Merinos/$/$/p
2993a92d97fSJulio Merinob
3003a92d97fSJulio Merino:l2
3013a92d97fSJulio Merinos/^/ERROR/
3023a92d97fSJulio Merino' lines1
3033a92d97fSJulio Merino# Check that reading a line clears the substitution done flag
3043a92d97fSJulio Merino	mark '5.5'
3053a92d97fSJulio Merino	$SED -n -e '
3063a92d97fSJulio Merinot l2
3073a92d97fSJulio Merino1,8s/^/^/p
3083a92d97fSJulio Merino2,7N
3093a92d97fSJulio Merinob
3103a92d97fSJulio Merino:l2
3113a92d97fSJulio Merinos/^/ERROR/p
3123a92d97fSJulio Merino' lines1
3133a92d97fSJulio Merino	mark '5.6' ; $SED 5q lines1
3143a92d97fSJulio Merino	mark '5.7' ; $SED -e '
3153a92d97fSJulio Merino5i\
3163a92d97fSJulio Merinohello
3173a92d97fSJulio Merino5q' lines1
3183a92d97fSJulio Merino# Branch across block boundary
3193a92d97fSJulio Merino	mark '5.8' ; $SED -e '
3203a92d97fSJulio Merino{
3213a92d97fSJulio Merino:b
3223a92d97fSJulio Merino}
3233a92d97fSJulio Merinos/l/m/
3243a92d97fSJulio Merinotb' lines1
3253a92d97fSJulio Merino}
3263a92d97fSJulio Merino
3273a92d97fSJulio Merinotest_pattern()
3283a92d97fSJulio Merino{
3293a92d97fSJulio MerinoCOMMENT='Pattern space commands'
3303a92d97fSJulio Merino# Check that the pattern space is deleted
3313a92d97fSJulio Merino	mark '6.1' ; $SED -n -e '
3323a92d97fSJulio Merinoc\
3333a92d97fSJulio Merinochanged
3343a92d97fSJulio Merinop
3353a92d97fSJulio Merino' lines1
3363a92d97fSJulio Merino	mark '6.2' ; $SED -n -e '
3373a92d97fSJulio Merino4d
3383a92d97fSJulio Merinop
3393a92d97fSJulio Merino' lines1
3403a92d97fSJulio Merino	mark '6.3'
3413a92d97fSJulio Merino	$SED -e 'N;N;N;D' lines1
3423a92d97fSJulio Merino	mark '6.4' ; $SED -e '
3433a92d97fSJulio Merino2h
3443a92d97fSJulio Merino3H
3453a92d97fSJulio Merino4g
3463a92d97fSJulio Merino5G
3473a92d97fSJulio Merino6x
3483a92d97fSJulio Merino6p
3493a92d97fSJulio Merino6x
3503a92d97fSJulio Merino6p
3513a92d97fSJulio Merino' lines1
3523a92d97fSJulio Merino	mark '6.5' ; $SED -e '4n' lines1
3533a92d97fSJulio Merino	mark '6.6' ; $SED -n -e '4n' lines1
3543a92d97fSJulio Merino}
3553a92d97fSJulio Merino
3563a92d97fSJulio Merinotest_print()
3573a92d97fSJulio Merino{
3583a92d97fSJulio Merino	COMMENT='Print and file routines'
3593a92d97fSJulio Merino	awk 'END {for (i = 1; i < 256; i++) printf("%c", i);print "\n"}' \
3603a92d97fSJulio Merino		</dev/null >lines3
3613a92d97fSJulio Merino	# GNU and SunOS sed behave differently here
3623a92d97fSJulio Merino	mark '7.1'
3633a92d97fSJulio Merino	$SED -n l lines3
3643a92d97fSJulio Merino	mark '7.2' ; $SED -e '/l2_/=' lines1 lines2
3653a92d97fSJulio Merino	rm -f lines4
3663a92d97fSJulio Merino	mark '7.3' ; $SED -e '3,12w lines4' lines1
3673a92d97fSJulio Merino	COMMENT='w results'
3683a92d97fSJulio Merino	cat lines4
3693a92d97fSJulio Merino	mark '7.4' ; $SED -e '4r lines2' lines1
3703a92d97fSJulio Merino	mark '7.5' ; $SED -e '5r /dev/dds' lines1
3713a92d97fSJulio Merino	mark '7.6' ; $SED -e '6r /dev/null' lines1
3723a92d97fSJulio Merino	mark '7.7'
3733a92d97fSJulio Merino	sed '200q' $DICT | sed 's$.*$s/^/&/w tmpdir/&$' >script1
3743a92d97fSJulio Merino	rm -rf tmpdir
3753a92d97fSJulio Merino	mkdir tmpdir
3763a92d97fSJulio Merino	$SED -f script1 lines1
3773a92d97fSJulio Merino	cat tmpdir/*
3783a92d97fSJulio Merino	rm -rf tmpdir
3793a92d97fSJulio Merino	mark '7.8'
3803a92d97fSJulio Merino	echo line1 > lines3
3813a92d97fSJulio Merino	echo "" >> lines3
3823a92d97fSJulio Merino	$SED -n -e '$p' lines3 /dev/null
3833a92d97fSJulio Merino
3843a92d97fSJulio Merino}
3853a92d97fSJulio Merino
3863a92d97fSJulio Merinotest_subst()
3873a92d97fSJulio Merino{
3883a92d97fSJulio Merino	COMMENT='Substitution commands'
3893a92d97fSJulio Merino	mark '8.1' ; $SED -e 's/./X/g' lines1
3903a92d97fSJulio Merino	mark '8.2' ; $SED -e 's,.,X,g' lines1
3913a92d97fSJulio Merino# SunOS sed thinks we are escaping . as wildcard, not as separator
3923a92d97fSJulio Merino	mark '8.3'
3933a92d97fSJulio Merino	$SED -e 's.\..X.g' lines1
3943a92d97fSJulio Merino	mark '8.4' ; $SED -e 's/[\/]/Q/' lines1
3953a92d97fSJulio Merino	mark '8.5' ; $SED -e 's_\__X_' lines1
3963a92d97fSJulio Merino	mark '8.6' ; $SED -e 's/./(&)/g' lines1
3973a92d97fSJulio Merino	mark '8.7' ; $SED -e 's/./(\&)/g' lines1
3983a92d97fSJulio Merino	mark '8.8' ; $SED -e 's/\(.\)\(.\)\(.\)/x\3x\2x\1/g' lines1
3993a92d97fSJulio Merino	mark '8.9' ; $SED -e 's/_/u0\
4003a92d97fSJulio Merinou1\
4013a92d97fSJulio Merinou2/g' lines1
4023a92d97fSJulio Merino	mark '8.10'
4033a92d97fSJulio Merino	$SED -e 's/./X/4' lines1
4043a92d97fSJulio Merino	rm -f lines4
4053a92d97fSJulio Merino	mark '8.11' ; $SED -e 's/1/X/w lines4' lines1
4063a92d97fSJulio Merino	COMMENT='s wfile results'
4073a92d97fSJulio Merino	cat lines4
4083a92d97fSJulio Merino	mark '8.12' ; $SED -e 's/[123]/X/g' lines1
4093a92d97fSJulio Merino	mark '8.13' ; $SED -e 'y/0123456789/9876543210/' lines1
4103a92d97fSJulio Merino	mark '8.14' ;
4113a92d97fSJulio Merino	$SED -e 'y10\123456789198765432\101' lines1
4123a92d97fSJulio Merino	mark '8.15' ; $SED -e '1N;2y/\n/X/' lines1
4133a92d97fSJulio Merino	mark '8.16'
4143a92d97fSJulio Merino	echo 'eeefff' | $SED -e '
4153a92d97fSJulio Merino		p
4163a92d97fSJulio Merino		s/e/X/p
4173a92d97fSJulio Merino		:x
4183a92d97fSJulio Merino		s//Y/p
4193a92d97fSJulio Merino		# Establish limit counter in the hold space
4203a92d97fSJulio Merino		# GNU sed version 3.02 enters into an infinite loop here
4213a92d97fSJulio Merino		x
4223a92d97fSJulio Merino		/.\{10\}/ {
4233a92d97fSJulio Merino			s/.*/ERROR/
4243a92d97fSJulio Merino			b
4253a92d97fSJulio Merino		}
4263a92d97fSJulio Merino		s/.*/&./
4273a92d97fSJulio Merino		x
4283a92d97fSJulio Merino		/f/bx
4293a92d97fSJulio Merino	'
4303a92d97fSJulio Merino	# POSIX does not say that this should work,
4313a92d97fSJulio Merino	# but it does for GNU, BSD, and SunOS
4323a92d97fSJulio Merino	mark '8.17' ; $SED -e 's/[/]/Q/' lines1
4333a92d97fSJulio Merino
4343a92d97fSJulio Merino	COMMENT='[ as an s delimiter and its escapes'
4353a92d97fSJulio Merino	mark '8.18' ; $SED -e 's[_[X[' lines1
4363a92d97fSJulio Merino	# This is a matter of interpretation
4373a92d97fSJulio Merino	# POSIX 1003.1, 2004 says "Within the BRE and the replacement,
4383a92d97fSJulio Merino	# the BRE delimiter itself can be used as a *literal* character
4393a92d97fSJulio Merino	# if it is preceded by a backslash"
4403a92d97fSJulio Merino	# SunOS 5.1 /usr/bin/sed and Mac OS X follow the literal POSIX
4413a92d97fSJulio Merino	# interpretation.
4423a92d97fSJulio Merino	# GNU sed version 4.1.5 treats \[ as the beginning of a character
4433a92d97fSJulio Merino	# set specification (both with --posix and without).
4443a92d97fSJulio Merino	mark '8.19' ; sed 's/l/[/' lines1 | $SED -e 's[\[.[X['
4453a92d97fSJulio Merino	mark '8.20' ; sed 's/l/[/' lines1 | $SED -e 's[\[.[X\[['
4463a92d97fSJulio Merino	COMMENT='\ in y command'
4473a92d97fSJulio Merino	mark '8.21'
4483a92d97fSJulio Merino	echo 'a\b(c' |
4493a92d97fSJulio Merino	$SED 'y%ABCDEFGHIJKLMNOPQRSTUVWXYZ, /\\()"%abcdefghijklmnopqrstuvwxyz,------%'
4503a92d97fSJulio Merino	COMMENT='\n in a character class and a BRE'
4513a92d97fSJulio Merino	mark '8.22' ; (echo 1; echo 2) | $SED -n '1{;N;s/[\n]/X/;p;}'
4523a92d97fSJulio Merino	mark '8.23' ; (echo 1; echo 2) | $SED -n '1{;N;s/\n/X/;p;}'
4533a92d97fSJulio Merino}
4543a92d97fSJulio Merino
4553a92d97fSJulio Merinotest_error()
4563a92d97fSJulio Merino{
4573a92d97fSJulio Merino	COMMENT='Error cases'
4583a92d97fSJulio Merino	mark '9.1' ; $SED -x 2>/dev/null ; echo $?
4593a92d97fSJulio Merino	mark '9.2' ; $SED -f 2>/dev/null ; echo $?
4603a92d97fSJulio Merino	mark '9.3' ; $SED -e 2>/dev/null ; echo $?
4613a92d97fSJulio Merino	mark '9.4' ; $SED -f /dev/xyzzyxyzy 2>/dev/null ; echo $?
4623a92d97fSJulio Merino	mark '9.5' ; $SED p /dev/xyzzyxyzy 2>/dev/null ; echo $?
4633a92d97fSJulio Merino	mark '9.6' ; $SED -f /bin/sh 2>/dev/null ; echo $?
4643a92d97fSJulio Merino	mark '9.7' ; $SED '{' 2>/dev/null ; echo $?
4653a92d97fSJulio Merino	mark '9.8' ; $SED '{' 2>/dev/null ; echo $?
4663a92d97fSJulio Merino	mark '9.9' ; $SED '/hello/' 2>/dev/null ; echo $?
4673a92d97fSJulio Merino	mark '9.10' ; $SED '1,/hello/' 2>/dev/null ; echo $?
4683a92d97fSJulio Merino	mark '9.11' ; $SED -e '-5p' 2>/dev/null ; echo $?
4693a92d97fSJulio Merino	mark '9.12' ; $SED '/jj' 2>/dev/null ; echo $?
4703a92d97fSJulio Merino	mark '9.13' ; $SED 'a hello' 2>/dev/null ; echo $?
4713a92d97fSJulio Merino	mark '9.14' ; $SED 'a \ hello' 2>/dev/null ; echo $?
4723a92d97fSJulio Merino	mark '9.15' ; $SED 'b foo' 2>/dev/null ; echo $?
4733a92d97fSJulio Merino	mark '9.16' ; $SED 'd hello' 2>/dev/null ; echo $?
4743a92d97fSJulio Merino	mark '9.17' ; $SED 's/aa' 2>/dev/null ; echo $?
4753a92d97fSJulio Merino	mark '9.18' ; $SED 's/aa/' 2>/dev/null ; echo $?
4763a92d97fSJulio Merino	mark '9.19' ; $SED 's/a/b' 2>/dev/null ; echo $?
4773a92d97fSJulio Merino	mark '9.20' ; $SED 's/a/b/c/d' 2>/dev/null ; echo $?
4783a92d97fSJulio Merino	mark '9.21' ; $SED 's/a/b/ 1 2' 2>/dev/null ; echo $?
4793a92d97fSJulio Merino	mark '9.22' ; $SED 's/a/b/ 1 g' 2>/dev/null ; echo $?
4803a92d97fSJulio Merino	mark '9.23' ; $SED 's/a/b/w' 2>/dev/null ; echo $?
4813a92d97fSJulio Merino	mark '9.24' ; $SED 'y/aa' 2>/dev/null ; echo $?
4823a92d97fSJulio Merino	mark '9.25' ; $SED 'y/aa/b/' 2>/dev/null ; echo $?
4833a92d97fSJulio Merino	mark '9.26' ; $SED 'y/aa/' 2>/dev/null ; echo $?
4843a92d97fSJulio Merino	mark '9.27' ; $SED 'y/a/b' 2>/dev/null ; echo $?
4853a92d97fSJulio Merino	mark '9.28' ; $SED 'y/a/b/c/d' 2>/dev/null ; echo $?
4863a92d97fSJulio Merino	mark '9.29' ; $SED '!' 2>/dev/null ; echo $?
4873a92d97fSJulio Merino	mark '9.30' ; $SED supercalifrangolisticexprialidociussupercalifrangolisticexcius 2>/dev/null ; echo $?
4883a92d97fSJulio Merino	mark '9.31' ; $SED '' /dev/null 2>/dev/null ; echo $?
4893a92d97fSJulio Merino}
4903a92d97fSJulio Merino
4913a92d97fSJulio Merinomain
492