xref: /vim-8.2.3635/src/testdir/test_pyx2.vim (revision 577fadfc)
1" Test for pyx* commands and functions with Python 2.
2
3set pyx=2
4if !has('python')
5  finish
6endif
7
8let s:py2pattern = '^2\.[0-7]\.\d\+'
9let s:py3pattern = '^3\.\d\+\.\d\+'
10
11
12func Test_has_pythonx()
13  call assert_true(has('pythonx'))
14endfunc
15
16
17func Test_pyx()
18  redir => var
19  pyx << EOF
20import sys
21print(sys.version)
22EOF
23  redir END
24  call assert_match(s:py2pattern, split(var)[0])
25endfunc
26
27
28func Test_pyxdo()
29  pyx import sys
30  enew
31  pyxdo return sys.version.split("\n")[0]
32  call assert_match(s:py2pattern, split(getline('.'))[0])
33endfunc
34
35
36func Test_pyxeval()
37  pyx import sys
38  call assert_match(s:py2pattern, split(pyxeval('sys.version'))[0])
39endfunc
40
41
42func Test_pyxfile()
43  " No special comments nor shebangs
44  redir => var
45  pyxfile pyxfile/pyx.py
46  redir END
47  call assert_match(s:py2pattern, split(var)[0])
48
49  " Python 2 special comment
50  redir => var
51  pyxfile pyxfile/py2_magic.py
52  redir END
53  call assert_match(s:py2pattern, split(var)[0])
54
55  " Python 2 shebang
56  redir => var
57  pyxfile pyxfile/py2_shebang.py
58  redir END
59  call assert_match(s:py2pattern, split(var)[0])
60
61  if has('python3')
62    " Python 3 special comment
63    redir => var
64    pyxfile pyxfile/py3_magic.py
65    redir END
66    call assert_match(s:py3pattern, split(var)[0])
67
68    " Python 3 shebang
69    redir => var
70    pyxfile pyxfile/py3_shebang.py
71    redir END
72    call assert_match(s:py3pattern, split(var)[0])
73  endif
74endfunc
75