annotate src/testdir/test_xxd.vim @ 20601:75ef263d09d6 v8.2.0854

patch 8.2.0854: xxd cannot show offset as a decimal number Commit: https://github.com/vim/vim/commit/363d6148dfc2cc17fb0d286c7a36c305f56f5813 Author: Bram Moolenaar <Bram@vim.org> Date: Sat May 30 20:50:25 2020 +0200 patch 8.2.0854: xxd cannot show offset as a decimal number Problem: Xxd cannot show offset as a decimal number. Solution: Add the "-d" flag. (Aapo Rantalainen, closes https://github.com/vim/vim/issues/5616
author Bram Moolenaar <Bram@vim.org>
date Sat, 30 May 2020 21:00:12 +0200
parents 6990c1160ea5
children d7d6993fc266
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
13634
2678e38e1de6 patch 8.0.1689: no tests for xxd
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1 " Test for the xxd command
13646
86eb21bb5920 patch 8.0.1695: xxd test not run on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 13638
diff changeset
2 if empty($XXD) && executable('..\xxd\xxd.exe')
86eb21bb5920 patch 8.0.1695: xxd test not run on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 13638
diff changeset
3 let s:xxd_cmd = '..\xxd\xxd.exe'
86eb21bb5920 patch 8.0.1695: xxd test not run on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 13638
diff changeset
4 elseif empty($XXD) || !executable($XXD)
17089
8e9e9124c7a2 patch 8.1.1544: some balloon tests don't run when they can
Bram Moolenaar <Bram@vim.org>
parents: 17049
diff changeset
5 throw 'Skipped: xxd program missing'
13646
86eb21bb5920 patch 8.0.1695: xxd test not run on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 13638
diff changeset
6 else
86eb21bb5920 patch 8.0.1695: xxd test not run on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 13638
diff changeset
7 let s:xxd_cmd = $XXD
13634
2678e38e1de6 patch 8.0.1689: no tests for xxd
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
8 endif
2678e38e1de6 patch 8.0.1689: no tests for xxd
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
9
15406
63b02fcf1361 patch 8.1.0711: test files still use function!
Bram Moolenaar <Bram@vim.org>
parents: 13963
diff changeset
10 func PrepareBuffer(lines)
13638
b3068807f5df patch 8.0.1691: xxd test sometimes fails
Christian Brabandt <cb@256bit.org>
parents: 13634
diff changeset
11 new
b3068807f5df patch 8.0.1691: xxd test sometimes fails
Christian Brabandt <cb@256bit.org>
parents: 13634
diff changeset
12 call append(0, a:lines)
13634
2678e38e1de6 patch 8.0.1689: no tests for xxd
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
13 $d
2678e38e1de6 patch 8.0.1689: no tests for xxd
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
14 endfunc
2678e38e1de6 patch 8.0.1689: no tests for xxd
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
15
15406
63b02fcf1361 patch 8.1.0711: test files still use function!
Bram Moolenaar <Bram@vim.org>
parents: 13963
diff changeset
16 func s:Mess(counter)
13634
2678e38e1de6 patch 8.0.1689: no tests for xxd
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
17 return printf("Failed xxd test %d:", a:counter)
2678e38e1de6 patch 8.0.1689: no tests for xxd
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
18 endfunc
2678e38e1de6 patch 8.0.1689: no tests for xxd
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
19
15406
63b02fcf1361 patch 8.1.0711: test files still use function!
Bram Moolenaar <Bram@vim.org>
parents: 13963
diff changeset
20 func Test_xxd()
13634
2678e38e1de6 patch 8.0.1689: no tests for xxd
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
21 call PrepareBuffer(range(1,30))
13646
86eb21bb5920 patch 8.0.1695: xxd test not run on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 13638
diff changeset
22 set ff=unix
15627
11879b89bb69 patch 8.1.0821: xxd "usage" output and other arguments not tested
Bram Moolenaar <Bram@vim.org>
parents: 15406
diff changeset
23 w! XXDfile
13638
b3068807f5df patch 8.0.1691: xxd test sometimes fails
Christian Brabandt <cb@256bit.org>
parents: 13634
diff changeset
24
13634
2678e38e1de6 patch 8.0.1689: no tests for xxd
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
25 " Test 1: simple, filter the result through xxd
2678e38e1de6 patch 8.0.1689: no tests for xxd
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
26 let s:test = 1
13646
86eb21bb5920 patch 8.0.1695: xxd test not run on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 13638
diff changeset
27 exe '%!' . s:xxd_cmd . ' %'
13634
2678e38e1de6 patch 8.0.1689: no tests for xxd
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
28 let expected = [
2678e38e1de6 patch 8.0.1689: no tests for xxd
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
29 \ '00000000: 310a 320a 330a 340a 350a 360a 370a 380a 1.2.3.4.5.6.7.8.',
2678e38e1de6 patch 8.0.1689: no tests for xxd
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
30 \ '00000010: 390a 3130 0a31 310a 3132 0a31 330a 3134 9.10.11.12.13.14',
2678e38e1de6 patch 8.0.1689: no tests for xxd
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
31 \ '00000020: 0a31 350a 3136 0a31 370a 3138 0a31 390a .15.16.17.18.19.',
2678e38e1de6 patch 8.0.1689: no tests for xxd
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
32 \ '00000030: 3230 0a32 310a 3232 0a32 330a 3234 0a32 20.21.22.23.24.2',
2678e38e1de6 patch 8.0.1689: no tests for xxd
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
33 \ '00000040: 350a 3236 0a32 370a 3238 0a32 390a 3330 5.26.27.28.29.30',
2678e38e1de6 patch 8.0.1689: no tests for xxd
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
34 \ '00000050: 0a .']
2678e38e1de6 patch 8.0.1689: no tests for xxd
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
35 call assert_equal(expected, getline(1,'$'), s:Mess(s:test))
13638
b3068807f5df patch 8.0.1691: xxd test sometimes fails
Christian Brabandt <cb@256bit.org>
parents: 13634
diff changeset
36
13634
2678e38e1de6 patch 8.0.1689: no tests for xxd
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
37 " Test 2: reverse the result
2678e38e1de6 patch 8.0.1689: no tests for xxd
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
38 let s:test += 1
13646
86eb21bb5920 patch 8.0.1695: xxd test not run on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 13638
diff changeset
39 exe '%!' . s:xxd_cmd . ' -r'
13634
2678e38e1de6 patch 8.0.1689: no tests for xxd
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
40 call assert_equal(map(range(1,30), {v,c -> string(c)}), getline(1,'$'), s:Mess(s:test))
2678e38e1de6 patch 8.0.1689: no tests for xxd
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
41
15627
11879b89bb69 patch 8.1.0821: xxd "usage" output and other arguments not tested
Bram Moolenaar <Bram@vim.org>
parents: 15406
diff changeset
42 " Test 3: Skip the first 0x30 bytes
13634
2678e38e1de6 patch 8.0.1689: no tests for xxd
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
43 let s:test += 1
15627
11879b89bb69 patch 8.1.0821: xxd "usage" output and other arguments not tested
Bram Moolenaar <Bram@vim.org>
parents: 15406
diff changeset
44 for arg in ['-s 0x30', '-s0x30', '-s+0x30', '-skip 0x030', '-seek 0x30', '-seek +0x30 --']
11879b89bb69 patch 8.1.0821: xxd "usage" output and other arguments not tested
Bram Moolenaar <Bram@vim.org>
parents: 15406
diff changeset
45 exe '%!' . s:xxd_cmd . ' ' . arg . ' %'
11879b89bb69 patch 8.1.0821: xxd "usage" output and other arguments not tested
Bram Moolenaar <Bram@vim.org>
parents: 15406
diff changeset
46 call assert_equal(expected[3:], getline(1,'$'), s:Mess(s:test))
11879b89bb69 patch 8.1.0821: xxd "usage" output and other arguments not tested
Bram Moolenaar <Bram@vim.org>
parents: 15406
diff changeset
47 endfor
13634
2678e38e1de6 patch 8.0.1689: no tests for xxd
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
48
2678e38e1de6 patch 8.0.1689: no tests for xxd
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
49 " Test 4: Skip the first 30 bytes
2678e38e1de6 patch 8.0.1689: no tests for xxd
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
50 let s:test += 1
15627
11879b89bb69 patch 8.1.0821: xxd "usage" output and other arguments not tested
Bram Moolenaar <Bram@vim.org>
parents: 15406
diff changeset
51 for arg in ['-s -0x31', '-s-0x31']
11879b89bb69 patch 8.1.0821: xxd "usage" output and other arguments not tested
Bram Moolenaar <Bram@vim.org>
parents: 15406
diff changeset
52 exe '%!' . s:xxd_cmd . ' ' . arg . ' %'
11879b89bb69 patch 8.1.0821: xxd "usage" output and other arguments not tested
Bram Moolenaar <Bram@vim.org>
parents: 15406
diff changeset
53 call assert_equal(expected[2:], getline(1,'$'), s:Mess(s:test))
11879b89bb69 patch 8.1.0821: xxd "usage" output and other arguments not tested
Bram Moolenaar <Bram@vim.org>
parents: 15406
diff changeset
54 endfor
13634
2678e38e1de6 patch 8.0.1689: no tests for xxd
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
55
15647
f7b88b1d3350 patch 8.1.0831: xxd test fails if man page has dos fileformat
Bram Moolenaar <Bram@vim.org>
parents: 15630
diff changeset
56 " The following tests use the xxd man page.
f7b88b1d3350 patch 8.1.0831: xxd test fails if man page has dos fileformat
Bram Moolenaar <Bram@vim.org>
parents: 15630
diff changeset
57 " For these tests to pass, the fileformat must be "unix".
f7b88b1d3350 patch 8.1.0831: xxd test fails if man page has dos fileformat
Bram Moolenaar <Bram@vim.org>
parents: 15630
diff changeset
58 let man_copy = 'Xxd.1'
f7b88b1d3350 patch 8.1.0831: xxd test fails if man page has dos fileformat
Bram Moolenaar <Bram@vim.org>
parents: 15630
diff changeset
59 let man_page = '../../runtime/doc/xxd.1'
f7b88b1d3350 patch 8.1.0831: xxd test fails if man page has dos fileformat
Bram Moolenaar <Bram@vim.org>
parents: 15630
diff changeset
60 if has('win32') && !filereadable(man_page)
f7b88b1d3350 patch 8.1.0831: xxd test fails if man page has dos fileformat
Bram Moolenaar <Bram@vim.org>
parents: 15630
diff changeset
61 let man_page = '../../doc/xxd.1'
f7b88b1d3350 patch 8.1.0831: xxd test fails if man page has dos fileformat
Bram Moolenaar <Bram@vim.org>
parents: 15630
diff changeset
62 endif
f7b88b1d3350 patch 8.1.0831: xxd test fails if man page has dos fileformat
Bram Moolenaar <Bram@vim.org>
parents: 15630
diff changeset
63 %d
f7b88b1d3350 patch 8.1.0831: xxd test fails if man page has dos fileformat
Bram Moolenaar <Bram@vim.org>
parents: 15630
diff changeset
64 exe '0r ' man_page '| set ff=unix | $d | w' man_copy '| bwipe!' man_copy
f7b88b1d3350 patch 8.1.0831: xxd test fails if man page has dos fileformat
Bram Moolenaar <Bram@vim.org>
parents: 15630
diff changeset
65
13634
2678e38e1de6 patch 8.0.1689: no tests for xxd
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
66 " Test 5: Print 120 bytes as continuous hexdump with 20 octets per line
2678e38e1de6 patch 8.0.1689: no tests for xxd
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
67 let s:test += 1
2678e38e1de6 patch 8.0.1689: no tests for xxd
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
68 %d
15647
f7b88b1d3350 patch 8.1.0831: xxd test fails if man page has dos fileformat
Bram Moolenaar <Bram@vim.org>
parents: 15630
diff changeset
69 exe '0r! ' . s:xxd_cmd . ' -l 120 -ps -c20 ' . man_copy
13634
2678e38e1de6 patch 8.0.1689: no tests for xxd
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
70 $d
2678e38e1de6 patch 8.0.1689: no tests for xxd
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
71 let expected = [
2678e38e1de6 patch 8.0.1689: no tests for xxd
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
72 \ '2e54482058584420312022417567757374203139',
2678e38e1de6 patch 8.0.1689: no tests for xxd
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
73 \ '39362220224d616e75616c207061676520666f72',
2678e38e1de6 patch 8.0.1689: no tests for xxd
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
74 \ '20787864220a2e5c220a2e5c222032317374204d',
2678e38e1de6 patch 8.0.1689: no tests for xxd
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
75 \ '617920313939360a2e5c22204d616e2070616765',
2678e38e1de6 patch 8.0.1689: no tests for xxd
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
76 \ '20617574686f723a0a2e5c2220202020546f6e79',
2678e38e1de6 patch 8.0.1689: no tests for xxd
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
77 \ '204e7567656e74203c746f6e79407363746e7567']
2678e38e1de6 patch 8.0.1689: no tests for xxd
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
78 call assert_equal(expected, getline(1,'$'), s:Mess(s:test))
13638
b3068807f5df patch 8.0.1691: xxd test sometimes fails
Christian Brabandt <cb@256bit.org>
parents: 13634
diff changeset
79
13634
2678e38e1de6 patch 8.0.1689: no tests for xxd
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
80 " Test 6: Print the date from xxd.1
2678e38e1de6 patch 8.0.1689: no tests for xxd
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
81 let s:test += 1
15627
11879b89bb69 patch 8.1.0821: xxd "usage" output and other arguments not tested
Bram Moolenaar <Bram@vim.org>
parents: 15406
diff changeset
82 for arg in ['-l 13', '-l13', '-len 13']
11879b89bb69 patch 8.1.0821: xxd "usage" output and other arguments not tested
Bram Moolenaar <Bram@vim.org>
parents: 15406
diff changeset
83 %d
15647
f7b88b1d3350 patch 8.1.0831: xxd test fails if man page has dos fileformat
Bram Moolenaar <Bram@vim.org>
parents: 15630
diff changeset
84 exe '0r! ' . s:xxd_cmd . ' -s 0x36 ' . arg . ' -cols 13 ' . man_copy
15627
11879b89bb69 patch 8.1.0821: xxd "usage" output and other arguments not tested
Bram Moolenaar <Bram@vim.org>
parents: 15406
diff changeset
85 $d
11879b89bb69 patch 8.1.0821: xxd "usage" output and other arguments not tested
Bram Moolenaar <Bram@vim.org>
parents: 15406
diff changeset
86 call assert_equal('00000036: 3231 7374 204d 6179 2031 3939 36 21st May 1996', getline(1), s:Mess(s:test))
11879b89bb69 patch 8.1.0821: xxd "usage" output and other arguments not tested
Bram Moolenaar <Bram@vim.org>
parents: 15406
diff changeset
87 endfor
13638
b3068807f5df patch 8.0.1691: xxd test sometimes fails
Christian Brabandt <cb@256bit.org>
parents: 13634
diff changeset
88
15647
f7b88b1d3350 patch 8.1.0831: xxd test fails if man page has dos fileformat
Bram Moolenaar <Bram@vim.org>
parents: 15630
diff changeset
89 " Cleanup after tests 5 and 6
f7b88b1d3350 patch 8.1.0831: xxd test fails if man page has dos fileformat
Bram Moolenaar <Bram@vim.org>
parents: 15630
diff changeset
90 call delete(man_copy)
f7b88b1d3350 patch 8.1.0831: xxd test fails if man page has dos fileformat
Bram Moolenaar <Bram@vim.org>
parents: 15630
diff changeset
91
13634
2678e38e1de6 patch 8.0.1689: no tests for xxd
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
92 " Test 7: Print C include
2678e38e1de6 patch 8.0.1689: no tests for xxd
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
93 let s:test += 1
2678e38e1de6 patch 8.0.1689: no tests for xxd
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
94 call writefile(['TESTabcd09'], 'XXDfile')
2678e38e1de6 patch 8.0.1689: no tests for xxd
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
95 %d
13646
86eb21bb5920 patch 8.0.1695: xxd test not run on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 13638
diff changeset
96 exe '0r! ' . s:xxd_cmd . ' -i XXDfile'
13634
2678e38e1de6 patch 8.0.1689: no tests for xxd
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
97 $d
16720
9c90cf08cfa8 patch 8.1.1362: code and data in tests can be hard to read
Bram Moolenaar <Bram@vim.org>
parents: 15647
diff changeset
98 let expected =<< trim [CODE]
17172
6990c1160ea5 patch 8.1.1585: :let-heredoc does not trim enough
Bram Moolenaar <Bram@vim.org>
parents: 17089
diff changeset
99 unsigned char XXDfile[] = {
6990c1160ea5 patch 8.1.1585: :let-heredoc does not trim enough
Bram Moolenaar <Bram@vim.org>
parents: 17089
diff changeset
100 0x54, 0x45, 0x53, 0x54, 0x61, 0x62, 0x63, 0x64, 0x30, 0x39, 0x0a
6990c1160ea5 patch 8.1.1585: :let-heredoc does not trim enough
Bram Moolenaar <Bram@vim.org>
parents: 17089
diff changeset
101 };
6990c1160ea5 patch 8.1.1585: :let-heredoc does not trim enough
Bram Moolenaar <Bram@vim.org>
parents: 17089
diff changeset
102 unsigned int XXDfile_len = 11;
16720
9c90cf08cfa8 patch 8.1.1362: code and data in tests can be hard to read
Bram Moolenaar <Bram@vim.org>
parents: 15647
diff changeset
103 [CODE]
9c90cf08cfa8 patch 8.1.1362: code and data in tests can be hard to read
Bram Moolenaar <Bram@vim.org>
parents: 15647
diff changeset
104
13634
2678e38e1de6 patch 8.0.1689: no tests for xxd
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
105 call assert_equal(expected, getline(1,'$'), s:Mess(s:test))
13638
b3068807f5df patch 8.0.1691: xxd test sometimes fails
Christian Brabandt <cb@256bit.org>
parents: 13634
diff changeset
106
13634
2678e38e1de6 patch 8.0.1689: no tests for xxd
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
107 " Test 8: Print C include capitalized
2678e38e1de6 patch 8.0.1689: no tests for xxd
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
108 let s:test += 1
15627
11879b89bb69 patch 8.1.0821: xxd "usage" output and other arguments not tested
Bram Moolenaar <Bram@vim.org>
parents: 15406
diff changeset
109 for arg in ['-C', '-capitalize']
11879b89bb69 patch 8.1.0821: xxd "usage" output and other arguments not tested
Bram Moolenaar <Bram@vim.org>
parents: 15406
diff changeset
110 call writefile(['TESTabcd09'], 'XXDfile')
11879b89bb69 patch 8.1.0821: xxd "usage" output and other arguments not tested
Bram Moolenaar <Bram@vim.org>
parents: 15406
diff changeset
111 %d
11879b89bb69 patch 8.1.0821: xxd "usage" output and other arguments not tested
Bram Moolenaar <Bram@vim.org>
parents: 15406
diff changeset
112 exe '0r! ' . s:xxd_cmd . ' -i ' . arg . ' XXDfile'
11879b89bb69 patch 8.1.0821: xxd "usage" output and other arguments not tested
Bram Moolenaar <Bram@vim.org>
parents: 15406
diff changeset
113 $d
16720
9c90cf08cfa8 patch 8.1.1362: code and data in tests can be hard to read
Bram Moolenaar <Bram@vim.org>
parents: 15647
diff changeset
114 let expected =<< trim [CODE]
17172
6990c1160ea5 patch 8.1.1585: :let-heredoc does not trim enough
Bram Moolenaar <Bram@vim.org>
parents: 17089
diff changeset
115 unsigned char XXDFILE[] = {
6990c1160ea5 patch 8.1.1585: :let-heredoc does not trim enough
Bram Moolenaar <Bram@vim.org>
parents: 17089
diff changeset
116 0x54, 0x45, 0x53, 0x54, 0x61, 0x62, 0x63, 0x64, 0x30, 0x39, 0x0a
6990c1160ea5 patch 8.1.1585: :let-heredoc does not trim enough
Bram Moolenaar <Bram@vim.org>
parents: 17089
diff changeset
117 };
6990c1160ea5 patch 8.1.1585: :let-heredoc does not trim enough
Bram Moolenaar <Bram@vim.org>
parents: 17089
diff changeset
118 unsigned int XXDFILE_LEN = 11;
16720
9c90cf08cfa8 patch 8.1.1362: code and data in tests can be hard to read
Bram Moolenaar <Bram@vim.org>
parents: 15647
diff changeset
119 [CODE]
15627
11879b89bb69 patch 8.1.0821: xxd "usage" output and other arguments not tested
Bram Moolenaar <Bram@vim.org>
parents: 15406
diff changeset
120 call assert_equal(expected, getline(1,'$'), s:Mess(s:test))
11879b89bb69 patch 8.1.0821: xxd "usage" output and other arguments not tested
Bram Moolenaar <Bram@vim.org>
parents: 15406
diff changeset
121 endfor
13638
b3068807f5df patch 8.0.1691: xxd test sometimes fails
Christian Brabandt <cb@256bit.org>
parents: 13634
diff changeset
122
b3068807f5df patch 8.0.1691: xxd test sometimes fails
Christian Brabandt <cb@256bit.org>
parents: 13634
diff changeset
123 " Test 9: Create a file with containing a single 'A'
13634
2678e38e1de6 patch 8.0.1689: no tests for xxd
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
124 let s:test += 1
2678e38e1de6 patch 8.0.1689: no tests for xxd
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
125 call delete('XXDfile')
13638
b3068807f5df patch 8.0.1691: xxd test sometimes fails
Christian Brabandt <cb@256bit.org>
parents: 13634
diff changeset
126 bwipe! XXDfile
13646
86eb21bb5920 patch 8.0.1695: xxd test not run on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 13638
diff changeset
127 if has('unix')
86eb21bb5920 patch 8.0.1695: xxd test not run on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 13638
diff changeset
128 call system('echo "010000: 41"|' . s:xxd_cmd . ' -r -s -0x10000 > XXDfile')
86eb21bb5920 patch 8.0.1695: xxd test not run on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 13638
diff changeset
129 else
86eb21bb5920 patch 8.0.1695: xxd test not run on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 13638
diff changeset
130 call writefile(['010000: 41'], 'Xinput')
86eb21bb5920 patch 8.0.1695: xxd test not run on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 13638
diff changeset
131 silent exe '!' . s:xxd_cmd . ' -r -s -0x10000 < Xinput > XXDfile'
86eb21bb5920 patch 8.0.1695: xxd test not run on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 13638
diff changeset
132 call delete('Xinput')
86eb21bb5920 patch 8.0.1695: xxd test not run on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 13638
diff changeset
133 endif
13634
2678e38e1de6 patch 8.0.1689: no tests for xxd
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
134 call PrepareBuffer(readfile('XXDfile')[0])
2678e38e1de6 patch 8.0.1689: no tests for xxd
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
135 call assert_equal('A', getline(1), s:Mess(s:test))
2678e38e1de6 patch 8.0.1689: no tests for xxd
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
136 call delete('XXDfile')
15627
11879b89bb69 patch 8.1.0821: xxd "usage" output and other arguments not tested
Bram Moolenaar <Bram@vim.org>
parents: 15406
diff changeset
137
11879b89bb69 patch 8.1.0821: xxd "usage" output and other arguments not tested
Bram Moolenaar <Bram@vim.org>
parents: 15406
diff changeset
138 " Test 10: group with 4 octets
11879b89bb69 patch 8.1.0821: xxd "usage" output and other arguments not tested
Bram Moolenaar <Bram@vim.org>
parents: 15406
diff changeset
139 let s:test += 1
11879b89bb69 patch 8.1.0821: xxd "usage" output and other arguments not tested
Bram Moolenaar <Bram@vim.org>
parents: 15406
diff changeset
140 for arg in ['-g 4', '-group 4', '-g4']
11879b89bb69 patch 8.1.0821: xxd "usage" output and other arguments not tested
Bram Moolenaar <Bram@vim.org>
parents: 15406
diff changeset
141 call writefile(['TESTabcd09'], 'XXDfile')
11879b89bb69 patch 8.1.0821: xxd "usage" output and other arguments not tested
Bram Moolenaar <Bram@vim.org>
parents: 15406
diff changeset
142 %d
11879b89bb69 patch 8.1.0821: xxd "usage" output and other arguments not tested
Bram Moolenaar <Bram@vim.org>
parents: 15406
diff changeset
143 exe '0r! ' . s:xxd_cmd . ' ' . arg . ' XXDfile'
11879b89bb69 patch 8.1.0821: xxd "usage" output and other arguments not tested
Bram Moolenaar <Bram@vim.org>
parents: 15406
diff changeset
144 $d
11879b89bb69 patch 8.1.0821: xxd "usage" output and other arguments not tested
Bram Moolenaar <Bram@vim.org>
parents: 15406
diff changeset
145 let expected = ['00000000: 54455354 61626364 30390a TESTabcd09.']
11879b89bb69 patch 8.1.0821: xxd "usage" output and other arguments not tested
Bram Moolenaar <Bram@vim.org>
parents: 15406
diff changeset
146 call assert_equal(expected, getline(1,'$'), s:Mess(s:test))
11879b89bb69 patch 8.1.0821: xxd "usage" output and other arguments not tested
Bram Moolenaar <Bram@vim.org>
parents: 15406
diff changeset
147 call delete('XXDfile')
11879b89bb69 patch 8.1.0821: xxd "usage" output and other arguments not tested
Bram Moolenaar <Bram@vim.org>
parents: 15406
diff changeset
148 endfor
11879b89bb69 patch 8.1.0821: xxd "usage" output and other arguments not tested
Bram Moolenaar <Bram@vim.org>
parents: 15406
diff changeset
149
15630
db6cfc44eb65 patch 8.1.0823: not sufficient testing of xxd
Bram Moolenaar <Bram@vim.org>
parents: 15627
diff changeset
150 " Test 11: reverse with CR, hex upper, Postscript style with a TAB
db6cfc44eb65 patch 8.1.0823: not sufficient testing of xxd
Bram Moolenaar <Bram@vim.org>
parents: 15627
diff changeset
151 let s:test += 1
db6cfc44eb65 patch 8.1.0823: not sufficient testing of xxd
Bram Moolenaar <Bram@vim.org>
parents: 15627
diff changeset
152 call writefile([" 54455354\t610B6364 30390A TESTa\0x0bcd09.\r"], 'Xinput')
db6cfc44eb65 patch 8.1.0823: not sufficient testing of xxd
Bram Moolenaar <Bram@vim.org>
parents: 15627
diff changeset
153 silent exe '!' . s:xxd_cmd . ' -r -p < Xinput > XXDfile'
db6cfc44eb65 patch 8.1.0823: not sufficient testing of xxd
Bram Moolenaar <Bram@vim.org>
parents: 15627
diff changeset
154 let blob = readfile('XXDfile', 'B')
db6cfc44eb65 patch 8.1.0823: not sufficient testing of xxd
Bram Moolenaar <Bram@vim.org>
parents: 15627
diff changeset
155 call assert_equal(0z54455354.610B6364.30390A, blob)
db6cfc44eb65 patch 8.1.0823: not sufficient testing of xxd
Bram Moolenaar <Bram@vim.org>
parents: 15627
diff changeset
156 call delete('Xinput')
db6cfc44eb65 patch 8.1.0823: not sufficient testing of xxd
Bram Moolenaar <Bram@vim.org>
parents: 15627
diff changeset
157 call delete('XXDfile')
db6cfc44eb65 patch 8.1.0823: not sufficient testing of xxd
Bram Moolenaar <Bram@vim.org>
parents: 15627
diff changeset
158
db6cfc44eb65 patch 8.1.0823: not sufficient testing of xxd
Bram Moolenaar <Bram@vim.org>
parents: 15627
diff changeset
159 " Test 12: reverse with seek
db6cfc44eb65 patch 8.1.0823: not sufficient testing of xxd
Bram Moolenaar <Bram@vim.org>
parents: 15627
diff changeset
160 let s:test += 1
db6cfc44eb65 patch 8.1.0823: not sufficient testing of xxd
Bram Moolenaar <Bram@vim.org>
parents: 15627
diff changeset
161 call writefile(["00000000: 54455354\t610B6364 30390A TESTa\0x0bcd09.\r"], 'Xinput')
db6cfc44eb65 patch 8.1.0823: not sufficient testing of xxd
Bram Moolenaar <Bram@vim.org>
parents: 15627
diff changeset
162 silent exe '!' . s:xxd_cmd . ' -r -seek 5 < Xinput > XXDfile'
db6cfc44eb65 patch 8.1.0823: not sufficient testing of xxd
Bram Moolenaar <Bram@vim.org>
parents: 15627
diff changeset
163 let blob = readfile('XXDfile', 'B')
db6cfc44eb65 patch 8.1.0823: not sufficient testing of xxd
Bram Moolenaar <Bram@vim.org>
parents: 15627
diff changeset
164 call assert_equal(0z0000000000.54455354.610B6364.30390A, blob)
db6cfc44eb65 patch 8.1.0823: not sufficient testing of xxd
Bram Moolenaar <Bram@vim.org>
parents: 15627
diff changeset
165 call delete('Xinput')
db6cfc44eb65 patch 8.1.0823: not sufficient testing of xxd
Bram Moolenaar <Bram@vim.org>
parents: 15627
diff changeset
166 call delete('XXDfile')
db6cfc44eb65 patch 8.1.0823: not sufficient testing of xxd
Bram Moolenaar <Bram@vim.org>
parents: 15627
diff changeset
167
20601
75ef263d09d6 patch 8.2.0854: xxd cannot show offset as a decimal number
Bram Moolenaar <Bram@vim.org>
parents: 17172
diff changeset
168 " Test 13: simple, decimal offset
75ef263d09d6 patch 8.2.0854: xxd cannot show offset as a decimal number
Bram Moolenaar <Bram@vim.org>
parents: 17172
diff changeset
169 call PrepareBuffer(range(1,30))
75ef263d09d6 patch 8.2.0854: xxd cannot show offset as a decimal number
Bram Moolenaar <Bram@vim.org>
parents: 17172
diff changeset
170 set ff=unix
75ef263d09d6 patch 8.2.0854: xxd cannot show offset as a decimal number
Bram Moolenaar <Bram@vim.org>
parents: 17172
diff changeset
171 w! XXDfile
75ef263d09d6 patch 8.2.0854: xxd cannot show offset as a decimal number
Bram Moolenaar <Bram@vim.org>
parents: 17172
diff changeset
172 let s:test += 1
75ef263d09d6 patch 8.2.0854: xxd cannot show offset as a decimal number
Bram Moolenaar <Bram@vim.org>
parents: 17172
diff changeset
173 exe '%!' . s:xxd_cmd . ' -d %'
75ef263d09d6 patch 8.2.0854: xxd cannot show offset as a decimal number
Bram Moolenaar <Bram@vim.org>
parents: 17172
diff changeset
174 let expected = [
75ef263d09d6 patch 8.2.0854: xxd cannot show offset as a decimal number
Bram Moolenaar <Bram@vim.org>
parents: 17172
diff changeset
175 \ '00000000: 310a 320a 330a 340a 350a 360a 370a 380a 1.2.3.4.5.6.7.8.',
75ef263d09d6 patch 8.2.0854: xxd cannot show offset as a decimal number
Bram Moolenaar <Bram@vim.org>
parents: 17172
diff changeset
176 \ '00000016: 390a 3130 0a31 310a 3132 0a31 330a 3134 9.10.11.12.13.14',
75ef263d09d6 patch 8.2.0854: xxd cannot show offset as a decimal number
Bram Moolenaar <Bram@vim.org>
parents: 17172
diff changeset
177 \ '00000032: 0a31 350a 3136 0a31 370a 3138 0a31 390a .15.16.17.18.19.',
75ef263d09d6 patch 8.2.0854: xxd cannot show offset as a decimal number
Bram Moolenaar <Bram@vim.org>
parents: 17172
diff changeset
178 \ '00000048: 3230 0a32 310a 3232 0a32 330a 3234 0a32 20.21.22.23.24.2',
75ef263d09d6 patch 8.2.0854: xxd cannot show offset as a decimal number
Bram Moolenaar <Bram@vim.org>
parents: 17172
diff changeset
179 \ '00000064: 350a 3236 0a32 370a 3238 0a32 390a 3330 5.26.27.28.29.30',
75ef263d09d6 patch 8.2.0854: xxd cannot show offset as a decimal number
Bram Moolenaar <Bram@vim.org>
parents: 17172
diff changeset
180 \ '00000080: 0a .']
75ef263d09d6 patch 8.2.0854: xxd cannot show offset as a decimal number
Bram Moolenaar <Bram@vim.org>
parents: 17172
diff changeset
181 call assert_equal(expected, getline(1,'$'), s:Mess(s:test))
75ef263d09d6 patch 8.2.0854: xxd cannot show offset as a decimal number
Bram Moolenaar <Bram@vim.org>
parents: 17172
diff changeset
182
75ef263d09d6 patch 8.2.0854: xxd cannot show offset as a decimal number
Bram Moolenaar <Bram@vim.org>
parents: 17172
diff changeset
183 " Test 14: grouping with -d
75ef263d09d6 patch 8.2.0854: xxd cannot show offset as a decimal number
Bram Moolenaar <Bram@vim.org>
parents: 17172
diff changeset
184 let s:test += 1
75ef263d09d6 patch 8.2.0854: xxd cannot show offset as a decimal number
Bram Moolenaar <Bram@vim.org>
parents: 17172
diff changeset
185 let expected = [
75ef263d09d6 patch 8.2.0854: xxd cannot show offset as a decimal number
Bram Moolenaar <Bram@vim.org>
parents: 17172
diff changeset
186 \ '00000000: 310a320a 330a340a 350a360a 370a380a 1.2.3.4.5.6.7.8.',
75ef263d09d6 patch 8.2.0854: xxd cannot show offset as a decimal number
Bram Moolenaar <Bram@vim.org>
parents: 17172
diff changeset
187 \ '00000016: 390a3130 0a31310a 31320a31 330a3134 9.10.11.12.13.14',
75ef263d09d6 patch 8.2.0854: xxd cannot show offset as a decimal number
Bram Moolenaar <Bram@vim.org>
parents: 17172
diff changeset
188 \ '00000032: 0a31350a 31360a31 370a3138 0a31390a .15.16.17.18.19.',
75ef263d09d6 patch 8.2.0854: xxd cannot show offset as a decimal number
Bram Moolenaar <Bram@vim.org>
parents: 17172
diff changeset
189 \ '00000048: 32300a32 310a3232 0a32330a 32340a32 20.21.22.23.24.2',
75ef263d09d6 patch 8.2.0854: xxd cannot show offset as a decimal number
Bram Moolenaar <Bram@vim.org>
parents: 17172
diff changeset
190 \ '00000064: 350a3236 0a32370a 32380a32 390a3330 5.26.27.28.29.30',
75ef263d09d6 patch 8.2.0854: xxd cannot show offset as a decimal number
Bram Moolenaar <Bram@vim.org>
parents: 17172
diff changeset
191 \ '00000080: 0a .']
75ef263d09d6 patch 8.2.0854: xxd cannot show offset as a decimal number
Bram Moolenaar <Bram@vim.org>
parents: 17172
diff changeset
192 for arg in ['-g 4', '-group 4', '-g4']
75ef263d09d6 patch 8.2.0854: xxd cannot show offset as a decimal number
Bram Moolenaar <Bram@vim.org>
parents: 17172
diff changeset
193 exe '%!' . s:xxd_cmd . ' ' . arg . ' -d %'
75ef263d09d6 patch 8.2.0854: xxd cannot show offset as a decimal number
Bram Moolenaar <Bram@vim.org>
parents: 17172
diff changeset
194 call assert_equal(expected, getline(1,'$'), s:Mess(s:test))
75ef263d09d6 patch 8.2.0854: xxd cannot show offset as a decimal number
Bram Moolenaar <Bram@vim.org>
parents: 17172
diff changeset
195 endfor
75ef263d09d6 patch 8.2.0854: xxd cannot show offset as a decimal number
Bram Moolenaar <Bram@vim.org>
parents: 17172
diff changeset
196
75ef263d09d6 patch 8.2.0854: xxd cannot show offset as a decimal number
Bram Moolenaar <Bram@vim.org>
parents: 17172
diff changeset
197 " Test 15: cols with decimal offset: -c 21 -d
75ef263d09d6 patch 8.2.0854: xxd cannot show offset as a decimal number
Bram Moolenaar <Bram@vim.org>
parents: 17172
diff changeset
198 let s:test += 1
75ef263d09d6 patch 8.2.0854: xxd cannot show offset as a decimal number
Bram Moolenaar <Bram@vim.org>
parents: 17172
diff changeset
199 let expected = [
75ef263d09d6 patch 8.2.0854: xxd cannot show offset as a decimal number
Bram Moolenaar <Bram@vim.org>
parents: 17172
diff changeset
200 \ '00000000: 310a 320a 330a 340a 350a 360a 370a 380a 390a 3130 0a 1.2.3.4.5.6.7.8.9.10.',
75ef263d09d6 patch 8.2.0854: xxd cannot show offset as a decimal number
Bram Moolenaar <Bram@vim.org>
parents: 17172
diff changeset
201 \ '00000021: 3131 0a31 320a 3133 0a31 340a 3135 0a31 360a 3137 0a 11.12.13.14.15.16.17.',
75ef263d09d6 patch 8.2.0854: xxd cannot show offset as a decimal number
Bram Moolenaar <Bram@vim.org>
parents: 17172
diff changeset
202 \ '00000042: 3138 0a31 390a 3230 0a32 310a 3232 0a32 330a 3234 0a 18.19.20.21.22.23.24.',
75ef263d09d6 patch 8.2.0854: xxd cannot show offset as a decimal number
Bram Moolenaar <Bram@vim.org>
parents: 17172
diff changeset
203 \ '00000063: 3235 0a32 360a 3237 0a32 380a 3239 0a33 300a 25.26.27.28.29.30.']
75ef263d09d6 patch 8.2.0854: xxd cannot show offset as a decimal number
Bram Moolenaar <Bram@vim.org>
parents: 17172
diff changeset
204 exe '%!' . s:xxd_cmd . ' -c 21 -d %'
75ef263d09d6 patch 8.2.0854: xxd cannot show offset as a decimal number
Bram Moolenaar <Bram@vim.org>
parents: 17172
diff changeset
205 call assert_equal(expected, getline(1,'$'), s:Mess(s:test))
75ef263d09d6 patch 8.2.0854: xxd cannot show offset as a decimal number
Bram Moolenaar <Bram@vim.org>
parents: 17172
diff changeset
206
15627
11879b89bb69 patch 8.1.0821: xxd "usage" output and other arguments not tested
Bram Moolenaar <Bram@vim.org>
parents: 15406
diff changeset
207 " TODO:
11879b89bb69 patch 8.1.0821: xxd "usage" output and other arguments not tested
Bram Moolenaar <Bram@vim.org>
parents: 15406
diff changeset
208 " -o -offset
11879b89bb69 patch 8.1.0821: xxd "usage" output and other arguments not tested
Bram Moolenaar <Bram@vim.org>
parents: 15406
diff changeset
209
13634
2678e38e1de6 patch 8.0.1689: no tests for xxd
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
210 %d
2678e38e1de6 patch 8.0.1689: no tests for xxd
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
211 bw!
2678e38e1de6 patch 8.0.1689: no tests for xxd
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
212 endfunc
15627
11879b89bb69 patch 8.1.0821: xxd "usage" output and other arguments not tested
Bram Moolenaar <Bram@vim.org>
parents: 15406
diff changeset
213
11879b89bb69 patch 8.1.0821: xxd "usage" output and other arguments not tested
Bram Moolenaar <Bram@vim.org>
parents: 15406
diff changeset
214 " Various ways with wrong arguments that trigger the usage output.
11879b89bb69 patch 8.1.0821: xxd "usage" output and other arguments not tested
Bram Moolenaar <Bram@vim.org>
parents: 15406
diff changeset
215 func Test_xxd_usage()
11879b89bb69 patch 8.1.0821: xxd "usage" output and other arguments not tested
Bram Moolenaar <Bram@vim.org>
parents: 15406
diff changeset
216 for arg in ['-c', '-g', '-o', '-s', '-l', '-X', 'one two three']
11879b89bb69 patch 8.1.0821: xxd "usage" output and other arguments not tested
Bram Moolenaar <Bram@vim.org>
parents: 15406
diff changeset
217 new
11879b89bb69 patch 8.1.0821: xxd "usage" output and other arguments not tested
Bram Moolenaar <Bram@vim.org>
parents: 15406
diff changeset
218 exe 'r! ' . s:xxd_cmd . ' ' . arg
11879b89bb69 patch 8.1.0821: xxd "usage" output and other arguments not tested
Bram Moolenaar <Bram@vim.org>
parents: 15406
diff changeset
219 call assert_match("Usage:", join(getline(1, 3)))
11879b89bb69 patch 8.1.0821: xxd "usage" output and other arguments not tested
Bram Moolenaar <Bram@vim.org>
parents: 15406
diff changeset
220 bwipe!
11879b89bb69 patch 8.1.0821: xxd "usage" output and other arguments not tested
Bram Moolenaar <Bram@vim.org>
parents: 15406
diff changeset
221 endfor
11879b89bb69 patch 8.1.0821: xxd "usage" output and other arguments not tested
Bram Moolenaar <Bram@vim.org>
parents: 15406
diff changeset
222 endfunc
11879b89bb69 patch 8.1.0821: xxd "usage" output and other arguments not tested
Bram Moolenaar <Bram@vim.org>
parents: 15406
diff changeset
223
11879b89bb69 patch 8.1.0821: xxd "usage" output and other arguments not tested
Bram Moolenaar <Bram@vim.org>
parents: 15406
diff changeset
224 func Test_xxd_version()
11879b89bb69 patch 8.1.0821: xxd "usage" output and other arguments not tested
Bram Moolenaar <Bram@vim.org>
parents: 15406
diff changeset
225 new
11879b89bb69 patch 8.1.0821: xxd "usage" output and other arguments not tested
Bram Moolenaar <Bram@vim.org>
parents: 15406
diff changeset
226 exe 'r! ' . s:xxd_cmd . ' -v'
11879b89bb69 patch 8.1.0821: xxd "usage" output and other arguments not tested
Bram Moolenaar <Bram@vim.org>
parents: 15406
diff changeset
227 call assert_match("xxd V1.10 .* by Juergen Weigert", join(getline(1, 3)))
11879b89bb69 patch 8.1.0821: xxd "usage" output and other arguments not tested
Bram Moolenaar <Bram@vim.org>
parents: 15406
diff changeset
228 bwipe!
11879b89bb69 patch 8.1.0821: xxd "usage" output and other arguments not tested
Bram Moolenaar <Bram@vim.org>
parents: 15406
diff changeset
229 endfunc