blob: 344034af0049434141ef71a2a6aa0e0f11b21092 [file] [log] [blame]
Bram Moolenaar53901442018-07-25 22:02:36 +02001" Test for python 3 commands.
Bram Moolenaara58883b2017-01-29 21:31:09 +01002" TODO: move tests from test88.in here.
3
4if !has('python3')
5 finish
6endif
7
8func Test_py3do()
9 " Check deleting lines does not trigger an ml_get error.
10 py3 import vim
11 new
12 call setline(1, ['one', 'two', 'three'])
13 py3do vim.command("%d_")
14 bwipe!
15
16 " Check switching to another buffer does not trigger an ml_get error.
17 new
18 let wincount = winnr('$')
19 call setline(1, ['one', 'two', 'three'])
20 py3do vim.command("new")
21 call assert_equal(wincount + 1, winnr('$'))
22 bwipe!
23 bwipe!
24endfunc
Bram Moolenaar53901442018-07-25 22:02:36 +020025
26func Test_set_cursor()
27 " Check that setting the cursor position works.
28 py3 import vim
29 new
30 call setline(1, ['first line', 'second line'])
31 normal gg
32 py3do vim.current.window.cursor = (1, 5)
33 call assert_equal([1, 6], [line('.'), col('.')])
34
35 " Check that movement after setting cursor position keeps current column.
36 normal j
37 call assert_equal([2, 6], [line('.'), col('.')])
38endfunc
Bram Moolenaar9123c0b2018-12-22 18:59:06 +010039
40func Test_vim_function()
41 " Check creating vim.Function object
42 py3 import vim
43
44 func s:foo()
45 return matchstr(expand('<sfile>'), '<SNR>\zs\d\+_foo$')
46 endfunc
47 let name = '<SNR>' . s:foo()
48
49 try
50 py3 f = vim.bindeval('function("s:foo")')
51 call assert_equal(name, py3eval('f.name'))
52 catch
53 call assert_false(v:exception)
54 endtry
55
56 try
57 py3 f = vim.Function(b'\x80\xfdR' + vim.eval('s:foo()').encode())
58 call assert_equal(name, py3eval('f.name'))
59 catch
60 call assert_false(v:exception)
61 endtry
62
63 py3 del f
64 delfunc s:foo
65endfunc