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 |
| 4 | CheckFeature textobjects |
Bram Moolenaar | 00b24be | 2016-07-23 22:04:47 +0200 | [diff] [blame] | 5 | |
Bram Moolenaar | c5e2b04 | 2017-06-05 16:37:07 +0200 | [diff] [blame] | 6 | func CpoM(line, useM, expected) |
Bram Moolenaar | 00b24be | 2016-07-23 22:04:47 +0200 | [diff] [blame] | 7 | new |
| 8 | |
| 9 | if a:useM |
| 10 | set cpoptions+=M |
| 11 | else |
| 12 | set cpoptions-=M |
| 13 | endif |
| 14 | |
| 15 | call setline(1, a:line) |
| 16 | |
| 17 | call setreg('"', '') |
| 18 | normal! ggfrmavi)y |
| 19 | call assert_equal(getreg('"'), a:expected[0]) |
| 20 | |
| 21 | call setreg('"', '') |
| 22 | normal! `afbmavi)y |
| 23 | call assert_equal(getreg('"'), a:expected[1]) |
| 24 | |
| 25 | call setreg('"', '') |
| 26 | normal! `afgmavi)y |
| 27 | call assert_equal(getreg('"'), a:expected[2]) |
| 28 | |
| 29 | q! |
Bram Moolenaar | c5e2b04 | 2017-06-05 16:37:07 +0200 | [diff] [blame] | 30 | endfunc |
Bram Moolenaar | 00b24be | 2016-07-23 22:04:47 +0200 | [diff] [blame] | 31 | |
Bram Moolenaar | c5e2b04 | 2017-06-05 16:37:07 +0200 | [diff] [blame] | 32 | func Test_inner_block_without_cpo_M() |
Bram Moolenaar | 00b24be | 2016-07-23 22:04:47 +0200 | [diff] [blame] | 33 | call CpoM('(red \(blue) green)', 0, ['red \(blue', 'red \(blue', '']) |
Bram Moolenaar | c5e2b04 | 2017-06-05 16:37:07 +0200 | [diff] [blame] | 34 | endfunc |
Bram Moolenaar | 00b24be | 2016-07-23 22:04:47 +0200 | [diff] [blame] | 35 | |
Bram Moolenaar | c5e2b04 | 2017-06-05 16:37:07 +0200 | [diff] [blame] | 36 | func Test_inner_block_with_cpo_M_left_backslash() |
Bram Moolenaar | 00b24be | 2016-07-23 22:04:47 +0200 | [diff] [blame] | 37 | 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] | 38 | endfunc |
Bram Moolenaar | 00b24be | 2016-07-23 22:04:47 +0200 | [diff] [blame] | 39 | |
Bram Moolenaar | c5e2b04 | 2017-06-05 16:37:07 +0200 | [diff] [blame] | 40 | func Test_inner_block_with_cpo_M_right_backslash() |
Bram Moolenaar | 00b24be | 2016-07-23 22:04:47 +0200 | [diff] [blame] | 41 | 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] | 42 | endfunc |
| 43 | |
| 44 | func Test_quote_selection_selection_exclusive() |
| 45 | new |
| 46 | call setline(1, "a 'bcde' f") |
| 47 | set selection=exclusive |
| 48 | exe "norm! fdvhi'y" |
| 49 | call assert_equal('bcde', @") |
Bram Moolenaar | 7170b29 | 2019-11-17 17:32:28 +0100 | [diff] [blame] | 50 | let @"='dummy' |
| 51 | exe "norm! $gevi'y" |
| 52 | call assert_equal('bcde', @") |
Bram Moolenaar | c5e2b04 | 2017-06-05 16:37:07 +0200 | [diff] [blame] | 53 | set selection&vim |
| 54 | bw! |
| 55 | endfunc |
Bram Moolenaar | db51007 | 2017-09-28 21:52:17 +0200 | [diff] [blame] | 56 | |
Bram Moolenaar | 55d3bdb | 2019-02-22 15:04:17 +0100 | [diff] [blame] | 57 | func Test_quote_selection_selection_exclusive_abort() |
| 58 | new |
| 59 | set selection=exclusive |
| 60 | call setline(1, "'abzzc'") |
| 61 | let exp_curs = [0, 1, 6, 0] |
| 62 | call cursor(1,1) |
| 63 | exe 'norm! fcdvi"' |
| 64 | " make sure to end visual mode to have a clear state |
| 65 | exe "norm! \<esc>" |
| 66 | call assert_equal(exp_curs, getpos('.')) |
| 67 | call cursor(1,1) |
| 68 | exe 'norm! fcvi"' |
| 69 | exe "norm! \<esc>" |
| 70 | call assert_equal(exp_curs, getpos('.')) |
| 71 | call cursor(1,2) |
| 72 | exe 'norm! vfcoi"' |
| 73 | exe "norm! \<esc>" |
| 74 | let exp_curs = [0, 1, 2, 0] |
| 75 | let exp_visu = [0, 1, 7, 0] |
| 76 | call assert_equal(exp_curs, getpos('.')) |
| 77 | call assert_equal(exp_visu, getpos("'>")) |
| 78 | set selection&vim |
| 79 | bw! |
| 80 | endfunc |
| 81 | |
Bram Moolenaar | db51007 | 2017-09-28 21:52:17 +0200 | [diff] [blame] | 82 | " Tests for string and html text objects |
| 83 | func Test_string_html_objects() |
| 84 | enew! |
| 85 | |
| 86 | let t = '"wo\"rd\\" foo' |
| 87 | put =t |
| 88 | normal! da" |
| 89 | call assert_equal('foo', getline('.')) |
| 90 | |
| 91 | let t = "'foo' 'bar' 'piep'" |
| 92 | put =t |
| 93 | normal! 0va'a'rx |
| 94 | call assert_equal("xxxxxxxxxxxx'piep'", getline('.')) |
| 95 | |
| 96 | let t = "bla bla `quote` blah" |
| 97 | put =t |
| 98 | normal! 02f`da` |
| 99 | call assert_equal("bla bla blah", getline('.')) |
| 100 | |
| 101 | let t = 'out " in "noXno"' |
| 102 | put =t |
| 103 | normal! 0fXdi" |
| 104 | call assert_equal('out " in ""', getline('.')) |
| 105 | |
| 106 | let t = "\"'\" 'blah' rep 'buh'" |
| 107 | put =t |
| 108 | normal! 03f'vi'ry |
| 109 | call assert_equal("\"'\" 'blah'yyyyy'buh'", getline('.')) |
| 110 | |
| 111 | set quoteescape=+*- |
| 112 | let t = "bla `s*`d-`+++`l**` b`la" |
| 113 | put =t |
| 114 | normal! di` |
| 115 | call assert_equal("bla `` b`la", getline('.')) |
| 116 | |
| 117 | let t = 'voo "nah" sdf " asdf" sdf " sdf" sd' |
| 118 | put =t |
| 119 | normal! $F"va"oha"i"rz |
| 120 | call assert_equal('voo "zzzzzzzzzzzzzzzzzzzzzzzzzzzzsd', getline('.')) |
| 121 | |
| 122 | let t = "-<b>asdf<i>Xasdf</i>asdf</b>-" |
| 123 | put =t |
| 124 | normal! fXdit |
| 125 | call assert_equal('-<b>asdf<i></i>asdf</b>-', getline('.')) |
| 126 | |
| 127 | let t = "-<b>asdX<i>a<i />sdf</i>asdf</b>-" |
| 128 | put =t |
| 129 | normal! 0fXdit |
| 130 | call assert_equal('-<b></b>-', getline('.')) |
| 131 | |
| 132 | let t = "-<b>asdf<i>Xasdf</i>asdf</b>-" |
| 133 | put =t |
| 134 | normal! fXdat |
| 135 | call assert_equal('-<b>asdfasdf</b>-', getline('.')) |
| 136 | |
| 137 | let t = "-<b>asdX<i>as<b />df</i>asdf</b>-" |
| 138 | put =t |
| 139 | normal! 0fXdat |
| 140 | call assert_equal('--', getline('.')) |
| 141 | |
| 142 | let t = "-<b>\ninnertext object\n</b>" |
| 143 | put =t |
| 144 | normal! dit |
| 145 | call assert_equal('-<b></b>', getline('.')) |
| 146 | |
| 147 | set quoteescape& |
| 148 | enew! |
| 149 | endfunc |
| 150 | |
Bram Moolenaar | b476cb7 | 2018-08-16 21:37:50 +0200 | [diff] [blame] | 151 | func Test_empty_html_tag() |
| 152 | new |
| 153 | call setline(1, '<div></div>') |
| 154 | normal 0citxxx |
| 155 | call assert_equal('<div>xxx</div>', getline(1)) |
| 156 | |
| 157 | call setline(1, '<div></div>') |
| 158 | normal 0f<cityyy |
| 159 | call assert_equal('<div>yyy</div>', getline(1)) |
| 160 | |
| 161 | call setline(1, '<div></div>') |
| 162 | normal 0f<vitsaaa |
| 163 | call assert_equal('aaa', getline(1)) |
| 164 | |
| 165 | bwipe! |
| 166 | endfunc |
| 167 | |
Bram Moolenaar | db51007 | 2017-09-28 21:52:17 +0200 | [diff] [blame] | 168 | " Tests for match() and matchstr() |
| 169 | func Test_match() |
| 170 | call assert_equal("b", matchstr("abcd", ".", 0, 2)) |
| 171 | call assert_equal("bc", matchstr("abcd", "..", 0, 2)) |
| 172 | call assert_equal("c", matchstr("abcd", ".", 2, 0)) |
| 173 | call assert_equal("a", matchstr("abcd", ".", 0, -1)) |
| 174 | call assert_equal(-1, match("abcd", ".", 0, 5)) |
| 175 | call assert_equal(0 , match("abcd", ".", 0, -1)) |
| 176 | call assert_equal(0 , match('abc', '.', 0, 1)) |
| 177 | call assert_equal(1 , match('abc', '.', 0, 2)) |
| 178 | call assert_equal(2 , match('abc', '.', 0, 3)) |
| 179 | call assert_equal(-1, match('abc', '.', 0, 4)) |
| 180 | call assert_equal(1 , match('abc', '.', 1, 1)) |
| 181 | call assert_equal(2 , match('abc', '.', 2, 1)) |
| 182 | call assert_equal(-1, match('abc', '.', 3, 1)) |
| 183 | call assert_equal(3 , match('abc', '$', 0, 1)) |
| 184 | call assert_equal(-1, match('abc', '$', 0, 2)) |
| 185 | call assert_equal(3 , match('abc', '$', 1, 1)) |
| 186 | call assert_equal(3 , match('abc', '$', 2, 1)) |
| 187 | call assert_equal(3 , match('abc', '$', 3, 1)) |
| 188 | call assert_equal(-1, match('abc', '$', 4, 1)) |
| 189 | call assert_equal(0 , match('abc', '\zs', 0, 1)) |
| 190 | call assert_equal(1 , match('abc', '\zs', 0, 2)) |
| 191 | call assert_equal(2 , match('abc', '\zs', 0, 3)) |
| 192 | call assert_equal(3 , match('abc', '\zs', 0, 4)) |
| 193 | call assert_equal(-1, match('abc', '\zs', 0, 5)) |
| 194 | call assert_equal(1 , match('abc', '\zs', 1, 1)) |
| 195 | call assert_equal(2 , match('abc', '\zs', 2, 1)) |
| 196 | call assert_equal(3 , match('abc', '\zs', 3, 1)) |
| 197 | call assert_equal(-1, match('abc', '\zs', 4, 1)) |
| 198 | endfunc |
Bram Moolenaar | 82846a0 | 2018-02-09 18:09:54 +0100 | [diff] [blame] | 199 | |
| 200 | " This was causing an illegal memory access |
| 201 | func Test_inner_tag() |
| 202 | new |
| 203 | norm ixxx |
| 204 | call feedkeys("v", 'xt') |
| 205 | insert |
| 206 | x |
| 207 | x |
| 208 | . |
| 209 | norm it |
| 210 | q! |
| 211 | endfunc |
Bram Moolenaar | 8516071 | 2018-06-19 18:27:41 +0200 | [diff] [blame] | 212 | |
| 213 | func Test_sentence() |
| 214 | enew! |
| 215 | call setline(1, 'A sentence. A sentence? A sentence!') |
| 216 | |
| 217 | normal yis |
| 218 | call assert_equal('A sentence.', @") |
| 219 | normal yas |
| 220 | call assert_equal('A sentence. ', @") |
| 221 | |
| 222 | normal ) |
| 223 | |
| 224 | normal yis |
| 225 | call assert_equal('A sentence?', @") |
| 226 | normal yas |
| 227 | call assert_equal('A sentence? ', @") |
| 228 | |
| 229 | normal ) |
| 230 | |
| 231 | normal yis |
| 232 | call assert_equal('A sentence!', @") |
| 233 | normal yas |
| 234 | call assert_equal(' A sentence!', @") |
| 235 | |
| 236 | normal 0 |
| 237 | normal 2yis |
| 238 | call assert_equal('A sentence. ', @") |
| 239 | normal 3yis |
| 240 | call assert_equal('A sentence. A sentence?', @") |
| 241 | normal 2yas |
| 242 | call assert_equal('A sentence. A sentence? ', @") |
| 243 | |
| 244 | %delete _ |
| 245 | endfunc |
| 246 | |
| 247 | func Test_sentence_with_quotes() |
| 248 | enew! |
| 249 | call setline(1, 'A "sentence." A sentence.') |
| 250 | |
| 251 | normal yis |
| 252 | call assert_equal('A "sentence."', @") |
| 253 | normal yas |
| 254 | call assert_equal('A "sentence." ', @") |
| 255 | |
| 256 | normal ) |
| 257 | |
| 258 | normal yis |
| 259 | call assert_equal('A sentence.', @") |
| 260 | normal yas |
| 261 | call assert_equal(' A sentence.', @") |
| 262 | |
| 263 | %delete _ |
| 264 | endfunc |
| 265 | |
Bram Moolenaar | 1e11536 | 2019-01-09 23:01:02 +0100 | [diff] [blame] | 266 | func Test_sentence_with_cursor_on_delimiter() |
Bram Moolenaar | 8516071 | 2018-06-19 18:27:41 +0200 | [diff] [blame] | 267 | enew! |
| 268 | call setline(1, "A '([sentence.])' A sentence.") |
| 269 | |
| 270 | normal! 15|yis |
| 271 | call assert_equal("A '([sentence.])'", @") |
| 272 | normal! 15|yas |
| 273 | call assert_equal("A '([sentence.])' ", @") |
| 274 | |
| 275 | normal! 16|yis |
| 276 | call assert_equal("A '([sentence.])'", @") |
| 277 | normal! 16|yas |
| 278 | call assert_equal("A '([sentence.])' ", @") |
| 279 | |
| 280 | normal! 17|yis |
| 281 | call assert_equal("A '([sentence.])'", @") |
| 282 | normal! 17|yas |
| 283 | call assert_equal("A '([sentence.])' ", @") |
| 284 | |
| 285 | %delete _ |
| 286 | endfunc |