cut.tests 3.5 KB

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