xxd.test 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. #!/bin/bash
  2. [ -f testing.sh ] && . testing.sh
  3. #testing "name" "command" "result" "infile" "stdin"
  4. echo "this is some text" > file1
  5. echo -n > file2
  6. # Note that the xxd in vim-common on Ubuntu 14 uses %07x for the file offset.
  7. testing "file1" "xxd file1" \
  8. "00000000: 7468 6973 2069 7320 736f 6d65 2074 6578 this is some tex\n00000010: 740a t.\n" \
  9. "" ""
  10. testing "file1 -l" "xxd -l 2 file1" \
  11. "00000000: 7468 th\n" \
  12. "" ""
  13. testing "-" "xxd -" \
  14. "00000000: 6865 6c6c 6f hello\n" "" "hello"
  15. testing "xxd" "xxd" \
  16. "00000000: 776f 726c 64 world\n" "" "world"
  17. testing "-c 8 -g 4 file1" "xxd -c 8 -g 4 file1" \
  18. "00000000: 74686973 20697320 this is \n00000008: 736f6d65 20746578 some tex\n00000010: 740a t.\n" "" ""
  19. testing "-c 8 -g 3 file1" "xxd -c 8 -g 3 file1" \
  20. "00000000: 746869 732069 7320 this is \n00000008: 736f6d 652074 6578 some tex\n00000010: 740a t.\n" "" ""
  21. testing "-i" "cat file1 | xxd -i -" " 0x74, 0x68, 0x69, 0x73, 0x20, 0x69, 0x73, 0x20, 0x73, 0x6f, 0x6d, 0x65,\n 0x20, 0x74, 0x65, 0x78, 0x74, 0x0a\n" "" ""
  22. testing "-o 0x8000" "xxd -o 0x8000 file1" "00008000: 7468 6973 2069 7320 736f 6d65 2074 6578 this is some tex\n00008010: 740a t.\n" "" ""
  23. testing "-p" "xxd -p file1" "7468697320697320736f6d6520746578740a\n" "" ""
  24. testing "-s" "xxd -s 13 file1" "0000000d: 7465 7874 0a text.\n" "" ""
  25. testing "-r" "echo -e ' 00000000: 7468 6973 2069 7320 736f 6d65 2074 6578 this is some tex\n00000010: 740a t.' | xxd -r" "this is some text\n" "" ""
  26. toyonly testing "-r -i" "echo -e '0x74, 0x68, 0x69, 0x73, 0x20, 0x69, 0x73, 0x20, 0x73, 0x6f, 0x6d, 0x65,\n 0x20, 0x74, 0x65, 0x78, 0x74, 0x0a' | xxd -ri" "this is some text\n" "" ""
  27. testing "-r -p" "echo 7468697320697320736f6d6520746578740a | xxd -r -p" "this is some text\n" "" ""
  28. testing "-r garbage" "echo '0000: 68 65 6c6c 6fxxxx' | xxd -r -" "hello" "" ""
  29. # -r will only read -c bytes (default 16) before skipping to the next line,
  30. # ignoring the rest.
  31. testing "-r long" \
  32. "echo '0000: 40404040404040404040404040404040404040404040404040404040404040404040404040404040' | xxd -r -" \
  33. "@@@@@@@@@@@@@@@@" "" ""
  34. # -r -p ignores the usual -p 30-byte/line limit (or any limit set by -c) and
  35. # will take as many bytes as you give it.
  36. testing "-r -p long" \
  37. "echo '40404040404040404040404040404040404040404040404040404040404040404040404040404040' | xxd -r -p -" \
  38. "@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@" "" ""
  39. rm file1 file2