#! /bin/sh
# $NetBSD: sed.test,v 1.2 2020/05/11 03:10:46 rillig Exp $
#

set -eu

mydir=`dirname "$0"`
. "${mydir}/tests.subr"

#
# Functions specific for the "sed" testsuite.
#

# usage: sed_test <testname> <input> <expected-output> <args...>
sed_test() {
	testname=$1; input=$2; expected=$3; shift 3;

	testcase_start "${testname}"
	output=`sed "$@" <<EOF
$input
EOF
`
	assert_equal "${testname}" "${expected}" "${output}"
}

#
# The actual test.
#

nl="
"

#
# Make sure that sed(1) can handle character classes.
#
sed_test "[[:character classes:]]" \
	"hello${nl}foo bar" \
	"hello" \
	-e "/[[:space:]]/d"


# nbsed-20120308 from textproc/nbsed does not add a newline here.
sed_test 'adding a line' \
	'1'"$nl"'2'"$nl"'3'"$nl"'4' \
	'1'"$nl"'2'"$nl"'between 2 and 3'"$nl"'3'"$nl"'4' \
	-e '/2/a\'"$nl"'between 2 and 3'