Bram Moolenaar | 321efdd | 2016-07-15 17:09:11 +0200 | [diff] [blame] | 1 | " Test the netbeans interface. |
| 2 | |
Bram Moolenaar | b46fecd | 2019-06-15 17:58:09 +0200 | [diff] [blame] | 3 | source check.vim |
| 4 | CheckFeature netbeans_intg |
Bram Moolenaar | 321efdd | 2016-07-15 17:09:11 +0200 | [diff] [blame] | 5 | |
| 6 | source shared.vim |
| 7 | |
| 8 | let s:python = PythonProg() |
| 9 | if s:python == '' |
Bram Moolenaar | b46fecd | 2019-06-15 17:58:09 +0200 | [diff] [blame] | 10 | throw 'Skipped: python program missing' |
Bram Moolenaar | 321efdd | 2016-07-15 17:09:11 +0200 | [diff] [blame] | 11 | endif |
| 12 | |
Bram Moolenaar | 4b96df5 | 2020-01-26 22:00:26 +0100 | [diff] [blame] | 13 | " Run "testfunc" after starting the server and stop the server afterwards. |
Bram Moolenaar | 321efdd | 2016-07-15 17:09:11 +0200 | [diff] [blame] | 14 | func s:run_server(testfunc, ...) |
| 15 | call RunServer('test_netbeans.py', a:testfunc, a:000) |
| 16 | endfunc |
| 17 | |
Bram Moolenaar | 173d841 | 2020-04-19 14:02:26 +0200 | [diff] [blame] | 18 | " Wait for an exception (error) to be thrown. This is used to check whether a |
| 19 | " message from the netbeans server causes an error. It takes some time for Vim |
| 20 | " to process a netbeans message. So a sleep is used below to account for this. |
| 21 | func WaitForError(errcode) |
| 22 | let save_exception = '' |
| 23 | for i in range(200) |
| 24 | try |
| 25 | sleep 5m |
| 26 | catch |
| 27 | let save_exception = v:exception |
| 28 | break |
| 29 | endtry |
| 30 | endfor |
| 31 | call assert_match(a:errcode, save_exception) |
| 32 | endfunc |
| 33 | |
Bram Moolenaar | 321efdd | 2016-07-15 17:09:11 +0200 | [diff] [blame] | 34 | func Nb_basic(port) |
| 35 | call delete("Xnetbeans") |
Bram Moolenaar | c20e0d5 | 2017-11-02 18:19:19 +0100 | [diff] [blame] | 36 | call writefile([], "Xnetbeans") |
Bram Moolenaar | 173d841 | 2020-04-19 14:02:26 +0200 | [diff] [blame] | 37 | |
| 38 | " Last line number in the Xnetbeans file. Used to verify the result of the |
| 39 | " communication with the netbeans server |
| 40 | let g:last = 0 |
| 41 | |
| 42 | " Establish the connection with the netbeans server |
| 43 | exe 'nbstart :localhost:' .. a:port .. ':bunny' |
Bram Moolenaar | 321efdd | 2016-07-15 17:09:11 +0200 | [diff] [blame] | 44 | call assert_true(has("netbeans_enabled")) |
Bram Moolenaar | 173d841 | 2020-04-19 14:02:26 +0200 | [diff] [blame] | 45 | call WaitFor('len(readfile("Xnetbeans")) > (g:last + 2)') |
| 46 | let l = readfile("Xnetbeans") |
| 47 | call assert_equal(['AUTH bunny', |
| 48 | \ '0:version=0 "2.5"', |
| 49 | \ '0:startupDone=0'], l[-3:]) |
| 50 | let g:last += 3 |
Bram Moolenaar | 321efdd | 2016-07-15 17:09:11 +0200 | [diff] [blame] | 51 | |
Bram Moolenaar | 173d841 | 2020-04-19 14:02:26 +0200 | [diff] [blame] | 52 | " Trying to connect again to netbeans server should fail |
| 53 | call assert_fails("exe 'nbstart :localhost:' . a:port . ':bunny'", 'E511:') |
Bram Moolenaar | 321efdd | 2016-07-15 17:09:11 +0200 | [diff] [blame] | 54 | |
Bram Moolenaar | 173d841 | 2020-04-19 14:02:26 +0200 | [diff] [blame] | 55 | " Open the command buffer to communicate with the server |
| 56 | split Xcmdbuf |
| 57 | let cmdbufnr = bufnr() |
| 58 | call WaitFor('len(readfile("Xnetbeans")) > (g:last + 2)') |
| 59 | let l = readfile("Xnetbeans") |
| 60 | call assert_equal('0:fileOpened=0 "Xcmdbuf" T F', |
| 61 | \ substitute(l[-3], '".*/', '"', '')) |
| 62 | call assert_equal('send: 1:putBufferNumber!15 "Xcmdbuf"', |
| 63 | \ substitute(l[-2], '".*/', '"', '')) |
| 64 | call assert_equal('1:startDocumentListen!16', l[-1]) |
| 65 | let g:last += 3 |
Bram Moolenaar | 321efdd | 2016-07-15 17:09:11 +0200 | [diff] [blame] | 66 | |
Bram Moolenaar | 173d841 | 2020-04-19 14:02:26 +0200 | [diff] [blame] | 67 | " Keep the command buffer loaded for communication |
| 68 | hide |
| 69 | |
| 70 | sleep 1m |
| 71 | |
| 72 | " getCursor test |
| 73 | call writefile(['foo bar', 'foo bar', 'foo bar'], 'Xfile1') |
| 74 | split Xfile1 |
| 75 | call cursor(3, 4) |
| 76 | sleep 10m |
| 77 | call appendbufline(cmdbufnr, '$', 'getCursor_Test') |
| 78 | call WaitFor('len(readfile("Xnetbeans")) >= (g:last + 5)') |
| 79 | let l = readfile('Xnetbeans') |
| 80 | call assert_equal(['send: 0:getCursor/30', '30 -1 3 3 19'], l[-2:]) |
| 81 | let g:last += 5 |
| 82 | |
| 83 | " Test for E627 |
| 84 | call appendbufline(cmdbufnr, '$', 'E627_Test') |
| 85 | call WaitForError('E627:') |
| 86 | call WaitFor('len(readfile("Xnetbeans")) >= (g:last + 3)') |
| 87 | let l = readfile('Xnetbeans') |
| 88 | call assert_equal('send: 0 setReadOnly!31', l[-1]) |
| 89 | let g:last += 3 |
| 90 | |
| 91 | " Test for E628 |
| 92 | call appendbufline(cmdbufnr, '$', 'E628_Test') |
| 93 | call WaitForError('E628:') |
| 94 | call WaitFor('len(readfile("Xnetbeans")) >= (g:last + 3)') |
| 95 | let l = readfile('Xnetbeans') |
| 96 | call assert_equal('send: 0:setReadOnly 32', l[-1]) |
| 97 | let g:last += 3 |
| 98 | |
| 99 | " Test for E632 |
| 100 | call appendbufline(cmdbufnr, '$', 'E632_Test') |
| 101 | call WaitForError('E632:') |
| 102 | call WaitFor('len(readfile("Xnetbeans")) >= (g:last + 4)') |
| 103 | let l = readfile('Xnetbeans') |
| 104 | call assert_equal(['send: 0:getLength/33', '33 0'], l[-2:]) |
| 105 | let g:last += 4 |
| 106 | |
| 107 | " Test for E633 |
| 108 | call appendbufline(cmdbufnr, '$', 'E633_Test') |
| 109 | call WaitForError('E633:') |
| 110 | call WaitFor('len(readfile("Xnetbeans")) >= (g:last + 4)') |
| 111 | let l = readfile('Xnetbeans') |
| 112 | call assert_equal(['send: 0:getText/34', '34 '], l[-2:]) |
| 113 | let g:last += 4 |
| 114 | |
| 115 | " Test for E634 |
| 116 | call appendbufline(cmdbufnr, '$', 'E634_Test') |
| 117 | call WaitForError('E634:') |
| 118 | call WaitFor('len(readfile("Xnetbeans")) >= (g:last + 4)') |
| 119 | let l = readfile('Xnetbeans') |
| 120 | call assert_equal(['send: 0:remove/35 1 1', '35'], l[-2:]) |
| 121 | let g:last += 4 |
| 122 | |
| 123 | " Test for E635 |
| 124 | call appendbufline(cmdbufnr, '$', 'E635_Test') |
| 125 | call WaitForError('E635:') |
| 126 | call WaitFor('len(readfile("Xnetbeans")) >= (g:last + 4)') |
| 127 | let l = readfile('Xnetbeans') |
| 128 | call assert_equal(['send: 0:insert/36 0 "line1\n"', '36'], l[-2:]) |
| 129 | let g:last += 4 |
| 130 | |
| 131 | " Test for E636 |
| 132 | call appendbufline(cmdbufnr, '$', 'E636_Test') |
| 133 | call WaitForError('E636:') |
| 134 | call WaitFor('len(readfile("Xnetbeans")) >= (g:last + 3)') |
| 135 | let l = readfile('Xnetbeans') |
| 136 | call assert_equal('send: 0:create!37', l[-1]) |
| 137 | let g:last += 3 |
| 138 | |
| 139 | " Test for E637 |
| 140 | call appendbufline(cmdbufnr, '$', 'E637_Test') |
| 141 | call WaitForError('E637:') |
| 142 | call WaitFor('len(readfile("Xnetbeans")) >= (g:last + 3)') |
| 143 | let l = readfile('Xnetbeans') |
| 144 | call assert_equal('send: 0:startDocumentListen!38', l[-1]) |
| 145 | let g:last += 3 |
| 146 | |
| 147 | " Test for E638 |
| 148 | call appendbufline(cmdbufnr, '$', 'E638_Test') |
| 149 | call WaitForError('E638:') |
| 150 | call WaitFor('len(readfile("Xnetbeans")) >= (g:last + 3)') |
| 151 | let l = readfile('Xnetbeans') |
| 152 | call assert_equal('send: 0:stopDocumentListen!39', l[-1]) |
| 153 | let g:last += 3 |
| 154 | |
| 155 | " Test for E639 |
| 156 | call appendbufline(cmdbufnr, '$', 'E639_Test') |
| 157 | call WaitForError('E639:') |
| 158 | call WaitFor('len(readfile("Xnetbeans")) >= (g:last + 3)') |
| 159 | let l = readfile('Xnetbeans') |
| 160 | call assert_equal('send: 0:setTitle!40 "Title"', l[-1]) |
| 161 | let g:last += 3 |
| 162 | |
| 163 | " Test for E640 |
| 164 | call appendbufline(cmdbufnr, '$', 'E640_Test') |
| 165 | call WaitForError('E640:') |
| 166 | call WaitFor('len(readfile("Xnetbeans")) >= (g:last + 3)') |
| 167 | let l = readfile('Xnetbeans') |
| 168 | call assert_equal('send: 0:initDone!41', l[-1]) |
| 169 | let g:last += 3 |
| 170 | |
| 171 | " Test for E641 |
| 172 | call appendbufline(cmdbufnr, '$', 'E641_Test') |
| 173 | call WaitForError('E641:') |
| 174 | call WaitFor('len(readfile("Xnetbeans")) >= (g:last + 3)') |
| 175 | let l = readfile('Xnetbeans') |
| 176 | call assert_equal('send: 0:putBufferNumber!42 "XSomeBuf"', l[-1]) |
| 177 | let g:last += 3 |
| 178 | |
| 179 | " Test for E642 |
| 180 | call appendbufline(cmdbufnr, '$', 'E642_Test') |
| 181 | call WaitForError('E642:') |
| 182 | call WaitFor('len(readfile("Xnetbeans")) >= (g:last + 3)') |
| 183 | let l = readfile('Xnetbeans') |
| 184 | call assert_equal('send: 9:putBufferNumber!43 "XInvalidBuf"', l[-1]) |
| 185 | let g:last += 3 |
| 186 | |
| 187 | " Test for E643 |
| 188 | call appendbufline(cmdbufnr, '$', 'E643_Test') |
| 189 | call WaitForError('E643:') |
| 190 | call WaitFor('len(readfile("Xnetbeans")) >= (g:last + 3)') |
| 191 | let l = readfile('Xnetbeans') |
| 192 | call assert_equal('send: 0:setFullName!44 "XSomeBuf"', l[-1]) |
| 193 | let g:last += 3 |
| 194 | |
| 195 | enew! |
| 196 | |
| 197 | " Test for E644 |
| 198 | call appendbufline(cmdbufnr, '$', 'E644_Test') |
| 199 | call WaitForError('E644:') |
| 200 | call WaitFor('len(readfile("Xnetbeans")) >= (g:last + 3)') |
| 201 | let l = readfile('Xnetbeans') |
| 202 | call assert_equal('send: 0:editFile!45 "Xfile3"', l[-1]) |
| 203 | let g:last += 3 |
| 204 | |
| 205 | " Test for E645 (shown only when verbose > 0) |
| 206 | call appendbufline(cmdbufnr, '$', 'E645_Test') |
| 207 | set verbose=1 |
| 208 | call WaitForError('E645:') |
| 209 | set verbose& |
| 210 | call WaitFor('len(readfile("Xnetbeans")) >= (g:last + 3)') |
| 211 | let l = readfile('Xnetbeans') |
| 212 | call assert_equal('send: 0:setVisible!46 T', l[-1]) |
| 213 | let g:last += 3 |
| 214 | |
| 215 | " Test for E646 (shown only when verbose > 0) |
| 216 | call appendbufline(cmdbufnr, '$', 'E646_Test') |
| 217 | set verbose=1 |
| 218 | call WaitForError('E646:') |
| 219 | set verbose& |
| 220 | call WaitFor('len(readfile("Xnetbeans")) >= (g:last + 3)') |
| 221 | let l = readfile('Xnetbeans') |
| 222 | call assert_equal('send: 0:setModified!47 T', l[-1]) |
| 223 | let g:last += 3 |
| 224 | |
| 225 | " Test for E647 |
| 226 | call appendbufline(cmdbufnr, '$', 'E647_Test') |
| 227 | call WaitForError('E647:') |
| 228 | call WaitFor('len(readfile("Xnetbeans")) >= (g:last + 3)') |
| 229 | let l = readfile('Xnetbeans') |
| 230 | call assert_equal('send: 0:setDot!48 1/1', l[-1]) |
| 231 | let g:last += 3 |
| 232 | |
| 233 | " Test for E648 |
| 234 | call appendbufline(cmdbufnr, '$', 'E648_Test') |
| 235 | call WaitForError('E648:') |
| 236 | call WaitFor('len(readfile("Xnetbeans")) >= (g:last + 3)') |
| 237 | let l = readfile('Xnetbeans') |
| 238 | call assert_equal('send: 0:close!49', l[-1]) |
| 239 | let g:last += 3 |
| 240 | |
| 241 | " Test for E650 |
| 242 | call appendbufline(cmdbufnr, '$', 'E650_Test') |
| 243 | call WaitForError('E650:') |
| 244 | call WaitFor('len(readfile("Xnetbeans")) >= (g:last + 3)') |
| 245 | let l = readfile('Xnetbeans') |
| 246 | call assert_equal('send: 0:defineAnnoType!50 1 "abc" "a" "a" 1 1', l[-1]) |
| 247 | let g:last += 3 |
| 248 | |
| 249 | " Test for E651 |
| 250 | call appendbufline(cmdbufnr, '$', 'E651_Test') |
| 251 | call WaitForError('E651:') |
| 252 | call WaitFor('len(readfile("Xnetbeans")) >= (g:last + 3)') |
| 253 | let l = readfile('Xnetbeans') |
| 254 | call assert_equal('send: 0:addAnno!51 1 1 1 1', l[-1]) |
| 255 | let g:last += 3 |
| 256 | |
| 257 | " Test for E652 |
| 258 | call appendbufline(cmdbufnr, '$', 'E652_Test') |
| 259 | call WaitForError('E652:') |
| 260 | call WaitFor('len(readfile("Xnetbeans")) >= (g:last + 4)') |
| 261 | let l = readfile('Xnetbeans') |
| 262 | call assert_equal(['send: 0:getAnno/52 8', '52 0'], l[-2:]) |
| 263 | let g:last += 4 |
| 264 | |
| 265 | " editFile test |
| 266 | call writefile(['foo bar1', 'foo bar2', 'foo bar3'], 'Xfile3') |
| 267 | call appendbufline(cmdbufnr, '$', 'editFile_Test') |
| 268 | call WaitFor('len(readfile("Xnetbeans")) >= (g:last + 4)') |
| 269 | let l = readfile('Xnetbeans') |
| 270 | call assert_equal('send: 2:editFile!53 "Xfile3"', l[-2]) |
| 271 | call assert_match('0:fileOpened=0 ".*/Xfile3" T F', l[-1]) |
| 272 | call assert_equal('Xfile3', bufname()) |
| 273 | let g:last += 4 |
| 274 | |
| 275 | " getLength test |
| 276 | call appendbufline(cmdbufnr, '$', 'getLength_Test') |
| 277 | call WaitFor('len(readfile("Xnetbeans")) >= (g:last + 4)') |
| 278 | let l = readfile('Xnetbeans') |
| 279 | call assert_equal(['send: 2:getLength/54', '54 27'], l[-2:]) |
| 280 | let g:last += 4 |
| 281 | |
| 282 | " getModified test |
| 283 | call appendbufline(cmdbufnr, '$', 'getModified_Test') |
| 284 | call WaitFor('len(readfile("Xnetbeans")) >= (g:last + 4)') |
| 285 | let l = readfile('Xnetbeans') |
| 286 | call assert_equal(['send: 2:getModified/55', '55 0'], l[-2:]) |
| 287 | let g:last += 4 |
| 288 | |
| 289 | " getText test |
| 290 | call appendbufline(cmdbufnr, '$', 'getText_Test') |
| 291 | call WaitFor('len(readfile("Xnetbeans")) >= (g:last + 4)') |
| 292 | let l = readfile('Xnetbeans') |
| 293 | call assert_equal(['send: 2:getText/56', |
| 294 | \ '56 "foo bar1\nfoo bar2\nfoo bar3\n"'], l[-2:]) |
| 295 | let g:last += 4 |
| 296 | |
| 297 | " setDot test |
| 298 | call appendbufline(cmdbufnr, '$', 'setDot_Test') |
| 299 | call WaitFor('len(readfile("Xnetbeans")) >= (g:last + 3)') |
| 300 | let l = readfile('Xnetbeans') |
| 301 | call assert_equal('send: 2:setDot!57 3/6', l[-1]) |
| 302 | let g:last += 3 |
| 303 | |
| 304 | " startDocumentListen test |
| 305 | call appendbufline(cmdbufnr, '$', 'startDocumentListen_Test') |
| 306 | call WaitFor('len(readfile("Xnetbeans")) >= (g:last + 3)') |
| 307 | let l = readfile('Xnetbeans') |
| 308 | call assert_equal('send: 2:startDocumentListen!58', l[-1]) |
| 309 | let g:last += 3 |
| 310 | |
| 311 | " make some changes to the buffer and check whether the netbeans server |
| 312 | " received the notifications |
| 313 | call append(2, 'blue sky') |
| 314 | 1d |
| 315 | call WaitFor('len(readfile("Xnetbeans")) >= (g:last + 3)') |
| 316 | let l = readfile('Xnetbeans') |
| 317 | call assert_match('2:insert=\d\+ 18 "blue sky"', l[-3]) |
| 318 | call assert_match('2:insert=\d\+ 26 "\\n"', l[-2]) |
| 319 | call assert_match('2:remove=\d\+ 0 9', l[-1]) |
| 320 | let g:last += 3 |
| 321 | |
| 322 | " stopDocumentListen test |
| 323 | call appendbufline(cmdbufnr, '$', 'stopDocumentListen_Test') |
| 324 | call WaitFor('len(readfile("Xnetbeans")) >= (g:last + 3)') |
| 325 | let l = readfile('Xnetbeans') |
| 326 | call assert_equal('send: 2:stopDocumentListen!59', l[-1]) |
| 327 | let g:last += 3 |
| 328 | |
| 329 | " Wait for vim to process the previous netbeans message |
| 330 | sleep 1m |
| 331 | |
| 332 | " modify the buffer and make sure that the netbeans server is not notified |
| 333 | call append(2, 'clear sky') |
| 334 | 1d |
| 335 | |
| 336 | " defineAnnoType test |
| 337 | call appendbufline(cmdbufnr, '$', 'define_anno_Test') |
| 338 | call WaitFor('len(readfile("Xnetbeans")) >= (g:last + 3)') |
| 339 | let l = readfile('Xnetbeans') |
| 340 | call assert_equal('send: 2:defineAnnoType!60 1 "s1" "x" "=>" blue none', l[-1]) |
| 341 | sleep 1m |
Bram Moolenaar | 37d1b4f | 2020-05-13 17:16:04 +0200 | [diff] [blame] | 342 | call assert_equal({'name': '1', 'texthl': 'NB_s1', 'text': '=>'}, |
| 343 | \ sign_getdefined()[0]) |
Bram Moolenaar | 173d841 | 2020-04-19 14:02:26 +0200 | [diff] [blame] | 344 | let g:last += 3 |
| 345 | |
| 346 | " defineAnnoType with a long color name |
| 347 | call appendbufline(cmdbufnr, '$', 'E532_Test') |
| 348 | call WaitForError('E532:') |
| 349 | call WaitFor('len(readfile("Xnetbeans")) >= (g:last + 3)') |
| 350 | let l = readfile('Xnetbeans') |
| 351 | call assert_equal('send: 2:defineAnnoType!61 1 "s1" "x" "=>" aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa none', l[-1]) |
| 352 | let g:last += 3 |
| 353 | |
| 354 | " addAnno test |
| 355 | call appendbufline(cmdbufnr, '$', 'add_anno_Test') |
| 356 | call WaitFor('len(readfile("Xnetbeans")) >= (g:last + 3)') |
| 357 | let l = readfile('Xnetbeans') |
| 358 | call assert_equal('send: 2:addAnno!62 1 1 2/1 0', l[-1]) |
| 359 | sleep 1m |
| 360 | call assert_equal([{'lnum': 2, 'id': 1, 'name': '1', 'priority': 10, |
| 361 | \ 'group': ''}], sign_getplaced()[0].signs) |
| 362 | let g:last += 3 |
| 363 | |
| 364 | " getAnno test |
| 365 | call appendbufline(cmdbufnr, '$', 'get_anno_Test') |
| 366 | call WaitFor('len(readfile("Xnetbeans")) >= (g:last + 4)') |
| 367 | let l = readfile('Xnetbeans') |
| 368 | call assert_equal(['send: 2:getAnno/63 1', '63 2'], l[-2:]) |
| 369 | let g:last += 4 |
| 370 | |
| 371 | " removeAnno test |
| 372 | call appendbufline(cmdbufnr, '$', 'remove_anno_Test') |
| 373 | call WaitFor('len(readfile("Xnetbeans")) >= (g:last + 3)') |
| 374 | let l = readfile('Xnetbeans') |
| 375 | call assert_equal('send: 2:removeAnno!64 1', l[-1]) |
| 376 | sleep 1m |
| 377 | call assert_equal([], sign_getplaced()) |
| 378 | let g:last += 3 |
| 379 | |
| 380 | " getModified test to get the number of modified buffers |
| 381 | call appendbufline(cmdbufnr, '$', 'getModifiedAll_Test') |
| 382 | call WaitFor('len(readfile("Xnetbeans")) >= (g:last + 4)') |
| 383 | let l = readfile('Xnetbeans') |
| 384 | call assert_equal(['send: 0:getModified/65', '65 2'], l[-2:]) |
| 385 | let g:last += 4 |
| 386 | |
| 387 | let bufcount = len(getbufinfo()) |
| 388 | |
| 389 | " create test to create a new buffer |
| 390 | call appendbufline(cmdbufnr, '$', 'create_Test') |
| 391 | call WaitFor('len(readfile("Xnetbeans")) >= (g:last + 3)') |
| 392 | let l = readfile('Xnetbeans') |
| 393 | call assert_equal('send: 3:create!66', l[-1]) |
| 394 | " Wait for vim to process the previous netbeans message |
| 395 | sleep 10m |
| 396 | call assert_equal(bufcount + 1, len(getbufinfo())) |
| 397 | let g:last += 3 |
| 398 | |
| 399 | " setTitle test |
| 400 | call appendbufline(cmdbufnr, '$', 'setTitle_Test') |
| 401 | call WaitFor('len(readfile("Xnetbeans")) >= (g:last + 3)') |
| 402 | let l = readfile('Xnetbeans') |
| 403 | call assert_equal('send: 3:setTitle!67 "Xfile4"', l[-1]) |
| 404 | let g:last += 3 |
| 405 | |
| 406 | " setFullName test |
| 407 | call appendbufline(cmdbufnr, '$', 'setFullName_Test') |
| 408 | call WaitFor('len(readfile("Xnetbeans")) >= (g:last + 5)') |
| 409 | let l = readfile('Xnetbeans') |
| 410 | call assert_equal('send: 3:setFullName!68 "Xfile4"', l[-3]) |
| 411 | call assert_match('0:fileOpened=0 ".*/Xfile4" T F', l[-1]) |
| 412 | call assert_equal('Xfile4', bufname()) |
| 413 | let g:last += 5 |
| 414 | |
| 415 | " initDone test |
| 416 | call appendbufline(cmdbufnr, '$', 'initDone_Test') |
| 417 | call WaitFor('len(readfile("Xnetbeans")) >= (g:last + 3)') |
| 418 | let l = readfile('Xnetbeans') |
| 419 | call assert_equal('send: 3:initDone!69', l[-1]) |
| 420 | let g:last += 3 |
| 421 | |
| 422 | " setVisible test |
| 423 | hide enew |
| 424 | call appendbufline(cmdbufnr, '$', 'setVisible_Test') |
| 425 | call WaitFor('len(readfile("Xnetbeans")) >= (g:last + 3)') |
| 426 | let l = readfile('Xnetbeans') |
| 427 | call assert_equal('send: 3:setVisible!70 T', l[-1]) |
| 428 | let g:last += 3 |
| 429 | |
| 430 | " setModtime test |
| 431 | call appendbufline(cmdbufnr, '$', 'setModtime_Test') |
| 432 | call WaitFor('len(readfile("Xnetbeans")) >= (g:last + 3)') |
| 433 | let l = readfile('Xnetbeans') |
| 434 | call assert_equal('send: 3:setModtime!71 6', l[-1]) |
| 435 | let g:last += 3 |
| 436 | |
| 437 | " insert test |
| 438 | call appendbufline(cmdbufnr, '$', 'insert_Test') |
| 439 | call WaitFor('len(readfile("Xnetbeans")) >= (g:last + 4)') |
| 440 | let l = readfile('Xnetbeans') |
| 441 | call assert_equal(['send: 3:insert/72 0 "line1\nline2\n"', '72'], l[-2:]) |
| 442 | call assert_equal(['line1', 'line2'], getline(1, '$')) |
| 443 | let g:last += 4 |
| 444 | |
| 445 | " remove test |
| 446 | call appendbufline(cmdbufnr, '$', 'remove_Test') |
| 447 | call WaitFor('len(readfile("Xnetbeans")) >= (g:last + 4)') |
| 448 | let l = readfile('Xnetbeans') |
| 449 | call assert_equal(['send: 3:remove/73 3 4', '73'], l[-2:]) |
| 450 | call assert_equal(['linine2'], getline(1, '$')) |
| 451 | let g:last += 4 |
| 452 | |
| 453 | " remove with invalid offset |
| 454 | call appendbufline(cmdbufnr, '$', 'remove_invalid_offset_Test') |
| 455 | call WaitFor('len(readfile("Xnetbeans")) >= (g:last + 4)') |
| 456 | let l = readfile('Xnetbeans') |
| 457 | call assert_equal(['send: 3:remove/74 900 4', '74 !bad position'], l[-2:]) |
| 458 | let g:last += 4 |
| 459 | |
| 460 | " remove with invalid count |
| 461 | call appendbufline(cmdbufnr, '$', 'remove_invalid_count_Test') |
| 462 | call WaitFor('len(readfile("Xnetbeans")) >= (g:last + 4)') |
| 463 | let l = readfile('Xnetbeans') |
| 464 | call assert_equal(['send: 3:remove/75 1 800', '75 !bad count'], l[-2:]) |
| 465 | let g:last += 4 |
| 466 | |
| 467 | " guard test |
| 468 | %d |
| 469 | call setline(1, ['foo bar', 'foo bar', 'foo bar']) |
| 470 | call WaitFor('len(readfile("Xnetbeans")) >= (g:last + 8)') |
| 471 | let g:last += 8 |
| 472 | |
| 473 | call appendbufline(cmdbufnr, '$', 'guard_Test') |
| 474 | call WaitFor('len(readfile("Xnetbeans")) >= (g:last + 3)') |
| 475 | let l = readfile('Xnetbeans') |
| 476 | call assert_equal('send: 3:guard!76 8 7', l[-1]) |
| 477 | sleep 1m |
| 478 | " second line is guarded. Try modifying the line |
| 479 | call assert_fails('normal 2GIbaz', 'E463:') |
| 480 | call assert_fails('normal 2GAbaz', 'E463:') |
| 481 | call assert_fails('normal dd', 'E463:') |
| 482 | call assert_equal([{'name': '1', 'texthl': 'NB_s1', 'text': '=>'}, |
| 483 | \ {'name': '10000', 'linehl': 'NBGuarded'}], |
| 484 | \ sign_getdefined()) |
| 485 | call assert_equal([{'lnum': 2, 'id': 1000000, 'name': '10000', |
| 486 | \ 'priority': 10, 'group': ''}], sign_getplaced()[0].signs) |
| 487 | let g:last += 3 |
| 488 | |
| 489 | " setModified test |
| 490 | call appendbufline(cmdbufnr, '$', 'setModified_Test') |
| 491 | call WaitFor('len(readfile("Xnetbeans")) >= (g:last + 3)') |
| 492 | let l = readfile('Xnetbeans') |
| 493 | call assert_equal('send: 3:setModified!77 T', l[-1]) |
| 494 | call assert_equal(1, &modified) |
| 495 | let g:last += 3 |
| 496 | |
| 497 | " insertDone test |
| 498 | let v:statusmsg = '' |
| 499 | call appendbufline(cmdbufnr, '$', 'insertDone_Test') |
| 500 | call WaitFor('len(readfile("Xnetbeans")) >= (g:last + 3)') |
| 501 | let l = readfile('Xnetbeans') |
| 502 | call assert_equal('send: 3:insertDone!78 T F', l[-1]) |
| 503 | sleep 1m |
| 504 | call assert_match('.*/Xfile4" 3L, 0C', v:statusmsg) |
| 505 | let g:last += 3 |
| 506 | |
| 507 | " saveDone test |
| 508 | let v:statusmsg = '' |
| 509 | call appendbufline(cmdbufnr, '$', 'saveDone_Test') |
| 510 | call WaitFor('len(readfile("Xnetbeans")) >= (g:last + 3)') |
| 511 | let l = readfile('Xnetbeans') |
| 512 | call assert_equal('send: 3:saveDone!79', l[-1]) |
| 513 | sleep 1m |
| 514 | call assert_match('.*/Xfile4" 3L, 0C', v:statusmsg) |
| 515 | let g:last += 3 |
| 516 | |
| 517 | " unimplemented command test |
| 518 | call appendbufline(cmdbufnr, '$', 'invalidcmd_Test') |
| 519 | call WaitFor('len(readfile("Xnetbeans")) >= (g:last + 3)') |
| 520 | let l = readfile('Xnetbeans') |
| 521 | call assert_equal('send: 3:invalidcmd!80', l[-1]) |
| 522 | let g:last += 3 |
| 523 | |
| 524 | " unimplemented function test |
| 525 | call appendbufline(cmdbufnr, '$', 'invalidfunc_Test') |
| 526 | call WaitFor('len(readfile("Xnetbeans")) >= (g:last + 4)') |
| 527 | let l = readfile('Xnetbeans') |
| 528 | call assert_equal(['send: 3:invalidfunc/81', '81'], l[-2:]) |
| 529 | let g:last += 4 |
| 530 | |
| 531 | " Test for removeAnno cmd failure |
| 532 | call appendbufline(cmdbufnr, '$', 'removeAnno_fail_Test') |
| 533 | call WaitFor('len(readfile("Xnetbeans")) >= (g:last + 4)') |
| 534 | let l = readfile('Xnetbeans') |
| 535 | call assert_equal(['send: 0:removeAnno/82 1', '82'], l[-2:]) |
| 536 | let g:last += 4 |
| 537 | |
| 538 | " Test for guard cmd failure |
| 539 | call appendbufline(cmdbufnr, '$', 'guard_fail_Test') |
| 540 | call WaitFor('len(readfile("Xnetbeans")) >= (g:last + 4)') |
| 541 | let l = readfile('Xnetbeans') |
| 542 | call assert_equal(['send: 0:guard/83 1 1', '83'], l[-2:]) |
| 543 | let g:last += 4 |
| 544 | |
| 545 | " Test for save cmd failure |
| 546 | call appendbufline(cmdbufnr, '$', 'save_fail_Test') |
| 547 | call WaitFor('len(readfile("Xnetbeans")) >= (g:last + 4)') |
| 548 | let l = readfile('Xnetbeans') |
| 549 | call assert_equal(['send: 0:save/84', '84'], l[-2:]) |
| 550 | let g:last += 4 |
| 551 | |
| 552 | " Test for netbeansBuffer cmd failure |
| 553 | call appendbufline(cmdbufnr, '$', 'netbeansBuffer_fail_Test') |
| 554 | call WaitFor('len(readfile("Xnetbeans")) >= (g:last + 4)') |
| 555 | let l = readfile('Xnetbeans') |
| 556 | call assert_equal(['send: 0:netbeansBuffer/85 T', '85'], l[-2:]) |
| 557 | let g:last += 4 |
| 558 | |
| 559 | " nbkey test |
| 560 | call cursor(3, 3) |
| 561 | nbkey "\<C-F2>" |
| 562 | call WaitFor('len(readfile("Xnetbeans")) >= (g:last + 3)') |
| 563 | let l = readfile('Xnetbeans') |
| 564 | call assert_equal(['3:newDotAndMark=85 18 18', |
| 565 | \ '3:keyCommand=85 ""\<C-F2>""', |
| 566 | \ '3:keyAtPos=85 ""\<C-F2>"" 18 3/2'], l[-3:]) |
| 567 | let g:last += 3 |
| 568 | |
| 569 | " setExitDelay test |
| 570 | call appendbufline(cmdbufnr, '$', 'setExitDelay_Test') |
| 571 | call WaitFor('len(readfile("Xnetbeans")) >= (g:last + 3)') |
| 572 | let l = readfile('Xnetbeans') |
| 573 | call assert_equal('send: 0:setExitDelay!86 2', l[-1]) |
| 574 | let g:last += 3 |
| 575 | |
| 576 | " setReadonly test |
| 577 | call appendbufline(cmdbufnr, '$', 'setReadOnly_Test') |
| 578 | call WaitFor('len(readfile("Xnetbeans")) >= (g:last + 3)') |
| 579 | let l = readfile('Xnetbeans') |
| 580 | call assert_equal('send: 3:setReadOnly!87', l[-1]) |
| 581 | let g:last += 3 |
| 582 | |
| 583 | " close test. Don't use buffer 10 after this |
| 584 | call appendbufline(cmdbufnr, '$', 'close_Test') |
| 585 | call WaitFor('len(readfile("Xnetbeans")) >= (g:last + 4)') |
| 586 | let l = readfile('Xnetbeans') |
| 587 | call assert_equal('send: 3:close!88', l[-2]) |
| 588 | call assert_equal('3:killed=88', l[-1]) |
| 589 | call assert_equal(1, winnr('$')) |
| 590 | let g:last += 4 |
| 591 | |
| 592 | " specialKeys test |
| 593 | call appendbufline(cmdbufnr, '$', 'specialKeys_Test') |
| 594 | call WaitFor('len(readfile("Xnetbeans")) >= (g:last + 3)') |
| 595 | let l = readfile('Xnetbeans') |
| 596 | call assert_equal('send: 0:specialKeys!89 "F12 F13"', l[-1]) |
| 597 | sleep 1m |
| 598 | call assert_equal(':nbkey F12<CR>', maparg('<F12>', 'n')) |
| 599 | call assert_equal(':nbkey F13<CR>', maparg('<F13>', 'n')) |
| 600 | let g:last += 3 |
| 601 | |
| 602 | " Open a buffer not monitored by netbeans |
| 603 | enew | only! |
| 604 | nbkey "\<C-F3>" |
| 605 | call WaitFor('len(readfile("Xnetbeans")) >= (g:last + 1)') |
| 606 | let l = readfile('Xnetbeans') |
| 607 | call assert_equal('0:fileOpened=0 "" T F', l[-1]) |
| 608 | let g:last += 1 |
| 609 | |
Bram Moolenaar | 494e906 | 2020-05-31 21:28:02 +0200 | [diff] [blame] | 610 | " Test for writing a netbeans buffer |
| 611 | call appendbufline(cmdbufnr, '$', 'nbbufwrite_Test') |
| 612 | call WaitFor('len(readfile("Xnetbeans")) >= (g:last + 5)') |
| 613 | call assert_fails('write', 'E656:') |
| 614 | call setline(1, ['one', 'two']) |
| 615 | call assert_fails('1write!', 'E657:') |
| 616 | write |
| 617 | call WaitFor('len(readfile("Xnetbeans")) >= (g:last + 10)') |
| 618 | let g:last += 10 |
| 619 | |
Bram Moolenaar | 173d841 | 2020-04-19 14:02:26 +0200 | [diff] [blame] | 620 | " detach |
| 621 | call appendbufline(cmdbufnr, '$', 'detach_Test') |
Bram Moolenaar | 0b39ec3 | 2020-05-17 22:33:53 +0200 | [diff] [blame] | 622 | call WaitFor('len(readfile("Xnetbeans")) >= (g:last + 8)') |
Bram Moolenaar | 494e906 | 2020-05-31 21:28:02 +0200 | [diff] [blame] | 623 | call WaitForAssert({-> assert_equal('0:disconnect=93', readfile("Xnetbeans")[-1])}) |
Bram Moolenaar | 173d841 | 2020-04-19 14:02:26 +0200 | [diff] [blame] | 624 | |
Bram Moolenaar | 37d1b4f | 2020-05-13 17:16:04 +0200 | [diff] [blame] | 625 | " the connection was closed |
Bram Moolenaar | 8ddef48 | 2016-10-09 15:43:25 +0200 | [diff] [blame] | 626 | call assert_false(has("netbeans_enabled")) |
Bram Moolenaar | 321efdd | 2016-07-15 17:09:11 +0200 | [diff] [blame] | 627 | |
| 628 | call delete("Xnetbeans") |
Bram Moolenaar | 173d841 | 2020-04-19 14:02:26 +0200 | [diff] [blame] | 629 | call delete('Xfile1') |
| 630 | call delete('Xfile3') |
Bram Moolenaar | 321efdd | 2016-07-15 17:09:11 +0200 | [diff] [blame] | 631 | endfunc |
| 632 | |
| 633 | func Test_nb_basic() |
| 634 | call ch_log('Test_nb_basic') |
| 635 | call s:run_server('Nb_basic') |
| 636 | endfunc |
Bram Moolenaar | 603d657 | 2016-07-15 17:41:56 +0200 | [diff] [blame] | 637 | |
| 638 | func Nb_file_auth(port) |
Bram Moolenaar | c20e0d5 | 2017-11-02 18:19:19 +0100 | [diff] [blame] | 639 | call delete("Xnetbeans") |
| 640 | call writefile([], "Xnetbeans") |
| 641 | |
Bram Moolenaar | 603d657 | 2016-07-15 17:41:56 +0200 | [diff] [blame] | 642 | call assert_fails('nbstart =notexist', 'E660:') |
| 643 | call writefile(['host=localhost', 'port=' . a:port, 'auth=bunny'], 'Xnbauth') |
Bram Moolenaar | 53bdec2 | 2016-07-20 00:03:18 +0200 | [diff] [blame] | 644 | if has('unix') |
| 645 | call setfperm('Xnbauth', "rw-r--r--") |
| 646 | call assert_fails('nbstart =Xnbauth', 'E668:') |
| 647 | endif |
Bram Moolenaar | 603d657 | 2016-07-15 17:41:56 +0200 | [diff] [blame] | 648 | call setfperm('Xnbauth', "rw-------") |
Bram Moolenaar | ffdf08c | 2016-08-27 19:52:47 +0200 | [diff] [blame] | 649 | exe 'nbstart =Xnbauth' |
Bram Moolenaar | 603d657 | 2016-07-15 17:41:56 +0200 | [diff] [blame] | 650 | call assert_true(has("netbeans_enabled")) |
| 651 | |
| 652 | call WaitFor('len(readfile("Xnetbeans")) > 2') |
| 653 | nbclose |
| 654 | let lines = readfile("Xnetbeans") |
| 655 | call assert_equal('AUTH bunny', lines[0]) |
| 656 | call assert_equal('0:version=0 "2.5"', lines[1]) |
| 657 | call assert_equal('0:startupDone=0', lines[2]) |
| 658 | |
| 659 | call delete("Xnbauth") |
| 660 | call delete("Xnetbeans") |
| 661 | endfunc |
| 662 | |
| 663 | func Test_nb_file_auth() |
| 664 | call ch_log('Test_nb_file_auth') |
| 665 | call s:run_server('Nb_file_auth') |
| 666 | endfunc |
Bram Moolenaar | 173d841 | 2020-04-19 14:02:26 +0200 | [diff] [blame] | 667 | |
| 668 | " Test for quiting Vim with an open netbeans connection |
| 669 | func Nb_quit_with_conn(port) |
| 670 | call delete("Xnetbeans") |
| 671 | call writefile([], "Xnetbeans") |
| 672 | let after =<< trim END |
| 673 | source shared.vim |
| 674 | |
| 675 | " Establish the connection with the netbeans server |
| 676 | exe 'nbstart :localhost:' .. g:port .. ':star' |
| 677 | call assert_true(has("netbeans_enabled")) |
| 678 | call WaitFor('len(readfile("Xnetbeans")) >= 3') |
| 679 | let l = readfile("Xnetbeans") |
| 680 | call assert_equal(['AUTH star', |
| 681 | \ '0:version=0 "2.5"', |
| 682 | \ '0:startupDone=0'], l[-3:]) |
| 683 | |
| 684 | " Open the command buffer to communicate with the server |
| 685 | split Xcmdbuf |
| 686 | call WaitFor('len(readfile("Xnetbeans")) >= 6') |
| 687 | let l = readfile("Xnetbeans") |
| 688 | call assert_equal('0:fileOpened=0 "Xcmdbuf" T F', |
| 689 | \ substitute(l[-3], '".*/', '"', '')) |
| 690 | call assert_equal('send: 1:putBufferNumber!15 "Xcmdbuf"', |
| 691 | \ substitute(l[-2], '".*/', '"', '')) |
| 692 | call assert_equal('1:startDocumentListen!16', l[-1]) |
| 693 | sleep 1m |
| 694 | |
| 695 | quit! |
| 696 | quit! |
| 697 | END |
| 698 | if RunVim(['let g:port = ' .. a:port], after, '') |
| 699 | call WaitFor('len(readfile("Xnetbeans")) >= 9') |
| 700 | let l = readfile('Xnetbeans') |
| 701 | call assert_equal('1:unmodified=16', l[-3]) |
| 702 | call assert_equal('1:killed=16', l[-2]) |
| 703 | call assert_equal('0:disconnect=16', l[-1]) |
| 704 | endif |
| 705 | call delete('Xnetbeans') |
| 706 | endfunc |
| 707 | |
| 708 | func Test_nb_quit_with_conn() |
| 709 | " Exiting Vim with a netbeans connection doesn't work properly on |
| 710 | " MS-Windows. |
| 711 | CheckUnix |
| 712 | call s:run_server('Nb_quit_with_conn') |
| 713 | endfunc |
| 714 | |
| 715 | " vim: shiftwidth=2 sts=2 expandtab |