Mercurial > vim
annotate src/testdir/test_xxd.vim @ 13634:2678e38e1de6 v8.0.1689
patch 8.0.1689: no tests for xxd
commit https://github.com/vim/vim/commit/29f9ed20b42e7badea6cfb82fb1fb8d71f33e282
Author: Bram Moolenaar <Bram@vim.org>
Date: Tue Apr 10 19:20:31 2018 +0200
patch 8.0.1689: no tests for xxd
Problem: No tests for xxd.
Solution: Add a test. (Christian Brabandt)
author | Christian Brabandt <cb@256bit.org> |
---|---|
date | Tue, 10 Apr 2018 19:30:07 +0200 |
parents | |
children | b3068807f5df |
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 |
2678e38e1de6
patch 8.0.1689: no tests for xxd
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2 if empty($XXD) || !executable($XXD) |
2678e38e1de6
patch 8.0.1689: no tests for xxd
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3 finish |
2678e38e1de6
patch 8.0.1689: no tests for xxd
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4 endif |
2678e38e1de6
patch 8.0.1689: no tests for xxd
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5 |
2678e38e1de6
patch 8.0.1689: no tests for xxd
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6 func! PrepareBuffer(command) |
2678e38e1de6
patch 8.0.1689: no tests for xxd
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
7 %d |
2678e38e1de6
patch 8.0.1689: no tests for xxd
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
8 call append(0, a:command) |
2678e38e1de6
patch 8.0.1689: no tests for xxd
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
9 $d |
2678e38e1de6
patch 8.0.1689: no tests for xxd
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
10 w XXDfile |
2678e38e1de6
patch 8.0.1689: no tests for xxd
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
11 endfunc |
2678e38e1de6
patch 8.0.1689: no tests for xxd
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
12 |
2678e38e1de6
patch 8.0.1689: no tests for xxd
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
13 func! s:Mess(counter) |
2678e38e1de6
patch 8.0.1689: no tests for xxd
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
14 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
|
15 endfunc |
2678e38e1de6
patch 8.0.1689: no tests for xxd
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
16 |
2678e38e1de6
patch 8.0.1689: no tests for xxd
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
17 func! Test_xxd() |
2678e38e1de6
patch 8.0.1689: no tests for xxd
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
18 new |
2678e38e1de6
patch 8.0.1689: no tests for xxd
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
19 call PrepareBuffer(range(1,30)) |
2678e38e1de6
patch 8.0.1689: no tests for xxd
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
20 " 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
|
21 let s:test = 1 |
2678e38e1de6
patch 8.0.1689: no tests for xxd
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
22 %!$XXD % |
2678e38e1de6
patch 8.0.1689: no tests for xxd
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
23 let expected = [ |
2678e38e1de6
patch 8.0.1689: no tests for xxd
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
24 \ '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
|
25 \ '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
|
26 \ '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
|
27 \ '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
|
28 \ '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
|
29 \ '00000050: 0a .'] |
2678e38e1de6
patch 8.0.1689: no tests for xxd
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
30 call assert_equal(expected, getline(1,'$'), s:Mess(s:test)) |
2678e38e1de6
patch 8.0.1689: no tests for xxd
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
31 " Test 2: reverse the result |
2678e38e1de6
patch 8.0.1689: no tests for xxd
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
32 let s:test += 1 |
2678e38e1de6
patch 8.0.1689: no tests for xxd
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
33 %!$XXD -r |
2678e38e1de6
patch 8.0.1689: no tests for xxd
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
34 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
|
35 |
2678e38e1de6
patch 8.0.1689: no tests for xxd
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
36 " Test 3: Skip the first 30 bytes |
2678e38e1de6
patch 8.0.1689: no tests for xxd
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
37 let s:test += 1 |
2678e38e1de6
patch 8.0.1689: no tests for xxd
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
38 %!$XXD -s 0x30 % |
2678e38e1de6
patch 8.0.1689: no tests for xxd
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
39 call assert_equal(expected[3:], getline(1,'$'), s:Mess(s:test)) |
2678e38e1de6
patch 8.0.1689: no tests for xxd
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
40 |
2678e38e1de6
patch 8.0.1689: no tests for xxd
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
41 " Test 4: Skip the first 30 bytes |
2678e38e1de6
patch 8.0.1689: no tests for xxd
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
42 let s:test += 1 |
2678e38e1de6
patch 8.0.1689: no tests for xxd
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
43 %!$XXD -s -0x31 % |
2678e38e1de6
patch 8.0.1689: no tests for xxd
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
44 call assert_equal(expected[2:], getline(1,'$'), s:Mess(s:test)) |
2678e38e1de6
patch 8.0.1689: no tests for xxd
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
45 |
2678e38e1de6
patch 8.0.1689: no tests for xxd
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
46 " 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
|
47 let s:test += 1 |
2678e38e1de6
patch 8.0.1689: no tests for xxd
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
48 %d |
2678e38e1de6
patch 8.0.1689: no tests for xxd
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
49 0r! $XXD -l 120 -ps -c 20 ../../runtime/doc/xxd.1 |
2678e38e1de6
patch 8.0.1689: no tests for xxd
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
50 $d |
2678e38e1de6
patch 8.0.1689: no tests for xxd
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
51 let expected = [ |
2678e38e1de6
patch 8.0.1689: no tests for xxd
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
52 \ '2e54482058584420312022417567757374203139', |
2678e38e1de6
patch 8.0.1689: no tests for xxd
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
53 \ '39362220224d616e75616c207061676520666f72', |
2678e38e1de6
patch 8.0.1689: no tests for xxd
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
54 \ '20787864220a2e5c220a2e5c222032317374204d', |
2678e38e1de6
patch 8.0.1689: no tests for xxd
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
55 \ '617920313939360a2e5c22204d616e2070616765', |
2678e38e1de6
patch 8.0.1689: no tests for xxd
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
56 \ '20617574686f723a0a2e5c2220202020546f6e79', |
2678e38e1de6
patch 8.0.1689: no tests for xxd
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
57 \ '204e7567656e74203c746f6e79407363746e7567'] |
2678e38e1de6
patch 8.0.1689: no tests for xxd
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
58 call assert_equal(expected, getline(1,'$'), s:Mess(s:test)) |
2678e38e1de6
patch 8.0.1689: no tests for xxd
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
59 " 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
|
60 let s:test += 1 |
2678e38e1de6
patch 8.0.1689: no tests for xxd
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
61 %d |
2678e38e1de6
patch 8.0.1689: no tests for xxd
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
62 0r! $XXD -s 0x36 -l 13 -c 13 ../../runtime/doc/xxd.1 |
2678e38e1de6
patch 8.0.1689: no tests for xxd
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
63 $d |
2678e38e1de6
patch 8.0.1689: no tests for xxd
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
64 call assert_equal('00000036: 3231 7374 204d 6179 2031 3939 36 21st May 1996', getline(1), s:Mess(s:test)) |
2678e38e1de6
patch 8.0.1689: no tests for xxd
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
65 " Test 7: Print C include |
2678e38e1de6
patch 8.0.1689: no tests for xxd
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
66 let s:test += 1 |
2678e38e1de6
patch 8.0.1689: no tests for xxd
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
67 call writefile(['TESTabcd09'], 'XXDfile') |
2678e38e1de6
patch 8.0.1689: no tests for xxd
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
68 %d |
2678e38e1de6
patch 8.0.1689: no tests for xxd
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
69 0r! $XXD -i XXDfile |
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 = ['unsigned char XXDfile[] = {', |
2678e38e1de6
patch 8.0.1689: no tests for xxd
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
72 \ ' 0x54, 0x45, 0x53, 0x54, 0x61, 0x62, 0x63, 0x64, 0x30, 0x39, 0x0a', '};', |
2678e38e1de6
patch 8.0.1689: no tests for xxd
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
73 \ 'unsigned int XXDfile_len = 11;'] |
2678e38e1de6
patch 8.0.1689: no tests for xxd
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
74 call assert_equal(expected, getline(1,'$'), s:Mess(s:test)) |
2678e38e1de6
patch 8.0.1689: no tests for xxd
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
75 " Test 8: Print C include capitalized |
2678e38e1de6
patch 8.0.1689: no tests for xxd
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
76 let s:test += 1 |
2678e38e1de6
patch 8.0.1689: no tests for xxd
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
77 call writefile(['TESTabcd09'], 'XXDfile') |
2678e38e1de6
patch 8.0.1689: no tests for xxd
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
78 %d |
2678e38e1de6
patch 8.0.1689: no tests for xxd
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
79 0r! $XXD -i -C XXDfile |
2678e38e1de6
patch 8.0.1689: no tests for xxd
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
80 $d |
2678e38e1de6
patch 8.0.1689: no tests for xxd
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
81 let expected = ['unsigned char XXDFILE[] = {', |
2678e38e1de6
patch 8.0.1689: no tests for xxd
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
82 \ ' 0x54, 0x45, 0x53, 0x54, 0x61, 0x62, 0x63, 0x64, 0x30, 0x39, 0x0a', '};', |
2678e38e1de6
patch 8.0.1689: no tests for xxd
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
83 \ 'unsigned int XXDFILE_LEN = 11;'] |
2678e38e1de6
patch 8.0.1689: no tests for xxd
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
84 call assert_equal(expected, getline(1,'$'), s:Mess(s:test)) |
2678e38e1de6
patch 8.0.1689: no tests for xxd
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
85 " Test 9: Create a file with containing a single 'A' |
2678e38e1de6
patch 8.0.1689: no tests for xxd
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
86 let s:test += 1 |
2678e38e1de6
patch 8.0.1689: no tests for xxd
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
87 call delete('XXDfile') |
2678e38e1de6
patch 8.0.1689: no tests for xxd
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
88 call system('echo "010000: 41"|'.$XXD.' -r -s -0x10000 > XXDfile') |
2678e38e1de6
patch 8.0.1689: no tests for xxd
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
89 call PrepareBuffer(readfile('XXDfile')[0]) |
2678e38e1de6
patch 8.0.1689: no tests for xxd
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
90 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
|
91 call delete('XXDfile') |
2678e38e1de6
patch 8.0.1689: no tests for xxd
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
92 %d |
2678e38e1de6
patch 8.0.1689: no tests for xxd
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
93 bw! |
2678e38e1de6
patch 8.0.1689: no tests for xxd
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
94 endfunc |