1" Test for python 2 commands. 2" TODO: move tests from test86.in here. 3 4source check.vim 5CheckFeature python 6 7func Test_pydo() 8 " Check deleting lines does not trigger ml_get error. 9 py import vim 10 new 11 call setline(1, ['one', 'two', 'three']) 12 pydo vim.command("%d_") 13 bwipe! 14 15 " Check switching to another buffer does not trigger ml_get error. 16 new 17 let wincount = winnr('$') 18 call setline(1, ['one', 'two', 'three']) 19 pydo vim.command("new") 20 call assert_equal(wincount + 1, winnr('$')) 21 bwipe! 22 bwipe! 23endfunc 24 25func Test_set_cursor() 26 " Check that setting the cursor position works. 27 py import vim 28 new 29 call setline(1, ['first line', 'second line']) 30 normal gg 31 pydo vim.current.window.cursor = (1, 5) 32 call assert_equal([1, 6], [line('.'), col('.')]) 33 34 " Check that movement after setting cursor position keeps current column. 35 normal j 36 call assert_equal([2, 6], [line('.'), col('.')]) 37endfunc 38 39func Test_vim_function() 40 " Check creating vim.Function object 41 py import vim 42 43 func s:foo() 44 return matchstr(expand('<sfile>'), '<SNR>\zs\d\+_foo$') 45 endfunc 46 let name = '<SNR>' . s:foo() 47 48 try 49 py f = vim.bindeval('function("s:foo")') 50 call assert_equal(name, pyeval('f.name')) 51 catch 52 call assert_false(v:exception) 53 endtry 54 55 try 56 py f = vim.Function('\x80\xfdR' + vim.eval('s:foo()')) 57 call assert_equal(name, 'f.name'->pyeval()) 58 catch 59 call assert_false(v:exception) 60 endtry 61 62 py del f 63 delfunc s:foo 64endfunc 65 66func Test_skipped_python_command_does_not_affect_pyxversion() 67 set pyxversion=0 68 if 0 69 python import vim 70 endif 71 call assert_equal(0, &pyxversion) " This assertion would have failed with Vim 8.0.0251. (pyxversion was introduced in 8.0.0251.) 72endfunc 73 74func _SetUpHiddenBuffer() 75 py import vim 76 new 77 edit hidden 78 setlocal bufhidden=hide 79 80 enew 81 let lnum = 0 82 while lnum < 10 83 call append( 1, string( lnum ) ) 84 let lnum = lnum + 1 85 endwhile 86 normal G 87 88 call assert_equal( line( '.' ), 11 ) 89endfunc 90 91func _CleanUpHiddenBuffer() 92 bwipe! hidden 93 bwipe! 94endfunc 95 96func Test_Write_To_HiddenBuffer_Does_Not_Fix_Cursor_Clear() 97 call _SetUpHiddenBuffer() 98 py vim.buffers[ int( vim.eval( 'bufnr("hidden")' ) ) ][:] = None 99 call assert_equal( line( '.' ), 11 ) 100 call _CleanUpHiddenBuffer() 101endfunc 102 103func Test_Write_To_HiddenBuffer_Does_Not_Fix_Cursor_List() 104 call _SetUpHiddenBuffer() 105 py vim.buffers[ int( vim.eval( 'bufnr("hidden")' ) ) ][:] = [ 'test' ] 106 call assert_equal( line( '.' ), 11 ) 107 call _CleanUpHiddenBuffer() 108endfunc 109 110func Test_Write_To_HiddenBuffer_Does_Not_Fix_Cursor_Str() 111 call _SetUpHiddenBuffer() 112 py vim.buffers[ int( vim.eval( 'bufnr("hidden")' ) ) ][0] = 'test' 113 call assert_equal( line( '.' ), 11 ) 114 call _CleanUpHiddenBuffer() 115endfunc 116 117func Test_Write_To_HiddenBuffer_Does_Not_Fix_Cursor_ClearLine() 118 call _SetUpHiddenBuffer() 119 py vim.buffers[ int( vim.eval( 'bufnr("hidden")' ) ) ][0] = None 120 call assert_equal( line( '.' ), 11 ) 121 call _CleanUpHiddenBuffer() 122endfunc 123 124func _SetUpVisibleBuffer() 125 py import vim 126 new 127 let lnum = 0 128 while lnum < 10 129 call append( 1, string( lnum ) ) 130 let lnum = lnum + 1 131 endwhile 132 normal G 133 call assert_equal( line( '.' ), 11 ) 134endfunc 135 136func Test_Write_To_Current_Buffer_Fixes_Cursor_Clear() 137 call _SetUpVisibleBuffer() 138 139 py vim.current.buffer[:] = None 140 call assert_equal( line( '.' ), 1 ) 141 142 bwipe! 143endfunc 144 145func Test_Write_To_Current_Buffer_Fixes_Cursor_List() 146 call _SetUpVisibleBuffer() 147 148 py vim.current.buffer[:] = [ 'test' ] 149 call assert_equal( line( '.' ), 1 ) 150 151 bwipe! 152endfunction 153 154func Test_Write_To_Current_Buffer_Fixes_Cursor_Str() 155 call _SetUpVisibleBuffer() 156 157 py vim.current.buffer[-1] = None 158 call assert_equal( line( '.' ), 10 ) 159 160 bwipe! 161endfunction 162 163func Test_Catch_Exception_Message() 164 try 165 py raise RuntimeError( 'TEST' ) 166 catch /.*/ 167 call assert_match( '^Vim(.*):RuntimeError: TEST$', v:exception ) 168 endtry 169endfunc 170 171" Test for various heredoc syntax 172func Test_python_heredoc() 173 python << END 174s='A' 175END 176 python << 177s+='B' 178. 179 python << trim END 180 s+='C' 181 END 182 python << trim 183 s+='D' 184 . 185 python << trim eof 186 s+='E' 187 eof 188 call assert_equal('ABCDE', pyxeval('s')) 189endfunc 190 191" vim: shiftwidth=2 sts=2 expandtab 192