logo

utils-std

Collection of commonly available Unix tools git clone https://anongit.hacktivis.me/git/utils-std.git

wc.sh (1601B)


  1. #!/bin/sh
  2. # SPDX-FileCopyrightText: 2017 Haelwenn (lanodan) Monnier <contact+utils@hacktivis.me>
  3. # SPDX-License-Identifier: MPL-2.0
  4. WD="$(dirname "$0")/../"
  5. target="${WD}/cmd/wc"
  6. plans=24
  7. . "${WD}/test-cmd/tap.sh"
  8. . "${WD}/test-cmd/init_env.sh"
  9. t --input='a b c' 'a b c' '' '0 3 5
  10. '
  11. t --input='a
  12. b
  13. c
  14. ' 'a\nb\nc' '' '3 3 6
  15. '
  16. t --input='a
  17. b
  18. c
  19. ' 'a\nb\nc' '-clw' '3 3 6
  20. '
  21. t --input='a
  22. bb
  23. ccc
  24. ' 'a\nbb\nccc\n' '' '3 3 9
  25. '
  26. t --input='a
  27. bb
  28. ccc
  29. ' 'a\nbb\nccc\n:-clw' '-clw' '3 3 9
  30. '
  31. t --input='я нет 草' 'ru+jp:-m' '-m' '7
  32. '
  33. t --input='я нет 草' 'ru+jp:-mw' '-mw' '3 7
  34. '
  35. t --input='я нет 草' 'ru+jp:-mlw' '-mlw' '0 3 7
  36. '
  37. t --input='' 'empty_stdin' '' '0 0 0
  38. '
  39. t 'empty_file' "${WD}/test-cmd/inputs/empty" "0 0 0 ${WD}/test-cmd/inputs/empty
  40. "
  41. t --exit=1 'enoent' '/var/empty/e/no/ent' "wc: error: Failed opening file '/var/empty/e/no/ent': No such file or directory
  42. "
  43. # Formatting with reduced counts
  44. t --input='
  45. ' '\n:1l' '-l' '1
  46. '
  47. t --input='a
  48. ' 'a\n:1l' '-l' '1
  49. '
  50. t --input='
  51. ' '\n:1c' '-c' '1
  52. '
  53. t --input='a
  54. ' 'a\n:2c' '-c' '2
  55. '
  56. t --input='
  57. ' '\n:0w' '-w' '0
  58. '
  59. t --input='a
  60. ' 'a\n:1w' '-w' '1
  61. '
  62. t --input='
  63. ' '\n:1l1c' '-lc' '1 1
  64. '
  65. t --input='a
  66. ' 'a\n:1l2c' '-lc' '1 2
  67. '
  68. t --input='' 'empty_stdin:0c' '-c' '0
  69. '
  70. t --input='' 'empty_stdin:0c0l' '-cl' '0 0
  71. '
  72. t --input='' 'empty_stdin:0w' '-w' '0
  73. '
  74. # Total when multiple files are specified
  75. t --input='foo
  76. ' 'foo+empty' "${WD}/test-cmd/inputs/empty -" "\
  77. 0 0 0 ${WD}/test-cmd/inputs/empty
  78. 1 1 4
  79. 1 1 4 total
  80. "
  81. t --input='foo
  82. ' 'foo+empty:c' "-c ${WD}/test-cmd/inputs/empty -" "\
  83. 0 ${WD}/test-cmd/inputs/empty
  84. 4
  85. 4 total
  86. "