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