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