blob: 92a4d059988cf9497a56e6ef11ccc038fa78f04e [file] [log] [blame]
Bram Moolenaar29f9ed22018-04-10 19:20:31 +02001" Test for the xxd command
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +02002
Bram Moolenaar6995c0a2018-04-10 21:46:10 +02003if empty($XXD) && executable('..\xxd\xxd.exe')
4 let s:xxd_cmd = '..\xxd\xxd.exe'
5elseif empty($XXD) || !executable($XXD)
Bram Moolenaarb46fecd2019-06-15 17:58:09 +02006 throw 'Skipped: xxd program missing'
Bram Moolenaar6995c0a2018-04-10 21:46:10 +02007else
8 let s:xxd_cmd = $XXD
Bram Moolenaar29f9ed22018-04-10 19:20:31 +02009endif
10
Bram Moolenaar1e115362019-01-09 23:01:02 +010011func PrepareBuffer(lines)
Bram Moolenaar164268d2018-04-10 20:06:17 +020012 new
13 call append(0, a:lines)
Bram Moolenaar29f9ed22018-04-10 19:20:31 +020014 $d
Bram Moolenaar29f9ed22018-04-10 19:20:31 +020015endfunc
16
Bram Moolenaar1e115362019-01-09 23:01:02 +010017func s:Mess(counter)
Bram Moolenaar29f9ed22018-04-10 19:20:31 +020018 return printf("Failed xxd test %d:", a:counter)
19endfunc
20
Bram Moolenaar1e115362019-01-09 23:01:02 +010021func Test_xxd()
Bram Moolenaar29f9ed22018-04-10 19:20:31 +020022 call PrepareBuffer(range(1,30))
Bram Moolenaar6995c0a2018-04-10 21:46:10 +020023 set ff=unix
Bram Moolenaar970f5d32019-01-25 21:52:17 +010024 w! XXDfile
Bram Moolenaar164268d2018-04-10 20:06:17 +020025
Bram Moolenaar29f9ed22018-04-10 19:20:31 +020026 " Test 1: simple, filter the result through xxd
27 let s:test = 1
Bram Moolenaar6995c0a2018-04-10 21:46:10 +020028 exe '%!' . s:xxd_cmd . ' %'
Bram Moolenaar29f9ed22018-04-10 19:20:31 +020029 let expected = [
30 \ '00000000: 310a 320a 330a 340a 350a 360a 370a 380a 1.2.3.4.5.6.7.8.',
31 \ '00000010: 390a 3130 0a31 310a 3132 0a31 330a 3134 9.10.11.12.13.14',
32 \ '00000020: 0a31 350a 3136 0a31 370a 3138 0a31 390a .15.16.17.18.19.',
33 \ '00000030: 3230 0a32 310a 3232 0a32 330a 3234 0a32 20.21.22.23.24.2',
34 \ '00000040: 350a 3236 0a32 370a 3238 0a32 390a 3330 5.26.27.28.29.30',
35 \ '00000050: 0a .']
36 call assert_equal(expected, getline(1,'$'), s:Mess(s:test))
Bram Moolenaar164268d2018-04-10 20:06:17 +020037
Bram Moolenaar29f9ed22018-04-10 19:20:31 +020038 " Test 2: reverse the result
39 let s:test += 1
Bram Moolenaar6995c0a2018-04-10 21:46:10 +020040 exe '%!' . s:xxd_cmd . ' -r'
Bram Moolenaar29f9ed22018-04-10 19:20:31 +020041 call assert_equal(map(range(1,30), {v,c -> string(c)}), getline(1,'$'), s:Mess(s:test))
42
Bram Moolenaar970f5d32019-01-25 21:52:17 +010043 " Test 3: Skip the first 0x30 bytes
Bram Moolenaar29f9ed22018-04-10 19:20:31 +020044 let s:test += 1
Bram Moolenaar970f5d32019-01-25 21:52:17 +010045 for arg in ['-s 0x30', '-s0x30', '-s+0x30', '-skip 0x030', '-seek 0x30', '-seek +0x30 --']
46 exe '%!' . s:xxd_cmd . ' ' . arg . ' %'
47 call assert_equal(expected[3:], getline(1,'$'), s:Mess(s:test))
48 endfor
Bram Moolenaar29f9ed22018-04-10 19:20:31 +020049
50 " Test 4: Skip the first 30 bytes
51 let s:test += 1
Bram Moolenaar970f5d32019-01-25 21:52:17 +010052 for arg in ['-s -0x31', '-s-0x31']
53 exe '%!' . s:xxd_cmd . ' ' . arg . ' %'
54 call assert_equal(expected[2:], getline(1,'$'), s:Mess(s:test))
55 endfor
Bram Moolenaar29f9ed22018-04-10 19:20:31 +020056
Bram Moolenaar0eb220c2019-01-27 14:41:43 +010057 " The following tests use the xxd man page.
58 " For these tests to pass, the fileformat must be "unix".
59 let man_copy = 'Xxd.1'
60 let man_page = '../../runtime/doc/xxd.1'
61 if has('win32') && !filereadable(man_page)
62 let man_page = '../../doc/xxd.1'
63 endif
64 %d
65 exe '0r ' man_page '| set ff=unix | $d | w' man_copy '| bwipe!' man_copy
66
Bram Moolenaar29f9ed22018-04-10 19:20:31 +020067 " Test 5: Print 120 bytes as continuous hexdump with 20 octets per line
68 let s:test += 1
69 %d
Bram Moolenaar0eb220c2019-01-27 14:41:43 +010070 exe '0r! ' . s:xxd_cmd . ' -l 120 -ps -c20 ' . man_copy
Bram Moolenaar29f9ed22018-04-10 19:20:31 +020071 $d
72 let expected = [
73 \ '2e54482058584420312022417567757374203139',
74 \ '39362220224d616e75616c207061676520666f72',
75 \ '20787864220a2e5c220a2e5c222032317374204d',
76 \ '617920313939360a2e5c22204d616e2070616765',
77 \ '20617574686f723a0a2e5c2220202020546f6e79',
78 \ '204e7567656e74203c746f6e79407363746e7567']
79 call assert_equal(expected, getline(1,'$'), s:Mess(s:test))
Bram Moolenaar164268d2018-04-10 20:06:17 +020080
Bram Moolenaar29f9ed22018-04-10 19:20:31 +020081 " Test 6: Print the date from xxd.1
82 let s:test += 1
Bram Moolenaar970f5d32019-01-25 21:52:17 +010083 for arg in ['-l 13', '-l13', '-len 13']
84 %d
Bram Moolenaar0eb220c2019-01-27 14:41:43 +010085 exe '0r! ' . s:xxd_cmd . ' -s 0x36 ' . arg . ' -cols 13 ' . man_copy
Bram Moolenaar970f5d32019-01-25 21:52:17 +010086 $d
87 call assert_equal('00000036: 3231 7374 204d 6179 2031 3939 36 21st May 1996', getline(1), s:Mess(s:test))
88 endfor
Bram Moolenaar164268d2018-04-10 20:06:17 +020089
Bram Moolenaar0eb220c2019-01-27 14:41:43 +010090 " Cleanup after tests 5 and 6
91 call delete(man_copy)
92
Bram Moolenaar29f9ed22018-04-10 19:20:31 +020093 " Test 7: Print C include
94 let s:test += 1
95 call writefile(['TESTabcd09'], 'XXDfile')
96 %d
Bram Moolenaar6995c0a2018-04-10 21:46:10 +020097 exe '0r! ' . s:xxd_cmd . ' -i XXDfile'
Bram Moolenaar29f9ed22018-04-10 19:20:31 +020098 $d
Bram Moolenaarc79745a2019-05-20 22:12:34 +020099 let expected =<< trim [CODE]
Bram Moolenaare7eb9272019-06-24 00:58:07 +0200100 unsigned char XXDfile[] = {
101 0x54, 0x45, 0x53, 0x54, 0x61, 0x62, 0x63, 0x64, 0x30, 0x39, 0x0a
102 };
103 unsigned int XXDfile_len = 11;
Bram Moolenaarc79745a2019-05-20 22:12:34 +0200104 [CODE]
105
Bram Moolenaar29f9ed22018-04-10 19:20:31 +0200106 call assert_equal(expected, getline(1,'$'), s:Mess(s:test))
Bram Moolenaar164268d2018-04-10 20:06:17 +0200107
Bram Moolenaar29f9ed22018-04-10 19:20:31 +0200108 " Test 8: Print C include capitalized
109 let s:test += 1
Bram Moolenaar970f5d32019-01-25 21:52:17 +0100110 for arg in ['-C', '-capitalize']
111 call writefile(['TESTabcd09'], 'XXDfile')
112 %d
113 exe '0r! ' . s:xxd_cmd . ' -i ' . arg . ' XXDfile'
114 $d
Bram Moolenaarc79745a2019-05-20 22:12:34 +0200115 let expected =<< trim [CODE]
Bram Moolenaare7eb9272019-06-24 00:58:07 +0200116 unsigned char XXDFILE[] = {
117 0x54, 0x45, 0x53, 0x54, 0x61, 0x62, 0x63, 0x64, 0x30, 0x39, 0x0a
118 };
119 unsigned int XXDFILE_LEN = 11;
Bram Moolenaarc79745a2019-05-20 22:12:34 +0200120 [CODE]
Bram Moolenaar970f5d32019-01-25 21:52:17 +0100121 call assert_equal(expected, getline(1,'$'), s:Mess(s:test))
122 endfor
Bram Moolenaar164268d2018-04-10 20:06:17 +0200123
124 " Test 9: Create a file with containing a single 'A'
Bram Moolenaar29f9ed22018-04-10 19:20:31 +0200125 let s:test += 1
126 call delete('XXDfile')
Bram Moolenaar164268d2018-04-10 20:06:17 +0200127 bwipe! XXDfile
Bram Moolenaar6995c0a2018-04-10 21:46:10 +0200128 if has('unix')
129 call system('echo "010000: 41"|' . s:xxd_cmd . ' -r -s -0x10000 > XXDfile')
130 else
131 call writefile(['010000: 41'], 'Xinput')
132 silent exe '!' . s:xxd_cmd . ' -r -s -0x10000 < Xinput > XXDfile'
133 call delete('Xinput')
134 endif
Bram Moolenaar29f9ed22018-04-10 19:20:31 +0200135 call PrepareBuffer(readfile('XXDfile')[0])
136 call assert_equal('A', getline(1), s:Mess(s:test))
137 call delete('XXDfile')
Bram Moolenaar970f5d32019-01-25 21:52:17 +0100138
139 " Test 10: group with 4 octets
140 let s:test += 1
141 for arg in ['-g 4', '-group 4', '-g4']
142 call writefile(['TESTabcd09'], 'XXDfile')
143 %d
144 exe '0r! ' . s:xxd_cmd . ' ' . arg . ' XXDfile'
145 $d
146 let expected = ['00000000: 54455354 61626364 30390a TESTabcd09.']
147 call assert_equal(expected, getline(1,'$'), s:Mess(s:test))
148 call delete('XXDfile')
149 endfor
150
Bram Moolenaar203651b2019-01-26 14:11:19 +0100151 " Test 11: reverse with CR, hex upper, Postscript style with a TAB
152 let s:test += 1
153 call writefile([" 54455354\t610B6364 30390A TESTa\0x0bcd09.\r"], 'Xinput')
154 silent exe '!' . s:xxd_cmd . ' -r -p < Xinput > XXDfile'
155 let blob = readfile('XXDfile', 'B')
156 call assert_equal(0z54455354.610B6364.30390A, blob)
157 call delete('Xinput')
158 call delete('XXDfile')
159
160 " Test 12: reverse with seek
161 let s:test += 1
162 call writefile(["00000000: 54455354\t610B6364 30390A TESTa\0x0bcd09.\r"], 'Xinput')
163 silent exe '!' . s:xxd_cmd . ' -r -seek 5 < Xinput > XXDfile'
164 let blob = readfile('XXDfile', 'B')
165 call assert_equal(0z0000000000.54455354.610B6364.30390A, blob)
166 call delete('Xinput')
167 call delete('XXDfile')
168
Bram Moolenaar363d6142020-05-30 20:50:25 +0200169 " Test 13: simple, decimal offset
170 call PrepareBuffer(range(1,30))
171 set ff=unix
172 w! XXDfile
173 let s:test += 1
174 exe '%!' . s:xxd_cmd . ' -d %'
175 let expected = [
176 \ '00000000: 310a 320a 330a 340a 350a 360a 370a 380a 1.2.3.4.5.6.7.8.',
177 \ '00000016: 390a 3130 0a31 310a 3132 0a31 330a 3134 9.10.11.12.13.14',
178 \ '00000032: 0a31 350a 3136 0a31 370a 3138 0a31 390a .15.16.17.18.19.',
179 \ '00000048: 3230 0a32 310a 3232 0a32 330a 3234 0a32 20.21.22.23.24.2',
180 \ '00000064: 350a 3236 0a32 370a 3238 0a32 390a 3330 5.26.27.28.29.30',
181 \ '00000080: 0a .']
182 call assert_equal(expected, getline(1,'$'), s:Mess(s:test))
183
184 " Test 14: grouping with -d
185 let s:test += 1
186 let expected = [
187 \ '00000000: 310a320a 330a340a 350a360a 370a380a 1.2.3.4.5.6.7.8.',
188 \ '00000016: 390a3130 0a31310a 31320a31 330a3134 9.10.11.12.13.14',
189 \ '00000032: 0a31350a 31360a31 370a3138 0a31390a .15.16.17.18.19.',
190 \ '00000048: 32300a32 310a3232 0a32330a 32340a32 20.21.22.23.24.2',
191 \ '00000064: 350a3236 0a32370a 32380a32 390a3330 5.26.27.28.29.30',
192 \ '00000080: 0a .']
193 for arg in ['-g 4', '-group 4', '-g4']
194 exe '%!' . s:xxd_cmd . ' ' . arg . ' -d %'
195 call assert_equal(expected, getline(1,'$'), s:Mess(s:test))
196 endfor
197
198 " Test 15: cols with decimal offset: -c 21 -d
199 let s:test += 1
200 let expected = [
201 \ '00000000: 310a 320a 330a 340a 350a 360a 370a 380a 390a 3130 0a 1.2.3.4.5.6.7.8.9.10.',
202 \ '00000021: 3131 0a31 320a 3133 0a31 340a 3135 0a31 360a 3137 0a 11.12.13.14.15.16.17.',
203 \ '00000042: 3138 0a31 390a 3230 0a32 310a 3232 0a32 330a 3234 0a 18.19.20.21.22.23.24.',
204 \ '00000063: 3235 0a32 360a 3237 0a32 380a 3239 0a33 300a 25.26.27.28.29.30.']
205 exe '%!' . s:xxd_cmd . ' -c 21 -d %'
206 call assert_equal(expected, getline(1,'$'), s:Mess(s:test))
207
Erik Auerswalda00e6222022-01-13 17:42:28 +0000208 " Test 16: -o -offset
209 let s:test += 1
210 let expected = [
211 \ '0000000f: 310a 320a 330a 340a 350a 360a 370a 380a 1.2.3.4.5.6.7.8.',
212 \ '0000001f: 390a 3130 0a31 310a 3132 0a31 330a 3134 9.10.11.12.13.14',
213 \ '0000002f: 0a31 350a 3136 0a31 370a 3138 0a31 390a .15.16.17.18.19.',
214 \ '0000003f: 3230 0a32 310a 3232 0a32 330a 3234 0a32 20.21.22.23.24.2',
215 \ '0000004f: 350a 3236 0a32 370a 3238 0a32 390a 3330 5.26.27.28.29.30',
216 \ '0000005f: 0a .']
217 for arg in ['-o 15', '-offset 15', '-o15']
218 exe '%!' . s:xxd_cmd . ' ' . arg . ' %'
219 call assert_equal(expected, getline(1,'$'), s:Mess(s:test))
220 endfor
Bram Moolenaar970f5d32019-01-25 21:52:17 +0100221
David Gow83e11802022-06-29 20:24:49 +0100222 " Test 17: Print C include with custom variable name
223 let s:test += 1
224 call writefile(['TESTabcd09'], 'XXDfile')
225 for arg in ['-nvarName', '-n varName', '-name varName']
226 %d
227 exe '0r! ' . s:xxd_cmd . ' -i ' . arg . ' XXDfile'
228 $d
229 let expected =<< trim [CODE]
230 unsigned char varName[] = {
231 0x54, 0x45, 0x53, 0x54, 0x61, 0x62, 0x63, 0x64, 0x30, 0x39, 0x0a
232 };
233 unsigned int varName_len = 11;
234 [CODE]
Bram Moolenaar94722c52023-01-28 19:19:03 +0000235
David Gow83e11802022-06-29 20:24:49 +0100236 call assert_equal(expected, getline(1,'$'), s:Mess(s:test))
237 endfor
238
239 " using "-n name" reading from stdin
240 %d
241 exe '0r! ' . s:xxd_cmd . ' -i < XXDfile -n StdIn'
242 $d
243 let expected =<< trim [CODE]
244 unsigned char StdIn[] = {
245 0x54, 0x45, 0x53, 0x54, 0x61, 0x62, 0x63, 0x64, 0x30, 0x39, 0x0a
246 };
247 unsigned int StdIn_len = 11;
248 [CODE]
249 call assert_equal(expected, getline(1,'$'), s:Mess(s:test))
250
251
252 " Test 18: Print C include: custom variable names can be capitalized
253 let s:test += 1
254 for arg in ['-C', '-capitalize']
255 call writefile(['TESTabcd09'], 'XXDfile')
256 %d
257 exe '0r! ' . s:xxd_cmd . ' -i ' . arg . ' -n varName XXDfile'
258 $d
259 let expected =<< trim [CODE]
260 unsigned char VARNAME[] = {
261 0x54, 0x45, 0x53, 0x54, 0x61, 0x62, 0x63, 0x64, 0x30, 0x39, 0x0a
262 };
263 unsigned int VARNAME_LEN = 11;
264 [CODE]
265 call assert_equal(expected, getline(1,'$'), s:Mess(s:test))
266 endfor
267
268
Bram Moolenaar29f9ed22018-04-10 19:20:31 +0200269 %d
Bram Moolenaar253ea9f2020-06-10 14:21:20 +0200270 bwipe!
271 call delete('XXDfile')
Bram Moolenaar29f9ed22018-04-10 19:20:31 +0200272endfunc
Bram Moolenaar970f5d32019-01-25 21:52:17 +0100273
DungSaga47810462021-10-22 12:55:42 +0100274func Test_xxd_patch()
Bram Moolenaar5a5c1112021-10-22 15:11:37 +0100275 let cmd1 = 'silent !' .. s:xxd_cmd .. ' -r Xxxdin Xxxdfile'
276 let cmd2 = 'silent !' .. s:xxd_cmd .. ' -g1 Xxxdfile > Xxxdout'
Bram Moolenaardb4c9472022-10-15 22:06:06 +0100277 call writefile(["2: 41 41", "8: 42 42"], 'Xxxdin', 'D')
278 call writefile(['::::::::'], 'Xxxdfile', 'D')
Bram Moolenaar5a5c1112021-10-22 15:11:37 +0100279 exe cmd1
280 exe cmd2
DungSaga47810462021-10-22 12:55:42 +0100281 call assert_equal(['00000000: 3a 3a 41 41 3a 3a 3a 3a 42 42 ::AA::::BB'], readfile('Xxxdout'))
282
283 call writefile(["2: 43 43 ", "8: 44 44"], 'Xxxdin')
Bram Moolenaar5a5c1112021-10-22 15:11:37 +0100284 exe cmd1
285 exe cmd2
DungSaga47810462021-10-22 12:55:42 +0100286 call assert_equal(['00000000: 3a 3a 43 43 3a 3a 3a 3a 44 44 ::CC::::DD'], readfile('Xxxdout'))
287
288 call writefile(["2: 45 45 ", "8: 46 46"], 'Xxxdin')
Bram Moolenaar5a5c1112021-10-22 15:11:37 +0100289 exe cmd1
290 exe cmd2
DungSaga47810462021-10-22 12:55:42 +0100291 call assert_equal(['00000000: 3a 3a 45 45 3a 3a 3a 3a 46 46 ::EE::::FF'], readfile('Xxxdout'))
Bram Moolenaar94722c52023-01-28 19:19:03 +0000292
DungSaga47810462021-10-22 12:55:42 +0100293 call writefile(["2: 41 41", "08: 42 42"], 'Xxxdin')
294 call writefile(['::::::::'], 'Xxxdfile')
Bram Moolenaar5a5c1112021-10-22 15:11:37 +0100295 exe cmd1
296 exe cmd2
DungSaga47810462021-10-22 12:55:42 +0100297 call assert_equal(['00000000: 3a 3a 41 41 3a 3a 3a 3a 42 42 ::AA::::BB'], readfile('Xxxdout'))
298
299 call writefile(["2: 43 43 ", "09: 44 44"], 'Xxxdin')
Bram Moolenaar5a5c1112021-10-22 15:11:37 +0100300 exe cmd1
301 exe cmd2
DungSaga47810462021-10-22 12:55:42 +0100302 call assert_equal(['00000000: 3a 3a 43 43 3a 3a 3a 3a 42 44 44 ::CC::::BDD'], readfile('Xxxdout'))
303
304 call writefile(["2: 45 45 ", "0a: 46 46"], 'Xxxdin')
Bram Moolenaar5a5c1112021-10-22 15:11:37 +0100305 exe cmd1
306 exe cmd2
DungSaga47810462021-10-22 12:55:42 +0100307 call assert_equal(['00000000: 3a 3a 45 45 3a 3a 3a 3a 42 44 46 46 ::EE::::BDFF'], readfile('Xxxdout'))
Bram Moolenaar94722c52023-01-28 19:19:03 +0000308
DungSaga47810462021-10-22 12:55:42 +0100309 call delete('Xxxdout')
310endfunc
311
Bram Moolenaar970f5d32019-01-25 21:52:17 +0100312" Various ways with wrong arguments that trigger the usage output.
313func Test_xxd_usage()
Erik Auerswalda00e6222022-01-13 17:42:28 +0000314 for arg in ['-h', '-c', '-g', '-o', '-s', '-l', '-X', 'one two three']
Bram Moolenaar970f5d32019-01-25 21:52:17 +0100315 new
316 exe 'r! ' . s:xxd_cmd . ' ' . arg
317 call assert_match("Usage:", join(getline(1, 3)))
318 bwipe!
319 endfor
320endfunc
321
DungSaga48608b42021-11-24 11:18:07 +0000322func Test_xxd_ignore_garbage()
323 new
324 exe 'r! printf "\n\r xxxx 0: 42 42" | ' . s:xxd_cmd . ' -r'
325 call assert_match('BB', join(getline(1, 3)))
326 bwipe!
327endfunc
328
329func Test_xxd_bit_dump()
330 new
331 exe 'r! printf "123456" | ' . s:xxd_cmd . ' -b1'
332 call assert_match('00000000: 00110001 00110010 00110011 00110100 00110101 00110110 123456', join(getline(1, 3)))
333 bwipe!
334endfunc
335
Bram Moolenaar970f5d32019-01-25 21:52:17 +0100336func Test_xxd_version()
337 new
338 exe 'r! ' . s:xxd_cmd . ' -v'
=?UTF-8?q?J=C3=BCrgen=20Weigert?=80b2ba32021-06-29 20:36:25 +0200339 call assert_match('xxd 20\d\d-\d\d-\d\d by Juergen Weigert et al\.', join(getline(1, 3)))
Bram Moolenaar970f5d32019-01-25 21:52:17 +0100340 bwipe!
341endfunc
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +0200342
Erik Auerswalda00e6222022-01-13 17:42:28 +0000343" number of columns must be non-negative
344func Test_xxd_min_cols()
345 for cols in ['-c-1', '-c -1', '-cols -1']
346 for fmt in ['', '-b', '-e', '-i', '-p', ]
347 new
348 exe 'r! printf "ignored" | ' . s:xxd_cmd . ' ' . cols . ' ' . fmt
349 call assert_match("invalid number of columns", join(getline(1, '$')))
350 bwipe!
351 endfor
352 endfor
353endfunc
354
355" some hex formats limit columns to 256 (a #define in xxd.c)
356func Test_xxd_max_cols()
357 for cols in ['-c257', '-c 257', '-cols 257']
358 for fmt in ['', '-b', '-e' ]
359 new
360 exe 'r! printf "ignored" | ' . s:xxd_cmd . ' ' . cols . ' ' . fmt
361 call assert_match("invalid number of columns", join(getline(1, '$')))
362 bwipe!
363 endfor
364 endfor
365endfunc
366
367" -c0 selects the format specific default column value, as if no -c was given
Erik Auerswaldc0a1d372022-01-14 11:58:48 +0000368" except for -ps, where it disables extra newlines
Erik Auerswalda00e6222022-01-13 17:42:28 +0000369func Test_xxd_c0_is_def_cols()
Bram Moolenaardb4c9472022-10-15 22:06:06 +0100370 call writefile(["abcdefghijklmnopqrstuvwxyz0123456789"], 'Xxdin', 'D')
Erik Auerswalda00e6222022-01-13 17:42:28 +0000371 for cols in ['-c0', '-c 0', '-cols 0']
Erik Auerswaldc0a1d372022-01-14 11:58:48 +0000372 for fmt in ['', '-b', '-e', '-i']
Erik Auerswalda00e6222022-01-13 17:42:28 +0000373 exe 'r! ' . s:xxd_cmd . ' ' . fmt ' Xxdin > Xxdout1'
374 exe 'r! ' . s:xxd_cmd . ' ' . cols . ' ' . fmt ' Xxdin > Xxdout2'
375 call assert_equalfile('Xxdout1', 'Xxdout2')
376 endfor
377 endfor
Erik Auerswalda00e6222022-01-13 17:42:28 +0000378 call delete('Xxdout1')
379 call delete('Xxdout2')
380endfunc
381
Erik Auerswaldc0a1d372022-01-14 11:58:48 +0000382" all output in a single line for -c0 -ps
383func Test_xxd_plain_one_line()
384 call writefile([
385 \ "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789",
386 \ "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789",
387 \ "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789",
388 \ "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789",
389 \ "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789",
390 \ "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"],
Bram Moolenaardb4c9472022-10-15 22:06:06 +0100391 \ 'Xxdin', 'D')
Erik Auerswaldc0a1d372022-01-14 11:58:48 +0000392 for cols in ['-c0', '-c 0', '-cols 0']
393 exe 'r! ' . s:xxd_cmd . ' -ps ' . cols ' Xxdin'
394 " output seems to start in line 2
395 let out = join(getline(2, '$'))
396 bwipe!
397 " newlines in xxd output result in spaces in the string variable out
398 call assert_notmatch(" ", out)
399 " xxd output must be non-empty and comprise only lower case hex digits
400 call assert_match("^[0-9a-f][0-9a-f]*$", out)
401 endfor
Erik Auerswaldc0a1d372022-01-14 11:58:48 +0000402endfunc
403
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +0200404" vim: shiftwidth=2 sts=2 expandtab