Bram Moolenaar | fa0ad0b | 2017-04-02 15:45:17 +0200 | [diff] [blame] | 1 | " Test :z |
| 2 | |
| 3 | func Test_z() |
| 4 | call setline(1, range(1, 100)) |
| 5 | |
| 6 | let a = execute('20z3') |
| 7 | call assert_equal("\n20\n21\n22", a) |
| 8 | call assert_equal(22, line('.')) |
| 9 | " 'window' should be set to the {count} value. |
| 10 | call assert_equal(3, &window) |
| 11 | |
| 12 | " If there is only one window, then twice the amount of 'scroll' is used. |
| 13 | set scroll=2 |
| 14 | let a = execute('20z') |
| 15 | call assert_equal("\n20\n21\n22\n23", a) |
| 16 | call assert_equal(23, line('.')) |
| 17 | |
| 18 | let a = execute('20z+3') |
Dominique Pelle | 7f2dd1e | 2021-09-04 13:44:01 +0200 | [diff] [blame] | 19 | " FIXME: I would expect the same result as '20z3' since 'help z' |
| 20 | " says: Specifying no mark at all is the same as "+". |
| 21 | " However it " gives "\n21\n22\n23" instead. Bug in Vim or in ":help :z"? |
Bram Moolenaar | fa0ad0b | 2017-04-02 15:45:17 +0200 | [diff] [blame] | 22 | "call assert_equal("\n20\n21\n22", a) |
| 23 | "call assert_equal(22, line('.')) |
| 24 | |
| 25 | let a = execute('20z-3') |
| 26 | call assert_equal("\n18\n19\n20", a) |
| 27 | call assert_equal(20, line('.')) |
| 28 | |
| 29 | let a = execute('20z=3') |
| 30 | call assert_match("^\n18\n19\n-\\+\n20\n-\\+\n21\n22$", a) |
| 31 | call assert_equal(20, line('.')) |
| 32 | |
| 33 | let a = execute('20z^3') |
| 34 | call assert_equal("\n14\n15\n16\n17", a) |
| 35 | call assert_equal(17, line('.')) |
| 36 | |
| 37 | let a = execute('20z.3') |
| 38 | call assert_equal("\n19\n20\n21", a) |
| 39 | call assert_equal(21, line('.')) |
| 40 | |
| 41 | let a = execute('20z#3') |
| 42 | call assert_equal("\n 20 20\n 21 21\n 22 22", a) |
| 43 | call assert_equal(22, line('.')) |
| 44 | |
| 45 | let a = execute('20z#-3') |
| 46 | call assert_equal("\n 18 18\n 19 19\n 20 20", a) |
| 47 | call assert_equal(20, line('.')) |
| 48 | |
| 49 | let a = execute('20z#=3') |
| 50 | call assert_match("^\n 18 18\n 19 19\n-\\+\n 20 20\n-\\+\n 21 21\n 22 22$", a) |
| 51 | call assert_equal(20, line('.')) |
| 52 | |
| 53 | " Test with {count} bigger than the number of lines in buffer. |
| 54 | let a = execute('20z1000') |
| 55 | call assert_match("^\n20\n21\n.*\n99\n100$", a) |
| 56 | call assert_equal(100, line('.')) |
| 57 | |
| 58 | let a = execute('20z-1000') |
Bram Moolenaar | fa0ad0b | 2017-04-02 15:45:17 +0200 | [diff] [blame] | 59 | call assert_equal(20, line('.')) |
| 60 | |
| 61 | let a = execute('20z=1000') |
| 62 | call assert_match("^\n1\n.*\n-\\+\n20\n-\\\+\n.*\n100$", a) |
| 63 | call assert_equal(20, line('.')) |
| 64 | |
Dominique Pelle | 7f2dd1e | 2021-09-04 13:44:01 +0200 | [diff] [blame] | 65 | " Tests with multiple windows. |
| 66 | 5split |
| 67 | call setline(1, range(1, 100)) |
| 68 | " Without a count, the number line is window height - 3. |
| 69 | let a = execute('20z') |
| 70 | call assert_equal("\n20\n21", a) |
| 71 | call assert_equal(21, line('.')) |
| 72 | " If window height - 3 is less than 1, it should be clamped to 1. |
| 73 | resize 2 |
| 74 | let a = execute('20z') |
| 75 | call assert_equal("\n20", a) |
| 76 | call assert_equal(20, line('.')) |
| 77 | |
Bram Moolenaar | fa0ad0b | 2017-04-02 15:45:17 +0200 | [diff] [blame] | 78 | call assert_fails('20z=a', 'E144:') |
| 79 | |
| 80 | set window& scroll& |
| 81 | bw! |
| 82 | endfunc |
| 83 | |
Dominique Pelle | 7f2dd1e | 2021-09-04 13:44:01 +0200 | [diff] [blame] | 84 | " :z! is the same as :z but count uses the Vim window height when not specified. |
| 85 | func Test_z_bang() |
| 86 | 4split |
| 87 | call setline(1, range(1, 20)) |
| 88 | |
| 89 | let a = execute('10z!') |
| 90 | call assert_equal("\n10\n11\n12\n13\n14\n15\n16\n17\n18\n19\n20", a) |
| 91 | |
| 92 | let a = execute('10z!#') |
| 93 | call assert_equal("\n 10 10\n 11 11\n 12 12\n 13 13\n 14 14\n 15 15\n 16 16\n 17 17\n 18 18\n 19 19\n 20 20", a) |
| 94 | |
| 95 | let a = execute('10z!3') |
| 96 | call assert_equal("\n10\n11\n12", a) |
| 97 | |
| 98 | %bwipe! |
| 99 | endfunc |
| 100 | |
Bram Moolenaar | a364cdb | 2017-04-20 21:12:30 +0200 | [diff] [blame] | 101 | func Test_z_overflow() |
Bram Moolenaar | fa0ad0b | 2017-04-02 15:45:17 +0200 | [diff] [blame] | 102 | " This used to access invalid memory as a result of an integer overflow |
| 103 | " and freeze vim. |
| 104 | normal ox |
| 105 | normal Heat |
| 106 | z777777776666666 |
| 107 | ') |
| 108 | endfunc |
Bram Moolenaar | a364cdb | 2017-04-20 21:12:30 +0200 | [diff] [blame] | 109 | |
| 110 | func Test_z_negative_lnum() |
| 111 | new |
| 112 | z^ |
| 113 | call assert_equal(1, line('.')) |
| 114 | bwipe! |
| 115 | endfunc |
Bram Moolenaar | 6d91bcb | 2020-08-12 18:50:36 +0200 | [diff] [blame] | 116 | |
| 117 | " vim: shiftwidth=2 sts=2 expandtab |