UltiSnips/test/test_ContextSnippets.py
Holger Rapp 306f0ace5f Add a testing interface that works for Neovim.
- Remove support for python 3.2 to reduce number of test cases and because
  it actually fails with Neovim. It is not a supported version anyways.
- Due to Neovim not handling fast typing through the console properly
  (https://github.com/neovim/neovim/issues/2454), the typing is actually
  simulated through the Python client. We need to differentiate now if a
  keystroke is meant for the terminal or for the Vim session. Using
  neovim.input() introduces additional chances for races since inputs
  are not buffered but processed right away. This results in more
  retries for some tests.
- Neovim needs more parameters and configuration passed in through the
  test script. Added command line arguments for these.
- Skip an extra test under Neovim due to
  https://github.com/neovim/python-client/issues/128.
2015-07-14 21:58:30 +02:00

130 lines
2.8 KiB
Python

from test.constant import *
from test.vim_test_case import VimTestCase as _VimTest
class ContextSnippets_SimpleSnippet(_VimTest):
files = { 'us/all.snippets': r"""
snippet a "desc" "True" e
abc
endsnippet
"""}
keys = 'a' + EX
wanted = 'abc'
class ContextSnippets_ExpandOnTrue(_VimTest):
files = { 'us/all.snippets': r"""
global !p
def check_context():
return True
endglobal
snippet a "desc" "check_context()" e
abc
endsnippet
"""}
keys = 'a' + EX
wanted = 'abc'
class ContextSnippets_DoNotExpandOnFalse(_VimTest):
files = { 'us/all.snippets': r"""
global !p
def check_context():
return False
endglobal
snippet a "desc" "check_context()" e
abc
endsnippet
"""}
keys = 'a' + EX
wanted = keys
class ContextSnippets_UseContext(_VimTest):
files = { 'us/all.snippets': r"""
global !p
def wrap(ins):
return "< " + ins + " >"
endglobal
snippet a "desc" "wrap(buffer[line-1])" e
{ `!p snip.rv = context` }
endsnippet
"""}
keys = 'a' + EX
wanted = '{ < a > }'
class ContextSnippets_SnippetPriority(_VimTest):
files = { 'us/all.snippets': r"""
snippet i "desc" "re.search('err :=', buffer[line-2])" e
if err != nil {
${1:// pass}
}
endsnippet
snippet i
if ${1:true} {
${2:// pass}
}
endsnippet
"""}
keys = r"""
err := some_call()
i""" + EX + JF + """
i""" + EX
wanted = r"""
err := some_call()
if err != nil {
// pass
}
if true {
// pass
}"""
class ContextSnippets_PriorityKeyword(_VimTest):
files = { 'us/all.snippets': r"""
snippet i "desc" "True" e
a
endsnippet
priority 100
snippet i
b
endsnippet
"""}
keys = 'i' + EX
wanted = 'b'
class ContextSnippets_ReportError(_VimTest):
files = { 'us/all.snippets': r"""
snippet e "desc" "Tru" e
error
endsnippet
"""}
keys = 'e' + EX
wanted = 'e' + EX
expected_error = r"NameError: name 'Tru' is not defined"
class ContextSnippets_ReportErrorOnIndexOutOfRange(_VimTest):
# Working around: https://github.com/neovim/python-client/issues/128.
skip_if = lambda self: 'Bug in Neovim.' \
if self.vim_flavor == 'neovim' else None
files = { 'us/all.snippets': r"""
snippet e "desc" "buffer[123]" e
error
endsnippet
"""}
keys = 'e' + EX
wanted = 'e' + EX
expected_error = r"IndexError: line number out of range"