Bram Moolenaar | f42dd3c | 2017-01-28 16:06:38 +0100 | [diff] [blame] | 1 | " Test for pyx* commands and functions with Python 2. |
| 2 | |
| 3 | set pyx=2 |
Bram Moolenaar | b46fecd | 2019-06-15 17:58:09 +0200 | [diff] [blame] | 4 | source check.vim |
| 5 | CheckFeature python |
Bram Moolenaar | f42dd3c | 2017-01-28 16:06:38 +0100 | [diff] [blame] | 6 | |
| 7 | let s:py2pattern = '^2\.[0-7]\.\d\+' |
| 8 | let s:py3pattern = '^3\.\d\+\.\d\+' |
| 9 | |
| 10 | |
| 11 | func Test_has_pythonx() |
| 12 | call assert_true(has('pythonx')) |
| 13 | endfunc |
| 14 | |
| 15 | |
| 16 | func Test_pyx() |
| 17 | redir => var |
Bram Moolenaar | 6c2b7b8 | 2020-04-14 20:15:49 +0200 | [diff] [blame] | 18 | pyx << trim EOF |
| 19 | import sys |
| 20 | print(sys.version) |
| 21 | EOF |
Bram Moolenaar | f42dd3c | 2017-01-28 16:06:38 +0100 | [diff] [blame] | 22 | redir END |
| 23 | call assert_match(s:py2pattern, split(var)[0]) |
| 24 | endfunc |
| 25 | |
| 26 | |
| 27 | func Test_pyxdo() |
| 28 | pyx import sys |
| 29 | enew |
| 30 | pyxdo return sys.version.split("\n")[0] |
| 31 | call assert_match(s:py2pattern, split(getline('.'))[0]) |
| 32 | endfunc |
| 33 | |
| 34 | |
| 35 | func Test_pyxeval() |
| 36 | pyx import sys |
Bram Moolenaar | 3f4f3d8 | 2019-09-04 20:05:59 +0200 | [diff] [blame] | 37 | call assert_match(s:py2pattern, split('sys.version'->pyxeval())[0]) |
Bram Moolenaar | f42dd3c | 2017-01-28 16:06:38 +0100 | [diff] [blame] | 38 | endfunc |
| 39 | |
| 40 | |
| 41 | func Test_pyxfile() |
| 42 | " No special comments nor shebangs |
| 43 | redir => var |
| 44 | pyxfile pyxfile/pyx.py |
| 45 | redir END |
| 46 | call assert_match(s:py2pattern, split(var)[0]) |
| 47 | |
| 48 | " Python 2 special comment |
| 49 | redir => var |
| 50 | pyxfile pyxfile/py2_magic.py |
| 51 | redir END |
| 52 | call assert_match(s:py2pattern, split(var)[0]) |
| 53 | |
| 54 | " Python 2 shebang |
| 55 | redir => var |
| 56 | pyxfile pyxfile/py2_shebang.py |
| 57 | redir END |
| 58 | call assert_match(s:py2pattern, split(var)[0]) |
| 59 | |
| 60 | if has('python3') |
| 61 | " Python 3 special comment |
| 62 | redir => var |
| 63 | pyxfile pyxfile/py3_magic.py |
| 64 | redir END |
| 65 | call assert_match(s:py3pattern, split(var)[0]) |
| 66 | |
| 67 | " Python 3 shebang |
| 68 | redir => var |
| 69 | pyxfile pyxfile/py3_shebang.py |
| 70 | redir END |
| 71 | call assert_match(s:py3pattern, split(var)[0]) |
| 72 | endif |
| 73 | endfunc |
Bram Moolenaar | 7f3a284 | 2019-05-18 15:02:25 +0200 | [diff] [blame] | 74 | |
| 75 | func Test_Catch_Exception_Message() |
| 76 | try |
| 77 | pyx raise RuntimeError( 'TEST' ) |
| 78 | catch /.*/ |
| 79 | call assert_match( '^Vim(.*):RuntimeError: TEST$', v:exception ) |
| 80 | endtry |
| 81 | endfunc |
Bram Moolenaar | 6c2b7b8 | 2020-04-14 20:15:49 +0200 | [diff] [blame] | 82 | |
| 83 | " Test for various heredoc syntaxes |
| 84 | func Test_pyx2_heredoc() |
| 85 | pyx << END |
| 86 | result='A' |
| 87 | END |
| 88 | pyx << |
| 89 | result+='B' |
| 90 | . |
| 91 | pyx << trim END |
| 92 | result+='C' |
| 93 | END |
| 94 | pyx << trim |
| 95 | result+='D' |
| 96 | . |
Bram Moolenaar | 6ab0953 | 2020-05-01 14:10:13 +0200 | [diff] [blame] | 97 | pyx << trim eof |
| 98 | result+='E' |
| 99 | eof |
| 100 | call assert_equal('ABCDE', pyxeval('result')) |
Bram Moolenaar | 6c2b7b8 | 2020-04-14 20:15:49 +0200 | [diff] [blame] | 101 | endfunc |
| 102 | |
| 103 | " vim: shiftwidth=2 sts=2 expandtab |