X-Git-Url: http://git.osdn.net/view?a=blobdiff_plain;f=tests%2Fsed.test;h=75d6ec5d25c87b36536ce1b0f23d152fbf7b7d44;hb=1b9e29ec2a26c8e8b12fa4a2c928d88a1f63af51;hp=c62f9c4d72d1d40f33381d13e4b7ad8b3b11f40d;hpb=19ef8b8a7d596e032eb5b2449120d6d3d3031f0e;p=android-x86%2Fexternal-toybox.git diff --git a/tests/sed.test b/tests/sed.test index c62f9c4d..75d6ec5d 100755 --- a/tests/sed.test +++ b/tests/sed.test @@ -2,26 +2,26 @@ #testing "name" "command" "result" "infile" "stdin" -testing 'sed as cat' 'sed ""' "one\ntwo\nthree" "" "one\ntwo\nthree" +testing 'as cat' 'sed ""' "one\ntwo\nthree" "" "one\ntwo\nthree" # This segfaults ubuntu 12.04's sed. No really. SKIP_HOST=1 testing 'sed - - twice' 'sed "" - -' "hello\n" "" "hello\n" -testing 'sed -n' 'sed -n ""' "" "" "one\ntwo\nthree" -testing 'sed -n p' 'sed -n p' "one\ntwo\nthree" "" "one\ntwo\nthree" -testing 'sed explicit pattern' 'sed -e p -n' "one\ntwo\nthree" "" \ +testing '-n' 'sed -n ""' "" "" "one\ntwo\nthree" +testing '-n p' 'sed -n p' "one\ntwo\nthree" "" "one\ntwo\nthree" +testing 'explicit pattern' 'sed -e p -n' "one\ntwo\nthree" "" \ "one\ntwo\nthree" # Exploring the wonders of sed addressing modes testing '' 'sed -n 1p' "one\n" "" "one\ntwo\nthree" testing '' 'sed 2p' "one\ntwo\ntwo\nthree" "" "one\ntwo\nthree" testing '' 'sed -n 2p' "two\n" "" "one\ntwo\nthree" -testing 'sed -n $p' 'sed -n \$p' "three" "" "one\ntwo\nthree" -testing 'sed as cat #2' "sed -n '1,\$p'" "one\ntwo\nthree" "" "one\ntwo\nthree" -testing 'sed no input means no last line' "sed '\$a boing'" "" "" "" -testing 'sed -n $,$p' 'sed -n \$,\$p' 'three' '' 'one\ntwo\nthree' +testing '-n $p' 'sed -n \$p' "three" "" "one\ntwo\nthree" +testing 'as cat #2' "sed -n '1,\$p'" "one\ntwo\nthree" "" "one\ntwo\nthree" +testing 'no input means no last line' "sed '\$a boing'" "" "" "" +testing '-n $,$p' 'sed -n \$,\$p' 'three' '' 'one\ntwo\nthree' testing '' 'sed -n 1,2p' "one\ntwo\n" "" "one\ntwo\nthree" testing '' 'sed -n 2,3p' "two\nthree" "" "one\ntwo\nthree" testing '' 'sed -n 2,1p' "two\n" "" "one\ntwo\nthree" -testing 'sed $ with 2 inputs' 'sed -n \$p - input' "four\n" "four\n" \ +testing '$ with 2 inputs' 'sed -n \$p - input' "four\n" "four\n" \ "one\ntwo\nthree" testing '' 'sed -n /two/p' "two\n" "" "one\ntwo\nthree" testing '' 'sed -n 1,/two/p' 'one\ntwo\n' '' 'one\ntwo\nthree' @@ -33,54 +33,60 @@ testing 'sed -n /two/,$p' 'sed -n /two/,\$p' 'two\nthree' '' 'one\ntwo\nthree' # Fun with newlines! testing '' 'sed -n 3p' "three" "" "one\ntwo\nthree" -testing 'sed prodigal newline' "sed -n '1,\$p' - input" \ +testing 'prodigal newline' "sed -n '1,\$p' - input" \ "one\ntwo\nthree\nfour\n" "four\n" "one\ntwo\nthree" -testing 'sed Newline only added if further output' "sed -n 3p - input" "three" \ +testing 'Newline only added if further output' "sed -n 3p - input" "three" \ "four\n" "one\ntwo\nthree" # Fun with match delimiters and escapes -testing 'sed match \t tab' "sed -n '/\t/p'" "\tx\n" "" "\tx\n" -testing 'sed match t delim disables \t tab' "sed -n '\t\txtp'" "" "" "\tx\n" -testing 'sed match t delim makes \t literal t' \ +testing 'match \t tab' "sed -n '/\t/p'" "\tx\n" "" "\tx\n" +testing 'match t delim disables \t tab' "sed -n '\t\txtp'" "" "" "\tx\n" +testing 'match t delim makes \t literal t' \ "sed -n '\t\txtp'" "tx\n" "" "tx\n" -testing 'sed match n delim' "sed -n '\n\txnp'" "\tx\n" "" "\tx\n" -testing 'sed match n delim disables \n newline' "sed -n '\n\nxnp'" "" "" "\nx\n" -SKIP_HOST=1 testing 'sed match \n literal n' "sed -n '\n\nxnp'" "nx\n" "" "nx\n" -testing 'sed end match does not check starting match line' \ +testing 'match n delim' "sed -n '\n\txnp'" "\tx\n" "" "\tx\n" +testing 'match n delim disables \n newline' "sed -n '\n\nxnp'" "" "" "\nx\n" +SKIP_HOST=1 testing 'match \n literal n' "sed -n '\n\nxnp'" "nx\n" "" "nx\n" +testing 'end match does not check starting match line' \ "sed -n '/two/,/two/p'" "two\nthree" "" "one\ntwo\nthree" -testing 'sed end match/start match mixing number/letter' \ +testing 'end match/start match mixing number/letter' \ "sed -n '2,/two/p'" "two\nthree" "" "one\ntwo\nthree" -testing 'sed num then regex' 'sed -n 2,/d/p' 'b\nc\nd\n' '' 'a\nb\nc\nd\ne\nf\n' -testing 'sed regex then num' 'sed -n /b/,4p' 'b\nc\nd\n' '' 'a\nb\nc\nd\ne\nf\n' -testing 'sed multiple regex address match' 'sed -n /on/,/off/p' \ +testing 'num then regex' 'sed -n 2,/d/p' 'b\nc\nd\n' '' 'a\nb\nc\nd\ne\nf\n' +testing 'regex then num' 'sed -n /b/,4p' 'b\nc\nd\n' '' 'a\nb\nc\nd\ne\nf\n' +testing 'multiple regex address match' 'sed -n /on/,/off/p' \ 'bone\nturtle\scoff\ntron\nlurid\noffer\n' "" \ 'zap\nbone\nturtle\scoff\nfred\ntron\nlurid\noffer\nbecause\n' -testing 'sed regex address overlap' 'sed -n /on/,/off/p' "on\nzap\noffon\n" "" \ +testing 'regex address overlap' 'sed -n /on/,/off/p' "on\nzap\noffon\n" "" \ 'on\nzap\noffon\nping\noff\n' +testing 'getdelim with nested [:blah:]' 'sed -n "sa\a[a[:space:]bc]*aXXagp"' \ + "ABXXCDXXEFXXGHXXIXX" "" "ABaaCDa EFaa aGHa a Ia " +testing '[ in [[]' "sed 's@[[]@X@g'" "X" "" "[" +testing '[[] with ] as delimiter' "sed 's][[]]X]g'" "X" "" "[" +testing '[[] with [ as delimiter' "sed 's[\[\[][X['" "X" "" "[" # gGhHlnNpPqrstwxy:= # s///#comment # abcdDi -testing 'sed prodigaler newline' 'sed -e a\\ -e woo' 'one\nwoo\n' '' 'one' -testing "sed aci" \ +testing 'prodigaler newline' 'sed -e a\\ -e woo' 'one\nwoo\n' '' 'one' +testing "aci" \ "sed -e '3a boom' -e '/hre/i bang' -e '3a whack' -e '3c bong'" \ "one\ntwo\nbang\nbong\nboom\nwhack\nfour\n" "" \ "one\ntwo\nthree\nfour\n" -testing "sed b loop" "sed ':woo;=;b woo' | head -n 5" '1\n1\n1\n1\n1\n' "" "X" -testing "sed b skip" "sed -n '2b zap;d;:zap;p'" "two\n" "" "one\ntwo\nthree" -testing "sed b end" "sed -n '2b;p'" "one\nthree" "" "one\ntwo\nthree" -testing "sed c range" "sed '2,4c blah'" "one\nblah\nfive\nsix" "" \ +testing "b loop" "sed ':woo;=;b woo' | head -n 5" '1\n1\n1\n1\n1\n' "" "X" +testing "b skip" "sed -n '2b zap;d;:zap;p'" "two\n" "" "one\ntwo\nthree" +testing "b end" "sed -n '2b;p'" "one\nthree" "" "one\ntwo\nthree" +testing "c range" "sed '2,4c blah'" "one\nblah\nfive\nsix" "" \ "one\ntwo\nthree\nfour\nfive\nsix" -testing "sed c {range}" "sed -e '2,4{c blah' -e '}'" \ +testing "c {range}" "sed -e '2,4{c blah' -e '}'" \ "one\nblah\nblah\nblah\nfive\nsix" \ "" "one\ntwo\nthree\nfour\nfive\nsix" -testing "sed c multiple continuation" \ +testing "c multiple continuation" \ "sed -e 'c\\' -e 'two\\' -e ''" "two\n\n" "" "hello" -testing "sed D further processing depends on whether line is blank" \ +SKIP_HOST=1 testing "c empty continuation" "sed -e 'c\\'" "\n" "" "hello" +testing "D further processing depends on whether line is blank" \ "sed -e '/one/,/three/{' -e 'i meep' -e'N;2D;}'" \ "meep\nmeep\ntwo\nthree\n" "" "one\ntwo\nthree\n" -testing 'sed newline staying away' 'sed s/o/x/' 'xne\ntwx' '' 'one\ntwo' +testing 'newline staying away' 'sed s/o/x/' 'xne\ntwx' '' 'one\ntwo' # Why on _earth_ is this not an error? There's a \ with no continuation! #testing 'sed what, _really_?' 'sed -e a\\ && echo yes really' \ @@ -88,36 +94,36 @@ testing 'sed newline staying away' 'sed s/o/x/' 'xne\ntwx' '' 'one\ntwo' # all the s/// test -testing "sed match empty line" "sed -e 's/^\$/@/'" "@\n" "" "\n" +testing "match empty line" "sed -e 's/^\$/@/'" "@\n" "" "\n" -testing 'sed \1' "sed 's/t\\(w\\)o/za\\1py/'" "one\nzawpy\nthree" "" \ +testing '\1' "sed 's/t\\(w\\)o/za\\1py/'" "one\nzawpy\nthree" "" \ "one\ntwo\nthree" -testing 'sed \1 p' "sed 's/t\\(w\\)o/za\\1py/p'" "one\nzawpy\nzawpy\nthree" \ +testing '\1 p' "sed 's/t\\(w\\)o/za\\1py/p'" "one\nzawpy\nzawpy\nthree" \ "" "one\ntwo\nthree" -testing 'sed \1 no newline' "sed 's/t\\(w\\)o/za\\1py/'" "one\nzawpy" "" \ +testing '\1 no newline' "sed 's/t\\(w\\)o/za\\1py/'" "one\nzawpy" "" \ "one\ntwo" -testing 'sed \1 p no newline' "sed 's/t\\(w\\)o/za\\1py/p'" \ +testing '\1 p no newline' "sed 's/t\\(w\\)o/za\\1py/p'" \ "one\nzawpy\nzawpy" "" "one\ntwo" -testing 'sed -n s//\1/p' "sed -n 's/t\\(w\\)o/za\\1py/p'" "zawpy" "" "one\ntwo" -testing 'sed -n s//\1/p no newline' "sed -n 's/t\\(w\\)o/za\\1py/p'" "zawpy" \ +testing '-n s//\1/p' "sed -n 's/t\\(w\\)o/za\\1py/p'" "zawpy" "" "one\ntwo" +testing '-n s//\1/p no newline' "sed -n 's/t\\(w\\)o/za\\1py/p'" "zawpy" \ "" "one\ntwo" -testing 'sed backref error' \ +testing 'backref error' \ "sed 's/w/ale \2 ha/' >/dev/null 2>/dev/null || echo no" \ "no\n" "" "one\ntwo\nthree" -testing 'sed empty match after nonempty match' "sed -e 's/a*/c/g'" 'cbcncgc' \ +testing 'empty match after nonempty match' "sed -e 's/a*/c/g'" 'cbcncgc' \ '' 'baaang' -testing 'sed empty match' "sed -e 's/[^ac]*/A/g'" 'AaAcA' '' 'abcde' -testing 'sed s///#comment' "sed -e 's/TWO/four/i#comment'" "one\nfour\nthree" \ +testing 'empty match' "sed -e 's/[^ac]*/A/g'" 'AaAcA' '' 'abcde' +testing 's///#comment' "sed -e 's/TWO/four/i#comment'" "one\nfour\nthree" \ "" "one\ntwo\nthree" -testing 'sed N flushes pending a and advances match counter' \ +testing 'N flushes pending a and advances match counter' \ "sed -e 'a woo' -e 'N;\$p'" 'woo\none\ntwo\none\ntwo' "" 'one\ntwo' -testing "sed delimiter in regex [char range] doesn't count" "sed -e 's/[/]//'" \ +testing "delimiter in regex [char range] doesn't count" "sed -e 's/[/]//'" \ "onetwo\n" "" 'one/two\n' -testing "sed delete regex range start line after trigger" \ +testing "delete regex range start line after trigger" \ "sed -e '/one/,/three/{' -e 'i meep' -e '1D;}'" \ "meep\nmeep\ntwo\nmeep\nthree" "" "one\ntwo\nthree" -testing "sed blank pattern repeats last pattern" \ +testing "blank pattern repeats last pattern" \ "sed -e '/^three/s//abc&def/'" \ "one two three\nabcthreedef four five\nfive six seven\n" "" \ "one two three\nthree four five\nfive six seven\n" @@ -126,28 +132,32 @@ testing "sed blank pattern repeats last pattern" \ testing "" "sed -e '1a\' -e 'huh'" "meep\nhuh\n" "" "meep" testing "" "sed -f input" "blah\nboom\n" '1a\\\nboom' 'blah' +testing "" "sed -f - input" "blah\nboom\n" 'blah' '1a\\\nboom' testing "" "sed '1a\ hello'" "merp\nhello\n" "" "merp" testing "" "sed -e '/x/c\' -e 'y'" 'y\n' '' 'x\n' testing "" "sed -e 's/a[([]*b/X/'" 'X' '' 'a[(b' testing "" "sed 'y/a\\bc/de\f/'" "db\f" "" "abc" -testing "sed [a-a] (for perl)" "sed '"'s/\([^a-zA-Z0-9.:_\-\/]\)/\\\1/g'"'" \ +testing "[a-a] (for perl)" "sed '"'s/\([^a-zA-Z0-9.:_\-\/]\)/\\\1/g'"'" \ 'he\ llo' "" "he llo" +# Debian bug https://bugs.debian.org/635570 added code to ensure a file +# ends with a newline via "sed -e '$a\'". Apparently all a\ with no additional +# pattern lines after it does (other than making posix throw up) is +# flush the pending newline as _if_ it had added another line. *shrug* Ok? +testing "trailing a\ (for debian)" "sed 'a\\'" "hello\n" "" "hello" + # You have to match the first line of a range in order to activate # the range, numeric and ascii work the same way -testing "sed skip start of range" "sed -e n -e '1,2s/b/c/'" "a\nb\n" "" "a\nb\n" +testing "skip start of range" "sed -e n -e '1,2s/b/c/'" "a\nb\n" "" "a\nb\n" #echo meep | sed/sed -e '1a\' -e 'huh' #echo blah | sed/sed -f <(echo -e "1a\\\\\nboom") #echo merp | sed/sed "1a\\ #hello" -testing "sed bonus backslashes" \ +testing "bonus backslashes" \ "sed -e 'a \l \x\' -e \"\$(echo -e 'ab\\\nc')\"" \ "hello\nl x\nab\nc\n" "" "hello\n" # -i with $ last line test - - -exit $FAILCOUNT