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()
|
func Test_xxd()
|
||||||
call PrepareBuffer(range(1,30))
|
call PrepareBuffer(range(1,30))
|
||||||
set ff=unix
|
set ff=unix
|
||||||
w XXDfile
|
w! XXDfile
|
||||||
|
|
||||||
" Test 1: simple, filter the result through xxd
|
" Test 1: simple, filter the result through xxd
|
||||||
let s:test = 1
|
let s:test = 1
|
||||||
@@ -39,15 +39,19 @@ func Test_xxd()
|
|||||||
exe '%!' . s:xxd_cmd . ' -r'
|
exe '%!' . s:xxd_cmd . ' -r'
|
||||||
call assert_equal(map(range(1,30), {v,c -> string(c)}), getline(1,'$'), s:Mess(s:test))
|
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
|
let s:test += 1
|
||||||
exe '%!' . s:xxd_cmd . ' -s 0x30 %'
|
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))
|
call assert_equal(expected[3:], getline(1,'$'), s:Mess(s:test))
|
||||||
|
endfor
|
||||||
|
|
||||||
" Test 4: Skip the first 30 bytes
|
" Test 4: Skip the first 30 bytes
|
||||||
let s:test += 1
|
let s:test += 1
|
||||||
exe '%!' . s:xxd_cmd . ' -s -0x31 %'
|
for arg in ['-s -0x31', '-s-0x31']
|
||||||
|
exe '%!' . s:xxd_cmd . ' ' . arg . ' %'
|
||||||
call assert_equal(expected[2:], getline(1,'$'), s:Mess(s:test))
|
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
|
" Test 5: Print 120 bytes as continuous hexdump with 20 octets per line
|
||||||
let s:test += 1
|
let s:test += 1
|
||||||
@@ -69,10 +73,12 @@ func Test_xxd()
|
|||||||
|
|
||||||
" Test 6: Print the date from xxd.1
|
" Test 6: Print the date from xxd.1
|
||||||
let s:test += 1
|
let s:test += 1
|
||||||
|
for arg in ['-l 13', '-l13', '-len 13']
|
||||||
%d
|
%d
|
||||||
exe '0r! ' . s:xxd_cmd . ' -s 0x36 -l 13 -c 13 ' . fname
|
exe '0r! ' . s:xxd_cmd . ' -s 0x36 -l 13 -cols 13 ' . fname
|
||||||
$d
|
$d
|
||||||
call assert_equal('00000036: 3231 7374 204d 6179 2031 3939 36 21st May 1996', getline(1), s:Mess(s:test))
|
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
|
" Test 7: Print C include
|
||||||
let s:test += 1
|
let s:test += 1
|
||||||
@@ -87,14 +93,16 @@ func Test_xxd()
|
|||||||
|
|
||||||
" Test 8: Print C include capitalized
|
" Test 8: Print C include capitalized
|
||||||
let s:test += 1
|
let s:test += 1
|
||||||
|
for arg in ['-C', '-capitalize']
|
||||||
call writefile(['TESTabcd09'], 'XXDfile')
|
call writefile(['TESTabcd09'], 'XXDfile')
|
||||||
%d
|
%d
|
||||||
exe '0r! ' . s:xxd_cmd . ' -i -C XXDfile'
|
exe '0r! ' . s:xxd_cmd . ' -i ' . arg . ' XXDfile'
|
||||||
$d
|
$d
|
||||||
let expected = ['unsigned char XXDFILE[] = {',
|
let expected = ['unsigned char XXDFILE[] = {',
|
||||||
\ ' 0x54, 0x45, 0x53, 0x54, 0x61, 0x62, 0x63, 0x64, 0x30, 0x39, 0x0a', '};',
|
\ ' 0x54, 0x45, 0x53, 0x54, 0x61, 0x62, 0x63, 0x64, 0x30, 0x39, 0x0a', '};',
|
||||||
\ 'unsigned int XXDFILE_LEN = 11;']
|
\ 'unsigned int XXDFILE_LEN = 11;']
|
||||||
call assert_equal(expected, getline(1,'$'), s:Mess(s:test))
|
call assert_equal(expected, getline(1,'$'), s:Mess(s:test))
|
||||||
|
endfor
|
||||||
|
|
||||||
" Test 9: Create a file with containing a single 'A'
|
" Test 9: Create a file with containing a single 'A'
|
||||||
let s:test += 1
|
let s:test += 1
|
||||||
@@ -110,6 +118,39 @@ func Test_xxd()
|
|||||||
call PrepareBuffer(readfile('XXDfile')[0])
|
call PrepareBuffer(readfile('XXDfile')[0])
|
||||||
call assert_equal('A', getline(1), s:Mess(s:test))
|
call assert_equal('A', getline(1), s:Mess(s:test))
|
||||||
call delete('XXDfile')
|
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
|
%d
|
||||||
bw!
|
bw!
|
||||||
endfunc
|
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[] =
|
static int included_patches[] =
|
||||||
{ /* Add new patch number below this line */
|
{ /* Add new patch number below this line */
|
||||||
|
/**/
|
||||||
|
821,
|
||||||
/**/
|
/**/
|
||||||
820,
|
820,
|
||||||
/**/
|
/**/
|
||||||
|
@@ -508,10 +508,10 @@ main(int argc, char *argv[])
|
|||||||
}
|
}
|
||||||
else if (!STRNCMP(pp, "-c", 2))
|
else if (!STRNCMP(pp, "-c", 2))
|
||||||
{
|
{
|
||||||
if (pp[2] && STRNCMP("ols", pp + 2, 3))
|
if (pp[2] && !STRNCMP("apitalize", pp + 2, 9))
|
||||||
cols = (int)strtol(pp + 2, NULL, 0);
|
|
||||||
else if (pp[2] && STRNCMP("apitalize", pp + 2, 9))
|
|
||||||
capitalize = 1;
|
capitalize = 1;
|
||||||
|
else if (pp[2] && STRNCMP("ols", pp + 2, 3))
|
||||||
|
cols = (int)strtol(pp + 2, NULL, 0);
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (!argv[2])
|
if (!argv[2])
|
||||||
@@ -523,7 +523,7 @@ main(int argc, char *argv[])
|
|||||||
}
|
}
|
||||||
else if (!STRNCMP(pp, "-g", 2))
|
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);
|
octspergrp = (int)strtol(pp + 2, NULL, 0);
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
Reference in New Issue
Block a user