cut.test 3.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. #!/bin/bash
  2. # Copyright 2013 Robin Mittal <robinmittal.it@gmail.com>
  3. # Copyright 2013 Divya Kothari <divya.s.kothari@gmail.com>
  4. # Copyright 2013 Kyungwan.Han <asura321@gmail.com>
  5. [ -f testing.sh ] && . testing.sh
  6. #testing "name" "command" "result" "infile" "stdin"
  7. # Creating test file for testing cut
  8. echo "one:two:three:four:five:six:seven
  9. alpha:beta:gamma:delta:epsilon:zeta:eta:theta:iota:kappa:lambda:mu
  10. the quick brown fox jumps over the lazy dog" >abc.txt
  11. testcmd "-b a,a,a" "-b 3,3,3 abc.txt" "e\np\ne\n" "" ""
  12. testcmd "-b overlaps" "-b 1-3,2-5,7-9,9-10 abc.txt" \
  13. "one:to:th\nalphabeta\nthe qick \n" "" ""
  14. testcmd "-b encapsulated" "-b 3-8,4-6 abc.txt" "e:two:\npha:be\ne quic\n" \
  15. "" ""
  16. testcmd "-bO overlaps" "-O ' ' -b 1-3,2-5,7-9,9-10 abc.txt" \
  17. "one:t o:th\nalpha beta\nthe q ick \n" "" ""
  18. testcmd "high-low error" "-b 8-3 abc.txt 2>/dev/null || echo err" "err\n" \
  19. "" ""
  20. testcmd "-c a-b" "-c 4-10 abc.txt" ":two:th\nha:beta\n quick \n" "" ""
  21. testcmd "-c a-" "-c 41- abc.txt" "\ntheta:iota:kappa:lambda:mu\ndog\n" "" ""
  22. testcmd "-c -b" "-c -39 abc.txt" \
  23. "one:two:three:four:five:six:seven\nalpha:beta:gamma:delta:epsilon:zeta:eta\nthe quick brown fox jumps over the lazy\n" \
  24. "" ""
  25. testcmd "-c a" "-c 40 abc.txt" "\n:\n \n" "" ""
  26. testcmd "-c a,b-c,d" "-c 3,5-7,10 abc.txt" "etwoh\npa:ba\nequi \n" "" ""
  27. toyonly testcmd "-c japan.txt" '-c 3-6,9-12 "$FILES/utf8/japan.txt"' \
  28. "ガラスをられます\n" "" ""
  29. toyonly testcmd "-C test1.txt" '-C -1 "$FILES/utf8/test1.txt"' "l̴̗̞̠\n" "" ""
  30. # substitute for awk
  31. testcmd "-DF" "-DF 2,7,5" \
  32. "said and your\nare\nis demand. supply\nforecast :\nyou you better,\n\nEm: Took hate\n" "" \
  33. "Bother, said Pooh. It's your husband, and he has a gun.
  34. Cheerios are donut seeds.
  35. Talk is cheap because supply exceeds demand.
  36. Weather forecast for tonight : dark.
  37. Apple: you can buy better, but you can't pay more.
  38. Subcalifragilisticexpialidocious.
  39. Auntie Em: Hate you, hate Kansas. Took the dog. Dorothy."
  40. testcmd "-DF 2" "-DF 7,1,3-6,2-5" \
  41. "seven one three four five six two three four five\n" "" \
  42. "one two three four five six seven eight nine\n"
  43. testcmd "empty field" "-d ':' -f 1-3" "a::b\n" "" "a::b\n"
  44. testcmd "empty field 2" "-d ':' -f 3-5" "b::c\n" "" "a::b::c:d\n"
  45. testcmd "-f a-" "-d ':' -f 5- abc.txt" "five:six:seven\nepsilon:zeta:eta:theta:iota:kappa:lambda:mu\nthe quick brown fox jumps over the lazy dog\n" "" ""
  46. testcmd "show whole line with no delim" "-d ' ' -f 3 abc.txt" \
  47. "one:two:three:four:five:six:seven\nalpha:beta:gamma:delta:epsilon:zeta:eta:theta:iota:kappa:lambda:mu\nbrown\n" "" ""
  48. testcmd "-c (a-b)" "-c 1-15 " "ref_categorie=t\n" "" "ref_categorie=test\n"
  49. testcmd "-c (a)" "-c 14" "=\n" "" "ref_categorie=test\n"
  50. # Modifying abc.txt data as per new testcase
  51. echo "abcdefghijklmnopqrstuvwxyz" >abc.txt
  52. testcmd "-c (a,b,c)" "-c 4,5,20 abc.txt" "det\n" "" ""
  53. testcmd "-b (a,b,c)" "-b 4,5,20 abc.txt" "det\n" "" ""
  54. # Modifying abc.txt data as per testcase
  55. echo "406378:Sales:Itorre:Jan
  56. 031762:Marketing:Nasium:Jim
  57. 636496:Research:Ancholie:Mel
  58. 396082:Sales:Jucacion:Ed" >abc.txt
  59. testcmd "-d -f(:) -s" "-d: -f3 -s abc.txt" "Itorre\nNasium\nAncholie\nJucacion\n" "" ""
  60. testcmd "-d -f( ) -s" "-d' ' -f3 -s abc.txt && echo yes" "yes\n" "" ""
  61. testcmd "-d -f(a) -s" "-da -f3 -s abc.txt" "n\nsium:Jim\n\ncion:Ed\n" "" ""
  62. testcmd "-d -f(a) -s -n" "-da -f3 -s -n abc.txt" "n\nsium:Jim\n\ncion:Ed\n" "" ""
  63. # Feature posix documents but nobody bothers to implement
  64. toyonly testcmd "-nb" '-nb 8-17 "$FILES/utf8/japan.txt"' "ガラス\n" "" ""
  65. # Feature that is, as far as I can tell, totally undocumented?
  66. testcmd "-d newline" "-d \$'\n' -f 2-3,5" "two\nthree\nfive\n" "" \
  67. 'one\ntwo\nthree\nfour\nfive\nsix\seven\n'
  68. # Removing abc.txt file for cleanup purpose
  69. rm abc.txt