annotate src/testdir/test_ex_z.vim @ 19783:546bdeef35f1 v8.2.0448

patch 8.2.0448: various functions not properly tested Commit: https://github.com/vim/vim/commit/0e05de46226eb4e5ea580beefa71831f92d613d3 Author: Bram Moolenaar <Bram@vim.org> Date: Wed Mar 25 22:23:46 2020 +0100 patch 8.2.0448: various functions not properly tested Problem: Various functions not properly tested. Solution: Add more tests, especially for failures. (Yegappan Lakshmanan, closes #5843)
author Bram Moolenaar <Bram@vim.org>
date Wed, 25 Mar 2020 22:30:04 +0100
parents 1074f58e1673
children 08940efa6b4e
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
11303
ef32a5c74515 patch 8.0.0537: illegal memory access with :z and large count
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1 " Test :z
ef32a5c74515 patch 8.0.0537: illegal memory access with :z and large count
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2
ef32a5c74515 patch 8.0.0537: illegal memory access with :z and large count
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3 func Test_z()
ef32a5c74515 patch 8.0.0537: illegal memory access with :z and large count
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4 call setline(1, range(1, 100))
ef32a5c74515 patch 8.0.0537: illegal memory access with :z and large count
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5
ef32a5c74515 patch 8.0.0537: illegal memory access with :z and large count
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6 let a = execute('20z3')
ef32a5c74515 patch 8.0.0537: illegal memory access with :z and large count
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
7 call assert_equal("\n20\n21\n22", a)
ef32a5c74515 patch 8.0.0537: illegal memory access with :z and large count
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
8 call assert_equal(22, line('.'))
ef32a5c74515 patch 8.0.0537: illegal memory access with :z and large count
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
9 " 'window' should be set to the {count} value.
ef32a5c74515 patch 8.0.0537: illegal memory access with :z and large count
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
10 call assert_equal(3, &window)
ef32a5c74515 patch 8.0.0537: illegal memory access with :z and large count
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
11
ef32a5c74515 patch 8.0.0537: illegal memory access with :z and large count
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
12 " If there is only one window, then twice the amount of 'scroll' is used.
ef32a5c74515 patch 8.0.0537: illegal memory access with :z and large count
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
13 set scroll=2
ef32a5c74515 patch 8.0.0537: illegal memory access with :z and large count
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
14 let a = execute('20z')
ef32a5c74515 patch 8.0.0537: illegal memory access with :z and large count
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
15 call assert_equal("\n20\n21\n22\n23", a)
ef32a5c74515 patch 8.0.0537: illegal memory access with :z and large count
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
16 call assert_equal(23, line('.'))
ef32a5c74515 patch 8.0.0537: illegal memory access with :z and large count
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
17
ef32a5c74515 patch 8.0.0537: illegal memory access with :z and large count
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
18 let a = execute('20z+3')
ef32a5c74515 patch 8.0.0537: illegal memory access with :z and large count
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
19 " FIXME: I would expect the same result as '20z3' but it
ef32a5c74515 patch 8.0.0537: illegal memory access with :z and large count
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
20 " gives "\n21\n22\n23" instead. Bug in Vim or in ":help :z"?
ef32a5c74515 patch 8.0.0537: illegal memory access with :z and large count
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
21 "call assert_equal("\n20\n21\n22", a)
ef32a5c74515 patch 8.0.0537: illegal memory access with :z and large count
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
22 "call assert_equal(22, line('.'))
ef32a5c74515 patch 8.0.0537: illegal memory access with :z and large count
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
23
ef32a5c74515 patch 8.0.0537: illegal memory access with :z and large count
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
24 let a = execute('20z-3')
ef32a5c74515 patch 8.0.0537: illegal memory access with :z and large count
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
25 call assert_equal("\n18\n19\n20", a)
ef32a5c74515 patch 8.0.0537: illegal memory access with :z and large count
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
26 call assert_equal(20, line('.'))
ef32a5c74515 patch 8.0.0537: illegal memory access with :z and large count
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
27
ef32a5c74515 patch 8.0.0537: illegal memory access with :z and large count
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
28 let a = execute('20z=3')
ef32a5c74515 patch 8.0.0537: illegal memory access with :z and large count
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
29 call assert_match("^\n18\n19\n-\\+\n20\n-\\+\n21\n22$", a)
ef32a5c74515 patch 8.0.0537: illegal memory access with :z and large count
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
30 call assert_equal(20, line('.'))
ef32a5c74515 patch 8.0.0537: illegal memory access with :z and large count
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
31
ef32a5c74515 patch 8.0.0537: illegal memory access with :z and large count
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
32 let a = execute('20z^3')
ef32a5c74515 patch 8.0.0537: illegal memory access with :z and large count
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
33 call assert_equal("\n14\n15\n16\n17", a)
ef32a5c74515 patch 8.0.0537: illegal memory access with :z and large count
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
34 call assert_equal(17, line('.'))
ef32a5c74515 patch 8.0.0537: illegal memory access with :z and large count
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
35
ef32a5c74515 patch 8.0.0537: illegal memory access with :z and large count
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
36 let a = execute('20z.3')
ef32a5c74515 patch 8.0.0537: illegal memory access with :z and large count
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
37 call assert_equal("\n19\n20\n21", a)
ef32a5c74515 patch 8.0.0537: illegal memory access with :z and large count
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
38 call assert_equal(21, line('.'))
ef32a5c74515 patch 8.0.0537: illegal memory access with :z and large count
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
39
ef32a5c74515 patch 8.0.0537: illegal memory access with :z and large count
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
40 let a = execute('20z#3')
ef32a5c74515 patch 8.0.0537: illegal memory access with :z and large count
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
41 call assert_equal("\n 20 20\n 21 21\n 22 22", a)
ef32a5c74515 patch 8.0.0537: illegal memory access with :z and large count
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
42 call assert_equal(22, line('.'))
ef32a5c74515 patch 8.0.0537: illegal memory access with :z and large count
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
43
ef32a5c74515 patch 8.0.0537: illegal memory access with :z and large count
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
44 let a = execute('20z#-3')
ef32a5c74515 patch 8.0.0537: illegal memory access with :z and large count
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
45 call assert_equal("\n 18 18\n 19 19\n 20 20", a)
ef32a5c74515 patch 8.0.0537: illegal memory access with :z and large count
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
46 call assert_equal(20, line('.'))
ef32a5c74515 patch 8.0.0537: illegal memory access with :z and large count
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
47
ef32a5c74515 patch 8.0.0537: illegal memory access with :z and large count
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
48 let a = execute('20z#=3')
ef32a5c74515 patch 8.0.0537: illegal memory access with :z and large count
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
49 call assert_match("^\n 18 18\n 19 19\n-\\+\n 20 20\n-\\+\n 21 21\n 22 22$", a)
ef32a5c74515 patch 8.0.0537: illegal memory access with :z and large count
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
50 call assert_equal(20, line('.'))
ef32a5c74515 patch 8.0.0537: illegal memory access with :z and large count
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
51
ef32a5c74515 patch 8.0.0537: illegal memory access with :z and large count
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
52 " Test with {count} bigger than the number of lines in buffer.
ef32a5c74515 patch 8.0.0537: illegal memory access with :z and large count
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
53 let a = execute('20z1000')
ef32a5c74515 patch 8.0.0537: illegal memory access with :z and large count
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
54 call assert_match("^\n20\n21\n.*\n99\n100$", a)
ef32a5c74515 patch 8.0.0537: illegal memory access with :z and large count
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
55 call assert_equal(100, line('.'))
ef32a5c74515 patch 8.0.0537: illegal memory access with :z and large count
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
56
ef32a5c74515 patch 8.0.0537: illegal memory access with :z and large count
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
57 let a = execute('20z-1000')
ef32a5c74515 patch 8.0.0537: illegal memory access with :z and large count
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
58 call assert_match("^\n1\n2\n.*\n19\n20$", a)
ef32a5c74515 patch 8.0.0537: illegal memory access with :z and large count
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
59 call assert_equal(20, line('.'))
ef32a5c74515 patch 8.0.0537: illegal memory access with :z and large count
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
60
ef32a5c74515 patch 8.0.0537: illegal memory access with :z and large count
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
61 let a = execute('20z=1000')
ef32a5c74515 patch 8.0.0537: illegal memory access with :z and large count
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
62 call assert_match("^\n1\n.*\n-\\+\n20\n-\\\+\n.*\n100$", a)
ef32a5c74515 patch 8.0.0537: illegal memory access with :z and large count
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
63 call assert_equal(20, line('.'))
ef32a5c74515 patch 8.0.0537: illegal memory access with :z and large count
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
64
ef32a5c74515 patch 8.0.0537: illegal memory access with :z and large count
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
65 call assert_fails('20z=a', 'E144:')
ef32a5c74515 patch 8.0.0537: illegal memory access with :z and large count
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
66
ef32a5c74515 patch 8.0.0537: illegal memory access with :z and large count
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
67 set window& scroll&
ef32a5c74515 patch 8.0.0537: illegal memory access with :z and large count
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
68 bw!
ef32a5c74515 patch 8.0.0537: illegal memory access with :z and large count
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
69 endfunc
ef32a5c74515 patch 8.0.0537: illegal memory access with :z and large count
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
70
11372
1074f58e1673 patch 8.0.0571: negative line number when using :z^ in an empty buffer
Christian Brabandt <cb@256bit.org>
parents: 11303
diff changeset
71 func Test_z_overflow()
11303
ef32a5c74515 patch 8.0.0537: illegal memory access with :z and large count
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
72 " This used to access invalid memory as a result of an integer overflow
ef32a5c74515 patch 8.0.0537: illegal memory access with :z and large count
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
73 " and freeze vim.
ef32a5c74515 patch 8.0.0537: illegal memory access with :z and large count
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
74 normal ox
ef32a5c74515 patch 8.0.0537: illegal memory access with :z and large count
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
75 normal Heat
ef32a5c74515 patch 8.0.0537: illegal memory access with :z and large count
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
76 z777777776666666
ef32a5c74515 patch 8.0.0537: illegal memory access with :z and large count
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
77 ')
ef32a5c74515 patch 8.0.0537: illegal memory access with :z and large count
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
78 endfunc
11372
1074f58e1673 patch 8.0.0571: negative line number when using :z^ in an empty buffer
Christian Brabandt <cb@256bit.org>
parents: 11303
diff changeset
79
1074f58e1673 patch 8.0.0571: negative line number when using :z^ in an empty buffer
Christian Brabandt <cb@256bit.org>
parents: 11303
diff changeset
80 func Test_z_negative_lnum()
1074f58e1673 patch 8.0.0571: negative line number when using :z^ in an empty buffer
Christian Brabandt <cb@256bit.org>
parents: 11303
diff changeset
81 new
1074f58e1673 patch 8.0.0571: negative line number when using :z^ in an empty buffer
Christian Brabandt <cb@256bit.org>
parents: 11303
diff changeset
82 z^
1074f58e1673 patch 8.0.0571: negative line number when using :z^ in an empty buffer
Christian Brabandt <cb@256bit.org>
parents: 11303
diff changeset
83 call assert_equal(1, line('.'))
1074f58e1673 patch 8.0.0571: negative line number when using :z^ in an empty buffer
Christian Brabandt <cb@256bit.org>
parents: 11303
diff changeset
84 bwipe!
1074f58e1673 patch 8.0.0571: negative line number when using :z^ in an empty buffer
Christian Brabandt <cb@256bit.org>
parents: 11303
diff changeset
85 endfunc