mirror of
https://github.com/vim/vim.git
synced 2025-09-24 03:44:06 -04:00
patch 8.0.1689: no tests for xxd
Problem: No tests for xxd. Solution: Add a test. (Christian Brabandt)
This commit is contained in:
@@ -2308,6 +2308,7 @@ test_arglist \
|
||||
test_windows_home \
|
||||
test_wordcount \
|
||||
test_writefile \
|
||||
test_xxd \
|
||||
test_alot_latin \
|
||||
test_alot_utf8 \
|
||||
test_alot:
|
||||
|
@@ -188,6 +188,7 @@ NEW_TESTS = test_arabic.res \
|
||||
test_windows_home.res \
|
||||
test_wordcount.res \
|
||||
test_writefile.res \
|
||||
test_xxd.res \
|
||||
test_alot_latin.res \
|
||||
test_alot_utf8.res \
|
||||
test_alot.res
|
||||
|
@@ -4,6 +4,7 @@
|
||||
|
||||
# Use console or GUI.
|
||||
VIMPROG = ../vim
|
||||
XXDPROG = ../xxd/xxd
|
||||
# VIMPROG = ../gvim
|
||||
|
||||
SCRIPTSOURCE = ../../runtime
|
||||
@@ -145,3 +146,6 @@ test_gui_init.res: test_gui_init.vim
|
||||
|
||||
opt_test.vim: ../option.c gen_opt_test.vim
|
||||
$(VIMPROG) -u NONE -S gen_opt_test.vim --noplugin --not-a-term ../option.c
|
||||
|
||||
test_xxd.res:
|
||||
XXD=$(XXDPROG); export XXD; $(RUN_VIMTEST) $(NO_INITS) -S runtest.vim test_xxd.vim
|
||||
|
@@ -199,7 +199,11 @@ func FinishTesting()
|
||||
write
|
||||
endif
|
||||
|
||||
let message = 'Executed ' . s:done . (s:done > 1 ? ' tests' : ' test')
|
||||
if s:done == 0
|
||||
let message = 'NO tests executed'
|
||||
else
|
||||
let message = 'Executed ' . s:done . (s:done > 1 ? ' tests' : ' test')
|
||||
endif
|
||||
echo message
|
||||
call add(s:messages, message)
|
||||
if s:fail > 0
|
||||
|
94
src/testdir/test_xxd.vim
Normal file
94
src/testdir/test_xxd.vim
Normal file
@@ -0,0 +1,94 @@
|
||||
" Test for the xxd command
|
||||
if empty($XXD) || !executable($XXD)
|
||||
finish
|
||||
endif
|
||||
|
||||
func! PrepareBuffer(command)
|
||||
%d
|
||||
call append(0, a:command)
|
||||
$d
|
||||
w XXDfile
|
||||
endfunc
|
||||
|
||||
func! s:Mess(counter)
|
||||
return printf("Failed xxd test %d:", a:counter)
|
||||
endfunc
|
||||
|
||||
func! Test_xxd()
|
||||
new
|
||||
call PrepareBuffer(range(1,30))
|
||||
" Test 1: simple, filter the result through xxd
|
||||
let s:test = 1
|
||||
%!$XXD %
|
||||
let expected = [
|
||||
\ '00000000: 310a 320a 330a 340a 350a 360a 370a 380a 1.2.3.4.5.6.7.8.',
|
||||
\ '00000010: 390a 3130 0a31 310a 3132 0a31 330a 3134 9.10.11.12.13.14',
|
||||
\ '00000020: 0a31 350a 3136 0a31 370a 3138 0a31 390a .15.16.17.18.19.',
|
||||
\ '00000030: 3230 0a32 310a 3232 0a32 330a 3234 0a32 20.21.22.23.24.2',
|
||||
\ '00000040: 350a 3236 0a32 370a 3238 0a32 390a 3330 5.26.27.28.29.30',
|
||||
\ '00000050: 0a .']
|
||||
call assert_equal(expected, getline(1,'$'), s:Mess(s:test))
|
||||
" Test 2: reverse the result
|
||||
let s:test += 1
|
||||
%!$XXD -r
|
||||
call assert_equal(map(range(1,30), {v,c -> string(c)}), getline(1,'$'), s:Mess(s:test))
|
||||
|
||||
" Test 3: Skip the first 30 bytes
|
||||
let s:test += 1
|
||||
%!$XXD -s 0x30 %
|
||||
call assert_equal(expected[3:], getline(1,'$'), s:Mess(s:test))
|
||||
|
||||
" Test 4: Skip the first 30 bytes
|
||||
let s:test += 1
|
||||
%!$XXD -s -0x31 %
|
||||
call assert_equal(expected[2:], getline(1,'$'), s:Mess(s:test))
|
||||
|
||||
" Test 5: Print 120 bytes as continuous hexdump with 20 octets per line
|
||||
let s:test += 1
|
||||
%d
|
||||
0r! $XXD -l 120 -ps -c 20 ../../runtime/doc/xxd.1
|
||||
$d
|
||||
let expected = [
|
||||
\ '2e54482058584420312022417567757374203139',
|
||||
\ '39362220224d616e75616c207061676520666f72',
|
||||
\ '20787864220a2e5c220a2e5c222032317374204d',
|
||||
\ '617920313939360a2e5c22204d616e2070616765',
|
||||
\ '20617574686f723a0a2e5c2220202020546f6e79',
|
||||
\ '204e7567656e74203c746f6e79407363746e7567']
|
||||
call assert_equal(expected, getline(1,'$'), s:Mess(s:test))
|
||||
" Test 6: Print the date from xxd.1
|
||||
let s:test += 1
|
||||
%d
|
||||
0r! $XXD -s 0x36 -l 13 -c 13 ../../runtime/doc/xxd.1
|
||||
$d
|
||||
call assert_equal('00000036: 3231 7374 204d 6179 2031 3939 36 21st May 1996', getline(1), s:Mess(s:test))
|
||||
" Test 7: Print C include
|
||||
let s:test += 1
|
||||
call writefile(['TESTabcd09'], 'XXDfile')
|
||||
%d
|
||||
0r! $XXD -i XXDfile
|
||||
$d
|
||||
let expected = ['unsigned char XXDfile[] = {',
|
||||
\ ' 0x54, 0x45, 0x53, 0x54, 0x61, 0x62, 0x63, 0x64, 0x30, 0x39, 0x0a', '};',
|
||||
\ 'unsigned int XXDfile_len = 11;']
|
||||
call assert_equal(expected, getline(1,'$'), s:Mess(s:test))
|
||||
" Test 8: Print C include capitalized
|
||||
let s:test += 1
|
||||
call writefile(['TESTabcd09'], 'XXDfile')
|
||||
%d
|
||||
0r! $XXD -i -C XXDfile
|
||||
$d
|
||||
let expected = ['unsigned char XXDFILE[] = {',
|
||||
\ ' 0x54, 0x45, 0x53, 0x54, 0x61, 0x62, 0x63, 0x64, 0x30, 0x39, 0x0a', '};',
|
||||
\ 'unsigned int XXDFILE_LEN = 11;']
|
||||
call assert_equal(expected, getline(1,'$'), s:Mess(s:test))
|
||||
" Test 9: Create a file with containing a single 'A'
|
||||
let s:test += 1
|
||||
call delete('XXDfile')
|
||||
call system('echo "010000: 41"|'.$XXD.' -r -s -0x10000 > XXDfile')
|
||||
call PrepareBuffer(readfile('XXDfile')[0])
|
||||
call assert_equal('A', getline(1), s:Mess(s:test))
|
||||
call delete('XXDfile')
|
||||
%d
|
||||
bw!
|
||||
endfunc
|
@@ -762,6 +762,8 @@ static char *(features[]) =
|
||||
|
||||
static int included_patches[] =
|
||||
{ /* Add new patch number below this line */
|
||||
/**/
|
||||
1689,
|
||||
/**/
|
||||
1688,
|
||||
/**/
|
||||
|
Reference in New Issue
Block a user