mirror of
https://github.com/vim/vim.git
synced 2025-09-29 04:34:16 -04:00
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.
This commit is contained in:
@@ -20,7 +20,7 @@ endfunc
|
||||
func Test_xxd()
|
||||
call PrepareBuffer(range(1,30))
|
||||
set ff=unix
|
||||
w XXDfile
|
||||
w! XXDfile
|
||||
|
||||
" Test 1: simple, filter the result through xxd
|
||||
let s:test = 1
|
||||
@@ -39,15 +39,19 @@ func Test_xxd()
|
||||
exe '%!' . s:xxd_cmd . ' -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
|
||||
" Test 3: Skip the first 0x30 bytes
|
||||
let s:test += 1
|
||||
exe '%!' . s:xxd_cmd . ' -s 0x30 %'
|
||||
call assert_equal(expected[3:], getline(1,'$'), s:Mess(s:test))
|
||||
for arg in ['-s 0x30', '-s0x30', '-s+0x30', '-skip 0x030', '-seek 0x30', '-seek +0x30 --']
|
||||
exe '%!' . s:xxd_cmd . ' ' . arg . ' %'
|
||||
call assert_equal(expected[3:], getline(1,'$'), s:Mess(s:test))
|
||||
endfor
|
||||
|
||||
" Test 4: Skip the first 30 bytes
|
||||
let s:test += 1
|
||||
exe '%!' . s:xxd_cmd . ' -s -0x31 %'
|
||||
call assert_equal(expected[2:], getline(1,'$'), s:Mess(s:test))
|
||||
for arg in ['-s -0x31', '-s-0x31']
|
||||
exe '%!' . s:xxd_cmd . ' ' . arg . ' %'
|
||||
call assert_equal(expected[2:], getline(1,'$'), s:Mess(s:test))
|
||||
endfor
|
||||
|
||||
" Test 5: Print 120 bytes as continuous hexdump with 20 octets per line
|
||||
let s:test += 1
|
||||
@@ -56,7 +60,7 @@ func Test_xxd()
|
||||
if has('win32') && !filereadable(fname)
|
||||
let fname = '../../doc/xxd.1'
|
||||
endif
|
||||
exe '0r! ' . s:xxd_cmd . ' -l 120 -ps -c 20 ' . fname
|
||||
exe '0r! ' . s:xxd_cmd . ' -l 120 -ps -c20 ' . fname
|
||||
$d
|
||||
let expected = [
|
||||
\ '2e54482058584420312022417567757374203139',
|
||||
@@ -69,10 +73,12 @@ func Test_xxd()
|
||||
|
||||
" Test 6: Print the date from xxd.1
|
||||
let s:test += 1
|
||||
%d
|
||||
exe '0r! ' . s:xxd_cmd . ' -s 0x36 -l 13 -c 13 ' . fname
|
||||
$d
|
||||
call assert_equal('00000036: 3231 7374 204d 6179 2031 3939 36 21st May 1996', getline(1), s:Mess(s:test))
|
||||
for arg in ['-l 13', '-l13', '-len 13']
|
||||
%d
|
||||
exe '0r! ' . s:xxd_cmd . ' -s 0x36 -l 13 -cols 13 ' . fname
|
||||
$d
|
||||
call assert_equal('00000036: 3231 7374 204d 6179 2031 3939 36 21st May 1996', getline(1), s:Mess(s:test))
|
||||
endfor
|
||||
|
||||
" Test 7: Print C include
|
||||
let s:test += 1
|
||||
@@ -87,14 +93,16 @@ func Test_xxd()
|
||||
|
||||
" Test 8: Print C include capitalized
|
||||
let s:test += 1
|
||||
call writefile(['TESTabcd09'], 'XXDfile')
|
||||
%d
|
||||
exe '0r! ' . s:xxd_cmd . ' -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))
|
||||
for arg in ['-C', '-capitalize']
|
||||
call writefile(['TESTabcd09'], 'XXDfile')
|
||||
%d
|
||||
exe '0r! ' . s:xxd_cmd . ' -i ' . arg . ' 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))
|
||||
endfor
|
||||
|
||||
" Test 9: Create a file with containing a single 'A'
|
||||
let s:test += 1
|
||||
@@ -110,6 +118,39 @@ func Test_xxd()
|
||||
call PrepareBuffer(readfile('XXDfile')[0])
|
||||
call assert_equal('A', getline(1), s:Mess(s:test))
|
||||
call delete('XXDfile')
|
||||
|
||||
" Test 10: group with 4 octets
|
||||
let s:test += 1
|
||||
for arg in ['-g 4', '-group 4', '-g4']
|
||||
call writefile(['TESTabcd09'], 'XXDfile')
|
||||
%d
|
||||
exe '0r! ' . s:xxd_cmd . ' ' . arg . ' XXDfile'
|
||||
$d
|
||||
let expected = ['00000000: 54455354 61626364 30390a TESTabcd09.']
|
||||
call assert_equal(expected, getline(1,'$'), s:Mess(s:test))
|
||||
call delete('XXDfile')
|
||||
endfor
|
||||
|
||||
" TODO:
|
||||
" -o -offset
|
||||
|
||||
%d
|
||||
bw!
|
||||
endfunc
|
||||
|
||||
" Various ways with wrong arguments that trigger the usage output.
|
||||
func Test_xxd_usage()
|
||||
for arg in ['-c', '-g', '-o', '-s', '-l', '-X', 'one two three']
|
||||
new
|
||||
exe 'r! ' . s:xxd_cmd . ' ' . arg
|
||||
call assert_match("Usage:", join(getline(1, 3)))
|
||||
bwipe!
|
||||
endfor
|
||||
endfunc
|
||||
|
||||
func Test_xxd_version()
|
||||
new
|
||||
exe 'r! ' . s:xxd_cmd . ' -v'
|
||||
call assert_match("xxd V1.10 .* by Juergen Weigert", join(getline(1, 3)))
|
||||
bwipe!
|
||||
endfunc
|
||||
|
@@ -787,6 +787,8 @@ static char *(features[]) =
|
||||
|
||||
static int included_patches[] =
|
||||
{ /* Add new patch number below this line */
|
||||
/**/
|
||||
821,
|
||||
/**/
|
||||
820,
|
||||
/**/
|
||||
|
@@ -508,10 +508,10 @@ main(int argc, char *argv[])
|
||||
}
|
||||
else if (!STRNCMP(pp, "-c", 2))
|
||||
{
|
||||
if (pp[2] && STRNCMP("ols", pp + 2, 3))
|
||||
cols = (int)strtol(pp + 2, NULL, 0);
|
||||
else if (pp[2] && STRNCMP("apitalize", pp + 2, 9))
|
||||
if (pp[2] && !STRNCMP("apitalize", pp + 2, 9))
|
||||
capitalize = 1;
|
||||
else if (pp[2] && STRNCMP("ols", pp + 2, 3))
|
||||
cols = (int)strtol(pp + 2, NULL, 0);
|
||||
else
|
||||
{
|
||||
if (!argv[2])
|
||||
@@ -523,7 +523,7 @@ main(int argc, char *argv[])
|
||||
}
|
||||
else if (!STRNCMP(pp, "-g", 2))
|
||||
{
|
||||
if (pp[2] && STRNCMP("group", pp + 2, 5))
|
||||
if (pp[2] && STRNCMP("roup", pp + 2, 4))
|
||||
octspergrp = (int)strtol(pp + 2, NULL, 0);
|
||||
else
|
||||
{
|
||||
|
Reference in New Issue
Block a user