Skip to content

Commit 970f5d3

Browse files
committed
patch 8.1.0821: xxd "usage" output and other arguments not tested
Problem: Xxd "usage" output and other arguments not tested. Solution: Add a test to trigger the usage output in various ways. Fix uncovered problem.
1 parent e295609 commit 970f5d3

3 files changed

Lines changed: 66 additions & 23 deletions

File tree

src/testdir/test_xxd.vim

Lines changed: 60 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ endfunc
2020
func Test_xxd()
2121
call PrepareBuffer(range(1,30))
2222
set ff=unix
23-
w XXDfile
23+
w! XXDfile
2424

2525
" Test 1: simple, filter the result through xxd
2626
let s:test = 1
@@ -39,15 +39,19 @@ func Test_xxd()
3939
exe '%!' . s:xxd_cmd . ' -r'
4040
call assert_equal(map(range(1,30), {v,c -> string(c)}), getline(1,'$'), s:Mess(s:test))
4141

42-
" Test 3: Skip the first 30 bytes
42+
" Test 3: Skip the first 0x30 bytes
4343
let s:test += 1
44-
exe '%!' . s:xxd_cmd . ' -s 0x30 %'
45-
call assert_equal(expected[3:], getline(1,'$'), s:Mess(s:test))
44+
for arg in ['-s 0x30', '-s0x30', '-s+0x30', '-skip 0x030', '-seek 0x30', '-seek +0x30 --']
45+
exe '%!' . s:xxd_cmd . ' ' . arg . ' %'
46+
call assert_equal(expected[3:], getline(1,'$'), s:Mess(s:test))
47+
endfor
4648

4749
" Test 4: Skip the first 30 bytes
4850
let s:test += 1
49-
exe '%!' . s:xxd_cmd . ' -s -0x31 %'
50-
call assert_equal(expected[2:], getline(1,'$'), s:Mess(s:test))
51+
for arg in ['-s -0x31', '-s-0x31']
52+
exe '%!' . s:xxd_cmd . ' ' . arg . ' %'
53+
call assert_equal(expected[2:], getline(1,'$'), s:Mess(s:test))
54+
endfor
5155

5256
" Test 5: Print 120 bytes as continuous hexdump with 20 octets per line
5357
let s:test += 1
@@ -56,7 +60,7 @@ func Test_xxd()
5660
if has('win32') && !filereadable(fname)
5761
let fname = '../../doc/xxd.1'
5862
endif
59-
exe '0r! ' . s:xxd_cmd . ' -l 120 -ps -c 20 ' . fname
63+
exe '0r! ' . s:xxd_cmd . ' -l 120 -ps -c20 ' . fname
6064
$d
6165
let expected = [
6266
\ '2e54482058584420312022417567757374203139',
@@ -69,10 +73,12 @@ func Test_xxd()
6973

7074
" Test 6: Print the date from xxd.1
7175
let s:test += 1
72-
%d
73-
exe '0r! ' . s:xxd_cmd . ' -s 0x36 -l 13 -c 13 ' . fname
74-
$d
75-
call assert_equal('00000036: 3231 7374 204d 6179 2031 3939 36 21st May 1996', getline(1), s:Mess(s:test))
76+
for arg in ['-l 13', '-l13', '-len 13']
77+
%d
78+
exe '0r! ' . s:xxd_cmd . ' -s 0x36 -l 13 -cols 13 ' . fname
79+
$d
80+
call assert_equal('00000036: 3231 7374 204d 6179 2031 3939 36 21st May 1996', getline(1), s:Mess(s:test))
81+
endfor
7682

7783
" Test 7: Print C include
7884
let s:test += 1
@@ -87,14 +93,16 @@ func Test_xxd()
8793

8894
" Test 8: Print C include capitalized
8995
let s:test += 1
90-
call writefile(['TESTabcd09'], 'XXDfile')
91-
%d
92-
exe '0r! ' . s:xxd_cmd . ' -i -C XXDfile'
93-
$d
94-
let expected = ['unsigned char XXDFILE[] = {',
95-
\ ' 0x54, 0x45, 0x53, 0x54, 0x61, 0x62, 0x63, 0x64, 0x30, 0x39, 0x0a', '};',
96-
\ 'unsigned int XXDFILE_LEN = 11;']
97-
call assert_equal(expected, getline(1,'$'), s:Mess(s:test))
96+
for arg in ['-C', '-capitalize']
97+
call writefile(['TESTabcd09'], 'XXDfile')
98+
%d
99+
exe '0r! ' . s:xxd_cmd . ' -i ' . arg . ' XXDfile'
100+
$d
101+
let expected = ['unsigned char XXDFILE[] = {',
102+
\ ' 0x54, 0x45, 0x53, 0x54, 0x61, 0x62, 0x63, 0x64, 0x30, 0x39, 0x0a', '};',
103+
\ 'unsigned int XXDFILE_LEN = 11;']
104+
call assert_equal(expected, getline(1,'$'), s:Mess(s:test))
105+
endfor
98106

99107
" Test 9: Create a file with containing a single 'A'
100108
let s:test += 1
@@ -110,6 +118,39 @@ func Test_xxd()
110118
call PrepareBuffer(readfile('XXDfile')[0])
111119
call assert_equal('A', getline(1), s:Mess(s:test))
112120
call delete('XXDfile')
121+
122+
" Test 10: group with 4 octets
123+
let s:test += 1
124+
for arg in ['-g 4', '-group 4', '-g4']
125+
call writefile(['TESTabcd09'], 'XXDfile')
126+
%d
127+
exe '0r! ' . s:xxd_cmd . ' ' . arg . ' XXDfile'
128+
$d
129+
let expected = ['00000000: 54455354 61626364 30390a TESTabcd09.']
130+
call assert_equal(expected, getline(1,'$'), s:Mess(s:test))
131+
call delete('XXDfile')
132+
endfor
133+
134+
" TODO:
135+
" -o -offset
136+
113137
%d
114138
bw!
115139
endfunc
140+
141+
" Various ways with wrong arguments that trigger the usage output.
142+
func Test_xxd_usage()
143+
for arg in ['-c', '-g', '-o', '-s', '-l', '-X', 'one two three']
144+
new
145+
exe 'r! ' . s:xxd_cmd . ' ' . arg
146+
call assert_match("Usage:", join(getline(1, 3)))
147+
bwipe!
148+
endfor
149+
endfunc
150+
151+
func Test_xxd_version()
152+
new
153+
exe 'r! ' . s:xxd_cmd . ' -v'
154+
call assert_match("xxd V1.10 .* by Juergen Weigert", join(getline(1, 3)))
155+
bwipe!
156+
endfunc

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -787,6 +787,8 @@ static char *(features[]) =
787787

788788
static int included_patches[] =
789789
{ /* Add new patch number below this line */
790+
/**/
791+
821,
790792
/**/
791793
820,
792794
/**/

src/xxd/xxd.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -508,10 +508,10 @@ main(int argc, char *argv[])
508508
}
509509
else if (!STRNCMP(pp, "-c", 2))
510510
{
511-
if (pp[2] && STRNCMP("ols", pp + 2, 3))
512-
cols = (int)strtol(pp + 2, NULL, 0);
513-
else if (pp[2] && STRNCMP("apitalize", pp + 2, 9))
511+
if (pp[2] && !STRNCMP("apitalize", pp + 2, 9))
514512
capitalize = 1;
513+
else if (pp[2] && STRNCMP("ols", pp + 2, 3))
514+
cols = (int)strtol(pp + 2, NULL, 0);
515515
else
516516
{
517517
if (!argv[2])
@@ -523,7 +523,7 @@ main(int argc, char *argv[])
523523
}
524524
else if (!STRNCMP(pp, "-g", 2))
525525
{
526-
if (pp[2] && STRNCMP("group", pp + 2, 5))
526+
if (pp[2] && STRNCMP("roup", pp + 2, 4))
527527
octspergrp = (int)strtol(pp + 2, NULL, 0);
528528
else
529529
{

0 commit comments

Comments
 (0)