Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/tests/usr.bin/sed Add some tests for selection of line range...
details: https://anonhg.NetBSD.org/src/rev/2ec5eb248603
branches: trunk
changeset: 778180:2ec5eb248603
user: dholland <dholland%NetBSD.org@localhost>
date: Sun Mar 18 15:35:27 2012 +0000
description:
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.
diffstat:
tests/usr.bin/sed/t_sed.sh | 52 ++++++++++++++++++++++++++++++++++++++++++++-
1 files changed, 50 insertions(+), 2 deletions(-)
diffs (71 lines):
diff -r d8d5a6b64480 -r 2ec5eb248603 tests/usr.bin/sed/t_sed.sh
--- a/tests/usr.bin/sed/t_sed.sh Sun Mar 18 15:32:23 2012 +0000
+++ b/tests/usr.bin/sed/t_sed.sh Sun Mar 18 15:35:27 2012 +0000
@@ -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 @@
-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
}
Home |
Main Index |
Thread Index |
Old Index