• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/bin/bash
2
3[ -f testing.sh ] && . testing.sh
4
5#testing "name" "command" "result" "infile" "stdin"
6
7echo "this is some text" > file1
8echo -n > file2
9
10# Note that the xxd in vim-common on Ubuntu 14 uses %07x for the file offset.
11
12testcmd "file1" "file1" \
13    "00000000: 7468 6973 2069 7320 736f 6d65 2074 6578  this is some tex\n00000010: 740a                                     t.\n" \
14    "" ""
15testcmd "file1 -l" "-l 2 file1" \
16    "00000000: 7468                                     th\n" \
17    "" ""
18testcmd "-" "-" \
19    "00000000: 6865 6c6c 6f                             hello\n" "" "hello"
20testcmd "no args" "" \
21    "00000000: 776f 726c 64                             world\n" "" "world"
22testcmd "-c 8 -g 4 file1" "-c 8 -g 4 file1" \
23    "00000000: 74686973 20697320  this is \n00000008: 736f6d65 20746578  some tex\n00000010: 740a               t.\n" "" ""
24testcmd "-c 8 -g 3 file1" "-c 8 -g 3 file1" \
25    "00000000: 746869 732069 7320  this is \n00000008: 736f6d 652074 6578  some tex\n00000010: 740a                t.\n" "" ""
26
27testcmd "-i" "-i - < file1" "  0x74, 0x68, 0x69, 0x73, 0x20, 0x69, 0x73, 0x20, 0x73, 0x6f, 0x6d, 0x65,\n  0x20, 0x74, 0x65, 0x78, 0x74, 0x0a\n" "" ""
28
29testcmd "-o 0x8000" "-o 0x8000 file1" "00008000: 7468 6973 2069 7320 736f 6d65 2074 6578  this is some tex\n00008010: 740a                                     t.\n" "" ""
30
31testcmd "-p" "-p file1" "7468697320697320736f6d6520746578740a\n" "" ""
32
33# TODO: remove toyonly when distro catches up
34toyonly testcmd "-pc0" "-pc0" \
35  "73686f77203830206865782064696769747320776974686f757420776f72647772617070696e670a\n" \
36  "" "show 80 hex digits without wordwrapping\n"
37toyonly testcmd "-pc0 long" "-pc0 | wc -c" "97787\n" "" "$(seq 1 10000)"
38
39testcmd "-s" "-s 13 file1" \
40  "0000000d: 7465 7874 0a                             text.\n" "" ""
41
42testcmd "-r" "-r" "this is some text\n" "" \
43  '    00000000: 7468 6973 2069 7320 736f 6d65 2074 6578  this is some tex\n00000010: 740a                                     t.\n'
44
45toyonly testcmd "-r -i" "-ri" "this is some text\n" "" \
46  '0x74, 0x68, 0x69, 0x73, 0x20, 0x69, 0x73, 0x20, 0x73, 0x6f, 0x6d, 0x65,\n  0x20, 0x74, 0x65, 0x78, 0x74, 0x0a\n'
47
48testcmd "-r garbage" '-r -' 'hello' '' '0000: 68 65 6c6c 6fxxxx\n'
49
50# -r will only read -c bytes (default 16) before skipping to the next line,
51# ignoring the rest.
52testcmd "-r long" '-r -' "@@@@@@@@@@@@@@@@" "" \
53    '0000: 40404040404040404040404040404040404040404040404040404040404040404040404040404040\r'
54
55# -r -p ignores the usual -p 30-byte/line limit (or any limit set by -c) and
56# will take as many bytes as you give it.
57testcmd "-r -p long" '-r -p -' "@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@" "" \
58    '40404040404040404040404040404040404040404040404040404040404040404040404040404040\n'
59
60testcmd "-r unnecessary output seeks" '-r | xxd' \
61  "00000000: 0100 0000 0000 0000 0000 0000 0000 00ff  ................\n" '' \
62  '00000000: 0100 0000 0000 0000 0000 0000 0000 00ff  deadbeef........\n'
63
64# Little-endian, testing both the "EOF in first word on line" and "EOF in word
65# mid-line" cases.
66testcmd "LE partial" "-e -" \
67    "00000000:     6568                             he\n" "" "he"
68testcmd "LE partial mid-line" "-e -" \
69    "00000000: 6c6c6568       6f                    hello\n" "" "hello"
70
71rm file1 file2
72