logo

utils-std

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

truncate.sh (705B)


  1. #!/bin/sh
  2. # SPDX-FileCopyrightText: 2017 Haelwenn (lanodan) Monnier <contact+utils@hacktivis.me>
  3. # SPDX-License-Identifier: MPL-2.0
  4. plans=24
  5. WD="$(dirname "$0")"
  6. target="${WD}/../cmd/truncate"
  7. . "${WD}/tap.sh"
  8. touch foo
  9. wc_c() {
  10. wc -c "$@" \
  11. | while read foo bar; do
  12. printf '%s,' "$foo"
  13. done
  14. }
  15. tt() {
  16. tt_name="tt_${1}" ; shift
  17. tt_size="$1" ; shift
  18. t_args "${tt_name}" '' "$@" foo
  19. t_cmd "${tt_name}_check" "${tt_size}," wc_c foo
  20. }
  21. tt 0 0 -s 0
  22. tt 666 666 -s 666
  23. tt 666K 681984 -s 666K
  24. tt 666KiB 681984 -s 666KiB
  25. tt 666KB 666000 -s 666KB
  26. tt 1024 1024 -s 1024
  27. tt -666 358 -s -666
  28. tt +666 1024 -s +666
  29. tt -1024 0 -s -1024
  30. tt 2560 2560 -s 2560
  31. tt %1K $((3*1024)) -s %1K
  32. tt /2K 2048 -s /2K
  33. rm foo