Skip to content

Commit 29f9ed2

Browse files
committed
patch 8.0.1689: no tests for xxd
Problem: No tests for xxd. Solution: Add a test. (Christian Brabandt)
1 parent 6f47002 commit 29f9ed2

6 files changed

Lines changed: 107 additions & 1 deletion

File tree

‎src/Makefile‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2308,6 +2308,7 @@ test_arglist \
23082308
test_windows_home \
23092309
test_wordcount \
23102310
test_writefile \
2311+
test_xxd \
23112312
test_alot_latin \
23122313
test_alot_utf8 \
23132314
test_alot:

‎src/testdir/Make_all.mak‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,7 @@ NEW_TESTS = test_arabic.res \
188188
test_windows_home.res \
189189
test_wordcount.res \
190190
test_writefile.res \
191+
test_xxd.res \
191192
test_alot_latin.res \
192193
test_alot_utf8.res \
193194
test_alot.res

‎src/testdir/Makefile‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
# Use console or GUI.
66
VIMPROG = ../vim
7+
XXDPROG = ../xxd/xxd
78
# VIMPROG = ../gvim
89

910
SCRIPTSOURCE = ../../runtime
@@ -145,3 +146,6 @@ test_gui_init.res: test_gui_init.vim
145146

146147
opt_test.vim: ../option.c gen_opt_test.vim
147148
$(VIMPROG) -u NONE -S gen_opt_test.vim --noplugin --not-a-term ../option.c
149+
150+
test_xxd.res:
151+
XXD=$(XXDPROG); export XXD; $(RUN_VIMTEST) $(NO_INITS) -S runtest.vim test_xxd.vim

‎src/testdir/runtest.vim‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,11 @@ func FinishTesting()
199199
write
200200
endif
201201

202-
let message = 'Executed ' . s:done . (s:done > 1 ? ' tests' : ' test')
202+
if s:done == 0
203+
let message = 'NO tests executed'
204+
else
205+
let message = 'Executed ' . s:done . (s:done > 1 ? ' tests' : ' test')
206+
endif
203207
echo message
204208
call add(s:messages, message)
205209
if s:fail > 0

‎src/testdir/test_xxd.vim‎

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
" Test for the xxd command
2+
if empty($XXD) || !executable($XXD)
3+
finish
4+
endif
5+
6+
func! PrepareBuffer(command)
7+
%d
8+
call append(0, a:command)
9+
$d
10+
w XXDfile
11+
endfunc
12+
13+
func! s:Mess(counter)
14+
return printf("Failed xxd test %d:", a:counter)
15+
endfunc
16+
17+
func! Test_xxd()
18+
new
19+
call PrepareBuffer(range(1,30))
20+
" Test 1: simple, filter the result through xxd
21+
let s:test = 1
22+
%!$XXD %
23+
let expected = [
24+
\ '00000000: 310a 320a 330a 340a 350a 360a 370a 380a 1.2.3.4.5.6.7.8.',
25+
\ '00000010: 390a 3130 0a31 310a 3132 0a31 330a 3134 9.10.11.12.13.14',
26+
\ '00000020: 0a31 350a 3136 0a31 370a 3138 0a31 390a .15.16.17.18.19.',
27+
\ '00000030: 3230 0a32 310a 3232 0a32 330a 3234 0a32 20.21.22.23.24.2',
28+
\ '00000040: 350a 3236 0a32 370a 3238 0a32 390a 3330 5.26.27.28.29.30',
29+
\ '00000050: 0a .']
30+
call assert_equal(expected, getline(1,'$'), s:Mess(s:test))
31+
" Test 2: reverse the result
32+
let s:test += 1
33+
%!$XXD -r
34+
call assert_equal(map(range(1,30), {v,c -> string(c)}), getline(1,'$'), s:Mess(s:test))
35+
36+
" Test 3: Skip the first 30 bytes
37+
let s:test += 1
38+
%!$XXD -s 0x30 %
39+
call assert_equal(expected[3:], getline(1,'$'), s:Mess(s:test))
40+
41+
" Test 4: Skip the first 30 bytes
42+
let s:test += 1
43+
%!$XXD -s -0x31 %
44+
call assert_equal(expected[2:], getline(1,'$'), s:Mess(s:test))
45+
46+
" Test 5: Print 120 bytes as continuous hexdump with 20 octets per line
47+
let s:test += 1
48+
%d
49+
0r! $XXD -l 120 -ps -c 20 ../../runtime/doc/xxd.1
50+
$d
51+
let expected = [
52+
\ '2e54482058584420312022417567757374203139',
53+
\ '39362220224d616e75616c207061676520666f72',
54+
\ '20787864220a2e5c220a2e5c222032317374204d',
55+
\ '617920313939360a2e5c22204d616e2070616765',
56+
\ '20617574686f723a0a2e5c2220202020546f6e79',
57+
\ '204e7567656e74203c746f6e79407363746e7567']
58+
call assert_equal(expected, getline(1,'$'), s:Mess(s:test))
59+
" Test 6: Print the date from xxd.1
60+
let s:test += 1
61+
%d
62+
0r! $XXD -s 0x36 -l 13 -c 13 ../../runtime/doc/xxd.1
63+
$d
64+
call assert_equal('00000036: 3231 7374 204d 6179 2031 3939 36 21st May 1996', getline(1), s:Mess(s:test))
65+
" Test 7: Print C include
66+
let s:test += 1
67+
call writefile(['TESTabcd09'], 'XXDfile')
68+
%d
69+
0r! $XXD -i XXDfile
70+
$d
71+
let expected = ['unsigned char XXDfile[] = {',
72+
\ ' 0x54, 0x45, 0x53, 0x54, 0x61, 0x62, 0x63, 0x64, 0x30, 0x39, 0x0a', '};',
73+
\ 'unsigned int XXDfile_len = 11;']
74+
call assert_equal(expected, getline(1,'$'), s:Mess(s:test))
75+
" Test 8: Print C include capitalized
76+
let s:test += 1
77+
call writefile(['TESTabcd09'], 'XXDfile')
78+
%d
79+
0r! $XXD -i -C XXDfile
80+
$d
81+
let expected = ['unsigned char XXDFILE[] = {',
82+
\ ' 0x54, 0x45, 0x53, 0x54, 0x61, 0x62, 0x63, 0x64, 0x30, 0x39, 0x0a', '};',
83+
\ 'unsigned int XXDFILE_LEN = 11;']
84+
call assert_equal(expected, getline(1,'$'), s:Mess(s:test))
85+
" Test 9: Create a file with containing a single 'A'
86+
let s:test += 1
87+
call delete('XXDfile')
88+
call system('echo "010000: 41"|'.$XXD.' -r -s -0x10000 > XXDfile')
89+
call PrepareBuffer(readfile('XXDfile')[0])
90+
call assert_equal('A', getline(1), s:Mess(s:test))
91+
call delete('XXDfile')
92+
%d
93+
bw!
94+
endfunc

‎src/version.c‎

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

763763
static int included_patches[] =
764764
{ /* Add new patch number below this line */
765+
/**/
766+
1689,
765767
/**/
766768
1688,
767769
/**/

0 commit comments

Comments
 (0)