test_pyx3.vim 1.9 KB

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