3 # Copyright 2007 by Denys Vlasenko <vda.linux@googlemail.com>
4 # Licensed under GPLv2, see file LICENSE in this source tree.
8 # testing "test name" "options" "expected result" "file input" "stdin"
9 # file input will be file called "input"
10 # test can create a file "actual" instead of writing to stdout
12 testing
"cut '-' (stdin) and multi file handling" \
13 "cut -d' ' -f2 - input" \
15 "the quick brown fox\n" \
16 "jumps over the lazy dog\n" \
19 one:two:three:four:five:six:seven
20 alpha:beta:gamma:delta:epsilon:zeta:eta:theta:iota:kappa:lambda:mu
21 the quick brown fox jumps over the lazy dog
24 testing
"cut -b a,a,a" "cut -b 3,3,3 input" "e\np\ne\n" "$abc" ""
26 testing
"cut -b overlaps" \
27 "cut -b 1-3,2-5,7-9,9-10 input" \
33 testing
"-b encapsulated" \
34 "cut -b 3-8,4-6 input" \
41 testing
"cut -b --output-delimiter overlaps" \
42 "cut --output-delimiter='^' -b 1-3,2-5,7-9,9-10 input" \
50 testing
"cut high-low error" "cut -b 8-3 input 2>/dev/null || echo err" "err\n" \
53 testing
"cut -b 2-1 error" "cut -b 2-1 input 2>/dev/null || echo err" "err\n" \
56 testing
"cut -c a-b" "cut -c 4-10 input" ":two:th\nha:beta\n quick \n" "$abc" ""
57 testing
"cut -c a-" "cut -c 41- input" "\ntheta:iota:kappa:lambda:mu\ndog\n" "$abc" ""
58 testing
"cut -c -b" "cut -c -39 input" \
59 "one:two:three:four:five:six:seven\nalpha:beta:gamma:delta:epsilon:zeta:eta\nthe quick brown fox jumps over the lazy\n" \
61 testing
"cut -c a" "cut -c 40 input" "\n:\n \n" "$abc" ""
62 testing
"cut -c a,b-c,d" "cut -c 3,5-7,10 input" "etwoh\npa:ba\nequi \n" "$abc" ""
64 testing
"cut -f a-" "cut -d ':' -f 5- input" "five:six:seven\nepsilon:zeta:eta:theta:iota:kappa:lambda:mu\nthe quick brown fox jumps over the lazy dog\n" "$abc" ""
66 testing
"cut show whole line with no delim" "cut -d ' ' -f 3 input" \
67 "one:two:three:four:five:six:seven\nalpha:beta:gamma:delta:epsilon:zeta:eta:theta:iota:kappa:lambda:mu\nbrown\n" "$abc" ""
69 testing
"cut with echo, -c (a-b)" "echo 'ref_categorie=test' | cut -c 1-15 " "ref_categorie=t\n" "" ""
70 testing
"cut with echo, -c (a)" "echo 'ref_categorie=test' | cut -c 14" "=\n" "" ""
72 testing
"cut with -c (a,b,c)" "cut -c 4,5,20 input" "det\n" "abcdefghijklmnopqrstuvwxyz" ""
74 testing
"cut with -b (a,b,c)" "cut -b 4,5,20 input" "det\n" "abcdefghijklmnopqrstuvwxyz" ""
77 406378:Sales:Itorre:Jan
78 031762:Marketing:Nasium:Jim
79 636496:Research:Ancholie:Mel
80 396082:Sales:Jucacion:Ed
82 testing
"cut with -d -f(:) -s" "cut -d: -f3 -s input" "Itorre\nNasium\nAncholie\nJucacion\n" "$input" ""
83 testing
"cut with -d -f( ) -s" "cut -d' ' -f3 -s input && echo yes" "yes\n" "$input" ""
84 testing
"cut with -d -f(a) -s" "cut -da -f3 -s input" "n\nsium:Jim\n\ncion:Ed\n" "$input" ""
85 testing
"cut with -d -f(a) -s -n" "cut -da -f3 -s -n input" "n\nsium:Jim\n\ncion:Ed\n" "$input" ""
94 testing
"cut with -d -s omits blank lines" "cut -d' ' -f2 -s input" "bar\nbong\n" "$input" ""
97 optional FEATURE_CUT_REGEX
98 testing
"cut -DF unordered" "cut -DF 2,7,5" \
108 "Bother, said Pooh. It's your husband, and he has a gun.
109 Cheerios are donut seeds.
110 Talk is cheap because supply exceeds demand.
111 Weather forecast for tonight : dark.
112 Apple: you can buy better, but you can't pay more.
113 Subcalifragilisticexpialidocious.
114 Auntie Em: Hate you, hate Kansas. Took the dog. Dorothy."
116 # No delimiter found: print entire line regardless of -F RANGES
117 testing
"cut -F1" "cut -d: -F1" \
118 "the_only_field\n" "" \
120 testing
"cut -F2" "cut -d: -F2" \
121 "the_only_field\n" "" \
123 # No delimiter found and -s: skip entire line
124 testing
"cut -sF1" "cut -d: -sF1" \
127 #^^^ the above is probably mishandled by toybox, it prints the line
128 testing
"cut -sF2" "cut -d: -sF2" \
131 # -D disables special handling of lines with no delimiters, the line is treated as the 1st field
132 testing
"cut -DF1" "cut -d: -DF1" \
133 "the_only_field\n" "" \
135 testing
"cut -DF2" "cut -d: -DF2" \
139 optional FEATURE_CUT_REGEX LONG_OPTS
140 testing
"cut -F preserves intermediate delimiters" \
141 "cut --output-delimiter=: -F2,4-6,7" \
143 "" "1 2 3 4\t\t5 6 7 8\n"
147 testing
"cut -f does not preserve intermediate delimiters" \
148 "cut --output-delimiter=: -d' ' -f2,4-6,7" \
150 "" "1 2 3 4 5 6 7 8\n"
153 testing
"cut empty field" "cut -d ':' -f 1-3" \
156 testing
"cut empty field 2" "cut -d ':' -f 3-5" \
159 testing
"cut non-existing field" "cut -d ':' -f1,3" \
163 # cut -d$'\n' has a special meaning: "select input lines".
164 # I didn't find any documentation for this feature.
165 testing
"cut -dNEWLINE" \
169 "" "1\n2\n3\n4\n5\n6\n7"
172 testing
"cut -dNEWLINE --output-delimiter" \
174 ' --output-delimiter=@@ -f4,2,6-8" \
176 "" "1\n2\n3\n4\n5\n6\n7"
178 testing
"cut -dNEWLINE --output-delimiter 2" \
180 ' --output-delimiter=@@ -f4,2,6-8" \
182 "" "1\n2\n3\n4\n5\n6\n7\n"
184 testing
"cut -dNEWLINE --output-delimiter EMPTY_INPUT" \
186 ' --output-delimiter=@@ -f4,2,6-8" \
191 # This seems to work as if delimiter is never found.
192 # We test here that -d '' does *not* operate as if there was no -d
193 # and delimiter has defaulted to TAB:
194 testing
"cut -d EMPTY" \
198 testing
"cut -d EMPTY -s" \
199 "cut -d '' -f2- -s" \