comparison src/testdir/test_xxd.vim @ 15627:11879b89bb69 v8.1.0821

patch 8.1.0821: xxd "usage" output and other arguments not tested commit https://github.com/vim/vim/commit/970f5d39f27717b1a529b7b250a8ed7c3f791949 Author: Bram Moolenaar <Bram@vim.org> Date: Fri Jan 25 21:52:17 2019 +0100 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.
author Bram Moolenaar <Bram@vim.org>
date Fri, 25 Jan 2019 22:00:15 +0100
parents 63b02fcf1361
children db6cfc44eb65
comparison
equal deleted inserted replaced
15626:a19dbbd9fae5 15627:11879b89bb69
18 endfunc 18 endfunc
19 19
20 func Test_xxd() 20 func Test_xxd()
21 call PrepareBuffer(range(1,30)) 21 call PrepareBuffer(range(1,30))
22 set ff=unix 22 set ff=unix
23 w XXDfile 23 w! XXDfile
24 24
25 " Test 1: simple, filter the result through xxd 25 " Test 1: simple, filter the result through xxd
26 let s:test = 1 26 let s:test = 1
27 exe '%!' . s:xxd_cmd . ' %' 27 exe '%!' . s:xxd_cmd . ' %'
28 let expected = [ 28 let expected = [
37 " Test 2: reverse the result 37 " Test 2: reverse the result
38 let s:test += 1 38 let s:test += 1
39 exe '%!' . s:xxd_cmd . ' -r' 39 exe '%!' . s:xxd_cmd . ' -r'
40 call assert_equal(map(range(1,30), {v,c -> string(c)}), getline(1,'$'), s:Mess(s:test)) 40 call assert_equal(map(range(1,30), {v,c -> string(c)}), getline(1,'$'), s:Mess(s:test))
41 41
42 " Test 3: Skip the first 30 bytes 42 " Test 3: Skip the first 0x30 bytes
43 let s:test += 1 43 let s:test += 1
44 exe '%!' . s:xxd_cmd . ' -s 0x30 %' 44 for arg in ['-s 0x30', '-s0x30', '-s+0x30', '-skip 0x030', '-seek 0x30', '-seek +0x30 --']
45 call assert_equal(expected[3:], getline(1,'$'), s:Mess(s:test)) 45 exe '%!' . s:xxd_cmd . ' ' . arg . ' %'
46 call assert_equal(expected[3:], getline(1,'$'), s:Mess(s:test))
47 endfor
46 48
47 " Test 4: Skip the first 30 bytes 49 " Test 4: Skip the first 30 bytes
48 let s:test += 1 50 let s:test += 1
49 exe '%!' . s:xxd_cmd . ' -s -0x31 %' 51 for arg in ['-s -0x31', '-s-0x31']
50 call assert_equal(expected[2:], getline(1,'$'), s:Mess(s:test)) 52 exe '%!' . s:xxd_cmd . ' ' . arg . ' %'
53 call assert_equal(expected[2:], getline(1,'$'), s:Mess(s:test))
54 endfor
51 55
52 " Test 5: Print 120 bytes as continuous hexdump with 20 octets per line 56 " Test 5: Print 120 bytes as continuous hexdump with 20 octets per line
53 let s:test += 1 57 let s:test += 1
54 %d 58 %d
55 let fname = '../../runtime/doc/xxd.1' 59 let fname = '../../runtime/doc/xxd.1'
56 if has('win32') && !filereadable(fname) 60 if has('win32') && !filereadable(fname)
57 let fname = '../../doc/xxd.1' 61 let fname = '../../doc/xxd.1'
58 endif 62 endif
59 exe '0r! ' . s:xxd_cmd . ' -l 120 -ps -c 20 ' . fname 63 exe '0r! ' . s:xxd_cmd . ' -l 120 -ps -c20 ' . fname
60 $d 64 $d
61 let expected = [ 65 let expected = [
62 \ '2e54482058584420312022417567757374203139', 66 \ '2e54482058584420312022417567757374203139',
63 \ '39362220224d616e75616c207061676520666f72', 67 \ '39362220224d616e75616c207061676520666f72',
64 \ '20787864220a2e5c220a2e5c222032317374204d', 68 \ '20787864220a2e5c220a2e5c222032317374204d',
67 \ '204e7567656e74203c746f6e79407363746e7567'] 71 \ '204e7567656e74203c746f6e79407363746e7567']
68 call assert_equal(expected, getline(1,'$'), s:Mess(s:test)) 72 call assert_equal(expected, getline(1,'$'), s:Mess(s:test))
69 73
70 " Test 6: Print the date from xxd.1 74 " Test 6: Print the date from xxd.1
71 let s:test += 1 75 let s:test += 1
72 %d 76 for arg in ['-l 13', '-l13', '-len 13']
73 exe '0r! ' . s:xxd_cmd . ' -s 0x36 -l 13 -c 13 ' . fname 77 %d
74 $d 78 exe '0r! ' . s:xxd_cmd . ' -s 0x36 -l 13 -cols 13 ' . fname
75 call assert_equal('00000036: 3231 7374 204d 6179 2031 3939 36 21st May 1996', getline(1), s:Mess(s:test)) 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
76 82
77 " Test 7: Print C include 83 " Test 7: Print C include
78 let s:test += 1 84 let s:test += 1
79 call writefile(['TESTabcd09'], 'XXDfile') 85 call writefile(['TESTabcd09'], 'XXDfile')
80 %d 86 %d
85 \ 'unsigned int XXDfile_len = 11;'] 91 \ 'unsigned int XXDfile_len = 11;']
86 call assert_equal(expected, getline(1,'$'), s:Mess(s:test)) 92 call assert_equal(expected, getline(1,'$'), s:Mess(s:test))
87 93
88 " Test 8: Print C include capitalized 94 " Test 8: Print C include capitalized
89 let s:test += 1 95 let s:test += 1
90 call writefile(['TESTabcd09'], 'XXDfile') 96 for arg in ['-C', '-capitalize']
91 %d 97 call writefile(['TESTabcd09'], 'XXDfile')
92 exe '0r! ' . s:xxd_cmd . ' -i -C XXDfile' 98 %d
93 $d 99 exe '0r! ' . s:xxd_cmd . ' -i ' . arg . ' XXDfile'
94 let expected = ['unsigned char XXDFILE[] = {', 100 $d
95 \ ' 0x54, 0x45, 0x53, 0x54, 0x61, 0x62, 0x63, 0x64, 0x30, 0x39, 0x0a', '};', 101 let expected = ['unsigned char XXDFILE[] = {',
96 \ 'unsigned int XXDFILE_LEN = 11;'] 102 \ ' 0x54, 0x45, 0x53, 0x54, 0x61, 0x62, 0x63, 0x64, 0x30, 0x39, 0x0a', '};',
97 call assert_equal(expected, getline(1,'$'), s:Mess(s:test)) 103 \ 'unsigned int XXDFILE_LEN = 11;']
104 call assert_equal(expected, getline(1,'$'), s:Mess(s:test))
105 endfor
98 106
99 " Test 9: Create a file with containing a single 'A' 107 " Test 9: Create a file with containing a single 'A'
100 let s:test += 1 108 let s:test += 1
101 call delete('XXDfile') 109 call delete('XXDfile')
102 bwipe! XXDfile 110 bwipe! XXDfile
108 call delete('Xinput') 116 call delete('Xinput')
109 endif 117 endif
110 call PrepareBuffer(readfile('XXDfile')[0]) 118 call PrepareBuffer(readfile('XXDfile')[0])
111 call assert_equal('A', getline(1), s:Mess(s:test)) 119 call assert_equal('A', getline(1), s:Mess(s:test))
112 call delete('XXDfile') 120 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
113 %d 137 %d
114 bw! 138 bw!
115 endfunc 139 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