1 #!/bin/echo Run scripts/test.sh
3 #testing "name" "command" "result" "infile" "stdin"
5 testing 'sed as cat' 'sed ""' "one\ntwo\nthree" "" "one\ntwo\nthree"
7 # Exploring the wonders of sed addressing modes
8 testing '' 'sed -n 1p' "one\n" "" "one\ntwo\nthree"
9 testing '' 'sed 2p' "one\ntwo\ntwo\nthree" "" "one\ntwo\nthree"
10 testing '' 'sed -n 2p' "two\n" "" "one\ntwo\nthree"
11 testing 'sed -n $p' 'sed -n \$p' "three" "" "one\ntwo\nthree"
12 testing 'sed as cat #2' "sed -n '1,\$p'" "one\ntwo\nthree" "" "one\ntwo\nthree"
13 testing 'no input means no last line' "sed '\$a boing'" "" "" ""
14 testing 'sed -n $,$p' 'sed -n \$,\$p' 'three' '' 'one\ntwo\nthree'
15 testing '' 'sed -n 1,2p' "one\ntwo\n" "" "one\ntwo\nthree"
16 testing '' 'sed -n 2,3p' "two\nthree" "" "one\ntwo\nthree"
17 testing '' 'sed -n 2,1p' "two\n" "" "one\ntwo\nthree"
18 testing 'sed $ with 2 inputs' 'sed -n \$p - input' "four\n" "four\n" \
20 testing '' 'sed -n /two/p' "two\n" "" "one\ntwo\nthree"
21 testing '' 'sed -n 1,/two/p' 'one\ntwo\n' '' 'one\ntwo\nthree'
22 testing '' 'sed -n /one/,2p' 'one\ntwo\n' '' 'one\ntwo\nthree'
23 testing '' 'sed -n 1,/one/p' 'one\ntwo\nthree' '' 'one\ntwo\nthree'
24 testing '' 'sed -n /one/,1p' 'one\n' '' 'one\ntwo\nthree'
25 testing 'sed -n /two/,$p' 'sed -n /two/,\$p' 'two\nthree' '' 'one\ntwo\nthree'
29 testing '' 'sed -n 3p' "three" "" "one\ntwo\nthree"
30 testing 'prodigal newline' "sed -n '1,\$p' - input" "one\ntwo\nthree\nfour\n" \
31 "four\n" "one\ntwo\nthree"
32 testing 'Newline only added if further output' "sed -n 3p - input" "three" \
33 "four\n" "one\ntwo\nthree"
35 # Fun with match delimiters and escapes
36 testing 'sed match \t tab' "sed -n '/\t/p'" "\tx\n" "" "\tx\n"
37 testing 'sed match t delim disables \t tab' "sed -n '\t\txtp'" "" "" "\tx\n"
38 testing 'sed match t delim makes \t literal t' \
39 "sed -n '\t\txtp'" "tx\n" "" "tx\n"
40 testing 'sed match n delim' "sed -n '\n\txnp'" "\tx\n" "" "\tx\n"
41 testing 'sed match n delim disables \n newline' "sed -n '\n\nxnp'" "" "" "\nx\n"
42 testing 'sed match n delim makes \n literal n' \
43 "sed -n '\n\nxnp'" "nx\n" "" "nx\n"
44 testing 'end match does not check starting match line' \
45 "sed -n '/two/,/two/p'" "two\nthree" "" "one\ntwo\nthree"
46 testing 'end match/start match mixing number/letter' \
47 "sed -n '2,/two/p'" "two\nthree" "" "one\ntwo\nthree"
48 testing 'sed num then regex' 'sed -n 2,/d/p' 'b\nc\nd\n' '' 'a\nb\nc\nd\ne\nf\n'
49 testing 'sed regex then num' 'sed -n /b/,4p' 'b\nc\nd\n' '' 'a\nb\nc\nd\ne\nf\n'
50 testing 'sed multiple regex address match' 'sed -n /on/,/off/p' \
51 'bone\nturtle\scoff\ntron\nlurid\noffer\n' "" \
52 'zap\nbone\nturtle\scoff\nfred\ntron\nlurid\noffer\nbecause\n'
53 testing 'sed regex address overlap' 'sed -n /on/,/off/p' "on\nzap\noffon\n" "" \
54 'on\nzap\noffon\nping\noff\n'
57 "sed -e '3a boom' -e '/hre/i bang' -e '3a whack' -e '3c bong'" \
58 "one\ntwo\nbang\nbong\nboom\nwhack\nfour\n" "" \
59 "one\ntwo\nthree\nfour\n"
60 testing 'sed prodigaler newline' 'sed -e a\\ -e woo' 'one\nwoo\n' '' 'one'
61 testing 'sed newline staying away' 'sed s/o/x/' 'xne\ntwx' '' 'one\ntwo'
62 # Why on _earth_ is this not an error? There's a \ with no continuation!
63 testing 'sed what, _really_?' 'sed -e a\\ && echo yes really' \
64 'one\nyes really\n' '' 'one\n'