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