Module Name:    src
Committed By:   dholland
Date:           Sun Mar 18 15:35:27 UTC 2012

Modified Files:
        src/tests/usr.bin/sed: t_sed.sh

Log Message:
Add some tests for selection of line ranges, based on a case that came
across the POSIX list a few days ago and some related phenomena.


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/tests/usr.bin/sed/t_sed.sh

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/tests/usr.bin/sed/t_sed.sh
diff -u src/tests/usr.bin/sed/t_sed.sh:1.1 src/tests/usr.bin/sed/t_sed.sh:1.2
--- src/tests/usr.bin/sed/t_sed.sh:1.1	Sun Mar 18 10:12:30 2012
+++ src/tests/usr.bin/sed/t_sed.sh	Sun Mar 18 15:35:27 2012
@@ -1,10 +1,10 @@
-# $NetBSD: t_sed.sh,v 1.1 2012/03/18 10:12:30 jruoho Exp $
+# $NetBSD: t_sed.sh,v 1.2 2012/03/18 15:35:27 dholland Exp $
 #
 # Copyright (c) 2012 The NetBSD Foundation, Inc.
 # All rights reserved.
 #
 # This code is derived from software contributed to The NetBSD Foundation
-# by Jukka Ruohonen.
+# by Jukka Ruohonen and David A. Holland.
 #
 # Redistribution and use in source and binary forms, with or without
 # modification, are permitted provided that the following conditions
@@ -47,6 +47,54 @@ emptybackref_body() {
 		-x "echo foobar | sed -ne '/foo\(.*\)bar\1/p'"
 }
 
+atf_test_case rangeselection
+rangeselection_head() {
+	atf_set "descr" "Test that sed(1) handles " \
+			"range selection correctly"
+}
+
+rangeselection_body() {
+	# basic cases
+	atf_check -o inline:"D\n" \
+		-x "printf 'A\nB\nC\nD\n' | sed '1,3d'"
+	atf_check -o inline:"A\n" \
+		-x "printf 'A\nB\nC\nD\n' | sed '2,4d'"
+	# two nonoverlapping ranges
+	atf_check -o inline:"C\n" \
+		-x "printf 'A\nB\nC\nD\nE\n' | sed '1,2d;4,5d'"
+	# overlapping ranges; the first prevents the second from being entered
+	atf_check -o inline:"D\nE\n" \
+		-x "printf 'A\nB\nC\nD\nE\n' | sed '1,3d;3,5d'"
+	# the 'n' command can also prevent ranges from being entered
+	atf_check -o inline:"B\nB\nC\nD\n" \
+		-x "printf 'A\nB\nC\nD\n' | sed '1,3s/A/B/;1,3n;1,3s/B/C/'"
+	atf_check -o inline:"B\nC\nC\nD\n" \
+		-x "printf 'A\nB\nC\nD\n' | sed '1,3s/A/B/;1,3n;2,3s/B/C/'"
+
+	# basic cases using regexps
+	atf_check -o inline:"D\n" \
+		-x "printf 'A\nB\nC\nD\n' | sed '/A/,/C/d'"
+	atf_check -o inline:"A\n" \
+		-x "printf 'A\nB\nC\nD\n' | sed '/B/,/D/d'"
+	# two nonoverlapping ranges
+	atf_check -o inline:"C\n" \
+		-x "printf 'A\nB\nC\nD\nE\n' | sed '/A/,/B/d;/D/,/E/d'"
+	# two overlapping ranges; the first blocks the second as above
+	atf_check -o inline:"D\nE\n" \
+		-x "printf 'A\nB\nC\nD\nE\n' | sed '/A/,/C/d;/C/,/E/d'"
+	# the 'n' command makes some lines invisible to downstreap regexps
+	atf_check -o inline:"B\nC\nC\nD\n" \
+		-x "printf 'A\nB\nC\nD\n' | sed '/A/,/C/s/A/B/;1,3n;/B/,/C/s/B/C/'"
+
+	# a range ends at the *first* matching end line
+	atf_check -o inline:"D\nC\n" \
+		-x "printf 'A\nB\nC\nD\nC\n' | sed '/A/,/C/d'"
+	# another matching start line within the range has no effect
+	atf_check -o inline:"D\nC\n" \
+		-x "printf 'A\nB\nA\nC\nD\nC\n' | sed '/A/,/C/d'"
+}
+
 atf_init_test_cases() {
 	atf_add_test_case emptybackref
+	atf_add_test_case rangeselection
 }

Reply via email to