1" Test commands that jump somewhere. 2 3" Create a new buffer using "lines" and place the cursor on the word after the 4" first occurrence of return and invoke "cmd". The cursor should now be 5" positioned at the given line and col. 6func XTest_goto_decl(cmd, lines, line, col) 7 new 8 call setline(1, a:lines) 9 /return/ 10 normal! W 11 execute 'norm! ' . a:cmd 12 call assert_equal(a:line, line('.')) 13 call assert_equal(a:col, col('.')) 14 quit! 15endfunc 16 17func Test_gD() 18 let lines = [ 19 \ 'int x;', 20 \ '', 21 \ 'int func(void)', 22 \ '{', 23 \ ' return x;', 24 \ '}', 25 \ ] 26 call XTest_goto_decl('gD', lines, 1, 5) 27endfunc 28 29func Test_gD_too() 30 let lines = [ 31 \ 'Filename x;', 32 \ '', 33 \ 'int Filename', 34 \ 'int func() {', 35 \ ' Filename x;', 36 \ ' return x;', 37 \ ] 38 call XTest_goto_decl('gD', lines, 1, 10) 39endfunc 40 41func Test_gD_comment() 42 let lines = [ 43 \ '/* int x; */', 44 \ 'int x;', 45 \ '', 46 \ 'int func(void)', 47 \ '{', 48 \ ' return x;', 49 \ '}', 50 \ ] 51 call XTest_goto_decl('gD', lines, 2, 5) 52endfunc 53 54func Test_gD_inline_comment() 55 let lines = [ 56 \ 'int y /* , x */;', 57 \ 'int x;', 58 \ '', 59 \ 'int func(void)', 60 \ '{', 61 \ ' return x;', 62 \ '}', 63 \ ] 64 call XTest_goto_decl('gD', lines, 2, 5) 65endfunc 66 67func Test_gD_string() 68 let lines = [ 69 \ 'char *s[] = "x";', 70 \ 'int x = 1;', 71 \ '', 72 \ 'int func(void)', 73 \ '{', 74 \ ' return x;', 75 \ '}', 76 \ ] 77 call XTest_goto_decl('gD', lines, 2, 5) 78endfunc 79 80func Test_gD_string_same_line() 81 let lines = [ 82 \ 'char *s[] = "x", int x = 1;', 83 \ '', 84 \ 'int func(void)', 85 \ '{', 86 \ ' return x;', 87 \ '}', 88 \ ] 89 call XTest_goto_decl('gD', lines, 1, 22) 90endfunc 91 92func Test_gD_char() 93 let lines = [ 94 \ "char c = 'x';", 95 \ 'int x = 1;', 96 \ '', 97 \ 'int func(void)', 98 \ '{', 99 \ ' return x;', 100 \ '}', 101 \ ] 102 call XTest_goto_decl('gD', lines, 2, 5) 103endfunc 104 105func Test_gd() 106 let lines = [ 107 \ 'int x;', 108 \ '', 109 \ 'int func(int x)', 110 \ '{', 111 \ ' return x;', 112 \ '}', 113 \ ] 114 call XTest_goto_decl('gd', lines, 3, 14) 115endfunc 116 117func Test_gd_not_local() 118 let lines = [ 119 \ 'int func1(void)', 120 \ '{', 121 \ ' return x;', 122 \ '}', 123 \ '', 124 \ 'int func2(int x)', 125 \ '{', 126 \ ' return x;', 127 \ '}', 128 \ ] 129 call XTest_goto_decl('gd', lines, 3, 10) 130endfunc 131 132func Test_gd_kr_style() 133 let lines = [ 134 \ 'int func(x)', 135 \ ' int x;', 136 \ '{', 137 \ ' return x;', 138 \ '}', 139 \ ] 140 call XTest_goto_decl('gd', lines, 2, 7) 141endfunc 142 143func Test_gd_missing_braces() 144 let lines = [ 145 \ 'def func1(a)', 146 \ ' a + 1', 147 \ 'end', 148 \ '', 149 \ 'a = 1', 150 \ '', 151 \ 'def func2()', 152 \ ' return a', 153 \ 'end', 154 \ ] 155 call XTest_goto_decl('gd', lines, 1, 11) 156endfunc 157 158func Test_gd_comment() 159 let lines = [ 160 \ 'int func(void)', 161 \ '{', 162 \ ' /* int x; */', 163 \ ' int x;', 164 \ ' return x;', 165 \ '}', 166 \] 167 call XTest_goto_decl('gd', lines, 4, 7) 168endfunc 169 170func Test_gd_comment_in_string() 171 let lines = [ 172 \ 'int func(void)', 173 \ '{', 174 \ ' char *s ="//"; int x;', 175 \ ' int x;', 176 \ ' return x;', 177 \ '}', 178 \] 179 call XTest_goto_decl('gd', lines, 3, 22) 180endfunc 181 182func Test_gd_string_in_comment() 183 set comments= 184 let lines = [ 185 \ 'int func(void)', 186 \ '{', 187 \ ' /* " */ int x;', 188 \ ' int x;', 189 \ ' return x;', 190 \ '}', 191 \] 192 call XTest_goto_decl('gd', lines, 3, 15) 193 set comments& 194endfunc 195 196func Test_gd_inline_comment() 197 let lines = [ 198 \ 'int func(/* x is an int */ int x)', 199 \ '{', 200 \ ' return x;', 201 \ '}', 202 \ ] 203 call XTest_goto_decl('gd', lines, 1, 32) 204endfunc 205 206func Test_gd_inline_comment_only() 207 let lines = [ 208 \ 'int func(void) /* one lonely x */', 209 \ '{', 210 \ ' return x;', 211 \ '}', 212 \ ] 213 call XTest_goto_decl('gd', lines, 3, 10) 214endfunc 215 216func Test_gd_inline_comment_body() 217 let lines = [ 218 \ 'int func(void)', 219 \ '{', 220 \ ' int y /* , x */;', 221 \ '', 222 \ ' for (/* int x = 0 */; y < 2; y++);', 223 \ '', 224 \ ' int x = 0;', 225 \ '', 226 \ ' return x;', 227 \ '}', 228 \ ] 229 call XTest_goto_decl('gd', lines, 7, 7) 230endfunc 231 232func Test_gd_trailing_multiline_comment() 233 let lines = [ 234 \ 'int func(int x) /* x is an int */', 235 \ '{', 236 \ ' return x;', 237 \ '}', 238 \ ] 239 call XTest_goto_decl('gd', lines, 1, 14) 240endfunc 241 242func Test_gd_trailing_comment() 243 let lines = [ 244 \ 'int func(int x) // x is an int', 245 \ '{', 246 \ ' return x;', 247 \ '}', 248 \ ] 249 call XTest_goto_decl('gd', lines, 1, 14) 250endfunc 251 252func Test_gd_string() 253 let lines = [ 254 \ 'int func(void)', 255 \ '{', 256 \ ' char *s = "x";', 257 \ ' int x = 1;', 258 \ '', 259 \ ' return x;', 260 \ '}', 261 \ ] 262 call XTest_goto_decl('gd', lines, 4, 7) 263endfunc 264 265func Test_gd_string_only() 266 let lines = [ 267 \ 'int func(void)', 268 \ '{', 269 \ ' char *s = "x";', 270 \ '', 271 \ ' return x;', 272 \ '}', 273 \ ] 274 call XTest_goto_decl('gd', lines, 5, 10) 275endfunc 276 277" Check that setting 'cursorline' does not change curswant 278func Test_cursorline_keep_col() 279 new 280 call setline(1, ['long long long line', 'short line']) 281 normal ggfi 282 let pos = getcurpos() 283 normal j 284 set cursorline 285 normal k 286 call assert_equal(pos, getcurpos()) 287 bwipe! 288 set nocursorline 289endfunc 290 291func Test_gd_local_block() 292 let lines = [ 293 \ ' int main()', 294 \ '{', 295 \ ' char *a = "NOT NULL";', 296 \ ' if(a)', 297 \ ' {', 298 \ ' char *b = a;', 299 \ ' printf("%s\n", b);', 300 \ ' }', 301 \ ' else', 302 \ ' {', 303 \ ' char *b = "NULL";', 304 \ ' return b;', 305 \ ' }', 306 \ '', 307 \ ' return 0;', 308 \ '}', 309 \ ] 310 call XTest_goto_decl('1gd', lines, 11, 11) 311endfunc 312