Denis Vlasenko | 30297a5 | 2007-11-26 07:23:27 +0000 | [diff] [blame] | 1 | #!/bin/sh |
| 2 | |
| 3 | # Copyright 2007 by Denys Vlasenko <vda.linux@googlemail.com> |
Denys Vlasenko | 0ef64bd | 2010-08-16 20:14:46 +0200 | [diff] [blame] | 4 | # Licensed under GPLv2, see file LICENSE in this source tree. |
Denis Vlasenko | 30297a5 | 2007-11-26 07:23:27 +0000 | [diff] [blame] | 5 | |
Mike Frysinger | caa7940 | 2009-11-04 18:41:22 -0500 | [diff] [blame] | 6 | . ./testing.sh |
Denis Vlasenko | 30297a5 | 2007-11-26 07:23:27 +0000 | [diff] [blame] | 7 | |
| 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 |
| 11 | |
| 12 | testing "cut '-' (stdin) and multi file handling" \ |
| 13 | "cut -d' ' -f2 - input" \ |
| 14 | "over\n""quick\n" \ |
| 15 | "the quick brown fox\n" \ |
| 16 | "jumps over the lazy dog\n" \ |
| 17 | |
Rob Landley | 0068ce2 | 2021-07-20 16:02:31 +0200 | [diff] [blame] | 18 | abc="\ |
| 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 |
| 22 | " |
| 23 | |
| 24 | testing "cut -b a,a,a" "cut -b 3,3,3 input" "e\np\ne\n" "$abc" "" |
| 25 | |
| 26 | testing "cut -b overlaps" "cut -b 1-3,2-5,7-9,9-10 input" \ |
| 27 | "one:to:th\nalphabeta\nthe qick \n" "$abc" "" |
| 28 | testing "-b encapsulated" "cut -b 3-8,4-6 input" "e:two:\npha:be\ne quic\n" \ |
| 29 | "$abc" "" |
| 30 | # --output-delimiter not implemnted (yet?) |
| 31 | #testing "cut -bO overlaps" \ |
| 32 | # "cut --output-delimiter ' ' -b 1-3,2-5,7-9,9-10 input" \ |
| 33 | # "one:t o:th\nalpha beta\nthe q ick \n" "$abc" "" |
| 34 | testing "cut high-low error" "cut -b 8-3 abc.txt 2>/dev/null || echo err" "err\n" \ |
| 35 | "$abc" "" |
| 36 | |
| 37 | testing "cut -c a-b" "cut -c 4-10 input" ":two:th\nha:beta\n quick \n" "$abc" "" |
| 38 | testing "cut -c a-" "cut -c 41- input" "\ntheta:iota:kappa:lambda:mu\ndog\n" "$abc" "" |
| 39 | testing "cut -c -b" "cut -c -39 input" \ |
| 40 | "one:two:three:four:five:six:seven\nalpha:beta:gamma:delta:epsilon:zeta:eta\nthe quick brown fox jumps over the lazy\n" \ |
| 41 | "$abc" "" |
| 42 | testing "cut -c a" "cut -c 40 input" "\n:\n \n" "$abc" "" |
| 43 | testing "cut -c a,b-c,d" "cut -c 3,5-7,10 input" "etwoh\npa:ba\nequi \n" "$abc" "" |
| 44 | |
| 45 | 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" "" |
| 46 | |
| 47 | testing "cut show whole line with no delim" "cut -d ' ' -f 3 input" \ |
| 48 | "one:two:three:four:five:six:seven\nalpha:beta:gamma:delta:epsilon:zeta:eta:theta:iota:kappa:lambda:mu\nbrown\n" "$abc" "" |
| 49 | |
| 50 | testing "cut with echo, -c (a-b)" "echo 'ref_categorie=test' | cut -c 1-15 " "ref_categorie=t\n" "" "" |
| 51 | testing "cut with echo, -c (a)" "echo 'ref_categorie=test' | cut -c 14" "=\n" "" "" |
| 52 | |
| 53 | testing "cut with -c (a,b,c)" "cut -c 4,5,20 input" "det\n" "abcdefghijklmnopqrstuvwxyz" "" |
| 54 | |
| 55 | testing "cut with -b (a,b,c)" "cut -b 4,5,20 input" "det\n" "abcdefghijklmnopqrstuvwxyz" "" |
| 56 | |
| 57 | input="\ |
| 58 | 406378:Sales:Itorre:Jan |
| 59 | 031762:Marketing:Nasium:Jim |
| 60 | 636496:Research:Ancholie:Mel |
| 61 | 396082:Sales:Jucacion:Ed |
| 62 | " |
| 63 | testing "cut with -d -f(:) -s" "cut -d: -f3 -s input" "Itorre\nNasium\nAncholie\nJucacion\n" "$input" "" |
| 64 | testing "cut with -d -f( ) -s" "cut -d' ' -f3 -s input && echo yes" "yes\n" "$input" "" |
| 65 | testing "cut with -d -f(a) -s" "cut -da -f3 -s input" "n\nsium:Jim\n\ncion:Ed\n" "$input" "" |
| 66 | testing "cut with -d -f(a) -s -n" "cut -da -f3 -s -n input" "n\nsium:Jim\n\ncion:Ed\n" "$input" "" |
| 67 | |
| 68 | # substitute for awk |
Denys Vlasenko | eaa8ee4 | 2021-08-15 20:15:42 +0200 | [diff] [blame] | 69 | optional FEATURE_CUT_REGEX |
Rob Landley | 0068ce2 | 2021-07-20 16:02:31 +0200 | [diff] [blame] | 70 | testing "cut -DF" "cut -DF 2,7,5" \ |
| 71 | "said and your\nare\nis demand. supply\nforecast :\nyou you better,\n\nEm: Took hate\n" "" \ |
| 72 | "Bother, said Pooh. It's your husband, and he has a gun. |
| 73 | Cheerios are donut seeds. |
| 74 | Talk is cheap because supply exceeds demand. |
| 75 | Weather forecast for tonight : dark. |
| 76 | Apple: you can buy better, but you can't pay more. |
| 77 | Subcalifragilisticexpialidocious. |
| 78 | Auntie Em: Hate you, hate Kansas. Took the dog. Dorothy." |
Denys Vlasenko | eaa8ee4 | 2021-08-15 20:15:42 +0200 | [diff] [blame] | 79 | SKIP= |
Rob Landley | 0068ce2 | 2021-07-20 16:02:31 +0200 | [diff] [blame] | 80 | |
| 81 | testing "cut empty field" "cut -d ':' -f 1-3" "a::b\n" "" "a::b\n" |
| 82 | testing "cut empty field 2" "cut -d ':' -f 3-5" "b::c\n" "" "a::b::c:d\n" |
| 83 | |
Denis Vlasenko | 30297a5 | 2007-11-26 07:23:27 +0000 | [diff] [blame] | 84 | exit $FAILCOUNT |