blob: 79fc9bf10dcefd17ac9d7a329b1b1ea0792170b4 [file] [log] [blame]
Bram Moolenaar29f9ed22018-04-10 19:20:31 +02001" Test for the xxd command
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +02002
Christian Brabandteb380b92025-07-07 20:53:55 +02003source util/screendump.vim
Aapo Rantalainene2528ae2023-08-31 17:58:13 +02004
Bram Moolenaar6995c0a2018-04-10 21:46:10 +02005if empty($XXD) && executable('..\xxd\xxd.exe')
6 let s:xxd_cmd = '..\xxd\xxd.exe'
7elseif empty($XXD) || !executable($XXD)
Bram Moolenaarb46fecd2019-06-15 17:58:09 +02008 throw 'Skipped: xxd program missing'
Bram Moolenaar6995c0a2018-04-10 21:46:10 +02009else
10 let s:xxd_cmd = $XXD
Bram Moolenaar29f9ed22018-04-10 19:20:31 +020011endif
12
Bram Moolenaar1e115362019-01-09 23:01:02 +010013func PrepareBuffer(lines)
Bram Moolenaar164268d2018-04-10 20:06:17 +020014 new
15 call append(0, a:lines)
Bram Moolenaar29f9ed22018-04-10 19:20:31 +020016 $d
Bram Moolenaar29f9ed22018-04-10 19:20:31 +020017endfunc
18
Bram Moolenaar1e115362019-01-09 23:01:02 +010019func s:Mess(counter)
Bram Moolenaar29f9ed22018-04-10 19:20:31 +020020 return printf("Failed xxd test %d:", a:counter)
21endfunc
22
Bram Moolenaar1e115362019-01-09 23:01:02 +010023func Test_xxd()
Bram Moolenaar29f9ed22018-04-10 19:20:31 +020024 call PrepareBuffer(range(1,30))
Bram Moolenaar6995c0a2018-04-10 21:46:10 +020025 set ff=unix
Bram Moolenaar970f5d32019-01-25 21:52:17 +010026 w! XXDfile
Bram Moolenaar164268d2018-04-10 20:06:17 +020027
Bram Moolenaar29f9ed22018-04-10 19:20:31 +020028 " Test 1: simple, filter the result through xxd
29 let s:test = 1
Bram Moolenaar6995c0a2018-04-10 21:46:10 +020030 exe '%!' . s:xxd_cmd . ' %'
Bram Moolenaar29f9ed22018-04-10 19:20:31 +020031 let expected = [
32 \ '00000000: 310a 320a 330a 340a 350a 360a 370a 380a 1.2.3.4.5.6.7.8.',
33 \ '00000010: 390a 3130 0a31 310a 3132 0a31 330a 3134 9.10.11.12.13.14',
34 \ '00000020: 0a31 350a 3136 0a31 370a 3138 0a31 390a .15.16.17.18.19.',
35 \ '00000030: 3230 0a32 310a 3232 0a32 330a 3234 0a32 20.21.22.23.24.2',
36 \ '00000040: 350a 3236 0a32 370a 3238 0a32 390a 3330 5.26.27.28.29.30',
37 \ '00000050: 0a .']
38 call assert_equal(expected, getline(1,'$'), s:Mess(s:test))
Bram Moolenaar164268d2018-04-10 20:06:17 +020039
Bram Moolenaar29f9ed22018-04-10 19:20:31 +020040 " Test 2: reverse the result
41 let s:test += 1
Bram Moolenaar6995c0a2018-04-10 21:46:10 +020042 exe '%!' . s:xxd_cmd . ' -r'
Bram Moolenaar29f9ed22018-04-10 19:20:31 +020043 call assert_equal(map(range(1,30), {v,c -> string(c)}), getline(1,'$'), s:Mess(s:test))
44
Bram Moolenaar970f5d32019-01-25 21:52:17 +010045 " Test 3: Skip the first 0x30 bytes
Bram Moolenaar29f9ed22018-04-10 19:20:31 +020046 let s:test += 1
Bram Moolenaar970f5d32019-01-25 21:52:17 +010047 for arg in ['-s 0x30', '-s0x30', '-s+0x30', '-skip 0x030', '-seek 0x30', '-seek +0x30 --']
48 exe '%!' . s:xxd_cmd . ' ' . arg . ' %'
49 call assert_equal(expected[3:], getline(1,'$'), s:Mess(s:test))
50 endfor
Bram Moolenaar29f9ed22018-04-10 19:20:31 +020051
52 " Test 4: Skip the first 30 bytes
53 let s:test += 1
Bram Moolenaar970f5d32019-01-25 21:52:17 +010054 for arg in ['-s -0x31', '-s-0x31']
55 exe '%!' . s:xxd_cmd . ' ' . arg . ' %'
56 call assert_equal(expected[2:], getline(1,'$'), s:Mess(s:test))
57 endfor
Bram Moolenaar29f9ed22018-04-10 19:20:31 +020058
Bram Moolenaar0eb220c2019-01-27 14:41:43 +010059 " The following tests use the xxd man page.
60 " For these tests to pass, the fileformat must be "unix".
61 let man_copy = 'Xxd.1'
62 let man_page = '../../runtime/doc/xxd.1'
63 if has('win32') && !filereadable(man_page)
64 let man_page = '../../doc/xxd.1'
65 endif
66 %d
67 exe '0r ' man_page '| set ff=unix | $d | w' man_copy '| bwipe!' man_copy
68
Bram Moolenaar29f9ed22018-04-10 19:20:31 +020069 " Test 5: Print 120 bytes as continuous hexdump with 20 octets per line
70 let s:test += 1
71 %d
Bram Moolenaar0eb220c2019-01-27 14:41:43 +010072 exe '0r! ' . s:xxd_cmd . ' -l 120 -ps -c20 ' . man_copy
Bram Moolenaar29f9ed22018-04-10 19:20:31 +020073 $d
74 let expected = [
RestorerZ81b62dd2024-08-15 21:39:33 +020075 \ '2e544820585844203120224d6179203230323422',
76 \ '20224d616e75616c207061676520666f72207878',
77 \ '64220a2e5c220a2e5c222032317374204d617920',
78 \ '313939360a2e5c22204d616e2070616765206175',
79 \ '74686f723a0a2e5c2220202020546f6e79204e75',
80 \ '67656e74203c746f6e79407363746e7567656e2e']
Bram Moolenaar29f9ed22018-04-10 19:20:31 +020081 call assert_equal(expected, getline(1,'$'), s:Mess(s:test))
Bram Moolenaar164268d2018-04-10 20:06:17 +020082
Bram Moolenaar29f9ed22018-04-10 19:20:31 +020083 " Test 6: Print the date from xxd.1
84 let s:test += 1
Bram Moolenaar970f5d32019-01-25 21:52:17 +010085 for arg in ['-l 13', '-l13', '-len 13']
86 %d
RestorerZ81b62dd2024-08-15 21:39:33 +020087 exe '0r! ' . s:xxd_cmd . ' -s 0x33 ' . arg . ' -cols 13 ' . man_copy
Bram Moolenaar970f5d32019-01-25 21:52:17 +010088 $d
RestorerZ81b62dd2024-08-15 21:39:33 +020089 call assert_equal('00000033: 3231 7374 204d 6179 2031 3939 36 21st May 1996', getline(1), s:Mess(s:test))
Bram Moolenaar970f5d32019-01-25 21:52:17 +010090 endfor
Bram Moolenaar164268d2018-04-10 20:06:17 +020091
Bram Moolenaar0eb220c2019-01-27 14:41:43 +010092 " Cleanup after tests 5 and 6
93 call delete(man_copy)
94
Bram Moolenaar29f9ed22018-04-10 19:20:31 +020095 " Test 7: Print C include
96 let s:test += 1
97 call writefile(['TESTabcd09'], 'XXDfile')
98 %d
Bram Moolenaar6995c0a2018-04-10 21:46:10 +020099 exe '0r! ' . s:xxd_cmd . ' -i XXDfile'
Bram Moolenaar29f9ed22018-04-10 19:20:31 +0200100 $d
Bram Moolenaarc79745a2019-05-20 22:12:34 +0200101 let expected =<< trim [CODE]
Bram Moolenaare7eb9272019-06-24 00:58:07 +0200102 unsigned char XXDfile[] = {
103 0x54, 0x45, 0x53, 0x54, 0x61, 0x62, 0x63, 0x64, 0x30, 0x39, 0x0a
104 };
Christian Brabandtfa8c9712024-01-25 20:50:49 +0100105 unsigned int XXDfile_len = 11;
Bram Moolenaarc79745a2019-05-20 22:12:34 +0200106 [CODE]
107
Bram Moolenaar29f9ed22018-04-10 19:20:31 +0200108 call assert_equal(expected, getline(1,'$'), s:Mess(s:test))
Bram Moolenaar164268d2018-04-10 20:06:17 +0200109
Bram Moolenaar29f9ed22018-04-10 19:20:31 +0200110 " Test 8: Print C include capitalized
111 let s:test += 1
Bram Moolenaar970f5d32019-01-25 21:52:17 +0100112 for arg in ['-C', '-capitalize']
113 call writefile(['TESTabcd09'], 'XXDfile')
114 %d
115 exe '0r! ' . s:xxd_cmd . ' -i ' . arg . ' XXDfile'
116 $d
Bram Moolenaarc79745a2019-05-20 22:12:34 +0200117 let expected =<< trim [CODE]
Bram Moolenaare7eb9272019-06-24 00:58:07 +0200118 unsigned char XXDFILE[] = {
119 0x54, 0x45, 0x53, 0x54, 0x61, 0x62, 0x63, 0x64, 0x30, 0x39, 0x0a
120 };
Christian Brabandtfa8c9712024-01-25 20:50:49 +0100121 unsigned int XXDFILE_LEN = 11;
Bram Moolenaarc79745a2019-05-20 22:12:34 +0200122 [CODE]
Bram Moolenaar970f5d32019-01-25 21:52:17 +0100123 call assert_equal(expected, getline(1,'$'), s:Mess(s:test))
124 endfor
Bram Moolenaar164268d2018-04-10 20:06:17 +0200125
126 " Test 9: Create a file with containing a single 'A'
Bram Moolenaar29f9ed22018-04-10 19:20:31 +0200127 let s:test += 1
128 call delete('XXDfile')
Bram Moolenaar164268d2018-04-10 20:06:17 +0200129 bwipe! XXDfile
Bram Moolenaar6995c0a2018-04-10 21:46:10 +0200130 if has('unix')
131 call system('echo "010000: 41"|' . s:xxd_cmd . ' -r -s -0x10000 > XXDfile')
132 else
133 call writefile(['010000: 41'], 'Xinput')
134 silent exe '!' . s:xxd_cmd . ' -r -s -0x10000 < Xinput > XXDfile'
135 call delete('Xinput')
136 endif
Bram Moolenaar29f9ed22018-04-10 19:20:31 +0200137 call PrepareBuffer(readfile('XXDfile')[0])
138 call assert_equal('A', getline(1), s:Mess(s:test))
139 call delete('XXDfile')
Bram Moolenaar970f5d32019-01-25 21:52:17 +0100140
141 " Test 10: group with 4 octets
142 let s:test += 1
143 for arg in ['-g 4', '-group 4', '-g4']
144 call writefile(['TESTabcd09'], 'XXDfile')
145 %d
146 exe '0r! ' . s:xxd_cmd . ' ' . arg . ' XXDfile'
147 $d
148 let expected = ['00000000: 54455354 61626364 30390a TESTabcd09.']
149 call assert_equal(expected, getline(1,'$'), s:Mess(s:test))
150 call delete('XXDfile')
151 endfor
152
Bram Moolenaar203651b2019-01-26 14:11:19 +0100153 " Test 11: reverse with CR, hex upper, Postscript style with a TAB
154 let s:test += 1
155 call writefile([" 54455354\t610B6364 30390A TESTa\0x0bcd09.\r"], 'Xinput')
156 silent exe '!' . s:xxd_cmd . ' -r -p < Xinput > XXDfile'
157 let blob = readfile('XXDfile', 'B')
158 call assert_equal(0z54455354.610B6364.30390A, blob)
159 call delete('Xinput')
160 call delete('XXDfile')
161
162 " Test 12: reverse with seek
163 let s:test += 1
164 call writefile(["00000000: 54455354\t610B6364 30390A TESTa\0x0bcd09.\r"], 'Xinput')
165 silent exe '!' . s:xxd_cmd . ' -r -seek 5 < Xinput > XXDfile'
166 let blob = readfile('XXDfile', 'B')
167 call assert_equal(0z0000000000.54455354.610B6364.30390A, blob)
168 call delete('Xinput')
169 call delete('XXDfile')
170
Bram Moolenaar363d6142020-05-30 20:50:25 +0200171 " Test 13: simple, decimal offset
172 call PrepareBuffer(range(1,30))
173 set ff=unix
174 w! XXDfile
175 let s:test += 1
176 exe '%!' . s:xxd_cmd . ' -d %'
177 let expected = [
178 \ '00000000: 310a 320a 330a 340a 350a 360a 370a 380a 1.2.3.4.5.6.7.8.',
179 \ '00000016: 390a 3130 0a31 310a 3132 0a31 330a 3134 9.10.11.12.13.14',
180 \ '00000032: 0a31 350a 3136 0a31 370a 3138 0a31 390a .15.16.17.18.19.',
181 \ '00000048: 3230 0a32 310a 3232 0a32 330a 3234 0a32 20.21.22.23.24.2',
182 \ '00000064: 350a 3236 0a32 370a 3238 0a32 390a 3330 5.26.27.28.29.30',
183 \ '00000080: 0a .']
184 call assert_equal(expected, getline(1,'$'), s:Mess(s:test))
185
186 " Test 14: grouping with -d
187 let s:test += 1
188 let expected = [
189 \ '00000000: 310a320a 330a340a 350a360a 370a380a 1.2.3.4.5.6.7.8.',
190 \ '00000016: 390a3130 0a31310a 31320a31 330a3134 9.10.11.12.13.14',
191 \ '00000032: 0a31350a 31360a31 370a3138 0a31390a .15.16.17.18.19.',
192 \ '00000048: 32300a32 310a3232 0a32330a 32340a32 20.21.22.23.24.2',
193 \ '00000064: 350a3236 0a32370a 32380a32 390a3330 5.26.27.28.29.30',
194 \ '00000080: 0a .']
195 for arg in ['-g 4', '-group 4', '-g4']
196 exe '%!' . s:xxd_cmd . ' ' . arg . ' -d %'
197 call assert_equal(expected, getline(1,'$'), s:Mess(s:test))
198 endfor
199
200 " Test 15: cols with decimal offset: -c 21 -d
201 let s:test += 1
202 let expected = [
203 \ '00000000: 310a 320a 330a 340a 350a 360a 370a 380a 390a 3130 0a 1.2.3.4.5.6.7.8.9.10.',
204 \ '00000021: 3131 0a31 320a 3133 0a31 340a 3135 0a31 360a 3137 0a 11.12.13.14.15.16.17.',
205 \ '00000042: 3138 0a31 390a 3230 0a32 310a 3232 0a32 330a 3234 0a 18.19.20.21.22.23.24.',
206 \ '00000063: 3235 0a32 360a 3237 0a32 380a 3239 0a33 300a 25.26.27.28.29.30.']
207 exe '%!' . s:xxd_cmd . ' -c 21 -d %'
208 call assert_equal(expected, getline(1,'$'), s:Mess(s:test))
209
Erik Auerswalda00e6222022-01-13 17:42:28 +0000210 " Test 16: -o -offset
211 let s:test += 1
212 let expected = [
213 \ '0000000f: 310a 320a 330a 340a 350a 360a 370a 380a 1.2.3.4.5.6.7.8.',
214 \ '0000001f: 390a 3130 0a31 310a 3132 0a31 330a 3134 9.10.11.12.13.14',
215 \ '0000002f: 0a31 350a 3136 0a31 370a 3138 0a31 390a .15.16.17.18.19.',
216 \ '0000003f: 3230 0a32 310a 3232 0a32 330a 3234 0a32 20.21.22.23.24.2',
217 \ '0000004f: 350a 3236 0a32 370a 3238 0a32 390a 3330 5.26.27.28.29.30',
218 \ '0000005f: 0a .']
219 for arg in ['-o 15', '-offset 15', '-o15']
220 exe '%!' . s:xxd_cmd . ' ' . arg . ' %'
221 call assert_equal(expected, getline(1,'$'), s:Mess(s:test))
222 endfor
Bram Moolenaar970f5d32019-01-25 21:52:17 +0100223
David Gow83e11802022-06-29 20:24:49 +0100224 " Test 17: Print C include with custom variable name
225 let s:test += 1
226 call writefile(['TESTabcd09'], 'XXDfile')
227 for arg in ['-nvarName', '-n varName', '-name varName']
228 %d
229 exe '0r! ' . s:xxd_cmd . ' -i ' . arg . ' XXDfile'
230 $d
231 let expected =<< trim [CODE]
232 unsigned char varName[] = {
233 0x54, 0x45, 0x53, 0x54, 0x61, 0x62, 0x63, 0x64, 0x30, 0x39, 0x0a
234 };
Christian Brabandtfa8c9712024-01-25 20:50:49 +0100235 unsigned int varName_len = 11;
David Gow83e11802022-06-29 20:24:49 +0100236 [CODE]
Bram Moolenaar94722c52023-01-28 19:19:03 +0000237
David Gow83e11802022-06-29 20:24:49 +0100238 call assert_equal(expected, getline(1,'$'), s:Mess(s:test))
239 endfor
240
241 " using "-n name" reading from stdin
242 %d
243 exe '0r! ' . s:xxd_cmd . ' -i < XXDfile -n StdIn'
244 $d
245 let expected =<< trim [CODE]
246 unsigned char StdIn[] = {
247 0x54, 0x45, 0x53, 0x54, 0x61, 0x62, 0x63, 0x64, 0x30, 0x39, 0x0a
248 };
Christian Brabandtfa8c9712024-01-25 20:50:49 +0100249 unsigned int StdIn_len = 11;
David Gow83e11802022-06-29 20:24:49 +0100250 [CODE]
251 call assert_equal(expected, getline(1,'$'), s:Mess(s:test))
252
253
254 " Test 18: Print C include: custom variable names can be capitalized
255 let s:test += 1
256 for arg in ['-C', '-capitalize']
257 call writefile(['TESTabcd09'], 'XXDfile')
258 %d
259 exe '0r! ' . s:xxd_cmd . ' -i ' . arg . ' -n varName XXDfile'
260 $d
261 let expected =<< trim [CODE]
262 unsigned char VARNAME[] = {
263 0x54, 0x45, 0x53, 0x54, 0x61, 0x62, 0x63, 0x64, 0x30, 0x39, 0x0a
264 };
Christian Brabandtfa8c9712024-01-25 20:50:49 +0100265 unsigned int VARNAME_LEN = 11;
David Gow83e11802022-06-29 20:24:49 +0100266 [CODE]
267 call assert_equal(expected, getline(1,'$'), s:Mess(s:test))
268 endfor
269
270
Andre Chang15022722024-09-15 20:03:05 +0200271 " Test 19: Print C include in binary format
272 let s:test += 1
273 call writefile(['TESTabcd09'], 'XXDfile')
274 %d
275 exe '0r! ' . s:xxd_cmd . ' -i -b XXDfile'
276 $d
277 let expected =<< trim [CODE]
278 unsigned char XXDfile[] = {
279 0b01010100, 0b01000101, 0b01010011, 0b01010100, 0b01100001, 0b01100010,
280 0b01100011, 0b01100100, 0b00110000, 0b00111001, 0b00001010
281 };
282 unsigned int XXDfile_len = 11;
283 [CODE]
284
285 call assert_equal(expected, getline(1,'$'), s:Mess(s:test))
286
287
Bram Moolenaar29f9ed22018-04-10 19:20:31 +0200288 %d
Bram Moolenaar253ea9f2020-06-10 14:21:20 +0200289 bwipe!
290 call delete('XXDfile')
Bram Moolenaar29f9ed22018-04-10 19:20:31 +0200291endfunc
Bram Moolenaar970f5d32019-01-25 21:52:17 +0100292
DungSaga47810462021-10-22 12:55:42 +0100293func Test_xxd_patch()
Bram Moolenaar5a5c1112021-10-22 15:11:37 +0100294 let cmd1 = 'silent !' .. s:xxd_cmd .. ' -r Xxxdin Xxxdfile'
295 let cmd2 = 'silent !' .. s:xxd_cmd .. ' -g1 Xxxdfile > Xxxdout'
Bram Moolenaardb4c9472022-10-15 22:06:06 +0100296 call writefile(["2: 41 41", "8: 42 42"], 'Xxxdin', 'D')
297 call writefile(['::::::::'], 'Xxxdfile', 'D')
Bram Moolenaar5a5c1112021-10-22 15:11:37 +0100298 exe cmd1
299 exe cmd2
DungSaga47810462021-10-22 12:55:42 +0100300 call assert_equal(['00000000: 3a 3a 41 41 3a 3a 3a 3a 42 42 ::AA::::BB'], readfile('Xxxdout'))
301
302 call writefile(["2: 43 43 ", "8: 44 44"], 'Xxxdin')
Bram Moolenaar5a5c1112021-10-22 15:11:37 +0100303 exe cmd1
304 exe cmd2
DungSaga47810462021-10-22 12:55:42 +0100305 call assert_equal(['00000000: 3a 3a 43 43 3a 3a 3a 3a 44 44 ::CC::::DD'], readfile('Xxxdout'))
306
307 call writefile(["2: 45 45 ", "8: 46 46"], 'Xxxdin')
Bram Moolenaar5a5c1112021-10-22 15:11:37 +0100308 exe cmd1
309 exe cmd2
DungSaga47810462021-10-22 12:55:42 +0100310 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 +0000311
DungSaga47810462021-10-22 12:55:42 +0100312 call writefile(["2: 41 41", "08: 42 42"], 'Xxxdin')
313 call writefile(['::::::::'], 'Xxxdfile')
Bram Moolenaar5a5c1112021-10-22 15:11:37 +0100314 exe cmd1
315 exe cmd2
DungSaga47810462021-10-22 12:55:42 +0100316 call assert_equal(['00000000: 3a 3a 41 41 3a 3a 3a 3a 42 42 ::AA::::BB'], readfile('Xxxdout'))
317
318 call writefile(["2: 43 43 ", "09: 44 44"], 'Xxxdin')
Bram Moolenaar5a5c1112021-10-22 15:11:37 +0100319 exe cmd1
320 exe cmd2
DungSaga47810462021-10-22 12:55:42 +0100321 call assert_equal(['00000000: 3a 3a 43 43 3a 3a 3a 3a 42 44 44 ::CC::::BDD'], readfile('Xxxdout'))
322
323 call writefile(["2: 45 45 ", "0a: 46 46"], 'Xxxdin')
Bram Moolenaar5a5c1112021-10-22 15:11:37 +0100324 exe cmd1
325 exe cmd2
DungSaga47810462021-10-22 12:55:42 +0100326 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 +0000327
DungSaga47810462021-10-22 12:55:42 +0100328 call delete('Xxxdout')
329endfunc
330
tristhaus85f45212023-10-06 19:51:13 +0200331func Test_xxd_patch_with_bitdump()
332 let cmd1 = 'silent !' .. s:xxd_cmd .. ' -r -b Xxxdin Xxxdfile'
333 let cmd2 = 'silent !' .. s:xxd_cmd .. ' -g1 Xxxdfile > Xxxdout'
334
335 call writefile(["2: 01000001 01000001", "8: 01000010 01000010"], 'Xxxdin', 'D')
336 call writefile(['::::::::'], 'Xxxdfile', 'D')
337 exe cmd1
338 exe cmd2
339 call assert_equal(['00000000: 3a 3a 41 41 3a 3a 3a 3a 42 42 ::AA::::BB'], readfile('Xxxdout'))
340
341 call writefile(["1: 01000011 01000011", "4: 01000100 01000100"], 'Xxxdin', 'D')
342 call writefile(['::::::::'], 'Xxxdfile', 'D')
343 exe cmd1
344 exe cmd2
345 call assert_equal(['00000000: 3a 43 43 3a 44 44 3a 3a 0a :CC:DD::.'], readfile('Xxxdout'))
346
347 call writefile(["02: 01000101 01000101", "08: 01000110 01000110"], 'Xxxdin', 'D')
348 call writefile(['::::::::'], 'Xxxdfile', 'D')
349 exe cmd1
350 exe cmd2
351 call assert_equal(['00000000: 3a 3a 45 45 3a 3a 3a 3a 46 46 ::EE::::FF'], readfile('Xxxdout'))
352
353 call delete('Xxxdout')
354endfunc
355
Bram Moolenaar970f5d32019-01-25 21:52:17 +0100356" Various ways with wrong arguments that trigger the usage output.
357func Test_xxd_usage()
DungSaga4b9fa952024-11-11 22:19:50 +0100358 for arg in ['-h', '-c', '-g', '-o', '-s', '-l', '-X', '-R', 'one two three', '----', '---']
Bram Moolenaar970f5d32019-01-25 21:52:17 +0100359 new
360 exe 'r! ' . s:xxd_cmd . ' ' . arg
361 call assert_match("Usage:", join(getline(1, 3)))
362 bwipe!
363 endfor
364endfunc
365
DungSaga4b9fa952024-11-11 22:19:50 +0100366func Test_xxd_end_of_options()
367 new
368 exe 'r! ' . s:xxd_cmd . ' -- random-file-' . rand()
369 call assert_match('random-file-.*: No such file or directory', join(getline(1, 3)))
370 bwipe!
371endfunc
372
DungSaga48608b42021-11-24 11:18:07 +0000373func Test_xxd_ignore_garbage()
374 new
375 exe 'r! printf "\n\r xxxx 0: 42 42" | ' . s:xxd_cmd . ' -r'
376 call assert_match('BB', join(getline(1, 3)))
377 bwipe!
378endfunc
379
380func Test_xxd_bit_dump()
381 new
382 exe 'r! printf "123456" | ' . s:xxd_cmd . ' -b1'
383 call assert_match('00000000: 00110001 00110010 00110011 00110100 00110101 00110110 123456', join(getline(1, 3)))
384 bwipe!
385endfunc
386
tristhaus85f45212023-10-06 19:51:13 +0200387func Test_xxd_revert_bit_dump()
388 new
389 exe 'r! printf "00000000: 01000001 01100010 01000011 01100100 01000101 01100110 01000111 01101000 AbCdEfGh" | ' . s:xxd_cmd . ' -r -b1 -c 8'
390 call assert_match('AbCdEfGh', join(getline(1, 3)))
391 bwipe!
392
393 new
394 exe 'r! printf "00000000: 01000001 01100010 01000011 01100100 01000101 01100110 AbCdEf\n00000006: 01000111 01101000 Gh\n" | ' . s:xxd_cmd . ' -r -b1'
395 call assert_match('AbCdEfGh', join(getline(1, 3)))
396 bwipe!
397endfunc
398
OldWorldOrdr1c140302023-10-25 20:57:30 +0200399func Test_xxd_roundtrip_large_bit_dump()
400 new
401 exe 'r! printf "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789" | ' . s:xxd_cmd . ' -b | ' . s:xxd_cmd . ' -r -b'
402 call assert_match('abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ012345678', join(getline(1, 3)))
403 bwipe!
404endfunc
405
Bram Moolenaar970f5d32019-01-25 21:52:17 +0100406func Test_xxd_version()
407 new
408 exe 'r! ' . s:xxd_cmd . ' -v'
=?UTF-8?q?J=C3=BCrgen=20Weigert?=80b2ba32021-06-29 20:36:25 +0200409 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 +0100410 bwipe!
411endfunc
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +0200412
Erik Auerswalda00e6222022-01-13 17:42:28 +0000413" number of columns must be non-negative
414func Test_xxd_min_cols()
415 for cols in ['-c-1', '-c -1', '-cols -1']
416 for fmt in ['', '-b', '-e', '-i', '-p', ]
417 new
418 exe 'r! printf "ignored" | ' . s:xxd_cmd . ' ' . cols . ' ' . fmt
419 call assert_match("invalid number of columns", join(getline(1, '$')))
420 bwipe!
421 endfor
422 endfor
423endfunc
424
425" some hex formats limit columns to 256 (a #define in xxd.c)
426func Test_xxd_max_cols()
427 for cols in ['-c257', '-c 257', '-cols 257']
428 for fmt in ['', '-b', '-e' ]
429 new
430 exe 'r! printf "ignored" | ' . s:xxd_cmd . ' ' . cols . ' ' . fmt
431 call assert_match("invalid number of columns", join(getline(1, '$')))
432 bwipe!
433 endfor
434 endfor
435endfunc
436
Lennard Hofmann67797192024-05-10 14:17:26 +0200437
Christian Brabandtb7deb1b2024-05-10 20:00:33 +0200438" This used to trigger a buffer overflow (#14738)
Lennard Hofmann67797192024-05-10 14:17:26 +0200439func Test_xxd_buffer_overflow()
440 CheckUnix
Christian Brabandtb7deb1b2024-05-10 20:00:33 +0200441 if system('file ' .. s:xxd_cmd) =~ '32-bit'
442 throw 'Skipped: test only works on 64-bit architecture'
443 endif
Lennard Hofmann67797192024-05-10 14:17:26 +0200444 new
445 let input = repeat('A', 256)
Emanuel Krollmann6897f182025-06-15 16:24:09 +0200446 call writefile(['-9223372036854775808: ' . repeat("\e[1;32m41\e[0m ", 256) . ' ' . "\e[1;32m" . repeat('A', 256) . "\e[0m"], 'Xxdexpected', 'D')
Lennard Hofmann67797192024-05-10 14:17:26 +0200447 exe 'r! printf ' . input . '| ' . s:xxd_cmd . ' -Ralways -g1 -c256 -d -o 9223372036854775808 > Xxdout'
448 call assert_equalfile('Xxdexpected', 'Xxdout')
449 call delete('Xxdout')
450 bwipe!
451endfunc
452
Erik Auerswalda00e6222022-01-13 17:42:28 +0000453" -c0 selects the format specific default column value, as if no -c was given
Erik Auerswaldc0a1d372022-01-14 11:58:48 +0000454" except for -ps, where it disables extra newlines
Erik Auerswalda00e6222022-01-13 17:42:28 +0000455func Test_xxd_c0_is_def_cols()
Bram Moolenaardb4c9472022-10-15 22:06:06 +0100456 call writefile(["abcdefghijklmnopqrstuvwxyz0123456789"], 'Xxdin', 'D')
Erik Auerswalda00e6222022-01-13 17:42:28 +0000457 for cols in ['-c0', '-c 0', '-cols 0']
Erik Auerswaldc0a1d372022-01-14 11:58:48 +0000458 for fmt in ['', '-b', '-e', '-i']
Erik Auerswalda00e6222022-01-13 17:42:28 +0000459 exe 'r! ' . s:xxd_cmd . ' ' . fmt ' Xxdin > Xxdout1'
460 exe 'r! ' . s:xxd_cmd . ' ' . cols . ' ' . fmt ' Xxdin > Xxdout2'
461 call assert_equalfile('Xxdout1', 'Xxdout2')
462 endfor
463 endfor
Erik Auerswalda00e6222022-01-13 17:42:28 +0000464 call delete('Xxdout1')
465 call delete('Xxdout2')
466endfunc
467
Erik Auerswaldc0a1d372022-01-14 11:58:48 +0000468" all output in a single line for -c0 -ps
469func Test_xxd_plain_one_line()
470 call writefile([
471 \ "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789",
472 \ "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789",
473 \ "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789",
474 \ "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789",
475 \ "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789",
476 \ "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"],
Bram Moolenaardb4c9472022-10-15 22:06:06 +0100477 \ 'Xxdin', 'D')
Erik Auerswaldc0a1d372022-01-14 11:58:48 +0000478 for cols in ['-c0', '-c 0', '-cols 0']
479 exe 'r! ' . s:xxd_cmd . ' -ps ' . cols ' Xxdin'
480 " output seems to start in line 2
481 let out = join(getline(2, '$'))
482 bwipe!
483 " newlines in xxd output result in spaces in the string variable out
484 call assert_notmatch(" ", out)
485 " xxd output must be non-empty and comprise only lower case hex digits
486 call assert_match("^[0-9a-f][0-9a-f]*$", out)
487 endfor
Erik Auerswaldc0a1d372022-01-14 11:58:48 +0000488endfunc
489
Bram Moolenaar4390d872023-03-05 20:17:39 +0000490func Test_xxd_little_endian_with_cols()
491 enew!
492 call writefile(["ABCDEF"], 'Xxdin', 'D')
493 exe 'r! ' .. s:xxd_cmd .. ' -e -c6 ' .. ' Xxdin'
Aapo Rantalainenc73fc862024-10-19 15:54:57 +0200494 call assert_equal('00000000: 44434241 4645 ABCDEF', getline(2))
Bram Moolenaar4390d872023-03-05 20:17:39 +0000495
496 enew!
497 call writefile(["ABCDEFGHI"], 'Xxdin', 'D')
498 exe 'r! ' .. s:xxd_cmd .. ' -e -c9 ' .. ' Xxdin'
Aapo Rantalainenc73fc862024-10-19 15:54:57 +0200499 call assert_equal('00000000: 44434241 48474645 49 ABCDEFGHI', getline(2))
Bram Moolenaar4390d872023-03-05 20:17:39 +0000500
501 bwipe!
502endfunc
503
Aapo Rantalainene2528ae2023-08-31 17:58:13 +0200504func Test_xxd_color()
505"Test: color=never
506let s:test = 1
507
508"Note Quotation mark escaped
509"Note Aposhpere vaihdettu apostrophe replaced with 0x00
510"Note Backslash replaced with 0x00
511let data = [
512 \ "00000000: 0001 0203 0405 0607 0809 0a0b 0c0d 0e0f ................",
513 \ "00000010: 1011 1213 1415 1617 1819 1a1b 1c1d 1e1f ................",
514 \ "00000020: 2021 2223 2425 2600 2829 2a2b 2c2d 2e2f !\"#$%&.()*+,-./",
515 \ "00000030: 3031 3233 3435 3637 3839 3a3b 3c3d 3e3f 0123456789:;<=>?",
516 \ "00000040: 4041 4243 4445 4647 4849 4a4b 4c4d 4e4f @ABCDEFGHIJKLMNO",
517 \ "00000050: 5051 5253 5455 5657 5859 5a5b 005d 5e5f PQRSTUVWXYZ[.]^_",
518 \ "00000060: 6061 6263 6465 6667 6869 6a6b 6c6d 6e6f `abcdefghijklmno",
519 \ "00000070: 7071 7273 7475 7677 7879 7a7b 7c7d 7e7f pqrstuvwxyz{|}~.",
520 \ "00000080: 8081 8283 8485 8687 8889 8a8b 8c8d 8e8f ................",
521 \ "00000090: 9091 9293 9495 9697 9899 9a9b 9c9d 9e9f ................",
522 \ "000000a0: a0a1 a2a3 a4a5 a6a7 a8a9 aaab acad aeaf ................",
523 \ "000000b0: b0b1 b2b3 b4b5 b6b7 b8b9 babb bcbd bebf ................",
524 \ "000000c0: c0c1 c2c3 c4c5 c6c7 c8c9 cacb cccd cecf ................",
525 \ "000000d0: d0d1 d2d3 d4d5 d6d7 d8d9 dadb dcdd dedf ................",
526 \ "000000e0: e0e1 e2e3 e4e5 e6e7 e8e9 eaeb eced eeef ................",
527 \ "000000f0: f0f1 f2f3 f4f5 f6f7 f8f9 fafb fcfd feff ................"]
528call writefile(data,'Xinput')
529
530 silent exe '!' . s:xxd_cmd . ' -r < Xinput > XXDfile'
531
532 %d
533 exe '0r! ' . s:xxd_cmd . ' -R never ' . ' XXDfile'
534 $d
535 let expected = [
536 \ "00000000: 0001 0203 0405 0607 0809 0a0b 0c0d 0e0f ................",
537 \ "00000010: 1011 1213 1415 1617 1819 1a1b 1c1d 1e1f ................",
538 \ "00000020: 2021 2223 2425 2600 2829 2a2b 2c2d 2e2f !\"#$%&.()*+,-./",
539 \ "00000030: 3031 3233 3435 3637 3839 3a3b 3c3d 3e3f 0123456789:;<=>?",
540 \ "00000040: 4041 4243 4445 4647 4849 4a4b 4c4d 4e4f @ABCDEFGHIJKLMNO",
541 \ "00000050: 5051 5253 5455 5657 5859 5a5b 005d 5e5f PQRSTUVWXYZ[.]^_",
542 \ "00000060: 6061 6263 6465 6667 6869 6a6b 6c6d 6e6f `abcdefghijklmno",
543 \ "00000070: 7071 7273 7475 7677 7879 7a7b 7c7d 7e7f pqrstuvwxyz{|}~.",
544 \ "00000080: 8081 8283 8485 8687 8889 8a8b 8c8d 8e8f ................",
545 \ "00000090: 9091 9293 9495 9697 9899 9a9b 9c9d 9e9f ................",
546 \ "000000a0: a0a1 a2a3 a4a5 a6a7 a8a9 aaab acad aeaf ................",
547 \ "000000b0: b0b1 b2b3 b4b5 b6b7 b8b9 babb bcbd bebf ................",
548 \ "000000c0: c0c1 c2c3 c4c5 c6c7 c8c9 cacb cccd cecf ................",
549 \ "000000d0: d0d1 d2d3 d4d5 d6d7 d8d9 dadb dcdd dedf ................",
550 \ "000000e0: e0e1 e2e3 e4e5 e6e7 e8e9 eaeb eced eeef ................",
551 \ "000000f0: f0f1 f2f3 f4f5 f6f7 f8f9 fafb fcfd feff ................"]
552
553 call assert_equal(expected, getline(1,'$'), s:Mess(s:test))
554
555 "Test: color=always
556 let s:test += 1
557
558 %d
559 exe '0r! ' . s:xxd_cmd . ' -R always -c 4 ' . ' XXDfile'
560 $d
561 let expected = [
Emanuel Krollmann6897f182025-06-15 16:24:09 +0200562 \ "00000000: \e[1;37m00\e[0m\e[1;31m01\e[0m \e[1;31m0203\e[0m \e[1;37m.\e[0m\e[1;31m...\e[0m",
563 \ "00000004: \e[1;31m0405\e[0m \e[1;31m0607\e[0m \e[1;31m....\e[0m",
564 \ "00000008: \e[1;31m08\e[0m\e[1;33m09\e[0m \e[1;33m0a\e[0m\e[1;31m0b\e[0m \e[1;31m.\e[0m\e[1;33m..\e[0m\e[1;31m.\e[0m",
565 \ "0000000c: \e[1;31m0c\e[0m\e[1;33m0d\e[0m \e[1;31m0e0f\e[0m \e[1;31m.\e[0m\e[1;33m.\e[0m\e[1;31m..\e[0m",
566 \ "00000010: \e[1;31m1011\e[0m \e[1;31m1213\e[0m \e[1;31m....\e[0m",
567 \ "00000014: \e[1;31m1415\e[0m \e[1;31m1617\e[0m \e[1;31m....\e[0m",
568 \ "00000018: \e[1;31m1819\e[0m \e[1;31m1a1b\e[0m \e[1;31m....\e[0m",
569 \ "0000001c: \e[1;31m1c1d\e[0m \e[1;31m1e1f\e[0m \e[1;31m....\e[0m",
570 \ "00000020: \e[1;32m2021\e[0m \e[1;32m2223\e[0m \e[1;32m !\"#\e[0m",
571 \ "00000024: \e[1;32m2425\e[0m \e[1;32m26\e[0m\e[1;37m00\e[0m \e[1;32m$%&\e[0m\e[1;37m.\e[0m",
572 \ "00000028: \e[1;32m2829\e[0m \e[1;32m2a2b\e[0m \e[1;32m()*+\e[0m",
573 \ "0000002c: \e[1;32m2c2d\e[0m \e[1;32m2e2f\e[0m \e[1;32m,-./\e[0m",
574 \ "00000030: \e[1;32m3031\e[0m \e[1;32m3233\e[0m \e[1;32m0123\e[0m",
575 \ "00000034: \e[1;32m3435\e[0m \e[1;32m3637\e[0m \e[1;32m4567\e[0m",
576 \ "00000038: \e[1;32m3839\e[0m \e[1;32m3a3b\e[0m \e[1;32m89:;\e[0m",
577 \ "0000003c: \e[1;32m3c3d\e[0m \e[1;32m3e3f\e[0m \e[1;32m<=>?\e[0m",
578 \ "00000040: \e[1;32m4041\e[0m \e[1;32m4243\e[0m \e[1;32m@ABC\e[0m",
579 \ "00000044: \e[1;32m4445\e[0m \e[1;32m4647\e[0m \e[1;32mDEFG\e[0m",
580 \ "00000048: \e[1;32m4849\e[0m \e[1;32m4a4b\e[0m \e[1;32mHIJK\e[0m",
581 \ "0000004c: \e[1;32m4c4d\e[0m \e[1;32m4e4f\e[0m \e[1;32mLMNO\e[0m",
582 \ "00000050: \e[1;32m5051\e[0m \e[1;32m5253\e[0m \e[1;32mPQRS\e[0m",
583 \ "00000054: \e[1;32m5455\e[0m \e[1;32m5657\e[0m \e[1;32mTUVW\e[0m",
584 \ "00000058: \e[1;32m5859\e[0m \e[1;32m5a5b\e[0m \e[1;32mXYZ[\e[0m",
585 \ "0000005c: \e[1;37m00\e[0m\e[1;32m5d\e[0m \e[1;32m5e5f\e[0m \e[1;37m.\e[0m\e[1;32m]^_\e[0m",
586 \ "00000060: \e[1;32m6061\e[0m \e[1;32m6263\e[0m \e[1;32m`abc\e[0m",
587 \ "00000064: \e[1;32m6465\e[0m \e[1;32m6667\e[0m \e[1;32mdefg\e[0m",
588 \ "00000068: \e[1;32m6869\e[0m \e[1;32m6a6b\e[0m \e[1;32mhijk\e[0m",
589 \ "0000006c: \e[1;32m6c6d\e[0m \e[1;32m6e6f\e[0m \e[1;32mlmno\e[0m",
590 \ "00000070: \e[1;32m7071\e[0m \e[1;32m7273\e[0m \e[1;32mpqrs\e[0m",
591 \ "00000074: \e[1;32m7475\e[0m \e[1;32m7677\e[0m \e[1;32mtuvw\e[0m",
592 \ "00000078: \e[1;32m7879\e[0m \e[1;32m7a7b\e[0m \e[1;32mxyz{\e[0m",
593 \ "0000007c: \e[1;32m7c7d\e[0m \e[1;32m7e\e[0m\e[1;31m7f\e[0m \e[1;32m|}~\e[0m\e[1;31m.\e[0m",
594 \ "00000080: \e[1;31m8081\e[0m \e[1;31m8283\e[0m \e[1;31m....\e[0m",
595 \ "00000084: \e[1;31m8485\e[0m \e[1;31m8687\e[0m \e[1;31m....\e[0m",
596 \ "00000088: \e[1;31m8889\e[0m \e[1;31m8a8b\e[0m \e[1;31m....\e[0m",
597 \ "0000008c: \e[1;31m8c8d\e[0m \e[1;31m8e8f\e[0m \e[1;31m....\e[0m",
598 \ "00000090: \e[1;31m9091\e[0m \e[1;31m9293\e[0m \e[1;31m....\e[0m",
599 \ "00000094: \e[1;31m9495\e[0m \e[1;31m9697\e[0m \e[1;31m....\e[0m",
600 \ "00000098: \e[1;31m9899\e[0m \e[1;31m9a9b\e[0m \e[1;31m....\e[0m",
601 \ "0000009c: \e[1;31m9c9d\e[0m \e[1;31m9e9f\e[0m \e[1;31m....\e[0m",
602 \ "000000a0: \e[1;31ma0a1\e[0m \e[1;31ma2a3\e[0m \e[1;31m....\e[0m",
603 \ "000000a4: \e[1;31ma4a5\e[0m \e[1;31ma6a7\e[0m \e[1;31m....\e[0m",
604 \ "000000a8: \e[1;31ma8a9\e[0m \e[1;31maaab\e[0m \e[1;31m....\e[0m",
605 \ "000000ac: \e[1;31macad\e[0m \e[1;31maeaf\e[0m \e[1;31m....\e[0m",
606 \ "000000b0: \e[1;31mb0b1\e[0m \e[1;31mb2b3\e[0m \e[1;31m....\e[0m",
607 \ "000000b4: \e[1;31mb4b5\e[0m \e[1;31mb6b7\e[0m \e[1;31m....\e[0m",
608 \ "000000b8: \e[1;31mb8b9\e[0m \e[1;31mbabb\e[0m \e[1;31m....\e[0m",
609 \ "000000bc: \e[1;31mbcbd\e[0m \e[1;31mbebf\e[0m \e[1;31m....\e[0m",
610 \ "000000c0: \e[1;31mc0c1\e[0m \e[1;31mc2c3\e[0m \e[1;31m....\e[0m",
611 \ "000000c4: \e[1;31mc4c5\e[0m \e[1;31mc6c7\e[0m \e[1;31m....\e[0m",
612 \ "000000c8: \e[1;31mc8c9\e[0m \e[1;31mcacb\e[0m \e[1;31m....\e[0m",
613 \ "000000cc: \e[1;31mcccd\e[0m \e[1;31mcecf\e[0m \e[1;31m....\e[0m",
614 \ "000000d0: \e[1;31md0d1\e[0m \e[1;31md2d3\e[0m \e[1;31m....\e[0m",
615 \ "000000d4: \e[1;31md4d5\e[0m \e[1;31md6d7\e[0m \e[1;31m....\e[0m",
616 \ "000000d8: \e[1;31md8d9\e[0m \e[1;31mdadb\e[0m \e[1;31m....\e[0m",
617 \ "000000dc: \e[1;31mdcdd\e[0m \e[1;31mdedf\e[0m \e[1;31m....\e[0m",
618 \ "000000e0: \e[1;31me0e1\e[0m \e[1;31me2e3\e[0m \e[1;31m....\e[0m",
619 \ "000000e4: \e[1;31me4e5\e[0m \e[1;31me6e7\e[0m \e[1;31m....\e[0m",
620 \ "000000e8: \e[1;31me8e9\e[0m \e[1;31meaeb\e[0m \e[1;31m....\e[0m",
621 \ "000000ec: \e[1;31meced\e[0m \e[1;31meeef\e[0m \e[1;31m....\e[0m",
622 \ "000000f0: \e[1;31mf0f1\e[0m \e[1;31mf2f3\e[0m \e[1;31m....\e[0m",
623 \ "000000f4: \e[1;31mf4f5\e[0m \e[1;31mf6f7\e[0m \e[1;31m....\e[0m",
624 \ "000000f8: \e[1;31mf8f9\e[0m \e[1;31mfafb\e[0m \e[1;31m....\e[0m",
625 \ "000000fc: \e[1;31mfcfd\e[0m \e[1;31mfe\e[0m\e[1;34mff\e[0m \e[1;31m...\e[0m\e[1;34m.\e[0m"]
Aapo Rantalainene2528ae2023-08-31 17:58:13 +0200626 call assert_equal(expected, getline(1,'$'), s:Mess(s:test))
627
628 call delete('Xinput')
629 call delete('XXDfile')
630
631endfunc
632
633func Test_xxd_color2()
634 CheckScreendump
635 CheckUnix
636 CheckNotMac
637 CheckNotBSD
Philip H1690ec62023-09-06 20:20:07 +0200638 CheckExecutable dash
Aapo Rantalainene2528ae2023-08-31 17:58:13 +0200639
640 "Note Quotation mark escaped
641 "Note Aposhpere vaihdettu apostrophe replaced with 0x00
642 "Note Backslash replaced with 0x00
643 let data = [
644 \ "00000000: 0001 0203 0405 0607 0809 0a0b 0c0d 0e0f ................",
645 \ "00000010: 1011 1213 1415 1617 1819 1a1b 1c1d 1e1f ................",
646 \ "00000020: 2021 2223 2425 2600 2829 2a2b 2c2d 2e2f !\"#$%&.()*+,-./",
647 \ "00000030: 3031 3233 3435 3637 3839 3a3b 3c3d 3e3f 0123456789:;<=>?",
648 \ "00000040: 4041 4243 4445 4647 4849 4a4b 4c4d 4e4f @ABCDEFGHIJKLMNO",
649 \ "00000050: 5051 5253 5455 5657 5859 5a5b 005d 5e5f PQRSTUVWXYZ[.]^_",
650 \ "00000060: 6061 6263 6465 6667 6869 6a6b 6c6d 6e6f `abcdefghijklmno",
651 \ "00000070: 7071 7273 7475 7677 7879 7a7b 7c7d 7e7f pqrstuvwxyz{|}~.",
652 \ "00000080: 8081 8283 8485 8687 8889 8a8b 8c8d 8e8f ................",
653 \ "00000090: 9091 9293 9495 9697 9899 9a9b 9c9d 9e9f ................",
654 \ "000000a0: a0a1 a2a3 a4a5 a6a7 a8a9 aaab acad aeaf ................",
655 \ "000000b0: b0b1 b2b3 b4b5 b6b7 b8b9 babb bcbd bebf ................",
656 \ "000000c0: c0c1 c2c3 c4c5 c6c7 c8c9 cacb cccd cecf ................",
657 \ "000000d0: d0d1 d2d3 d4d5 d6d7 d8d9 dadb dcdd dedf ................",
658 \ "000000e0: e0e1 e2e3 e4e5 e6e7 e8e9 eaeb eced eeef ................",
659 \ "000000f0: f0f1 f2f3 f4f5 f6f7 f8f9 fafb fcfd feff ................"]
660 call writefile(data, 'Xinput', 'D')
661
662 call system(s:xxd_cmd .. ' -r < Xinput > XXDfile_colors')
663
Christian Brabandtb2422f72023-09-02 16:01:18 +0200664 let $PS1='$ '
Philip H1690ec62023-09-06 20:20:07 +0200665 " This needs dash, plain bashs sh does not seem to work :(
Aapo Rantalainene2528ae2023-08-31 17:58:13 +0200666 let buf = RunVimInTerminal('', #{rows: 20, cmd: 'sh'})
667 call term_sendkeys(buf, s:xxd_cmd .. " -R never < XXDfile_colors\<cr>")
668 call TermWait(buf)
Drew Vogelea67ba72025-05-07 22:05:17 +0200669 redraw
Aapo Rantalainene2528ae2023-08-31 17:58:13 +0200670 call VerifyScreenDump(buf, 'Test_xxd_color_0', {})
671
672 call TermWait(buf)
673 call term_sendkeys(buf, "clear\<CR>")
674 call term_sendkeys(buf, s:xxd_cmd .. " -R always < XXDfile_colors\<cr>")
675 call TermWait(buf)
676 call VerifyScreenDump(buf, 'Test_xxd_color_1', {})
677
678 call term_sendkeys(buf, "exit\<CR>")
679
680 call delete('XXDfile_colors')
Christian Brabandtb2422f72023-09-02 16:01:18 +0200681 unlet! $PS1
Aapo Rantalainene2528ae2023-08-31 17:58:13 +0200682endfunc
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +0200683" vim: shiftwidth=2 sts=2 expandtab