To: vim_dev@googlegroups.com Subject: Patch 8.2.1942 Fcc: outbox From: Bram Moolenaar Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ------------ Patch 8.2.1942 Problem: Insufficient test coverage for the Netbeans interface. Solution: Add more tests. Fix an uncovered bug. (Yegappan Lakshmanan, closes #7240) Files: runtime/doc/netbeans.txt, src/mouse.c, src/testdir/test_netbeans.py, src/testdir/test_netbeans.vim, src/testdir/test_quickfix.vim *** ../vim-8.2.1941/runtime/doc/netbeans.txt 2020-04-19 14:02:22.423687037 +0200 --- runtime/doc/netbeans.txt 2020-11-02 20:02:11.424064518 +0100 *************** *** 362,373 **** offset A number argument that indicates a byte position in a buffer. The first byte has offset zero. Line breaks are counted for how they appear in the file (CR/LF counts for two bytes). ! Note that a multi-byte character is counted for the number of bytes it takes. lnum/col Argument with a line number and column number position. The line number starts with one, the column is the byte position, ! starting with zero. Note that a multi-byte character counts for several columns. pathname String argument: file name with full path. --- 362,373 ---- offset A number argument that indicates a byte position in a buffer. The first byte has offset zero. Line breaks are counted for how they appear in the file (CR/LF counts for two bytes). ! Note that a multibyte character is counted for the number of bytes it takes. lnum/col Argument with a line number and column number position. The line number starts with one, the column is the byte position, ! starting with zero. Note that a multibyte character counts for several columns. pathname String argument: file name with full path. *************** *** 562,570 **** saved directly by the Vim Controller. New in version 2.3. ! setReadOnly ! Set a file as readonly ! Implemented in version 2.3. setStyle Not implemented. --- 562,571 ---- saved directly by the Vim Controller. New in version 2.3. ! setReadOnly readonly ! When the boolean argument "readonly" is "T" for True, mark the ! buffer as readonly, when it is "F" for False, mark it as not ! readonly. Implemented in version 2.3. setStyle Not implemented. *** ../vim-8.2.1941/src/mouse.c 2020-09-08 22:45:31.113504961 +0200 --- src/mouse.c 2020-11-02 19:58:58.364583736 +0100 *************** *** 2929,2938 **** // skip line number and fold column in front of the line col -= win_col_off(win); ! if (col < 0) { #ifdef FEAT_NETBEANS_INTG ! netbeans_gutter_click(lnum); #endif col = 0; } --- 2929,2940 ---- // skip line number and fold column in front of the line col -= win_col_off(win); ! if (col <= 0) { #ifdef FEAT_NETBEANS_INTG ! // if mouse is clicked on the gutter, then inform the netbeans server ! if (*colp < win_col_off(win)) ! netbeans_gutter_click(lnum); #endif col = 0; } *** ../vim-8.2.1941/src/testdir/test_netbeans.py 2020-05-31 21:27:58.331221914 +0200 --- src/testdir/test_netbeans.py 2020-11-02 19:58:58.364583736 +0100 *************** *** 41,46 **** --- 41,48 ---- elif re.match('1:insert=.* "\\\\n"', line): # extract the command from the previous line cmd = re.search('.*"(.*)"', self.prev_line).group(1) + + # map of test names and the netbeans commands/functions testmap = { 'getCursor_Test' : '0:getCursor/30\n', 'E627_Test' : '0 setReadOnly!31\n', *************** *** 70,75 **** --- 72,78 ---- 'getModified_Test' : '2:getModified/55\n', 'getText_Test' : '2:getText/56\n', 'setDot_Test' : '2:setDot!57 3/6\n', + 'setDot2_Test' : '2:setDot!57 9\n', 'startDocumentListen_Test' : '2:startDocumentListen!58\n', 'stopDocumentListen_Test' : '2:stopDocumentListen!59\n', 'define_anno_Test' : '2:defineAnnoType!60 1 "s1" "x" "=>" blue none\n', *************** *** 90,95 **** --- 93,99 ---- 'remove_invalid_count_Test' : '3:remove/75 1 800\n', 'guard_Test' : '3:guard!76 8 7\n', 'setModified_Test' : '3:setModified!77 T\n', + 'setModifiedClear_Test' : '3:setModified!77 F\n', 'insertDone_Test' : '3:insertDone!78 T F\n', 'saveDone_Test' : '3:saveDone!79\n', 'invalidcmd_Test' : '3:invalidcmd!80\n', *************** *** 99,109 **** 'save_fail_Test' : '0:save/84\n', 'netbeansBuffer_fail_Test' : '0:netbeansBuffer/85 T\n', 'setExitDelay_Test' : '0:setExitDelay!86 2\n', ! 'setReadOnly_Test' : '3:setReadOnly!87\n', ! 'close_Test' : '3:close!88\n', ! 'specialKeys_Test' : '0:specialKeys!89 "F12 F13"\n', ! 'nbbufwrite_Test' : '4:editFile!90 "XnbBuffer"\n4:netbeansBuffer!91 T\n', ! 'detach_Test' : '2:close!92\n1:close!93\nDETACH\n' } # execute the specified test if cmd not in testmap: --- 103,118 ---- 'save_fail_Test' : '0:save/84\n', 'netbeansBuffer_fail_Test' : '0:netbeansBuffer/85 T\n', 'setExitDelay_Test' : '0:setExitDelay!86 2\n', ! 'setReadOnly_Test' : '3:setReadOnly!87 T\n', ! 'setReadOnlyClear_Test' : '3:setReadOnly!88 F\n', ! 'save_Test' : '3:save!89\n', ! 'close_Test' : '3:close!90\n', ! 'specialKeys_Test' : '0:specialKeys!91 "F12 F13 C-F13"\n', ! 'nbbufwrite_Test' : '4:editFile!92 "XnbBuffer"\n4:netbeansBuffer!93 T\n', ! 'startAtomic_Test' : '0:startAtomic!94\n', ! 'endAtomic_Test' : '0:endAtomic!95\n', ! 'AnnoScale_Test' : "".join(['2:defineAnnoType!60 ' + str(i) + ' "s' + str(i) + '" "x" "=>" blue none\n' for i in range(2, 26)]), ! 'detach_Test' : '2:close!96\n1:close!97\nDETACH\n' } # execute the specified test if cmd not in testmap: *** ../vim-8.2.1941/src/testdir/test_netbeans.vim 2020-07-19 18:24:28.394951652 +0200 --- src/testdir/test_netbeans.vim 2020-11-02 19:58:58.364583736 +0100 *************** *** 303,313 **** \ '56 "foo bar1\nfoo bar2\nfoo bar3\n"'], l[-2:]) let g:last += 4 ! " setDot test call appendbufline(cmdbufnr, '$', 'setDot_Test') call WaitFor('len(ReadXnetbeans()) >= (g:last + 3)') let l = ReadXnetbeans() call assert_equal('send: 2:setDot!57 3/6', l[-1]) let g:last += 3 " startDocumentListen test --- 303,324 ---- \ '56 "foo bar1\nfoo bar2\nfoo bar3\n"'], l[-2:]) let g:last += 4 ! " setDot test with lnum/col ! call cursor(1, 1) call appendbufline(cmdbufnr, '$', 'setDot_Test') call WaitFor('len(ReadXnetbeans()) >= (g:last + 3)') let l = ReadXnetbeans() call assert_equal('send: 2:setDot!57 3/6', l[-1]) + call assert_equal([0, 3, 7, 0], getpos('.')) + let g:last += 3 + + " setDot test with an offset + call cursor(1, 1) + call appendbufline(cmdbufnr, '$', 'setDot2_Test') + call WaitFor('len(ReadXnetbeans()) >= (g:last + 3)') + let l = ReadXnetbeans() + call assert_equal('send: 2:setDot!57 9', l[-1]) + call assert_equal([0, 2, 1, 0], getpos('.')) let g:last += 3 " startDocumentListen test *************** *** 328,333 **** --- 339,370 ---- call assert_match('2:remove=\d\+ 0 9', l[-1]) let g:last += 3 + " Change case using the ~ command with 'whichwrap' containing '~' + set whichwrap+=~ + normal 2G$~ + set whichwrap& + call WaitFor('len(ReadXnetbeans()) >= (g:last + 2)') + let l = ReadXnetbeans() + call assert_match('2:remove=\d\+ 16 1', l[-4]) + call assert_match('2:insert=\d\+ 16 "Y"', l[-3]) + call assert_match('2:remove=\d\+ 18 0', l[-2]) + call assert_match('2:insert=\d\+ 18 ""', l[-1]) + let g:last += 4 + + " Test for replacing spaces with a tab character using 'softtabstop' and + " 'noexpandtab' + setlocal softtabstop=4 + setlocal noexpandtab + exe "normal I\\" + setlocal expandtab& + setlocal softtabstop& + call WaitFor('len(ReadXnetbeans()) >= (g:last + 18)') + let l = ReadXnetbeans() + call assert_match('2:insert=\d\+ 18 " foo bar3"', l[-3]) + call assert_match('2:remove=\d\+ 26 8', l[-2]) + call assert_match('2:insert=\d\+ 26 "\t"', l[-1]) + let g:last += 18 + " stopDocumentListen test call appendbufline(cmdbufnr, '$', 'stopDocumentListen_Test') call WaitFor('len(ReadXnetbeans()) >= (g:last + 3)') *************** *** 491,498 **** call assert_equal([{'name': '1', 'texthl': 'NB_s1', 'text': '=>'}, \ {'name': '10000', 'linehl': 'NBGuarded'}], \ sign_getdefined()) ! call assert_equal([{'lnum': 2, 'id': 1000000, 'name': '10000', ! \ 'priority': 10, 'group': ''}], sign_getplaced()[0].signs) let g:last += 3 " setModified test --- 528,536 ---- call assert_equal([{'name': '1', 'texthl': 'NB_s1', 'text': '=>'}, \ {'name': '10000', 'linehl': 'NBGuarded'}], \ sign_getdefined()) ! let s = sign_getplaced()[0].signs[0] ! call assert_equal(2, s.lnum) ! call assert_equal('10000', s.name) let g:last += 3 " setModified test *************** *** 500,508 **** --- 538,556 ---- call WaitFor('len(ReadXnetbeans()) >= (g:last + 3)') let l = ReadXnetbeans() call assert_equal('send: 3:setModified!77 T', l[-1]) + sleep 1m call assert_equal(1, &modified) let g:last += 3 + " clear setModified test + call appendbufline(cmdbufnr, '$', 'setModifiedClear_Test') + call WaitFor('len(ReadXnetbeans()) >= (g:last + 3)') + let l = ReadXnetbeans() + call assert_equal('send: 3:setModified!77 F', l[-1]) + sleep 1m + call assert_equal(0, &modified) + let g:last += 3 + " insertDone test let v:statusmsg = '' call appendbufline(cmdbufnr, '$', 'insertDone_Test') *************** *** 586,600 **** call appendbufline(cmdbufnr, '$', 'setReadOnly_Test') call WaitFor('len(ReadXnetbeans()) >= (g:last + 3)') let l = ReadXnetbeans() ! call assert_equal('send: 3:setReadOnly!87', l[-1]) let g:last += 3 " close test. Don't use buffer 10 after this call appendbufline(cmdbufnr, '$', 'close_Test') call WaitFor('len(ReadXnetbeans()) >= (g:last + 4)') let l = ReadXnetbeans() ! call assert_equal('send: 3:close!88', l[-2]) ! call assert_equal('3:killed=88', l[-1]) call assert_equal(1, winnr('$')) let g:last += 4 --- 634,669 ---- call appendbufline(cmdbufnr, '$', 'setReadOnly_Test') call WaitFor('len(ReadXnetbeans()) >= (g:last + 3)') let l = ReadXnetbeans() ! call assert_equal('send: 3:setReadOnly!87 T', l[-1]) ! sleep 1m ! call assert_equal(1, &readonly) ! let g:last += 3 ! ! " clear setReadonly test ! call appendbufline(cmdbufnr, '$', 'setReadOnlyClear_Test') ! call WaitFor('len(ReadXnetbeans()) >= (g:last + 3)') ! let l = ReadXnetbeans() ! call assert_equal('send: 3:setReadOnly!88 F', l[-1]) ! sleep 1m ! call assert_equal(0, &readonly) ! let g:last += 3 ! ! " save test ! call setbufvar(bufnr('Xfile4'), '&modified', 1) ! call appendbufline(cmdbufnr, '$', 'save_Test') ! call WaitFor('len(ReadXnetbeans()) >= (g:last + 3)') ! let l = ReadXnetbeans() ! call assert_equal('send: 3:save!89', l[-1]) ! sleep 1m ! call assert_true(filereadable('Xfile4')) let g:last += 3 " close test. Don't use buffer 10 after this call appendbufline(cmdbufnr, '$', 'close_Test') call WaitFor('len(ReadXnetbeans()) >= (g:last + 4)') let l = ReadXnetbeans() ! call assert_equal('send: 3:close!90', l[-2]) ! call assert_equal('3:killed=90', l[-1]) call assert_equal(1, winnr('$')) let g:last += 4 *************** *** 602,611 **** call appendbufline(cmdbufnr, '$', 'specialKeys_Test') call WaitFor('len(ReadXnetbeans()) >= (g:last + 3)') let l = ReadXnetbeans() ! call assert_equal('send: 0:specialKeys!89 "F12 F13"', l[-1]) sleep 1m call assert_equal(':nbkey F12', maparg('', 'n')) call assert_equal(':nbkey F13', maparg('', 'n')) let g:last += 3 " Open a buffer not monitored by netbeans --- 671,681 ---- call appendbufline(cmdbufnr, '$', 'specialKeys_Test') call WaitFor('len(ReadXnetbeans()) >= (g:last + 3)') let l = ReadXnetbeans() ! call assert_equal('send: 0:specialKeys!91 "F12 F13 C-F13"', l[-1]) sleep 1m call assert_equal(':nbkey F12', maparg('', 'n')) call assert_equal(':nbkey F13', maparg('', 'n')) + call assert_equal(':nbkey C-F13', maparg('', 'n')) let g:last += 3 " Open a buffer not monitored by netbeans *************** *** 626,642 **** call WaitFor('len(ReadXnetbeans()) >= (g:last + 10)') let g:last += 10 " detach call appendbufline(cmdbufnr, '$', 'detach_Test') call WaitFor('len(ReadXnetbeans()) >= (g:last + 8)') ! call WaitForAssert({-> assert_equal('0:disconnect=93', ReadXnetbeans()[-1])}) " the connection was closed call assert_false(has("netbeans_enabled")) call delete("Xnetbeans") call delete('Xfile1') call delete('Xfile3') endfunc func Test_nb_basic() --- 696,805 ---- call WaitFor('len(ReadXnetbeans()) >= (g:last + 10)') let g:last += 10 + if has('mouse') + " Test for mouse button release + let save_mouse = &mouse + set mouse=a + call feedkeys("\\", 'xt') + let &mouse = save_mouse + call WaitFor('len(ReadXnetbeans()) >= (g:last + 2)') + let l = ReadXnetbeans() + call assert_equal('4:newDotAndMark=93 0 0', l[-2]) + call assert_equal('4:buttonRelease=93 0 1 -1', l[-1]) + let g:last += 2 + endif + + " Test for startAtomic + call appendbufline(cmdbufnr, '$', 'startAtomic_Test') + call WaitFor('len(ReadXnetbeans()) >= (g:last + 3)') + let l = ReadXnetbeans() + call assert_equal('send: 0:startAtomic!94', l[-1]) + let g:last += 3 + + " Test for endAtomic + call appendbufline(cmdbufnr, '$', 'endAtomic_Test') + call WaitFor('len(ReadXnetbeans()) >= (g:last + 3)') + let l = ReadXnetbeans() + call assert_equal('send: 0:endAtomic!95', l[-1]) + let g:last += 3 + + " Test for invoking a netbeans key binding + let special_keys = [ + \ ["\", 'F1'], ["\", 'S-F1'], + \ ["\", 'F2'], ["\", 'S-F2'], + \ ["\", 'F3'], ["\", 'S-F3'], + \ ["\", 'F4'], ["\", 'S-F4'], + \ ["\", 'F5'], ["\", 'S-F5'], + \ ["\", 'F6'], ["\", 'S-F6'], + \ ["\", 'F7'], ["\", 'S-F7'], + \ ["\", 'F8'], ["\", 'S-F8'], + \ ["\", 'F9'], ["\", 'S-F9'], + \ ["\", 'F11'], ["\", 'S-F11'], + \ ["\", 'F12'], ["\", 'S-F12'], ['!', '!'] + \ ] + for [key, name] in special_keys + call feedkeys("\" .. key, 'xt') + call WaitFor('len(ReadXnetbeans()) >= (g:last + 3)') + let l = ReadXnetbeans() + call assert_match('4:keyCommand=\d\+ "' .. name .. '"', l[-2]) + call assert_match('4:keyAtPos=\d\+ "' .. name .. '" 0 1/0', l[-1]) + let g:last += 3 + endfor + call feedkeys("\\", 'xt') + call WaitFor('len(ReadXnetbeans()) >= (g:last + 3)') + let l = ReadXnetbeans() + call assert_match('4:keyCommand=\d\+ "CSM-F9"', l[-2]) + call assert_match('4:keyAtPos=\d\+ "CSM-F9" 0 1/0', l[-1]) + let g:last += 3 + + if has('signs') && has('mouse') + sign define S1 linehl=Search text==> + sign define S2 linehl=ErrorMsg text=!! + sign place 10 line=1 name=S1 + sign place 20 line=1 name=S2 + + let save_mouse = &mouse + set mouse=a + call assert_equal('S2', sign_getplaced()[0].signs[0].name) + call test_setmouse(1, 1) + call feedkeys("\\", 'xt') + call assert_equal('S1', sign_getplaced()[0].signs[0].name) + call test_setmouse(1, 1) + call feedkeys("\\", 'xt') + call assert_equal('S2', sign_getplaced()[0].signs[0].name) + let &mouse = save_mouse + + sign unplace 10 + sign unplace 20 + sign undefine S1 + sign undefine S2 + endif + + " define a large number of annotations + call appendbufline(cmdbufnr, '$', 'AnnoScale_Test') + call WaitFor('len(ReadXnetbeans()) >= (g:last + 26)') + let l = ReadXnetbeans() + call assert_equal('2:defineAnnoType!60 25 "s25" "x" "=>" blue none', l[-1]) + sleep 1m + call assert_true(len(sign_getdefined()) >= 25) + let g:last += 26 + " detach call appendbufline(cmdbufnr, '$', 'detach_Test') call WaitFor('len(ReadXnetbeans()) >= (g:last + 8)') ! call WaitForAssert({-> assert_equal('0:disconnect=97', ReadXnetbeans()[-1])}) " the connection was closed call assert_false(has("netbeans_enabled")) + " Remove all the signs + call sign_unplace('*') + call sign_undefine() + call delete("Xnetbeans") call delete('Xfile1') call delete('Xfile3') + call delete('Xfile4') endfunc func Test_nb_basic() *** ../vim-8.2.1941/src/testdir/test_quickfix.vim 2020-10-20 14:59:08.689104235 +0200 --- src/testdir/test_quickfix.vim 2020-11-02 19:58:58.364583736 +0100 *************** *** 3949,3954 **** --- 3949,3958 ---- au BufEnter * call setqflist([], 'f') augroup END call assert_fails('helpgrep quickfix', 'E925:') + " run the test with a help window already open + help + wincmd w + call assert_fails('helpgrep quickfix', 'E925:') augroup QF_Test au! BufEnter augroup END *** ../vim-8.2.1941/src/version.c 2020-11-01 22:31:05.027982238 +0100 --- src/version.c 2020-11-02 20:00:40.588308951 +0100 *************** *** 752,753 **** --- 752,755 ---- { /* Add new patch number below this line */ + /**/ + 1942, /**/ -- hundred-and-one symptoms of being an internet addict: 180. You maintain more than six e-mail addresses. /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net \\\ /// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\ \\\ an exciting new programming language -- http://www.Zimbu.org /// \\\ help me help AIDS victims -- http://ICCF-Holland.org ///