Mercurial > hg > toybox
annotate tests/sed.test @ 1566:62a7d617e1ce draft 0.5.1
Make md5sum and sha1sum work on big endian systems.
author | Rob Landley <rob@landley.net> |
---|---|
date | Wed, 19 Nov 2014 21:38:00 -0600 |
parents | e7944f8fdcbb |
children | ac84a209cb05 |
rev | line source |
---|---|
1539 | 1 #!/bin/echo Run scripts/test.sh |
2 | |
3 #testing "name" "command" "result" "infile" "stdin" | |
4 | |
1546 | 5 testing 'sed as cat' 'sed ""' "one\ntwo\nthree" "" "one\ntwo\nthree" |
6 | |
1539 | 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" | |
1546 | 13 testing 'no input means no last line' "sed '\$a boing'" "" "" "" |
14 testing 'sed -n $,$p' 'sed -n \$,\$p' 'three' '' 'one\ntwo\nthree' | |
1539 | 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" | |
1546 | 18 testing 'sed $ with 2 inputs' 'sed -n \$p - input' "four\n" "four\n" \ |
1539 | 19 "one\ntwo\nthree" |
1546 | 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' | |
26 | |
27 | |
28 # Fun with newlines! | |
29 testing '' 'sed -n 3p' "three" "" "one\ntwo\nthree" | |
1539 | 30 testing 'prodigal newline' "sed -n '1,\$p' - input" "one\ntwo\nthree\nfour\n" \ |
31 "four\n" "one\ntwo\nthree" | |
1546 | 32 testing 'Newline only added if further output' "sed -n 3p - input" "three" \ |
33 "four\n" "one\ntwo\nthree" | |
1539 | 34 |
1546 | 35 # Fun with match delimiters and escapes |
1539 | 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" | |
1544 | 40 testing 'sed match n delim' "sed -n '\n\txnp'" "\tx\n" "" "\tx\n" |
1546 | 41 testing 'sed match n delim disables \n newline' "sed -n '\n\nxnp'" "" "" "\nx\n" |
1555 | 42 SKIP_HOST=1 testing 'sed match \n literal n' "sed -n '\n\nxnp'" "nx\n" "" "nx\n" |
1544 | 43 testing 'end match does not check starting match line' \ |
44 "sed -n '/two/,/two/p'" "two\nthree" "" "one\ntwo\nthree" | |
45 testing 'end match/start match mixing number/letter' \ | |
46 "sed -n '2,/two/p'" "two\nthree" "" "one\ntwo\nthree" | |
47 testing 'sed num then regex' 'sed -n 2,/d/p' 'b\nc\nd\n' '' 'a\nb\nc\nd\ne\nf\n' | |
48 testing 'sed regex then num' 'sed -n /b/,4p' 'b\nc\nd\n' '' 'a\nb\nc\nd\ne\nf\n' | |
49 testing 'sed multiple regex address match' 'sed -n /on/,/off/p' \ | |
50 'bone\nturtle\scoff\ntron\nlurid\noffer\n' "" \ | |
51 'zap\nbone\nturtle\scoff\nfred\ntron\nlurid\noffer\nbecause\n' | |
52 testing 'sed regex address overlap' 'sed -n /on/,/off/p' "on\nzap\noffon\n" "" \ | |
53 'on\nzap\noffon\nping\noff\n' | |
54 | |
55 testing "sed aci" \ | |
56 "sed -e '3a boom' -e '/hre/i bang' -e '3a whack' -e '3c bong'" \ | |
57 "one\ntwo\nbang\nbong\nboom\nwhack\nfour\n" "" \ | |
58 "one\ntwo\nthree\nfour\n" | |
59 testing 'sed prodigaler newline' 'sed -e a\\ -e woo' 'one\nwoo\n' '' 'one' | |
60 testing 'sed newline staying away' 'sed s/o/x/' 'xne\ntwx' '' 'one\ntwo' | |
61 # Why on _earth_ is this not an error? There's a \ with no continuation! | |
62 testing 'sed what, _really_?' 'sed -e a\\ && echo yes really' \ | |
63 'one\nyes really\n' '' 'one\n' | |
1546 | 64 |
1555 | 65 # all the s/// test |
66 | |
67 | |
68 testing 'sed \1' "sed 's/t\\(w\\)o/za\\1py/'" "one\nzawpy\nthree" "" \ | |
69 "one\ntwo\nthree" | |
70 testing 'sed \1 p' "sed 's/t\\(w\\)o/za\\1py/p'" "one\nzawpy\nzawpy\nthree" \ | |
71 "" "one\ntwo\nthree" | |
72 testing 'sed \1 no newline' "sed 's/t\\(w\\)o/za\\1py/'" "one\nzawpy" "" \ | |
73 "one\ntwo" | |
74 testing 'sed \1 p no newline' "sed 's/t\\(w\\)o/za\\1py/p'" \ | |
75 "one\nzawpy\nzawpy" "" "one\ntwo" | |
76 testing 'sed -n s//\1/p' "sed -n 's/t\\(w\\)o/za\\1py/p'" "zawpy" "" "one\ntwo" | |
77 testing 'sed -n s//\1/p no newline' "sed -n 's/t\\(w\\)o/za\\1py/p'" "zawpy" \ | |
78 "" "one\ntwo" | |
1556
e7944f8fdcbb
Debugging pass on sed: make the existing test suite pass.
Rob Landley <rob@landley.net>
parents:
1555
diff
changeset
|
79 testing 'sed backref error' \ |
e7944f8fdcbb
Debugging pass on sed: make the existing test suite pass.
Rob Landley <rob@landley.net>
parents:
1555
diff
changeset
|
80 "sed 's/w/ale \2 ha/' >/dev/null 2>/dev/null || echo no" \ |
1555 | 81 "no\n" "" "one\ntwo\nthree" |
82 testing 'sed empty match after nonempty match' "sed -e 's/a*/c/g'" 'cbcncgc' \ | |
83 '' 'baaang' | |
84 testing 'sed empty match' "sed -e 's/[^ac]*/A/g'" 'AaAcA' '' 'abcde' | |
1556
e7944f8fdcbb
Debugging pass on sed: make the existing test suite pass.
Rob Landley <rob@landley.net>
parents:
1555
diff
changeset
|
85 testing 'sed s///#' "sed -e 's/TWO/four/i#comment'" "one\nfour\nthree" \ |
e7944f8fdcbb
Debugging pass on sed: make the existing test suite pass.
Rob Landley <rob@landley.net>
parents:
1555
diff
changeset
|
86 "" "one\ntwo\nthree" |