xxd.tests 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. #!/bin/sh
  2. # Copyright 2020 by Denys Vlasenko <vda.linux@googlemail.com>
  3. # Licensed under GPLv2, see file LICENSE in this source tree.
  4. . ./testing.sh
  5. # testing "description" "command" "result" "infile" "stdin"
  6. testing 'xxd -p with one NUL' \
  7. 'xxd -p' \
  8. "\
  9. 00
  10. " \
  11. '' \
  12. '\0'
  13. testing 'xxd -p with 30 NULs' \
  14. 'xxd -p' \
  15. "\
  16. 000000000000000000000000000000000000000000000000000000000000
  17. " \
  18. '' \
  19. '\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0'
  20. testing 'xxd -p with 31 NULs' \
  21. 'xxd -p' \
  22. "\
  23. 000000000000000000000000000000000000000000000000000000000000
  24. 00
  25. " \
  26. '' \
  27. '\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0'
  28. testing 'xxd -p -r' \
  29. 'xxd -p -r' \
  30. '01234567765432100123456776543210' \
  31. '' \
  32. '30313233343536373736353433323130 30313233343536373736353433323130'
  33. testing 'xxd -r skips leading whitespace and truncates at two spaces' \
  34. 'xxd -r' \
  35. '0123456789:;<=>?@' \
  36. '' "\
  37. 00000000: 3031 3233 3435 3637 3839 3a3b 3c3d 3e3f 0123456789:;<=>?
  38. 00000010: 40 @
  39. "
  40. testing 'xxd -p -r skips one bad char, truncates at two bad chars' \
  41. 'xxd -p -r' \
  42. '01' \
  43. '' "\
  44. 30 !31 !!32
  45. "
  46. testing 'xxd -p -r ignores the nibble with 2nd char bad' \
  47. 'xxd -p -r' \
  48. '3C6' \
  49. '' "\
  50. 33 3!4 3!!5
  51. 36
  52. "
  53. exit $FAILCOUNT