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 exe "norm! fdvhi'y" 49 call assert_equal('bcde', @") 50 let @"='dummy' 51 exe "norm! $gevi'y" 52 call assert_equal('bcde', @") 53 set selection&vim 54 bw! 55endfunc 56 57func 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! 80endfunc 81 82" Tests for string and html text objects 83func 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! 149endfunc 150 151func 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! 166endfunc 167 168" Tests for match() and matchstr() 169func 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)) 198endfunc 199 200" This was causing an illegal memory access 201func Test_inner_tag() 202 new 203 norm ixxx 204 call feedkeys("v", 'xt') 205 insert 206x 207x 208. 209 norm it 210 q! 211endfunc 212 213func 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 _ 245endfunc 246 247func 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 _ 264endfunc 265 266func Test_sentence_with_cursor_on_delimiter() 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 _ 286endfunc 287