Mercurial > vim
comparison src/testdir/test_pyx2.vim @ 10722:7598ce51bf2a v8.0.0251
patch 8.0.0251: not easy to select Python 2 or 3
commit https://github.com/vim/vim/commit/f42dd3c3901ea0ba38e67a616aea9953cae81b8d
Author: Bram Moolenaar <Bram@vim.org>
Date: Sat Jan 28 16:06:38 2017 +0100
patch 8.0.0251: not easy to select Python 2 or 3
Problem: It is not so easy to write a script that works with both Python 2
and Python 3, even when the Python code works with both.
Solution: Add 'pyxversion', :pyx, etc. (Marc Weber, Ken Takata)
author | Christian Brabandt <cb@256bit.org> |
---|---|
date | Sat, 28 Jan 2017 16:15:04 +0100 |
parents | |
children | e791f29affae |
comparison
equal
deleted
inserted
replaced
10721:9177c4f6a229 | 10722:7598ce51bf2a |
---|---|
1 " Test for pyx* commands and functions with Python 2. | |
2 | |
3 set pyx=2 | |
4 if !has('python') | |
5 finish | |
6 endif | |
7 | |
8 let s:py2pattern = '^2\.[0-7]\.\d\+' | |
9 let s:py3pattern = '^3\.\d\+\.\d\+' | |
10 | |
11 | |
12 func Test_has_pythonx() | |
13 call assert_true(has('pythonx')) | |
14 endfunc | |
15 | |
16 | |
17 func Test_pyx() | |
18 redir => var | |
19 pyx << EOF | |
20 import sys | |
21 print(sys.version) | |
22 EOF | |
23 redir END | |
24 call assert_match(s:py2pattern, split(var)[0]) | |
25 endfunc | |
26 | |
27 | |
28 func 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]) | |
33 endfunc | |
34 | |
35 | |
36 func Test_pyxeval() | |
37 pyx import sys | |
38 call assert_match(s:py2pattern, split(pyxeval('sys.version'))[0]) | |
39 endfunc | |
40 | |
41 | |
42 func 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 | |
74 endfunc |