Bram Moolenaar | 00b24be | 2016-07-23 22:04:47 +0200 | [diff] [blame] | 1 | " Test for textobjects |
| 2 | |
Bram Moolenaar | b46fecd | 2019-06-15 17:58:09 +0200 | [diff] [blame] | 3 | source check.vim |
Bram Moolenaar | 00b24be | 2016-07-23 22:04:47 +0200 | [diff] [blame] | 4 | |
Bram Moolenaar | c5e2b04 | 2017-06-05 16:37:07 +0200 | [diff] [blame] | 5 | func CpoM(line, useM, expected) |
Bram Moolenaar | 00b24be | 2016-07-23 22:04:47 +0200 | [diff] [blame] | 6 | new |
| 7 | |
| 8 | if a:useM |
| 9 | set cpoptions+=M |
| 10 | else |
| 11 | set cpoptions-=M |
| 12 | endif |
| 13 | |
| 14 | call setline(1, a:line) |
| 15 | |
| 16 | call setreg('"', '') |
| 17 | normal! ggfrmavi)y |
| 18 | call assert_equal(getreg('"'), a:expected[0]) |
| 19 | |
| 20 | call setreg('"', '') |
| 21 | normal! `afbmavi)y |
| 22 | call assert_equal(getreg('"'), a:expected[1]) |
| 23 | |
| 24 | call setreg('"', '') |
| 25 | normal! `afgmavi)y |
| 26 | call assert_equal(getreg('"'), a:expected[2]) |
| 27 | |
| 28 | q! |
Bram Moolenaar | c5e2b04 | 2017-06-05 16:37:07 +0200 | [diff] [blame] | 29 | endfunc |
Bram Moolenaar | 00b24be | 2016-07-23 22:04:47 +0200 | [diff] [blame] | 30 | |
Bram Moolenaar | c5e2b04 | 2017-06-05 16:37:07 +0200 | [diff] [blame] | 31 | func Test_inner_block_without_cpo_M() |
Bram Moolenaar | 00b24be | 2016-07-23 22:04:47 +0200 | [diff] [blame] | 32 | call CpoM('(red \(blue) green)', 0, ['red \(blue', 'red \(blue', '']) |
Bram Moolenaar | c5e2b04 | 2017-06-05 16:37:07 +0200 | [diff] [blame] | 33 | endfunc |
Bram Moolenaar | 00b24be | 2016-07-23 22:04:47 +0200 | [diff] [blame] | 34 | |
Bram Moolenaar | c5e2b04 | 2017-06-05 16:37:07 +0200 | [diff] [blame] | 35 | func Test_inner_block_with_cpo_M_left_backslash() |
Bram Moolenaar | 00b24be | 2016-07-23 22:04:47 +0200 | [diff] [blame] | 36 | call CpoM('(red \(blue) green)', 1, ['red \(blue) green', 'blue', 'red \(blue) green']) |
Bram Moolenaar | c5e2b04 | 2017-06-05 16:37:07 +0200 | [diff] [blame] | 37 | endfunc |
Bram Moolenaar | 00b24be | 2016-07-23 22:04:47 +0200 | [diff] [blame] | 38 | |
Bram Moolenaar | c5e2b04 | 2017-06-05 16:37:07 +0200 | [diff] [blame] | 39 | func Test_inner_block_with_cpo_M_right_backslash() |
Bram Moolenaar | 00b24be | 2016-07-23 22:04:47 +0200 | [diff] [blame] | 40 | call CpoM('(red (blue\) green)', 1, ['red (blue\) green', 'blue\', 'red (blue\) green']) |
Bram Moolenaar | c5e2b04 | 2017-06-05 16:37:07 +0200 | [diff] [blame] | 41 | endfunc |
| 42 | |
LemonBoy | 53737b5 | 2022-05-24 11:49:31 +0100 | [diff] [blame] | 43 | func Test_inner_block_single_char() |
| 44 | new |
| 45 | call setline(1, "(a)") |
| 46 | |
| 47 | set selection=inclusive |
| 48 | let @" = '' |
| 49 | call assert_nobeep('norm! 0faviby') |
| 50 | call assert_equal('a', @") |
| 51 | |
| 52 | set selection=exclusive |
| 53 | let @" = '' |
| 54 | call assert_nobeep('norm! 0faviby') |
| 55 | call assert_equal('a', @") |
| 56 | |
| 57 | set selection& |
| 58 | bwipe! |
| 59 | endfunc |
| 60 | |
Bram Moolenaar | c5e2b04 | 2017-06-05 16:37:07 +0200 | [diff] [blame] | 61 | func Test_quote_selection_selection_exclusive() |
| 62 | new |
| 63 | call setline(1, "a 'bcde' f") |
| 64 | set selection=exclusive |
Bram Moolenaar | 94d9f4f | 2019-11-21 20:55:26 +0100 | [diff] [blame] | 65 | |
Bram Moolenaar | c5e2b04 | 2017-06-05 16:37:07 +0200 | [diff] [blame] | 66 | exe "norm! fdvhi'y" |
| 67 | call assert_equal('bcde', @") |
Bram Moolenaar | 94d9f4f | 2019-11-21 20:55:26 +0100 | [diff] [blame] | 68 | |
LemonBoy | 53737b5 | 2022-05-24 11:49:31 +0100 | [diff] [blame] | 69 | let @" = 'dummy' |
Bram Moolenaar | 7170b29 | 2019-11-17 17:32:28 +0100 | [diff] [blame] | 70 | exe "norm! $gevi'y" |
| 71 | call assert_equal('bcde', @") |
Bram Moolenaar | 94d9f4f | 2019-11-21 20:55:26 +0100 | [diff] [blame] | 72 | |
LemonBoy | 53737b5 | 2022-05-24 11:49:31 +0100 | [diff] [blame] | 73 | let @" = 'dummy' |
Bram Moolenaar | 94d9f4f | 2019-11-21 20:55:26 +0100 | [diff] [blame] | 74 | exe "norm! 0fbhvi'y" |
| 75 | call assert_equal('bcde', @") |
| 76 | |
Bram Moolenaar | c5e2b04 | 2017-06-05 16:37:07 +0200 | [diff] [blame] | 77 | set selection&vim |
| 78 | bw! |
| 79 | endfunc |
Bram Moolenaar | db51007 | 2017-09-28 21:52:17 +0200 | [diff] [blame] | 80 | |
Bram Moolenaar | 55d3bdb | 2019-02-22 15:04:17 +0100 | [diff] [blame] | 81 | func Test_quote_selection_selection_exclusive_abort() |
| 82 | new |
| 83 | set selection=exclusive |
| 84 | call setline(1, "'abzzc'") |
| 85 | let exp_curs = [0, 1, 6, 0] |
| 86 | call cursor(1,1) |
| 87 | exe 'norm! fcdvi"' |
| 88 | " make sure to end visual mode to have a clear state |
| 89 | exe "norm! \<esc>" |
| 90 | call assert_equal(exp_curs, getpos('.')) |
| 91 | call cursor(1,1) |
| 92 | exe 'norm! fcvi"' |
| 93 | exe "norm! \<esc>" |
| 94 | call assert_equal(exp_curs, getpos('.')) |
| 95 | call cursor(1,2) |
| 96 | exe 'norm! vfcoi"' |
| 97 | exe "norm! \<esc>" |
| 98 | let exp_curs = [0, 1, 2, 0] |
| 99 | let exp_visu = [0, 1, 7, 0] |
| 100 | call assert_equal(exp_curs, getpos('.')) |
| 101 | call assert_equal(exp_visu, getpos("'>")) |
| 102 | set selection&vim |
| 103 | bw! |
| 104 | endfunc |
| 105 | |
Bram Moolenaar | db51007 | 2017-09-28 21:52:17 +0200 | [diff] [blame] | 106 | " Tests for string and html text objects |
| 107 | func Test_string_html_objects() |
Bram Moolenaar | db51007 | 2017-09-28 21:52:17 +0200 | [diff] [blame] | 108 | |
Dominique Pelle | af631f6 | 2021-09-03 16:50:16 +0200 | [diff] [blame] | 109 | for e in ['utf-8', 'latin1', 'cp932'] |
| 110 | enew! |
| 111 | exe 'set enc=' .. e |
Bram Moolenaar | db51007 | 2017-09-28 21:52:17 +0200 | [diff] [blame] | 112 | |
Dominique Pelle | af631f6 | 2021-09-03 16:50:16 +0200 | [diff] [blame] | 113 | let t = '"wo\"rd\\" foo' |
| 114 | put =t |
| 115 | normal! da" |
| 116 | call assert_equal('foo', getline('.'), e) |
Bram Moolenaar | db51007 | 2017-09-28 21:52:17 +0200 | [diff] [blame] | 117 | |
Dominique Pelle | af631f6 | 2021-09-03 16:50:16 +0200 | [diff] [blame] | 118 | let t = "'foo' 'bar' 'piep'" |
| 119 | put =t |
| 120 | normal! 0va'a'rx |
| 121 | call assert_equal("xxxxxxxxxxxx'piep'", getline('.'), e) |
Bram Moolenaar | db51007 | 2017-09-28 21:52:17 +0200 | [diff] [blame] | 122 | |
Dominique Pelle | af631f6 | 2021-09-03 16:50:16 +0200 | [diff] [blame] | 123 | let t = "bla bla `quote` blah" |
| 124 | put =t |
| 125 | normal! 02f`da` |
| 126 | call assert_equal("bla bla blah", getline('.'), e) |
Bram Moolenaar | db51007 | 2017-09-28 21:52:17 +0200 | [diff] [blame] | 127 | |
Dominique Pelle | af631f6 | 2021-09-03 16:50:16 +0200 | [diff] [blame] | 128 | let t = 'out " in "noXno"' |
| 129 | put =t |
| 130 | normal! 0fXdi" |
| 131 | call assert_equal('out " in ""', getline('.'), e) |
Bram Moolenaar | db51007 | 2017-09-28 21:52:17 +0200 | [diff] [blame] | 132 | |
Dominique Pelle | af631f6 | 2021-09-03 16:50:16 +0200 | [diff] [blame] | 133 | let t = "\"'\" 'blah' rep 'buh'" |
| 134 | put =t |
| 135 | normal! 03f'vi'ry |
| 136 | call assert_equal("\"'\" 'blah'yyyyy'buh'", getline('.'), e) |
Bram Moolenaar | db51007 | 2017-09-28 21:52:17 +0200 | [diff] [blame] | 137 | |
Dominique Pelle | af631f6 | 2021-09-03 16:50:16 +0200 | [diff] [blame] | 138 | set quoteescape=+*- |
| 139 | let t = "bla `s*`d-`+++`l**` b`la" |
| 140 | put =t |
| 141 | normal! di` |
| 142 | call assert_equal("bla `` b`la", getline('.'), e) |
Bram Moolenaar | db51007 | 2017-09-28 21:52:17 +0200 | [diff] [blame] | 143 | |
Dominique Pelle | af631f6 | 2021-09-03 16:50:16 +0200 | [diff] [blame] | 144 | let t = 'voo "nah" sdf " asdf" sdf " sdf" sd' |
| 145 | put =t |
| 146 | normal! $F"va"oha"i"rz |
| 147 | call assert_equal('voo "zzzzzzzzzzzzzzzzzzzzzzzzzzzzsd', getline('.'), e) |
Bram Moolenaar | db51007 | 2017-09-28 21:52:17 +0200 | [diff] [blame] | 148 | |
Dominique Pelle | af631f6 | 2021-09-03 16:50:16 +0200 | [diff] [blame] | 149 | let t = "-<b>asdf<i>Xasdf</i>asdf</b>-" |
| 150 | put =t |
| 151 | normal! fXdit |
| 152 | call assert_equal('-<b>asdf<i></i>asdf</b>-', getline('.'), e) |
Bram Moolenaar | db51007 | 2017-09-28 21:52:17 +0200 | [diff] [blame] | 153 | |
Dominique Pelle | af631f6 | 2021-09-03 16:50:16 +0200 | [diff] [blame] | 154 | let t = "-<b>asdX<i>a<i />sdf</i>asdf</b>-" |
| 155 | put =t |
| 156 | normal! 0fXdit |
| 157 | call assert_equal('-<b></b>-', getline('.'), e) |
Bram Moolenaar | db51007 | 2017-09-28 21:52:17 +0200 | [diff] [blame] | 158 | |
Dominique Pelle | af631f6 | 2021-09-03 16:50:16 +0200 | [diff] [blame] | 159 | let t = "-<b>asdf<i>Xasdf</i>asdf</b>-" |
| 160 | put =t |
| 161 | normal! fXdat |
| 162 | call assert_equal('-<b>asdfasdf</b>-', getline('.'), e) |
Bram Moolenaar | db51007 | 2017-09-28 21:52:17 +0200 | [diff] [blame] | 163 | |
Dominique Pelle | af631f6 | 2021-09-03 16:50:16 +0200 | [diff] [blame] | 164 | let t = "-<b>asdX<i>as<b />df</i>asdf</b>-" |
| 165 | put =t |
| 166 | normal! 0fXdat |
| 167 | call assert_equal('--', getline('.'), e) |
Bram Moolenaar | db51007 | 2017-09-28 21:52:17 +0200 | [diff] [blame] | 168 | |
Dominique Pelle | af631f6 | 2021-09-03 16:50:16 +0200 | [diff] [blame] | 169 | let t = "-<b>\ninnertext object\n</b>" |
| 170 | put =t |
| 171 | normal! dit |
| 172 | call assert_equal('-<b></b>', getline('.'), e) |
Bram Moolenaar | 224a5f1 | 2020-04-28 20:29:07 +0200 | [diff] [blame] | 173 | |
Dominique Pelle | af631f6 | 2021-09-03 16:50:16 +0200 | [diff] [blame] | 174 | " copy the tag block from leading indentation before the start tag |
| 175 | let t = " <b>\ntext\n</b>" |
| 176 | $put =t |
| 177 | normal! 2kvaty |
| 178 | call assert_equal("<b>\ntext\n</b>", @", e) |
Bram Moolenaar | 224a5f1 | 2020-04-28 20:29:07 +0200 | [diff] [blame] | 179 | |
Dominique Pelle | af631f6 | 2021-09-03 16:50:16 +0200 | [diff] [blame] | 180 | " copy the tag block from the end tag |
| 181 | let t = "<title>\nwelcome\n</title>" |
| 182 | $put =t |
| 183 | normal! $vaty |
| 184 | call assert_equal("<title>\nwelcome\n</title>", @", e) |
Bram Moolenaar | 224a5f1 | 2020-04-28 20:29:07 +0200 | [diff] [blame] | 185 | |
Dominique Pelle | af631f6 | 2021-09-03 16:50:16 +0200 | [diff] [blame] | 186 | " copy the outer tag block from a tag without an end tag |
| 187 | let t = "<html>\n<title>welcome\n</html>" |
| 188 | $put =t |
| 189 | normal! k$vaty |
| 190 | call assert_equal("<html>\n<title>welcome\n</html>", @", e) |
Bram Moolenaar | a604ccc | 2020-10-15 21:23:28 +0200 | [diff] [blame] | 191 | |
Dominique Pelle | af631f6 | 2021-09-03 16:50:16 +0200 | [diff] [blame] | 192 | " nested tag that has < in a different line from > |
| 193 | let t = "<div><div\n></div></div>" |
| 194 | $put =t |
| 195 | normal! k0vaty |
| 196 | call assert_equal("<div><div\n></div></div>", @", e) |
Bram Moolenaar | a604ccc | 2020-10-15 21:23:28 +0200 | [diff] [blame] | 197 | |
Dominique Pelle | af631f6 | 2021-09-03 16:50:16 +0200 | [diff] [blame] | 198 | " nested tag with attribute that has < in a different line from > |
| 199 | let t = "<div><div\nattr=\"attr\"\n></div></div>" |
| 200 | $put =t |
| 201 | normal! 2k0vaty |
| 202 | call assert_equal("<div><div\nattr=\"attr\"\n></div></div>", @", e) |
| 203 | |
| 204 | set quoteescape& |
Bram Moolenaar | 53a7028 | 2022-05-09 13:15:07 +0100 | [diff] [blame] | 205 | |
| 206 | " this was going beyond the end of the line |
| 207 | %del |
| 208 | sil! norm i"\ |
| 209 | sil! norm i"\ |
| 210 | sil! norm i"\ |
| 211 | call assert_equal('"\', getline(1)) |
| 212 | |
| 213 | bwipe! |
Dominique Pelle | af631f6 | 2021-09-03 16:50:16 +0200 | [diff] [blame] | 214 | endfor |
| 215 | |
| 216 | set enc=utf-8 |
Bram Moolenaar | db51007 | 2017-09-28 21:52:17 +0200 | [diff] [blame] | 217 | endfunc |
| 218 | |
Bram Moolenaar | b476cb7 | 2018-08-16 21:37:50 +0200 | [diff] [blame] | 219 | func Test_empty_html_tag() |
| 220 | new |
| 221 | call setline(1, '<div></div>') |
| 222 | normal 0citxxx |
| 223 | call assert_equal('<div>xxx</div>', getline(1)) |
| 224 | |
| 225 | call setline(1, '<div></div>') |
| 226 | normal 0f<cityyy |
| 227 | call assert_equal('<div>yyy</div>', getline(1)) |
| 228 | |
| 229 | call setline(1, '<div></div>') |
| 230 | normal 0f<vitsaaa |
| 231 | call assert_equal('aaa', getline(1)) |
| 232 | |
Dominique Pelle | 923dce2 | 2021-11-21 11:36:04 +0000 | [diff] [blame] | 233 | " selecting a tag block in a non-empty blank line should fail |
Bram Moolenaar | 224a5f1 | 2020-04-28 20:29:07 +0200 | [diff] [blame] | 234 | call setline(1, ' ') |
| 235 | call assert_beeps('normal $vaty') |
| 236 | |
Bram Moolenaar | b476cb7 | 2018-08-16 21:37:50 +0200 | [diff] [blame] | 237 | bwipe! |
| 238 | endfunc |
| 239 | |
Bram Moolenaar | db51007 | 2017-09-28 21:52:17 +0200 | [diff] [blame] | 240 | " Tests for match() and matchstr() |
| 241 | func Test_match() |
| 242 | call assert_equal("b", matchstr("abcd", ".", 0, 2)) |
| 243 | call assert_equal("bc", matchstr("abcd", "..", 0, 2)) |
| 244 | call assert_equal("c", matchstr("abcd", ".", 2, 0)) |
| 245 | call assert_equal("a", matchstr("abcd", ".", 0, -1)) |
| 246 | call assert_equal(-1, match("abcd", ".", 0, 5)) |
Bram Moolenaar | 9d48956 | 2020-07-30 20:08:50 +0200 | [diff] [blame] | 247 | call assert_equal(0, match("abcd", ".", 0, -1)) |
| 248 | call assert_equal(0, match('abc', '.', 0, 1)) |
| 249 | call assert_equal(1, match('abc', '.', 0, 2)) |
| 250 | call assert_equal(2, match('abc', '.', 0, 3)) |
Bram Moolenaar | db51007 | 2017-09-28 21:52:17 +0200 | [diff] [blame] | 251 | call assert_equal(-1, match('abc', '.', 0, 4)) |
Bram Moolenaar | 9d48956 | 2020-07-30 20:08:50 +0200 | [diff] [blame] | 252 | call assert_equal(1, match('abc', '.', 1, 1)) |
| 253 | call assert_equal(2, match('abc', '.', 2, 1)) |
Bram Moolenaar | db51007 | 2017-09-28 21:52:17 +0200 | [diff] [blame] | 254 | call assert_equal(-1, match('abc', '.', 3, 1)) |
Bram Moolenaar | 9d48956 | 2020-07-30 20:08:50 +0200 | [diff] [blame] | 255 | call assert_equal(3, match('abc', '$', 0, 1)) |
Bram Moolenaar | db51007 | 2017-09-28 21:52:17 +0200 | [diff] [blame] | 256 | call assert_equal(-1, match('abc', '$', 0, 2)) |
Bram Moolenaar | 9d48956 | 2020-07-30 20:08:50 +0200 | [diff] [blame] | 257 | call assert_equal(3, match('abc', '$', 1, 1)) |
| 258 | call assert_equal(3, match('abc', '$', 2, 1)) |
| 259 | call assert_equal(3, match('abc', '$', 3, 1)) |
Bram Moolenaar | db51007 | 2017-09-28 21:52:17 +0200 | [diff] [blame] | 260 | call assert_equal(-1, match('abc', '$', 4, 1)) |
Bram Moolenaar | 9d48956 | 2020-07-30 20:08:50 +0200 | [diff] [blame] | 261 | call assert_equal(0, match('abc', '\zs', 0, 1)) |
| 262 | call assert_equal(1, match('abc', '\zs', 0, 2)) |
| 263 | call assert_equal(2, match('abc', '\zs', 0, 3)) |
| 264 | call assert_equal(3, match('abc', '\zs', 0, 4)) |
Bram Moolenaar | db51007 | 2017-09-28 21:52:17 +0200 | [diff] [blame] | 265 | call assert_equal(-1, match('abc', '\zs', 0, 5)) |
Bram Moolenaar | 9d48956 | 2020-07-30 20:08:50 +0200 | [diff] [blame] | 266 | call assert_equal(1, match('abc', '\zs', 1, 1)) |
| 267 | call assert_equal(2, match('abc', '\zs', 2, 1)) |
| 268 | call assert_equal(3, match('abc', '\zs', 3, 1)) |
Bram Moolenaar | db51007 | 2017-09-28 21:52:17 +0200 | [diff] [blame] | 269 | call assert_equal(-1, match('abc', '\zs', 4, 1)) |
| 270 | endfunc |
Bram Moolenaar | 82846a0 | 2018-02-09 18:09:54 +0100 | [diff] [blame] | 271 | |
| 272 | " This was causing an illegal memory access |
| 273 | func Test_inner_tag() |
| 274 | new |
| 275 | norm ixxx |
| 276 | call feedkeys("v", 'xt') |
| 277 | insert |
| 278 | x |
| 279 | x |
| 280 | . |
| 281 | norm it |
| 282 | q! |
| 283 | endfunc |
Bram Moolenaar | 8516071 | 2018-06-19 18:27:41 +0200 | [diff] [blame] | 284 | |
| 285 | func Test_sentence() |
| 286 | enew! |
| 287 | call setline(1, 'A sentence. A sentence? A sentence!') |
| 288 | |
| 289 | normal yis |
| 290 | call assert_equal('A sentence.', @") |
| 291 | normal yas |
| 292 | call assert_equal('A sentence. ', @") |
| 293 | |
| 294 | normal ) |
| 295 | |
| 296 | normal yis |
| 297 | call assert_equal('A sentence?', @") |
| 298 | normal yas |
| 299 | call assert_equal('A sentence? ', @") |
| 300 | |
| 301 | normal ) |
| 302 | |
| 303 | normal yis |
| 304 | call assert_equal('A sentence!', @") |
| 305 | normal yas |
| 306 | call assert_equal(' A sentence!', @") |
| 307 | |
| 308 | normal 0 |
| 309 | normal 2yis |
| 310 | call assert_equal('A sentence. ', @") |
| 311 | normal 3yis |
| 312 | call assert_equal('A sentence. A sentence?', @") |
| 313 | normal 2yas |
| 314 | call assert_equal('A sentence. A sentence? ', @") |
| 315 | |
| 316 | %delete _ |
| 317 | endfunc |
| 318 | |
| 319 | func Test_sentence_with_quotes() |
| 320 | enew! |
| 321 | call setline(1, 'A "sentence." A sentence.') |
| 322 | |
| 323 | normal yis |
| 324 | call assert_equal('A "sentence."', @") |
| 325 | normal yas |
| 326 | call assert_equal('A "sentence." ', @") |
| 327 | |
| 328 | normal ) |
| 329 | |
| 330 | normal yis |
| 331 | call assert_equal('A sentence.', @") |
| 332 | normal yas |
| 333 | call assert_equal(' A sentence.', @") |
| 334 | |
| 335 | %delete _ |
| 336 | endfunc |
| 337 | |
Bram Moolenaar | 1e11536 | 2019-01-09 23:01:02 +0100 | [diff] [blame] | 338 | func Test_sentence_with_cursor_on_delimiter() |
Bram Moolenaar | 8516071 | 2018-06-19 18:27:41 +0200 | [diff] [blame] | 339 | enew! |
| 340 | call setline(1, "A '([sentence.])' A sentence.") |
| 341 | |
| 342 | normal! 15|yis |
| 343 | call assert_equal("A '([sentence.])'", @") |
| 344 | normal! 15|yas |
| 345 | call assert_equal("A '([sentence.])' ", @") |
| 346 | |
| 347 | normal! 16|yis |
| 348 | call assert_equal("A '([sentence.])'", @") |
| 349 | normal! 16|yas |
| 350 | call assert_equal("A '([sentence.])' ", @") |
| 351 | |
| 352 | normal! 17|yis |
| 353 | call assert_equal("A '([sentence.])'", @") |
| 354 | normal! 17|yas |
| 355 | call assert_equal("A '([sentence.])' ", @") |
| 356 | |
Bram Moolenaar | 2f03e5a | 2020-06-18 15:33:25 +0200 | [diff] [blame] | 357 | " don't get stuck on a quote at the start of a sentence |
| 358 | %delete _ |
| 359 | call setline(1, ['A sentence.', '"A sentence"?', 'A sentence!']) |
| 360 | normal gg)) |
| 361 | call assert_equal(3, getcurpos()[1]) |
| 362 | |
| 363 | %delete _ |
| 364 | call setline(1, ['A sentence.', "'A sentence'?", 'A sentence!']) |
| 365 | normal gg)) |
| 366 | call assert_equal(3, getcurpos()[1]) |
| 367 | |
Bram Moolenaar | 8516071 | 2018-06-19 18:27:41 +0200 | [diff] [blame] | 368 | %delete _ |
| 369 | endfunc |
Bram Moolenaar | 224a5f1 | 2020-04-28 20:29:07 +0200 | [diff] [blame] | 370 | |
| 371 | " Test for the paragraph (ap) text object |
| 372 | func Test_paragraph() |
| 373 | new |
| 374 | call setline(1, ['First line.', 'Second line.', 'Third line.']) |
| 375 | call cursor(2, 1) |
| 376 | normal vapy |
| 377 | call assert_equal("First line.\nSecond line.\nThird line.\n", @") |
| 378 | |
| 379 | call cursor(2, 1) |
| 380 | call assert_beeps('normal vapapy') |
| 381 | |
| 382 | call setline(1, ['First line.', 'Second line.', ' ', '']) |
| 383 | call cursor(1, 1) |
| 384 | normal vapy |
| 385 | call assert_equal("First line.\nSecond line.\n \n\n", @") |
| 386 | |
| 387 | call setline(1, ['', '', '', 'First line.', 'Second line.']) |
| 388 | call cursor(2, 1) |
| 389 | normal yap |
| 390 | call assert_equal("\n\n\nFirst line.\nSecond line.\n", @") |
| 391 | call assert_beeps('normal 3yap') |
| 392 | exe "normal \<C-C>" |
| 393 | |
| 394 | %d |
| 395 | call setline(1, [' ', ' ', ' ']) |
| 396 | call cursor(2, 1) |
| 397 | normal Vipy |
| 398 | call assert_equal(" \n \n \n", @") |
| 399 | call cursor(2, 1) |
| 400 | call assert_beeps("normal Vipip") |
| 401 | exe "normal \<C-C>" |
| 402 | |
Christian Brabandt | ad4d7f4 | 2024-01-04 21:43:36 +0100 | [diff] [blame] | 403 | bw! |
Bram Moolenaar | 224a5f1 | 2020-04-28 20:29:07 +0200 | [diff] [blame] | 404 | endfunc |
| 405 | |
| 406 | " Tests for text object aw |
| 407 | func Test_textobj_a_word() |
| 408 | new |
| 409 | call append(0, ['foobar,eins,foobar', 'foo,zwei,foo ']) |
| 410 | " diw |
| 411 | norm! 1gg0diw |
| 412 | call assert_equal([',eins,foobar', 'foo,zwei,foo ', ''], getline(1,'$')) |
| 413 | " daw |
| 414 | norm! 2ggEdaw |
| 415 | call assert_equal([',eins,foobar', 'foo,zwei,', ''], getline(1, '$')) |
| 416 | " daw the last word in a line |
| 417 | call setline(1, ['foo bar', 'foo bar', '']) |
| 418 | call cursor(1, 5) |
| 419 | normal daw |
| 420 | call assert_equal('foo', getline(1)) |
| 421 | " aw in visual mode |
| 422 | call cursor(2, 5) |
| 423 | normal! vawx |
| 424 | call assert_equal('foo', getline(2)) |
| 425 | %d |
| 426 | call append(0, ["foo\teins\tfoobar", "foo\tzwei\tfoo "]) |
| 427 | " diW |
| 428 | norm! 2ggwd2iW |
| 429 | call assert_equal(['foo eins foobar', 'foo foo ', ''], getline(1,'$')) |
| 430 | " daW |
| 431 | norm! 1ggd2aW |
| 432 | call assert_equal(['foobar', 'foo foo ', ''], getline(1,'$')) |
| 433 | |
| 434 | %d |
| 435 | call append(0, ["foo\teins\tfoobar", "foo\tzwei\tfoo "]) |
| 436 | " aw in visual line mode switches to characterwise mode |
| 437 | norm! 2gg$Vawd |
| 438 | call assert_equal(['foo eins foobar', 'foo zwei foo'], getline(1,'$')) |
| 439 | norm! 1gg$Viwd |
| 440 | call assert_equal(['foo eins ', 'foo zwei foo'], getline(1,'$')) |
| 441 | |
| 442 | " visually selecting a tab before a word with 'selection' set to 'exclusive' |
| 443 | set selection=exclusive |
| 444 | normal gg3lvlawy |
| 445 | call assert_equal("\teins", @") |
| 446 | " visually selecting a tab before a word with 'selection' set to 'inclusive' |
| 447 | set selection=inclusive |
| 448 | normal gg3lvlawy |
| 449 | call assert_equal("\teins\t", @") |
| 450 | set selection& |
| 451 | |
| 452 | " selecting a word with no non-space characters in a buffer fails |
| 453 | %d |
| 454 | call setline(1, ' ') |
| 455 | call assert_beeps('normal 3lyaw') |
| 456 | |
| 457 | " visually selecting words backwards with no more words to select |
| 458 | call setline(1, 'one two') |
| 459 | call assert_beeps('normal 2lvh2aw') |
| 460 | exe "normal \<C-C>" |
| 461 | call assert_beeps('normal $vh3aw') |
| 462 | exe "normal \<C-C>" |
| 463 | call setline(1, ['', 'one two']) |
| 464 | call assert_beeps('normal 2G2lvh3aw') |
| 465 | exe "normal \<C-C>" |
| 466 | |
| 467 | " selecting words forward with no more words to select |
| 468 | %d |
| 469 | call setline(1, 'one a') |
| 470 | call assert_beeps('normal 0y3aw') |
| 471 | call setline(1, 'one two ') |
| 472 | call assert_beeps('normal 0y3aw') |
| 473 | call assert_beeps('normal 03ly2aw') |
| 474 | |
| 475 | " clean up |
| 476 | bw! |
| 477 | endfunc |
| 478 | |
| 479 | " Test for is and as text objects |
| 480 | func Test_textobj_sentence() |
| 481 | new |
| 482 | call append(0, ['This is a test. With some sentences!', '', |
| 483 | \ 'Even with a question? And one more. And no sentence here']) |
| 484 | " Test for dis - does not remove trailing whitespace |
| 485 | norm! 1gg0dis |
| 486 | call assert_equal([' With some sentences!', '', |
| 487 | \ 'Even with a question? And one more. And no sentence here', ''], |
| 488 | \ getline(1,'$')) |
| 489 | " Test for das - removes leading whitespace |
| 490 | norm! 3ggf?ldas |
| 491 | call assert_equal([' With some sentences!', '', |
| 492 | \ 'Even with a question? And no sentence here', ''], getline(1,'$')) |
| 493 | " when used in visual mode, is made characterwise |
| 494 | norm! 3gg$Visy |
| 495 | call assert_equal('v', visualmode()) |
| 496 | " reset visualmode() |
| 497 | norm! 3ggVy |
| 498 | norm! 3gg$Vasy |
| 499 | call assert_equal('v', visualmode()) |
| 500 | " basic testing for textobjects a< and at |
| 501 | %d |
| 502 | call setline(1, ['<div> ','<a href="foobar" class="foo">xyz</a>',' </div>', ' ']) |
| 503 | " a< |
| 504 | norm! 1gg0da< |
| 505 | call assert_equal([' ', '<a href="foobar" class="foo">xyz</a>', ' </div>', ' '], getline(1,'$')) |
| 506 | norm! 1pj |
| 507 | call assert_equal([' <div>', '<a href="foobar" class="foo">xyz</a>', ' </div>', ' '], getline(1,'$')) |
| 508 | " at |
| 509 | norm! d2at |
| 510 | call assert_equal([' '], getline(1,'$')) |
| 511 | %d |
| 512 | call setline(1, ['<div> ','<a href="foobar" class="foo">xyz</a>',' </div>', ' ']) |
| 513 | " i< |
| 514 | norm! 1gg0di< |
| 515 | call assert_equal(['<> ', '<a href="foobar" class="foo">xyz</a>', ' </div>', ' '], getline(1,'$')) |
| 516 | norm! 1Pj |
| 517 | call assert_equal(['<div> ', '<a href="foobar" class="foo">xyz</a>', ' </div>', ' '], getline(1,'$')) |
| 518 | norm! d2it |
| 519 | call assert_equal(['<div></div>',' '], getline(1,'$')) |
| 520 | " basic testing for a[ and i[ text object |
| 521 | %d |
| 522 | call setline(1, [' ', '[', 'one [two]', 'thre', ']']) |
| 523 | norm! 3gg0di[ |
| 524 | call assert_equal([' ', '[', ']'], getline(1,'$')) |
| 525 | call setline(1, [' ', '[', 'one [two]', 'thre', ']']) |
| 526 | norm! 3gg0ftd2a[ |
| 527 | call assert_equal([' '], getline(1,'$')) |
| 528 | |
| 529 | " clean up |
| 530 | bw! |
| 531 | endfunc |
| 532 | |
| 533 | " Test for quote (', " and `) textobjects |
| 534 | func Test_textobj_quote() |
| 535 | new |
| 536 | |
| 537 | " Test for i" when cursor is in front of a quoted object |
| 538 | call append(0, 'foo "bar"') |
| 539 | norm! 1gg0di" |
| 540 | call assert_equal(['foo ""', ''], getline(1,'$')) |
| 541 | |
| 542 | " Test for visually selecting an inner quote |
| 543 | %d |
| 544 | " extend visual selection from one quote to the next |
| 545 | call setline(1, 'color "red" color "blue"') |
| 546 | call cursor(1, 7) |
| 547 | normal v4li"y |
| 548 | call assert_equal('"red" color "blue', @") |
| 549 | |
| 550 | " try to extend visual selection from one quote to a non-existing quote |
| 551 | call setline(1, 'color "red" color blue') |
| 552 | call cursor(1, 7) |
| 553 | call feedkeys('v4li"y', 'xt') |
| 554 | call assert_equal('"red"', @") |
| 555 | |
| 556 | " try to extend visual selection from one quote to a next partial quote |
| 557 | call setline(1, 'color "red" color "blue') |
| 558 | call cursor(1, 7) |
| 559 | normal v4li"y |
| 560 | call assert_equal('"red" color ', @") |
| 561 | |
| 562 | " select a quote backwards in visual mode |
| 563 | call cursor(1, 12) |
| 564 | normal vhi"y |
| 565 | call assert_equal('red" ', @") |
| 566 | call assert_equal(8, col('.')) |
| 567 | |
| 568 | " select a quote backwards in visual mode from outside the quote |
| 569 | call cursor(1, 17) |
| 570 | normal v2hi"y |
| 571 | call assert_equal('red', @") |
| 572 | call assert_equal(8, col('.')) |
| 573 | |
| 574 | " visually selecting a quote with 'selection' set to 'exclusive' |
| 575 | call setline(1, 'He said "How are you?"') |
| 576 | set selection=exclusive |
| 577 | normal 012lv2li"y |
| 578 | call assert_equal('How are you?', @") |
| 579 | set selection& |
| 580 | |
| 581 | " try copy a quote object with a single quote in the line |
| 582 | call setline(1, "Smith's car") |
| 583 | call cursor(1, 6) |
| 584 | call assert_beeps("normal yi'") |
| 585 | call assert_beeps("normal 2lyi'") |
| 586 | |
| 587 | " selecting space before and after a quoted string |
| 588 | call setline(1, "some 'special' string") |
| 589 | normal 0ya' |
| 590 | call assert_equal("'special' ", @") |
| 591 | call setline(1, "some 'special'string") |
| 592 | normal 0ya' |
| 593 | call assert_equal(" 'special'", @") |
| 594 | |
Dominique Pelle | af631f6 | 2021-09-03 16:50:16 +0200 | [diff] [blame] | 595 | " quoted string with odd or even number of backslashes. |
| 596 | call setline(1, 'char *s = "foo\"bar"') |
| 597 | normal $hhyi" |
| 598 | call assert_equal('foo\"bar', @") |
| 599 | call setline(1, 'char *s = "foo\\"bar"') |
| 600 | normal $hhyi" |
| 601 | call assert_equal('bar', @") |
| 602 | call setline(1, 'char *s = "foo\\\"bar"') |
| 603 | normal $hhyi" |
| 604 | call assert_equal('foo\\\"bar', @") |
| 605 | call setline(1, 'char *s = "foo\\\\"bar"') |
| 606 | normal $hhyi" |
| 607 | call assert_equal('bar', @") |
| 608 | |
Christian Brabandt | ad4d7f4 | 2024-01-04 21:43:36 +0100 | [diff] [blame] | 609 | bw! |
Bram Moolenaar | 224a5f1 | 2020-04-28 20:29:07 +0200 | [diff] [blame] | 610 | endfunc |
| 611 | |
Connor Lane Smith | b9115da | 2021-07-31 13:31:42 +0200 | [diff] [blame] | 612 | " Test for i(, i<, etc. when cursor is in front of a block |
| 613 | func Test_textobj_find_paren_forward() |
| 614 | new |
| 615 | |
| 616 | " i< and a> when cursor is in front of a block |
| 617 | call setline(1, '#include <foo.h>') |
| 618 | normal 0yi< |
| 619 | call assert_equal('foo.h', @") |
| 620 | normal 0ya> |
| 621 | call assert_equal('<foo.h>', @") |
| 622 | |
| 623 | " 2i(, 3i( in front of a block enters second/third nested '(' |
| 624 | call setline(1, 'foo (bar (baz (quux)))') |
| 625 | normal 0yi) |
| 626 | call assert_equal('bar (baz (quux))', @") |
| 627 | normal 02yi) |
| 628 | call assert_equal('baz (quux)', @") |
| 629 | normal 03yi) |
| 630 | call assert_equal('quux', @") |
| 631 | |
| 632 | " 3i( in front of a block doesn't enter third but un-nested '(' |
| 633 | call setline(1, 'foo (bar (baz) (quux))') |
| 634 | normal 03di) |
| 635 | call assert_equal('foo (bar (baz) (quux))', getline(1)) |
| 636 | normal 02di) |
| 637 | call assert_equal('foo (bar () (quux))', getline(1)) |
| 638 | normal 0di) |
| 639 | call assert_equal('foo ()', getline(1)) |
| 640 | |
Christian Brabandt | ad4d7f4 | 2024-01-04 21:43:36 +0100 | [diff] [blame] | 641 | bw! |
| 642 | endfunc |
| 643 | |
| 644 | func Test_inner_block_empty_paren() |
| 645 | new |
Maxim Kim | 3779516 | 2024-01-05 17:52:49 +0100 | [diff] [blame] | 646 | call setline(1, ["(text)()", "", "(text)(", ")", "", "()()", "", "text()"]) |
Christian Brabandt | ad4d7f4 | 2024-01-04 21:43:36 +0100 | [diff] [blame] | 647 | |
| 648 | " Example 1 |
| 649 | call cursor(1, 1) |
| 650 | let @" = '' |
| 651 | call assert_beeps(':call feedkeys("0f(viby","xt")') |
| 652 | call assert_equal(7, getpos('.')[2]) |
| 653 | call assert_equal('(', @") |
| 654 | |
| 655 | " Example 2 |
| 656 | call cursor(3, 1) |
| 657 | let @" = '' |
| 658 | call assert_beeps('call feedkeys("0f(viby", "xt")') |
| 659 | call assert_equal(7, getpos('.')[2]) |
| 660 | call assert_equal('(', @") |
| 661 | |
| 662 | " Example 3 |
| 663 | call cursor(6, 1) |
| 664 | let @" = '' |
| 665 | call assert_beeps('call feedkeys("0f(viby", "xt")') |
| 666 | call assert_equal(3, getpos('.')[2]) |
| 667 | call assert_equal('(', @") |
Maxim Kim | 3779516 | 2024-01-05 17:52:49 +0100 | [diff] [blame] | 668 | |
| 669 | " Change empty inner block |
| 670 | call cursor(8, 1) |
| 671 | call feedkeys("0cibtext", "xt") |
| 672 | call assert_equal("text(text)", getline('.')) |
| 673 | |
Christian Brabandt | ad4d7f4 | 2024-01-04 21:43:36 +0100 | [diff] [blame] | 674 | bwipe! |
| 675 | endfunc |
| 676 | |
| 677 | func Test_inner_block_empty_bracket() |
| 678 | new |
Maxim Kim | 3779516 | 2024-01-05 17:52:49 +0100 | [diff] [blame] | 679 | call setline(1, ["[text][]", "", "[text][", "]", "", "[][]", "", "text[]"]) |
Christian Brabandt | ad4d7f4 | 2024-01-04 21:43:36 +0100 | [diff] [blame] | 680 | |
| 681 | " Example 1 |
| 682 | call cursor(1, 1) |
| 683 | let @" = '' |
| 684 | call assert_beeps(':call feedkeys("0f[viby","xt")') |
| 685 | call assert_equal(7, getpos('.')[2]) |
| 686 | call assert_equal('[', @") |
| 687 | |
| 688 | " Example 2 |
| 689 | call cursor(3, 1) |
| 690 | let @" = '' |
| 691 | call assert_beeps('call feedkeys("0f[viby", "xt")') |
| 692 | call assert_equal(7, getpos('.')[2]) |
| 693 | call assert_equal('[', @") |
| 694 | |
| 695 | " Example 3 |
| 696 | call cursor(6, 1) |
| 697 | let @" = '' |
| 698 | call assert_beeps('call feedkeys("0f[viby", "xt")') |
| 699 | call assert_equal(3, getpos('.')[2]) |
| 700 | call assert_equal('[', @") |
Maxim Kim | 3779516 | 2024-01-05 17:52:49 +0100 | [diff] [blame] | 701 | |
| 702 | " Change empty inner block |
| 703 | call cursor(8, 1) |
| 704 | call feedkeys("0ci[text", "xt") |
| 705 | call assert_equal("text[text]", getline('.')) |
| 706 | |
Christian Brabandt | ad4d7f4 | 2024-01-04 21:43:36 +0100 | [diff] [blame] | 707 | bwipe! |
| 708 | endfunc |
| 709 | |
| 710 | func Test_inner_block_empty_brace() |
| 711 | new |
Maxim Kim | 3779516 | 2024-01-05 17:52:49 +0100 | [diff] [blame] | 712 | call setline(1, ["{text}{}", "", "{text}{", "}", "", "{}{}", "", "text{}"]) |
Christian Brabandt | ad4d7f4 | 2024-01-04 21:43:36 +0100 | [diff] [blame] | 713 | |
| 714 | " Example 1 |
| 715 | call cursor(1, 1) |
| 716 | let @" = '' |
| 717 | call assert_beeps(':call feedkeys("0f{viby","xt")') |
| 718 | call assert_equal(7, getpos('.')[2]) |
| 719 | call assert_equal('{', @") |
| 720 | |
| 721 | " Example 2 |
| 722 | call cursor(3, 1) |
| 723 | let @" = '' |
| 724 | call assert_beeps('call feedkeys("0f{viby", "xt")') |
| 725 | call assert_equal(7, getpos('.')[2]) |
| 726 | call assert_equal('{', @") |
| 727 | |
| 728 | " Example 3 |
| 729 | call cursor(6, 1) |
| 730 | let @" = '' |
| 731 | call assert_beeps('call feedkeys("0f{viby", "xt")') |
| 732 | call assert_equal(3, getpos('.')[2]) |
| 733 | call assert_equal('{', @") |
Maxim Kim | 3779516 | 2024-01-05 17:52:49 +0100 | [diff] [blame] | 734 | |
| 735 | " Change empty inner block |
| 736 | call cursor(8, 1) |
| 737 | call feedkeys("0ciBtext", "xt") |
| 738 | call assert_equal("text{text}", getline('.')) |
| 739 | |
Christian Brabandt | ad4d7f4 | 2024-01-04 21:43:36 +0100 | [diff] [blame] | 740 | bwipe! |
| 741 | endfunc |
| 742 | |
| 743 | func Test_inner_block_empty_lessthan() |
| 744 | new |
| 745 | call setline(1, ["<text><>", "", "<text><", ">", "", "<><>"]) |
| 746 | |
| 747 | " Example 1 |
| 748 | call cursor(1, 1) |
| 749 | let @" = '' |
| 750 | call assert_beeps(':call feedkeys("0f<viby","xt")') |
| 751 | call assert_equal(7, getpos('.')[2]) |
| 752 | call assert_equal('<', @") |
| 753 | |
| 754 | " Example 2 |
| 755 | call cursor(3, 1) |
| 756 | let @" = '' |
| 757 | call assert_beeps('call feedkeys("0f<viby", "xt")') |
| 758 | call assert_equal(7, getpos('.')[2]) |
| 759 | call assert_equal('<', @") |
| 760 | |
| 761 | " Example 3 |
| 762 | call cursor(6, 1) |
| 763 | let @" = '' |
| 764 | call assert_beeps('call feedkeys("0f<viby", "xt")') |
| 765 | call assert_equal(3, getpos('.')[2]) |
| 766 | call assert_equal('<', @") |
| 767 | bwipe! |
Connor Lane Smith | b9115da | 2021-07-31 13:31:42 +0200 | [diff] [blame] | 768 | endfunc |
| 769 | |
Bram Moolenaar | 224a5f1 | 2020-04-28 20:29:07 +0200 | [diff] [blame] | 770 | " vim: shiftwidth=2 sts=2 expandtab |