Bram Moolenaar | a58883b | 2017-01-29 21:31:09 +0100 | [diff] [blame] | 1 | " Test for python 2 commands. |
Bram Moolenaar | a58883b | 2017-01-29 21:31:09 +0100 | [diff] [blame] | 2 | |
Bram Moolenaar | b46fecd | 2019-06-15 17:58:09 +0200 | [diff] [blame] | 3 | source check.vim |
| 4 | CheckFeature python |
Bram Moolenaar | 92fdd1e | 2020-07-03 18:00:05 +0200 | [diff] [blame] | 5 | CheckFeature quickfix |
Bram Moolenaar | ab58946 | 2020-07-06 21:03:06 +0200 | [diff] [blame] | 6 | source shared.vim |
Bram Moolenaar | 92fdd1e | 2020-07-03 18:00:05 +0200 | [diff] [blame] | 7 | |
| 8 | " NOTE: This will cause errors when run under valgrind. |
| 9 | " This would require recompiling Python with: |
| 10 | " ./configure --without-pymalloc |
| 11 | " See http://svn.python.org/view/python/trunk/Misc/README.valgrind?view=markup |
| 12 | " |
| 13 | |
| 14 | " This function should be called first. This sets up python functions used by |
| 15 | " the other tests. |
| 16 | func Test_AAA_python_setup() |
| 17 | py << trim EOF |
| 18 | import vim |
| 19 | import sys |
| 20 | |
| 21 | def emsg(ei): |
| 22 | return ei[0].__name__ + ':' + repr(ei[1].args) |
| 23 | |
| 24 | def ee(expr, g=globals(), l=locals()): |
| 25 | try: |
| 26 | exec(expr, g, l) |
| 27 | except: |
| 28 | ei = sys.exc_info() |
| 29 | msg = emsg(ei) |
| 30 | msg = msg.replace('TypeError:(\'argument 1 ', 'TypeError:(\'') |
| 31 | if expr.find('None') > -1: |
| 32 | msg = msg.replace('TypeError:(\'iteration over non-sequence\',)', |
| 33 | 'TypeError:("\'NoneType\' object is not iterable",)') |
| 34 | if expr.find('FailingNumber') > -1: |
| 35 | msg = msg.replace(', not \'FailingNumber\'', '').replace('"', '\'') |
| 36 | msg = msg.replace('TypeError:(\'iteration over non-sequence\',)', |
| 37 | 'TypeError:("\'FailingNumber\' object is not iterable",)') |
| 38 | if msg.find('(\'\'') > -1 or msg.find('(\'can\'t') > -1: |
| 39 | msg = msg.replace('(\'', '("').replace('\',)', '",)') |
| 40 | # Some Python versions say can't, others cannot. |
| 41 | if msg.find('can\'t') > -1: |
| 42 | msg = msg.replace('can\'t', 'cannot') |
| 43 | # Some Python versions use single quote, some double quote |
| 44 | if msg.find('"cannot ') > -1: |
| 45 | msg = msg.replace('"cannot ', '\'cannot ') |
| 46 | if msg.find(' attributes"') > -1: |
| 47 | msg = msg.replace(' attributes"', ' attributes\'') |
| 48 | if expr == 'fd(self=[])': |
| 49 | # HACK: PyMapping_Check changed meaning |
| 50 | msg = msg.replace('AttributeError:(\'keys\',)', |
| 51 | 'TypeError:(\'unable to convert list to vim dictionary\',)') |
| 52 | vim.current.buffer.append(expr + ':' + msg) |
| 53 | else: |
| 54 | vim.current.buffer.append(expr + ':NOT FAILED') |
| 55 | EOF |
| 56 | endfunc |
Bram Moolenaar | a58883b | 2017-01-29 21:31:09 +0100 | [diff] [blame] | 57 | |
| 58 | func Test_pydo() |
Bram Moolenaar | a58883b | 2017-01-29 21:31:09 +0100 | [diff] [blame] | 59 | new |
zeertzjq | e99f068 | 2024-01-29 19:32:39 +0100 | [diff] [blame] | 60 | |
| 61 | " Check deleting lines does not trigger an ml_get error. |
Bram Moolenaar | a58883b | 2017-01-29 21:31:09 +0100 | [diff] [blame] | 62 | call setline(1, ['one', 'two', 'three']) |
| 63 | pydo vim.command("%d_") |
zeertzjq | e99f068 | 2024-01-29 19:32:39 +0100 | [diff] [blame] | 64 | call assert_equal([''], getline(1, '$')) |
| 65 | |
| 66 | call setline(1, ['one', 'two', 'three']) |
| 67 | pydo vim.command("1,2d_") |
| 68 | call assert_equal(['three'], getline(1, '$')) |
| 69 | |
| 70 | call setline(1, ['one', 'two', 'three']) |
| 71 | pydo vim.command("2,3d_"); return "REPLACED" |
| 72 | call assert_equal(['REPLACED'], getline(1, '$')) |
| 73 | |
| 74 | call setline(1, ['one', 'two', 'three']) |
| 75 | 2,3pydo vim.command("1,2d_"); return "REPLACED" |
| 76 | call assert_equal(['three'], getline(1, '$')) |
| 77 | |
Bram Moolenaar | a58883b | 2017-01-29 21:31:09 +0100 | [diff] [blame] | 78 | bwipe! |
| 79 | |
Bram Moolenaar | ab58946 | 2020-07-06 21:03:06 +0200 | [diff] [blame] | 80 | " Check switching to another buffer does not trigger an ml_get error. |
Bram Moolenaar | a58883b | 2017-01-29 21:31:09 +0100 | [diff] [blame] | 81 | new |
| 82 | let wincount = winnr('$') |
| 83 | call setline(1, ['one', 'two', 'three']) |
| 84 | pydo vim.command("new") |
| 85 | call assert_equal(wincount + 1, winnr('$')) |
| 86 | bwipe! |
| 87 | bwipe! |
Bram Moolenaar | ab58946 | 2020-07-06 21:03:06 +0200 | [diff] [blame] | 88 | |
| 89 | " Try modifying a buffer with 'nomodifiable' set |
| 90 | set nomodifiable |
Bram Moolenaar | 9b7bf9e | 2020-07-11 22:14:59 +0200 | [diff] [blame] | 91 | call assert_fails('pydo toupper(line)', 'E21:') |
Bram Moolenaar | ab58946 | 2020-07-06 21:03:06 +0200 | [diff] [blame] | 92 | set modifiable |
| 93 | |
| 94 | " Invalid command |
| 95 | call AssertException(['pydo non_existing_cmd'], |
| 96 | \ "Vim(pydo):NameError: global name 'non_existing_cmd' is not defined") |
| 97 | call AssertException(["pydo raise Exception('test')"], |
| 98 | \ 'Vim(pydo):Exception: test') |
| 99 | call AssertException(["pydo {lambda}"], |
| 100 | \ 'Vim(pydo):SyntaxError: invalid syntax') |
Bram Moolenaar | a58883b | 2017-01-29 21:31:09 +0100 | [diff] [blame] | 101 | endfunc |
Bram Moolenaar | 5390144 | 2018-07-25 22:02:36 +0200 | [diff] [blame] | 102 | |
| 103 | func Test_set_cursor() |
| 104 | " Check that setting the cursor position works. |
Bram Moolenaar | 5390144 | 2018-07-25 22:02:36 +0200 | [diff] [blame] | 105 | new |
| 106 | call setline(1, ['first line', 'second line']) |
| 107 | normal gg |
| 108 | pydo vim.current.window.cursor = (1, 5) |
| 109 | call assert_equal([1, 6], [line('.'), col('.')]) |
| 110 | |
| 111 | " Check that movement after setting cursor position keeps current column. |
| 112 | normal j |
| 113 | call assert_equal([2, 6], [line('.'), col('.')]) |
| 114 | endfunc |
Bram Moolenaar | 9123c0b | 2018-12-22 18:59:06 +0100 | [diff] [blame] | 115 | |
| 116 | func Test_vim_function() |
| 117 | " Check creating vim.Function object |
Bram Moolenaar | 9123c0b | 2018-12-22 18:59:06 +0100 | [diff] [blame] | 118 | |
| 119 | func s:foo() |
| 120 | return matchstr(expand('<sfile>'), '<SNR>\zs\d\+_foo$') |
| 121 | endfunc |
| 122 | let name = '<SNR>' . s:foo() |
| 123 | |
| 124 | try |
| 125 | py f = vim.bindeval('function("s:foo")') |
| 126 | call assert_equal(name, pyeval('f.name')) |
| 127 | catch |
| 128 | call assert_false(v:exception) |
| 129 | endtry |
| 130 | |
| 131 | try |
| 132 | py f = vim.Function('\x80\xfdR' + vim.eval('s:foo()')) |
Bram Moolenaar | 3f4f3d8 | 2019-09-04 20:05:59 +0200 | [diff] [blame] | 133 | call assert_equal(name, 'f.name'->pyeval()) |
Bram Moolenaar | 9123c0b | 2018-12-22 18:59:06 +0100 | [diff] [blame] | 134 | catch |
| 135 | call assert_false(v:exception) |
| 136 | endtry |
| 137 | |
Bram Moolenaar | ab58946 | 2020-07-06 21:03:06 +0200 | [diff] [blame] | 138 | " Non-existing function attribute |
| 139 | call AssertException(["let x = pyeval('f.abc')"], |
| 140 | \ 'Vim(let):AttributeError: abc') |
Bram Moolenaar | 92fdd1e | 2020-07-03 18:00:05 +0200 | [diff] [blame] | 141 | |
Bram Moolenaar | 9123c0b | 2018-12-22 18:59:06 +0100 | [diff] [blame] | 142 | py del f |
| 143 | delfunc s:foo |
| 144 | endfunc |
Bram Moolenaar | 14816ad | 2019-02-18 22:04:56 +0100 | [diff] [blame] | 145 | |
| 146 | func Test_skipped_python_command_does_not_affect_pyxversion() |
| 147 | set pyxversion=0 |
| 148 | if 0 |
| 149 | python import vim |
| 150 | endif |
| 151 | call assert_equal(0, &pyxversion) " This assertion would have failed with Vim 8.0.0251. (pyxversion was introduced in 8.0.0251.) |
| 152 | endfunc |
Bram Moolenaar | 63dbfd3 | 2019-03-23 17:41:59 +0100 | [diff] [blame] | 153 | |
| 154 | func _SetUpHiddenBuffer() |
Bram Moolenaar | 63dbfd3 | 2019-03-23 17:41:59 +0100 | [diff] [blame] | 155 | new |
| 156 | edit hidden |
| 157 | setlocal bufhidden=hide |
| 158 | |
| 159 | enew |
| 160 | let lnum = 0 |
| 161 | while lnum < 10 |
| 162 | call append( 1, string( lnum ) ) |
| 163 | let lnum = lnum + 1 |
| 164 | endwhile |
| 165 | normal G |
| 166 | |
| 167 | call assert_equal( line( '.' ), 11 ) |
| 168 | endfunc |
| 169 | |
Bram Moolenaar | bfd3603 | 2019-03-30 12:33:13 +0100 | [diff] [blame] | 170 | func _CleanUpHiddenBuffer() |
| 171 | bwipe! hidden |
| 172 | bwipe! |
| 173 | endfunc |
| 174 | |
Bram Moolenaar | 63dbfd3 | 2019-03-23 17:41:59 +0100 | [diff] [blame] | 175 | func Test_Write_To_HiddenBuffer_Does_Not_Fix_Cursor_Clear() |
| 176 | call _SetUpHiddenBuffer() |
| 177 | py vim.buffers[ int( vim.eval( 'bufnr("hidden")' ) ) ][:] = None |
| 178 | call assert_equal( line( '.' ), 11 ) |
Bram Moolenaar | bfd3603 | 2019-03-30 12:33:13 +0100 | [diff] [blame] | 179 | call _CleanUpHiddenBuffer() |
Bram Moolenaar | 63dbfd3 | 2019-03-23 17:41:59 +0100 | [diff] [blame] | 180 | endfunc |
| 181 | |
| 182 | func Test_Write_To_HiddenBuffer_Does_Not_Fix_Cursor_List() |
| 183 | call _SetUpHiddenBuffer() |
| 184 | py vim.buffers[ int( vim.eval( 'bufnr("hidden")' ) ) ][:] = [ 'test' ] |
| 185 | call assert_equal( line( '.' ), 11 ) |
Bram Moolenaar | bfd3603 | 2019-03-30 12:33:13 +0100 | [diff] [blame] | 186 | call _CleanUpHiddenBuffer() |
Bram Moolenaar | 63dbfd3 | 2019-03-23 17:41:59 +0100 | [diff] [blame] | 187 | endfunc |
| 188 | |
| 189 | func Test_Write_To_HiddenBuffer_Does_Not_Fix_Cursor_Str() |
| 190 | call _SetUpHiddenBuffer() |
| 191 | py vim.buffers[ int( vim.eval( 'bufnr("hidden")' ) ) ][0] = 'test' |
| 192 | call assert_equal( line( '.' ), 11 ) |
Bram Moolenaar | bfd3603 | 2019-03-30 12:33:13 +0100 | [diff] [blame] | 193 | call _CleanUpHiddenBuffer() |
Bram Moolenaar | 63dbfd3 | 2019-03-23 17:41:59 +0100 | [diff] [blame] | 194 | endfunc |
| 195 | |
| 196 | func Test_Write_To_HiddenBuffer_Does_Not_Fix_Cursor_ClearLine() |
| 197 | call _SetUpHiddenBuffer() |
| 198 | py vim.buffers[ int( vim.eval( 'bufnr("hidden")' ) ) ][0] = None |
| 199 | call assert_equal( line( '.' ), 11 ) |
Bram Moolenaar | bfd3603 | 2019-03-30 12:33:13 +0100 | [diff] [blame] | 200 | call _CleanUpHiddenBuffer() |
Bram Moolenaar | 63dbfd3 | 2019-03-23 17:41:59 +0100 | [diff] [blame] | 201 | endfunc |
| 202 | |
| 203 | func _SetUpVisibleBuffer() |
Bram Moolenaar | 63dbfd3 | 2019-03-23 17:41:59 +0100 | [diff] [blame] | 204 | new |
| 205 | let lnum = 0 |
| 206 | while lnum < 10 |
| 207 | call append( 1, string( lnum ) ) |
| 208 | let lnum = lnum + 1 |
| 209 | endwhile |
| 210 | normal G |
| 211 | call assert_equal( line( '.' ), 11 ) |
| 212 | endfunc |
| 213 | |
| 214 | func Test_Write_To_Current_Buffer_Fixes_Cursor_Clear() |
| 215 | call _SetUpVisibleBuffer() |
| 216 | |
| 217 | py vim.current.buffer[:] = None |
| 218 | call assert_equal( line( '.' ), 1 ) |
| 219 | |
| 220 | bwipe! |
| 221 | endfunc |
| 222 | |
| 223 | func Test_Write_To_Current_Buffer_Fixes_Cursor_List() |
| 224 | call _SetUpVisibleBuffer() |
| 225 | |
| 226 | py vim.current.buffer[:] = [ 'test' ] |
| 227 | call assert_equal( line( '.' ), 1 ) |
| 228 | |
| 229 | bwipe! |
Bram Moolenaar | 92fdd1e | 2020-07-03 18:00:05 +0200 | [diff] [blame] | 230 | endfunc |
Bram Moolenaar | 63dbfd3 | 2019-03-23 17:41:59 +0100 | [diff] [blame] | 231 | |
| 232 | func Test_Write_To_Current_Buffer_Fixes_Cursor_Str() |
| 233 | call _SetUpVisibleBuffer() |
| 234 | |
| 235 | py vim.current.buffer[-1] = None |
| 236 | call assert_equal( line( '.' ), 10 ) |
| 237 | |
| 238 | bwipe! |
Bram Moolenaar | 92fdd1e | 2020-07-03 18:00:05 +0200 | [diff] [blame] | 239 | endfunc |
Bram Moolenaar | 7f3a284 | 2019-05-18 15:02:25 +0200 | [diff] [blame] | 240 | |
| 241 | func Test_Catch_Exception_Message() |
| 242 | try |
| 243 | py raise RuntimeError( 'TEST' ) |
| 244 | catch /.*/ |
| 245 | call assert_match( '^Vim(.*):RuntimeError: TEST$', v:exception ) |
| 246 | endtry |
| 247 | endfunc |
Bram Moolenaar | 6c2b7b8 | 2020-04-14 20:15:49 +0200 | [diff] [blame] | 248 | |
| 249 | " Test for various heredoc syntax |
| 250 | func Test_python_heredoc() |
| 251 | python << END |
| 252 | s='A' |
| 253 | END |
| 254 | python << |
| 255 | s+='B' |
| 256 | . |
| 257 | python << trim END |
| 258 | s+='C' |
| 259 | END |
| 260 | python << trim |
| 261 | s+='D' |
| 262 | . |
Bram Moolenaar | 6ab0953 | 2020-05-01 14:10:13 +0200 | [diff] [blame] | 263 | python << trim eof |
| 264 | s+='E' |
| 265 | eof |
zeertzjq | 449c2e5 | 2025-02-03 18:56:16 +0100 | [diff] [blame] | 266 | python << trimm |
| 267 | s+='F' |
| 268 | trimm |
| 269 | call assert_equal('ABCDEF', pyxeval('s')) |
Bram Moolenaar | 6c2b7b8 | 2020-04-14 20:15:49 +0200 | [diff] [blame] | 270 | endfunc |
| 271 | |
Bram Moolenaar | 92fdd1e | 2020-07-03 18:00:05 +0200 | [diff] [blame] | 272 | " Test for the buffer range object |
| 273 | func Test_python_range() |
| 274 | new |
| 275 | call setline(1, ['one', 'two', 'three']) |
| 276 | py b = vim.current.buffer |
| 277 | py r = b.range(1, 3) |
| 278 | call assert_equal(0, pyeval('r.start')) |
| 279 | call assert_equal(2, pyeval('r.end')) |
Bram Moolenaar | ab58946 | 2020-07-06 21:03:06 +0200 | [diff] [blame] | 280 | call assert_equal('one', pyeval('r[0]')) |
| 281 | call assert_equal('one', pyeval('r[-3]')) |
| 282 | call assert_equal('three', pyeval('r[-4]')) |
Bram Moolenaar | 92fdd1e | 2020-07-03 18:00:05 +0200 | [diff] [blame] | 283 | call assert_equal(['two', 'three'], pyeval('r[1:]')) |
| 284 | py r[0] = 'green' |
| 285 | call assert_equal(['green', 'two', 'three'], getline(1, '$')) |
| 286 | py r[0:2] = ['red', 'blue'] |
| 287 | call assert_equal(['red', 'blue', 'three'], getline(1, '$')) |
| 288 | call assert_equal(['start', 'end', '__members__'], pyeval('r.__members__')) |
| 289 | |
Bram Moolenaar | ab58946 | 2020-07-06 21:03:06 +0200 | [diff] [blame] | 290 | " try different invalid start/end index for the range slice |
| 291 | %d |
| 292 | call setline(1, ['one', 'two', 'three']) |
| 293 | py r[-10:1] = ["a"] |
| 294 | py r[10:12] = ["b"] |
| 295 | py r[-10:-9] = ["c"] |
| 296 | py r[1:0] = ["d"] |
| 297 | call assert_equal(['c', 'd', 'a', 'two', 'three', 'b'], getline(1, '$')) |
| 298 | |
Bram Moolenaar | bb790dc | 2020-07-07 20:12:54 +0200 | [diff] [blame] | 299 | " The following code used to trigger an ml_get error |
| 300 | %d |
| 301 | let x = pyeval('r[:]') |
Bram Moolenaar | ab58946 | 2020-07-06 21:03:06 +0200 | [diff] [blame] | 302 | |
| 303 | " Non-existing range attribute |
| 304 | call AssertException(["let x = pyeval('r.abc')"], |
| 305 | \ 'Vim(let):AttributeError: abc') |
Bram Moolenaar | 92fdd1e | 2020-07-03 18:00:05 +0200 | [diff] [blame] | 306 | |
| 307 | close! |
| 308 | endfunc |
| 309 | |
| 310 | " Test for the python tabpage object |
| 311 | func Test_python_tabpage() |
| 312 | tabnew |
| 313 | py t = vim.tabpages[1] |
Bram Moolenaar | ab58946 | 2020-07-06 21:03:06 +0200 | [diff] [blame] | 314 | py wl = t.windows |
Bram Moolenaar | 92fdd1e | 2020-07-03 18:00:05 +0200 | [diff] [blame] | 315 | tabclose |
Bram Moolenaar | ab58946 | 2020-07-06 21:03:06 +0200 | [diff] [blame] | 316 | " Accessing a closed tabpage |
| 317 | call AssertException(["let n = pyeval('t.number')"], |
| 318 | \ 'Vim(let):vim.error: attempt to refer to deleted tab page') |
| 319 | call AssertException(["let n = pyeval('len(wl)')"], |
| 320 | \ 'Vim(let):vim.error: attempt to refer to deleted tab page') |
| 321 | call AssertException(["py w = wl[0]"], |
| 322 | \ 'Vim(python):vim.error: attempt to refer to deleted tab page') |
| 323 | call AssertException(["py vim.current.tabpage = t"], |
| 324 | \ 'Vim(python):vim.error: attempt to refer to deleted tab page') |
| 325 | call assert_match('<tabpage object (deleted)', pyeval('repr(t)')) |
Bram Moolenaar | 92fdd1e | 2020-07-03 18:00:05 +0200 | [diff] [blame] | 326 | %bw! |
| 327 | endfunc |
| 328 | |
| 329 | " Test for the python window object |
| 330 | func Test_python_window() |
Bram Moolenaar | ab58946 | 2020-07-06 21:03:06 +0200 | [diff] [blame] | 331 | " Test for setting the window height |
| 332 | 10new |
| 333 | py vim.current.window.height = 5 |
| 334 | call assert_equal(5, winheight(0)) |
Yegappan Lakshmanan | 611728f | 2021-05-24 15:15:47 +0200 | [diff] [blame] | 335 | py vim.current.window.height = 3.2 |
| 336 | call assert_equal(3, winheight(0)) |
Bram Moolenaar | ab58946 | 2020-07-06 21:03:06 +0200 | [diff] [blame] | 337 | |
| 338 | " Test for setting the window width |
| 339 | 10vnew |
| 340 | py vim.current.window.width = 6 |
| 341 | call assert_equal(6, winwidth(0)) |
| 342 | |
| 343 | " Try accessing a closed window |
Bram Moolenaar | 92fdd1e | 2020-07-03 18:00:05 +0200 | [diff] [blame] | 344 | py w = vim.current.window |
Bram Moolenaar | ab58946 | 2020-07-06 21:03:06 +0200 | [diff] [blame] | 345 | py wopts = w.options |
Bram Moolenaar | 92fdd1e | 2020-07-03 18:00:05 +0200 | [diff] [blame] | 346 | close |
Bram Moolenaar | ab58946 | 2020-07-06 21:03:06 +0200 | [diff] [blame] | 347 | " Access the attributes of a closed window |
| 348 | call AssertException(["let n = pyeval('w.number')"], |
| 349 | \ 'Vim(let):vim.error: attempt to refer to deleted window') |
| 350 | call AssertException(["py w.height = 5"], |
| 351 | \ 'Vim(python):vim.error: attempt to refer to deleted window') |
| 352 | call AssertException(["py vim.current.window = w"], |
| 353 | \ 'Vim(python):vim.error: attempt to refer to deleted window') |
| 354 | " Try to set one of the options of the closed window |
Bram Moolenaar | bb790dc | 2020-07-07 20:12:54 +0200 | [diff] [blame] | 355 | " The following caused an ASAN failure |
| 356 | call AssertException(["py wopts['list'] = False"], |
| 357 | \ 'vim.error: attempt to refer to deleted window') |
Bram Moolenaar | ab58946 | 2020-07-06 21:03:06 +0200 | [diff] [blame] | 358 | call assert_match('<window object (deleted)', pyeval("repr(w)")) |
| 359 | %bw! |
Bram Moolenaar | 92fdd1e | 2020-07-03 18:00:05 +0200 | [diff] [blame] | 360 | endfunc |
| 361 | |
| 362 | " Test for the python List object |
| 363 | func Test_python_list() |
| 364 | let l = [1, 2] |
| 365 | py pl = vim.bindeval('l') |
| 366 | call assert_equal(['locked', '__members__'], pyeval('pl.__members__')) |
| 367 | |
Bram Moolenaar | ab58946 | 2020-07-06 21:03:06 +0200 | [diff] [blame] | 368 | " Try to convert a null List |
| 369 | call AssertException(["py t = vim.eval('test_null_list()')"], |
| 370 | \ 'Vim(python):SystemError: error return without exception set') |
| 371 | |
| 372 | " Try to convert a List with a null List item |
| 373 | call AssertException(["py t = vim.eval('[test_null_list()]')"], |
| 374 | \ 'Vim(python):SystemError: error return without exception set') |
| 375 | |
Bram Moolenaar | 64ffa9b | 2020-11-04 12:23:06 +0100 | [diff] [blame] | 376 | " Try to bind a null List variable (works because an empty list is used) |
Bram Moolenaar | ab58946 | 2020-07-06 21:03:06 +0200 | [diff] [blame] | 377 | let cmds =<< trim END |
| 378 | let l = test_null_list() |
| 379 | py ll = vim.bindeval('l') |
| 380 | END |
Bram Moolenaar | 64ffa9b | 2020-11-04 12:23:06 +0100 | [diff] [blame] | 381 | call AssertException(cmds, '') |
Bram Moolenaar | ab58946 | 2020-07-06 21:03:06 +0200 | [diff] [blame] | 382 | |
Bram Moolenaar | 92fdd1e | 2020-07-03 18:00:05 +0200 | [diff] [blame] | 383 | let l = [] |
| 384 | py l = vim.bindeval('l') |
| 385 | py f = vim.bindeval('function("strlen")') |
| 386 | " Extending List directly with different types |
| 387 | py l.extend([1, "as'd", [1, 2, f, {'a': 1}]]) |
| 388 | call assert_equal([1, "as'd", [1, 2, function("strlen"), {'a': 1}]], l) |
| 389 | call assert_equal([1, 2, function("strlen"), {'a': 1}], l[-1]) |
| 390 | call assert_fails('echo l[-4]', 'E684:') |
| 391 | |
| 392 | " List assignment |
| 393 | py l[0] = 0 |
| 394 | call assert_equal([0, "as'd", [1, 2, function("strlen"), {'a': 1}]], l) |
| 395 | py l[-2] = f |
| 396 | call assert_equal([0, function("strlen"), [1, 2, function("strlen"), {'a': 1}]], l) |
Bram Moolenaar | ab58946 | 2020-07-06 21:03:06 +0200 | [diff] [blame] | 397 | |
| 398 | " appending to a list |
| 399 | let l = [1, 2] |
| 400 | py ll = vim.bindeval('l') |
| 401 | py ll[2] = 8 |
| 402 | call assert_equal([1, 2, 8], l) |
| 403 | |
| 404 | " Using dict as an index |
| 405 | call AssertException(['py ll[{}] = 10'], |
| 406 | \ 'Vim(python):TypeError: index must be int or slice, not dict') |
Bram Moolenaar | 92fdd1e | 2020-07-03 18:00:05 +0200 | [diff] [blame] | 407 | endfunc |
| 408 | |
| 409 | " Test for the python Dict object |
| 410 | func Test_python_dict() |
| 411 | let d = {} |
| 412 | py pd = vim.bindeval('d') |
| 413 | call assert_equal(['locked', 'scope', '__members__'], |
| 414 | \ pyeval('pd.__members__')) |
Bram Moolenaar | ab58946 | 2020-07-06 21:03:06 +0200 | [diff] [blame] | 415 | |
| 416 | " Try to convert a null Dict |
| 417 | call AssertException(["py t = vim.eval('test_null_dict()')"], |
| 418 | \ 'Vim(python):SystemError: error return without exception set') |
| 419 | |
| 420 | " Try to convert a Dict with a null List value |
| 421 | call AssertException(["py t = vim.eval(\"{'a' : test_null_list()}\")"], |
| 422 | \ 'Vim(python):SystemError: error return without exception set') |
| 423 | |
| 424 | " Try to convert a Dict with a null string key |
| 425 | py t = vim.eval("{test_null_string() : 10}") |
| 426 | call assert_fails("let d = pyeval('t')", 'E859:') |
| 427 | |
| 428 | " Dict length |
| 429 | let d = {'a' : 10, 'b' : 20} |
| 430 | py d = vim.bindeval('d') |
| 431 | call assert_equal(2, pyeval('len(d)')) |
| 432 | |
Dominique Pelle | 923dce2 | 2021-11-21 11:36:04 +0000 | [diff] [blame] | 433 | " Deleting a non-existing key |
Bram Moolenaar | ab58946 | 2020-07-06 21:03:06 +0200 | [diff] [blame] | 434 | call AssertException(["py del d['c']"], "Vim(python):KeyError: 'c'") |
Bram Moolenaar | 92fdd1e | 2020-07-03 18:00:05 +0200 | [diff] [blame] | 435 | endfunc |
| 436 | |
| 437 | " Extending Dictionary directly with different types |
| 438 | func Test_python_dict_extend() |
| 439 | let d = {} |
| 440 | func d.f() |
| 441 | return 1 |
| 442 | endfunc |
| 443 | |
| 444 | py f = vim.bindeval('function("strlen")') |
| 445 | py << trim EOF |
| 446 | d = vim.bindeval('d') |
| 447 | d['1'] = 'asd' |
| 448 | d.update() # Must not do anything, including throwing errors |
| 449 | d.update(b = [1, 2, f]) |
| 450 | d.update((('-1', {'a': 1}),)) |
| 451 | d.update({'0': -1}) |
| 452 | dk = d.keys() |
| 453 | dv = d.values() |
| 454 | di = d.items() |
| 455 | cmpfun = lambda a, b: cmp(repr(a), repr(b)) |
| 456 | dk.sort(cmpfun) |
| 457 | dv.sort(cmpfun) |
| 458 | di.sort(cmpfun) |
| 459 | EOF |
| 460 | |
Bram Moolenaar | ab58946 | 2020-07-06 21:03:06 +0200 | [diff] [blame] | 461 | " Try extending a locked dictionary |
| 462 | lockvar d |
| 463 | call AssertException(["py d.update({'b' : 20})"], |
| 464 | \ 'Vim(python):vim.error: dictionary is locked') |
| 465 | unlockvar d |
| 466 | |
Bram Moolenaar | 92fdd1e | 2020-07-03 18:00:05 +0200 | [diff] [blame] | 467 | call assert_equal(1, pyeval("d['f'](self={})")) |
| 468 | call assert_equal("['-1', '0', '1', 'b', 'f']", pyeval('repr(dk)')) |
| 469 | call assert_equal("['asd', -1L, <vim.Function '1'>, <vim.dictionary object at >, <vim.list object at >]", substitute(pyeval('repr(dv)'),'0x\x\+','','g')) |
| 470 | call assert_equal("[('-1', <vim.dictionary object at >), ('0', -1L), ('1', 'asd'), ('b', <vim.list object at >), ('f', <vim.Function '1'>)]", substitute(pyeval('repr(di)'),'0x\x\+','','g')) |
| 471 | call assert_equal(['0', '1', 'b', 'f', '-1'], keys(d)) |
| 472 | call assert_equal("[-1, 'asd', [1, 2, function('strlen')], function('1'), {'a': 1}]", string(values(d))) |
| 473 | py del dk |
| 474 | py del di |
| 475 | py del dv |
| 476 | endfunc |
| 477 | |
| 478 | func Test_python_list_del_items() |
| 479 | " removing items with del |
| 480 | let l = [0, function("strlen"), [1, 2, function("strlen"), {'a': 1}]] |
| 481 | py l = vim.bindeval('l') |
| 482 | py del l[2] |
| 483 | call assert_equal("[0, function('strlen')]", string(l)) |
| 484 | |
| 485 | let l = range(8) |
| 486 | py l = vim.bindeval('l') |
| 487 | py del l[:3] |
| 488 | py del l[1:] |
| 489 | call assert_equal([3], l) |
| 490 | |
| 491 | " removing items out of range: silently skip items that don't exist |
| 492 | |
| 493 | " The following two ranges delete nothing as they match empty list: |
| 494 | let l = [0, 1, 2, 3] |
| 495 | py l = vim.bindeval('l') |
| 496 | py del l[2:1] |
| 497 | call assert_equal([0, 1, 2, 3], l) |
| 498 | py del l[2:2] |
| 499 | call assert_equal([0, 1, 2, 3], l) |
| 500 | py del l[2:3] |
| 501 | call assert_equal([0, 1, 3], l) |
| 502 | |
| 503 | let l = [0, 1, 2, 3] |
| 504 | py l = vim.bindeval('l') |
| 505 | py del l[2:4] |
| 506 | call assert_equal([0, 1], l) |
| 507 | |
| 508 | let l = [0, 1, 2, 3] |
| 509 | py l = vim.bindeval('l') |
| 510 | py del l[2:5] |
| 511 | call assert_equal([0, 1], l) |
| 512 | |
| 513 | let l = [0, 1, 2, 3] |
| 514 | py l = vim.bindeval('l') |
| 515 | py del l[2:6] |
| 516 | call assert_equal([0, 1], l) |
| 517 | |
| 518 | " The following two ranges delete nothing as they match empty list: |
| 519 | let l = [0, 1, 2, 3] |
| 520 | py l = vim.bindeval('l') |
| 521 | py del l[-1:2] |
| 522 | call assert_equal([0, 1, 2, 3], l) |
| 523 | py del l[-2:2] |
| 524 | call assert_equal([0, 1, 2, 3], l) |
| 525 | py del l[-3:2] |
| 526 | call assert_equal([0, 2, 3], l) |
| 527 | |
| 528 | let l = [0, 1, 2, 3] |
| 529 | py l = vim.bindeval('l') |
| 530 | py del l[-4:2] |
| 531 | call assert_equal([2, 3], l) |
| 532 | |
| 533 | let l = [0, 1, 2, 3] |
| 534 | py l = vim.bindeval('l') |
| 535 | py del l[-5:2] |
| 536 | call assert_equal([2, 3], l) |
| 537 | |
| 538 | let l = [0, 1, 2, 3] |
| 539 | py l = vim.bindeval('l') |
| 540 | py del l[-6:2] |
| 541 | call assert_equal([2, 3], l) |
| 542 | |
| 543 | let l = [0, 1, 2, 3] |
| 544 | py l = vim.bindeval('l') |
| 545 | py del l[::2] |
| 546 | call assert_equal([1, 3], l) |
| 547 | |
| 548 | let l = [0, 1, 2, 3] |
| 549 | py l = vim.bindeval('l') |
| 550 | py del l[3:0:-2] |
| 551 | call assert_equal([0, 2], l) |
| 552 | |
| 553 | let l = [0, 1, 2, 3] |
| 554 | py l = vim.bindeval('l') |
| 555 | py del l[2:4:-2] |
| 556 | let l = [0, 1, 2, 3] |
| 557 | endfunc |
| 558 | |
| 559 | func Test_python_dict_del_items() |
| 560 | let d = eval("{'0' : -1, '1' : 'asd', 'b' : [1, 2, function('strlen')], 'f' : function('min'), '-1' : {'a': 1}}") |
| 561 | py d = vim.bindeval('d') |
| 562 | py del d['-1'] |
| 563 | py del d['f'] |
| 564 | call assert_equal([1, 2, function('strlen')], pyeval('d.get(''b'', 1)')) |
| 565 | call assert_equal([1, 2, function('strlen')], pyeval('d.pop(''b'')')) |
| 566 | call assert_equal(1, pyeval('d.get(''b'', 1)')) |
| 567 | call assert_equal('asd', pyeval('d.pop(''1'', 2)')) |
| 568 | call assert_equal(2, pyeval('d.pop(''1'', 2)')) |
| 569 | call assert_equal('True', pyeval('repr(d.has_key(''0''))')) |
| 570 | call assert_equal('False', pyeval('repr(d.has_key(''1''))')) |
| 571 | call assert_equal('True', pyeval('repr(''0'' in d)')) |
| 572 | call assert_equal('False', pyeval('repr(''1'' in d)')) |
| 573 | call assert_equal("['0']", pyeval('repr(list(iter(d)))')) |
| 574 | call assert_equal({'0' : -1}, d) |
| 575 | call assert_equal("('0', -1L)", pyeval('repr(d.popitem())')) |
| 576 | call assert_equal('None', pyeval('repr(d.get(''0''))')) |
| 577 | call assert_equal('[]', pyeval('repr(list(iter(d)))')) |
| 578 | endfunc |
| 579 | |
| 580 | " Slice assignment to a list |
| 581 | func Test_python_slice_assignment() |
| 582 | let l = [0, 1, 2, 3] |
| 583 | py l = vim.bindeval('l') |
| 584 | py l[0:0] = ['a'] |
| 585 | call assert_equal(['a', 0, 1, 2, 3], l) |
| 586 | |
| 587 | let l = [0, 1, 2, 3] |
| 588 | py l = vim.bindeval('l') |
| 589 | py l[1:2] = ['b'] |
| 590 | call assert_equal([0, 'b', 2, 3], l) |
| 591 | |
| 592 | let l = [0, 1, 2, 3] |
| 593 | py l = vim.bindeval('l') |
| 594 | py l[2:4] = ['c'] |
| 595 | call assert_equal([0, 1, 'c'], l) |
| 596 | |
| 597 | let l = [0, 1, 2, 3] |
| 598 | py l = vim.bindeval('l') |
| 599 | py l[4:4] = ['d'] |
| 600 | call assert_equal([0, 1, 2, 3, 'd'], l) |
| 601 | |
| 602 | let l = [0, 1, 2, 3] |
| 603 | py l = vim.bindeval('l') |
| 604 | py l[-1:2] = ['e'] |
| 605 | call assert_equal([0, 1, 2, 'e', 3], l) |
| 606 | |
| 607 | let l = [0, 1, 2, 3] |
| 608 | py l = vim.bindeval('l') |
| 609 | py l[-10:2] = ['f'] |
| 610 | call assert_equal(['f', 2, 3], l) |
| 611 | |
| 612 | let l = [0, 1, 2, 3] |
| 613 | py l = vim.bindeval('l') |
| 614 | py l[2:-10] = ['g'] |
| 615 | call assert_equal([0, 1, 'g', 2, 3], l) |
| 616 | |
| 617 | let l = [] |
| 618 | py l = vim.bindeval('l') |
| 619 | py l[0:0] = ['h'] |
| 620 | call assert_equal(['h'], l) |
| 621 | |
| 622 | let l = range(8) |
| 623 | py l = vim.bindeval('l') |
| 624 | py l[2:6:2] = [10, 20] |
| 625 | call assert_equal([0, 1, 10, 3, 20, 5, 6, 7], l) |
| 626 | |
| 627 | let l = range(8) |
| 628 | py l = vim.bindeval('l') |
| 629 | py l[6:2:-2] = [10, 20] |
| 630 | call assert_equal([0, 1, 2, 3, 20, 5, 10, 7], l) |
| 631 | |
| 632 | let l = range(8) |
| 633 | py l = vim.bindeval('l') |
| 634 | py l[6:2] = () |
| 635 | call assert_equal([0, 1, 2, 3, 4, 5, 6, 7], l) |
| 636 | |
| 637 | let l = range(8) |
| 638 | py l = vim.bindeval('l') |
| 639 | py l[6:2:1] = () |
| 640 | call assert_equal([0, 1, 2, 3, 4, 5, 6, 7], l) |
| 641 | |
| 642 | let l = range(8) |
| 643 | py l = vim.bindeval('l') |
| 644 | py l[2:2:1] = () |
| 645 | call assert_equal([0, 1, 2, 3, 4, 5, 6, 7], l) |
Bram Moolenaar | 0ab55d6 | 2020-07-07 20:50:39 +0200 | [diff] [blame] | 646 | |
| 647 | call AssertException(["py x = l[10:11:0]"], |
| 648 | \ "Vim(python):ValueError: slice step cannot be zero") |
Bram Moolenaar | 92fdd1e | 2020-07-03 18:00:05 +0200 | [diff] [blame] | 649 | endfunc |
| 650 | |
| 651 | " Locked variables |
| 652 | func Test_python_lockedvar() |
| 653 | new |
| 654 | py cb = vim.current.buffer |
| 655 | let l = [0, 1, 2, 3] |
| 656 | py l = vim.bindeval('l') |
| 657 | lockvar! l |
| 658 | py << trim EOF |
| 659 | try: |
| 660 | l[2]='i' |
| 661 | except vim.error: |
| 662 | cb.append('l[2] threw vim.error: ' + emsg(sys.exc_info())) |
| 663 | EOF |
| 664 | call assert_equal(['', "l[2] threw vim.error: error:('list is locked',)"], |
| 665 | \ getline(1, '$')) |
Bram Moolenaar | ab58946 | 2020-07-06 21:03:06 +0200 | [diff] [blame] | 666 | |
| 667 | " Try to concatenate a locked list |
| 668 | call AssertException(['py l += [4, 5]'], |
| 669 | \ 'Vim(python):vim.error: list is locked') |
| 670 | |
Bram Moolenaar | 92fdd1e | 2020-07-03 18:00:05 +0200 | [diff] [blame] | 671 | call assert_equal([0, 1, 2, 3], l) |
| 672 | unlockvar! l |
| 673 | close! |
| 674 | endfunc |
| 675 | |
| 676 | " Test for calling a function |
| 677 | func Test_python_function_call() |
| 678 | func New(...) |
Bram Moolenaar | effb0cd | 2020-07-03 21:17:34 +0200 | [diff] [blame] | 679 | return ['NewStart'] + a:000 + ['NewEnd'] |
Bram Moolenaar | 92fdd1e | 2020-07-03 18:00:05 +0200 | [diff] [blame] | 680 | endfunc |
| 681 | |
| 682 | func DictNew(...) dict |
Bram Moolenaar | effb0cd | 2020-07-03 21:17:34 +0200 | [diff] [blame] | 683 | return ['DictNewStart'] + a:000 + ['DictNewEnd', self] |
Bram Moolenaar | 92fdd1e | 2020-07-03 18:00:05 +0200 | [diff] [blame] | 684 | endfunc |
| 685 | |
| 686 | new |
| 687 | let l = [function('New'), function('DictNew')] |
| 688 | py l = vim.bindeval('l') |
| 689 | py l.extend(list(l[0](1, 2, 3))) |
| 690 | call assert_equal([function('New'), function('DictNew'), 'NewStart', 1, 2, 3, 'NewEnd'], l) |
| 691 | py l.extend(list(l[1](1, 2, 3, self={'a': 'b'}))) |
| 692 | call assert_equal([function('New'), function('DictNew'), 'NewStart', 1, 2, 3, 'NewEnd', 'DictNewStart', 1, 2, 3, 'DictNewEnd', {'a': 'b'}], l) |
| 693 | py l.extend([l[0].name]) |
| 694 | call assert_equal([function('New'), function('DictNew'), 'NewStart', 1, 2, 3, 'NewEnd', 'DictNewStart', 1, 2, 3, 'DictNewEnd', {'a': 'b'}, 'New'], l) |
| 695 | py ee('l[1](1, 2, 3)') |
| 696 | call assert_equal("l[1](1, 2, 3):error:('Vim:E725: Calling dict function without Dictionary: DictNew',)", getline(2)) |
| 697 | %d |
| 698 | py f = l[0] |
| 699 | delfunction New |
| 700 | py ee('f(1, 2, 3)') |
| 701 | call assert_equal("f(1, 2, 3):error:('Vim:E117: Unknown function: New',)", getline(2)) |
| 702 | close! |
| 703 | delfunction DictNew |
| 704 | endfunc |
| 705 | |
| 706 | func Test_python_float() |
Bram Moolenaar | 92fdd1e | 2020-07-03 18:00:05 +0200 | [diff] [blame] | 707 | let l = [0.0] |
| 708 | py l = vim.bindeval('l') |
| 709 | py l.extend([0.0]) |
| 710 | call assert_equal([0.0, 0.0], l) |
| 711 | endfunc |
| 712 | |
| 713 | " Test for Dict key errors |
| 714 | func Test_python_dict_key_error() |
| 715 | let messages = [] |
| 716 | py << trim EOF |
| 717 | d = vim.bindeval('{}') |
| 718 | m = vim.bindeval('messages') |
| 719 | def em(expr, g=globals(), l=locals()): |
| 720 | try: |
| 721 | exec(expr, g, l) |
| 722 | except: |
| 723 | m.extend([sys.exc_type.__name__]) |
| 724 | |
| 725 | em('d["abc1"]') |
| 726 | em('d["abc1"]="\\0"') |
| 727 | em('d["abc1"]=vim') |
| 728 | em('d[""]=1') |
| 729 | em('d["a\\0b"]=1') |
| 730 | em('d[u"a\\0b"]=1') |
| 731 | em('d.pop("abc1")') |
| 732 | em('d.popitem()') |
| 733 | del em |
| 734 | del m |
| 735 | EOF |
| 736 | |
| 737 | call assert_equal(['KeyError', 'TypeError', 'TypeError', 'ValueError', |
| 738 | \ 'TypeError', 'TypeError', 'KeyError', 'KeyError'], messages) |
| 739 | unlet messages |
| 740 | endfunc |
| 741 | |
| 742 | " Test for locked and scope attributes |
| 743 | func Test_python_lock_scope_attr() |
| 744 | let d = {} | let dl = {} | lockvar dl |
| 745 | let res = [] |
| 746 | for s in split("d dl v: g:") |
| 747 | let name = tr(s, ':', 's') |
| 748 | execute 'py ' .. name .. ' = vim.bindeval("' .. s .. '")' |
| 749 | call add(res, s .. ' : ' .. join(map(['locked', 'scope'], |
| 750 | \ 'v:val .. ":" .. pyeval(name .. "." .. v:val)'), ';')) |
| 751 | endfor |
| 752 | call assert_equal(['d : locked:0;scope:0', 'dl : locked:1;scope:0', |
| 753 | \ 'v: : locked:2;scope:1', 'g: : locked:0;scope:2'], res) |
| 754 | |
| 755 | silent! let d.abc2 = 1 |
| 756 | silent! let dl.abc3 = 1 |
| 757 | py d.locked = True |
| 758 | py dl.locked = False |
| 759 | silent! let d.def = 1 |
| 760 | silent! let dl.def = 1 |
| 761 | call assert_equal({'abc2': 1}, d) |
| 762 | call assert_equal({'def': 1}, dl) |
| 763 | unlet d dl |
| 764 | |
| 765 | let l = [] | let ll = [] | lockvar ll |
| 766 | let res = [] |
| 767 | for s in split("l ll") |
| 768 | let name = tr(s, ':', 's') |
| 769 | execute 'py ' .. name .. '=vim.bindeval("' .. s .. '")' |
| 770 | call add(res, s .. ' : locked:' .. pyeval(name .. '.locked')) |
| 771 | endfor |
| 772 | call assert_equal(['l : locked:0', 'll : locked:1'], res) |
| 773 | |
| 774 | silent! call extend(l, [0]) |
| 775 | silent! call extend(ll, [0]) |
| 776 | py l.locked = True |
| 777 | py ll.locked = False |
| 778 | silent! call extend(l, [1]) |
| 779 | silent! call extend(ll, [1]) |
| 780 | call assert_equal([0], l) |
| 781 | call assert_equal([1], ll) |
| 782 | unlet l ll |
Bram Moolenaar | ab58946 | 2020-07-06 21:03:06 +0200 | [diff] [blame] | 783 | |
| 784 | " Try changing an attribute of a fixed list |
| 785 | py a = vim.bindeval('v:argv') |
| 786 | call AssertException(['py a.locked = 0'], |
| 787 | \ 'Vim(python):TypeError: cannot modify fixed list') |
Bram Moolenaar | 92fdd1e | 2020-07-03 18:00:05 +0200 | [diff] [blame] | 788 | endfunc |
| 789 | |
| 790 | " Test for pyeval() |
| 791 | func Test_python_pyeval() |
| 792 | let l = pyeval('range(3)') |
| 793 | call assert_equal([0, 1, 2], l) |
| 794 | |
| 795 | let d = pyeval('{"a": "b", "c": 1, "d": ["e"]}') |
| 796 | call assert_equal([['a', 'b'], ['c', 1], ['d', ['e']]], sort(items(d))) |
| 797 | |
| 798 | let v:errmsg = '' |
| 799 | call assert_equal(v:none, pyeval('None')) |
| 800 | call assert_equal('', v:errmsg) |
| 801 | |
Bram Moolenaar | ab58946 | 2020-07-06 21:03:06 +0200 | [diff] [blame] | 802 | py v = vim.eval('test_null_function()') |
| 803 | call assert_equal(v:none, pyeval('v')) |
| 804 | |
Bram Moolenaar | 73e28dc | 2022-09-17 21:08:33 +0100 | [diff] [blame] | 805 | call assert_equal(0.0, pyeval('0.0')) |
Bram Moolenaar | 92fdd1e | 2020-07-03 18:00:05 +0200 | [diff] [blame] | 806 | |
Bram Moolenaar | ab58946 | 2020-07-06 21:03:06 +0200 | [diff] [blame] | 807 | " Evaluate an invalid values |
| 808 | call AssertException(['let v = pyeval(''"\0"'')'], 'E859:') |
| 809 | call AssertException(['let v = pyeval(''{"\0" : 1}'')'], 'E859:') |
| 810 | call AssertException(['let v = pyeval("undefined_name")'], |
| 811 | \ "Vim(let):NameError: name 'undefined_name' is not defined") |
| 812 | call AssertException(['let v = pyeval("vim")'], 'E859:') |
| 813 | endfunc |
Bram Moolenaar | 92fdd1e | 2020-07-03 18:00:05 +0200 | [diff] [blame] | 814 | |
Ben Jackson | ea19e78 | 2024-11-06 21:50:05 +0100 | [diff] [blame] | 815 | " Test for py3eval with locals |
| 816 | func Test_python_pyeval_locals() |
| 817 | let str = 'a string' |
| 818 | let num = 0xbadb33f |
| 819 | let d = {'a': 1, 'b': 2, 'c': str} |
| 820 | let l = [ str, num, d ] |
| 821 | |
| 822 | let locals = #{ |
| 823 | \ s: str, |
| 824 | \ n: num, |
| 825 | \ d: d, |
| 826 | \ l: l, |
| 827 | \ } |
| 828 | |
| 829 | " check basics |
| 830 | call assert_equal('a string', pyeval('s', locals)) |
| 831 | call assert_equal(0xbadb33f, pyeval('n', locals)) |
| 832 | call assert_equal(d, pyeval('d', locals)) |
| 833 | call assert_equal(l, pyeval('l', locals)) |
| 834 | |
| 835 | py << trim EOF |
| 836 | def __UpdateDict(d, upd): |
| 837 | d.update(upd) |
| 838 | return d |
| 839 | |
| 840 | def __ExtendList(l, *args): |
| 841 | l.extend(*args) |
| 842 | return l |
| 843 | EOF |
| 844 | |
| 845 | " check assign to dict member works like bindeval |
| 846 | call assert_equal(3, pyeval('__UpdateDict( d, {"c": 3} )["c"]', locals)) |
| 847 | call assert_equal(3, d['c']) |
| 848 | |
| 849 | " check append lo list |
| 850 | call assert_equal(4, pyeval('len(__ExtendList(l, ["new item"]))', locals)) |
| 851 | call assert_equal("new item", l[-1]) |
| 852 | |
| 853 | " check calling a function |
| 854 | let StrLen = function('strlen') |
| 855 | call assert_equal(3, pyeval('f("abc")', {'f': StrLen})) |
| 856 | endfunc |
| 857 | |
Bram Moolenaar | ab58946 | 2020-07-06 21:03:06 +0200 | [diff] [blame] | 858 | " Test for vim.bindeval() |
| 859 | func Test_python_vim_bindeval() |
| 860 | " Float |
| 861 | let f = 3.14 |
| 862 | py f = vim.bindeval('f') |
| 863 | call assert_equal(3.14, pyeval('f')) |
Bram Moolenaar | 92fdd1e | 2020-07-03 18:00:05 +0200 | [diff] [blame] | 864 | |
Bram Moolenaar | ab58946 | 2020-07-06 21:03:06 +0200 | [diff] [blame] | 865 | " Blob |
| 866 | let b = 0z12 |
| 867 | py b = vim.bindeval('b') |
| 868 | call assert_equal("\x12", pyeval('b')) |
Bram Moolenaar | 92fdd1e | 2020-07-03 18:00:05 +0200 | [diff] [blame] | 869 | |
Bram Moolenaar | ab58946 | 2020-07-06 21:03:06 +0200 | [diff] [blame] | 870 | " Bool |
| 871 | call assert_equal(1, pyeval("vim.bindeval('v:true')")) |
| 872 | call assert_equal(0, pyeval("vim.bindeval('v:false')")) |
| 873 | call assert_equal(v:none, pyeval("vim.bindeval('v:null')")) |
| 874 | call assert_equal(v:none, pyeval("vim.bindeval('v:none')")) |
Bram Moolenaar | 0ab55d6 | 2020-07-07 20:50:39 +0200 | [diff] [blame] | 875 | |
| 876 | " channel/job |
Dominique Pelle | 56c9fd0 | 2021-05-19 00:16:14 +0200 | [diff] [blame] | 877 | if has('channel') |
| 878 | call assert_equal(v:none, pyeval("vim.bindeval('test_null_channel()')")) |
| 879 | endif |
| 880 | if has('job') |
| 881 | call assert_equal(v:none, pyeval("vim.bindeval('test_null_job()')")) |
| 882 | endif |
Bram Moolenaar | 92fdd1e | 2020-07-03 18:00:05 +0200 | [diff] [blame] | 883 | endfunc |
| 884 | |
| 885 | " threading |
| 886 | " Running pydo command (Test_pydo) before this test, stops the python thread |
| 887 | " from running. So this test should be run before the pydo test |
| 888 | func Test_aaa_python_threading() |
| 889 | let l = [0] |
| 890 | py l = vim.bindeval('l') |
| 891 | py << trim EOF |
| 892 | import threading |
| 893 | import time |
| 894 | |
| 895 | class T(threading.Thread): |
| 896 | def __init__(self): |
| 897 | threading.Thread.__init__(self) |
| 898 | self.t = 0 |
| 899 | self.running = True |
| 900 | |
| 901 | def run(self): |
| 902 | while self.running: |
| 903 | self.t += 1 |
| 904 | time.sleep(0.1) |
| 905 | |
| 906 | t = T() |
| 907 | del T |
| 908 | t.start() |
| 909 | EOF |
| 910 | |
| 911 | sleep 1 |
| 912 | py t.running = False |
| 913 | py t.join() |
| 914 | |
| 915 | " Check if the background thread is working. Count should be 10, but on a |
| 916 | " busy system (AppVeyor) it can be much lower. |
| 917 | py l[0] = t.t > 4 |
| 918 | py del time |
| 919 | py del threading |
| 920 | py del t |
| 921 | call assert_equal([1], l) |
| 922 | endfunc |
| 923 | |
| 924 | " settrace |
| 925 | func Test_python_settrace() |
| 926 | let l = [] |
| 927 | py l = vim.bindeval('l') |
| 928 | py << trim EOF |
| 929 | import sys |
| 930 | |
| 931 | def traceit(frame, event, arg): |
| 932 | global l |
| 933 | if event == "line": |
| 934 | l.extend([frame.f_lineno]) |
| 935 | return traceit |
| 936 | |
| 937 | def trace_main(): |
| 938 | for i in range(5): |
| 939 | pass |
| 940 | EOF |
| 941 | py sys.settrace(traceit) |
| 942 | py trace_main() |
| 943 | py sys.settrace(None) |
| 944 | py del traceit |
| 945 | py del trace_main |
| 946 | call assert_equal([1, 10, 11, 10, 11, 10, 11, 10, 11, 10, 11, 10, 1], l) |
| 947 | endfunc |
| 948 | |
| 949 | " Slice |
| 950 | func Test_python_list_slice() |
| 951 | py ll = vim.bindeval('[0, 1, 2, 3, 4, 5]') |
| 952 | py l = ll[:4] |
| 953 | call assert_equal([0, 1, 2, 3], pyeval('l')) |
| 954 | py l = ll[2:] |
| 955 | call assert_equal([2, 3, 4, 5], pyeval('l')) |
| 956 | py l = ll[:-4] |
| 957 | call assert_equal([0, 1], pyeval('l')) |
| 958 | py l = ll[-2:] |
| 959 | call assert_equal([4, 5], pyeval('l')) |
| 960 | py l = ll[2:4] |
| 961 | call assert_equal([2, 3], pyeval('l')) |
| 962 | py l = ll[4:2] |
| 963 | call assert_equal([], pyeval('l')) |
| 964 | py l = ll[-4:-2] |
| 965 | call assert_equal([2, 3], pyeval('l')) |
| 966 | py l = ll[-2:-4] |
| 967 | call assert_equal([], pyeval('l')) |
| 968 | py l = ll[:] |
| 969 | call assert_equal([0, 1, 2, 3, 4, 5], pyeval('l')) |
| 970 | py l = ll[0:6] |
| 971 | call assert_equal([0, 1, 2, 3, 4, 5], pyeval('l')) |
| 972 | py l = ll[-10:10] |
| 973 | call assert_equal([0, 1, 2, 3, 4, 5], pyeval('l')) |
| 974 | py l = ll[4:2:-1] |
| 975 | call assert_equal([4, 3], pyeval('l')) |
| 976 | py l = ll[::2] |
| 977 | call assert_equal([0, 2, 4], pyeval('l')) |
| 978 | py l = ll[4:2:1] |
| 979 | call assert_equal([], pyeval('l')) |
Bram Moolenaar | ab58946 | 2020-07-06 21:03:06 +0200 | [diff] [blame] | 980 | |
| 981 | " Error case: Use an invalid index |
| 982 | call AssertException(['py ll[-10] = 5'], 'Vim(python):vim.error: internal error:') |
| 983 | |
| 984 | " Use a step value of 0 |
| 985 | call AssertException(['py ll[0:3:0] = [1, 2, 3]'], |
| 986 | \ 'Vim(python):ValueError: slice step cannot be zero') |
| 987 | |
| 988 | " Error case: Invalid slice type |
| 989 | call AssertException(["py x = ll['abc']"], |
| 990 | \ 'Vim(python):TypeError: index must be int or slice, not str') |
Bram Moolenaar | 92fdd1e | 2020-07-03 18:00:05 +0200 | [diff] [blame] | 991 | py del l |
Bram Moolenaar | ab58946 | 2020-07-06 21:03:06 +0200 | [diff] [blame] | 992 | |
| 993 | " Error case: List with a null list item |
| 994 | let l = [test_null_list()] |
| 995 | py ll = vim.bindeval('l') |
| 996 | call AssertException(["py x = ll[:]"], |
| 997 | \ 'Vim(python):SystemError: error return without exception set') |
Bram Moolenaar | 92fdd1e | 2020-07-03 18:00:05 +0200 | [diff] [blame] | 998 | endfunc |
| 999 | |
| 1000 | " Vars |
| 1001 | func Test_python_vars() |
| 1002 | let g:foo = 'bac' |
| 1003 | let w:abc3 = 'def' |
| 1004 | let b:baz = 'bar' |
| 1005 | let t:bar = 'jkl' |
| 1006 | try |
| 1007 | throw "Abc" |
| 1008 | catch /Abc/ |
| 1009 | call assert_equal('Abc', pyeval('vim.vvars[''exception'']')) |
| 1010 | endtry |
| 1011 | call assert_equal('bac', pyeval('vim.vars[''foo'']')) |
| 1012 | call assert_equal('def', pyeval('vim.current.window.vars[''abc3'']')) |
| 1013 | call assert_equal('bar', pyeval('vim.current.buffer.vars[''baz'']')) |
| 1014 | call assert_equal('jkl', pyeval('vim.current.tabpage.vars[''bar'']')) |
| 1015 | endfunc |
| 1016 | |
| 1017 | " Options |
| 1018 | " paste: boolean, global |
| 1019 | " previewheight number, global |
| 1020 | " operatorfunc: string, global |
| 1021 | " number: boolean, window-local |
| 1022 | " numberwidth: number, window-local |
| 1023 | " colorcolumn: string, window-local |
| 1024 | " statusline: string, window-local/global |
| 1025 | " autoindent: boolean, buffer-local |
| 1026 | " shiftwidth: number, buffer-local |
| 1027 | " omnifunc: string, buffer-local |
| 1028 | " preserveindent: boolean, buffer-local/global |
| 1029 | " path: string, buffer-local/global |
| 1030 | func Test_python_opts() |
| 1031 | let g:res = [] |
| 1032 | let g:bufs = [bufnr('%')] |
| 1033 | new |
| 1034 | let g:bufs += [bufnr('%')] |
| 1035 | vnew |
| 1036 | let g:bufs += [bufnr('%')] |
| 1037 | wincmd j |
| 1038 | vnew |
| 1039 | let g:bufs += [bufnr('%')] |
| 1040 | wincmd l |
| 1041 | |
| 1042 | func RecVars(opt) |
| 1043 | let gval = string(eval('&g:' .. a:opt)) |
| 1044 | let wvals = join(map(range(1, 4), |
| 1045 | \ 'v:val .. ":" .. string(getwinvar(v:val, "&" .. a:opt))')) |
| 1046 | let bvals = join(map(copy(g:bufs), |
| 1047 | \ 'v:val .. ":" .. string(getbufvar(v:val, "&" .. a:opt))')) |
| 1048 | call add(g:res, ' G: ' .. gval) |
| 1049 | call add(g:res, ' W: ' .. wvals) |
| 1050 | call add(g:res, ' B: ' .. wvals) |
| 1051 | endfunc |
| 1052 | |
| 1053 | py << trim EOF |
| 1054 | def e(s, g=globals(), l=locals()): |
| 1055 | try: |
| 1056 | exec(s, g, l) |
| 1057 | except: |
| 1058 | vim.command('return ' + repr(sys.exc_type.__name__)) |
| 1059 | |
| 1060 | def ev(s, g=globals(), l=locals()): |
| 1061 | try: |
| 1062 | return eval(s, g, l) |
| 1063 | except: |
| 1064 | vim.command('let exc=' + repr(sys.exc_type.__name__)) |
| 1065 | return 0 |
| 1066 | EOF |
| 1067 | |
| 1068 | func E(s) |
| 1069 | python e(vim.eval('a:s')) |
| 1070 | endfunc |
| 1071 | |
| 1072 | func Ev(s) |
| 1073 | let r = pyeval('ev(vim.eval("a:s"))') |
| 1074 | if exists('exc') |
| 1075 | throw exc |
| 1076 | endif |
| 1077 | return r |
| 1078 | endfunc |
| 1079 | |
| 1080 | py gopts1 = vim.options |
| 1081 | py wopts1 = vim.windows[2].options |
| 1082 | py wopts2 = vim.windows[0].options |
| 1083 | py wopts3 = vim.windows[1].options |
| 1084 | py bopts1 = vim.buffers[vim.bindeval("g:bufs")[2]].options |
| 1085 | py bopts2 = vim.buffers[vim.bindeval("g:bufs")[1]].options |
| 1086 | py bopts3 = vim.buffers[vim.bindeval("g:bufs")[0]].options |
| 1087 | call add(g:res, 'wopts iters equal: ' .. |
| 1088 | \ pyeval('list(wopts1) == list(wopts2)')) |
| 1089 | call add(g:res, 'bopts iters equal: ' .. |
| 1090 | \ pyeval('list(bopts1) == list(bopts2)')) |
| 1091 | py gset = set(iter(gopts1)) |
| 1092 | py wset = set(iter(wopts1)) |
| 1093 | py bset = set(iter(bopts1)) |
| 1094 | |
| 1095 | set path=.,..,, |
| 1096 | let lst = [] |
| 1097 | let lst += [['paste', 1, 0, 1, 2, 1, 1, 0]] |
| 1098 | let lst += [['previewheight', 5, 1, 6, 'a', 0, 1, 0]] |
| 1099 | let lst += [['operatorfunc', 'A', 'B', 'C', 2, 0, 1, 0]] |
| 1100 | let lst += [['number', 0, 1, 1, 0, 1, 0, 1]] |
| 1101 | let lst += [['numberwidth', 2, 3, 5, -100, 0, 0, 1]] |
| 1102 | let lst += [['colorcolumn', '+1', '+2', '+3', 'abc4', 0, 0, 1]] |
| 1103 | let lst += [['statusline', '1', '2', '4', 0, 0, 1, 1]] |
| 1104 | let lst += [['autoindent', 0, 1, 1, 2, 1, 0, 2]] |
| 1105 | let lst += [['shiftwidth', 0, 2, 1, 3, 0, 0, 2]] |
| 1106 | let lst += [['omnifunc', 'A', 'B', 'C', 1, 0, 0, 2]] |
| 1107 | let lst += [['preserveindent', 0, 1, 1, 2, 1, 1, 2]] |
| 1108 | let lst += [['path', '.,,', ',,', '.', 0, 0, 1, 2]] |
| 1109 | for [oname, oval1, oval2, oval3, invval, bool, global, local] in lst |
| 1110 | py oname = vim.eval('oname') |
| 1111 | py oval1 = vim.bindeval('oval1') |
| 1112 | py oval2 = vim.bindeval('oval2') |
| 1113 | py oval3 = vim.bindeval('oval3') |
| 1114 | if invval is 0 || invval is 1 |
| 1115 | py invval = bool(vim.bindeval('invval')) |
| 1116 | else |
| 1117 | py invval = vim.bindeval('invval') |
| 1118 | endif |
| 1119 | if bool |
| 1120 | py oval1 = bool(oval1) |
| 1121 | py oval2 = bool(oval2) |
| 1122 | py oval3 = bool(oval3) |
| 1123 | endif |
| 1124 | call add(g:res, '>>> ' .. oname) |
| 1125 | call add(g:res, ' g/w/b:' .. pyeval('oname in gset') .. '/' .. |
| 1126 | \ pyeval('oname in wset') .. '/' .. pyeval('oname in bset')) |
| 1127 | call add(g:res, ' g/w/b (in):' .. pyeval('oname in gopts1') .. '/' .. |
| 1128 | \ pyeval('oname in wopts1') .. '/' .. pyeval('oname in bopts1')) |
| 1129 | for v in ['gopts1', 'wopts1', 'bopts1'] |
| 1130 | try |
| 1131 | call add(g:res, ' p/' .. v .. ': ' .. Ev('repr(' .. v .. '[''' .. oname .. '''])')) |
| 1132 | catch |
| 1133 | call add(g:res, ' p/' .. v .. '! ' .. v:exception) |
| 1134 | endtry |
| 1135 | let r = E(v .. '[''' .. oname .. ''']=invval') |
| 1136 | if r isnot 0 |
| 1137 | call add(g:res, ' inv: ' .. string(invval) .. '! ' .. r) |
| 1138 | endif |
| 1139 | for vv in (v is# 'gopts1' ? [v] : [v, v[:-2] .. '2', v[:-2] .. '3']) |
| 1140 | let val = substitute(vv, '^.opts', 'oval', '') |
| 1141 | let r = E(vv .. '[''' .. oname .. ''']=' .. val) |
| 1142 | if r isnot 0 |
| 1143 | call add(g:res, ' ' .. vv .. '! ' .. r) |
| 1144 | endif |
| 1145 | endfor |
| 1146 | endfor |
| 1147 | call RecVars(oname) |
| 1148 | for v in ['wopts3', 'bopts3'] |
| 1149 | let r = E('del ' .. v .. '["' .. oname .. '"]') |
| 1150 | if r isnot 0 |
| 1151 | call add(g:res, ' del ' .. v .. '! ' .. r) |
| 1152 | endif |
| 1153 | endfor |
| 1154 | call RecVars(oname) |
| 1155 | endfor |
| 1156 | delfunction RecVars |
| 1157 | delfunction E |
| 1158 | delfunction Ev |
| 1159 | py del ev |
| 1160 | py del e |
| 1161 | only |
| 1162 | for buf in g:bufs[1:] |
| 1163 | execute 'bwipeout!' buf |
| 1164 | endfor |
| 1165 | py del gopts1 |
| 1166 | py del wopts1 |
| 1167 | py del wopts2 |
| 1168 | py del wopts3 |
| 1169 | py del bopts1 |
| 1170 | py del bopts2 |
| 1171 | py del bopts3 |
| 1172 | py del oval1 |
| 1173 | py del oval2 |
| 1174 | py del oval3 |
| 1175 | py del oname |
| 1176 | py del invval |
| 1177 | |
| 1178 | let expected =<< trim END |
| 1179 | wopts iters equal: 1 |
| 1180 | bopts iters equal: 1 |
| 1181 | >>> paste |
| 1182 | g/w/b:1/0/0 |
| 1183 | g/w/b (in):1/0/0 |
| 1184 | p/gopts1: False |
| 1185 | p/wopts1! KeyError |
| 1186 | inv: 2! KeyError |
| 1187 | wopts1! KeyError |
| 1188 | wopts2! KeyError |
| 1189 | wopts3! KeyError |
| 1190 | p/bopts1! KeyError |
| 1191 | inv: 2! KeyError |
| 1192 | bopts1! KeyError |
| 1193 | bopts2! KeyError |
| 1194 | bopts3! KeyError |
| 1195 | G: 1 |
| 1196 | W: 1:1 2:1 3:1 4:1 |
| 1197 | B: 1:1 2:1 3:1 4:1 |
| 1198 | del wopts3! KeyError |
| 1199 | del bopts3! KeyError |
| 1200 | G: 1 |
| 1201 | W: 1:1 2:1 3:1 4:1 |
| 1202 | B: 1:1 2:1 3:1 4:1 |
| 1203 | >>> previewheight |
| 1204 | g/w/b:1/0/0 |
| 1205 | g/w/b (in):1/0/0 |
| 1206 | p/gopts1: 12 |
| 1207 | inv: 'a'! TypeError |
| 1208 | p/wopts1! KeyError |
| 1209 | inv: 'a'! KeyError |
| 1210 | wopts1! KeyError |
| 1211 | wopts2! KeyError |
| 1212 | wopts3! KeyError |
| 1213 | p/bopts1! KeyError |
| 1214 | inv: 'a'! KeyError |
| 1215 | bopts1! KeyError |
| 1216 | bopts2! KeyError |
| 1217 | bopts3! KeyError |
| 1218 | G: 5 |
| 1219 | W: 1:5 2:5 3:5 4:5 |
| 1220 | B: 1:5 2:5 3:5 4:5 |
| 1221 | del wopts3! KeyError |
| 1222 | del bopts3! KeyError |
| 1223 | G: 5 |
| 1224 | W: 1:5 2:5 3:5 4:5 |
| 1225 | B: 1:5 2:5 3:5 4:5 |
| 1226 | >>> operatorfunc |
| 1227 | g/w/b:1/0/0 |
| 1228 | g/w/b (in):1/0/0 |
| 1229 | p/gopts1: '' |
| 1230 | inv: 2! TypeError |
| 1231 | p/wopts1! KeyError |
| 1232 | inv: 2! KeyError |
| 1233 | wopts1! KeyError |
| 1234 | wopts2! KeyError |
| 1235 | wopts3! KeyError |
| 1236 | p/bopts1! KeyError |
| 1237 | inv: 2! KeyError |
| 1238 | bopts1! KeyError |
| 1239 | bopts2! KeyError |
| 1240 | bopts3! KeyError |
| 1241 | G: 'A' |
| 1242 | W: 1:'A' 2:'A' 3:'A' 4:'A' |
| 1243 | B: 1:'A' 2:'A' 3:'A' 4:'A' |
| 1244 | del wopts3! KeyError |
| 1245 | del bopts3! KeyError |
| 1246 | G: 'A' |
| 1247 | W: 1:'A' 2:'A' 3:'A' 4:'A' |
| 1248 | B: 1:'A' 2:'A' 3:'A' 4:'A' |
| 1249 | >>> number |
| 1250 | g/w/b:0/1/0 |
| 1251 | g/w/b (in):0/1/0 |
| 1252 | p/gopts1! KeyError |
| 1253 | inv: 0! KeyError |
| 1254 | gopts1! KeyError |
| 1255 | p/wopts1: False |
| 1256 | p/bopts1! KeyError |
| 1257 | inv: 0! KeyError |
| 1258 | bopts1! KeyError |
| 1259 | bopts2! KeyError |
| 1260 | bopts3! KeyError |
| 1261 | G: 0 |
| 1262 | W: 1:1 2:1 3:0 4:0 |
| 1263 | B: 1:1 2:1 3:0 4:0 |
| 1264 | del wopts3! ValueError |
| 1265 | del bopts3! KeyError |
| 1266 | G: 0 |
| 1267 | W: 1:1 2:1 3:0 4:0 |
| 1268 | B: 1:1 2:1 3:0 4:0 |
| 1269 | >>> numberwidth |
| 1270 | g/w/b:0/1/0 |
| 1271 | g/w/b (in):0/1/0 |
| 1272 | p/gopts1! KeyError |
| 1273 | inv: -100! KeyError |
| 1274 | gopts1! KeyError |
| 1275 | p/wopts1: 4 |
| 1276 | inv: -100! error |
| 1277 | p/bopts1! KeyError |
| 1278 | inv: -100! KeyError |
| 1279 | bopts1! KeyError |
| 1280 | bopts2! KeyError |
| 1281 | bopts3! KeyError |
| 1282 | G: 4 |
| 1283 | W: 1:3 2:5 3:2 4:4 |
| 1284 | B: 1:3 2:5 3:2 4:4 |
| 1285 | del wopts3! ValueError |
| 1286 | del bopts3! KeyError |
| 1287 | G: 4 |
| 1288 | W: 1:3 2:5 3:2 4:4 |
| 1289 | B: 1:3 2:5 3:2 4:4 |
| 1290 | >>> colorcolumn |
| 1291 | g/w/b:0/1/0 |
| 1292 | g/w/b (in):0/1/0 |
| 1293 | p/gopts1! KeyError |
| 1294 | inv: 'abc4'! KeyError |
| 1295 | gopts1! KeyError |
| 1296 | p/wopts1: '' |
| 1297 | inv: 'abc4'! error |
| 1298 | p/bopts1! KeyError |
| 1299 | inv: 'abc4'! KeyError |
| 1300 | bopts1! KeyError |
| 1301 | bopts2! KeyError |
| 1302 | bopts3! KeyError |
| 1303 | G: '' |
| 1304 | W: 1:'+2' 2:'+3' 3:'+1' 4:'' |
| 1305 | B: 1:'+2' 2:'+3' 3:'+1' 4:'' |
| 1306 | del wopts3! ValueError |
| 1307 | del bopts3! KeyError |
| 1308 | G: '' |
| 1309 | W: 1:'+2' 2:'+3' 3:'+1' 4:'' |
| 1310 | B: 1:'+2' 2:'+3' 3:'+1' 4:'' |
| 1311 | >>> statusline |
| 1312 | g/w/b:1/1/0 |
| 1313 | g/w/b (in):1/1/0 |
| 1314 | p/gopts1: '' |
| 1315 | inv: 0! TypeError |
| 1316 | p/wopts1: None |
| 1317 | inv: 0! TypeError |
| 1318 | p/bopts1! KeyError |
| 1319 | inv: 0! KeyError |
| 1320 | bopts1! KeyError |
| 1321 | bopts2! KeyError |
| 1322 | bopts3! KeyError |
| 1323 | G: '1' |
| 1324 | W: 1:'2' 2:'4' 3:'1' 4:'1' |
| 1325 | B: 1:'2' 2:'4' 3:'1' 4:'1' |
| 1326 | del bopts3! KeyError |
| 1327 | G: '1' |
| 1328 | W: 1:'2' 2:'1' 3:'1' 4:'1' |
| 1329 | B: 1:'2' 2:'1' 3:'1' 4:'1' |
| 1330 | >>> autoindent |
| 1331 | g/w/b:0/0/1 |
| 1332 | g/w/b (in):0/0/1 |
| 1333 | p/gopts1! KeyError |
| 1334 | inv: 2! KeyError |
| 1335 | gopts1! KeyError |
| 1336 | p/wopts1! KeyError |
| 1337 | inv: 2! KeyError |
| 1338 | wopts1! KeyError |
| 1339 | wopts2! KeyError |
| 1340 | wopts3! KeyError |
| 1341 | p/bopts1: False |
| 1342 | G: 0 |
| 1343 | W: 1:0 2:1 3:0 4:1 |
| 1344 | B: 1:0 2:1 3:0 4:1 |
| 1345 | del wopts3! KeyError |
| 1346 | del bopts3! ValueError |
| 1347 | G: 0 |
| 1348 | W: 1:0 2:1 3:0 4:1 |
| 1349 | B: 1:0 2:1 3:0 4:1 |
| 1350 | >>> shiftwidth |
| 1351 | g/w/b:0/0/1 |
| 1352 | g/w/b (in):0/0/1 |
| 1353 | p/gopts1! KeyError |
| 1354 | inv: 3! KeyError |
| 1355 | gopts1! KeyError |
| 1356 | p/wopts1! KeyError |
| 1357 | inv: 3! KeyError |
| 1358 | wopts1! KeyError |
| 1359 | wopts2! KeyError |
| 1360 | wopts3! KeyError |
| 1361 | p/bopts1: 8 |
| 1362 | G: 8 |
| 1363 | W: 1:0 2:2 3:8 4:1 |
| 1364 | B: 1:0 2:2 3:8 4:1 |
| 1365 | del wopts3! KeyError |
| 1366 | del bopts3! ValueError |
| 1367 | G: 8 |
| 1368 | W: 1:0 2:2 3:8 4:1 |
| 1369 | B: 1:0 2:2 3:8 4:1 |
| 1370 | >>> omnifunc |
| 1371 | g/w/b:0/0/1 |
| 1372 | g/w/b (in):0/0/1 |
| 1373 | p/gopts1! KeyError |
| 1374 | inv: 1! KeyError |
| 1375 | gopts1! KeyError |
| 1376 | p/wopts1! KeyError |
| 1377 | inv: 1! KeyError |
| 1378 | wopts1! KeyError |
| 1379 | wopts2! KeyError |
| 1380 | wopts3! KeyError |
| 1381 | p/bopts1: '' |
| 1382 | inv: 1! TypeError |
| 1383 | G: '' |
| 1384 | W: 1:'A' 2:'B' 3:'' 4:'C' |
| 1385 | B: 1:'A' 2:'B' 3:'' 4:'C' |
| 1386 | del wopts3! KeyError |
| 1387 | del bopts3! ValueError |
| 1388 | G: '' |
| 1389 | W: 1:'A' 2:'B' 3:'' 4:'C' |
| 1390 | B: 1:'A' 2:'B' 3:'' 4:'C' |
| 1391 | >>> preserveindent |
| 1392 | g/w/b:0/0/1 |
| 1393 | g/w/b (in):0/0/1 |
| 1394 | p/gopts1! KeyError |
| 1395 | inv: 2! KeyError |
| 1396 | gopts1! KeyError |
| 1397 | p/wopts1! KeyError |
| 1398 | inv: 2! KeyError |
| 1399 | wopts1! KeyError |
| 1400 | wopts2! KeyError |
| 1401 | wopts3! KeyError |
| 1402 | p/bopts1: False |
| 1403 | G: 0 |
| 1404 | W: 1:0 2:1 3:0 4:1 |
| 1405 | B: 1:0 2:1 3:0 4:1 |
| 1406 | del wopts3! KeyError |
| 1407 | del bopts3! ValueError |
| 1408 | G: 0 |
| 1409 | W: 1:0 2:1 3:0 4:1 |
| 1410 | B: 1:0 2:1 3:0 4:1 |
| 1411 | >>> path |
| 1412 | g/w/b:1/0/1 |
| 1413 | g/w/b (in):1/0/1 |
| 1414 | p/gopts1: '.,..,,' |
| 1415 | inv: 0! TypeError |
| 1416 | p/wopts1! KeyError |
| 1417 | inv: 0! KeyError |
| 1418 | wopts1! KeyError |
| 1419 | wopts2! KeyError |
| 1420 | wopts3! KeyError |
| 1421 | p/bopts1: None |
| 1422 | inv: 0! TypeError |
| 1423 | G: '.,,' |
| 1424 | W: 1:'.,,' 2:',,' 3:'.,,' 4:'.' |
| 1425 | B: 1:'.,,' 2:',,' 3:'.,,' 4:'.' |
| 1426 | del wopts3! KeyError |
| 1427 | G: '.,,' |
| 1428 | W: 1:'.,,' 2:',,' 3:'.,,' 4:'.,,' |
| 1429 | B: 1:'.,,' 2:',,' 3:'.,,' 4:'.,,' |
| 1430 | END |
| 1431 | |
| 1432 | call assert_equal(expected, g:res) |
| 1433 | unlet g:res |
Bram Moolenaar | ab58946 | 2020-07-06 21:03:06 +0200 | [diff] [blame] | 1434 | |
| 1435 | call assert_equal(0, pyeval("'' in vim.options")) |
| 1436 | |
| 1437 | " use an empty key to index vim.options |
| 1438 | call AssertException(["let v = pyeval(\"vim.options['']\")"], |
| 1439 | \ 'Vim(let):ValueError: empty keys are not allowed') |
| 1440 | call AssertException(["py vim.current.window.options[''] = 0"], |
| 1441 | \ 'Vim(python):ValueError: empty keys are not allowed') |
| 1442 | call AssertException(["py vim.current.window.options[{}] = 0"], |
| 1443 | \ 'Vim(python):TypeError: expected str() or unicode() instance, but got dict') |
| 1444 | |
| 1445 | " set one of the number options to a very large number |
| 1446 | let cmd = ["py vim.options['previewheight'] = 9999999999999999"] |
| 1447 | call AssertException(cmd, 'OverflowError:') |
| 1448 | |
| 1449 | " unset a global-local string option |
| 1450 | call AssertException(["py del vim.options['errorformat']"], |
| 1451 | \ 'Vim(python):ValueError: unable to unset global option errorformat') |
Bram Moolenaar | 92fdd1e | 2020-07-03 18:00:05 +0200 | [diff] [blame] | 1452 | endfunc |
| 1453 | |
| 1454 | " Test for vim.buffer object |
| 1455 | func Test_python_buffer() |
| 1456 | new |
| 1457 | call setline(1, "Hello\nWorld") |
| 1458 | call assert_fails("let x = pyeval('vim.current.buffer[0]')", 'E859:') |
| 1459 | %bw! |
| 1460 | |
| 1461 | edit Xfile1 |
| 1462 | let bnr1 = bufnr() |
| 1463 | py cb = vim.current.buffer |
| 1464 | vnew Xfile2 |
| 1465 | let bnr2 = bufnr() |
| 1466 | call setline(1, ['First line', 'Second line', 'Third line']) |
| 1467 | py b = vim.current.buffer |
| 1468 | wincmd w |
| 1469 | |
Bram Moolenaar | ab58946 | 2020-07-06 21:03:06 +0200 | [diff] [blame] | 1470 | " Test for getting lines from the buffer using a slice |
| 1471 | call assert_equal(['First line'], pyeval('b[-10:1]')) |
| 1472 | call assert_equal(['Third line'], pyeval('b[2:10]')) |
| 1473 | call assert_equal([], pyeval('b[2:0]')) |
| 1474 | call assert_equal([], pyeval('b[10:12]')) |
| 1475 | call assert_equal([], pyeval('b[-10:-8]')) |
Bram Moolenaar | 0ab55d6 | 2020-07-07 20:50:39 +0200 | [diff] [blame] | 1476 | call AssertException(["py x = b[0:3:0]"], |
| 1477 | \ "Vim(python):TypeError: sequence index must be integer, not 'slice'") |
| 1478 | call AssertException(["py b[0:3:0] = 'abc'"], |
| 1479 | \ "Vim(python):TypeError: sequence index must be integer, not 'slice'") |
| 1480 | call AssertException(["py x = b[{}]"], |
| 1481 | \ "Vim(python):TypeError: sequence index must be integer, not 'dict'") |
| 1482 | call AssertException(["py b[{}] = 'abc'"], |
| 1483 | \ "Vim(python):TypeError: sequence index must be integer, not 'dict'") |
| 1484 | |
| 1485 | " Test for getting lines using a range |
| 1486 | call AssertException(["py x = b.range(0,3)[0:2:0]"], |
| 1487 | \ "Vim(python):TypeError: sequence index must be integer, not 'slice'") |
| 1488 | call AssertException(["py b.range(0,3)[0:2:0] = 'abc'"], |
| 1489 | \ "Vim(python):TypeError: sequence index must be integer, not 'slice'") |
Bram Moolenaar | ab58946 | 2020-07-06 21:03:06 +0200 | [diff] [blame] | 1490 | |
Bram Moolenaar | 92fdd1e | 2020-07-03 18:00:05 +0200 | [diff] [blame] | 1491 | " Tests BufferAppend and BufferItem |
| 1492 | py cb.append(b[0]) |
| 1493 | call assert_equal(['First line'], getbufline(bnr1, 2)) |
| 1494 | %d |
| 1495 | |
Bram Moolenaar | ab58946 | 2020-07-06 21:03:06 +0200 | [diff] [blame] | 1496 | " Try to append using out-of-range line number |
| 1497 | call AssertException(["py b.append('abc', 10)"], |
| 1498 | \ 'Vim(python):IndexError: line number out of range') |
| 1499 | |
| 1500 | " Append a non-string item |
| 1501 | call AssertException(["py b.append([22])"], |
| 1502 | \ 'Vim(python):TypeError: expected str() or unicode() instance, but got int') |
| 1503 | |
Bram Moolenaar | 92fdd1e | 2020-07-03 18:00:05 +0200 | [diff] [blame] | 1504 | " Tests BufferSlice and BufferAssSlice |
| 1505 | py cb.append('abc5') # Will be overwritten |
| 1506 | py cb[-1:] = b[:-2] |
| 1507 | call assert_equal(['First line'], getbufline(bnr1, 2)) |
| 1508 | %d |
| 1509 | |
| 1510 | " Test BufferLength and BufferAssSlice |
| 1511 | py cb.append('def') # Will not be overwritten |
| 1512 | py cb[len(cb):] = b[:] |
| 1513 | call assert_equal(['def', 'First line', 'Second line', 'Third line'], |
| 1514 | \ getbufline(bnr1, 2, '$')) |
| 1515 | %d |
| 1516 | |
| 1517 | " Test BufferAssItem and BufferMark |
| 1518 | call setbufline(bnr1, 1, ['one', 'two', 'three']) |
| 1519 | call cursor(1, 3) |
| 1520 | normal ma |
| 1521 | py cb.append('ghi') # Will be overwritten |
| 1522 | py cb[-1] = repr((len(cb) - cb.mark('a')[0], cb.mark('a')[1])) |
| 1523 | call assert_equal(['(3, 2)'], getbufline(bnr1, 4)) |
| 1524 | %d |
| 1525 | |
| 1526 | " Test BufferRepr |
| 1527 | py cb.append(repr(cb) + repr(b)) |
| 1528 | call assert_equal(['<buffer Xfile1><buffer Xfile2>'], getbufline(bnr1, 2)) |
| 1529 | %d |
| 1530 | |
| 1531 | " Modify foreign buffer |
| 1532 | py << trim EOF |
| 1533 | b.append('foo') |
| 1534 | b[0]='bar' |
| 1535 | b[0:0]=['baz'] |
| 1536 | vim.command('call append("$", getbufline(%i, 1, "$"))' % b.number) |
| 1537 | EOF |
| 1538 | call assert_equal(['baz', 'bar', 'Second line', 'Third line', 'foo'], |
| 1539 | \ getbufline(bnr2, 1, '$')) |
| 1540 | %d |
| 1541 | |
| 1542 | " Test assigning to name property |
| 1543 | augroup BUFS |
Bram Moolenaar | effb0cd | 2020-07-03 21:17:34 +0200 | [diff] [blame] | 1544 | autocmd BufFilePost * python cb.append(vim.eval('expand("<abuf>")') + ':BufFilePost:' + vim.eval('bufnr("%")')) |
| 1545 | autocmd BufFilePre * python cb.append(vim.eval('expand("<abuf>")') + ':BufFilePre:' + vim.eval('bufnr("%")')) |
Bram Moolenaar | 92fdd1e | 2020-07-03 18:00:05 +0200 | [diff] [blame] | 1546 | augroup END |
| 1547 | py << trim EOF |
| 1548 | import os |
| 1549 | old_name = cb.name |
| 1550 | cb.name = 'foo' |
| 1551 | cb.append(cb.name[-11:].replace(os.path.sep, '/')) |
| 1552 | b.name = 'bar' |
| 1553 | cb.append(b.name[-11:].replace(os.path.sep, '/')) |
| 1554 | cb.name = old_name |
| 1555 | cb.append(cb.name[-14:].replace(os.path.sep, '/')) |
| 1556 | del old_name |
| 1557 | EOF |
| 1558 | call assert_equal([bnr1 .. ':BufFilePre:' .. bnr1, |
| 1559 | \ bnr1 .. ':BufFilePost:' .. bnr1, |
| 1560 | \ 'testdir/foo', |
| 1561 | \ bnr2 .. ':BufFilePre:' .. bnr2, |
| 1562 | \ bnr2 .. ':BufFilePost:' .. bnr2, |
| 1563 | \ 'testdir/bar', |
| 1564 | \ bnr1 .. ':BufFilePre:' .. bnr1, |
| 1565 | \ bnr1 .. ':BufFilePost:' .. bnr1, |
| 1566 | \ 'testdir/Xfile1'], getbufline(bnr1, 2, '$')) |
| 1567 | %d |
| 1568 | |
| 1569 | " Test CheckBuffer |
| 1570 | py << trim EOF |
| 1571 | for _b in vim.buffers: |
| 1572 | if _b is not cb: |
| 1573 | vim.command('bwipeout! ' + str(_b.number)) |
| 1574 | del _b |
| 1575 | cb.append('valid: b:%s, cb:%s' % (repr(b.valid), repr(cb.valid))) |
| 1576 | EOF |
| 1577 | call assert_equal('valid: b:False, cb:True', getline(2)) |
| 1578 | %d |
| 1579 | |
| 1580 | py << trim EOF |
| 1581 | for expr in ('b[1]','b[:] = ["A", "B"]','b[:]','b.append("abc6")', 'b.name = "!"'): |
| 1582 | try: |
| 1583 | exec(expr) |
| 1584 | except vim.error: |
| 1585 | pass |
| 1586 | else: |
| 1587 | # Usually a SEGV here |
| 1588 | # Should not happen in any case |
| 1589 | cb.append('No exception for ' + expr) |
| 1590 | vim.command('cd .') |
| 1591 | del b |
| 1592 | EOF |
| 1593 | call assert_equal([''], getline(1, '$')) |
| 1594 | |
Bram Moolenaar | ab58946 | 2020-07-06 21:03:06 +0200 | [diff] [blame] | 1595 | " Delete all the lines in a buffer |
| 1596 | call setline(1, ['a', 'b', 'c']) |
| 1597 | py vim.current.buffer[:] = [] |
| 1598 | call assert_equal([''], getline(1, '$')) |
| 1599 | |
Bram Moolenaar | 0ab55d6 | 2020-07-07 20:50:39 +0200 | [diff] [blame] | 1600 | " Test for buffer marks |
| 1601 | call assert_equal(v:none, pyeval("vim.current.buffer.mark('r')")) |
| 1602 | |
Bram Moolenaar | ab58946 | 2020-07-06 21:03:06 +0200 | [diff] [blame] | 1603 | " Test for modifying a 'nomodifiable' buffer |
| 1604 | setlocal nomodifiable |
| 1605 | call AssertException(["py vim.current.buffer[0] = 'abc'"], |
| 1606 | \ "Vim(python):vim.error: Vim:E21: Cannot make changes, 'modifiable' is off") |
| 1607 | call AssertException(["py vim.current.buffer[0] = None"], |
| 1608 | \ "Vim(python):vim.error: Vim:E21: Cannot make changes, 'modifiable' is off") |
| 1609 | call AssertException(["py vim.current.buffer[:] = None"], |
| 1610 | \ "Vim(python):vim.error: Vim:E21: Cannot make changes, 'modifiable' is off") |
| 1611 | call AssertException(["py vim.current.buffer[:] = []"], |
| 1612 | \ "Vim(python):vim.error: Vim:E21: Cannot make changes, 'modifiable' is off") |
| 1613 | call AssertException(["py vim.current.buffer.append('abc')"], |
| 1614 | \ "Vim(python):vim.error: Vim:E21: Cannot make changes, 'modifiable' is off") |
| 1615 | call AssertException(["py vim.current.buffer.append([])"], |
| 1616 | \ "Vim(python):vim.error: Vim:E21: Cannot make changes, 'modifiable' is off") |
| 1617 | setlocal modifiable |
| 1618 | |
Bram Moolenaar | 92fdd1e | 2020-07-03 18:00:05 +0200 | [diff] [blame] | 1619 | augroup BUFS |
Bram Moolenaar | effb0cd | 2020-07-03 21:17:34 +0200 | [diff] [blame] | 1620 | autocmd! |
Bram Moolenaar | 92fdd1e | 2020-07-03 18:00:05 +0200 | [diff] [blame] | 1621 | augroup END |
| 1622 | augroup! BUFS |
| 1623 | %bw! |
Bram Moolenaar | ab58946 | 2020-07-06 21:03:06 +0200 | [diff] [blame] | 1624 | |
| 1625 | " Range object for a deleted buffer |
Bram Moolenaar | b18b496 | 2022-09-02 21:55:50 +0100 | [diff] [blame] | 1626 | new Xpbuffile |
Bram Moolenaar | ab58946 | 2020-07-06 21:03:06 +0200 | [diff] [blame] | 1627 | call setline(1, ['one', 'two', 'three']) |
| 1628 | py b = vim.current.buffer |
| 1629 | py r = vim.current.buffer.range(0, 2) |
Bram Moolenaar | b18b496 | 2022-09-02 21:55:50 +0100 | [diff] [blame] | 1630 | call assert_equal('<range Xpbuffile (0:2)>', pyeval('repr(r)')) |
Bram Moolenaar | ab58946 | 2020-07-06 21:03:06 +0200 | [diff] [blame] | 1631 | %bw! |
| 1632 | call AssertException(['py r[:] = []'], |
| 1633 | \ 'Vim(python):vim.error: attempt to refer to deleted buffer') |
| 1634 | call assert_match('<buffer object (deleted)', pyeval('repr(b)')) |
| 1635 | call assert_match('<range object (for deleted buffer)', pyeval('repr(r)')) |
| 1636 | call AssertException(["let n = pyeval('len(r)')"], |
| 1637 | \ 'Vim(let):vim.error: attempt to refer to deleted buffer') |
| 1638 | call AssertException(["py r.append('abc')"], |
| 1639 | \ 'Vim(python):vim.error: attempt to refer to deleted buffer') |
| 1640 | |
| 1641 | " object for a deleted buffer |
| 1642 | call AssertException(["py b[0] = 'one'"], |
| 1643 | \ 'Vim(python):vim.error: attempt to refer to deleted buffer') |
| 1644 | call AssertException(["py b.append('one')"], |
| 1645 | \ 'Vim(python):vim.error: attempt to refer to deleted buffer') |
| 1646 | call AssertException(["let n = pyeval('len(b)')"], |
| 1647 | \ 'Vim(let):vim.error: attempt to refer to deleted buffer') |
| 1648 | call AssertException(["py pos = b.mark('a')"], |
| 1649 | \ 'Vim(python):vim.error: attempt to refer to deleted buffer') |
| 1650 | call AssertException(["py vim.current.buffer = b"], |
| 1651 | \ 'Vim(python):vim.error: attempt to refer to deleted buffer') |
| 1652 | call AssertException(["py rn = b.range(0, 2)"], |
| 1653 | \ 'Vim(python):vim.error: attempt to refer to deleted buffer') |
Bram Moolenaar | 92fdd1e | 2020-07-03 18:00:05 +0200 | [diff] [blame] | 1654 | endfunc |
| 1655 | |
| 1656 | " Test vim.buffers object |
| 1657 | func Test_python_buffers() |
| 1658 | %bw! |
Bram Moolenaar | b18b496 | 2022-09-02 21:55:50 +0100 | [diff] [blame] | 1659 | edit Xpbuffile |
Bram Moolenaar | 92fdd1e | 2020-07-03 18:00:05 +0200 | [diff] [blame] | 1660 | py cb = vim.current.buffer |
| 1661 | set hidden |
| 1662 | edit a |
| 1663 | buffer # |
| 1664 | edit b |
| 1665 | buffer # |
| 1666 | edit c |
| 1667 | buffer # |
| 1668 | py << trim EOF |
| 1669 | try: |
| 1670 | from __builtin__ import next |
| 1671 | except ImportError: |
| 1672 | next = lambda o: o.next() |
| 1673 | # Check GCing iterator that was not fully exhausted |
| 1674 | i = iter(vim.buffers) |
| 1675 | cb.append('i:' + str(next(i))) |
| 1676 | # and also check creating more than one iterator at a time |
| 1677 | i2 = iter(vim.buffers) |
| 1678 | cb.append('i2:' + str(next(i2))) |
| 1679 | cb.append('i:' + str(next(i))) |
| 1680 | # The following should trigger GC and not cause any problems |
| 1681 | del i |
| 1682 | del i2 |
| 1683 | i3 = iter(vim.buffers) |
| 1684 | cb.append('i3:' + str(next(i3))) |
| 1685 | del i3 |
| 1686 | EOF |
Bram Moolenaar | b18b496 | 2022-09-02 21:55:50 +0100 | [diff] [blame] | 1687 | call assert_equal(['i:<buffer Xpbuffile>', |
| 1688 | \ 'i2:<buffer Xpbuffile>', 'i:<buffer a>', 'i3:<buffer Xpbuffile>'], |
Bram Moolenaar | 92fdd1e | 2020-07-03 18:00:05 +0200 | [diff] [blame] | 1689 | \ getline(2, '$')) |
| 1690 | %d |
| 1691 | |
| 1692 | py << trim EOF |
| 1693 | prevnum = 0 |
| 1694 | for b in vim.buffers: |
| 1695 | # Check buffer order |
| 1696 | if prevnum >= b.number: |
| 1697 | cb.append('!!! Buffer numbers not in strictly ascending order') |
| 1698 | # Check indexing: vim.buffers[number].number == number |
| 1699 | cb.append(str(b.number) + ':' + repr(vim.buffers[b.number]) + \ |
| 1700 | '=' + repr(b)) |
| 1701 | prevnum = b.number |
| 1702 | del prevnum |
| 1703 | |
| 1704 | cb.append(str(len(vim.buffers))) |
| 1705 | EOF |
Bram Moolenaar | b18b496 | 2022-09-02 21:55:50 +0100 | [diff] [blame] | 1706 | call assert_equal([bufnr('Xpbuffile') .. ':<buffer Xpbuffile>=<buffer Xpbuffile>', |
Bram Moolenaar | 92fdd1e | 2020-07-03 18:00:05 +0200 | [diff] [blame] | 1707 | \ bufnr('a') .. ':<buffer a>=<buffer a>', |
| 1708 | \ bufnr('b') .. ':<buffer b>=<buffer b>', |
| 1709 | \ bufnr('c') .. ':<buffer c>=<buffer c>', '4'], getline(2, '$')) |
| 1710 | %d |
| 1711 | |
| 1712 | py << trim EOF |
| 1713 | bnums = list(map(lambda b: b.number, vim.buffers))[1:] |
| 1714 | |
| 1715 | # Test wiping out buffer with existing iterator |
| 1716 | i4 = iter(vim.buffers) |
| 1717 | cb.append('i4:' + str(next(i4))) |
| 1718 | vim.command('bwipeout! ' + str(bnums.pop(0))) |
| 1719 | try: |
| 1720 | next(i4) |
| 1721 | except vim.error: |
| 1722 | pass |
| 1723 | else: |
| 1724 | cb.append('!!!! No vim.error') |
| 1725 | i4 = iter(vim.buffers) |
| 1726 | vim.command('bwipeout! ' + str(bnums.pop(-1))) |
| 1727 | vim.command('bwipeout! ' + str(bnums.pop(-1))) |
| 1728 | cb.append('i4:' + str(next(i4))) |
| 1729 | try: |
| 1730 | next(i4) |
| 1731 | except StopIteration: |
| 1732 | cb.append('StopIteration') |
| 1733 | del i4 |
| 1734 | del bnums |
| 1735 | EOF |
Bram Moolenaar | b18b496 | 2022-09-02 21:55:50 +0100 | [diff] [blame] | 1736 | call assert_equal(['i4:<buffer Xpbuffile>', |
| 1737 | \ 'i4:<buffer Xpbuffile>', 'StopIteration'], getline(2, '$')) |
Bram Moolenaar | 92fdd1e | 2020-07-03 18:00:05 +0200 | [diff] [blame] | 1738 | %bw! |
| 1739 | endfunc |
| 1740 | |
| 1741 | " Test vim.{tabpage,window}list and vim.{tabpage,window} objects |
| 1742 | func Test_python_tabpage_window() |
| 1743 | %bw |
Bram Moolenaar | b18b496 | 2022-09-02 21:55:50 +0100 | [diff] [blame] | 1744 | edit Xpbuffile |
Bram Moolenaar | 92fdd1e | 2020-07-03 18:00:05 +0200 | [diff] [blame] | 1745 | py cb = vim.current.buffer |
| 1746 | tabnew 0 |
| 1747 | tabnew 1 |
| 1748 | vnew a.1 |
| 1749 | tabnew 2 |
| 1750 | vnew a.2 |
| 1751 | vnew b.2 |
| 1752 | vnew c.2 |
| 1753 | |
Bram Moolenaar | ab58946 | 2020-07-06 21:03:06 +0200 | [diff] [blame] | 1754 | call assert_equal(4, pyeval('vim.current.window.tabpage.number')) |
| 1755 | |
Bram Moolenaar | 92fdd1e | 2020-07-03 18:00:05 +0200 | [diff] [blame] | 1756 | py << trim EOF |
| 1757 | cb.append('Number of tabs: ' + str(len(vim.tabpages))) |
| 1758 | cb.append('Current tab pages:') |
| 1759 | def W(w): |
| 1760 | if repr(w).find('(unknown)') != -1: |
| 1761 | return '<window object (unknown)>' |
| 1762 | else: |
| 1763 | return repr(w) |
| 1764 | |
| 1765 | start = len(cb) |
| 1766 | |
| 1767 | def Cursor(w): |
| 1768 | if w.buffer is cb: |
| 1769 | return repr((start - w.cursor[0], w.cursor[1])) |
| 1770 | else: |
| 1771 | return repr(w.cursor) |
| 1772 | |
| 1773 | for t in vim.tabpages: |
| 1774 | cb.append(' ' + repr(t) + '(' + str(t.number) + ')' + ': ' + \ |
| 1775 | str(len(t.windows)) + ' windows, current is ' + W(t.window)) |
| 1776 | cb.append(' Windows:') |
| 1777 | for w in t.windows: |
| 1778 | cb.append(' ' + W(w) + '(' + str(w.number) + ')' + \ |
| 1779 | ': displays buffer ' + repr(w.buffer) + \ |
| 1780 | '; cursor is at ' + Cursor(w)) |
| 1781 | # Other values depend on the size of the terminal, so they are checked |
| 1782 | # partly: |
| 1783 | for attr in ('height', 'row', 'width', 'col'): |
| 1784 | try: |
| 1785 | aval = getattr(w, attr) |
| 1786 | if type(aval) is not long: |
| 1787 | raise TypeError |
| 1788 | if aval < 0: |
| 1789 | raise ValueError |
| 1790 | except Exception: |
| 1791 | cb.append('!!!!!! Error while getting attribute ' + attr + \ |
| 1792 | ': ' + sys.exc_type.__name__) |
| 1793 | del aval |
| 1794 | del attr |
| 1795 | w.cursor = (len(w.buffer), 0) |
| 1796 | del W |
| 1797 | del Cursor |
| 1798 | cb.append('Number of windows in current tab page: ' + \ |
| 1799 | str(len(vim.windows))) |
| 1800 | if list(vim.windows) != list(vim.current.tabpage.windows): |
| 1801 | cb.append('!!!!!! Windows differ') |
| 1802 | EOF |
| 1803 | |
Bram Moolenaar | effb0cd | 2020-07-03 21:17:34 +0200 | [diff] [blame] | 1804 | let expected =<< trim END |
Bram Moolenaar | 92fdd1e | 2020-07-03 18:00:05 +0200 | [diff] [blame] | 1805 | Number of tabs: 4 |
| 1806 | Current tab pages: |
| 1807 | <tabpage 0>(1): 1 windows, current is <window object (unknown)> |
| 1808 | Windows: |
Bram Moolenaar | b18b496 | 2022-09-02 21:55:50 +0100 | [diff] [blame] | 1809 | <window object (unknown)>(1): displays buffer <buffer Xpbuffile>; cursor is at (2, 0) |
Bram Moolenaar | 92fdd1e | 2020-07-03 18:00:05 +0200 | [diff] [blame] | 1810 | <tabpage 1>(2): 1 windows, current is <window object (unknown)> |
| 1811 | Windows: |
| 1812 | <window object (unknown)>(1): displays buffer <buffer 0>; cursor is at (1, 0) |
| 1813 | <tabpage 2>(3): 2 windows, current is <window object (unknown)> |
| 1814 | Windows: |
| 1815 | <window object (unknown)>(1): displays buffer <buffer a.1>; cursor is at (1, 0) |
| 1816 | <window object (unknown)>(2): displays buffer <buffer 1>; cursor is at (1, 0) |
| 1817 | <tabpage 3>(4): 4 windows, current is <window 0> |
| 1818 | Windows: |
| 1819 | <window 0>(1): displays buffer <buffer c.2>; cursor is at (1, 0) |
| 1820 | <window 1>(2): displays buffer <buffer b.2>; cursor is at (1, 0) |
| 1821 | <window 2>(3): displays buffer <buffer a.2>; cursor is at (1, 0) |
| 1822 | <window 3>(4): displays buffer <buffer 2>; cursor is at (1, 0) |
| 1823 | Number of windows in current tab page: 4 |
| 1824 | END |
Bram Moolenaar | b18b496 | 2022-09-02 21:55:50 +0100 | [diff] [blame] | 1825 | call assert_equal(expected, getbufline(bufnr('Xpbuffile'), 2, '$')) |
Bram Moolenaar | 92fdd1e | 2020-07-03 18:00:05 +0200 | [diff] [blame] | 1826 | %bw! |
| 1827 | endfunc |
| 1828 | |
| 1829 | " Test vim.current |
| 1830 | func Test_python_vim_current() |
| 1831 | %bw |
Bram Moolenaar | b18b496 | 2022-09-02 21:55:50 +0100 | [diff] [blame] | 1832 | edit Xpbuffile |
Bram Moolenaar | 92fdd1e | 2020-07-03 18:00:05 +0200 | [diff] [blame] | 1833 | py cb = vim.current.buffer |
| 1834 | tabnew 0 |
| 1835 | tabnew 1 |
| 1836 | vnew a.1 |
| 1837 | tabnew 2 |
| 1838 | vnew a.2 |
| 1839 | vnew b.2 |
| 1840 | vnew c.2 |
| 1841 | |
| 1842 | py << trim EOF |
| 1843 | def H(o): |
| 1844 | return repr(o) |
| 1845 | cb.append('Current tab page: ' + repr(vim.current.tabpage)) |
| 1846 | cb.append('Current window: ' + repr(vim.current.window) + ': ' + \ |
| 1847 | H(vim.current.window) + ' is ' + H(vim.current.tabpage.window)) |
| 1848 | cb.append('Current buffer: ' + repr(vim.current.buffer) + ': ' + \ |
| 1849 | H(vim.current.buffer) + ' is ' + H(vim.current.window.buffer)+ \ |
| 1850 | ' is ' + H(vim.current.tabpage.window.buffer)) |
| 1851 | del H |
| 1852 | EOF |
| 1853 | let expected =<< trim END |
| 1854 | Current tab page: <tabpage 3> |
| 1855 | Current window: <window 0>: <window 0> is <window 0> |
| 1856 | Current buffer: <buffer c.2>: <buffer c.2> is <buffer c.2> is <buffer c.2> |
| 1857 | END |
Bram Moolenaar | b18b496 | 2022-09-02 21:55:50 +0100 | [diff] [blame] | 1858 | call assert_equal(expected, getbufline(bufnr('Xpbuffile'), 2, '$')) |
| 1859 | call deletebufline(bufnr('Xpbuffile'), 1, '$') |
Bram Moolenaar | 92fdd1e | 2020-07-03 18:00:05 +0200 | [diff] [blame] | 1860 | |
| 1861 | " Assigning: fails |
| 1862 | py << trim EOF |
| 1863 | try: |
| 1864 | vim.current.window = vim.tabpages[0].window |
| 1865 | except ValueError: |
| 1866 | cb.append('ValueError at assigning foreign tab window') |
| 1867 | |
| 1868 | for attr in ('window', 'tabpage', 'buffer'): |
| 1869 | try: |
| 1870 | setattr(vim.current, attr, None) |
| 1871 | except TypeError: |
| 1872 | cb.append('Type error at assigning None to vim.current.' + attr) |
| 1873 | del attr |
| 1874 | EOF |
| 1875 | |
| 1876 | let expected =<< trim END |
| 1877 | ValueError at assigning foreign tab window |
| 1878 | Type error at assigning None to vim.current.window |
| 1879 | Type error at assigning None to vim.current.tabpage |
| 1880 | Type error at assigning None to vim.current.buffer |
| 1881 | END |
Bram Moolenaar | b18b496 | 2022-09-02 21:55:50 +0100 | [diff] [blame] | 1882 | call assert_equal(expected, getbufline(bufnr('Xpbuffile'), 2, '$')) |
| 1883 | call deletebufline(bufnr('Xpbuffile'), 1, '$') |
Bram Moolenaar | 92fdd1e | 2020-07-03 18:00:05 +0200 | [diff] [blame] | 1884 | |
Bram Moolenaar | b18b496 | 2022-09-02 21:55:50 +0100 | [diff] [blame] | 1885 | call setbufline(bufnr('Xpbuffile'), 1, 'python interface') |
Bram Moolenaar | 92fdd1e | 2020-07-03 18:00:05 +0200 | [diff] [blame] | 1886 | py << trim EOF |
| 1887 | # Assigning: success |
| 1888 | vim.current.tabpage = vim.tabpages[-2] |
| 1889 | vim.current.buffer = cb |
| 1890 | vim.current.window = vim.windows[0] |
| 1891 | vim.current.window.cursor = (len(vim.current.buffer), 0) |
| 1892 | cb.append('Current tab page: ' + repr(vim.current.tabpage)) |
| 1893 | cb.append('Current window: ' + repr(vim.current.window)) |
| 1894 | cb.append('Current buffer: ' + repr(vim.current.buffer)) |
| 1895 | cb.append('Current line: ' + repr(vim.current.line)) |
| 1896 | EOF |
| 1897 | |
| 1898 | let expected =<< trim END |
| 1899 | Current tab page: <tabpage 2> |
| 1900 | Current window: <window 0> |
Bram Moolenaar | b18b496 | 2022-09-02 21:55:50 +0100 | [diff] [blame] | 1901 | Current buffer: <buffer Xpbuffile> |
Bram Moolenaar | 92fdd1e | 2020-07-03 18:00:05 +0200 | [diff] [blame] | 1902 | Current line: 'python interface' |
| 1903 | END |
Bram Moolenaar | b18b496 | 2022-09-02 21:55:50 +0100 | [diff] [blame] | 1904 | call assert_equal(expected, getbufline(bufnr('Xpbuffile'), 2, '$')) |
Bram Moolenaar | ab58946 | 2020-07-06 21:03:06 +0200 | [diff] [blame] | 1905 | py vim.current.line = 'one line' |
| 1906 | call assert_equal('one line', getline('.')) |
Bram Moolenaar | b18b496 | 2022-09-02 21:55:50 +0100 | [diff] [blame] | 1907 | call deletebufline(bufnr('Xpbuffile'), 1, '$') |
Bram Moolenaar | 92fdd1e | 2020-07-03 18:00:05 +0200 | [diff] [blame] | 1908 | |
| 1909 | py << trim EOF |
| 1910 | ws = list(vim.windows) |
| 1911 | ts = list(vim.tabpages) |
| 1912 | for b in vim.buffers: |
| 1913 | if b is not cb: |
| 1914 | vim.command('bwipeout! ' + str(b.number)) |
| 1915 | del b |
| 1916 | cb.append('w.valid: ' + repr([w.valid for w in ws])) |
| 1917 | cb.append('t.valid: ' + repr([t.valid for t in ts])) |
| 1918 | del w |
| 1919 | del t |
| 1920 | del ts |
| 1921 | del ws |
| 1922 | EOF |
| 1923 | let expected =<< trim END |
| 1924 | w.valid: [True, False] |
| 1925 | t.valid: [True, False, True, False] |
| 1926 | END |
Bram Moolenaar | b18b496 | 2022-09-02 21:55:50 +0100 | [diff] [blame] | 1927 | call assert_equal(expected, getbufline(bufnr('Xpbuffile'), 2, '$')) |
Bram Moolenaar | 92fdd1e | 2020-07-03 18:00:05 +0200 | [diff] [blame] | 1928 | %bw! |
| 1929 | endfunc |
| 1930 | |
| 1931 | " Test types |
| 1932 | func Test_python_types() |
| 1933 | %d |
| 1934 | py cb = vim.current.buffer |
| 1935 | py << trim EOF |
| 1936 | for expr, attr in ( |
| 1937 | ('vim.vars', 'Dictionary'), |
| 1938 | ('vim.options', 'Options'), |
| 1939 | ('vim.bindeval("{}")', 'Dictionary'), |
| 1940 | ('vim.bindeval("[]")', 'List'), |
| 1941 | ('vim.bindeval("function(\'tr\')")', 'Function'), |
| 1942 | ('vim.current.buffer', 'Buffer'), |
| 1943 | ('vim.current.range', 'Range'), |
| 1944 | ('vim.current.window', 'Window'), |
| 1945 | ('vim.current.tabpage', 'TabPage'), |
| 1946 | ): |
| 1947 | cb.append(expr + ':' + attr + ':' + \ |
| 1948 | repr(type(eval(expr)) is getattr(vim, attr))) |
| 1949 | del expr |
| 1950 | del attr |
| 1951 | EOF |
| 1952 | let expected =<< trim END |
| 1953 | vim.vars:Dictionary:True |
| 1954 | vim.options:Options:True |
| 1955 | vim.bindeval("{}"):Dictionary:True |
| 1956 | vim.bindeval("[]"):List:True |
| 1957 | vim.bindeval("function('tr')"):Function:True |
| 1958 | vim.current.buffer:Buffer:True |
| 1959 | vim.current.range:Range:True |
| 1960 | vim.current.window:Window:True |
| 1961 | vim.current.tabpage:TabPage:True |
| 1962 | END |
| 1963 | call assert_equal(expected, getline(2, '$')) |
| 1964 | endfunc |
| 1965 | |
| 1966 | " Test __dir__() method |
| 1967 | func Test_python_dir_method() |
| 1968 | %d |
| 1969 | py cb = vim.current.buffer |
| 1970 | py << trim EOF |
| 1971 | for name, o in ( |
| 1972 | ('current', vim.current), |
| 1973 | ('buffer', vim.current.buffer), |
| 1974 | ('window', vim.current.window), |
| 1975 | ('tabpage', vim.current.tabpage), |
| 1976 | ('range', vim.current.range), |
| 1977 | ('dictionary', vim.bindeval('{}')), |
| 1978 | ('list', vim.bindeval('[]')), |
| 1979 | ('function', vim.bindeval('function("tr")')), |
| 1980 | ('output', sys.stdout), |
| 1981 | ): |
| 1982 | cb.append(name + ':' + ','.join(dir(o))) |
| 1983 | del name |
| 1984 | del o |
| 1985 | EOF |
| 1986 | let expected =<< trim END |
| 1987 | current:__dir__,__members__,buffer,line,range,tabpage,window |
| 1988 | buffer:__dir__,__members__,append,mark,name,number,options,range,valid,vars |
| 1989 | window:__dir__,__members__,buffer,col,cursor,height,number,options,row,tabpage,valid,vars,width |
| 1990 | tabpage:__dir__,__members__,number,valid,vars,window,windows |
| 1991 | range:__dir__,__members__,append,end,start |
| 1992 | dictionary:__dir__,__members__,get,has_key,items,keys,locked,pop,popitem,scope,update,values |
| 1993 | list:__dir__,__members__,extend,locked |
| 1994 | function:__dir__,__members__,args,auto_rebind,self,softspace |
| 1995 | output:__dir__,__members__,close,closed,flush,isatty,readable,seekable,softspace,writable,write,writelines |
| 1996 | END |
| 1997 | call assert_equal(expected, getline(2, '$')) |
| 1998 | endfunc |
| 1999 | |
| 2000 | " Test vim.*.__new__ |
| 2001 | func Test_python_new() |
| 2002 | call assert_equal({}, pyeval('vim.Dictionary({})')) |
| 2003 | call assert_equal({'a': 1}, pyeval('vim.Dictionary(a=1)')) |
| 2004 | call assert_equal({'a': 1}, pyeval('vim.Dictionary(((''a'', 1),))')) |
| 2005 | call assert_equal([], pyeval('vim.List()')) |
| 2006 | call assert_equal(['a', 'b', 'c', '7'], pyeval('vim.List(iter(''abc7''))')) |
| 2007 | call assert_equal(function('tr'), pyeval('vim.Function(''tr'')')) |
| 2008 | call assert_equal(function('tr', [123, 3, 4]), |
| 2009 | \ pyeval('vim.Function(''tr'', args=[123, 3, 4])')) |
| 2010 | call assert_equal(function('tr'), pyeval('vim.Function(''tr'', args=[])')) |
| 2011 | call assert_equal(function('tr', {}), |
| 2012 | \ pyeval('vim.Function(''tr'', self={})')) |
| 2013 | call assert_equal(function('tr', [123, 3, 4], {}), |
| 2014 | \ pyeval('vim.Function(''tr'', args=[123, 3, 4], self={})')) |
| 2015 | call assert_equal(function('tr'), |
| 2016 | \ pyeval('vim.Function(''tr'', auto_rebind=False)')) |
| 2017 | call assert_equal(function('tr', [123, 3, 4]), |
| 2018 | \ pyeval('vim.Function(''tr'', args=[123, 3, 4], auto_rebind=False)')) |
| 2019 | call assert_equal(function('tr'), |
| 2020 | \ pyeval('vim.Function(''tr'', args=[], auto_rebind=False)')) |
| 2021 | call assert_equal(function('tr', {}), |
| 2022 | \ pyeval('vim.Function(''tr'', self={}, auto_rebind=False)')) |
| 2023 | call assert_equal(function('tr', [123, 3, 4], {}), |
| 2024 | \ pyeval('vim.Function(''tr'', args=[123, 3, 4], self={}, auto_rebind=False)')) |
| 2025 | endfunc |
| 2026 | |
| 2027 | " Test vim.Function |
| 2028 | func Test_python_vim_func() |
Bram Moolenaar | ab58946 | 2020-07-06 21:03:06 +0200 | [diff] [blame] | 2029 | func Args(...) |
Bram Moolenaar | 92fdd1e | 2020-07-03 18:00:05 +0200 | [diff] [blame] | 2030 | return a:000 |
Bram Moolenaar | ab58946 | 2020-07-06 21:03:06 +0200 | [diff] [blame] | 2031 | endfunc |
Bram Moolenaar | 92fdd1e | 2020-07-03 18:00:05 +0200 | [diff] [blame] | 2032 | |
Bram Moolenaar | ab58946 | 2020-07-06 21:03:06 +0200 | [diff] [blame] | 2033 | func SelfArgs(...) dict |
Bram Moolenaar | 92fdd1e | 2020-07-03 18:00:05 +0200 | [diff] [blame] | 2034 | return [a:000, self] |
Bram Moolenaar | ab58946 | 2020-07-06 21:03:06 +0200 | [diff] [blame] | 2035 | endfunc |
Bram Moolenaar | 92fdd1e | 2020-07-03 18:00:05 +0200 | [diff] [blame] | 2036 | |
| 2037 | " The following four lines should not crash |
| 2038 | let Pt = function('tr', [[]], {'l': []}) |
| 2039 | py Pt = vim.bindeval('Pt') |
| 2040 | unlet Pt |
| 2041 | py del Pt |
| 2042 | |
Bram Moolenaar | ab58946 | 2020-07-06 21:03:06 +0200 | [diff] [blame] | 2043 | call assert_equal(3, pyeval('vim.strwidth("a\tb")')) |
| 2044 | |
Bram Moolenaar | 92fdd1e | 2020-07-03 18:00:05 +0200 | [diff] [blame] | 2045 | %bw! |
| 2046 | py cb = vim.current.buffer |
| 2047 | py << trim EOF |
| 2048 | def ecall(out_prefix, func, *args, **kwargs): |
| 2049 | line = out_prefix + ': ' |
| 2050 | try: |
| 2051 | ret = func(*args, **kwargs) |
| 2052 | except Exception: |
| 2053 | line += '!exception: ' + emsg(sys.exc_info()) |
| 2054 | else: |
| 2055 | line += '!result: ' + vim.Function('string')(ret) |
| 2056 | cb.append(line) |
| 2057 | a = vim.Function('Args') |
| 2058 | pa1 = vim.Function('Args', args=['abcArgsPA1']) |
| 2059 | pa2 = vim.Function('Args', args=[]) |
| 2060 | pa3 = vim.Function('Args', args=['abcArgsPA3'], self={'abcSelfPA3': 'abcSelfPA3Val'}) |
| 2061 | pa4 = vim.Function('Args', self={'abcSelfPA4': 'abcSelfPA4Val'}) |
| 2062 | cb.append('a: ' + repr(a)) |
| 2063 | cb.append('pa1: ' + repr(pa1)) |
| 2064 | cb.append('pa2: ' + repr(pa2)) |
| 2065 | cb.append('pa3: ' + repr(pa3)) |
| 2066 | cb.append('pa4: ' + repr(pa4)) |
| 2067 | sa = vim.Function('SelfArgs') |
| 2068 | psa1 = vim.Function('SelfArgs', args=['abcArgsPSA1']) |
| 2069 | psa2 = vim.Function('SelfArgs', args=[]) |
| 2070 | psa3 = vim.Function('SelfArgs', args=['abcArgsPSA3'], self={'abcSelfPSA3': 'abcSelfPSA3Val'}) |
| 2071 | psa4 = vim.Function('SelfArgs', self={'abcSelfPSA4': 'abcSelfPSA4Val'}) |
| 2072 | psa5 = vim.Function('SelfArgs', self={'abcSelfPSA5': 'abcSelfPSA5Val'}, auto_rebind=0) |
| 2073 | psa6 = vim.Function('SelfArgs', args=['abcArgsPSA6'], self={'abcSelfPSA6': 'abcSelfPSA6Val'}, auto_rebind=()) |
| 2074 | psa7 = vim.Function('SelfArgs', args=['abcArgsPSA7'], auto_rebind=[]) |
| 2075 | psa8 = vim.Function('SelfArgs', auto_rebind=False) |
| 2076 | psa9 = vim.Function('SelfArgs', self={'abcSelfPSA9': 'abcSelfPSA9Val'}, auto_rebind=True) |
| 2077 | psaA = vim.Function('SelfArgs', args=['abcArgsPSAA'], self={'abcSelfPSAA': 'abcSelfPSAAVal'}, auto_rebind=1) |
| 2078 | psaB = vim.Function('SelfArgs', args=['abcArgsPSAB'], auto_rebind={'abcARPSAB': 'abcARPSABVal'}) |
| 2079 | psaC = vim.Function('SelfArgs', auto_rebind=['abcARPSAC']) |
| 2080 | cb.append('sa: ' + repr(sa)) |
| 2081 | cb.append('psa1: ' + repr(psa1)) |
| 2082 | cb.append('psa2: ' + repr(psa2)) |
| 2083 | cb.append('psa3: ' + repr(psa3)) |
| 2084 | cb.append('psa4: ' + repr(psa4)) |
| 2085 | cb.append('psa5: ' + repr(psa5)) |
| 2086 | cb.append('psa6: ' + repr(psa6)) |
| 2087 | cb.append('psa7: ' + repr(psa7)) |
| 2088 | cb.append('psa8: ' + repr(psa8)) |
| 2089 | cb.append('psa9: ' + repr(psa9)) |
| 2090 | cb.append('psaA: ' + repr(psaA)) |
| 2091 | cb.append('psaB: ' + repr(psaB)) |
| 2092 | cb.append('psaC: ' + repr(psaC)) |
Bram Moolenaar | effb0cd | 2020-07-03 21:17:34 +0200 | [diff] [blame] | 2093 | |
Bram Moolenaar | 92fdd1e | 2020-07-03 18:00:05 +0200 | [diff] [blame] | 2094 | psar = vim.Function('SelfArgs', args=[{'abcArgsPSAr': 'abcArgsPSArVal'}], self={'abcSelfPSAr': 'abcSelfPSArVal'}) |
| 2095 | psar.args[0]['abcArgsPSAr2'] = [psar.self, psar.args[0]] |
| 2096 | psar.self['rec'] = psar |
| 2097 | psar.self['self'] = psar.self |
| 2098 | psar.self['args'] = psar.args |
Bram Moolenaar | effb0cd | 2020-07-03 21:17:34 +0200 | [diff] [blame] | 2099 | |
Bram Moolenaar | 92fdd1e | 2020-07-03 18:00:05 +0200 | [diff] [blame] | 2100 | try: |
| 2101 | cb.append('psar: ' + repr(psar)) |
| 2102 | except Exception: |
| 2103 | cb.append('!!!!!!!! Caught exception: ' + emsg(sys.exc_info())) |
| 2104 | EOF |
| 2105 | |
| 2106 | let expected =<< trim END |
| 2107 | a: <vim.Function 'Args'> |
| 2108 | pa1: <vim.Function 'Args', args=['abcArgsPA1']> |
| 2109 | pa2: <vim.Function 'Args'> |
| 2110 | pa3: <vim.Function 'Args', args=['abcArgsPA3'], self={'abcSelfPA3': 'abcSelfPA3Val'}> |
| 2111 | pa4: <vim.Function 'Args', self={'abcSelfPA4': 'abcSelfPA4Val'}> |
| 2112 | sa: <vim.Function 'SelfArgs'> |
| 2113 | psa1: <vim.Function 'SelfArgs', args=['abcArgsPSA1']> |
| 2114 | psa2: <vim.Function 'SelfArgs'> |
| 2115 | psa3: <vim.Function 'SelfArgs', args=['abcArgsPSA3'], self={'abcSelfPSA3': 'abcSelfPSA3Val'}> |
| 2116 | psa4: <vim.Function 'SelfArgs', self={'abcSelfPSA4': 'abcSelfPSA4Val'}> |
| 2117 | psa5: <vim.Function 'SelfArgs', self={'abcSelfPSA5': 'abcSelfPSA5Val'}> |
| 2118 | psa6: <vim.Function 'SelfArgs', args=['abcArgsPSA6'], self={'abcSelfPSA6': 'abcSelfPSA6Val'}> |
| 2119 | psa7: <vim.Function 'SelfArgs', args=['abcArgsPSA7']> |
| 2120 | psa8: <vim.Function 'SelfArgs'> |
| 2121 | psa9: <vim.Function 'SelfArgs', self={'abcSelfPSA9': 'abcSelfPSA9Val'}, auto_rebind=True> |
| 2122 | psaA: <vim.Function 'SelfArgs', args=['abcArgsPSAA'], self={'abcSelfPSAA': 'abcSelfPSAAVal'}, auto_rebind=True> |
| 2123 | psaB: <vim.Function 'SelfArgs', args=['abcArgsPSAB']> |
| 2124 | psaC: <vim.Function 'SelfArgs'> |
| 2125 | psar: <vim.Function 'SelfArgs', args=[{'abcArgsPSAr2': [{'rec': function('SelfArgs', [{...}], {...}), 'self': {...}, 'abcSelfPSAr': 'abcSelfPSArVal', 'args': [{...}]}, {...}], 'abcArgsPSAr': 'abcArgsPSArVal'}], self={'rec': function('SelfArgs', [{'abcArgsPSAr2': [{...}, {...}], 'abcArgsPSAr': 'abcArgsPSArVal'}], {...}), 'self': {...}, 'abcSelfPSAr': 'abcSelfPSArVal', 'args': [{'abcArgsPSAr2': [{...}, {...}], 'abcArgsPSAr': 'abcArgsPSArVal'}]}> |
| 2126 | END |
| 2127 | call assert_equal(expected, getline(2, '$')) |
| 2128 | %d |
| 2129 | |
| 2130 | call assert_equal(function('Args'), pyeval('a')) |
| 2131 | call assert_equal(function('Args', ['abcArgsPA1']), pyeval('pa1')) |
| 2132 | call assert_equal(function('Args'), pyeval('pa2')) |
| 2133 | call assert_equal(function('Args', ['abcArgsPA3'], {'abcSelfPA3': 'abcSelfPA3Val'}), pyeval('pa3')) |
| 2134 | call assert_equal(function('Args', {'abcSelfPA4': 'abcSelfPA4Val'}), pyeval('pa4')) |
| 2135 | call assert_equal(function('SelfArgs'), pyeval('sa')) |
| 2136 | call assert_equal(function('SelfArgs', ['abcArgsPSA1']), pyeval('psa1')) |
| 2137 | call assert_equal(function('SelfArgs'), pyeval('psa2')) |
| 2138 | call assert_equal(function('SelfArgs', ['abcArgsPSA3'], {'abcSelfPSA3': 'abcSelfPSA3Val'}), pyeval('psa3')) |
| 2139 | call assert_equal(function('SelfArgs', {'abcSelfPSA4': 'abcSelfPSA4Val'}), pyeval('psa4')) |
| 2140 | call assert_equal(function('SelfArgs', {'abcSelfPSA5': 'abcSelfPSA5Val'}), pyeval('psa5')) |
| 2141 | call assert_equal(function('SelfArgs', ['abcArgsPSA6'], {'abcSelfPSA6': 'abcSelfPSA6Val'}), pyeval('psa6')) |
| 2142 | call assert_equal(function('SelfArgs', ['abcArgsPSA7']), pyeval('psa7')) |
| 2143 | call assert_equal(function('SelfArgs'), pyeval('psa8')) |
| 2144 | call assert_equal(function('SelfArgs', {'abcSelfPSA9': 'abcSelfPSA9Val'}), pyeval('psa9')) |
| 2145 | call assert_equal(function('SelfArgs', ['abcArgsPSAA'], {'abcSelfPSAA': 'abcSelfPSAAVal'}), pyeval('psaA')) |
| 2146 | call assert_equal(function('SelfArgs', ['abcArgsPSAB']), pyeval('psaB')) |
| 2147 | call assert_equal(function('SelfArgs'), pyeval('psaC')) |
| 2148 | |
| 2149 | let res = [] |
| 2150 | for v in ['sa', 'psa1', 'psa2', 'psa3', 'psa4', 'psa5', 'psa6', 'psa7', |
| 2151 | \ 'psa8', 'psa9', 'psaA', 'psaB', 'psaC'] |
| 2152 | let d = {'f': pyeval(v)} |
| 2153 | call add(res, 'd.' .. v .. '(): ' .. string(d.f())) |
| 2154 | endfor |
| 2155 | |
| 2156 | let expected =<< trim END |
| 2157 | d.sa(): [[], {'f': function('SelfArgs')}] |
| 2158 | d.psa1(): [['abcArgsPSA1'], {'f': function('SelfArgs', ['abcArgsPSA1'])}] |
| 2159 | d.psa2(): [[], {'f': function('SelfArgs')}] |
| 2160 | d.psa3(): [['abcArgsPSA3'], {'abcSelfPSA3': 'abcSelfPSA3Val'}] |
| 2161 | d.psa4(): [[], {'abcSelfPSA4': 'abcSelfPSA4Val'}] |
| 2162 | d.psa5(): [[], {'abcSelfPSA5': 'abcSelfPSA5Val'}] |
| 2163 | d.psa6(): [['abcArgsPSA6'], {'abcSelfPSA6': 'abcSelfPSA6Val'}] |
| 2164 | d.psa7(): [['abcArgsPSA7'], {'f': function('SelfArgs', ['abcArgsPSA7'])}] |
| 2165 | d.psa8(): [[], {'f': function('SelfArgs')}] |
| 2166 | d.psa9(): [[], {'f': function('SelfArgs', {'abcSelfPSA9': 'abcSelfPSA9Val'})}] |
| 2167 | d.psaA(): [['abcArgsPSAA'], {'f': function('SelfArgs', ['abcArgsPSAA'], {'abcSelfPSAA': 'abcSelfPSAAVal'})}] |
| 2168 | d.psaB(): [['abcArgsPSAB'], {'f': function('SelfArgs', ['abcArgsPSAB'])}] |
| 2169 | d.psaC(): [[], {'f': function('SelfArgs')}] |
| 2170 | END |
| 2171 | call assert_equal(expected, res) |
| 2172 | |
| 2173 | py ecall('a()', a, ) |
| 2174 | py ecall('pa1()', pa1, ) |
| 2175 | py ecall('pa2()', pa2, ) |
| 2176 | py ecall('pa3()', pa3, ) |
| 2177 | py ecall('pa4()', pa4, ) |
| 2178 | py ecall('sa()', sa, ) |
| 2179 | py ecall('psa1()', psa1, ) |
| 2180 | py ecall('psa2()', psa2, ) |
| 2181 | py ecall('psa3()', psa3, ) |
| 2182 | py ecall('psa4()', psa4, ) |
| 2183 | |
| 2184 | py ecall('a(42, 43)', a, 42, 43) |
| 2185 | py ecall('pa1(42, 43)', pa1, 42, 43) |
| 2186 | py ecall('pa2(42, 43)', pa2, 42, 43) |
| 2187 | py ecall('pa3(42, 43)', pa3, 42, 43) |
| 2188 | py ecall('pa4(42, 43)', pa4, 42, 43) |
| 2189 | py ecall('sa(42, 43)', sa, 42, 43) |
| 2190 | py ecall('psa1(42, 43)', psa1, 42, 43) |
| 2191 | py ecall('psa2(42, 43)', psa2, 42, 43) |
| 2192 | py ecall('psa3(42, 43)', psa3, 42, 43) |
| 2193 | py ecall('psa4(42, 43)', psa4, 42, 43) |
| 2194 | |
| 2195 | py ecall('a(42, self={"20": 1})', a, 42, self={'20': 1}) |
| 2196 | py ecall('pa1(42, self={"20": 1})', pa1, 42, self={'20': 1}) |
| 2197 | py ecall('pa2(42, self={"20": 1})', pa2, 42, self={'20': 1}) |
| 2198 | py ecall('pa3(42, self={"20": 1})', pa3, 42, self={'20': 1}) |
| 2199 | py ecall('pa4(42, self={"20": 1})', pa4, 42, self={'20': 1}) |
| 2200 | py ecall('sa(42, self={"20": 1})', sa, 42, self={'20': 1}) |
| 2201 | py ecall('psa1(42, self={"20": 1})', psa1, 42, self={'20': 1}) |
| 2202 | py ecall('psa2(42, self={"20": 1})', psa2, 42, self={'20': 1}) |
| 2203 | py ecall('psa3(42, self={"20": 1})', psa3, 42, self={'20': 1}) |
| 2204 | py ecall('psa4(42, self={"20": 1})', psa4, 42, self={'20': 1}) |
| 2205 | |
| 2206 | py ecall('a(self={"20": 1})', a, self={'20': 1}) |
| 2207 | py ecall('pa1(self={"20": 1})', pa1, self={'20': 1}) |
| 2208 | py ecall('pa2(self={"20": 1})', pa2, self={'20': 1}) |
| 2209 | py ecall('pa3(self={"20": 1})', pa3, self={'20': 1}) |
| 2210 | py ecall('pa4(self={"20": 1})', pa4, self={'20': 1}) |
| 2211 | py ecall('sa(self={"20": 1})', sa, self={'20': 1}) |
| 2212 | py ecall('psa1(self={"20": 1})', psa1, self={'20': 1}) |
| 2213 | py ecall('psa2(self={"20": 1})', psa2, self={'20': 1}) |
| 2214 | py ecall('psa3(self={"20": 1})', psa3, self={'20': 1}) |
| 2215 | py ecall('psa4(self={"20": 1})', psa4, self={'20': 1}) |
| 2216 | |
| 2217 | py << trim EOF |
| 2218 | def s(v): |
| 2219 | if v is None: |
| 2220 | return repr(v) |
| 2221 | else: |
| 2222 | return vim.Function('string')(v) |
Bram Moolenaar | effb0cd | 2020-07-03 21:17:34 +0200 | [diff] [blame] | 2223 | |
Bram Moolenaar | 92fdd1e | 2020-07-03 18:00:05 +0200 | [diff] [blame] | 2224 | cb.append('a.args: ' + s(a.args)) |
| 2225 | cb.append('pa1.args: ' + s(pa1.args)) |
| 2226 | cb.append('pa2.args: ' + s(pa2.args)) |
| 2227 | cb.append('pa3.args: ' + s(pa3.args)) |
| 2228 | cb.append('pa4.args: ' + s(pa4.args)) |
| 2229 | cb.append('sa.args: ' + s(sa.args)) |
| 2230 | cb.append('psa1.args: ' + s(psa1.args)) |
| 2231 | cb.append('psa2.args: ' + s(psa2.args)) |
| 2232 | cb.append('psa3.args: ' + s(psa3.args)) |
| 2233 | cb.append('psa4.args: ' + s(psa4.args)) |
Bram Moolenaar | effb0cd | 2020-07-03 21:17:34 +0200 | [diff] [blame] | 2234 | |
Bram Moolenaar | 92fdd1e | 2020-07-03 18:00:05 +0200 | [diff] [blame] | 2235 | cb.append('a.self: ' + s(a.self)) |
| 2236 | cb.append('pa1.self: ' + s(pa1.self)) |
| 2237 | cb.append('pa2.self: ' + s(pa2.self)) |
| 2238 | cb.append('pa3.self: ' + s(pa3.self)) |
| 2239 | cb.append('pa4.self: ' + s(pa4.self)) |
| 2240 | cb.append('sa.self: ' + s(sa.self)) |
| 2241 | cb.append('psa1.self: ' + s(psa1.self)) |
| 2242 | cb.append('psa2.self: ' + s(psa2.self)) |
| 2243 | cb.append('psa3.self: ' + s(psa3.self)) |
| 2244 | cb.append('psa4.self: ' + s(psa4.self)) |
Bram Moolenaar | effb0cd | 2020-07-03 21:17:34 +0200 | [diff] [blame] | 2245 | |
Bram Moolenaar | 92fdd1e | 2020-07-03 18:00:05 +0200 | [diff] [blame] | 2246 | cb.append('a.name: ' + s(a.name)) |
| 2247 | cb.append('pa1.name: ' + s(pa1.name)) |
| 2248 | cb.append('pa2.name: ' + s(pa2.name)) |
| 2249 | cb.append('pa3.name: ' + s(pa3.name)) |
| 2250 | cb.append('pa4.name: ' + s(pa4.name)) |
| 2251 | cb.append('sa.name: ' + s(sa.name)) |
| 2252 | cb.append('psa1.name: ' + s(psa1.name)) |
| 2253 | cb.append('psa2.name: ' + s(psa2.name)) |
| 2254 | cb.append('psa3.name: ' + s(psa3.name)) |
| 2255 | cb.append('psa4.name: ' + s(psa4.name)) |
Bram Moolenaar | effb0cd | 2020-07-03 21:17:34 +0200 | [diff] [blame] | 2256 | |
Bram Moolenaar | 92fdd1e | 2020-07-03 18:00:05 +0200 | [diff] [blame] | 2257 | cb.append('a.auto_rebind: ' + s(a.auto_rebind)) |
| 2258 | cb.append('pa1.auto_rebind: ' + s(pa1.auto_rebind)) |
| 2259 | cb.append('pa2.auto_rebind: ' + s(pa2.auto_rebind)) |
| 2260 | cb.append('pa3.auto_rebind: ' + s(pa3.auto_rebind)) |
| 2261 | cb.append('pa4.auto_rebind: ' + s(pa4.auto_rebind)) |
| 2262 | cb.append('sa.auto_rebind: ' + s(sa.auto_rebind)) |
| 2263 | cb.append('psa1.auto_rebind: ' + s(psa1.auto_rebind)) |
| 2264 | cb.append('psa2.auto_rebind: ' + s(psa2.auto_rebind)) |
| 2265 | cb.append('psa3.auto_rebind: ' + s(psa3.auto_rebind)) |
| 2266 | cb.append('psa4.auto_rebind: ' + s(psa4.auto_rebind)) |
| 2267 | cb.append('psa5.auto_rebind: ' + s(psa5.auto_rebind)) |
| 2268 | cb.append('psa6.auto_rebind: ' + s(psa6.auto_rebind)) |
| 2269 | cb.append('psa7.auto_rebind: ' + s(psa7.auto_rebind)) |
| 2270 | cb.append('psa8.auto_rebind: ' + s(psa8.auto_rebind)) |
| 2271 | cb.append('psa9.auto_rebind: ' + s(psa9.auto_rebind)) |
| 2272 | cb.append('psaA.auto_rebind: ' + s(psaA.auto_rebind)) |
| 2273 | cb.append('psaB.auto_rebind: ' + s(psaB.auto_rebind)) |
| 2274 | cb.append('psaC.auto_rebind: ' + s(psaC.auto_rebind)) |
Bram Moolenaar | effb0cd | 2020-07-03 21:17:34 +0200 | [diff] [blame] | 2275 | |
Bram Moolenaar | 92fdd1e | 2020-07-03 18:00:05 +0200 | [diff] [blame] | 2276 | del s |
Bram Moolenaar | effb0cd | 2020-07-03 21:17:34 +0200 | [diff] [blame] | 2277 | |
Bram Moolenaar | 92fdd1e | 2020-07-03 18:00:05 +0200 | [diff] [blame] | 2278 | del a |
| 2279 | del pa1 |
| 2280 | del pa2 |
| 2281 | del pa3 |
| 2282 | del pa4 |
| 2283 | del sa |
| 2284 | del psa1 |
| 2285 | del psa2 |
| 2286 | del psa3 |
| 2287 | del psa4 |
| 2288 | del psa5 |
| 2289 | del psa6 |
| 2290 | del psa7 |
| 2291 | del psa8 |
| 2292 | del psa9 |
| 2293 | del psaA |
| 2294 | del psaB |
| 2295 | del psaC |
| 2296 | del psar |
Bram Moolenaar | effb0cd | 2020-07-03 21:17:34 +0200 | [diff] [blame] | 2297 | |
Bram Moolenaar | 92fdd1e | 2020-07-03 18:00:05 +0200 | [diff] [blame] | 2298 | del ecall |
| 2299 | EOF |
| 2300 | |
| 2301 | let expected =<< trim END |
| 2302 | a(): !result: [] |
| 2303 | pa1(): !result: ['abcArgsPA1'] |
| 2304 | pa2(): !result: [] |
| 2305 | pa3(): !result: ['abcArgsPA3'] |
| 2306 | pa4(): !result: [] |
| 2307 | sa(): !exception: error:('Vim:E725: Calling dict function without Dictionary: SelfArgs',) |
| 2308 | psa1(): !exception: error:('Vim:E725: Calling dict function without Dictionary: SelfArgs',) |
| 2309 | psa2(): !exception: error:('Vim:E725: Calling dict function without Dictionary: SelfArgs',) |
| 2310 | psa3(): !result: [['abcArgsPSA3'], {'abcSelfPSA3': 'abcSelfPSA3Val'}] |
| 2311 | psa4(): !result: [[], {'abcSelfPSA4': 'abcSelfPSA4Val'}] |
| 2312 | a(42, 43): !result: [42, 43] |
| 2313 | pa1(42, 43): !result: ['abcArgsPA1', 42, 43] |
| 2314 | pa2(42, 43): !result: [42, 43] |
| 2315 | pa3(42, 43): !result: ['abcArgsPA3', 42, 43] |
| 2316 | pa4(42, 43): !result: [42, 43] |
| 2317 | sa(42, 43): !exception: error:('Vim:E725: Calling dict function without Dictionary: SelfArgs',) |
| 2318 | psa1(42, 43): !exception: error:('Vim:E725: Calling dict function without Dictionary: SelfArgs',) |
| 2319 | psa2(42, 43): !exception: error:('Vim:E725: Calling dict function without Dictionary: SelfArgs',) |
| 2320 | psa3(42, 43): !result: [['abcArgsPSA3', 42, 43], {'abcSelfPSA3': 'abcSelfPSA3Val'}] |
| 2321 | psa4(42, 43): !result: [[42, 43], {'abcSelfPSA4': 'abcSelfPSA4Val'}] |
| 2322 | a(42, self={"20": 1}): !result: [42] |
| 2323 | pa1(42, self={"20": 1}): !result: ['abcArgsPA1', 42] |
| 2324 | pa2(42, self={"20": 1}): !result: [42] |
| 2325 | pa3(42, self={"20": 1}): !result: ['abcArgsPA3', 42] |
| 2326 | pa4(42, self={"20": 1}): !result: [42] |
| 2327 | sa(42, self={"20": 1}): !result: [[42], {'20': 1}] |
| 2328 | psa1(42, self={"20": 1}): !result: [['abcArgsPSA1', 42], {'20': 1}] |
| 2329 | psa2(42, self={"20": 1}): !result: [[42], {'20': 1}] |
| 2330 | psa3(42, self={"20": 1}): !result: [['abcArgsPSA3', 42], {'20': 1}] |
| 2331 | psa4(42, self={"20": 1}): !result: [[42], {'20': 1}] |
| 2332 | a(self={"20": 1}): !result: [] |
| 2333 | pa1(self={"20": 1}): !result: ['abcArgsPA1'] |
| 2334 | pa2(self={"20": 1}): !result: [] |
| 2335 | pa3(self={"20": 1}): !result: ['abcArgsPA3'] |
| 2336 | pa4(self={"20": 1}): !result: [] |
| 2337 | sa(self={"20": 1}): !result: [[], {'20': 1}] |
| 2338 | psa1(self={"20": 1}): !result: [['abcArgsPSA1'], {'20': 1}] |
| 2339 | psa2(self={"20": 1}): !result: [[], {'20': 1}] |
| 2340 | psa3(self={"20": 1}): !result: [['abcArgsPSA3'], {'20': 1}] |
| 2341 | psa4(self={"20": 1}): !result: [[], {'20': 1}] |
| 2342 | a.args: None |
| 2343 | pa1.args: ['abcArgsPA1'] |
| 2344 | pa2.args: None |
| 2345 | pa3.args: ['abcArgsPA3'] |
| 2346 | pa4.args: None |
| 2347 | sa.args: None |
| 2348 | psa1.args: ['abcArgsPSA1'] |
| 2349 | psa2.args: None |
| 2350 | psa3.args: ['abcArgsPSA3'] |
| 2351 | psa4.args: None |
| 2352 | a.self: None |
| 2353 | pa1.self: None |
| 2354 | pa2.self: None |
| 2355 | pa3.self: {'abcSelfPA3': 'abcSelfPA3Val'} |
| 2356 | pa4.self: {'abcSelfPA4': 'abcSelfPA4Val'} |
| 2357 | sa.self: None |
| 2358 | psa1.self: None |
| 2359 | psa2.self: None |
| 2360 | psa3.self: {'abcSelfPSA3': 'abcSelfPSA3Val'} |
| 2361 | psa4.self: {'abcSelfPSA4': 'abcSelfPSA4Val'} |
| 2362 | a.name: 'Args' |
| 2363 | pa1.name: 'Args' |
| 2364 | pa2.name: 'Args' |
| 2365 | pa3.name: 'Args' |
| 2366 | pa4.name: 'Args' |
| 2367 | sa.name: 'SelfArgs' |
| 2368 | psa1.name: 'SelfArgs' |
| 2369 | psa2.name: 'SelfArgs' |
| 2370 | psa3.name: 'SelfArgs' |
| 2371 | psa4.name: 'SelfArgs' |
| 2372 | a.auto_rebind: 1 |
| 2373 | pa1.auto_rebind: 1 |
| 2374 | pa2.auto_rebind: 1 |
| 2375 | pa3.auto_rebind: 0 |
| 2376 | pa4.auto_rebind: 0 |
| 2377 | sa.auto_rebind: 1 |
| 2378 | psa1.auto_rebind: 1 |
| 2379 | psa2.auto_rebind: 1 |
| 2380 | psa3.auto_rebind: 0 |
| 2381 | psa4.auto_rebind: 0 |
| 2382 | psa5.auto_rebind: 0 |
| 2383 | psa6.auto_rebind: 0 |
| 2384 | psa7.auto_rebind: 1 |
| 2385 | psa8.auto_rebind: 1 |
| 2386 | psa9.auto_rebind: 1 |
| 2387 | psaA.auto_rebind: 1 |
| 2388 | psaB.auto_rebind: 1 |
| 2389 | psaC.auto_rebind: 1 |
| 2390 | END |
| 2391 | call assert_equal(expected, getline(2, '$')) |
| 2392 | %bw! |
| 2393 | endfunc |
| 2394 | |
| 2395 | " Test stdout/stderr |
| 2396 | func Test_python_stdin_stderr() |
| 2397 | let caught_writeerr = 0 |
| 2398 | let caught_writelineerr = 0 |
| 2399 | redir => messages |
| 2400 | py sys.stdout.write('abc8') ; sys.stdout.write('def') |
| 2401 | try |
| 2402 | py sys.stderr.write('abc9') ; sys.stderr.write('def') |
| 2403 | catch /abc9def/ |
| 2404 | let caught_writeerr = 1 |
| 2405 | endtry |
| 2406 | py sys.stdout.writelines(iter('abcA')) |
| 2407 | try |
| 2408 | py sys.stderr.writelines(iter('abcB')) |
| 2409 | catch /abcB/ |
| 2410 | let caught_writelineerr = 1 |
| 2411 | endtry |
| 2412 | redir END |
| 2413 | call assert_equal("\nabc8def\nabcA", messages) |
| 2414 | call assert_equal(1, caught_writeerr) |
| 2415 | call assert_equal(1, caught_writelineerr) |
| 2416 | endfunc |
| 2417 | |
| 2418 | " Test subclassing |
| 2419 | func Test_python_subclass() |
| 2420 | new |
Bram Moolenaar | ab58946 | 2020-07-06 21:03:06 +0200 | [diff] [blame] | 2421 | func Put(...) |
| 2422 | return a:000 |
| 2423 | endfunc |
Bram Moolenaar | 92fdd1e | 2020-07-03 18:00:05 +0200 | [diff] [blame] | 2424 | |
| 2425 | py << trim EOF |
| 2426 | class DupDict(vim.Dictionary): |
| 2427 | def __setitem__(self, key, value): |
| 2428 | super(DupDict, self).__setitem__(key, value) |
| 2429 | super(DupDict, self).__setitem__('dup_' + key, value) |
| 2430 | dd = DupDict() |
| 2431 | dd['a'] = 'b' |
Bram Moolenaar | effb0cd | 2020-07-03 21:17:34 +0200 | [diff] [blame] | 2432 | |
Bram Moolenaar | 92fdd1e | 2020-07-03 18:00:05 +0200 | [diff] [blame] | 2433 | class DupList(vim.List): |
| 2434 | def __getitem__(self, idx): |
| 2435 | return [super(DupList, self).__getitem__(idx)] * 2 |
Bram Moolenaar | effb0cd | 2020-07-03 21:17:34 +0200 | [diff] [blame] | 2436 | |
Bram Moolenaar | 92fdd1e | 2020-07-03 18:00:05 +0200 | [diff] [blame] | 2437 | dl = DupList() |
| 2438 | dl2 = DupList(iter('abcC')) |
| 2439 | dl.extend(dl2[0]) |
Bram Moolenaar | effb0cd | 2020-07-03 21:17:34 +0200 | [diff] [blame] | 2440 | |
Bram Moolenaar | 92fdd1e | 2020-07-03 18:00:05 +0200 | [diff] [blame] | 2441 | class DupFun(vim.Function): |
| 2442 | def __call__(self, arg): |
| 2443 | return super(DupFun, self).__call__(arg, arg) |
Bram Moolenaar | effb0cd | 2020-07-03 21:17:34 +0200 | [diff] [blame] | 2444 | |
Bram Moolenaar | 92fdd1e | 2020-07-03 18:00:05 +0200 | [diff] [blame] | 2445 | df = DupFun('Put') |
| 2446 | EOF |
| 2447 | |
| 2448 | call assert_equal(['a', 'dup_a'], sort(keys(pyeval('dd')))) |
| 2449 | call assert_equal(['a', 'a'], pyeval('dl')) |
| 2450 | call assert_equal(['a', 'b', 'c', 'C'], pyeval('dl2')) |
| 2451 | call assert_equal([2, 2], pyeval('df(2)')) |
| 2452 | call assert_equal(1, pyeval('dl') is# pyeval('dl')) |
| 2453 | call assert_equal(1, pyeval('dd') is# pyeval('dd')) |
| 2454 | call assert_equal(function('Put'), pyeval('df')) |
| 2455 | delfunction Put |
| 2456 | py << trim EOF |
| 2457 | del DupDict |
| 2458 | del DupList |
| 2459 | del DupFun |
| 2460 | del dd |
| 2461 | del dl |
| 2462 | del dl2 |
| 2463 | del df |
| 2464 | EOF |
| 2465 | close! |
| 2466 | endfunc |
| 2467 | |
| 2468 | " Test chdir |
| 2469 | func Test_python_chdir() |
Bram Moolenaar | b18b496 | 2022-09-02 21:55:50 +0100 | [diff] [blame] | 2470 | new Xpycfile |
Bram Moolenaar | 92fdd1e | 2020-07-03 18:00:05 +0200 | [diff] [blame] | 2471 | py cb = vim.current.buffer |
| 2472 | py << trim EOF |
| 2473 | import os |
| 2474 | fnamemodify = vim.Function('fnamemodify') |
| 2475 | cb.append(fnamemodify('.', ':p:h:t')) |
| 2476 | cb.append(vim.eval('@%')) |
| 2477 | os.chdir('..') |
| 2478 | path = fnamemodify('.', ':p:h:t') |
Bram Moolenaar | 7d69796 | 2020-08-31 21:30:32 +0200 | [diff] [blame] | 2479 | if path != 'src' and path != 'src2': |
Bram Moolenaar | 92fdd1e | 2020-07-03 18:00:05 +0200 | [diff] [blame] | 2480 | # Running tests from a shadow directory, so move up another level |
Bram Moolenaar | b18b496 | 2022-09-02 21:55:50 +0100 | [diff] [blame] | 2481 | # This will result in @% looking like shadow/testdir/Xpycfile, hence the |
Bram Moolenaar | 92fdd1e | 2020-07-03 18:00:05 +0200 | [diff] [blame] | 2482 | # extra fnamemodify |
| 2483 | os.chdir('..') |
| 2484 | cb.append(fnamemodify('.', ':p:h:t')) |
| 2485 | cb.append(fnamemodify(vim.eval('@%'), ':s?^%s.??' % path).replace(os.path.sep, '/')) |
| 2486 | os.chdir(path) |
| 2487 | del path |
| 2488 | else: |
Bram Moolenaar | 7d69796 | 2020-08-31 21:30:32 +0200 | [diff] [blame] | 2489 | # Also accept running from src2/testdir/ for MS-Windows CI. |
| 2490 | cb.append(fnamemodify('.', ':p:h:t').replace('src2', 'src')) |
Bram Moolenaar | 92fdd1e | 2020-07-03 18:00:05 +0200 | [diff] [blame] | 2491 | cb.append(vim.eval('@%').replace(os.path.sep, '/')) |
| 2492 | os.chdir('testdir') |
| 2493 | cb.append(fnamemodify('.', ':p:h:t')) |
| 2494 | cb.append(vim.eval('@%')) |
| 2495 | del fnamemodify |
| 2496 | EOF |
Bram Moolenaar | b18b496 | 2022-09-02 21:55:50 +0100 | [diff] [blame] | 2497 | call assert_equal(['testdir', 'Xpycfile', 'src', 'testdir/Xpycfile', 'testdir', |
| 2498 | \ 'Xpycfile'], getline(2, '$')) |
Bram Moolenaar | 92fdd1e | 2020-07-03 18:00:05 +0200 | [diff] [blame] | 2499 | close! |
Bram Moolenaar | 0ab55d6 | 2020-07-07 20:50:39 +0200 | [diff] [blame] | 2500 | call AssertException(["py vim.chdir(None)"], "Vim(python):TypeError:") |
Bram Moolenaar | 92fdd1e | 2020-07-03 18:00:05 +0200 | [diff] [blame] | 2501 | endfunc |
| 2502 | |
| 2503 | " Test errors |
| 2504 | func Test_python_errors() |
Bram Moolenaar | ab58946 | 2020-07-06 21:03:06 +0200 | [diff] [blame] | 2505 | func F() dict |
| 2506 | endfunc |
Bram Moolenaar | 92fdd1e | 2020-07-03 18:00:05 +0200 | [diff] [blame] | 2507 | |
Bram Moolenaar | ab58946 | 2020-07-06 21:03:06 +0200 | [diff] [blame] | 2508 | func D() |
| 2509 | endfunc |
Bram Moolenaar | 92fdd1e | 2020-07-03 18:00:05 +0200 | [diff] [blame] | 2510 | |
| 2511 | new |
| 2512 | py cb = vim.current.buffer |
| 2513 | |
| 2514 | py << trim EOF |
| 2515 | d = vim.Dictionary() |
| 2516 | ned = vim.Dictionary(foo='bar', baz='abcD') |
| 2517 | dl = vim.Dictionary(a=1) |
| 2518 | dl.locked = True |
| 2519 | l = vim.List() |
| 2520 | ll = vim.List('abcE') |
| 2521 | ll.locked = True |
| 2522 | nel = vim.List('abcO') |
| 2523 | f = vim.Function('string') |
| 2524 | fd = vim.Function('F') |
| 2525 | fdel = vim.Function('D') |
| 2526 | vim.command('delfunction D') |
Bram Moolenaar | effb0cd | 2020-07-03 21:17:34 +0200 | [diff] [blame] | 2527 | |
Bram Moolenaar | 92fdd1e | 2020-07-03 18:00:05 +0200 | [diff] [blame] | 2528 | def subexpr_test(expr, name, subexprs): |
| 2529 | cb.append('>>> Testing %s using %s' % (name, expr)) |
| 2530 | for subexpr in subexprs: |
| 2531 | ee(expr % subexpr) |
| 2532 | cb.append('<<< Finished') |
Bram Moolenaar | effb0cd | 2020-07-03 21:17:34 +0200 | [diff] [blame] | 2533 | |
Bram Moolenaar | 92fdd1e | 2020-07-03 18:00:05 +0200 | [diff] [blame] | 2534 | def stringtochars_test(expr): |
| 2535 | return subexpr_test(expr, 'StringToChars', ( |
| 2536 | '1', # Fail type checks |
| 2537 | 'u"\\0"', # Fail PyString_AsStringAndSize(bytes, , NULL) check |
| 2538 | '"\\0"', # Fail PyString_AsStringAndSize(object, , NULL) check |
| 2539 | )) |
Bram Moolenaar | effb0cd | 2020-07-03 21:17:34 +0200 | [diff] [blame] | 2540 | |
Bram Moolenaar | 92fdd1e | 2020-07-03 18:00:05 +0200 | [diff] [blame] | 2541 | class Mapping(object): |
| 2542 | def __init__(self, d): |
| 2543 | self.d = d |
Bram Moolenaar | effb0cd | 2020-07-03 21:17:34 +0200 | [diff] [blame] | 2544 | |
Bram Moolenaar | 92fdd1e | 2020-07-03 18:00:05 +0200 | [diff] [blame] | 2545 | def __getitem__(self, key): |
| 2546 | return self.d[key] |
Bram Moolenaar | effb0cd | 2020-07-03 21:17:34 +0200 | [diff] [blame] | 2547 | |
Bram Moolenaar | 92fdd1e | 2020-07-03 18:00:05 +0200 | [diff] [blame] | 2548 | def keys(self): |
| 2549 | return self.d.keys() |
Bram Moolenaar | effb0cd | 2020-07-03 21:17:34 +0200 | [diff] [blame] | 2550 | |
Bram Moolenaar | 92fdd1e | 2020-07-03 18:00:05 +0200 | [diff] [blame] | 2551 | def items(self): |
| 2552 | return self.d.items() |
Bram Moolenaar | effb0cd | 2020-07-03 21:17:34 +0200 | [diff] [blame] | 2553 | |
Bram Moolenaar | 92fdd1e | 2020-07-03 18:00:05 +0200 | [diff] [blame] | 2554 | def convertfrompyobject_test(expr, recurse=True): |
| 2555 | # pydict_to_tv |
| 2556 | stringtochars_test(expr % '{%s : 1}') |
| 2557 | if recurse: |
| 2558 | convertfrompyobject_test(expr % '{"abcF" : %s}', False) |
| 2559 | # pymap_to_tv |
| 2560 | stringtochars_test(expr % 'Mapping({%s : 1})') |
| 2561 | if recurse: |
| 2562 | convertfrompyobject_test(expr % 'Mapping({"abcG" : %s})', False) |
| 2563 | # pyseq_to_tv |
| 2564 | iter_test(expr) |
| 2565 | return subexpr_test(expr, 'ConvertFromPyObject', ( |
| 2566 | 'None', # Not conversible |
| 2567 | '{"": 1}', # Empty key not allowed |
| 2568 | '{u"": 1}', # Same, but with unicode object |
| 2569 | 'FailingMapping()', # |
| 2570 | 'FailingMappingKey()', # |
| 2571 | 'FailingNumber()', # |
| 2572 | )) |
Bram Moolenaar | effb0cd | 2020-07-03 21:17:34 +0200 | [diff] [blame] | 2573 | |
Bram Moolenaar | 92fdd1e | 2020-07-03 18:00:05 +0200 | [diff] [blame] | 2574 | def convertfrompymapping_test(expr): |
| 2575 | convertfrompyobject_test(expr) |
| 2576 | return subexpr_test(expr, 'ConvertFromPyMapping', ( |
| 2577 | '[]', |
| 2578 | )) |
Bram Moolenaar | effb0cd | 2020-07-03 21:17:34 +0200 | [diff] [blame] | 2579 | |
Bram Moolenaar | 92fdd1e | 2020-07-03 18:00:05 +0200 | [diff] [blame] | 2580 | def iter_test(expr): |
| 2581 | return subexpr_test(expr, '*Iter*', ( |
| 2582 | 'FailingIter()', |
| 2583 | 'FailingIterNext()', |
| 2584 | )) |
Bram Moolenaar | effb0cd | 2020-07-03 21:17:34 +0200 | [diff] [blame] | 2585 | |
Bram Moolenaar | 92fdd1e | 2020-07-03 18:00:05 +0200 | [diff] [blame] | 2586 | def number_test(expr, natural=False, unsigned=False): |
| 2587 | if natural: |
| 2588 | unsigned = True |
| 2589 | return subexpr_test(expr, 'NumberToLong', ( |
| 2590 | '[]', |
| 2591 | 'None', |
| 2592 | ) + (unsigned and ('-1',) or ()) |
| 2593 | + (natural and ('0',) or ())) |
Bram Moolenaar | effb0cd | 2020-07-03 21:17:34 +0200 | [diff] [blame] | 2594 | |
Bram Moolenaar | 92fdd1e | 2020-07-03 18:00:05 +0200 | [diff] [blame] | 2595 | class FailingTrue(object): |
| 2596 | def __nonzero__(self): |
| 2597 | raise NotImplementedError('bool') |
Bram Moolenaar | effb0cd | 2020-07-03 21:17:34 +0200 | [diff] [blame] | 2598 | |
Bram Moolenaar | 92fdd1e | 2020-07-03 18:00:05 +0200 | [diff] [blame] | 2599 | class FailingIter(object): |
| 2600 | def __iter__(self): |
| 2601 | raise NotImplementedError('iter') |
Bram Moolenaar | effb0cd | 2020-07-03 21:17:34 +0200 | [diff] [blame] | 2602 | |
Bram Moolenaar | 92fdd1e | 2020-07-03 18:00:05 +0200 | [diff] [blame] | 2603 | class FailingIterNext(object): |
| 2604 | def __iter__(self): |
| 2605 | return self |
Bram Moolenaar | effb0cd | 2020-07-03 21:17:34 +0200 | [diff] [blame] | 2606 | |
Bram Moolenaar | 92fdd1e | 2020-07-03 18:00:05 +0200 | [diff] [blame] | 2607 | def next(self): |
| 2608 | raise NotImplementedError('next') |
Bram Moolenaar | effb0cd | 2020-07-03 21:17:34 +0200 | [diff] [blame] | 2609 | |
Bram Moolenaar | 92fdd1e | 2020-07-03 18:00:05 +0200 | [diff] [blame] | 2610 | class FailingIterNextN(object): |
| 2611 | def __init__(self, n): |
| 2612 | self.n = n |
Bram Moolenaar | effb0cd | 2020-07-03 21:17:34 +0200 | [diff] [blame] | 2613 | |
Bram Moolenaar | 92fdd1e | 2020-07-03 18:00:05 +0200 | [diff] [blame] | 2614 | def __iter__(self): |
| 2615 | return self |
Bram Moolenaar | effb0cd | 2020-07-03 21:17:34 +0200 | [diff] [blame] | 2616 | |
Bram Moolenaar | 92fdd1e | 2020-07-03 18:00:05 +0200 | [diff] [blame] | 2617 | def next(self): |
| 2618 | if self.n: |
| 2619 | self.n -= 1 |
| 2620 | return 1 |
| 2621 | else: |
| 2622 | raise NotImplementedError('next N') |
Bram Moolenaar | effb0cd | 2020-07-03 21:17:34 +0200 | [diff] [blame] | 2623 | |
Bram Moolenaar | 92fdd1e | 2020-07-03 18:00:05 +0200 | [diff] [blame] | 2624 | class FailingMappingKey(object): |
| 2625 | def __getitem__(self, item): |
| 2626 | raise NotImplementedError('getitem:mappingkey') |
Bram Moolenaar | effb0cd | 2020-07-03 21:17:34 +0200 | [diff] [blame] | 2627 | |
Bram Moolenaar | 92fdd1e | 2020-07-03 18:00:05 +0200 | [diff] [blame] | 2628 | def keys(self): |
| 2629 | return list("abcH") |
Bram Moolenaar | effb0cd | 2020-07-03 21:17:34 +0200 | [diff] [blame] | 2630 | |
Bram Moolenaar | 92fdd1e | 2020-07-03 18:00:05 +0200 | [diff] [blame] | 2631 | class FailingMapping(object): |
| 2632 | def __getitem__(self): |
| 2633 | raise NotImplementedError('getitem:mapping') |
Bram Moolenaar | effb0cd | 2020-07-03 21:17:34 +0200 | [diff] [blame] | 2634 | |
Bram Moolenaar | 92fdd1e | 2020-07-03 18:00:05 +0200 | [diff] [blame] | 2635 | def keys(self): |
| 2636 | raise NotImplementedError('keys') |
Bram Moolenaar | effb0cd | 2020-07-03 21:17:34 +0200 | [diff] [blame] | 2637 | |
Bram Moolenaar | 92fdd1e | 2020-07-03 18:00:05 +0200 | [diff] [blame] | 2638 | class FailingList(list): |
| 2639 | def __getitem__(self, idx): |
| 2640 | if i == 2: |
| 2641 | raise NotImplementedError('getitem:list') |
| 2642 | else: |
| 2643 | return super(FailingList, self).__getitem__(idx) |
Bram Moolenaar | effb0cd | 2020-07-03 21:17:34 +0200 | [diff] [blame] | 2644 | |
Bram Moolenaar | 92fdd1e | 2020-07-03 18:00:05 +0200 | [diff] [blame] | 2645 | class NoArgsCall(object): |
| 2646 | def __call__(self): |
| 2647 | pass |
Bram Moolenaar | effb0cd | 2020-07-03 21:17:34 +0200 | [diff] [blame] | 2648 | |
Bram Moolenaar | 92fdd1e | 2020-07-03 18:00:05 +0200 | [diff] [blame] | 2649 | class FailingCall(object): |
| 2650 | def __call__(self, path): |
| 2651 | raise NotImplementedError('call') |
Bram Moolenaar | effb0cd | 2020-07-03 21:17:34 +0200 | [diff] [blame] | 2652 | |
Bram Moolenaar | 92fdd1e | 2020-07-03 18:00:05 +0200 | [diff] [blame] | 2653 | class FailingNumber(object): |
| 2654 | def __int__(self): |
| 2655 | raise NotImplementedError('int') |
Bram Moolenaar | effb0cd | 2020-07-03 21:17:34 +0200 | [diff] [blame] | 2656 | |
Bram Moolenaar | 92fdd1e | 2020-07-03 18:00:05 +0200 | [diff] [blame] | 2657 | cb.append("> Output") |
| 2658 | cb.append(">> OutputSetattr") |
| 2659 | ee('del sys.stdout.softspace') |
| 2660 | number_test('sys.stdout.softspace = %s', unsigned=True) |
| 2661 | number_test('sys.stderr.softspace = %s', unsigned=True) |
| 2662 | ee('assert sys.stdout.isatty()==False') |
| 2663 | ee('assert sys.stdout.seekable()==False') |
| 2664 | ee('sys.stdout.close()') |
| 2665 | ee('sys.stdout.flush()') |
| 2666 | ee('assert sys.stderr.isatty()==False') |
| 2667 | ee('assert sys.stderr.seekable()==False') |
| 2668 | ee('sys.stderr.close()') |
| 2669 | ee('sys.stderr.flush()') |
| 2670 | ee('sys.stdout.attr = None') |
| 2671 | cb.append(">> OutputWrite") |
| 2672 | ee('assert sys.stdout.writable()==True') |
| 2673 | ee('assert sys.stdout.readable()==False') |
| 2674 | ee('assert sys.stderr.writable()==True') |
| 2675 | ee('assert sys.stderr.readable()==False') |
| 2676 | ee('assert sys.stdout.closed()==False') |
| 2677 | ee('assert sys.stderr.closed()==False') |
| 2678 | ee('assert sys.stdout.errors=="strict"') |
| 2679 | ee('assert sys.stderr.errors=="strict"') |
| 2680 | ee('assert sys.stdout.encoding==sys.stderr.encoding') |
| 2681 | ee('sys.stdout.write(None)') |
| 2682 | cb.append(">> OutputWriteLines") |
| 2683 | ee('sys.stdout.writelines(None)') |
| 2684 | ee('sys.stdout.writelines([1])') |
| 2685 | iter_test('sys.stdout.writelines(%s)') |
| 2686 | cb.append("> VimCommand") |
| 2687 | stringtochars_test('vim.command(%s)') |
| 2688 | ee('vim.command("", 2)') |
| 2689 | #! Not checked: vim->python exceptions translating: checked later |
| 2690 | cb.append("> VimToPython") |
| 2691 | #! Not checked: everything: needs errors in internal python functions |
| 2692 | cb.append("> VimEval") |
| 2693 | stringtochars_test('vim.eval(%s)') |
| 2694 | ee('vim.eval("", FailingTrue())') |
| 2695 | #! Not checked: everything: needs errors in internal python functions |
| 2696 | cb.append("> VimEvalPy") |
| 2697 | stringtochars_test('vim.bindeval(%s)') |
| 2698 | ee('vim.eval("", 2)') |
| 2699 | #! Not checked: vim->python exceptions translating: checked later |
| 2700 | cb.append("> VimStrwidth") |
| 2701 | stringtochars_test('vim.strwidth(%s)') |
| 2702 | cb.append("> VimForeachRTP") |
| 2703 | ee('vim.foreach_rtp(None)') |
| 2704 | ee('vim.foreach_rtp(NoArgsCall())') |
| 2705 | ee('vim.foreach_rtp(FailingCall())') |
| 2706 | ee('vim.foreach_rtp(int, 2)') |
| 2707 | cb.append('> import') |
| 2708 | old_rtp = vim.options['rtp'] |
| 2709 | vim.options['rtp'] = os.getcwd().replace('\\', '\\\\').replace(',', '\\,') |
| 2710 | ee('import xxx_no_such_module_xxx') |
| 2711 | ee('import failing_import') |
| 2712 | ee('import failing') |
| 2713 | vim.options['rtp'] = old_rtp |
| 2714 | del old_rtp |
| 2715 | cb.append("> Options") |
| 2716 | cb.append(">> OptionsItem") |
| 2717 | ee('vim.options["abcQ"]') |
| 2718 | ee('vim.options[""]') |
| 2719 | stringtochars_test('vim.options[%s]') |
| 2720 | cb.append(">> OptionsContains") |
| 2721 | stringtochars_test('%s in vim.options') |
| 2722 | cb.append("> Dictionary") |
| 2723 | cb.append(">> DictionaryConstructor") |
| 2724 | ee('vim.Dictionary("abcI")') |
| 2725 | ##! Not checked: py_dict_alloc failure |
| 2726 | cb.append(">> DictionarySetattr") |
| 2727 | ee('del d.locked') |
| 2728 | ee('d.locked = FailingTrue()') |
| 2729 | ee('vim.vvars.locked = False') |
| 2730 | ee('d.scope = True') |
| 2731 | ee('d.xxx = True') |
| 2732 | cb.append(">> _DictionaryItem") |
| 2733 | ee('d.get("a", 2, 3)') |
| 2734 | stringtochars_test('d.get(%s)') |
| 2735 | ee('d.pop("a")') |
| 2736 | ee('dl.pop("a")') |
| 2737 | cb.append(">> DictionaryContains") |
| 2738 | ee('"" in d') |
| 2739 | ee('0 in d') |
| 2740 | cb.append(">> DictionaryIterNext") |
| 2741 | ee('for i in ned: ned["a"] = 1') |
| 2742 | del i |
| 2743 | cb.append(">> DictionaryAssItem") |
| 2744 | ee('dl["b"] = 1') |
| 2745 | stringtochars_test('d[%s] = 1') |
| 2746 | convertfrompyobject_test('d["a"] = %s') |
| 2747 | cb.append(">> DictionaryUpdate") |
| 2748 | cb.append(">>> kwargs") |
| 2749 | cb.append(">>> iter") |
| 2750 | ee('d.update(FailingMapping())') |
| 2751 | ee('d.update([FailingIterNext()])') |
| 2752 | ee('d.update([FailingIterNextN(1)])') |
| 2753 | iter_test('d.update(%s)') |
| 2754 | convertfrompyobject_test('d.update(%s)') |
| 2755 | stringtochars_test('d.update(((%s, 0),))') |
| 2756 | convertfrompyobject_test('d.update((("a", %s),))') |
| 2757 | cb.append(">> DictionaryPopItem") |
| 2758 | ee('d.popitem(1, 2)') |
| 2759 | cb.append(">> DictionaryHasKey") |
| 2760 | ee('d.has_key()') |
| 2761 | cb.append("> List") |
| 2762 | cb.append(">> ListConstructor") |
| 2763 | ee('vim.List(1, 2)') |
| 2764 | ee('vim.List(a=1)') |
| 2765 | iter_test('vim.List(%s)') |
| 2766 | convertfrompyobject_test('vim.List([%s])') |
| 2767 | cb.append(">> ListItem") |
| 2768 | ee('l[1000]') |
| 2769 | cb.append(">> ListAssItem") |
| 2770 | ee('ll[1] = 2') |
| 2771 | ee('l[1000] = 3') |
| 2772 | cb.append(">> ListAssSlice") |
| 2773 | ee('ll[1:100] = "abcJ"') |
| 2774 | iter_test('l[:] = %s') |
| 2775 | ee('nel[1:10:2] = "abcK"') |
| 2776 | cb.append(repr(tuple(nel))) |
| 2777 | ee('nel[1:10:2] = "a"') |
| 2778 | cb.append(repr(tuple(nel))) |
| 2779 | ee('nel[1:1:-1] = "a"') |
| 2780 | cb.append(repr(tuple(nel))) |
| 2781 | ee('nel[:] = FailingIterNextN(2)') |
| 2782 | cb.append(repr(tuple(nel))) |
| 2783 | convertfrompyobject_test('l[:] = [%s]') |
| 2784 | cb.append(">> ListConcatInPlace") |
| 2785 | iter_test('l.extend(%s)') |
| 2786 | convertfrompyobject_test('l.extend([%s])') |
| 2787 | cb.append(">> ListSetattr") |
| 2788 | ee('del l.locked') |
| 2789 | ee('l.locked = FailingTrue()') |
| 2790 | ee('l.xxx = True') |
| 2791 | cb.append("> Function") |
| 2792 | cb.append(">> FunctionConstructor") |
| 2793 | cb.append(">>> FunctionConstructor") |
| 2794 | ee('vim.Function("123")') |
| 2795 | ee('vim.Function("xxx_non_existent_function_xxx")') |
| 2796 | ee('vim.Function("xxx#non#existent#function#xxx")') |
| 2797 | ee('vim.Function("xxx_non_existent_function_xxx2", args=[])') |
| 2798 | ee('vim.Function("xxx_non_existent_function_xxx3", self={})') |
| 2799 | ee('vim.Function("xxx_non_existent_function_xxx4", args=[], self={})') |
| 2800 | cb.append(">>> FunctionNew") |
| 2801 | ee('vim.Function("tr", self="abcFuncSelf")') |
| 2802 | ee('vim.Function("tr", args=427423)') |
| 2803 | ee('vim.Function("tr", self="abcFuncSelf2", args="abcFuncArgs2")') |
| 2804 | ee('vim.Function(self="abcFuncSelf2", args="abcFuncArgs2")') |
| 2805 | ee('vim.Function("tr", "", self="abcFuncSelf2", args="abcFuncArgs2")') |
| 2806 | ee('vim.Function("tr", "")') |
| 2807 | cb.append(">> FunctionCall") |
| 2808 | convertfrompyobject_test('f(%s)') |
| 2809 | convertfrompymapping_test('fd(self=%s)') |
| 2810 | cb.append("> TabPage") |
| 2811 | cb.append(">> TabPageAttr") |
| 2812 | ee('vim.current.tabpage.xxx') |
| 2813 | cb.append("> TabList") |
| 2814 | cb.append(">> TabListItem") |
| 2815 | ee('vim.tabpages[1000]') |
| 2816 | cb.append("> Window") |
| 2817 | cb.append(">> WindowAttr") |
| 2818 | ee('vim.current.window.xxx') |
| 2819 | cb.append(">> WindowSetattr") |
| 2820 | ee('vim.current.window.buffer = 0') |
| 2821 | ee('vim.current.window.cursor = (100000000, 100000000)') |
| 2822 | ee('vim.current.window.cursor = True') |
| 2823 | number_test('vim.current.window.height = %s', unsigned=True) |
| 2824 | number_test('vim.current.window.width = %s', unsigned=True) |
| 2825 | ee('vim.current.window.xxxxxx = True') |
| 2826 | cb.append("> WinList") |
| 2827 | cb.append(">> WinListItem") |
| 2828 | ee('vim.windows[1000]') |
| 2829 | cb.append("> Buffer") |
| 2830 | cb.append(">> StringToLine (indirect)") |
Bram Moolenaar | 92fdd1e | 2020-07-03 18:00:05 +0200 | [diff] [blame] | 2831 | ee('vim.current.buffer[0] = "\\na"') |
Bram Moolenaar | ab58946 | 2020-07-06 21:03:06 +0200 | [diff] [blame] | 2832 | ee('vim.current.buffer[0] = u"\\na"') |
Bram Moolenaar | 92fdd1e | 2020-07-03 18:00:05 +0200 | [diff] [blame] | 2833 | cb.append(">> SetBufferLine (indirect)") |
| 2834 | ee('vim.current.buffer[0] = True') |
| 2835 | cb.append(">> SetBufferLineList (indirect)") |
| 2836 | ee('vim.current.buffer[:] = True') |
| 2837 | ee('vim.current.buffer[:] = ["\\na", "bc"]') |
| 2838 | cb.append(">> InsertBufferLines (indirect)") |
| 2839 | ee('vim.current.buffer.append(None)') |
| 2840 | ee('vim.current.buffer.append(["\\na", "bc"])') |
| 2841 | ee('vim.current.buffer.append("\\nbc")') |
| 2842 | cb.append(">> RBItem") |
| 2843 | ee('vim.current.buffer[100000000]') |
| 2844 | cb.append(">> RBAsItem") |
| 2845 | ee('vim.current.buffer[100000000] = ""') |
| 2846 | cb.append(">> BufferAttr") |
| 2847 | ee('vim.current.buffer.xxx') |
| 2848 | cb.append(">> BufferSetattr") |
| 2849 | ee('vim.current.buffer.name = True') |
| 2850 | ee('vim.current.buffer.xxx = True') |
| 2851 | cb.append(">> BufferMark") |
| 2852 | ee('vim.current.buffer.mark(0)') |
| 2853 | ee('vim.current.buffer.mark("abcM")') |
| 2854 | ee('vim.current.buffer.mark("!")') |
| 2855 | cb.append(">> BufferRange") |
| 2856 | ee('vim.current.buffer.range(1, 2, 3)') |
| 2857 | cb.append("> BufMap") |
| 2858 | cb.append(">> BufMapItem") |
| 2859 | ee('vim.buffers[100000000]') |
| 2860 | number_test('vim.buffers[%s]', natural=True) |
| 2861 | cb.append("> Current") |
| 2862 | cb.append(">> CurrentGetattr") |
| 2863 | ee('vim.current.xxx') |
| 2864 | cb.append(">> CurrentSetattr") |
| 2865 | ee('vim.current.line = True') |
| 2866 | ee('vim.current.buffer = True') |
| 2867 | ee('vim.current.window = True') |
| 2868 | ee('vim.current.tabpage = True') |
| 2869 | ee('vim.current.xxx = True') |
| 2870 | del d |
| 2871 | del ned |
| 2872 | del dl |
| 2873 | del l |
| 2874 | del ll |
| 2875 | del nel |
| 2876 | del f |
| 2877 | del fd |
| 2878 | del fdel |
| 2879 | del subexpr_test |
| 2880 | del stringtochars_test |
| 2881 | del Mapping |
| 2882 | del convertfrompyobject_test |
| 2883 | del convertfrompymapping_test |
| 2884 | del iter_test |
| 2885 | del number_test |
| 2886 | del FailingTrue |
| 2887 | del FailingIter |
| 2888 | del FailingIterNext |
| 2889 | del FailingIterNextN |
| 2890 | del FailingMapping |
| 2891 | del FailingMappingKey |
| 2892 | del FailingList |
| 2893 | del NoArgsCall |
| 2894 | del FailingCall |
| 2895 | del FailingNumber |
| 2896 | EOF |
| 2897 | delfunction F |
| 2898 | |
| 2899 | let expected =<< trim END |
| 2900 | > Output |
| 2901 | >> OutputSetattr |
| 2902 | del sys.stdout.softspace:AttributeError:('cannot delete OutputObject attributes',) |
| 2903 | >>> Testing NumberToLong using sys.stdout.softspace = %s |
| 2904 | sys.stdout.softspace = []:TypeError:('expected int(), long() or something supporting coercing to long(), but got list',) |
| 2905 | sys.stdout.softspace = None:TypeError:('expected int(), long() or something supporting coercing to long(), but got NoneType',) |
| 2906 | sys.stdout.softspace = -1:ValueError:('number must be greater or equal to zero',) |
| 2907 | <<< Finished |
| 2908 | >>> Testing NumberToLong using sys.stderr.softspace = %s |
| 2909 | sys.stderr.softspace = []:TypeError:('expected int(), long() or something supporting coercing to long(), but got list',) |
| 2910 | sys.stderr.softspace = None:TypeError:('expected int(), long() or something supporting coercing to long(), but got NoneType',) |
| 2911 | sys.stderr.softspace = -1:ValueError:('number must be greater or equal to zero',) |
| 2912 | <<< Finished |
| 2913 | assert sys.stdout.isatty()==False:NOT FAILED |
| 2914 | assert sys.stdout.seekable()==False:NOT FAILED |
| 2915 | sys.stdout.close():NOT FAILED |
| 2916 | sys.stdout.flush():NOT FAILED |
| 2917 | assert sys.stderr.isatty()==False:NOT FAILED |
| 2918 | assert sys.stderr.seekable()==False:NOT FAILED |
| 2919 | sys.stderr.close():NOT FAILED |
| 2920 | sys.stderr.flush():NOT FAILED |
| 2921 | sys.stdout.attr = None:AttributeError:('invalid attribute: attr',) |
| 2922 | >> OutputWrite |
| 2923 | assert sys.stdout.writable()==True:NOT FAILED |
| 2924 | assert sys.stdout.readable()==False:NOT FAILED |
| 2925 | assert sys.stderr.writable()==True:NOT FAILED |
| 2926 | assert sys.stderr.readable()==False:NOT FAILED |
| 2927 | assert sys.stdout.closed()==False:NOT FAILED |
| 2928 | assert sys.stderr.closed()==False:NOT FAILED |
| 2929 | assert sys.stdout.errors=="strict":NOT FAILED |
| 2930 | assert sys.stderr.errors=="strict":NOT FAILED |
| 2931 | assert sys.stdout.encoding==sys.stderr.encoding:NOT FAILED |
| 2932 | sys.stdout.write(None):TypeError:('coercing to Unicode: need string or buffer, NoneType found',) |
| 2933 | >> OutputWriteLines |
| 2934 | sys.stdout.writelines(None):TypeError:("'NoneType' object is not iterable",) |
| 2935 | sys.stdout.writelines([1]):TypeError:('coercing to Unicode: need string or buffer, int found',) |
| 2936 | >>> Testing *Iter* using sys.stdout.writelines(%s) |
| 2937 | sys.stdout.writelines(FailingIter()):NotImplementedError:('iter',) |
| 2938 | sys.stdout.writelines(FailingIterNext()):NotImplementedError:('next',) |
| 2939 | <<< Finished |
| 2940 | > VimCommand |
| 2941 | >>> Testing StringToChars using vim.command(%s) |
| 2942 | vim.command(1):TypeError:('expected str() or unicode() instance, but got int',) |
| 2943 | vim.command(u"\0"):TypeError:('expected string without null bytes',) |
| 2944 | vim.command("\0"):TypeError:('expected string without null bytes',) |
| 2945 | <<< Finished |
| 2946 | vim.command("", 2):TypeError:('command() takes exactly one argument (2 given)',) |
| 2947 | > VimToPython |
| 2948 | > VimEval |
| 2949 | >>> Testing StringToChars using vim.eval(%s) |
| 2950 | vim.eval(1):TypeError:('expected str() or unicode() instance, but got int',) |
| 2951 | vim.eval(u"\0"):TypeError:('expected string without null bytes',) |
| 2952 | vim.eval("\0"):TypeError:('expected string without null bytes',) |
| 2953 | <<< Finished |
| 2954 | vim.eval("", FailingTrue()):TypeError:('function takes exactly 1 argument (2 given)',) |
| 2955 | > VimEvalPy |
| 2956 | >>> Testing StringToChars using vim.bindeval(%s) |
| 2957 | vim.bindeval(1):TypeError:('expected str() or unicode() instance, but got int',) |
| 2958 | vim.bindeval(u"\0"):TypeError:('expected string without null bytes',) |
| 2959 | vim.bindeval("\0"):TypeError:('expected string without null bytes',) |
| 2960 | <<< Finished |
| 2961 | vim.eval("", 2):TypeError:('function takes exactly 1 argument (2 given)',) |
| 2962 | > VimStrwidth |
| 2963 | >>> Testing StringToChars using vim.strwidth(%s) |
| 2964 | vim.strwidth(1):TypeError:('expected str() or unicode() instance, but got int',) |
| 2965 | vim.strwidth(u"\0"):TypeError:('expected string without null bytes',) |
| 2966 | vim.strwidth("\0"):TypeError:('expected string without null bytes',) |
| 2967 | <<< Finished |
| 2968 | > VimForeachRTP |
| 2969 | vim.foreach_rtp(None):TypeError:("'NoneType' object is not callable",) |
| 2970 | vim.foreach_rtp(NoArgsCall()):TypeError:('__call__() takes exactly 1 argument (2 given)',) |
| 2971 | vim.foreach_rtp(FailingCall()):NotImplementedError:('call',) |
| 2972 | vim.foreach_rtp(int, 2):TypeError:('foreach_rtp() takes exactly one argument (2 given)',) |
| 2973 | > import |
| 2974 | import xxx_no_such_module_xxx:ImportError:('No module named xxx_no_such_module_xxx',) |
| 2975 | import failing_import:ImportError:() |
| 2976 | import failing:NotImplementedError:() |
| 2977 | > Options |
| 2978 | >> OptionsItem |
| 2979 | vim.options["abcQ"]:KeyError:('abcQ',) |
| 2980 | vim.options[""]:ValueError:('empty keys are not allowed',) |
| 2981 | >>> Testing StringToChars using vim.options[%s] |
| 2982 | vim.options[1]:TypeError:('expected str() or unicode() instance, but got int',) |
| 2983 | vim.options[u"\0"]:TypeError:('expected string without null bytes',) |
| 2984 | vim.options["\0"]:TypeError:('expected string without null bytes',) |
| 2985 | <<< Finished |
| 2986 | >> OptionsContains |
| 2987 | >>> Testing StringToChars using %s in vim.options |
| 2988 | 1 in vim.options:TypeError:('expected str() or unicode() instance, but got int',) |
| 2989 | u"\0" in vim.options:TypeError:('expected string without null bytes',) |
| 2990 | "\0" in vim.options:TypeError:('expected string without null bytes',) |
| 2991 | <<< Finished |
| 2992 | > Dictionary |
| 2993 | >> DictionaryConstructor |
| 2994 | vim.Dictionary("abcI"):ValueError:('expected sequence element of size 2, but got sequence of size 1',) |
| 2995 | >> DictionarySetattr |
| 2996 | del d.locked:AttributeError:('cannot delete vim.Dictionary attributes',) |
| 2997 | d.locked = FailingTrue():NotImplementedError:('bool',) |
| 2998 | vim.vvars.locked = False:TypeError:('cannot modify fixed dictionary',) |
| 2999 | d.scope = True:AttributeError:('cannot set attribute scope',) |
| 3000 | d.xxx = True:AttributeError:('cannot set attribute xxx',) |
| 3001 | >> _DictionaryItem |
| 3002 | d.get("a", 2, 3):TypeError:('function takes at most 2 arguments (3 given)',) |
| 3003 | >>> Testing StringToChars using d.get(%s) |
| 3004 | d.get(1):TypeError:('expected str() or unicode() instance, but got int',) |
| 3005 | d.get(u"\0"):TypeError:('expected string without null bytes',) |
| 3006 | d.get("\0"):TypeError:('expected string without null bytes',) |
| 3007 | <<< Finished |
| 3008 | d.pop("a"):KeyError:('a',) |
| 3009 | dl.pop("a"):error:('dictionary is locked',) |
| 3010 | >> DictionaryContains |
| 3011 | "" in d:ValueError:('empty keys are not allowed',) |
| 3012 | 0 in d:TypeError:('expected str() or unicode() instance, but got int',) |
| 3013 | >> DictionaryIterNext |
| 3014 | for i in ned: ned["a"] = 1:RuntimeError:('hashtab changed during iteration',) |
| 3015 | >> DictionaryAssItem |
| 3016 | dl["b"] = 1:error:('dictionary is locked',) |
| 3017 | >>> Testing StringToChars using d[%s] = 1 |
| 3018 | d[1] = 1:TypeError:('expected str() or unicode() instance, but got int',) |
| 3019 | d[u"\0"] = 1:TypeError:('expected string without null bytes',) |
| 3020 | d["\0"] = 1:TypeError:('expected string without null bytes',) |
| 3021 | <<< Finished |
| 3022 | >>> Testing StringToChars using d["a"] = {%s : 1} |
| 3023 | d["a"] = {1 : 1}:TypeError:('expected str() or unicode() instance, but got int',) |
| 3024 | d["a"] = {u"\0" : 1}:TypeError:('expected string without null bytes',) |
| 3025 | d["a"] = {"\0" : 1}:TypeError:('expected string without null bytes',) |
| 3026 | <<< Finished |
| 3027 | >>> Testing StringToChars using d["a"] = {"abcF" : {%s : 1}} |
| 3028 | d["a"] = {"abcF" : {1 : 1}}:TypeError:('expected str() or unicode() instance, but got int',) |
| 3029 | d["a"] = {"abcF" : {u"\0" : 1}}:TypeError:('expected string without null bytes',) |
| 3030 | d["a"] = {"abcF" : {"\0" : 1}}:TypeError:('expected string without null bytes',) |
| 3031 | <<< Finished |
| 3032 | >>> Testing StringToChars using d["a"] = {"abcF" : Mapping({%s : 1})} |
| 3033 | d["a"] = {"abcF" : Mapping({1 : 1})}:TypeError:('expected str() or unicode() instance, but got int',) |
| 3034 | d["a"] = {"abcF" : Mapping({u"\0" : 1})}:TypeError:('expected string without null bytes',) |
| 3035 | d["a"] = {"abcF" : Mapping({"\0" : 1})}:TypeError:('expected string without null bytes',) |
| 3036 | <<< Finished |
| 3037 | >>> Testing *Iter* using d["a"] = {"abcF" : %s} |
| 3038 | d["a"] = {"abcF" : FailingIter()}:TypeError:('unable to convert FailingIter to a Vim structure',) |
| 3039 | d["a"] = {"abcF" : FailingIterNext()}:NotImplementedError:('next',) |
| 3040 | <<< Finished |
| 3041 | >>> Testing ConvertFromPyObject using d["a"] = {"abcF" : %s} |
| 3042 | d["a"] = {"abcF" : None}:NOT FAILED |
| 3043 | d["a"] = {"abcF" : {"": 1}}:ValueError:('empty keys are not allowed',) |
| 3044 | d["a"] = {"abcF" : {u"": 1}}:ValueError:('empty keys are not allowed',) |
| 3045 | d["a"] = {"abcF" : FailingMapping()}:NotImplementedError:('keys',) |
| 3046 | d["a"] = {"abcF" : FailingMappingKey()}:NotImplementedError:('getitem:mappingkey',) |
| 3047 | d["a"] = {"abcF" : FailingNumber()}:TypeError:('long() argument must be a string or a number',) |
| 3048 | <<< Finished |
| 3049 | >>> Testing StringToChars using d["a"] = Mapping({%s : 1}) |
| 3050 | d["a"] = Mapping({1 : 1}):TypeError:('expected str() or unicode() instance, but got int',) |
| 3051 | d["a"] = Mapping({u"\0" : 1}):TypeError:('expected string without null bytes',) |
| 3052 | d["a"] = Mapping({"\0" : 1}):TypeError:('expected string without null bytes',) |
| 3053 | <<< Finished |
| 3054 | >>> Testing StringToChars using d["a"] = Mapping({"abcG" : {%s : 1}}) |
| 3055 | d["a"] = Mapping({"abcG" : {1 : 1}}):TypeError:('expected str() or unicode() instance, but got int',) |
| 3056 | d["a"] = Mapping({"abcG" : {u"\0" : 1}}):TypeError:('expected string without null bytes',) |
| 3057 | d["a"] = Mapping({"abcG" : {"\0" : 1}}):TypeError:('expected string without null bytes',) |
| 3058 | <<< Finished |
| 3059 | >>> Testing StringToChars using d["a"] = Mapping({"abcG" : Mapping({%s : 1})}) |
| 3060 | d["a"] = Mapping({"abcG" : Mapping({1 : 1})}):TypeError:('expected str() or unicode() instance, but got int',) |
| 3061 | d["a"] = Mapping({"abcG" : Mapping({u"\0" : 1})}):TypeError:('expected string without null bytes',) |
| 3062 | d["a"] = Mapping({"abcG" : Mapping({"\0" : 1})}):TypeError:('expected string without null bytes',) |
| 3063 | <<< Finished |
| 3064 | >>> Testing *Iter* using d["a"] = Mapping({"abcG" : %s}) |
| 3065 | d["a"] = Mapping({"abcG" : FailingIter()}):TypeError:('unable to convert FailingIter to a Vim structure',) |
| 3066 | d["a"] = Mapping({"abcG" : FailingIterNext()}):NotImplementedError:('next',) |
| 3067 | <<< Finished |
| 3068 | >>> Testing ConvertFromPyObject using d["a"] = Mapping({"abcG" : %s}) |
| 3069 | d["a"] = Mapping({"abcG" : None}):NOT FAILED |
| 3070 | d["a"] = Mapping({"abcG" : {"": 1}}):ValueError:('empty keys are not allowed',) |
| 3071 | d["a"] = Mapping({"abcG" : {u"": 1}}):ValueError:('empty keys are not allowed',) |
| 3072 | d["a"] = Mapping({"abcG" : FailingMapping()}):NotImplementedError:('keys',) |
| 3073 | d["a"] = Mapping({"abcG" : FailingMappingKey()}):NotImplementedError:('getitem:mappingkey',) |
| 3074 | d["a"] = Mapping({"abcG" : FailingNumber()}):TypeError:('long() argument must be a string or a number',) |
| 3075 | <<< Finished |
| 3076 | >>> Testing *Iter* using d["a"] = %s |
| 3077 | d["a"] = FailingIter():TypeError:('unable to convert FailingIter to a Vim structure',) |
| 3078 | d["a"] = FailingIterNext():NotImplementedError:('next',) |
| 3079 | <<< Finished |
| 3080 | >>> Testing ConvertFromPyObject using d["a"] = %s |
| 3081 | d["a"] = None:NOT FAILED |
| 3082 | d["a"] = {"": 1}:ValueError:('empty keys are not allowed',) |
| 3083 | d["a"] = {u"": 1}:ValueError:('empty keys are not allowed',) |
| 3084 | d["a"] = FailingMapping():NotImplementedError:('keys',) |
| 3085 | d["a"] = FailingMappingKey():NotImplementedError:('getitem:mappingkey',) |
| 3086 | d["a"] = FailingNumber():TypeError:('long() argument must be a string or a number',) |
| 3087 | <<< Finished |
| 3088 | >> DictionaryUpdate |
| 3089 | >>> kwargs |
| 3090 | >>> iter |
| 3091 | d.update(FailingMapping()):NotImplementedError:('keys',) |
| 3092 | d.update([FailingIterNext()]):NotImplementedError:('next',) |
| 3093 | d.update([FailingIterNextN(1)]):NotImplementedError:('next N',) |
| 3094 | >>> Testing *Iter* using d.update(%s) |
| 3095 | d.update(FailingIter()):NotImplementedError:('iter',) |
| 3096 | d.update(FailingIterNext()):NotImplementedError:('next',) |
| 3097 | <<< Finished |
| 3098 | >>> Testing StringToChars using d.update({%s : 1}) |
| 3099 | d.update({1 : 1}):TypeError:('expected str() or unicode() instance, but got int',) |
| 3100 | d.update({u"\0" : 1}):TypeError:('expected string without null bytes',) |
| 3101 | d.update({"\0" : 1}):TypeError:('expected string without null bytes',) |
| 3102 | <<< Finished |
| 3103 | >>> Testing StringToChars using d.update({"abcF" : {%s : 1}}) |
| 3104 | d.update({"abcF" : {1 : 1}}):TypeError:('expected str() or unicode() instance, but got int',) |
| 3105 | d.update({"abcF" : {u"\0" : 1}}):TypeError:('expected string without null bytes',) |
| 3106 | d.update({"abcF" : {"\0" : 1}}):TypeError:('expected string without null bytes',) |
| 3107 | <<< Finished |
| 3108 | >>> Testing StringToChars using d.update({"abcF" : Mapping({%s : 1})}) |
| 3109 | d.update({"abcF" : Mapping({1 : 1})}):TypeError:('expected str() or unicode() instance, but got int',) |
| 3110 | d.update({"abcF" : Mapping({u"\0" : 1})}):TypeError:('expected string without null bytes',) |
| 3111 | d.update({"abcF" : Mapping({"\0" : 1})}):TypeError:('expected string without null bytes',) |
| 3112 | <<< Finished |
| 3113 | >>> Testing *Iter* using d.update({"abcF" : %s}) |
| 3114 | d.update({"abcF" : FailingIter()}):TypeError:('unable to convert FailingIter to a Vim structure',) |
| 3115 | d.update({"abcF" : FailingIterNext()}):NotImplementedError:('next',) |
| 3116 | <<< Finished |
| 3117 | >>> Testing ConvertFromPyObject using d.update({"abcF" : %s}) |
| 3118 | d.update({"abcF" : None}):NOT FAILED |
| 3119 | d.update({"abcF" : {"": 1}}):ValueError:('empty keys are not allowed',) |
| 3120 | d.update({"abcF" : {u"": 1}}):ValueError:('empty keys are not allowed',) |
| 3121 | d.update({"abcF" : FailingMapping()}):NotImplementedError:('keys',) |
| 3122 | d.update({"abcF" : FailingMappingKey()}):NotImplementedError:('getitem:mappingkey',) |
| 3123 | d.update({"abcF" : FailingNumber()}):TypeError:('long() argument must be a string or a number',) |
| 3124 | <<< Finished |
| 3125 | >>> Testing StringToChars using d.update(Mapping({%s : 1})) |
| 3126 | d.update(Mapping({1 : 1})):TypeError:('expected str() or unicode() instance, but got int',) |
| 3127 | d.update(Mapping({u"\0" : 1})):TypeError:('expected string without null bytes',) |
| 3128 | d.update(Mapping({"\0" : 1})):TypeError:('expected string without null bytes',) |
| 3129 | <<< Finished |
| 3130 | >>> Testing StringToChars using d.update(Mapping({"abcG" : {%s : 1}})) |
| 3131 | d.update(Mapping({"abcG" : {1 : 1}})):TypeError:('expected str() or unicode() instance, but got int',) |
| 3132 | d.update(Mapping({"abcG" : {u"\0" : 1}})):TypeError:('expected string without null bytes',) |
| 3133 | d.update(Mapping({"abcG" : {"\0" : 1}})):TypeError:('expected string without null bytes',) |
| 3134 | <<< Finished |
| 3135 | >>> Testing StringToChars using d.update(Mapping({"abcG" : Mapping({%s : 1})})) |
| 3136 | d.update(Mapping({"abcG" : Mapping({1 : 1})})):TypeError:('expected str() or unicode() instance, but got int',) |
| 3137 | d.update(Mapping({"abcG" : Mapping({u"\0" : 1})})):TypeError:('expected string without null bytes',) |
| 3138 | d.update(Mapping({"abcG" : Mapping({"\0" : 1})})):TypeError:('expected string without null bytes',) |
| 3139 | <<< Finished |
| 3140 | >>> Testing *Iter* using d.update(Mapping({"abcG" : %s})) |
| 3141 | d.update(Mapping({"abcG" : FailingIter()})):TypeError:('unable to convert FailingIter to a Vim structure',) |
| 3142 | d.update(Mapping({"abcG" : FailingIterNext()})):NotImplementedError:('next',) |
| 3143 | <<< Finished |
| 3144 | >>> Testing ConvertFromPyObject using d.update(Mapping({"abcG" : %s})) |
| 3145 | d.update(Mapping({"abcG" : None})):NOT FAILED |
| 3146 | d.update(Mapping({"abcG" : {"": 1}})):ValueError:('empty keys are not allowed',) |
| 3147 | d.update(Mapping({"abcG" : {u"": 1}})):ValueError:('empty keys are not allowed',) |
| 3148 | d.update(Mapping({"abcG" : FailingMapping()})):NotImplementedError:('keys',) |
| 3149 | d.update(Mapping({"abcG" : FailingMappingKey()})):NotImplementedError:('getitem:mappingkey',) |
| 3150 | d.update(Mapping({"abcG" : FailingNumber()})):TypeError:('long() argument must be a string or a number',) |
| 3151 | <<< Finished |
| 3152 | >>> Testing *Iter* using d.update(%s) |
| 3153 | d.update(FailingIter()):NotImplementedError:('iter',) |
| 3154 | d.update(FailingIterNext()):NotImplementedError:('next',) |
| 3155 | <<< Finished |
| 3156 | >>> Testing ConvertFromPyObject using d.update(%s) |
| 3157 | d.update(None):TypeError:("'NoneType' object is not iterable",) |
| 3158 | d.update({"": 1}):ValueError:('empty keys are not allowed',) |
| 3159 | d.update({u"": 1}):ValueError:('empty keys are not allowed',) |
| 3160 | d.update(FailingMapping()):NotImplementedError:('keys',) |
| 3161 | d.update(FailingMappingKey()):NotImplementedError:('getitem:mappingkey',) |
| 3162 | d.update(FailingNumber()):TypeError:("'FailingNumber' object is not iterable",) |
| 3163 | <<< Finished |
| 3164 | >>> Testing StringToChars using d.update(((%s, 0),)) |
| 3165 | d.update(((1, 0),)):TypeError:('expected str() or unicode() instance, but got int',) |
| 3166 | d.update(((u"\0", 0),)):TypeError:('expected string without null bytes',) |
| 3167 | d.update((("\0", 0),)):TypeError:('expected string without null bytes',) |
| 3168 | <<< Finished |
| 3169 | >>> Testing StringToChars using d.update((("a", {%s : 1}),)) |
| 3170 | d.update((("a", {1 : 1}),)):TypeError:('expected str() or unicode() instance, but got int',) |
| 3171 | d.update((("a", {u"\0" : 1}),)):TypeError:('expected string without null bytes',) |
| 3172 | d.update((("a", {"\0" : 1}),)):TypeError:('expected string without null bytes',) |
| 3173 | <<< Finished |
| 3174 | >>> Testing StringToChars using d.update((("a", {"abcF" : {%s : 1}}),)) |
| 3175 | d.update((("a", {"abcF" : {1 : 1}}),)):TypeError:('expected str() or unicode() instance, but got int',) |
| 3176 | d.update((("a", {"abcF" : {u"\0" : 1}}),)):TypeError:('expected string without null bytes',) |
| 3177 | d.update((("a", {"abcF" : {"\0" : 1}}),)):TypeError:('expected string without null bytes',) |
| 3178 | <<< Finished |
| 3179 | >>> Testing StringToChars using d.update((("a", {"abcF" : Mapping({%s : 1})}),)) |
| 3180 | d.update((("a", {"abcF" : Mapping({1 : 1})}),)):TypeError:('expected str() or unicode() instance, but got int',) |
| 3181 | d.update((("a", {"abcF" : Mapping({u"\0" : 1})}),)):TypeError:('expected string without null bytes',) |
| 3182 | d.update((("a", {"abcF" : Mapping({"\0" : 1})}),)):TypeError:('expected string without null bytes',) |
| 3183 | <<< Finished |
| 3184 | >>> Testing *Iter* using d.update((("a", {"abcF" : %s}),)) |
| 3185 | d.update((("a", {"abcF" : FailingIter()}),)):TypeError:('unable to convert FailingIter to a Vim structure',) |
| 3186 | d.update((("a", {"abcF" : FailingIterNext()}),)):NotImplementedError:('next',) |
| 3187 | <<< Finished |
| 3188 | >>> Testing ConvertFromPyObject using d.update((("a", {"abcF" : %s}),)) |
| 3189 | d.update((("a", {"abcF" : None}),)):error:("failed to add key 'a' to dictionary",) |
| 3190 | d.update((("a", {"abcF" : {"": 1}}),)):ValueError:('empty keys are not allowed',) |
| 3191 | d.update((("a", {"abcF" : {u"": 1}}),)):ValueError:('empty keys are not allowed',) |
| 3192 | d.update((("a", {"abcF" : FailingMapping()}),)):NotImplementedError:('keys',) |
| 3193 | d.update((("a", {"abcF" : FailingMappingKey()}),)):NotImplementedError:('getitem:mappingkey',) |
| 3194 | d.update((("a", {"abcF" : FailingNumber()}),)):TypeError:('long() argument must be a string or a number',) |
| 3195 | <<< Finished |
| 3196 | >>> Testing StringToChars using d.update((("a", Mapping({%s : 1})),)) |
| 3197 | d.update((("a", Mapping({1 : 1})),)):TypeError:('expected str() or unicode() instance, but got int',) |
| 3198 | d.update((("a", Mapping({u"\0" : 1})),)):TypeError:('expected string without null bytes',) |
| 3199 | d.update((("a", Mapping({"\0" : 1})),)):TypeError:('expected string without null bytes',) |
| 3200 | <<< Finished |
| 3201 | >>> Testing StringToChars using d.update((("a", Mapping({"abcG" : {%s : 1}})),)) |
| 3202 | d.update((("a", Mapping({"abcG" : {1 : 1}})),)):TypeError:('expected str() or unicode() instance, but got int',) |
| 3203 | d.update((("a", Mapping({"abcG" : {u"\0" : 1}})),)):TypeError:('expected string without null bytes',) |
| 3204 | d.update((("a", Mapping({"abcG" : {"\0" : 1}})),)):TypeError:('expected string without null bytes',) |
| 3205 | <<< Finished |
| 3206 | >>> Testing StringToChars using d.update((("a", Mapping({"abcG" : Mapping({%s : 1})})),)) |
| 3207 | d.update((("a", Mapping({"abcG" : Mapping({1 : 1})})),)):TypeError:('expected str() or unicode() instance, but got int',) |
| 3208 | d.update((("a", Mapping({"abcG" : Mapping({u"\0" : 1})})),)):TypeError:('expected string without null bytes',) |
| 3209 | d.update((("a", Mapping({"abcG" : Mapping({"\0" : 1})})),)):TypeError:('expected string without null bytes',) |
| 3210 | <<< Finished |
| 3211 | >>> Testing *Iter* using d.update((("a", Mapping({"abcG" : %s})),)) |
| 3212 | d.update((("a", Mapping({"abcG" : FailingIter()})),)):TypeError:('unable to convert FailingIter to a Vim structure',) |
| 3213 | d.update((("a", Mapping({"abcG" : FailingIterNext()})),)):NotImplementedError:('next',) |
| 3214 | <<< Finished |
| 3215 | >>> Testing ConvertFromPyObject using d.update((("a", Mapping({"abcG" : %s})),)) |
| 3216 | d.update((("a", Mapping({"abcG" : None})),)):error:("failed to add key 'a' to dictionary",) |
| 3217 | d.update((("a", Mapping({"abcG" : {"": 1}})),)):ValueError:('empty keys are not allowed',) |
| 3218 | d.update((("a", Mapping({"abcG" : {u"": 1}})),)):ValueError:('empty keys are not allowed',) |
| 3219 | d.update((("a", Mapping({"abcG" : FailingMapping()})),)):NotImplementedError:('keys',) |
| 3220 | d.update((("a", Mapping({"abcG" : FailingMappingKey()})),)):NotImplementedError:('getitem:mappingkey',) |
| 3221 | d.update((("a", Mapping({"abcG" : FailingNumber()})),)):TypeError:('long() argument must be a string or a number',) |
| 3222 | <<< Finished |
| 3223 | >>> Testing *Iter* using d.update((("a", %s),)) |
| 3224 | d.update((("a", FailingIter()),)):TypeError:('unable to convert FailingIter to a Vim structure',) |
| 3225 | d.update((("a", FailingIterNext()),)):NotImplementedError:('next',) |
| 3226 | <<< Finished |
| 3227 | >>> Testing ConvertFromPyObject using d.update((("a", %s),)) |
| 3228 | d.update((("a", None),)):error:("failed to add key 'a' to dictionary",) |
| 3229 | d.update((("a", {"": 1}),)):ValueError:('empty keys are not allowed',) |
| 3230 | d.update((("a", {u"": 1}),)):ValueError:('empty keys are not allowed',) |
| 3231 | d.update((("a", FailingMapping()),)):NotImplementedError:('keys',) |
| 3232 | d.update((("a", FailingMappingKey()),)):NotImplementedError:('getitem:mappingkey',) |
| 3233 | d.update((("a", FailingNumber()),)):TypeError:('long() argument must be a string or a number',) |
| 3234 | <<< Finished |
| 3235 | >> DictionaryPopItem |
| 3236 | d.popitem(1, 2):TypeError:('popitem() takes no arguments (2 given)',) |
| 3237 | >> DictionaryHasKey |
| 3238 | d.has_key():TypeError:('has_key() takes exactly one argument (0 given)',) |
| 3239 | > List |
| 3240 | >> ListConstructor |
| 3241 | vim.List(1, 2):TypeError:('function takes at most 1 argument (2 given)',) |
| 3242 | vim.List(a=1):TypeError:('list constructor does not accept keyword arguments',) |
| 3243 | >>> Testing *Iter* using vim.List(%s) |
| 3244 | vim.List(FailingIter()):NotImplementedError:('iter',) |
| 3245 | vim.List(FailingIterNext()):NotImplementedError:('next',) |
| 3246 | <<< Finished |
| 3247 | >>> Testing StringToChars using vim.List([{%s : 1}]) |
| 3248 | vim.List([{1 : 1}]):TypeError:('expected str() or unicode() instance, but got int',) |
| 3249 | vim.List([{u"\0" : 1}]):TypeError:('expected string without null bytes',) |
| 3250 | vim.List([{"\0" : 1}]):TypeError:('expected string without null bytes',) |
| 3251 | <<< Finished |
| 3252 | >>> Testing StringToChars using vim.List([{"abcF" : {%s : 1}}]) |
| 3253 | vim.List([{"abcF" : {1 : 1}}]):TypeError:('expected str() or unicode() instance, but got int',) |
| 3254 | vim.List([{"abcF" : {u"\0" : 1}}]):TypeError:('expected string without null bytes',) |
| 3255 | vim.List([{"abcF" : {"\0" : 1}}]):TypeError:('expected string without null bytes',) |
| 3256 | <<< Finished |
| 3257 | >>> Testing StringToChars using vim.List([{"abcF" : Mapping({%s : 1})}]) |
| 3258 | vim.List([{"abcF" : Mapping({1 : 1})}]):TypeError:('expected str() or unicode() instance, but got int',) |
| 3259 | vim.List([{"abcF" : Mapping({u"\0" : 1})}]):TypeError:('expected string without null bytes',) |
| 3260 | vim.List([{"abcF" : Mapping({"\0" : 1})}]):TypeError:('expected string without null bytes',) |
| 3261 | <<< Finished |
| 3262 | >>> Testing *Iter* using vim.List([{"abcF" : %s}]) |
| 3263 | vim.List([{"abcF" : FailingIter()}]):TypeError:('unable to convert FailingIter to a Vim structure',) |
| 3264 | vim.List([{"abcF" : FailingIterNext()}]):NotImplementedError:('next',) |
| 3265 | <<< Finished |
| 3266 | >>> Testing ConvertFromPyObject using vim.List([{"abcF" : %s}]) |
| 3267 | vim.List([{"abcF" : None}]):NOT FAILED |
| 3268 | vim.List([{"abcF" : {"": 1}}]):ValueError:('empty keys are not allowed',) |
| 3269 | vim.List([{"abcF" : {u"": 1}}]):ValueError:('empty keys are not allowed',) |
| 3270 | vim.List([{"abcF" : FailingMapping()}]):NotImplementedError:('keys',) |
| 3271 | vim.List([{"abcF" : FailingMappingKey()}]):NotImplementedError:('getitem:mappingkey',) |
| 3272 | vim.List([{"abcF" : FailingNumber()}]):TypeError:('long() argument must be a string or a number',) |
| 3273 | <<< Finished |
| 3274 | >>> Testing StringToChars using vim.List([Mapping({%s : 1})]) |
| 3275 | vim.List([Mapping({1 : 1})]):TypeError:('expected str() or unicode() instance, but got int',) |
| 3276 | vim.List([Mapping({u"\0" : 1})]):TypeError:('expected string without null bytes',) |
| 3277 | vim.List([Mapping({"\0" : 1})]):TypeError:('expected string without null bytes',) |
| 3278 | <<< Finished |
| 3279 | >>> Testing StringToChars using vim.List([Mapping({"abcG" : {%s : 1}})]) |
| 3280 | vim.List([Mapping({"abcG" : {1 : 1}})]):TypeError:('expected str() or unicode() instance, but got int',) |
| 3281 | vim.List([Mapping({"abcG" : {u"\0" : 1}})]):TypeError:('expected string without null bytes',) |
| 3282 | vim.List([Mapping({"abcG" : {"\0" : 1}})]):TypeError:('expected string without null bytes',) |
| 3283 | <<< Finished |
| 3284 | >>> Testing StringToChars using vim.List([Mapping({"abcG" : Mapping({%s : 1})})]) |
| 3285 | vim.List([Mapping({"abcG" : Mapping({1 : 1})})]):TypeError:('expected str() or unicode() instance, but got int',) |
| 3286 | vim.List([Mapping({"abcG" : Mapping({u"\0" : 1})})]):TypeError:('expected string without null bytes',) |
| 3287 | vim.List([Mapping({"abcG" : Mapping({"\0" : 1})})]):TypeError:('expected string without null bytes',) |
| 3288 | <<< Finished |
| 3289 | >>> Testing *Iter* using vim.List([Mapping({"abcG" : %s})]) |
| 3290 | vim.List([Mapping({"abcG" : FailingIter()})]):TypeError:('unable to convert FailingIter to a Vim structure',) |
| 3291 | vim.List([Mapping({"abcG" : FailingIterNext()})]):NotImplementedError:('next',) |
| 3292 | <<< Finished |
| 3293 | >>> Testing ConvertFromPyObject using vim.List([Mapping({"abcG" : %s})]) |
| 3294 | vim.List([Mapping({"abcG" : None})]):NOT FAILED |
| 3295 | vim.List([Mapping({"abcG" : {"": 1}})]):ValueError:('empty keys are not allowed',) |
| 3296 | vim.List([Mapping({"abcG" : {u"": 1}})]):ValueError:('empty keys are not allowed',) |
| 3297 | vim.List([Mapping({"abcG" : FailingMapping()})]):NotImplementedError:('keys',) |
| 3298 | vim.List([Mapping({"abcG" : FailingMappingKey()})]):NotImplementedError:('getitem:mappingkey',) |
| 3299 | vim.List([Mapping({"abcG" : FailingNumber()})]):TypeError:('long() argument must be a string or a number',) |
| 3300 | <<< Finished |
| 3301 | >>> Testing *Iter* using vim.List([%s]) |
| 3302 | vim.List([FailingIter()]):TypeError:('unable to convert FailingIter to a Vim structure',) |
| 3303 | vim.List([FailingIterNext()]):NotImplementedError:('next',) |
| 3304 | <<< Finished |
| 3305 | >>> Testing ConvertFromPyObject using vim.List([%s]) |
| 3306 | vim.List([None]):NOT FAILED |
| 3307 | vim.List([{"": 1}]):ValueError:('empty keys are not allowed',) |
| 3308 | vim.List([{u"": 1}]):ValueError:('empty keys are not allowed',) |
| 3309 | vim.List([FailingMapping()]):NotImplementedError:('keys',) |
| 3310 | vim.List([FailingMappingKey()]):NotImplementedError:('getitem:mappingkey',) |
| 3311 | vim.List([FailingNumber()]):TypeError:('long() argument must be a string or a number',) |
| 3312 | <<< Finished |
| 3313 | >> ListItem |
| 3314 | l[1000]:IndexError:('list index out of range',) |
| 3315 | >> ListAssItem |
| 3316 | ll[1] = 2:error:('list is locked',) |
| 3317 | l[1000] = 3:IndexError:('list index out of range',) |
| 3318 | >> ListAssSlice |
| 3319 | ll[1:100] = "abcJ":error:('list is locked',) |
| 3320 | >>> Testing *Iter* using l[:] = %s |
| 3321 | l[:] = FailingIter():NotImplementedError:('iter',) |
| 3322 | l[:] = FailingIterNext():NotImplementedError:('next',) |
| 3323 | <<< Finished |
| 3324 | nel[1:10:2] = "abcK":ValueError:('attempt to assign sequence of size greater than 2 to extended slice',) |
| 3325 | ('a', 'b', 'c', 'O') |
| 3326 | nel[1:10:2] = "a":ValueError:('attempt to assign sequence of size 1 to extended slice of size 2',) |
| 3327 | ('a', 'b', 'c', 'O') |
| 3328 | nel[1:1:-1] = "a":ValueError:('attempt to assign sequence of size greater than 0 to extended slice',) |
| 3329 | ('a', 'b', 'c', 'O') |
| 3330 | nel[:] = FailingIterNextN(2):NotImplementedError:('next N',) |
| 3331 | ('a', 'b', 'c', 'O') |
| 3332 | >>> Testing StringToChars using l[:] = [{%s : 1}] |
| 3333 | l[:] = [{1 : 1}]:TypeError:('expected str() or unicode() instance, but got int',) |
| 3334 | l[:] = [{u"\0" : 1}]:TypeError:('expected string without null bytes',) |
| 3335 | l[:] = [{"\0" : 1}]:TypeError:('expected string without null bytes',) |
| 3336 | <<< Finished |
| 3337 | >>> Testing StringToChars using l[:] = [{"abcF" : {%s : 1}}] |
| 3338 | l[:] = [{"abcF" : {1 : 1}}]:TypeError:('expected str() or unicode() instance, but got int',) |
| 3339 | l[:] = [{"abcF" : {u"\0" : 1}}]:TypeError:('expected string without null bytes',) |
| 3340 | l[:] = [{"abcF" : {"\0" : 1}}]:TypeError:('expected string without null bytes',) |
| 3341 | <<< Finished |
| 3342 | >>> Testing StringToChars using l[:] = [{"abcF" : Mapping({%s : 1})}] |
| 3343 | l[:] = [{"abcF" : Mapping({1 : 1})}]:TypeError:('expected str() or unicode() instance, but got int',) |
| 3344 | l[:] = [{"abcF" : Mapping({u"\0" : 1})}]:TypeError:('expected string without null bytes',) |
| 3345 | l[:] = [{"abcF" : Mapping({"\0" : 1})}]:TypeError:('expected string without null bytes',) |
| 3346 | <<< Finished |
| 3347 | >>> Testing *Iter* using l[:] = [{"abcF" : %s}] |
| 3348 | l[:] = [{"abcF" : FailingIter()}]:TypeError:('unable to convert FailingIter to a Vim structure',) |
| 3349 | l[:] = [{"abcF" : FailingIterNext()}]:NotImplementedError:('next',) |
| 3350 | <<< Finished |
| 3351 | >>> Testing ConvertFromPyObject using l[:] = [{"abcF" : %s}] |
| 3352 | l[:] = [{"abcF" : None}]:NOT FAILED |
| 3353 | l[:] = [{"abcF" : {"": 1}}]:ValueError:('empty keys are not allowed',) |
| 3354 | l[:] = [{"abcF" : {u"": 1}}]:ValueError:('empty keys are not allowed',) |
| 3355 | l[:] = [{"abcF" : FailingMapping()}]:NotImplementedError:('keys',) |
| 3356 | l[:] = [{"abcF" : FailingMappingKey()}]:NotImplementedError:('getitem:mappingkey',) |
| 3357 | l[:] = [{"abcF" : FailingNumber()}]:TypeError:('long() argument must be a string or a number',) |
| 3358 | <<< Finished |
| 3359 | >>> Testing StringToChars using l[:] = [Mapping({%s : 1})] |
| 3360 | l[:] = [Mapping({1 : 1})]:TypeError:('expected str() or unicode() instance, but got int',) |
| 3361 | l[:] = [Mapping({u"\0" : 1})]:TypeError:('expected string without null bytes',) |
| 3362 | l[:] = [Mapping({"\0" : 1})]:TypeError:('expected string without null bytes',) |
| 3363 | <<< Finished |
| 3364 | >>> Testing StringToChars using l[:] = [Mapping({"abcG" : {%s : 1}})] |
| 3365 | l[:] = [Mapping({"abcG" : {1 : 1}})]:TypeError:('expected str() or unicode() instance, but got int',) |
| 3366 | l[:] = [Mapping({"abcG" : {u"\0" : 1}})]:TypeError:('expected string without null bytes',) |
| 3367 | l[:] = [Mapping({"abcG" : {"\0" : 1}})]:TypeError:('expected string without null bytes',) |
| 3368 | <<< Finished |
| 3369 | >>> Testing StringToChars using l[:] = [Mapping({"abcG" : Mapping({%s : 1})})] |
| 3370 | l[:] = [Mapping({"abcG" : Mapping({1 : 1})})]:TypeError:('expected str() or unicode() instance, but got int',) |
| 3371 | l[:] = [Mapping({"abcG" : Mapping({u"\0" : 1})})]:TypeError:('expected string without null bytes',) |
| 3372 | l[:] = [Mapping({"abcG" : Mapping({"\0" : 1})})]:TypeError:('expected string without null bytes',) |
| 3373 | <<< Finished |
| 3374 | >>> Testing *Iter* using l[:] = [Mapping({"abcG" : %s})] |
| 3375 | l[:] = [Mapping({"abcG" : FailingIter()})]:TypeError:('unable to convert FailingIter to a Vim structure',) |
| 3376 | l[:] = [Mapping({"abcG" : FailingIterNext()})]:NotImplementedError:('next',) |
| 3377 | <<< Finished |
| 3378 | >>> Testing ConvertFromPyObject using l[:] = [Mapping({"abcG" : %s})] |
| 3379 | l[:] = [Mapping({"abcG" : None})]:NOT FAILED |
| 3380 | l[:] = [Mapping({"abcG" : {"": 1}})]:ValueError:('empty keys are not allowed',) |
| 3381 | l[:] = [Mapping({"abcG" : {u"": 1}})]:ValueError:('empty keys are not allowed',) |
| 3382 | l[:] = [Mapping({"abcG" : FailingMapping()})]:NotImplementedError:('keys',) |
| 3383 | l[:] = [Mapping({"abcG" : FailingMappingKey()})]:NotImplementedError:('getitem:mappingkey',) |
| 3384 | l[:] = [Mapping({"abcG" : FailingNumber()})]:TypeError:('long() argument must be a string or a number',) |
| 3385 | <<< Finished |
| 3386 | >>> Testing *Iter* using l[:] = [%s] |
| 3387 | l[:] = [FailingIter()]:TypeError:('unable to convert FailingIter to a Vim structure',) |
| 3388 | l[:] = [FailingIterNext()]:NotImplementedError:('next',) |
| 3389 | <<< Finished |
| 3390 | >>> Testing ConvertFromPyObject using l[:] = [%s] |
| 3391 | l[:] = [None]:NOT FAILED |
| 3392 | l[:] = [{"": 1}]:ValueError:('empty keys are not allowed',) |
| 3393 | l[:] = [{u"": 1}]:ValueError:('empty keys are not allowed',) |
| 3394 | l[:] = [FailingMapping()]:NotImplementedError:('keys',) |
| 3395 | l[:] = [FailingMappingKey()]:NotImplementedError:('getitem:mappingkey',) |
| 3396 | l[:] = [FailingNumber()]:TypeError:('long() argument must be a string or a number',) |
| 3397 | <<< Finished |
| 3398 | >> ListConcatInPlace |
| 3399 | >>> Testing *Iter* using l.extend(%s) |
| 3400 | l.extend(FailingIter()):NotImplementedError:('iter',) |
| 3401 | l.extend(FailingIterNext()):NotImplementedError:('next',) |
| 3402 | <<< Finished |
| 3403 | >>> Testing StringToChars using l.extend([{%s : 1}]) |
| 3404 | l.extend([{1 : 1}]):TypeError:('expected str() or unicode() instance, but got int',) |
| 3405 | l.extend([{u"\0" : 1}]):TypeError:('expected string without null bytes',) |
| 3406 | l.extend([{"\0" : 1}]):TypeError:('expected string without null bytes',) |
| 3407 | <<< Finished |
| 3408 | >>> Testing StringToChars using l.extend([{"abcF" : {%s : 1}}]) |
| 3409 | l.extend([{"abcF" : {1 : 1}}]):TypeError:('expected str() or unicode() instance, but got int',) |
| 3410 | l.extend([{"abcF" : {u"\0" : 1}}]):TypeError:('expected string without null bytes',) |
| 3411 | l.extend([{"abcF" : {"\0" : 1}}]):TypeError:('expected string without null bytes',) |
| 3412 | <<< Finished |
| 3413 | >>> Testing StringToChars using l.extend([{"abcF" : Mapping({%s : 1})}]) |
| 3414 | l.extend([{"abcF" : Mapping({1 : 1})}]):TypeError:('expected str() or unicode() instance, but got int',) |
| 3415 | l.extend([{"abcF" : Mapping({u"\0" : 1})}]):TypeError:('expected string without null bytes',) |
| 3416 | l.extend([{"abcF" : Mapping({"\0" : 1})}]):TypeError:('expected string without null bytes',) |
| 3417 | <<< Finished |
| 3418 | >>> Testing *Iter* using l.extend([{"abcF" : %s}]) |
| 3419 | l.extend([{"abcF" : FailingIter()}]):TypeError:('unable to convert FailingIter to a Vim structure',) |
| 3420 | l.extend([{"abcF" : FailingIterNext()}]):NotImplementedError:('next',) |
| 3421 | <<< Finished |
| 3422 | >>> Testing ConvertFromPyObject using l.extend([{"abcF" : %s}]) |
| 3423 | l.extend([{"abcF" : None}]):NOT FAILED |
| 3424 | l.extend([{"abcF" : {"": 1}}]):ValueError:('empty keys are not allowed',) |
| 3425 | l.extend([{"abcF" : {u"": 1}}]):ValueError:('empty keys are not allowed',) |
| 3426 | l.extend([{"abcF" : FailingMapping()}]):NotImplementedError:('keys',) |
| 3427 | l.extend([{"abcF" : FailingMappingKey()}]):NotImplementedError:('getitem:mappingkey',) |
| 3428 | l.extend([{"abcF" : FailingNumber()}]):TypeError:('long() argument must be a string or a number',) |
| 3429 | <<< Finished |
| 3430 | >>> Testing StringToChars using l.extend([Mapping({%s : 1})]) |
| 3431 | l.extend([Mapping({1 : 1})]):TypeError:('expected str() or unicode() instance, but got int',) |
| 3432 | l.extend([Mapping({u"\0" : 1})]):TypeError:('expected string without null bytes',) |
| 3433 | l.extend([Mapping({"\0" : 1})]):TypeError:('expected string without null bytes',) |
| 3434 | <<< Finished |
| 3435 | >>> Testing StringToChars using l.extend([Mapping({"abcG" : {%s : 1}})]) |
| 3436 | l.extend([Mapping({"abcG" : {1 : 1}})]):TypeError:('expected str() or unicode() instance, but got int',) |
| 3437 | l.extend([Mapping({"abcG" : {u"\0" : 1}})]):TypeError:('expected string without null bytes',) |
| 3438 | l.extend([Mapping({"abcG" : {"\0" : 1}})]):TypeError:('expected string without null bytes',) |
| 3439 | <<< Finished |
| 3440 | >>> Testing StringToChars using l.extend([Mapping({"abcG" : Mapping({%s : 1})})]) |
| 3441 | l.extend([Mapping({"abcG" : Mapping({1 : 1})})]):TypeError:('expected str() or unicode() instance, but got int',) |
| 3442 | l.extend([Mapping({"abcG" : Mapping({u"\0" : 1})})]):TypeError:('expected string without null bytes',) |
| 3443 | l.extend([Mapping({"abcG" : Mapping({"\0" : 1})})]):TypeError:('expected string without null bytes',) |
| 3444 | <<< Finished |
| 3445 | >>> Testing *Iter* using l.extend([Mapping({"abcG" : %s})]) |
| 3446 | l.extend([Mapping({"abcG" : FailingIter()})]):TypeError:('unable to convert FailingIter to a Vim structure',) |
| 3447 | l.extend([Mapping({"abcG" : FailingIterNext()})]):NotImplementedError:('next',) |
| 3448 | <<< Finished |
| 3449 | >>> Testing ConvertFromPyObject using l.extend([Mapping({"abcG" : %s})]) |
| 3450 | l.extend([Mapping({"abcG" : None})]):NOT FAILED |
| 3451 | l.extend([Mapping({"abcG" : {"": 1}})]):ValueError:('empty keys are not allowed',) |
| 3452 | l.extend([Mapping({"abcG" : {u"": 1}})]):ValueError:('empty keys are not allowed',) |
| 3453 | l.extend([Mapping({"abcG" : FailingMapping()})]):NotImplementedError:('keys',) |
| 3454 | l.extend([Mapping({"abcG" : FailingMappingKey()})]):NotImplementedError:('getitem:mappingkey',) |
| 3455 | l.extend([Mapping({"abcG" : FailingNumber()})]):TypeError:('long() argument must be a string or a number',) |
| 3456 | <<< Finished |
| 3457 | >>> Testing *Iter* using l.extend([%s]) |
| 3458 | l.extend([FailingIter()]):TypeError:('unable to convert FailingIter to a Vim structure',) |
| 3459 | l.extend([FailingIterNext()]):NotImplementedError:('next',) |
| 3460 | <<< Finished |
| 3461 | >>> Testing ConvertFromPyObject using l.extend([%s]) |
| 3462 | l.extend([None]):NOT FAILED |
| 3463 | l.extend([{"": 1}]):ValueError:('empty keys are not allowed',) |
| 3464 | l.extend([{u"": 1}]):ValueError:('empty keys are not allowed',) |
| 3465 | l.extend([FailingMapping()]):NotImplementedError:('keys',) |
| 3466 | l.extend([FailingMappingKey()]):NotImplementedError:('getitem:mappingkey',) |
| 3467 | l.extend([FailingNumber()]):TypeError:('long() argument must be a string or a number',) |
| 3468 | <<< Finished |
| 3469 | >> ListSetattr |
| 3470 | del l.locked:AttributeError:('cannot delete vim.List attributes',) |
| 3471 | l.locked = FailingTrue():NotImplementedError:('bool',) |
| 3472 | l.xxx = True:AttributeError:('cannot set attribute xxx',) |
| 3473 | > Function |
| 3474 | >> FunctionConstructor |
| 3475 | >>> FunctionConstructor |
| 3476 | vim.Function("123"):ValueError:('unnamed function 123 does not exist',) |
| 3477 | vim.Function("xxx_non_existent_function_xxx"):ValueError:('function xxx_non_existent_function_xxx does not exist',) |
| 3478 | vim.Function("xxx#non#existent#function#xxx"):NOT FAILED |
| 3479 | vim.Function("xxx_non_existent_function_xxx2", args=[]):ValueError:('function xxx_non_existent_function_xxx2 does not exist',) |
| 3480 | vim.Function("xxx_non_existent_function_xxx3", self={}):ValueError:('function xxx_non_existent_function_xxx3 does not exist',) |
| 3481 | vim.Function("xxx_non_existent_function_xxx4", args=[], self={}):ValueError:('function xxx_non_existent_function_xxx4 does not exist',) |
| 3482 | >>> FunctionNew |
| 3483 | vim.Function("tr", self="abcFuncSelf"):TypeError:('unable to convert str to a Vim dictionary',) |
| 3484 | vim.Function("tr", args=427423):TypeError:('unable to convert int to a Vim list',) |
| 3485 | vim.Function("tr", self="abcFuncSelf2", args="abcFuncArgs2"):TypeError:('unable to convert str to a Vim dictionary',) |
| 3486 | vim.Function(self="abcFuncSelf2", args="abcFuncArgs2"):TypeError:('unable to convert str to a Vim dictionary',) |
| 3487 | vim.Function("tr", "", self="abcFuncSelf2", args="abcFuncArgs2"):TypeError:('unable to convert str to a Vim dictionary',) |
| 3488 | vim.Function("tr", ""):TypeError:('function takes exactly 1 argument (2 given)',) |
| 3489 | >> FunctionCall |
| 3490 | >>> Testing StringToChars using f({%s : 1}) |
| 3491 | f({1 : 1}):TypeError:('expected str() or unicode() instance, but got int',) |
| 3492 | f({u"\0" : 1}):TypeError:('expected string without null bytes',) |
| 3493 | f({"\0" : 1}):TypeError:('expected string without null bytes',) |
| 3494 | <<< Finished |
| 3495 | >>> Testing StringToChars using f({"abcF" : {%s : 1}}) |
| 3496 | f({"abcF" : {1 : 1}}):TypeError:('expected str() or unicode() instance, but got int',) |
| 3497 | f({"abcF" : {u"\0" : 1}}):TypeError:('expected string without null bytes',) |
| 3498 | f({"abcF" : {"\0" : 1}}):TypeError:('expected string without null bytes',) |
| 3499 | <<< Finished |
| 3500 | >>> Testing StringToChars using f({"abcF" : Mapping({%s : 1})}) |
| 3501 | f({"abcF" : Mapping({1 : 1})}):TypeError:('expected str() or unicode() instance, but got int',) |
| 3502 | f({"abcF" : Mapping({u"\0" : 1})}):TypeError:('expected string without null bytes',) |
| 3503 | f({"abcF" : Mapping({"\0" : 1})}):TypeError:('expected string without null bytes',) |
| 3504 | <<< Finished |
| 3505 | >>> Testing *Iter* using f({"abcF" : %s}) |
| 3506 | f({"abcF" : FailingIter()}):TypeError:('unable to convert FailingIter to a Vim structure',) |
| 3507 | f({"abcF" : FailingIterNext()}):NotImplementedError:('next',) |
| 3508 | <<< Finished |
| 3509 | >>> Testing ConvertFromPyObject using f({"abcF" : %s}) |
| 3510 | f({"abcF" : None}):NOT FAILED |
| 3511 | f({"abcF" : {"": 1}}):ValueError:('empty keys are not allowed',) |
| 3512 | f({"abcF" : {u"": 1}}):ValueError:('empty keys are not allowed',) |
| 3513 | f({"abcF" : FailingMapping()}):NotImplementedError:('keys',) |
| 3514 | f({"abcF" : FailingMappingKey()}):NotImplementedError:('getitem:mappingkey',) |
| 3515 | f({"abcF" : FailingNumber()}):TypeError:('long() argument must be a string or a number',) |
| 3516 | <<< Finished |
| 3517 | >>> Testing StringToChars using f(Mapping({%s : 1})) |
| 3518 | f(Mapping({1 : 1})):TypeError:('expected str() or unicode() instance, but got int',) |
| 3519 | f(Mapping({u"\0" : 1})):TypeError:('expected string without null bytes',) |
| 3520 | f(Mapping({"\0" : 1})):TypeError:('expected string without null bytes',) |
| 3521 | <<< Finished |
| 3522 | >>> Testing StringToChars using f(Mapping({"abcG" : {%s : 1}})) |
| 3523 | f(Mapping({"abcG" : {1 : 1}})):TypeError:('expected str() or unicode() instance, but got int',) |
| 3524 | f(Mapping({"abcG" : {u"\0" : 1}})):TypeError:('expected string without null bytes',) |
| 3525 | f(Mapping({"abcG" : {"\0" : 1}})):TypeError:('expected string without null bytes',) |
| 3526 | <<< Finished |
| 3527 | >>> Testing StringToChars using f(Mapping({"abcG" : Mapping({%s : 1})})) |
| 3528 | f(Mapping({"abcG" : Mapping({1 : 1})})):TypeError:('expected str() or unicode() instance, but got int',) |
| 3529 | f(Mapping({"abcG" : Mapping({u"\0" : 1})})):TypeError:('expected string without null bytes',) |
| 3530 | f(Mapping({"abcG" : Mapping({"\0" : 1})})):TypeError:('expected string without null bytes',) |
| 3531 | <<< Finished |
| 3532 | >>> Testing *Iter* using f(Mapping({"abcG" : %s})) |
| 3533 | f(Mapping({"abcG" : FailingIter()})):TypeError:('unable to convert FailingIter to a Vim structure',) |
| 3534 | f(Mapping({"abcG" : FailingIterNext()})):NotImplementedError:('next',) |
| 3535 | <<< Finished |
| 3536 | >>> Testing ConvertFromPyObject using f(Mapping({"abcG" : %s})) |
| 3537 | f(Mapping({"abcG" : None})):NOT FAILED |
| 3538 | f(Mapping({"abcG" : {"": 1}})):ValueError:('empty keys are not allowed',) |
| 3539 | f(Mapping({"abcG" : {u"": 1}})):ValueError:('empty keys are not allowed',) |
| 3540 | f(Mapping({"abcG" : FailingMapping()})):NotImplementedError:('keys',) |
| 3541 | f(Mapping({"abcG" : FailingMappingKey()})):NotImplementedError:('getitem:mappingkey',) |
| 3542 | f(Mapping({"abcG" : FailingNumber()})):TypeError:('long() argument must be a string or a number',) |
| 3543 | <<< Finished |
| 3544 | >>> Testing *Iter* using f(%s) |
| 3545 | f(FailingIter()):TypeError:('unable to convert FailingIter to a Vim structure',) |
| 3546 | f(FailingIterNext()):NotImplementedError:('next',) |
| 3547 | <<< Finished |
| 3548 | >>> Testing ConvertFromPyObject using f(%s) |
| 3549 | f(None):NOT FAILED |
| 3550 | f({"": 1}):ValueError:('empty keys are not allowed',) |
| 3551 | f({u"": 1}):ValueError:('empty keys are not allowed',) |
| 3552 | f(FailingMapping()):NotImplementedError:('keys',) |
| 3553 | f(FailingMappingKey()):NotImplementedError:('getitem:mappingkey',) |
| 3554 | f(FailingNumber()):TypeError:('long() argument must be a string or a number',) |
| 3555 | <<< Finished |
| 3556 | >>> Testing StringToChars using fd(self={%s : 1}) |
| 3557 | fd(self={1 : 1}):TypeError:('expected str() or unicode() instance, but got int',) |
| 3558 | fd(self={u"\0" : 1}):TypeError:('expected string without null bytes',) |
| 3559 | fd(self={"\0" : 1}):TypeError:('expected string without null bytes',) |
| 3560 | <<< Finished |
| 3561 | >>> Testing StringToChars using fd(self={"abcF" : {%s : 1}}) |
| 3562 | fd(self={"abcF" : {1 : 1}}):TypeError:('expected str() or unicode() instance, but got int',) |
| 3563 | fd(self={"abcF" : {u"\0" : 1}}):TypeError:('expected string without null bytes',) |
| 3564 | fd(self={"abcF" : {"\0" : 1}}):TypeError:('expected string without null bytes',) |
| 3565 | <<< Finished |
| 3566 | >>> Testing StringToChars using fd(self={"abcF" : Mapping({%s : 1})}) |
| 3567 | fd(self={"abcF" : Mapping({1 : 1})}):TypeError:('expected str() or unicode() instance, but got int',) |
| 3568 | fd(self={"abcF" : Mapping({u"\0" : 1})}):TypeError:('expected string without null bytes',) |
| 3569 | fd(self={"abcF" : Mapping({"\0" : 1})}):TypeError:('expected string without null bytes',) |
| 3570 | <<< Finished |
| 3571 | >>> Testing *Iter* using fd(self={"abcF" : %s}) |
| 3572 | fd(self={"abcF" : FailingIter()}):TypeError:('unable to convert FailingIter to a Vim structure',) |
| 3573 | fd(self={"abcF" : FailingIterNext()}):NotImplementedError:('next',) |
| 3574 | <<< Finished |
| 3575 | >>> Testing ConvertFromPyObject using fd(self={"abcF" : %s}) |
| 3576 | fd(self={"abcF" : None}):NOT FAILED |
| 3577 | fd(self={"abcF" : {"": 1}}):ValueError:('empty keys are not allowed',) |
| 3578 | fd(self={"abcF" : {u"": 1}}):ValueError:('empty keys are not allowed',) |
| 3579 | fd(self={"abcF" : FailingMapping()}):NotImplementedError:('keys',) |
| 3580 | fd(self={"abcF" : FailingMappingKey()}):NotImplementedError:('getitem:mappingkey',) |
| 3581 | fd(self={"abcF" : FailingNumber()}):TypeError:('long() argument must be a string or a number',) |
| 3582 | <<< Finished |
| 3583 | >>> Testing StringToChars using fd(self=Mapping({%s : 1})) |
| 3584 | fd(self=Mapping({1 : 1})):TypeError:('expected str() or unicode() instance, but got int',) |
| 3585 | fd(self=Mapping({u"\0" : 1})):TypeError:('expected string without null bytes',) |
| 3586 | fd(self=Mapping({"\0" : 1})):TypeError:('expected string without null bytes',) |
| 3587 | <<< Finished |
| 3588 | >>> Testing StringToChars using fd(self=Mapping({"abcG" : {%s : 1}})) |
| 3589 | fd(self=Mapping({"abcG" : {1 : 1}})):TypeError:('expected str() or unicode() instance, but got int',) |
| 3590 | fd(self=Mapping({"abcG" : {u"\0" : 1}})):TypeError:('expected string without null bytes',) |
| 3591 | fd(self=Mapping({"abcG" : {"\0" : 1}})):TypeError:('expected string without null bytes',) |
| 3592 | <<< Finished |
| 3593 | >>> Testing StringToChars using fd(self=Mapping({"abcG" : Mapping({%s : 1})})) |
| 3594 | fd(self=Mapping({"abcG" : Mapping({1 : 1})})):TypeError:('expected str() or unicode() instance, but got int',) |
| 3595 | fd(self=Mapping({"abcG" : Mapping({u"\0" : 1})})):TypeError:('expected string without null bytes',) |
| 3596 | fd(self=Mapping({"abcG" : Mapping({"\0" : 1})})):TypeError:('expected string without null bytes',) |
| 3597 | <<< Finished |
| 3598 | >>> Testing *Iter* using fd(self=Mapping({"abcG" : %s})) |
| 3599 | fd(self=Mapping({"abcG" : FailingIter()})):TypeError:('unable to convert FailingIter to a Vim structure',) |
| 3600 | fd(self=Mapping({"abcG" : FailingIterNext()})):NotImplementedError:('next',) |
| 3601 | <<< Finished |
| 3602 | >>> Testing ConvertFromPyObject using fd(self=Mapping({"abcG" : %s})) |
| 3603 | fd(self=Mapping({"abcG" : None})):NOT FAILED |
| 3604 | fd(self=Mapping({"abcG" : {"": 1}})):ValueError:('empty keys are not allowed',) |
| 3605 | fd(self=Mapping({"abcG" : {u"": 1}})):ValueError:('empty keys are not allowed',) |
| 3606 | fd(self=Mapping({"abcG" : FailingMapping()})):NotImplementedError:('keys',) |
| 3607 | fd(self=Mapping({"abcG" : FailingMappingKey()})):NotImplementedError:('getitem:mappingkey',) |
| 3608 | fd(self=Mapping({"abcG" : FailingNumber()})):TypeError:('long() argument must be a string or a number',) |
| 3609 | <<< Finished |
| 3610 | >>> Testing *Iter* using fd(self=%s) |
| 3611 | fd(self=FailingIter()):TypeError:('unable to convert FailingIter to a Vim dictionary',) |
| 3612 | fd(self=FailingIterNext()):TypeError:('unable to convert FailingIterNext to a Vim dictionary',) |
| 3613 | <<< Finished |
| 3614 | >>> Testing ConvertFromPyObject using fd(self=%s) |
| 3615 | fd(self=None):TypeError:('unable to convert NoneType to a Vim dictionary',) |
| 3616 | fd(self={"": 1}):ValueError:('empty keys are not allowed',) |
| 3617 | fd(self={u"": 1}):ValueError:('empty keys are not allowed',) |
| 3618 | fd(self=FailingMapping()):NotImplementedError:('keys',) |
| 3619 | fd(self=FailingMappingKey()):NotImplementedError:('getitem:mappingkey',) |
| 3620 | fd(self=FailingNumber()):TypeError:('unable to convert FailingNumber to a Vim dictionary',) |
| 3621 | <<< Finished |
| 3622 | >>> Testing ConvertFromPyMapping using fd(self=%s) |
| 3623 | fd(self=[]):TypeError:('unable to convert list to a Vim dictionary',) |
| 3624 | <<< Finished |
| 3625 | > TabPage |
| 3626 | >> TabPageAttr |
| 3627 | vim.current.tabpage.xxx:AttributeError:('xxx',) |
| 3628 | > TabList |
| 3629 | >> TabListItem |
| 3630 | vim.tabpages[1000]:IndexError:('no such tab page',) |
| 3631 | > Window |
| 3632 | >> WindowAttr |
| 3633 | vim.current.window.xxx:AttributeError:('xxx',) |
| 3634 | >> WindowSetattr |
| 3635 | vim.current.window.buffer = 0:TypeError:('readonly attribute: buffer',) |
| 3636 | vim.current.window.cursor = (100000000, 100000000):error:('cursor position outside buffer',) |
| 3637 | vim.current.window.cursor = True:TypeError:('argument must be 2-item sequence, not bool',) |
| 3638 | >>> Testing NumberToLong using vim.current.window.height = %s |
| 3639 | vim.current.window.height = []:TypeError:('expected int(), long() or something supporting coercing to long(), but got list',) |
| 3640 | vim.current.window.height = None:TypeError:('expected int(), long() or something supporting coercing to long(), but got NoneType',) |
| 3641 | vim.current.window.height = -1:ValueError:('number must be greater or equal to zero',) |
| 3642 | <<< Finished |
| 3643 | >>> Testing NumberToLong using vim.current.window.width = %s |
| 3644 | vim.current.window.width = []:TypeError:('expected int(), long() or something supporting coercing to long(), but got list',) |
| 3645 | vim.current.window.width = None:TypeError:('expected int(), long() or something supporting coercing to long(), but got NoneType',) |
| 3646 | vim.current.window.width = -1:ValueError:('number must be greater or equal to zero',) |
| 3647 | <<< Finished |
| 3648 | vim.current.window.xxxxxx = True:AttributeError:('xxxxxx',) |
| 3649 | > WinList |
| 3650 | >> WinListItem |
| 3651 | vim.windows[1000]:IndexError:('no such window',) |
| 3652 | > Buffer |
| 3653 | >> StringToLine (indirect) |
Bram Moolenaar | 92fdd1e | 2020-07-03 18:00:05 +0200 | [diff] [blame] | 3654 | vim.current.buffer[0] = "\na":error:('string cannot contain newlines',) |
Bram Moolenaar | ab58946 | 2020-07-06 21:03:06 +0200 | [diff] [blame] | 3655 | vim.current.buffer[0] = u"\na":error:('string cannot contain newlines',) |
Bram Moolenaar | 92fdd1e | 2020-07-03 18:00:05 +0200 | [diff] [blame] | 3656 | >> SetBufferLine (indirect) |
| 3657 | vim.current.buffer[0] = True:TypeError:('bad argument type for built-in operation',) |
| 3658 | >> SetBufferLineList (indirect) |
| 3659 | vim.current.buffer[:] = True:TypeError:('bad argument type for built-in operation',) |
| 3660 | vim.current.buffer[:] = ["\na", "bc"]:error:('string cannot contain newlines',) |
| 3661 | >> InsertBufferLines (indirect) |
| 3662 | vim.current.buffer.append(None):TypeError:('bad argument type for built-in operation',) |
| 3663 | vim.current.buffer.append(["\na", "bc"]):error:('string cannot contain newlines',) |
| 3664 | vim.current.buffer.append("\nbc"):error:('string cannot contain newlines',) |
| 3665 | >> RBItem |
| 3666 | vim.current.buffer[100000000]:IndexError:('line number out of range',) |
| 3667 | >> RBAsItem |
| 3668 | vim.current.buffer[100000000] = "":IndexError:('line number out of range',) |
| 3669 | >> BufferAttr |
| 3670 | vim.current.buffer.xxx:AttributeError:('xxx',) |
| 3671 | >> BufferSetattr |
| 3672 | vim.current.buffer.name = True:TypeError:('expected str() or unicode() instance, but got bool',) |
| 3673 | vim.current.buffer.xxx = True:AttributeError:('xxx',) |
| 3674 | >> BufferMark |
| 3675 | vim.current.buffer.mark(0):TypeError:('expected str() or unicode() instance, but got int',) |
| 3676 | vim.current.buffer.mark("abcM"):ValueError:('mark name must be a single character',) |
| 3677 | vim.current.buffer.mark("!"):error:('invalid mark name',) |
| 3678 | >> BufferRange |
| 3679 | vim.current.buffer.range(1, 2, 3):TypeError:('function takes exactly 2 arguments (3 given)',) |
| 3680 | > BufMap |
| 3681 | >> BufMapItem |
| 3682 | vim.buffers[100000000]:KeyError:(100000000,) |
| 3683 | >>> Testing NumberToLong using vim.buffers[%s] |
| 3684 | vim.buffers[[]]:TypeError:('expected int(), long() or something supporting coercing to long(), but got list',) |
| 3685 | vim.buffers[None]:TypeError:('expected int(), long() or something supporting coercing to long(), but got NoneType',) |
| 3686 | vim.buffers[-1]:ValueError:('number must be greater than zero',) |
| 3687 | vim.buffers[0]:ValueError:('number must be greater than zero',) |
| 3688 | <<< Finished |
| 3689 | > Current |
| 3690 | >> CurrentGetattr |
| 3691 | vim.current.xxx:AttributeError:('xxx',) |
| 3692 | >> CurrentSetattr |
| 3693 | vim.current.line = True:TypeError:('bad argument type for built-in operation',) |
| 3694 | vim.current.buffer = True:TypeError:('expected vim.Buffer object, but got bool',) |
| 3695 | vim.current.window = True:TypeError:('expected vim.Window object, but got bool',) |
| 3696 | vim.current.tabpage = True:TypeError:('expected vim.TabPage object, but got bool',) |
| 3697 | vim.current.xxx = True:AttributeError:('xxx',) |
| 3698 | END |
| 3699 | |
| 3700 | call assert_equal(expected, getline(2, '$')) |
| 3701 | close! |
| 3702 | endfunc |
| 3703 | |
| 3704 | " Test import |
| 3705 | func Test_python_import() |
| 3706 | new |
| 3707 | py cb = vim.current.buffer |
| 3708 | |
| 3709 | py << trim EOF |
| 3710 | sys.path.insert(0, os.path.join(os.getcwd(), 'python_before')) |
| 3711 | sys.path.append(os.path.join(os.getcwd(), 'python_after')) |
| 3712 | vim.options['rtp'] = os.getcwd().replace(',', '\\,').replace('\\', '\\\\') |
| 3713 | l = [] |
| 3714 | def callback(path): |
| 3715 | l.append(path[-len('/testdir'):].replace(os.path.sep, '/')) |
| 3716 | vim.foreach_rtp(callback) |
| 3717 | cb.append(repr(l)) |
| 3718 | del l |
| 3719 | def callback(path): |
| 3720 | return path[-len('/testdir'):].replace(os.path.sep, '/') |
| 3721 | cb.append(repr(vim.foreach_rtp(callback))) |
| 3722 | del callback |
| 3723 | from module import dir as d |
| 3724 | from modulex import ddir |
| 3725 | cb.append(d + ',' + ddir) |
| 3726 | import before |
| 3727 | cb.append(before.dir) |
| 3728 | import after |
| 3729 | cb.append(after.dir) |
| 3730 | import topmodule as tm |
| 3731 | import topmodule.submodule as tms |
| 3732 | import topmodule.submodule.subsubmodule.subsubsubmodule as tmsss |
| 3733 | cb.append(tm.__file__.replace('.pyc', '.py').replace(os.path.sep, '/')[-len('modulex/topmodule/__init__.py'):]) |
| 3734 | cb.append(tms.__file__.replace('.pyc', '.py').replace(os.path.sep, '/')[-len('modulex/topmodule/submodule/__init__.py'):]) |
| 3735 | cb.append(tmsss.__file__.replace('.pyc', '.py').replace(os.path.sep, '/')[-len('modulex/topmodule/submodule/subsubmodule/subsubsubmodule.py'):]) |
Bram Moolenaar | ab58946 | 2020-07-06 21:03:06 +0200 | [diff] [blame] | 3736 | |
Bram Moolenaar | 92fdd1e | 2020-07-03 18:00:05 +0200 | [diff] [blame] | 3737 | del before |
| 3738 | del after |
| 3739 | del d |
| 3740 | del ddir |
| 3741 | del tm |
| 3742 | del tms |
| 3743 | del tmsss |
| 3744 | EOF |
| 3745 | |
| 3746 | let expected =<< trim END |
| 3747 | ['/testdir'] |
| 3748 | '/testdir' |
| 3749 | 2,xx |
| 3750 | before |
| 3751 | after |
| 3752 | pythonx/topmodule/__init__.py |
| 3753 | pythonx/topmodule/submodule/__init__.py |
| 3754 | pythonx/topmodule/submodule/subsubmodule/subsubsubmodule.py |
| 3755 | END |
| 3756 | call assert_equal(expected, getline(2, '$')) |
| 3757 | close! |
Bram Moolenaar | ab58946 | 2020-07-06 21:03:06 +0200 | [diff] [blame] | 3758 | |
Bram Moolenaar | 8e7d622 | 2020-12-18 19:49:56 +0100 | [diff] [blame] | 3759 | " Try to import a non-existing module with a dot (.) |
Bram Moolenaar | ab58946 | 2020-07-06 21:03:06 +0200 | [diff] [blame] | 3760 | call AssertException(['py import a.b.c'], 'ImportError:') |
Bram Moolenaar | 92fdd1e | 2020-07-03 18:00:05 +0200 | [diff] [blame] | 3761 | endfunc |
| 3762 | |
| 3763 | " Test exceptions |
| 3764 | func Test_python_exception() |
Bram Moolenaar | ab58946 | 2020-07-06 21:03:06 +0200 | [diff] [blame] | 3765 | func Exe(e) |
Bram Moolenaar | 92fdd1e | 2020-07-03 18:00:05 +0200 | [diff] [blame] | 3766 | execute a:e |
Bram Moolenaar | ab58946 | 2020-07-06 21:03:06 +0200 | [diff] [blame] | 3767 | endfunc |
Bram Moolenaar | 92fdd1e | 2020-07-03 18:00:05 +0200 | [diff] [blame] | 3768 | |
| 3769 | new |
| 3770 | py cb = vim.current.buffer |
| 3771 | |
| 3772 | py << trim EOF |
| 3773 | Exe = vim.bindeval('function("Exe")') |
| 3774 | ee('vim.command("throw \'abcN\'")') |
| 3775 | ee('Exe("throw \'def\'")') |
| 3776 | ee('vim.eval("Exe(\'throw \'\'ghi\'\'\')")') |
| 3777 | ee('vim.eval("Exe(\'echoerr \'\'jkl\'\'\')")') |
| 3778 | ee('vim.eval("Exe(\'xxx_non_existent_command_xxx\')")') |
| 3779 | ee('vim.eval("xxx_unknown_function_xxx()")') |
| 3780 | ee('vim.bindeval("Exe(\'xxx_non_existent_command_xxx\')")') |
| 3781 | del Exe |
| 3782 | EOF |
| 3783 | delfunction Exe |
| 3784 | |
| 3785 | let expected =<< trim END |
| 3786 | vim.command("throw 'abcN'"):error:('abcN',) |
| 3787 | Exe("throw 'def'"):error:('def',) |
| 3788 | vim.eval("Exe('throw ''ghi''')"):error:('ghi',) |
| 3789 | vim.eval("Exe('echoerr ''jkl''')"):error:('Vim(echoerr):jkl',) |
| 3790 | vim.eval("Exe('xxx_non_existent_command_xxx')"):error:('Vim:E492: Not an editor command: xxx_non_existent_command_xxx',) |
| 3791 | vim.eval("xxx_unknown_function_xxx()"):error:('Vim:E117: Unknown function: xxx_unknown_function_xxx',) |
| 3792 | vim.bindeval("Exe('xxx_non_existent_command_xxx')"):error:('Vim:E492: Not an editor command: xxx_non_existent_command_xxx',) |
| 3793 | END |
| 3794 | call assert_equal(expected, getline(2, '$')) |
| 3795 | close! |
| 3796 | endfunc |
| 3797 | |
| 3798 | " Regression: interrupting vim.command propagates to next vim.command |
| 3799 | func Test_python_keyboard_interrupt() |
| 3800 | new |
| 3801 | py cb = vim.current.buffer |
| 3802 | py << trim EOF |
| 3803 | def test_keyboard_interrupt(): |
| 3804 | try: |
| 3805 | vim.command('while 1 | endwhile') |
| 3806 | except KeyboardInterrupt: |
| 3807 | cb.append('Caught KeyboardInterrupt') |
| 3808 | except Exception: |
| 3809 | cb.append('!!!!!!!! Caught exception: ' + emsg(sys.exc_info())) |
| 3810 | else: |
| 3811 | cb.append('!!!!!!!! No exception') |
| 3812 | try: |
| 3813 | vim.command('$ put =\'Running :put\'') |
| 3814 | except KeyboardInterrupt: |
| 3815 | cb.append('!!!!!!!! Caught KeyboardInterrupt') |
| 3816 | except Exception: |
| 3817 | cb.append('!!!!!!!! Caught exception: ' + emsg(sys.exc_info())) |
| 3818 | else: |
| 3819 | cb.append('No exception') |
| 3820 | EOF |
| 3821 | |
| 3822 | debuggreedy |
| 3823 | call inputsave() |
| 3824 | call feedkeys("s\ns\ns\ns\nq\n") |
| 3825 | redir => output |
| 3826 | debug silent! py test_keyboard_interrupt() |
| 3827 | redir END |
| 3828 | 0 debuggreedy |
| 3829 | call inputrestore() |
| 3830 | py del test_keyboard_interrupt |
| 3831 | |
| 3832 | let expected =<< trim END |
| 3833 | Caught KeyboardInterrupt |
| 3834 | Running :put |
| 3835 | No exception |
| 3836 | END |
| 3837 | call assert_equal(expected, getline(2, '$')) |
| 3838 | call assert_equal('', output) |
| 3839 | close! |
| 3840 | endfunc |
| 3841 | |
Bram Moolenaar | 2e2f52a | 2020-12-21 16:03:02 +0100 | [diff] [blame] | 3842 | func Test_python_non_utf8_string() |
| 3843 | smap <Esc>@ <A-@> |
| 3844 | python vim.command('redir => _tmp_smaps | smap | redir END') |
| 3845 | python vim.eval('_tmp_smaps').splitlines() |
| 3846 | sunmap <Esc>@ |
| 3847 | endfunc |
| 3848 | |
Bram Moolenaar | 6c2b7b8 | 2020-04-14 20:15:49 +0200 | [diff] [blame] | 3849 | " vim: shiftwidth=2 sts=2 expandtab |