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